@Override public boolean visit(MethodInvocation mi) { if (mi.getName().getIdentifier().equals("getLogger") && mi.arguments().size() == 1 && AstUtils.tryGetConcreteType(cu) != null) { Object firstArg = mi.arguments().get(0); if (firstArg instanceof TypeLiteral) { String typeName = ((TypeLiteral) firstArg).getType().toString(); if (!typeName.equals(AstUtils.tryGetConcreteType(cu).getName().getIdentifier())) { addHit(mi); // Print out problem locations [line, path] System.out.printf("Line %d in %s\n", cu.getLineNumber(mi.getStartPosition()), file.getPath()); } } } return true; } });
public void setPositionFinder(String methodName) throws JavaModelException { //findMethod(methodName); IType type = this.javaProject.findType(this.className); ICompilationUnit unit = type.getCompilationUnit(); ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(unit); parser.setResolveBindings(true); CompilationUnit cunit = (CompilationUnit) parser.createAST(null); //ASTNode root = parser.createAST(null); final String name = this.newMethodName; cunit.accept(new ASTVisitor() { public boolean visit(MethodInvocation methodInvocation) { String methodName = methodInvocation.getName().toString(); System.out.println(methodName); if (methodName.equals(name)) { startPosition = methodInvocation.getStartPosition(); length = methodInvocation.getLength(); System.out.printf("startPosition %d - Length %d", startPosition, length); } return false; } }); }
@Override public boolean visit(MethodInvocation mi) { if (mi.getName().getIdentifier().equals("debug") && mi.getExpression() instanceof SimpleName && mi.getExpression().toString().contains("log")) { Object firstArg = mi.arguments().get(0); if (firstArg instanceof StringLiteral || firstArg instanceof SimpleName) { return true; // Simple call without computation is unnecessary to report } Statement st = FindUpper.statement(mi); IfStatement ifs = null; if (st.getParent() instanceof IfStatement) { ifs = (IfStatement) st.getParent(); } else if (st.getParent().getParent() instanceof IfStatement) { ifs = (IfStatement) st.getParent().getParent(); } if (ifs == null || !ifs.getExpression().toString().contains(".isDebugEnabled(")) { addHit(mi); // Print out problem locations [line, path] System.out.printf("Line %d in %s\n", cu.getLineNumber(mi.getStartPosition()), file.getPath()); } } return true; } };
ASTNode clone0(AST target) { MethodInvocation result = new MethodInvocation(target); result.setSourceRange(getStartPosition(), getLength()); result.setName((SimpleName) getName().clone(target)); result.setExpression( (Expression) ASTNode.copySubtree(target, getExpression())); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments())); } result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); return result; }
ASTNode clone0(AST target) { MethodInvocation result = new MethodInvocation(target); result.setSourceRange(getStartPosition(), getLength()); result.setName((SimpleName) getName().clone(target)); result.setExpression( (Expression) ASTNode.copySubtree(target, getExpression())); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments())); } result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); return result; }
@Override ASTNode clone0(AST target) { MethodInvocation result = new MethodInvocation(target); result.setSourceRange(getStartPosition(), getLength()); result.setName((SimpleName) getName().clone(target)); result.setExpression( (Expression) ASTNode.copySubtree(target, getExpression())); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments())); } result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); return result; }
ASTNode clone0(AST target) { MethodInvocation result = new MethodInvocation(target); result.setSourceRange(getStartPosition(), getLength()); result.setName((SimpleName) getName().clone(target)); result.setExpression( (Expression) ASTNode.copySubtree(target, getExpression())); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments())); } result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); return result; }
ASTNode clone0(AST target) { MethodInvocation result = new MethodInvocation(target); result.setSourceRange(getStartPosition(), getLength()); result.setName((SimpleName) getName().clone(target)); result.setExpression( (Expression) ASTNode.copySubtree(target, getExpression())); if (this.ast.apiLevel >= AST.JLS3) { result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments())); } result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); return result; }
ASTNode clone0(AST target) { MethodInvocation result = new MethodInvocation(target); result.setSourceRange(getStartPosition(), getLength()); result.setName((SimpleName) getName().clone(target)); result.setExpression( (Expression) ASTNode.copySubtree(target, getExpression())); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments())); } result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); return result; }
public static void getArrayAccessProposals(IInvocationContext context, IProblemLocation problem, Collection 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, currName); proposals.add(new RenameNodeCompletionProposal(label, context.getCompilationUnit(), nameNode.getStartPosition(), nameNode.getLength(), currName, 6)); } } // 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 RenameNodeCompletionProposal(label, context.getCompilationUnit(), offset, length, lengthId, 7)); }
public static void getArrayAccessProposals(IInvocationContext context, IProblemLocation problem, Collection 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, currName); proposals.add(new RenameNodeCompletionProposal(label, context.getCompilationUnit(), nameNode.getStartPosition(), nameNode.getLength(), currName, 6)); } } // 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 RenameNodeCompletionProposal(label, context.getCompilationUnit(), offset, length, lengthId, 7)); }
public static void getArrayAccessProposals(IInvocationContext context, IProblemLocationCore problem, Collection<CUCorrectionProposal> 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)); }
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)); }
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)); }
public boolean visit(MethodInvocation node) { if (!hasChildrenChanges(node)) { return doVisitUnchangedChildren(node); } int pos= rewriteOptionalQualifier(node, MethodInvocation.EXPRESSION_PROPERTY, node.getStartPosition()); if (node.getAST().apiLevel() >= JLS3_INTERNAL) { pos= rewriteOptionalTypeParameters(node, MethodInvocation.TYPE_ARGUMENTS_PROPERTY, pos, Util.EMPTY_STRING, false, false); } pos= rewriteRequiredNode(node, MethodInvocation.NAME_PROPERTY); if (isChanged(node, MethodInvocation.ARGUMENTS_PROPERTY)) { // eval position after opening parent try { int startOffset= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLPAREN, pos); rewriteNodeList(node, MethodInvocation.ARGUMENTS_PROPERTY, startOffset, Util.EMPTY_STRING, ", "); //$NON-NLS-1$ } catch (CoreException e) { handleException(e); } } else { voidVisit(node, MethodInvocation.ARGUMENTS_PROPERTY); } return false; }
@Override public boolean visit(MethodInvocation node) { if (!hasChildrenChanges(node)) { return doVisitUnchangedChildren(node); } int pos= rewriteOptionalQualifier(node, MethodInvocation.EXPRESSION_PROPERTY, node.getStartPosition()); if (node.getAST().apiLevel() >= JLS3_INTERNAL) { pos= rewriteOptionalTypeParameters(node, MethodInvocation.TYPE_ARGUMENTS_PROPERTY, pos, Util.EMPTY_STRING, false, false); } pos= rewriteRequiredNode(node, MethodInvocation.NAME_PROPERTY); if (isChanged(node, MethodInvocation.ARGUMENTS_PROPERTY)) { // eval position after opening parent try { int startOffset= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLPAREN, pos); rewriteNodeList(node, MethodInvocation.ARGUMENTS_PROPERTY, startOffset, Util.EMPTY_STRING, ", "); //$NON-NLS-1$ } catch (CoreException e) { handleException(e); } } else { voidVisit(node, MethodInvocation.ARGUMENTS_PROPERTY); } return false; }
public boolean visit(MethodInvocation node) { if (!hasChildrenChanges(node)) { return doVisitUnchangedChildren(node); } int pos= rewriteOptionalQualifier(node, MethodInvocation.EXPRESSION_PROPERTY, node.getStartPosition()); if (node.getAST().apiLevel() >= JLS3_INTERNAL) { pos= rewriteOptionalTypeParameters(node, MethodInvocation.TYPE_ARGUMENTS_PROPERTY, pos, Util.EMPTY_STRING, false, false); } pos= rewriteRequiredNode(node, MethodInvocation.NAME_PROPERTY); if (isChanged(node, MethodInvocation.ARGUMENTS_PROPERTY)) { // eval position after opening parent try { int startOffset= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLPAREN, pos); rewriteNodeList(node, MethodInvocation.ARGUMENTS_PROPERTY, startOffset, Util.EMPTY_STRING, ", "); //$NON-NLS-1$ } catch (CoreException e) { handleException(e); } } else { voidVisit(node, MethodInvocation.ARGUMENTS_PROPERTY); } return false; }
public boolean visit(MethodInvocation node) { if (!hasChildrenChanges(node)) { return doVisitUnchangedChildren(node); } int pos= rewriteOptionalQualifier(node, MethodInvocation.EXPRESSION_PROPERTY, node.getStartPosition()); if (node.getAST().apiLevel() >= JLS3_INTERNAL) { pos= rewriteOptionalTypeParameters(node, MethodInvocation.TYPE_ARGUMENTS_PROPERTY, pos, Util.EMPTY_STRING, false, false); } pos= rewriteRequiredNode(node, MethodInvocation.NAME_PROPERTY); if (isChanged(node, MethodInvocation.ARGUMENTS_PROPERTY)) { // eval position after opening parent try { int startOffset= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLPAREN, pos); rewriteNodeList(node, MethodInvocation.ARGUMENTS_PROPERTY, startOffset, Util.EMPTY_STRING, ", "); //$NON-NLS-1$ } catch (CoreException e) { handleException(e); } } else { voidVisit(node, MethodInvocation.ARGUMENTS_PROPERTY); } return false; }
public boolean visit(MethodInvocation node) { if (!hasChildrenChanges(node)) { return doVisitUnchangedChildren(node); } int pos= rewriteOptionalQualifier(node, MethodInvocation.EXPRESSION_PROPERTY, node.getStartPosition()); if (node.getAST().apiLevel() >= JLS3_INTERNAL) { pos= rewriteOptionalTypeParameters(node, MethodInvocation.TYPE_ARGUMENTS_PROPERTY, pos, Util.EMPTY_STRING, false, false); } pos= rewriteRequiredNode(node, MethodInvocation.NAME_PROPERTY); if (isChanged(node, MethodInvocation.ARGUMENTS_PROPERTY)) { // eval position after opening parent try { int startOffset= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLPAREN, pos); rewriteNodeList(node, MethodInvocation.ARGUMENTS_PROPERTY, startOffset, Util.EMPTY_STRING, ", "); //$NON-NLS-1$ } catch (CoreException e) { handleException(e); } } else { voidVisit(node, MethodInvocation.ARGUMENTS_PROPERTY); } return false; }
public boolean visit(MethodInvocation node) { if (!hasChildrenChanges(node)) { return doVisitUnchangedChildren(node); } int pos= rewriteOptionalQualifier(node, MethodInvocation.EXPRESSION_PROPERTY, node.getStartPosition()); if (node.getAST().apiLevel() >= AST.JLS3) { pos= rewriteOptionalTypeParameters(node, MethodInvocation.TYPE_ARGUMENTS_PROPERTY, pos, "", false, false); //$NON-NLS-1$ } pos= rewriteRequiredNode(node, MethodInvocation.NAME_PROPERTY); if (isChanged(node, MethodInvocation.ARGUMENTS_PROPERTY)) { // eval position after opening parent try { int startOffset= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLPAREN, pos); rewriteNodeList(node, MethodInvocation.ARGUMENTS_PROPERTY, startOffset, "", ", "); //$NON-NLS-1$ //$NON-NLS-2$ } catch (CoreException e) { handleException(e); } } else { voidVisit(node, MethodInvocation.ARGUMENTS_PROPERTY); } return false; }