Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2010 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 75-86
Link Here
|
75 |
import org.eclipse.jdt.core.dom.Name; |
75 |
import org.eclipse.jdt.core.dom.Name; |
76 |
import org.eclipse.jdt.core.dom.ParenthesizedExpression; |
76 |
import org.eclipse.jdt.core.dom.ParenthesizedExpression; |
77 |
import org.eclipse.jdt.core.dom.PrefixExpression; |
77 |
import org.eclipse.jdt.core.dom.PrefixExpression; |
|
|
78 |
import org.eclipse.jdt.core.dom.ReturnStatement; |
78 |
import org.eclipse.jdt.core.dom.SimpleName; |
79 |
import org.eclipse.jdt.core.dom.SimpleName; |
79 |
import org.eclipse.jdt.core.dom.SingleVariableDeclaration; |
80 |
import org.eclipse.jdt.core.dom.SingleVariableDeclaration; |
80 |
import org.eclipse.jdt.core.dom.Statement; |
81 |
import org.eclipse.jdt.core.dom.Statement; |
81 |
import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor; |
82 |
import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor; |
82 |
import org.eclipse.jdt.core.dom.SwitchCase; |
83 |
import org.eclipse.jdt.core.dom.SwitchCase; |
83 |
import org.eclipse.jdt.core.dom.SwitchStatement; |
84 |
import org.eclipse.jdt.core.dom.SwitchStatement; |
|
|
85 |
import org.eclipse.jdt.core.dom.ThrowStatement; |
84 |
import org.eclipse.jdt.core.dom.TryStatement; |
86 |
import org.eclipse.jdt.core.dom.TryStatement; |
85 |
import org.eclipse.jdt.core.dom.Type; |
87 |
import org.eclipse.jdt.core.dom.Type; |
86 |
import org.eclipse.jdt.core.dom.TypeDeclaration; |
88 |
import org.eclipse.jdt.core.dom.TypeDeclaration; |
Lines 111-116
Link Here
|
111 |
import org.eclipse.jdt.internal.corext.refactoring.surround.ExceptionAnalyzer; |
113 |
import org.eclipse.jdt.internal.corext.refactoring.surround.ExceptionAnalyzer; |
112 |
import org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithTryCatchRefactoring; |
114 |
import org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithTryCatchRefactoring; |
113 |
import org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer; |
115 |
import org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer; |
|
|
116 |
import org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer; |
114 |
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; |
117 |
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; |
115 |
import org.eclipse.jdt.internal.corext.util.Messages; |
118 |
import org.eclipse.jdt.internal.corext.util.Messages; |
116 |
|
119 |
|
Lines 992-997
Link Here
|
992 |
proposals.add(proposal); |
995 |
proposals.add(proposal); |
993 |
} |
996 |
} |
994 |
|
997 |
|
|
|
998 |
public static void getUnusedObjectAllocationProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) { |
999 |
CompilationUnit root= context.getASTRoot(); |
1000 |
AST ast= root.getAST(); |
1001 |
ASTNode selectedNode= problem.getCoveringNode(root); |
1002 |
if (selectedNode == null) { |
1003 |
return; |
1004 |
} |
1005 |
|
1006 |
ASTNode parent= selectedNode.getParent(); |
1007 |
|
1008 |
if (parent instanceof ExpressionStatement) { |
1009 |
ExpressionStatement expressionStatement= (ExpressionStatement) parent; |
1010 |
Expression expr= expressionStatement.getExpression(); |
1011 |
ITypeBinding exprType= expr.resolveTypeBinding(); |
1012 |
|
1013 |
if (exprType != null && Bindings.isSuperType(ast.resolveWellKnownType("java.lang.Throwable"), exprType)) { //$NON-NLS-1$ |
1014 |
ASTRewrite rewrite= ASTRewrite.create(ast); |
1015 |
TightSourceRangeComputer sourceRangeComputer= new TightSourceRangeComputer(); |
1016 |
rewrite.setTargetSourceRangeComputer(sourceRangeComputer); |
1017 |
|
1018 |
ThrowStatement throwStatement= ast.newThrowStatement(); |
1019 |
throwStatement.setExpression((Expression) rewrite.createMoveTarget(expr)); |
1020 |
sourceRangeComputer.addTightSourceNode(expressionStatement); |
1021 |
rewrite.replace(expressionStatement, throwStatement, null); |
1022 |
|
1023 |
String label= CorrectionMessages.LocalCorrectionsSubProcessor_throw_allocated_description; |
1024 |
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); |
1025 |
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 8, image); |
1026 |
proposals.add(proposal); |
1027 |
} |
1028 |
|
1029 |
MethodDeclaration method= ASTResolving.findParentMethodDeclaration(selectedNode); |
1030 |
if (method != null) { |
1031 |
ASTRewrite rewrite= ASTRewrite.create(ast); |
1032 |
TightSourceRangeComputer sourceRangeComputer= new TightSourceRangeComputer(); |
1033 |
rewrite.setTargetSourceRangeComputer(sourceRangeComputer); |
1034 |
|
1035 |
ReturnStatement returnStatement= ast.newReturnStatement(); |
1036 |
returnStatement.setExpression((Expression) rewrite.createMoveTarget(expr)); |
1037 |
sourceRangeComputer.addTightSourceNode(expressionStatement); |
1038 |
rewrite.replace(expressionStatement, returnStatement, null); |
1039 |
|
1040 |
String label= CorrectionMessages.LocalCorrectionsSubProcessor_return_allocated_description; |
1041 |
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); |
1042 |
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 7, image); |
1043 |
proposals.add(proposal); |
1044 |
} |
1045 |
|
1046 |
{ |
1047 |
ASTRewrite rewrite= ASTRewrite.create(ast); |
1048 |
rewrite.remove(parent, null); |
1049 |
|
1050 |
String label= CorrectionMessages.LocalCorrectionsSubProcessor_remove_allocated_description; |
1051 |
Image image= JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE); |
1052 |
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 2, image); |
1053 |
proposals.add(proposal); |
1054 |
} |
1055 |
|
1056 |
} |
1057 |
} |
1058 |
|
995 |
public static void getAssignmentHasNoEffectProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) { |
1059 |
public static void getAssignmentHasNoEffectProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) { |
996 |
CompilationUnit root= context.getASTRoot(); |
1060 |
CompilationUnit root= context.getASTRoot(); |
997 |
ASTNode selectedNode= problem.getCoveringNode(root); |
1061 |
ASTNode selectedNode= problem.getCoveringNode(root); |