public static void addUnnecessaryThrownExceptionProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); selectedNode= ASTNodes.getNormalizedNode(selectedNode); if (selectedNode == null || selectedNode.getLocationInParent() != MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) { return; } MethodDeclaration decl= (MethodDeclaration) selectedNode.getParent(); IMethodBinding binding= decl.resolveBinding(); if (binding != null) { List<Type> thrownExceptions= decl.thrownExceptionTypes(); int index= thrownExceptions.indexOf(selectedNode); if (index == -1) { return; } ChangeDescription[] desc= new ChangeDescription[thrownExceptions.size()]; desc[index]= new RemoveDescription(); ICompilationUnit cu= context.getCompilationUnit(); String label= CorrectionMessages.LocalCorrectionsSubProcessor_unnecessarythrow_description; Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION); proposals.add(new ChangeMethodSignatureProposal(label, cu, selectedNode, binding, null, desc, IProposalRelevance.UNNECESSARY_THROW, image)); } JavadocTagsSubProcessor.getUnusedAndUndocumentedParameterOrExceptionProposals(context, problem, proposals); }
ImportRewrite imports= getImportRewrite(); ImportRewriteContext context= new ContextSensitiveImportRewriteContext(methodDecl, imports); ListRewrite listRewrite= rewrite.getListRewrite(methodDecl, MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY); String key= getExceptionTypeGroupId(i); addLinkedPosition(rewrite.track(newNode), false, key); ASTNode newRef= ASTNodeFactory.newName(ast, type); newTagElement.fragments().add(newRef); insertTabStop(rewrite, newTagElement.fragments(), "throws_tagcomment" + i); //$NON-NLS-1$ insertThrowsTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), exceptions, k, newTagElement); addLinkedPosition(rewrite.track(newRef), false, key); TagElement tagNode= findThrowsTag(methodDecl, node); if (tagNode != null) { rewrite.remove(tagNode, null); String key= getExceptionTypeGroupId(i); addLinkedPosition(rewrite.track(newNode), false, key); TagElement tagNode= findThrowsTag(methodDecl, oldNode); if (tagNode != null) { ASTNode newRef= ASTNodeFactory.newType(ast, type); rewrite.replace((ASTNode) tagNode.fragments().get(0), newRef, null); addLinkedPosition(rewrite.track(newRef), false, key); TagElement tagNode1= findThrowsTag(methodDecl, decl1); TagElement tagNode2= findThrowsTag(methodDecl, decl2);
ModifyDescription desc= (ModifyDescription) curr; String typeKey= getParamTypeGroupId(i); String nameKey= getParamNameGroupId(i); favourite= StubUtility.suggestArgumentName(getCompilationUnit().getJavaProject(), suggestedName, excludedNames); addLinkedPositionProposal(nameKey, favourite, null); addLinkedPositionProposal(nameKey, ((EditDescription)desc).orginalName, null); String[] suggestedNames= StubUtility.getArgumentNameSuggestions(getCompilationUnit().getJavaProject(), type, excludedNames); for (int k= 0; k < suggestedNames.length; k++) { addLinkedPositionProposal(nameKey, suggestedNames[k], null); for (int j= 0; j < names.length; j++) { names[j].setIdentifier(favourite); addLinkedPosition(rewrite.track(names[j]), false, nameKey); addLinkedPosition(rewrite.track(desc.resultingParamType), true, typeKey); addLinkedPositionProposal(typeKey, bindings[k]); if (tagArg != null) { tagArg.setIdentifier(favourite); addLinkedPosition(rewrite.track(tagArg), false, nameKey);
@Override protected ASTRewrite getRewrite() throws CoreException { CompilationUnit astRoot= (CompilationUnit) fInvocationNode.getRoot(); ASTNode methodDecl= astRoot.findDeclaringNode(fSenderBinding); ASTNode newMethodDecl= null; if (methodDecl != null) { newMethodDecl= methodDecl; } else { astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newMethodDecl= astRoot.findDeclaringNode(fSenderBinding.getKey()); } createImportRewrite(astRoot); if (newMethodDecl instanceof MethodDeclaration) { MethodDeclaration decl= (MethodDeclaration) newMethodDecl; ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST()); if (fParameterChanges != null) { modifyParameters(rewrite, decl); } if (fExceptionChanges != null) { modifyExceptions(rewrite, decl); } return rewrite; } return null; }
ImportRewrite imports= getImportRewrite(); ImportRewriteContext context= new ContextSensitiveImportRewriteContext(methodDecl, imports); ListRewrite listRewrite= rewrite.getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY); SimpleName arg= ast.newSimpleName("x"); //$NON-NLS-1$ newTagElement.fragments().add(arg); insertTabStop(rewrite, newTagElement.fragments(), "param_tagcomment" + i); //$NON-NLS-1$ insertParamTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), parameters, k, newTagElement); k++; TagElement tagNode= findParamTag(methodDecl, decl); if (tagNode != null) { rewrite.remove(tagNode, null); TagElement tagNode= findParamTag(methodDecl, decl); if (tagNode != null) { List<? extends ASTNode> fragments= tagNode.fragments(); k++; TagElement tagNode1= findParamTag(methodDecl, decl1); TagElement tagNode2= findParamTag(methodDecl, decl2); if (tagNode1 != null && tagNode2 != null) { rewrite.replace(tagNode1, rewrite.createCopyTarget(tagNode2), null); fixupNames(rewrite, usedNames);
Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION); ChangeMethodSignatureProposal proposal= new ChangeMethodSignatureProposal(label, cu, astRoot, binding, null, desc, IProposalRelevance.ADD_THROWS_DECLARATION, image); for (int i= 0; i < uncaughtExceptions.length; i++) { addExceptionTypeLinkProposals(proposal, uncaughtExceptions[i], proposal.getExceptionTypeGroupId(i + nExistingExceptions)); proposal.setCommandId(ADD_EXCEPTION_TO_THROWS_ID); proposals.add(proposal);
private void insertTabStop(ASTRewrite rewriter, List<ASTNode> fragments, String linkedName) { TextElement textElement= rewriter.getAST().newTextElement(); textElement.setText(""); //$NON-NLS-1$ fragments.add(textElement); addLinkedPosition(rewriter.track(textElement), false, linkedName); }
ImportRewrite imports= getImportRewrite(); ImportRewriteContext context= new ContextSensitiveImportRewriteContext(methodDecl, imports); ListRewrite listRewrite= rewrite.getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY); SimpleName arg= ast.newSimpleName("x"); //$NON-NLS-1$ newTagElement.fragments().add(arg); insertTabStop(rewrite, newTagElement.fragments(), "param_tagcomment" + i); //$NON-NLS-1$ insertParamTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), parameters, k, newTagElement); k++; TagElement tagNode= findParamTag(methodDecl, decl); if (tagNode != null) { rewrite.remove(tagNode, null); TagElement tagNode= findParamTag(methodDecl, decl); if (tagNode != null) { List<? extends ASTNode> fragments= tagNode.fragments(); k++; TagElement tagNode1= findParamTag(methodDecl, decl1); TagElement tagNode2= findParamTag(methodDecl, decl2); if (tagNode1 != null && tagNode2 != null) { rewrite.replace(tagNode1, rewrite.createCopyTarget(tagNode2), null); fixupNames(rewrite, usedNames);
@Override protected ASTRewrite getRewrite() throws CoreException { CompilationUnit astRoot= (CompilationUnit) fInvocationNode.getRoot(); ASTNode methodDecl= astRoot.findDeclaringNode(fSenderBinding); ASTNode newMethodDecl= null; if (methodDecl != null) { newMethodDecl= methodDecl; } else { astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newMethodDecl= astRoot.findDeclaringNode(fSenderBinding.getKey()); } createImportRewrite(astRoot); if (newMethodDecl instanceof MethodDeclaration) { MethodDeclaration decl= (MethodDeclaration) newMethodDecl; ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST()); if (fParameterChanges != null) { modifyParameters(rewrite, decl); } if (fExceptionChanges != null) { modifyExceptions(rewrite, decl); } return rewrite; } return null; }
Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION); ChangeMethodSignatureProposal proposal= new ChangeMethodSignatureProposal(label, cu, astRoot, binding, null, desc, IProposalRelevance.ADD_THROWS_DECLARATION, image); for (int i= 0; i < uncaughtExceptions.length; i++) { addExceptionTypeLinkProposals(proposal, uncaughtExceptions[i], proposal.getExceptionTypeGroupId(i + nExistingExceptions)); proposal.setCommandId(ADD_EXCEPTION_TO_THROWS_ID); proposals.add(proposal);
private void insertTabStop(ASTRewrite rewriter, List<ASTNode> fragments, String linkedName) { TextElement textElement= rewriter.getAST().newTextElement(); textElement.setText(""); //$NON-NLS-1$ fragments.add(textElement); addLinkedPosition(rewriter.track(textElement), false, linkedName); }
ImportRewrite imports= getImportRewrite(); ImportRewriteContext context= new ContextSensitiveImportRewriteContext(methodDecl, imports); ListRewrite listRewrite= rewrite.getListRewrite(methodDecl, MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY); String key= getExceptionTypeGroupId(i); addLinkedPosition(rewrite.track(newNode), false, key); ASTNode newRef= ASTNodeFactory.newName(ast, type); newTagElement.fragments().add(newRef); insertTabStop(rewrite, newTagElement.fragments(), "throws_tagcomment" + i); //$NON-NLS-1$ insertThrowsTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), exceptions, k, newTagElement); addLinkedPosition(rewrite.track(newRef), false, key); TagElement tagNode= findThrowsTag(methodDecl, node); if (tagNode != null) { rewrite.remove(tagNode, null); String key= getExceptionTypeGroupId(i); addLinkedPosition(rewrite.track(newNode), false, key); TagElement tagNode= findThrowsTag(methodDecl, oldNode); if (tagNode != null) { ASTNode newRef= ASTNodeFactory.newType(ast, type); rewrite.replace((ASTNode) tagNode.fragments().get(0), newRef, null); addLinkedPosition(rewrite.track(newRef), false, key); TagElement tagNode1= findThrowsTag(methodDecl, decl1); TagElement tagNode2= findThrowsTag(methodDecl, decl2);
ModifyDescription desc= (ModifyDescription) curr; String typeKey= getParamTypeGroupId(i); String nameKey= getParamNameGroupId(i); favourite= StubUtility.suggestArgumentName(getCompilationUnit().getJavaProject(), suggestedName, excludedNames); addLinkedPositionProposal(nameKey, favourite, null); addLinkedPositionProposal(nameKey, ((EditDescription)desc).orginalName, null); String[] suggestedNames= StubUtility.getArgumentNameSuggestions(getCompilationUnit().getJavaProject(), type, excludedNames); for (int k= 0; k < suggestedNames.length; k++) { addLinkedPositionProposal(nameKey, suggestedNames[k], null); for (int j= 0; j < names.length; j++) { names[j].setIdentifier(favourite); addLinkedPosition(rewrite.track(names[j]), false, nameKey); addLinkedPosition(rewrite.track(desc.resultingParamType), true, typeKey); addLinkedPositionProposal(typeKey, bindings[k]); if (tagArg != null) { tagArg.setIdentifier(favourite); addLinkedPosition(rewrite.track(tagArg), false, nameKey);
public static void addUnnecessaryThrownExceptionProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); selectedNode= ASTNodes.getNormalizedNode(selectedNode); if (selectedNode == null || selectedNode.getLocationInParent() != MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) { return; } MethodDeclaration decl= (MethodDeclaration) selectedNode.getParent(); IMethodBinding binding= decl.resolveBinding(); if (binding != null) { List<Type> thrownExceptions= decl.thrownExceptionTypes(); int index= thrownExceptions.indexOf(selectedNode); if (index == -1) { return; } ChangeDescription[] desc= new ChangeDescription[thrownExceptions.size()]; desc[index]= new RemoveDescription(); ICompilationUnit cu= context.getCompilationUnit(); String label= CorrectionMessages.LocalCorrectionsSubProcessor_unnecessarythrow_description; Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION); proposals.add(new ChangeMethodSignatureProposal(label, cu, selectedNode, binding, null, desc, IProposalRelevance.UNNECESSARY_THROW, image)); } JavadocTagsSubProcessor.getUnusedAndUndocumentedParameterOrExceptionProposals(context, problem, proposals); }
proposals.add(new ChangeMethodSignatureProposal(label, cu, astRoot, methodDeclBinding, null, changes, IProposalRelevance.REMOVE_EXCEPTIONS, image)); String label= Messages.format(CorrectionMessages.TypeMismatchSubProcessor_addexceptions_description, args); Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD); proposals.add(new ChangeMethodSignatureProposal(label, targetCu, astRoot, overriddenDecl, null, changes, IProposalRelevance.ADD_EXCEPTIONS, image));
proposals.add(new ChangeMethodSignatureProposal(label, cu, astRoot, methodDeclBinding, null, changes, IProposalRelevance.REMOVE_EXCEPTIONS, image)); String label= Messages.format(CorrectionMessages.TypeMismatchSubProcessor_addexceptions_description, args); Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD); proposals.add(new ChangeMethodSignatureProposal(label, targetCu, astRoot, overriddenDecl, null, changes, IProposalRelevance.ADD_EXCEPTIONS, image));
ChangeMethodSignatureProposal proposal= new ChangeMethodSignatureProposal(label, targetCU, invocationNode, methodDecl, changeDesc, null, IProposalRelevance.CHANGE_METHOD_ADD_PARAMETER, image); proposals.add(proposal);
ChangeMethodSignatureProposal proposal= new ChangeMethodSignatureProposal(label, targetCU, invocationNode, methodDecl, changeDesc, null, IProposalRelevance.CHANGE_METHOD_REMOVE_PARAMETER, image); proposals.add(proposal);
ChangeMethodSignatureProposal proposal= new ChangeMethodSignatureProposal(label, targetCU, invocationNode, methodDecl, changeDesc, null, IProposalRelevance.CHANGE_METHOD_ADD_PARAMETER, image); proposals.add(proposal);
ChangeMethodSignatureProposal proposal= new ChangeMethodSignatureProposal(label, targetCU, invocationNode, methodDecl, changeDesc, null, IProposalRelevance.CHANGE_METHOD_REMOVE_PARAMETER, image); proposals.add(proposal);