Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 394724
Collapse All | Expand All

(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test49_in.java (+15 lines)
Added Link Here
1
package p;
2
class A {
3
    void f() throws Exception {
4
        final int m = g();
5
6
        new Object() {
7
            void f() {
8
                int n = m;
9
            }
10
        };
11
    }
12
    int g() throws Exception {
13
        return 0;
14
    }
15
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test49_out.java (+13 lines)
Added Link Here
1
package p;
2
class A {
3
    void f() throws Exception {
4
        new Object() {
5
            void f() throws Exception {
6
                int n = g();
7
            }
8
        };
9
    }
10
    int g() throws Exception {
11
        return 0;
12
    }
13
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineTempTests.java (-1 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Samrat Dhillon <samrat.dhillon@gmail.com> - [inline] Inline local variable does not add throws clause in the resulting method in anonymous class - https://bugs.eclipse.org/394724
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.ui.tests.refactoring;
12
package org.eclipse.jdt.ui.tests.refactoring;
12
13
Lines 339-344 Link Here
339
		//https://bugs.eclipse.org/bugs/show_bug.cgi?id=388078
340
		//https://bugs.eclipse.org/bugs/show_bug.cgi?id=388078
340
		helper1(6, 16, 6, 18);
341
		helper1(6, 16, 6, 18);
341
	}
342
	}
343
	
344
	public void test49() throws Exception {
345
		//https://bugs.eclipse.org/bugs/show_bug.cgi?id=394724
346
		helper1(4, 9, 4, 27);
347
	}
342
348
343
	//------
349
	//------
344
350
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java (-1 / +34 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-16 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Samrat Dhillon <samrat.dhillon@gmail.com> - [inline] Inline local variable does not add throws clause in the resulting method in anonymous class - https://bugs.eclipse.org/394724
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.corext.refactoring.code;
12
package org.eclipse.jdt.internal.corext.refactoring.code;
12
13
13
import java.util.HashMap;
14
import java.util.HashMap;
15
import java.util.Iterator;
14
import java.util.Map;
16
import java.util.Map;
15
import java.util.StringTokenizer;
17
import java.util.StringTokenizer;
16
18
Lines 61-66 Link Here
61
import org.eclipse.jdt.core.dom.MethodDeclaration;
63
import org.eclipse.jdt.core.dom.MethodDeclaration;
62
import org.eclipse.jdt.core.dom.MethodInvocation;
64
import org.eclipse.jdt.core.dom.MethodInvocation;
63
import org.eclipse.jdt.core.dom.Modifier;
65
import org.eclipse.jdt.core.dom.Modifier;
66
import org.eclipse.jdt.core.dom.Name;
64
import org.eclipse.jdt.core.dom.ParenthesizedExpression;
67
import org.eclipse.jdt.core.dom.ParenthesizedExpression;
65
import org.eclipse.jdt.core.dom.SimpleName;
68
import org.eclipse.jdt.core.dom.SimpleName;
66
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
69
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
Lines 79-84 Link Here
79
import org.eclipse.jdt.internal.core.refactoring.descriptors.RefactoringSignatureDescriptorFactory;
82
import org.eclipse.jdt.internal.core.refactoring.descriptors.RefactoringSignatureDescriptorFactory;
80
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
83
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
81
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
84
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
85
import org.eclipse.jdt.internal.corext.dom.Bindings;
82
import org.eclipse.jdt.internal.corext.dom.NecessaryParenthesesChecker;
86
import org.eclipse.jdt.internal.corext.dom.NecessaryParenthesesChecker;
83
import org.eclipse.jdt.internal.corext.refactoring.Checks;
87
import org.eclipse.jdt.internal.corext.refactoring.Checks;
84
import org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment;
88
import org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment;
Lines 354-365 Link Here
354
		}
358
		}
355
		return copy;
359
		return copy;
356
	}
360
	}
361
	
362
	private void addExceptionToNodeList(String fullyQualified, ListRewrite exceptionListRewrite, CompilationUnitRewrite rewrite) {
363
		for (Iterator<? extends ASTNode> iter= exceptionListRewrite.getOriginalList().iterator(); iter.hasNext(); ) {
364
			Name exName= (Name) iter.next();
365
			ITypeBinding typeBinding= exName.resolveTypeBinding();
366
			if (typeBinding == null)
367
				continue; // newly added or unresolvable type
368
			if (typeBinding.getQualifiedName().equals(fullyQualified))
369
				return; // don't add it again
370
		}
371
		String importedType= rewrite.getImportRewrite().addImport(fullyQualified);
372
		rewrite.getImportRemover().registerAddedImport(importedType);
373
		ASTNode exNode= rewrite.getASTRewrite().createStringPlaceholder(importedType, ASTNode.SIMPLE_NAME);
374
		exceptionListRewrite.insertLast(exNode, rewrite.createGroupDescription(RefactoringCoreMessages.InlineTempRefactoring_inline_edit_name));
375
	}
376
	
357
377
358
	private Expression getModifiedInitializerSource(CompilationUnitRewrite rewrite, SimpleName reference) throws JavaModelException {
378
	private Expression getModifiedInitializerSource(CompilationUnitRewrite rewrite, SimpleName reference) throws JavaModelException {
359
		VariableDeclaration varDecl= getVariableDeclaration();
379
		VariableDeclaration varDecl= getVariableDeclaration();
360
		Expression initializer= varDecl.getInitializer();
380
		Expression initializer= varDecl.getInitializer();
361
381
362
		ASTNode referenceContext= reference.getParent();
382
		ASTNode referenceContext= reference.getParent();
383
		
384
		if(initializer instanceof MethodInvocation){
385
			MethodInvocation mi= (MethodInvocation) initializer;
386
			ITypeBinding[] exceptionTypes= mi.resolveMethodBinding().getExceptionTypes();
387
			MethodDeclaration methodDeclaration= (MethodDeclaration) ASTNodes.getParent(reference, ASTNode.METHOD_DECLARATION);
388
			for(ITypeBinding binding: exceptionTypes){
389
				if(!Bindings.isRuntimeException(binding)){
390
					addExceptionToNodeList(binding.getQualifiedName(), rewrite.getASTRewrite().getListRewrite(methodDeclaration,  MethodDeclaration.THROWN_EXCEPTIONS_PROPERTY), rewrite);
391
				}
392
				
393
			}
394
		}
395
		
363
		if (Invocations.isResolvedTypeInferredFromExpectedType(initializer)) {
396
		if (Invocations.isResolvedTypeInferredFromExpectedType(initializer)) {
364
			if (! (referenceContext instanceof VariableDeclarationFragment
397
			if (! (referenceContext instanceof VariableDeclarationFragment
365
					|| referenceContext instanceof SingleVariableDeclaration
398
					|| referenceContext instanceof SingleVariableDeclaration

Return to bug 394724