Lines 121-126
Link Here
|
121 |
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory; |
121 |
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory; |
122 |
import org.eclipse.jdt.internal.corext.dom.ASTNodes; |
122 |
import org.eclipse.jdt.internal.corext.dom.ASTNodes; |
123 |
import org.eclipse.jdt.internal.corext.dom.Bindings; |
123 |
import org.eclipse.jdt.internal.corext.dom.Bindings; |
|
|
124 |
import org.eclipse.jdt.internal.corext.dom.DeclarationRewrite; |
124 |
import org.eclipse.jdt.internal.corext.dom.DimensionRewrite; |
125 |
import org.eclipse.jdt.internal.corext.dom.DimensionRewrite; |
125 |
import org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder; |
126 |
import org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder; |
126 |
import org.eclipse.jdt.internal.corext.dom.ModifierRewrite; |
127 |
import org.eclipse.jdt.internal.corext.dom.ModifierRewrite; |
Lines 951-957
Link Here
|
951 |
VariableDeclarationExpression oldVarDecl= (VariableDeclarationExpression) fragParent; |
952 |
VariableDeclarationExpression oldVarDecl= (VariableDeclarationExpression) fragParent; |
952 |
|
953 |
|
953 |
VariableDeclarationStatement newVarDec= ast.newVariableDeclarationStatement(newFrag); |
954 |
VariableDeclarationStatement newVarDec= ast.newVariableDeclarationStatement(newFrag); |
954 |
newVarDec.setType((Type) rewrite.createCopyTarget(oldVarDecl.getType())); |
955 |
Type copiedTypeNode= DeclarationRewrite.copyTypeAndAddTypeAnnotations(oldVarDecl.getType(), rewrite); |
|
|
956 |
newVarDec.setType(copiedTypeNode); |
955 |
newVarDec.modifiers().addAll(ASTNodeFactory.newModifiers(ast, oldVarDecl.getModifiers())); |
957 |
newVarDec.modifiers().addAll(ASTNodeFactory.newModifiers(ast, oldVarDecl.getModifiers())); |
956 |
newStatement= newVarDec; |
958 |
newStatement= newVarDec; |
957 |
} |
959 |
} |
Lines 1503-1509
Link Here
|
1503 |
ASTRewrite rewrite= ASTRewrite.create(ast); |
1505 |
ASTRewrite rewrite= ASTRewrite.create(ast); |
1504 |
if (selectedMultiCatchType != null) { |
1506 |
if (selectedMultiCatchType != null) { |
1505 |
removeException(rewrite, (UnionType) type, selectedMultiCatchType); |
1507 |
removeException(rewrite, (UnionType) type, selectedMultiCatchType); |
1506 |
addExceptionToThrows(ast, methodDeclaration, rewrite, selectedMultiCatchType); |
1508 |
addExceptionToThrows(methodDeclaration, rewrite, selectedMultiCatchType); |
1507 |
String label= CorrectionMessages.QuickAssistProcessor_exceptiontothrows_description; |
1509 |
String label= CorrectionMessages.QuickAssistProcessor_exceptiontothrows_description; |
1508 |
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_EXCEPTION_WITH_THROWS, image); |
1510 |
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_EXCEPTION_WITH_THROWS, image); |
1509 |
resultingCollections.add(proposal); |
1511 |
resultingCollections.add(proposal); |
Lines 1515-1524
Link Here
|
1515 |
for (Type elementType : types) { |
1517 |
for (Type elementType : types) { |
1516 |
if (!(elementType instanceof SimpleType || elementType instanceof NameQualifiedType)) |
1518 |
if (!(elementType instanceof SimpleType || elementType instanceof NameQualifiedType)) |
1517 |
return false; |
1519 |
return false; |
1518 |
addExceptionToThrows(ast, methodDeclaration, rewrite, elementType); |
1520 |
addExceptionToThrows(methodDeclaration, rewrite, elementType); |
1519 |
} |
1521 |
} |
1520 |
} else { |
1522 |
} else { |
1521 |
addExceptionToThrows(ast, methodDeclaration, rewrite, type); |
1523 |
addExceptionToThrows(methodDeclaration, rewrite, type); |
1522 |
} |
1524 |
} |
1523 |
String label= CorrectionMessages.QuickAssistProcessor_catchclausetothrows_description; |
1525 |
String label= CorrectionMessages.QuickAssistProcessor_catchclausetothrows_description; |
1524 |
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_CATCH_CLAUSE_WITH_THROWS, image); |
1526 |
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_CATCH_CLAUSE_WITH_THROWS, image); |
Lines 1544-1549
Link Here
|
1544 |
} |
1546 |
} |
1545 |
|
1547 |
|
1546 |
private static void removeException(ASTRewrite rewrite, UnionType unionType, Type exception) { |
1548 |
private static void removeException(ASTRewrite rewrite, UnionType unionType, Type exception) { |
|
|
1549 |
DeclarationRewrite.removeTypeAnnotationsFromDeclaration(exception, rewrite, null); |
1547 |
ListRewrite listRewrite= rewrite.getListRewrite(unionType, UnionType.TYPES_PROPERTY); |
1550 |
ListRewrite listRewrite= rewrite.getListRewrite(unionType, UnionType.TYPES_PROPERTY); |
1548 |
List<Type> types= unionType.types(); |
1551 |
List<Type> types= unionType.types(); |
1549 |
for (Iterator<Type> iterator= types.iterator(); iterator.hasNext();) { |
1552 |
for (Iterator<Type> iterator= types.iterator(); iterator.hasNext();) { |
Lines 1554-1563
Link Here
|
1554 |
} |
1557 |
} |
1555 |
} |
1558 |
} |
1556 |
|
1559 |
|
1557 |
private static void addExceptionToThrows(AST ast, MethodDeclaration methodDeclaration, ASTRewrite rewrite, Type type2) { |
1560 |
private static void addExceptionToThrows(MethodDeclaration methodDeclaration, ASTRewrite rewrite, Type type2) { |
1558 |
ITypeBinding binding= type2.resolveBinding(); |
1561 |
ITypeBinding binding= type2.resolveBinding(); |
1559 |
if (binding == null || isNotYetThrown(binding, methodDeclaration.thrownExceptionTypes())) { |
1562 |
if (binding == null || isNotYetThrown(binding, methodDeclaration.thrownExceptionTypes())) { |
1560 |
Type newType= (Type) ASTNode.copySubtree(ast, type2); |
1563 |
Type newType= DeclarationRewrite.copyTypeAndAddTypeAnnotations(type2, rewrite); |
1561 |
|
1564 |
|
1562 |
ListRewrite listRewriter= rewrite.getListRewrite(methodDeclaration, MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY); |
1565 |
ListRewrite listRewriter= rewrite.getListRewrite(methodDeclaration, MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY); |
1563 |
listRewriter.insertLast(newType, null); |
1566 |
listRewriter.insertLast(newType, null); |
Lines 1657-1664
Link Here
|
1657 |
List<Type> types= newUnionType.types(); |
1660 |
List<Type> types= newUnionType.types(); |
1658 |
for (int i= 0; i < coveredNodes.size(); i++) { |
1661 |
for (int i= 0; i < coveredNodes.size(); i++) { |
1659 |
ASTNode typeNode= coveredNodes.get(i); |
1662 |
ASTNode typeNode= coveredNodes.get(i); |
1660 |
types.add((Type) rewrite.createCopyTarget(typeNode)); |
1663 |
if (typeNode instanceof Type) { |
1661 |
rewrite.remove(typeNode, null); |
1664 |
Type copiedTypeNode= DeclarationRewrite.copyTypeAndMoveTypeAnnotations((Type) typeNode, rewrite, null); |
|
|
1665 |
types.add(copiedTypeNode); |
1666 |
rewrite.remove(typeNode, null); |
1667 |
} |
1662 |
} |
1668 |
} |
1663 |
newSingleVariableDeclaration.setType(newUnionType); |
1669 |
newSingleVariableDeclaration.setType(newUnionType); |
1664 |
newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(catchClause.getException().getName())); |
1670 |
newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(catchClause.getException().getName())); |
Lines 1747-1756
Link Here
|
1747 |
if (type instanceof UnionType) { |
1753 |
if (type instanceof UnionType) { |
1748 |
List<Type> types2= ((UnionType) type).types(); |
1754 |
List<Type> types2= ((UnionType) type).types(); |
1749 |
for (Iterator<Type> iterator2= types2.iterator(); iterator2.hasNext();) { |
1755 |
for (Iterator<Type> iterator2= types2.iterator(); iterator2.hasNext();) { |
1750 |
types.add((Type) rewrite.createCopyTarget(iterator2.next())); |
1756 |
Type copiedTypeNode= DeclarationRewrite.copyTypeAndMoveTypeAnnotations(iterator2.next(), rewrite, null); |
|
|
1757 |
types.add(copiedTypeNode); |
1751 |
} |
1758 |
} |
1752 |
} else { |
1759 |
} else { |
1753 |
types.add((Type) rewrite.createCopyTarget(type)); |
1760 |
Type copiedTypeNode= DeclarationRewrite.copyTypeAndMoveTypeAnnotations(type, rewrite, null); |
|
|
1761 |
types.add(copiedTypeNode); |
1754 |
} |
1762 |
} |
1755 |
} |
1763 |
} |
1756 |
|
1764 |
|
Lines 1817-1823
Link Here
|
1817 |
CatchClause newCatchClause= ast.newCatchClause(); |
1825 |
CatchClause newCatchClause= ast.newCatchClause(); |
1818 |
|
1826 |
|
1819 |
SingleVariableDeclaration newSingleVariableDeclaration= ast.newSingleVariableDeclaration(); |
1827 |
SingleVariableDeclaration newSingleVariableDeclaration= ast.newSingleVariableDeclaration(); |
1820 |
newSingleVariableDeclaration.setType((Type) rewrite.createCopyTarget(type2)); |
1828 |
Type copiedTypeNode= DeclarationRewrite.copyTypeAndMoveTypeAnnotations(type2, rewrite, null); |
|
|
1829 |
newSingleVariableDeclaration.setType(copiedTypeNode); |
1821 |
newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(singleVariableDeclaration.getName())); |
1830 |
newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(singleVariableDeclaration.getName())); |
1822 |
newCatchClause.setException(newSingleVariableDeclaration); |
1831 |
newCatchClause.setException(newSingleVariableDeclaration); |
1823 |
setCatchClauseBody(newCatchClause, rewrite, catchClause); |
1832 |
setCatchClauseBody(newCatchClause, rewrite, catchClause); |
Lines 2585-2593
Link Here
|
2585 |
VariableDeclarationStatement varDeclaration= ast.newVariableDeclarationStatement(varFragment); |
2594 |
VariableDeclarationStatement varDeclaration= ast.newVariableDeclarationStatement(varFragment); |
2586 |
Type varType; |
2595 |
Type varType; |
2587 |
if (initializerIsArray) { |
2596 |
if (initializerIsArray) { |
2588 |
ArrayType varArrayType= (ArrayType) DimensionRewrite.copyTypeAndAddDimensions(parameter.getType(), parameter.extraDimensions(), rewrite); |
2597 |
Type copiedType= DimensionRewrite.copyTypeAndAddDimensions(parameter.getType(), parameter.extraDimensions(), rewrite); |
2589 |
varArrayType.dimensions().add(0, ast.newDimension()); |
2598 |
varType= ASTNodeFactory.newArrayType(copiedType); |
2590 |
varType= varArrayType; |
|
|
2591 |
} else { |
2599 |
} else { |
2592 |
ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot()); |
2600 |
ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot()); |
2593 |
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(node, imports); |
2601 |
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(node, imports); |