public static void getArrayAccessProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { CompilationUnit root= context.getASTRoot(); ASTNode selectedNode= problem.getCoveringNode(root); if (!(selectedNode instanceof MethodInvocation)) { return; } MethodInvocation decl= (MethodInvocation) selectedNode; SimpleName nameNode= decl.getName(); String methodName= nameNode.getIdentifier(); IBinding[] bindings= (new ScopeAnalyzer(root)).getDeclarationsInScope(nameNode, ScopeAnalyzer.METHODS); for (int i= 0; i < bindings.length; i++) { String currName= bindings[i].getName(); if (NameMatcher.isSimilarName(methodName, currName)) { String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_arraychangetomethod_description, BasicElementLabels.getJavaElementName(currName)); proposals.add(new RenameNodeCorrectionProposal(label, context.getCompilationUnit(), nameNode.getStartPosition(), nameNode.getLength(), currName, IProposalRelevance.ARRAY_CHANGE_TO_METHOD)); } } // always suggest 'length' String lengthId= "length"; //$NON-NLS-1$ String label= CorrectionMessages.UnresolvedElementsSubProcessor_arraychangetolength_description; int offset= nameNode.getStartPosition(); int length= decl.getStartPosition() + decl.getLength() - offset; proposals.add(new RenameNodeCorrectionProposal(label, context.getCompilationUnit(), offset, length, lengthId, IProposalRelevance.ARRAY_CHANGE_TO_LENGTH)); }
@Override protected void addEdits(IDocument doc, TextEdit root) throws CoreException { super.addEdits(doc, root); // build a full AST CompilationUnit unit= SharedASTProvider.getAST(getCompilationUnit(), SharedASTProvider.WAIT_YES, null); ASTNode name= NodeFinder.perform(unit, fOffset, fLength); if (name instanceof SimpleName) { SimpleName[] names= LinkedNodeFinder.findByProblems(unit, (SimpleName) name); if (names != null) { for (int i= 0; i < names.length; i++) { SimpleName curr= names[i]; root.addChild(new ReplaceEdit(curr.getStartPosition(), curr.getLength(), fNewName)); } return; } } root.addChild(new ReplaceEdit(fOffset, fLength, fNewName)); } }
public static void getArrayAccessProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { CompilationUnit root= context.getASTRoot(); ASTNode selectedNode= problem.getCoveringNode(root); if (!(selectedNode instanceof MethodInvocation)) { return; } MethodInvocation decl= (MethodInvocation) selectedNode; SimpleName nameNode= decl.getName(); String methodName= nameNode.getIdentifier(); IBinding[] bindings= (new ScopeAnalyzer(root)).getDeclarationsInScope(nameNode, ScopeAnalyzer.METHODS); for (int i= 0; i < bindings.length; i++) { String currName= bindings[i].getName(); if (NameMatcher.isSimilarName(methodName, currName)) { String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_arraychangetomethod_description, BasicElementLabels.getJavaElementName(currName)); proposals.add(new RenameNodeCorrectionProposal(label, context.getCompilationUnit(), nameNode.getStartPosition(), nameNode.getLength(), currName, IProposalRelevance.ARRAY_CHANGE_TO_METHOD)); } } // always suggest 'length' String lengthId= "length"; //$NON-NLS-1$ String label= CorrectionMessages.UnresolvedElementsSubProcessor_arraychangetolength_description; int offset= nameNode.getStartPosition(); int length= decl.getStartPosition() + decl.getLength() - offset; proposals.add(new RenameNodeCorrectionProposal(label, context.getCompilationUnit(), offset, length, lengthId, IProposalRelevance.ARRAY_CHANGE_TO_LENGTH)); }
@Override protected void addEdits(IDocument doc, TextEdit root) throws CoreException { super.addEdits(doc, root); // build a full AST CompilationUnit unit= SharedASTProviderCore.getAST(getCompilationUnit(), SharedASTProviderCore.WAIT_YES, null); ASTNode name= NodeFinder.perform(unit, fOffset, fLength); if (name instanceof SimpleName) { SimpleName[] names= LinkedNodeFinder.findByProblems(unit, (SimpleName) name); if (names != null) { for (int i= 0; i < names.length; i++) { SimpleName curr= names[i]; root.addChild(new ReplaceEdit(curr.getStartPosition(), curr.getLength(), fNewName)); } return; } } root.addChild(new ReplaceEdit(fOffset, fLength, fNewName)); } }
if (!curr.equals(methodName) && binding.getParameterTypes().length == nArguments && NameMatcher.isSimilarName(methodName, curr) && suggestedRenames.add(curr)) { String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changemethod_description, BasicElementLabels.getJavaElementName(curr)); proposals.add(new RenameNodeCorrectionProposal(label, context.getCompilationUnit(), problem.getOffset(), problem.getLength(), curr, IProposalRelevance.CHANGE_METHOD));
if (!curr.equals(methodName) && binding.getParameterTypes().length == nArguments && NameMatcher.isSimilarName(methodName, curr) && suggestedRenames.add(curr)) { String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changemethod_description, BasicElementLabels.getJavaElementName(curr)); proposals.add(new RenameNodeCorrectionProposal(label, context.getCompilationUnit(), problem.getOffset(), problem.getLength(), curr, IProposalRelevance.CHANGE_METHOD));
newProposals.add(new RenameNodeCorrectionProposal(label, cu, node.getStartPosition(), node.getLength(), currName, relevance)); String idLength= "length"; //$NON-NLS-1$ String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changevariable_description, idLength); proposals.add(new RenameNodeCorrectionProposal(label, cu, node.getStartPosition(), node.getLength(), idLength, IProposalRelevance.CHANGE_VARIABLE));
newProposals.add(new RenameNodeCorrectionProposal(label, cu, node.getStartPosition(), node.getLength(), currName, relevance)); String idLength= "length"; //$NON-NLS-1$ String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changevariable_description, idLength); proposals.add(new RenameNodeCorrectionProposal(label, cu, node.getStartPosition(), node.getLength(), idLength, IProposalRelevance.CHANGE_VARIABLE));
int relevance= NameMatcher.isSimilarName(memberName, curr) ? IProposalRelevance.CHANGE_TO_ATTRIBUTE_SIMILAR_NAME : IProposalRelevance.CHANGE_TO_ATTRIBUTE; String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_UnresolvedElementsSubProcessor_changetoattribute_description, BasicElementLabels.getJavaElementName(curr)); proposals.add(new RenameNodeCorrectionProposal(label, cu, problem.getOffset(), problem.getLength(), curr, relevance));
int relevance= NameMatcher.isSimilarName(memberName, curr) ? IProposalRelevance.CHANGE_TO_ATTRIBUTE_SIMILAR_NAME : IProposalRelevance.CHANGE_TO_ATTRIBUTE; String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_UnresolvedElementsSubProcessor_changetoattribute_description, BasicElementLabels.getJavaElementName(curr)); proposals.add(new RenameNodeCorrectionProposal(label, cu, problem.getOffset(), problem.getLength(), curr, relevance));