|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2013 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2014 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 82-87
Link Here
|
| 82 |
import org.eclipse.jdt.core.dom.MethodInvocation; |
82 |
import org.eclipse.jdt.core.dom.MethodInvocation; |
| 83 |
import org.eclipse.jdt.core.dom.Modifier; |
83 |
import org.eclipse.jdt.core.dom.Modifier; |
| 84 |
import org.eclipse.jdt.core.dom.Name; |
84 |
import org.eclipse.jdt.core.dom.Name; |
|
|
85 |
import org.eclipse.jdt.core.dom.NameQualifiedType; |
| 85 |
import org.eclipse.jdt.core.dom.NumberLiteral; |
86 |
import org.eclipse.jdt.core.dom.NumberLiteral; |
| 86 |
import org.eclipse.jdt.core.dom.ParameterizedType; |
87 |
import org.eclipse.jdt.core.dom.ParameterizedType; |
| 87 |
import org.eclipse.jdt.core.dom.ParenthesizedExpression; |
88 |
import org.eclipse.jdt.core.dom.ParenthesizedExpression; |
|
Lines 579-586
Link Here
|
| 579 |
|
580 |
|
| 580 |
if (node instanceof Name) { |
581 |
if (node instanceof Name) { |
| 581 |
Name name= ASTNodes.getTopMostName((Name) node); |
582 |
Name name= ASTNodes.getTopMostName((Name) node); |
| 582 |
if (name.getLocationInParent() == SimpleType.NAME_PROPERTY) { |
583 |
if (name.getLocationInParent() == SimpleType.NAME_PROPERTY || |
| 583 |
SimpleType type= (SimpleType) name.getParent(); |
584 |
name.getLocationInParent() == NameQualifiedType.NAME_PROPERTY) { |
|
|
585 |
ASTNode type= name.getParent(); |
| 584 |
if (type.getLocationInParent() == ParameterizedType.TYPE_PROPERTY) { |
586 |
if (type.getLocationInParent() == ParameterizedType.TYPE_PROPERTY) { |
| 585 |
createdType= (ParameterizedType) type.getParent(); |
587 |
createdType= (ParameterizedType) type.getParent(); |
| 586 |
if (createdType.getLocationInParent() != ClassInstanceCreation.TYPE_PROPERTY) { |
588 |
if (createdType.getLocationInParent() != ClassInstanceCreation.TYPE_PROPERTY) { |
|
Lines 1349-1355
Link Here
|
| 1349 |
} |
1351 |
} |
| 1350 |
|
1352 |
|
| 1351 |
Type type= catchClause.getException().getType(); |
1353 |
Type type= catchClause.getException().getType(); |
| 1352 |
if (!type.isSimpleType() && !type.isUnionType()) { |
1354 |
if (!type.isSimpleType() && !type.isUnionType() && !type.isNameQualifiedType()) { |
| 1353 |
return false; |
1355 |
return false; |
| 1354 |
} |
1356 |
} |
| 1355 |
|
1357 |
|
|
Lines 1365-1376
Link Here
|
| 1365 |
AST ast= bodyDeclaration.getAST(); |
1367 |
AST ast= bodyDeclaration.getAST(); |
| 1366 |
Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION); |
1368 |
Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION); |
| 1367 |
|
1369 |
|
| 1368 |
SimpleType selectedMultiCatchType= null; |
1370 |
Type selectedMultiCatchType= null; |
| 1369 |
if (type.isUnionType() && node instanceof Name) { |
1371 |
if (type.isUnionType() && node instanceof Name) { |
| 1370 |
Name topMostName= ASTNodes.getTopMostName((Name) node); |
1372 |
Name topMostName= ASTNodes.getTopMostName((Name) node); |
| 1371 |
ASTNode parent= topMostName.getParent(); |
1373 |
ASTNode parent= topMostName.getParent(); |
| 1372 |
if (parent instanceof SimpleType) { |
1374 |
if (parent instanceof SimpleType) { |
| 1373 |
selectedMultiCatchType= (SimpleType) parent; |
1375 |
selectedMultiCatchType= (SimpleType) parent; |
|
|
1376 |
} else if (parent instanceof NameQualifiedType) { |
| 1377 |
selectedMultiCatchType= (NameQualifiedType) parent; |
| 1374 |
} |
1378 |
} |
| 1375 |
} |
1379 |
} |
| 1376 |
|
1380 |
|
|
Lines 1390-1401
Link Here
|
| 1390 |
UnionType unionType= (UnionType) type; |
1394 |
UnionType unionType= (UnionType) type; |
| 1391 |
List<Type> types= unionType.types(); |
1395 |
List<Type> types= unionType.types(); |
| 1392 |
for (Type elementType : types) { |
1396 |
for (Type elementType : types) { |
| 1393 |
if (!(elementType instanceof SimpleType)) |
1397 |
if (!(elementType instanceof SimpleType || elementType instanceof NameQualifiedType)) |
| 1394 |
return false; |
1398 |
return false; |
| 1395 |
addExceptionToThrows(ast, methodDeclaration, rewrite, (SimpleType) elementType); |
1399 |
addExceptionToThrows(ast, methodDeclaration, rewrite, elementType); |
| 1396 |
} |
1400 |
} |
| 1397 |
} else { |
1401 |
} else { |
| 1398 |
addExceptionToThrows(ast, methodDeclaration, rewrite, (SimpleType) type); |
1402 |
addExceptionToThrows(ast, methodDeclaration, rewrite, type); |
| 1399 |
} |
1403 |
} |
| 1400 |
String label= CorrectionMessages.QuickAssistProcessor_catchclausetothrows_description; |
1404 |
String label= CorrectionMessages.QuickAssistProcessor_catchclausetothrows_description; |
| 1401 |
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_CATCH_CLAUSE_WITH_THROWS, image); |
1405 |
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_CATCH_CLAUSE_WITH_THROWS, image); |
|
Lines 1431-1437
Link Here
|
| 1431 |
} |
1435 |
} |
| 1432 |
} |
1436 |
} |
| 1433 |
|
1437 |
|
| 1434 |
private static void addExceptionToThrows(AST ast, MethodDeclaration methodDeclaration, ASTRewrite rewrite, SimpleType type2) { |
1438 |
private static void addExceptionToThrows(AST ast, MethodDeclaration methodDeclaration, ASTRewrite rewrite, Type type2) { |
| 1435 |
ITypeBinding binding= type2.resolveBinding(); |
1439 |
ITypeBinding binding= type2.resolveBinding(); |
| 1436 |
if (binding == null || isNotYetThrown(binding, methodDeclaration.thrownExceptionTypes())) { |
1440 |
if (binding == null || isNotYetThrown(binding, methodDeclaration.thrownExceptionTypes())) { |
| 1437 |
Type newType= (Type) ASTNode.copySubtree(ast, type2); |
1441 |
Type newType= (Type) ASTNode.copySubtree(ast, type2); |
|
Lines 1498-1509
Link Here
|
| 1498 |
return false; |
1502 |
return false; |
| 1499 |
} |
1503 |
} |
| 1500 |
|
1504 |
|
| 1501 |
SimpleType selectedMultiCatchType= null; |
1505 |
Type selectedMultiCatchType= null; |
| 1502 |
if (type.isUnionType() && node instanceof Name) { |
1506 |
if (type.isUnionType() && node instanceof Name) { |
| 1503 |
Name topMostName= ASTNodes.getTopMostName((Name) node); |
1507 |
Name topMostName= ASTNodes.getTopMostName((Name) node); |
| 1504 |
ASTNode parent= topMostName.getParent(); |
1508 |
ASTNode parent= topMostName.getParent(); |
| 1505 |
if (parent instanceof SimpleType) { |
1509 |
if (parent instanceof SimpleType || parent instanceof NameQualifiedType) { |
| 1506 |
selectedMultiCatchType= (SimpleType) parent; |
1510 |
selectedMultiCatchType= (Type) parent; |
| 1507 |
} |
1511 |
} |
| 1508 |
} |
1512 |
} |
| 1509 |
|
1513 |
|
|
Lines 1571-1582
Link Here
|
| 1571 |
} |
1575 |
} |
| 1572 |
|
1576 |
|
| 1573 |
Type type1= catchClause.getException().getType(); |
1577 |
Type type1= catchClause.getException().getType(); |
| 1574 |
SimpleType selectedMultiCatchType= null; |
1578 |
Type selectedMultiCatchType= null; |
| 1575 |
if (type1.isUnionType() && covering instanceof Name) { |
1579 |
if (type1.isUnionType() && covering instanceof Name) { |
| 1576 |
Name topMostName= ASTNodes.getTopMostName((Name) covering); |
1580 |
Name topMostName= ASTNodes.getTopMostName((Name) covering); |
| 1577 |
ASTNode parent= topMostName.getParent(); |
1581 |
ASTNode parent= topMostName.getParent(); |
| 1578 |
if (parent instanceof SimpleType) { |
1582 |
if (parent instanceof SimpleType || parent instanceof NameQualifiedType) { |
| 1579 |
selectedMultiCatchType= (SimpleType) parent; |
1583 |
selectedMultiCatchType= (Type) parent; |
| 1580 |
} |
1584 |
} |
| 1581 |
} |
1585 |
} |
| 1582 |
if (selectedMultiCatchType != null) |
1586 |
if (selectedMultiCatchType != null) |
|
Lines 1662-1673
Link Here
|
| 1662 |
} |
1666 |
} |
| 1663 |
|
1667 |
|
| 1664 |
Type type1= catchClause.getException().getType(); |
1668 |
Type type1= catchClause.getException().getType(); |
| 1665 |
SimpleType selectedMultiCatchType= null; |
1669 |
Type selectedMultiCatchType= null; |
| 1666 |
if (type1.isUnionType() && covering instanceof Name) { |
1670 |
if (type1.isUnionType() && covering instanceof Name) { |
| 1667 |
Name topMostName= ASTNodes.getTopMostName((Name) covering); |
1671 |
Name topMostName= ASTNodes.getTopMostName((Name) covering); |
| 1668 |
ASTNode parent= topMostName.getParent(); |
1672 |
ASTNode parent= topMostName.getParent(); |
| 1669 |
if (parent instanceof SimpleType) { |
1673 |
if (parent instanceof SimpleType || parent instanceof NameQualifiedType) { |
| 1670 |
selectedMultiCatchType= (SimpleType) parent; |
1674 |
selectedMultiCatchType= (Type) parent; |
| 1671 |
} |
1675 |
} |
| 1672 |
} |
1676 |
} |
| 1673 |
if (selectedMultiCatchType != null) |
1677 |
if (selectedMultiCatchType != null) |