|
Lines 82-87
Link Here
|
| 82 |
import org.eclipse.jdt.core.dom.Modifier; |
82 |
import org.eclipse.jdt.core.dom.Modifier; |
| 83 |
import org.eclipse.jdt.core.dom.Name; |
83 |
import org.eclipse.jdt.core.dom.Name; |
| 84 |
import org.eclipse.jdt.core.dom.NumberLiteral; |
84 |
import org.eclipse.jdt.core.dom.NumberLiteral; |
|
|
85 |
import org.eclipse.jdt.core.dom.PackageQualifiedType; |
| 85 |
import org.eclipse.jdt.core.dom.ParameterizedType; |
86 |
import org.eclipse.jdt.core.dom.ParameterizedType; |
| 86 |
import org.eclipse.jdt.core.dom.ParenthesizedExpression; |
87 |
import org.eclipse.jdt.core.dom.ParenthesizedExpression; |
| 87 |
import org.eclipse.jdt.core.dom.PostfixExpression; |
88 |
import org.eclipse.jdt.core.dom.PostfixExpression; |
|
Lines 505-512
Link Here
|
| 505 |
|
506 |
|
| 506 |
if (node instanceof Name) { |
507 |
if (node instanceof Name) { |
| 507 |
Name name= ASTNodes.getTopMostName((Name) node); |
508 |
Name name= ASTNodes.getTopMostName((Name) node); |
| 508 |
if (name.getLocationInParent() == SimpleType.NAME_PROPERTY) { |
509 |
if (name.getLocationInParent() == SimpleType.NAME_PROPERTY || |
| 509 |
SimpleType type= (SimpleType) name.getParent(); |
510 |
name.getLocationInParent() == PackageQualifiedType.NAME_PROPERTY) { |
|
|
511 |
ASTNode type= name.getParent(); |
| 510 |
if (type.getLocationInParent() == ParameterizedType.TYPE_PROPERTY) { |
512 |
if (type.getLocationInParent() == ParameterizedType.TYPE_PROPERTY) { |
| 511 |
createdType= (ParameterizedType) type.getParent(); |
513 |
createdType= (ParameterizedType) type.getParent(); |
| 512 |
if (createdType.getLocationInParent() != ClassInstanceCreation.TYPE_PROPERTY) { |
514 |
if (createdType.getLocationInParent() != ClassInstanceCreation.TYPE_PROPERTY) { |
|
Lines 1275-1281
Link Here
|
| 1275 |
} |
1277 |
} |
| 1276 |
|
1278 |
|
| 1277 |
Type type= catchClause.getException().getType(); |
1279 |
Type type= catchClause.getException().getType(); |
| 1278 |
if (!type.isSimpleType() && !type.isUnionType()) { |
1280 |
if (!type.isSimpleType() && !type.isUnionType() && !type.isPackageQualifiedType()) { |
| 1279 |
return false; |
1281 |
return false; |
| 1280 |
} |
1282 |
} |
| 1281 |
|
1283 |
|
|
Lines 1291-1302
Link Here
|
| 1291 |
AST ast= bodyDeclaration.getAST(); |
1293 |
AST ast= bodyDeclaration.getAST(); |
| 1292 |
Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION); |
1294 |
Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION); |
| 1293 |
|
1295 |
|
| 1294 |
SimpleType selectedMultiCatchType= null; |
1296 |
Type selectedMultiCatchType= null; |
| 1295 |
if (type.isUnionType() && node instanceof Name) { |
1297 |
if (type.isUnionType() && node instanceof Name) { |
| 1296 |
Name topMostName= ASTNodes.getTopMostName((Name) node); |
1298 |
Name topMostName= ASTNodes.getTopMostName((Name) node); |
| 1297 |
ASTNode parent= topMostName.getParent(); |
1299 |
ASTNode parent= topMostName.getParent(); |
| 1298 |
if (parent instanceof SimpleType) { |
1300 |
if (parent instanceof SimpleType) { |
| 1299 |
selectedMultiCatchType= (SimpleType) parent; |
1301 |
selectedMultiCatchType= (SimpleType) parent; |
|
|
1302 |
} else if (parent instanceof PackageQualifiedType) { |
| 1303 |
selectedMultiCatchType= (PackageQualifiedType) parent; |
| 1300 |
} |
1304 |
} |
| 1301 |
} |
1305 |
} |
| 1302 |
|
1306 |
|
|
Lines 1316-1327
Link Here
|
| 1316 |
UnionType unionType= (UnionType) type; |
1320 |
UnionType unionType= (UnionType) type; |
| 1317 |
List<Type> types= unionType.types(); |
1321 |
List<Type> types= unionType.types(); |
| 1318 |
for (Type elementType : types) { |
1322 |
for (Type elementType : types) { |
| 1319 |
if (!(elementType instanceof SimpleType)) |
1323 |
if (!(elementType instanceof SimpleType || elementType instanceof PackageQualifiedType)) |
| 1320 |
return false; |
1324 |
return false; |
| 1321 |
addExceptionToThrows(ast, methodDeclaration, rewrite, (SimpleType) elementType); |
1325 |
addExceptionToThrows(ast, methodDeclaration, rewrite, elementType); |
| 1322 |
} |
1326 |
} |
| 1323 |
} else { |
1327 |
} else { |
| 1324 |
addExceptionToThrows(ast, methodDeclaration, rewrite, (SimpleType) type); |
1328 |
addExceptionToThrows(ast, methodDeclaration, rewrite, type); |
| 1325 |
} |
1329 |
} |
| 1326 |
String label= CorrectionMessages.QuickAssistProcessor_catchclausetothrows_description; |
1330 |
String label= CorrectionMessages.QuickAssistProcessor_catchclausetothrows_description; |
| 1327 |
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_CATCH_CLAUSE_WITH_THROWS, image); |
1331 |
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_CATCH_CLAUSE_WITH_THROWS, image); |
|
Lines 1357-1363
Link Here
|
| 1357 |
} |
1361 |
} |
| 1358 |
} |
1362 |
} |
| 1359 |
|
1363 |
|
| 1360 |
private static void addExceptionToThrows(AST ast, MethodDeclaration methodDeclaration, ASTRewrite rewrite, SimpleType type2) { |
1364 |
private static void addExceptionToThrows(AST ast, MethodDeclaration methodDeclaration, ASTRewrite rewrite, Type type2) { |
| 1361 |
ITypeBinding binding= type2.resolveBinding(); |
1365 |
ITypeBinding binding= type2.resolveBinding(); |
| 1362 |
if (binding == null || isNotYetThrown(binding, methodDeclaration.thrownExceptionTypes())) { |
1366 |
if (binding == null || isNotYetThrown(binding, methodDeclaration.thrownExceptionTypes())) { |
| 1363 |
Type newType= (Type) ASTNode.copySubtree(ast, type2); |
1367 |
Type newType= (Type) ASTNode.copySubtree(ast, type2); |
|
Lines 1424-1435
Link Here
|
| 1424 |
return false; |
1428 |
return false; |
| 1425 |
} |
1429 |
} |
| 1426 |
|
1430 |
|
| 1427 |
SimpleType selectedMultiCatchType= null; |
1431 |
Type selectedMultiCatchType= null; |
| 1428 |
if (type.isUnionType() && node instanceof Name) { |
1432 |
if (type.isUnionType() && node instanceof Name) { |
| 1429 |
Name topMostName= ASTNodes.getTopMostName((Name) node); |
1433 |
Name topMostName= ASTNodes.getTopMostName((Name) node); |
| 1430 |
ASTNode parent= topMostName.getParent(); |
1434 |
ASTNode parent= topMostName.getParent(); |
| 1431 |
if (parent instanceof SimpleType) { |
1435 |
if (parent instanceof SimpleType || parent instanceof PackageQualifiedType) { |
| 1432 |
selectedMultiCatchType= (SimpleType) parent; |
1436 |
selectedMultiCatchType= (Type) parent; |
| 1433 |
} |
1437 |
} |
| 1434 |
} |
1438 |
} |
| 1435 |
|
1439 |
|
|
Lines 1497-1508
Link Here
|
| 1497 |
} |
1501 |
} |
| 1498 |
|
1502 |
|
| 1499 |
Type type1= catchClause.getException().getType(); |
1503 |
Type type1= catchClause.getException().getType(); |
| 1500 |
SimpleType selectedMultiCatchType= null; |
1504 |
Type selectedMultiCatchType= null; |
| 1501 |
if (type1.isUnionType() && covering instanceof Name) { |
1505 |
if (type1.isUnionType() && covering instanceof Name) { |
| 1502 |
Name topMostName= ASTNodes.getTopMostName((Name) covering); |
1506 |
Name topMostName= ASTNodes.getTopMostName((Name) covering); |
| 1503 |
ASTNode parent= topMostName.getParent(); |
1507 |
ASTNode parent= topMostName.getParent(); |
| 1504 |
if (parent instanceof SimpleType) { |
1508 |
if (parent instanceof SimpleType || parent instanceof PackageQualifiedType) { |
| 1505 |
selectedMultiCatchType= (SimpleType) parent; |
1509 |
selectedMultiCatchType= (Type) parent; |
| 1506 |
} |
1510 |
} |
| 1507 |
} |
1511 |
} |
| 1508 |
if (selectedMultiCatchType != null) |
1512 |
if (selectedMultiCatchType != null) |
|
Lines 1588-1599
Link Here
|
| 1588 |
} |
1592 |
} |
| 1589 |
|
1593 |
|
| 1590 |
Type type1= catchClause.getException().getType(); |
1594 |
Type type1= catchClause.getException().getType(); |
| 1591 |
SimpleType selectedMultiCatchType= null; |
1595 |
Type selectedMultiCatchType= null; |
| 1592 |
if (type1.isUnionType() && covering instanceof Name) { |
1596 |
if (type1.isUnionType() && covering instanceof Name) { |
| 1593 |
Name topMostName= ASTNodes.getTopMostName((Name) covering); |
1597 |
Name topMostName= ASTNodes.getTopMostName((Name) covering); |
| 1594 |
ASTNode parent= topMostName.getParent(); |
1598 |
ASTNode parent= topMostName.getParent(); |
| 1595 |
if (parent instanceof SimpleType) { |
1599 |
if (parent instanceof SimpleType || parent instanceof PackageQualifiedType) { |
| 1596 |
selectedMultiCatchType= (SimpleType) parent; |
1600 |
selectedMultiCatchType= (Type) parent; |
| 1597 |
} |
1601 |
} |
| 1598 |
} |
1602 |
} |
| 1599 |
if (selectedMultiCatchType != null) |
1603 |
if (selectedMultiCatchType != null) |