|
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 |