@Override public boolean visit(SimpleName node) { VariableDeclaration decl = getVariableDeclaration(node); if (decl == null) return super.visit(node); IVariableBinding binding = decl.resolveBinding(); if (binding == null) return super.visit(node); boolean keysEqual = fKey.equals(binding.getKey()); boolean rangeInSet = fRanges.contains(new Region(node.getStartPosition(), node.getLength())); if (keysEqual && !rangeInSet) fProblemNodes.add(node); if (!keysEqual && rangeInSet) fProblemNodes.add(node); /* * if (!keyEquals && !rangeInSet) * ok, different local variable. * * if (keyEquals && rangeInSet) * ok, renamed local variable & has been renamed. */ return super.visit(node); }
/** {@inheritDoc} */ public boolean visit(SingleVariableDeclaration node) { SimpleName name = node.getName(); IBinding binding = name.resolveBinding(); if (!(binding instanceof IVariableBinding)) return false; IVariableBinding varBinding = (IVariableBinding) binding; if (fWrittenVariables.containsKey(varBinding)) return false; if (fAddFinalParameters && fAddFinalLocals) { ModifierChangeOperation op = createAddFinalOperation(name, node); if (op == null) return false; fResult.add(op); return false; } else if (fAddFinalParameters) { if (!varBinding.isParameter()) return false; ModifierChangeOperation op = createAddFinalOperation(name, node); if (op == null) return false; fResult.add(op); return false; } else if (fAddFinalLocals) { if (varBinding.isParameter()) return false; ModifierChangeOperation op = createAddFinalOperation(name, node); if (op == null) return false; fResult.add(op); return false; } return false; }
private ASTRewrite doAddEnumConst(CompilationUnit astRoot) { SimpleName node = fOriginalNode; ASTNode newTypeDecl = astRoot.findDeclaringNode(fSenderBinding); if (newTypeDecl == null) { astRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null); newTypeDecl = astRoot.findDeclaringNode(fSenderBinding.getKey()); } if (newTypeDecl != null) { AST ast = newTypeDecl.getAST(); ASTRewrite rewrite = ASTRewrite.create(ast); EnumConstantDeclaration constDecl = ast.newEnumConstantDeclaration(); constDecl.setName(ast.newSimpleName(node.getIdentifier())); ListRewrite listRewriter = rewrite.getListRewrite(newTypeDecl, EnumDeclaration.ENUM_CONSTANTS_PROPERTY); listRewriter.insertLast(constDecl, null); addLinkedPosition(rewrite.track(constDecl.getName()), false, KEY_NAME); return rewrite; } return null; }
public static MarkerAnnotation createValAnnotation( AST ast, Annotation original, int start, int end) { MarkerAnnotation out = null; try { out = Reflection.markerAnnotationConstructor.newInstance(ast); } catch (InstantiationException e) { throw Lombok.sneakyThrow(e); } catch (IllegalAccessException e) { throw Lombok.sneakyThrow(e); } catch (InvocationTargetException e) { throw Lombok.sneakyThrow(e); } if (out != null) { SimpleName valName = ast.newSimpleName("val"); valName.setSourceRange(start, end - start + 1); if (original.type instanceof SingleTypeReference) { out.setTypeName(valName); setIndex(valName, 1); } else { SimpleName lombokName = ast.newSimpleName("lombok"); lombokName.setSourceRange(start, end - start + 1); setIndex(lombokName, 1); setIndex(valName, 2); QualifiedName fullName = ast.newQualifiedName(lombokName, valName); setIndex(fullName, 1); fullName.setSourceRange(start, end - start + 1); out.setTypeName(fullName); } out.setSourceRange(start, end - start + 1); } return out; }
/** * A type has been entered - update the type being visited. * * @param name name from type node */ private void enterType(SimpleName name) { if (fType == null) { fType = fPackage.getType(name.getFullyQualifiedName()); } else { fType = fType.getType(name.getFullyQualifiedName()); } }
@Override public void indexVarUsage( final Document document, final MethodDeclaration method, final SimpleName name) { final SimpleName[] linkedNodes = LinkedNodeFinder.findByNode(method, name); for (final SimpleName linkedName : linkedNodes) { if (linkedName.getParent() != null) { switch (linkedName.getParent().getNodeType()) { case ASTNode.METHOD_INVOCATION: final MethodInvocation targetMethod = (MethodInvocation) linkedName.getParent(); if (targetMethod.arguments().size() == 0 || targetMethod.arguments().indexOf(linkedName) == -1) { /* * The idea is that when the the parent node of a simple name is a method invocation and the * simple name is not in the parameter list then it must be the target of the invocation. */ final Optional<String> opt = BindingHelper.getIdentifier(targetMethod); if (opt.isPresent()) { CodeIndexer.addFieldToDocument( document, Fields.USED_AS_TAGET_FOR_METHODS, opt.get()); } break; } } } } }
private MethodDecl getMethodDecl(MethodDeclaration node) { String qualifiedTypeName = currentPackage + "." + Joiner.on(".").skipNulls().join(typesInFile); SimpleName nameNode = node.getName(); String methodName = nameNode.toString(); String returnType = ""; if (node.getReturnType2() != null) { returnType = getNameOfType(node.getReturnType2()); } Map<String, String> params = new HashMap<>(); for (Object p : node.parameters()) { String typeName = OBJECT_TYPE; if (p instanceof SingleVariableDeclaration) { SingleVariableDeclaration svd = (SingleVariableDeclaration) p; String varName = svd.getName().toString(); Type type = svd.getType(); typeName = getNameOfType(type); params.put(varName, typeName); } else { System.err.println("Unxepected AST node type for param - " + p); } } return new MethodDecl( methodName, qualifiedTypeName, returnType, nameNode.getStartPosition(), params); }
private boolean isInRemoved(SimpleName ref, int[] removedStartsEnds) { int start = ref.getStartPosition(); int end = start + ref.getLength(); for (int index = 0; index < removedStartsEnds.length; index += 2) { if (start >= removedStartsEnds[index] && end <= removedStartsEnds[index + 1]) return true; } return false; }
private ASTRewrite doAddParam(CompilationUnit cu) { AST ast = cu.getAST(); SimpleName node = fOriginalNode; BodyDeclaration decl = ASTResolving.findParentBodyDeclaration(node); if (decl instanceof MethodDeclaration) { MethodDeclaration methodDeclaration = (MethodDeclaration) decl; ASTRewrite rewrite = ASTRewrite.create(ast); ImportRewrite imports = createImportRewrite((CompilationUnit) decl.getRoot()); ImportRewriteContext importRewriteContext = new ContextSensitiveImportRewriteContext(decl, imports); SingleVariableDeclaration newDecl = ast.newSingleVariableDeclaration(); newDecl.setType( evaluateVariableType( ast, imports, importRewriteContext, methodDeclaration.resolveBinding())); newDecl.setName(ast.newSimpleName(node.getIdentifier())); ListRewrite listRewriter = rewrite.getListRewrite(decl, MethodDeclaration.PARAMETERS_PROPERTY); listRewriter.insertLast(newDecl, null); addLinkedPosition(rewrite.track(node), true, KEY_NAME); // add javadoc tag Javadoc javadoc = methodDeclaration.getJavadoc(); if (javadoc != null) { HashSet<String> leadingNames = new HashSet<String>(); for (Iterator<SingleVariableDeclaration> iter = methodDeclaration.parameters().iterator(); iter.hasNext(); ) { SingleVariableDeclaration curr = iter.next(); leadingNames.add(curr.getName().getIdentifier()); } SimpleName newTagRef = ast.newSimpleName(node.getIdentifier()); TagElement newTagElement = ast.newTagElement(); newTagElement.setTagName(TagElement.TAG_PARAM); newTagElement.fragments().add(newTagRef); TextElement commentStart = ast.newTextElement(); newTagElement.fragments().add(commentStart); addLinkedPosition(rewrite.track(newTagRef), false, KEY_NAME); addLinkedPosition(rewrite.track(commentStart), false, "comment_start"); // $NON-NLS-1$ ListRewrite tagsRewriter = rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY); JavadocTagsSubProcessor.insertTag(tagsRewriter, newTagElement, leadingNames); } addLinkedPosition(rewrite.track(newDecl.getType()), false, KEY_TYPE); addLinkedPosition(rewrite.track(newDecl.getName()), false, KEY_NAME); return rewrite; } return null; }
private HashMap getPotentialRemoves(List removedRefs) { HashMap /* <String, IBinding> */ potentialRemoves = new HashMap(); for (Iterator iterator = removedRefs.iterator(); iterator.hasNext(); ) { SimpleName name = (SimpleName) iterator.next(); if (fAddedImports.contains(name.getIdentifier()) || hasAddedStaticImport(name)) continue; IBinding binding = name.resolveBinding(); if (binding != null) potentialRemoves.put(name.getIdentifier(), binding); } return potentialRemoves; }
/** * add binding to current scope * * @param node * @param name * @param fullTypeName */ private int addBinding(final ASTNode node, final SimpleName name, final String fullTypeName) { final int bindingId = nextVarId; nextVarId++; nodeScopes.get(node).put(name.getIdentifier(), bindingId); nodeScopes.get(node.getParent()).put(name.getIdentifier(), bindingId); variableBinding.put(bindingId, Lists.<ASTNode>newArrayList()); variableTypes.put(bindingId, fullTypeName); // Put the node reference in too (to know diff instances of same type) // Put the node reference name in too (to know diff instances of same type) variableDeclarationBinding.put(bindingId, name); return bindingId; }
private Statement createInnerConstructorInvocation(MethodDeclaration m) { ConstructorInvocation invocation = m.getAST().newConstructorInvocation(); Types.addBinding(invocation, Types.getBinding(m)); for (SingleVariableDeclaration param : ASTUtil.getParameters(m)) { SimpleName paramName = param.getName(); IVariableBinding paramBinding = Types.getVariableBinding(paramName); SimpleName argName = m.getAST().newSimpleName(paramName.getIdentifier()); Types.addBinding(argName, paramBinding); ASTUtil.getArguments(invocation).add(argName); } return invocation; }
private Type evaluateVariableType( AST ast, ImportRewrite imports, ImportRewriteContext importRewriteContext, IBinding targetContext) { if (fOriginalNode.getParent() instanceof MethodInvocation) { MethodInvocation parent = (MethodInvocation) fOriginalNode.getParent(); if (parent.getExpression() == fOriginalNode) { // _x_.foo() -> guess qualifier type by looking for a type with method 'foo' ITypeBinding[] bindings = ASTResolving.getQualifierGuess( fOriginalNode.getRoot(), parent.getName().getIdentifier(), parent.arguments(), targetContext); if (bindings.length > 0) { for (int i = 0; i < bindings.length; i++) { addLinkedPositionProposal(KEY_TYPE, bindings[i]); } return imports.addImport(bindings[0], ast, importRewriteContext); } } } ITypeBinding binding = ASTResolving.guessBindingForReference(fOriginalNode); if (binding != null) { if (binding.isWildcardType()) { binding = ASTResolving.normalizeWildcardType(binding, isVariableAssigned(), ast); if (binding == null) { // only null binding applies binding = ast.resolveWellKnownType("java.lang.Object"); // $NON-NLS-1$ } } if (isVariableAssigned()) { ITypeBinding[] typeProposals = ASTResolving.getRelaxingTypes(ast, binding); for (int i = 0; i < typeProposals.length; i++) { addLinkedPositionProposal(KEY_TYPE, typeProposals[i]); } } return imports.addImport(binding, ast, importRewriteContext); } // no binding, find type AST node instead -> ABC a= x-> use 'ABC' as is Type type = ASTResolving.guessTypeForReference(ast, fOriginalNode); if (type != null) { return type; } if (fVariableKind == CONST_FIELD) { return ast.newSimpleType(ast.newSimpleName("String")); // $NON-NLS-1$ } return ast.newSimpleType(ast.newSimpleName("Object")); // $NON-NLS-1$ }
public boolean visit(SimpleName node) { if (node.getParent() instanceof VariableDeclaration) { if (((VariableDeclaration) node.getParent()).getName() == node) return true; // don't include declaration } if (fTempBinding != null && fTempBinding == node.resolveBinding()) { if (fIsInJavadoc) fJavadocNodes.add(node); else fReferenceNodes.add(node); } return true; }
/* * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SimpleName) */ public boolean visit(SimpleName node) { fToken.update(node); for (int i = 0, n = fJobSemanticHighlightings.length; i < n; i++) { SemanticHighlighting semanticHighlighting = fJobSemanticHighlightings[i]; if (fJobHighlightings[i].isEnabled() && semanticHighlighting.consumes(fToken)) { int offset = node.getStartPosition(); int length = node.getLength(); if (offset > -1 && length > 0) addPosition(offset, length, fJobHighlightings[i]); break; } } fToken.clear(); return false; }
/** {@inheritDoc} */ public boolean visit(VariableDeclarationFragment node) { SimpleName name = node.getName(); IBinding binding = name.resolveBinding(); if (binding == null) return true; if (fWrittenVariables.containsKey(binding)) return true; ModifierChangeOperation op = createAddFinalOperation(name, node); if (op == null) return true; fResult.add(op); return true; }
private void possibleStaticImportFound(Name name) { if (fStaticImports == null || fASTRoot == null) { return; } while (name.isQualifiedName()) { name = ((QualifiedName) name).getQualifier(); } if (!isAffected(name)) { return; } IBinding binding = name.resolveBinding(); SimpleName simpleName = (SimpleName) name; if (binding == null || binding instanceof ITypeBinding || !Modifier.isStatic(binding.getModifiers()) || simpleName.isDeclaration()) { return; } if (binding instanceof IVariableBinding) { IVariableBinding varBinding = (IVariableBinding) binding; if (varBinding.isField()) { varBinding = varBinding.getVariableDeclaration(); ITypeBinding declaringClass = varBinding.getDeclaringClass(); if (declaringClass != null && !declaringClass.isLocal()) { if (new ScopeAnalyzer(fASTRoot) .isDeclaredInScope( varBinding, simpleName, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY)) return; fStaticImports.add(simpleName); } } } else if (binding instanceof IMethodBinding) { IMethodBinding methodBinding = ((IMethodBinding) binding).getMethodDeclaration(); ITypeBinding declaringClass = methodBinding.getDeclaringClass(); if (declaringClass != null && !declaringClass.isLocal()) { if (new ScopeAnalyzer(fASTRoot) .isDeclaredInScope( methodBinding, simpleName, ScopeAnalyzer.METHODS | ScopeAnalyzer.CHECK_VISIBILITY)) return; fStaticImports.add(simpleName); } } }
public static void setIsGeneratedFlagForSimpleName(SimpleName name, Object internalNode) throws Exception { if (internalNode instanceof org.eclipse.jdt.internal.compiler.ast.ASTNode) { if (internalNode.getClass().getField("$generatedBy").get(internalNode) != null) { name.getClass().getField("$isGenerated").set(name, true); } } }
/** * Visits {@link SimpleName} AST nodes. Resolves the binding of the simple name and looks for it * in the {variableScope} map. If the binding is found, this is a reference to a variable. * * @param node the node to visit */ @Override public boolean visit(final SimpleName node) { if (node.getParent().getNodeType() == ASTNode.METHOD_INVOCATION) { final MethodInvocation invocation = (MethodInvocation) node.getParent(); if (invocation.getName() == node) { return true; } } // method declaration can have same name as variable but this does not mean it is binding to // that variable // added particularly for enum if (node.getParent().getNodeType() == ASTNode.METHOD_DECLARATION) { return true; } addBindingData(node.getIdentifier(), node, nodeScopes.get(node)); return true; }
/** * 中断接受节点 * * @param node : 函数调用 */ public void interruptAcceptNodeHandle(MethodInvocation node) { int lineNumber = compilationUnit.getLineNumber(node.getStartPosition()); Node interruptedNode = new Node(filePath, lineNumber); String threadKey; Expression expression = node.getExpression(); ITypeBinding iTypeBinding = castHelper.getResolveTypeBinding(expression); if (expression == null || iTypeBinding == null) { System.out.println(filePath); System.out.println(compilationUnit.getLineNumber(node.getStartPosition())); System.out.println("interrupt iTypeBinding error!"); return; } // 普通变量 if (expression instanceof SimpleName && ((SimpleName) expression).resolveBinding() != null) { SimpleName simpleName = (SimpleName) expression; if (castHelper.getDecNode(simpleName) == null) { return; } int decLineNumber = compilationUnit.getLineNumber(castHelper.getDecNode(simpleName).getStartPosition()); String varKey = filePath + "_" + decLineNumber + "_" + iTypeBinding.getName() + "_" + simpleName.getIdentifier(); System.out.println(varKey); if (threadVarHashMap.containsKey(varKey)) { threadKey = threadVarHashMap.get(varKey).getThreadInfoKey(); if (threadInfo.get(threadKey).getInterruptNodes() != null) { threadInfo.get(threadKey).getInterruptNodes().add(interruptedNode); } } else { System.out.println("ERROR: didn't contains the varKey"); } } // 其它调用 else if (((SimpleName) expression).resolveBinding() != null) { threadKey = iTypeBinding.getBinaryName(); if (threadInfo.get(threadKey).getInterruptNodes() != null) { threadInfo.get(threadKey).getInterruptNodes().add(interruptedNode); } } }
/** {@inheritDoc} */ public boolean visit(VariableDeclarationExpression node) { if (fAddFinalLocals && node.fragments().size() == 1) { SimpleName name = ((VariableDeclarationFragment) node.fragments().get(0)).getName(); IBinding binding = name.resolveBinding(); if (binding == null) return false; if (fWrittenVariables.containsKey(binding)) return false; ModifierChangeOperation op = createAddFinalOperation(name, node); if (op == null) return false; fResult.add(op); return false; } return false; }
@Override public boolean visit(final SimpleName visitedNode) { if (this.identifier.equals(visitedNode.getIdentifier())) { setResult(visitedNode); stopSearching(); } return VISIT_CHILDREN; }
private boolean isEnhancedForStatementVariable(Statement statement, SimpleName name) { if (statement instanceof EnhancedForStatement) { EnhancedForStatement forStatement = (EnhancedForStatement) statement; SingleVariableDeclaration param = forStatement.getParameter(); return param.getType() == name.getParent(); // strange recovery, see https://bugs.eclipse.org/180456 } return false; }
public IBinding[] getImportsToRemove() { ArrayList /* <SimpleName> */ importNames = new ArrayList(); ArrayList /* <SimpleName> */ staticNames = new ArrayList(); ImportReferencesCollector.collect(fRoot, fProject, null, importNames, staticNames); List /* <SimpleName> */ removedRefs = new ArrayList(); List /* <SimpleName> */ unremovedRefs = new ArrayList(); divideTypeRefs(importNames, staticNames, removedRefs, unremovedRefs); if (removedRefs.size() == 0) return new IBinding[0]; HashMap /* <String, IBinding> */ potentialRemoves = getPotentialRemoves(removedRefs); for (Iterator iterator = unremovedRefs.iterator(); iterator.hasNext(); ) { SimpleName name = (SimpleName) iterator.next(); potentialRemoves.remove(name.getIdentifier()); } Collection importsToRemove = potentialRemoves.values(); return (IBinding[]) importsToRemove.toArray(new IBinding[importsToRemove.size()]); }
/** * 中断通知节点 * * @param node :函数调用 * @param threadInterruptNode :中断节点类 */ public void interruptNotifyNodeHandle( MethodInvocation node, ThreadInterruptNode threadInterruptNode) { String threadKey; Expression expression = node.getExpression(); ITypeBinding iTypeBinding = castHelper.getResolveTypeBinding(expression); if (expression == null || iTypeBinding == null) { System.out.println(filePath); System.out.println(compilationUnit.getLineNumber(node.getStartPosition())); System.out.println("interrupt iTypeBinding error!"); return; } // 普通变量,从变量集中获取线程key if (expression instanceof SimpleName && ((SimpleName) expression).resolveBinding() != null) { SimpleName simpleName = (SimpleName) expression; int lineNumber = compilationUnit.getLineNumber(castHelper.getDecNode(simpleName).getStartPosition()); String varKey = filePath + "_" + lineNumber + "_" + iTypeBinding.getName() + "_" + simpleName.getIdentifier(); System.out.println(varKey); if (threadVarHashMap.containsKey(varKey)) { threadKey = threadVarHashMap.get(varKey).getThreadInfoKey(); threadInterruptNode.getThreadKeyList().add(threadKey); // 添加至中断通知节点集合 threadInterruptNodes.add(threadInterruptNode); } else { System.out.println("ERROR: didn't contains the varKey"); } } // 其它调用(函数返回值等):直接从返回值类型推断具体线程key else { threadKey = iTypeBinding.getBinaryName(); threadInterruptNode.getThreadKeyList().add(threadKey); } }
/** {@inheritDoc} */ public boolean visit(SimpleName node) { if (node.getParent() instanceof VariableDeclarationFragment) return super.visit(node); if (node.getParent() instanceof SingleVariableDeclaration) return super.visit(node); IBinding binding = node.resolveBinding(); if (!(binding instanceof IVariableBinding)) return super.visit(node); binding = ((IVariableBinding) binding).getVariableDeclaration(); if (ASTResolving.isWriteAccess(node)) { List list; if (fResult.containsKey(binding)) { list = (List) fResult.get(binding); } else { list = new ArrayList(); } list.add(node); fResult.put(binding, list); } return super.visit(node); }
/** Renames the main type in <code>cu</code>. */ private void updateTypeName( ICompilationUnit cu, CompilationUnit astCU, String oldName, String newName, ASTRewrite rewriter) throws JavaModelException { if (newName != null) { String oldTypeName = Util.getNameWithoutJavaLikeExtension(oldName); String newTypeName = Util.getNameWithoutJavaLikeExtension(newName); AST ast = astCU.getAST(); // update main type name IType[] types = cu.getTypes(); for (int i = 0, max = types.length; i < max; i++) { IType currentType = types[i]; if (currentType.getElementName().equals(oldTypeName)) { AbstractTypeDeclaration typeNode = (AbstractTypeDeclaration) ((JavaElement) currentType).findNode(astCU); if (typeNode != null) { // rename type rewriter.replace(typeNode.getName(), ast.newSimpleName(newTypeName), null); // rename constructors Iterator bodyDeclarations = typeNode.bodyDeclarations().iterator(); while (bodyDeclarations.hasNext()) { Object bodyDeclaration = bodyDeclarations.next(); if (bodyDeclaration instanceof MethodDeclaration) { MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration; if (methodDeclaration.isConstructor()) { SimpleName methodName = methodDeclaration.getName(); if (methodName.getIdentifier().equals(oldTypeName)) { rewriter.replace(methodName, ast.newSimpleName(newTypeName), null); } } } } } } } } }
/* * Must be one of: * <ul> * <li>[result].length</li> * </ul> */ private boolean validateLengthQuery(Expression lengthQuery) { if (lengthQuery instanceof QualifiedName) { QualifiedName qualifiedName = (QualifiedName) lengthQuery; SimpleName name = qualifiedName.getName(); if (!LENGTH_QUERY.equals(name.getIdentifier())) return false; Name arrayAccess = qualifiedName.getQualifier(); ITypeBinding accessType = arrayAccess.resolveTypeBinding(); if (accessType == null) return false; if (!accessType.isArray()) return false; IBinding arrayBinding = arrayAccess.resolveBinding(); if (arrayBinding == null) return false; fArrayBinding = arrayBinding; fArrayAccess = arrayAccess; return true; } else if (lengthQuery instanceof FieldAccess) { FieldAccess fieldAccess = (FieldAccess) lengthQuery; SimpleName name = fieldAccess.getName(); if (!LENGTH_QUERY.equals(name.getIdentifier())) return false; Expression arrayAccess = fieldAccess.getExpression(); ITypeBinding accessType = arrayAccess.resolveTypeBinding(); if (accessType == null) return false; if (!accessType.isArray()) return false; IBinding arrayBinding = getBinding(arrayAccess); if (arrayBinding == null) return false; fArrayBinding = arrayBinding; fArrayAccess = arrayAccess; return true; } return false; }
private boolean hasAddedStaticImport(SimpleName name) { IBinding binding = name.resolveBinding(); if (binding instanceof IVariableBinding) { IVariableBinding variable = (IVariableBinding) binding; return hasAddedStaticImport( variable.getDeclaringClass().getQualifiedName(), variable.getName(), true); } else if (binding instanceof IMethodBinding) { IMethodBinding method = (IMethodBinding) binding; return hasAddedStaticImport( method.getDeclaringClass().getQualifiedName(), method.getName(), false); } return false; }
@SuppressWarnings("rawtypes") @Override public boolean visit(MethodInvocation node) { SimpleName methodName = node.getName(); List args = node.arguments(); Expression expression = node.getExpression(); Map<String, Integer> scopeBindings = getNodeScopes().get(node); String target = getTarget(expression); String targetType = translateTargetToType(target, scopeBindings); // Add only if you could guess the type of target, else ignore. // TODO: In case of a method in super type, this will still infer it as in "this". if (!targetType.isEmpty()) { List<String> argTypes = translateArgsToTypes(args, scopeBindings); if (!methodStack.empty()) { MethodDeclaration currentMethod = methodStack.peek(); MethodDecl methodDecl = getMethodDecl(currentMethod); List<MethodInvokRef> invoks = methodInvoks.get(methodDecl); if (invoks == null) { invoks = new ArrayList<>(); methodInvoks.put(methodDecl, invoks); } MethodInvokRef methodInvokRef = new MethodInvokRef( methodName.toString(), targetType, target, args.size(), node.getName().getStartPosition(), argTypes, methodName.getLength(), false, getReturnType(node)); invoks.add(methodInvokRef); } } return true; }