org.eclipse.jdt.core.dom.MethodInvocation#getName ( )源码实例Demo

下面列出了org.eclipse.jdt.core.dom.MethodInvocation#getName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: KodeBeagle   文件: TypeResolver.java
/**
 * 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;
}
 
源代码2 项目: eclipse.jdt.ls   文件: CodeScopeBuilder.java
@Override
public boolean visit(MethodInvocation node) {
	Expression receiver = node.getExpression();
	if (receiver == null) {
		SimpleName name = node.getName();
		if (fIgnoreBinding == null || !Bindings.equals(fIgnoreBinding, name.resolveBinding())) {
			node.getName().accept(this);
		}
	} else {
		receiver.accept(this);
	}
	accept(node.arguments());
	return false;
}
 
源代码3 项目: KodeBeagle   文件: MethodInvocationResolver.java
@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;
}
 
/**
 * Visits {@link SimpleName} AST nodes. Resolves the binding of the simple
 * name and looks for it in the {@link #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;
		}
	}
	addBindingData(node.getIdentifier(), node, variableNames.get(node));
	return true;
}
 
@Override
public boolean visit(MethodInvocation node) {
	Expression receiver= node.getExpression();
	if (receiver == null) {
		SimpleName name= node.getName();
		if (fIgnoreBinding == null || !Bindings.equals(fIgnoreBinding, name.resolveBinding()))
			node.getName().accept(this);
	} else {
		receiver.accept(this);
	}
	accept(node.arguments());
	return false;
}
 
@Override
public boolean visit(MethodInvocation node) {
	if (matches(node.resolveMethodBinding())) {
		SimpleName name= node.getName();
		fResult.add(new OccurrenceLocation(name.getStartPosition(), name.getLength(), 0, fDescription));
	}
	return super.visit(node);
}
 
@Override
public boolean visit(MethodInvocation node) {
	if (isExitPoint(node.resolveMethodBinding())) {
		SimpleName name= node.getName();
		fResult.add(new OccurrenceLocation(name.getStartPosition(), name.getLength(), 0, fExitDescription));
	}
	return true;
}
 
@Override
public boolean visit(MethodInvocation node) {
  visitExpressionIfName(node.getExpression());
  if (node.getExpression() != null) {
    return true;
  }
  // node is of the form `methodName(...)`, and not eg., `Foo.methodName()`.

  org.eclipse.jdt.core.dom.SimpleName simpleName = node.getName();

  if (compilationUnit.findDeclaringNode(simpleName.resolveBinding()) != null) {
    // simpleName is defined somewhere in this compilation unit - so no need to import it.
    return true;
  }

  // Do not report methods that appear in inner/anonymous classes that have a superclass:
  // Jade doesn't currently fetch inherited symbols for inner/anonymous classes, which
  // leads to inherited methods being imported. (b/35660499, b/35727475)
  // This isn't perfect because another class might call a same-named method; if this
  // becomes a problem, I'll use a blacklist.
  AbstractTypeDeclaration containingClass = getContainingClass(node);
  if (!(containingClass.getParent() instanceof CompilationUnit)
      && containingClass instanceof TypeDeclaration
      && ((TypeDeclaration) containingClass).getSuperclassType() != null) {
    return true;
  }
  if (isDescendantOfAnonymousClassDeclaration(node)) {
    return true;
  }

  // Work around Eclipse JDT Bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=462192,
  // where `simpleName.resolveBinding() == null` happens even though 'simpleName' is
  // defined in the current compilation unit.
  Set<String> methods = methodsOfClass.get(containingClass);
  if (methods.isEmpty()) {
    methods.addAll(getMethodDeclarations(containingClass));
  }
  if (!methods.contains(simpleName.getIdentifier())) {
    int startPosition = simpleName.getStartPosition();
    symbols.put(
        simpleName.getIdentifier(),
        Metadata.create(
            compilationUnit.getLineNumber(startPosition),
            compilationUnit.getColumnNumber(startPosition),
            true));
  }
  return true;
}
 
/**
 * {@inheritDoc}
 */
@Override
public boolean visit(final MethodInvocation node) {
	if (!fRemoveMethodQualifiers)
		return true;

	Expression expression= node.getExpression();
	if (!(expression instanceof ThisExpression))
		return true;

	final SimpleName name= node.getName();
	if (name.resolveBinding() == null)
		return true;

	if (hasConflict(expression.getStartPosition(), name, ScopeAnalyzer.METHODS | ScopeAnalyzer.CHECK_VISIBILITY))
		return true;

	Name qualifier= ((ThisExpression)expression).getQualifier();
	if (qualifier != null) {
		ITypeBinding declaringClass= ((IMethodBinding)name.resolveBinding()).getDeclaringClass();
		if (declaringClass == null)
			return true;

		ITypeBinding caller= getDeclaringType(node);
		if (caller == null)
			return true;

		ITypeBinding callee= (ITypeBinding)qualifier.resolveBinding();
		if (callee == null)
			return true;

		if (callee.isAssignmentCompatible(declaringClass) && caller.isAssignmentCompatible(declaringClass))
			return true;
	}

	fOperations.add(new CompilationUnitRewriteOperation() {
		@Override
		public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
			ASTRewrite rewrite= cuRewrite.getASTRewrite();
			TextEditGroup group= createTextEditGroup(FixMessages.CodeStyleFix_removeThis_groupDescription, cuRewrite);
			rewrite.remove(node.getExpression(), group);
		}
	});
	return super.visit(node);
}