Java 类org.eclipse.jdt.core.dom.MethodInvocation 实例源码

项目:evosuite    文件:CodeGenerator.java   
@SuppressWarnings("unchecked")
private void createUnobservedInitStmt(final int logRecNo, final Block methodBlock, final AST ast)
{
    // NOTE: PLAIN INIT: has always one non-null param
    // TODO: use primitives
    final int    oid     = this.log.objectIds.get(logRecNo);
    final String type    = this.log.oidClassNames.get(this.log.oidRecMapping.get(oid));
    final Object value   = this.log.params.get(logRecNo)[0];
    this.isXStreamNeeded = true;

    final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
    // handling because there must always be a new instantiation statement for pseudo inits
    this.oidToVarMapping.remove(oid);
    vd.setName(ast.newSimpleName(this.createNewVarName(oid, type)));

    final MethodInvocation methodInvocation = ast.newMethodInvocation();
    final Name name = ast.newSimpleName("XSTREAM");
    methodInvocation.setExpression(name);
    methodInvocation.setName(ast.newSimpleName("fromXML")); 

    final StringLiteral xmlParam = ast.newStringLiteral();
    xmlParam.setLiteralValue((String) value);
    methodInvocation.arguments().add(xmlParam);

    final CastExpression castExpr = ast.newCastExpression();
    castExpr.setType(this.createAstType(type, ast));
    castExpr.setExpression(methodInvocation);

    vd.setInitializer(castExpr);

    final VariableDeclarationStatement vs = ast.newVariableDeclarationStatement(vd);
    vs.setType(this.createAstType(type, ast));

    methodBlock.statements().add(vs);
}
项目:che    文件:CastCorrectionProposal.java   
private static boolean needsOuterParantheses(ASTNode nodeToCast) {
  ASTNode parent = nodeToCast.getParent();
  if (parent instanceof MethodInvocation) {
    if (((MethodInvocation) parent).getExpression() == nodeToCast) {
      return true;
    }
  } else if (parent instanceof QualifiedName) {
    if (((QualifiedName) parent).getQualifier() == nodeToCast) {
      return true;
    }
  } else if (parent instanceof FieldAccess) {
    if (((FieldAccess) parent).getExpression() == nodeToCast) {
      return true;
    }
  }
  return false;
}
项目:junit2spock    文件:MockitoThrowFeature.java   
@Override
public Expression apply(Object object, MethodInvocation whenMethodInvocation) {
    MethodInvocation methodInvocation = methodInvocation(object, thenThrow).get();
    List arguments = methodInvocation.arguments();
    if (arguments.size() == 1) {
        MethodInvocation mockedMethodInvocation = (MethodInvocation) whenMethodInvocation.arguments().get(0);
        Expression toBeThrown = argumentAsExpression(arguments.get(0));
        Expression throwingClosure = groovyClosureBuilder.aClosure()
                .withBodyStatement(nodeFactory.throwStatement(toBeThrown))
                .build()
                .asExpression();
        return nodeFactory.infixExpression(RIGHT_SHIFT_SIGNED,
                mockedMethodWithMatchers(mockedMethodInvocation),
                throwingClosure);
    }
    throw new UnsupportedOperationException("Supported only 1-arity thenThrow invocation");
}
项目:eclipse.jdt.ls    文件:CastCorrectionProposal.java   
private Type getNewCastTypeNode(ASTRewrite rewrite, ImportRewrite importRewrite) {
    AST ast= rewrite.getAST();

    ImportRewriteContext context= new ContextSensitiveImportRewriteContext((CompilationUnit) fNodeToCast.getRoot(), fNodeToCast.getStartPosition(), importRewrite);

    if (fCastType != null) {
        return importRewrite.addImport(fCastType, ast,context, TypeLocation.CAST);
    }

    ASTNode node= fNodeToCast;
    ASTNode parent= node.getParent();
    if (parent instanceof CastExpression) {
        node= parent;
        parent= parent.getParent();
    }
    while (parent instanceof ParenthesizedExpression) {
        node= parent;
        parent= parent.getParent();
    }
    if (parent instanceof MethodInvocation) {
        MethodInvocation invocation= (MethodInvocation) node.getParent();
        if (invocation.getExpression() == node) {
            IBinding targetContext= ASTResolving.getParentMethodOrTypeBinding(node);
            ITypeBinding[] bindings= ASTResolving.getQualifierGuess(node.getRoot(), invocation.getName().getIdentifier(), invocation.arguments(), targetContext);
            if (bindings.length > 0) {
                ITypeBinding first= getCastFavorite(bindings, fNodeToCast.resolveTypeBinding());

                Type newTypeNode= importRewrite.addImport(first, ast, context, TypeLocation.CAST);
                return newTypeNode;
            }
        }
    }
    Type newCastType= ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
    return newCastType;
}
项目:che    文件:ConvertIterableLoopOperation.java   
private IStatus checkIteratorCondition() {

    List<Expression> initializers = getForStatement().initializers();
    if (initializers.size() != 1) return SEMANTIC_CHANGE_WARNING_STATUS;

    Expression expression = initializers.get(0);
    if (!(expression instanceof VariableDeclarationExpression))
      return SEMANTIC_CHANGE_WARNING_STATUS;

    VariableDeclarationExpression declaration = (VariableDeclarationExpression) expression;
    List<VariableDeclarationFragment> variableDeclarationFragments = declaration.fragments();
    if (variableDeclarationFragments.size() != 1) return SEMANTIC_CHANGE_WARNING_STATUS;

    VariableDeclarationFragment declarationFragment = variableDeclarationFragments.get(0);

    Expression initializer = declarationFragment.getInitializer();
    if (!(initializer instanceof MethodInvocation)) return SEMANTIC_CHANGE_WARNING_STATUS;

    MethodInvocation methodInvocation = (MethodInvocation) initializer;
    String methodName = methodInvocation.getName().getIdentifier();
    if (!"iterator".equals(methodName) || methodInvocation.arguments().size() != 0) // $NON-NLS-1$
    return SEMANTIC_CHANGE_WARNING_STATUS;

    return StatusInfo.OK_STATUS;
  }
项目:che    文件:Invocations.java   
public static ChildListPropertyDescriptor getArgumentsProperty(ASTNode invocation) {
  switch (invocation.getNodeType()) {
    case ASTNode.METHOD_INVOCATION:
      return MethodInvocation.ARGUMENTS_PROPERTY;
    case ASTNode.SUPER_METHOD_INVOCATION:
      return SuperMethodInvocation.ARGUMENTS_PROPERTY;

    case ASTNode.CONSTRUCTOR_INVOCATION:
      return ConstructorInvocation.ARGUMENTS_PROPERTY;
    case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
      return SuperConstructorInvocation.ARGUMENTS_PROPERTY;

    case ASTNode.CLASS_INSTANCE_CREATION:
      return ClassInstanceCreation.ARGUMENTS_PROPERTY;
    case ASTNode.ENUM_CONSTANT_DECLARATION:
      return EnumConstantDeclaration.ARGUMENTS_PROPERTY;

    default:
      throw new IllegalArgumentException(invocation.toString());
  }
}
项目:che    文件:IntroduceIndirectionRefactoring.java   
private ITypeBinding getExpressionType(MethodInvocation invocation) {
  Expression expression = invocation.getExpression();
  ITypeBinding typeBinding = null;
  if (expression == null) {
    typeBinding = invocation.resolveMethodBinding().getDeclaringClass();
  } else {
    typeBinding = expression.resolveTypeBinding();
  }
  if (typeBinding != null && typeBinding.isTypeVariable()) {
    ITypeBinding[] typeBounds = typeBinding.getTypeBounds();
    if (typeBounds.length > 0) {
      for (ITypeBinding typeBound : typeBounds) {
        ITypeBinding expressionType = getExpressionType(invocation, typeBound);
        if (expressionType != null) {
          return expressionType;
        }
      }
      typeBinding = typeBounds[0].getTypeDeclaration();
    } else {
      typeBinding = invocation.getAST().resolveWellKnownType("java.lang.Object"); // $NON-NLS-1$
    }
  }
  Assert.isNotNull(
      typeBinding, "Type binding of target expression may not be null"); // $NON-NLS-1$
  return typeBinding;
}
项目:che    文件:IntroduceIndirectionRefactoring.java   
private ITypeBinding getExpressionType(
    final MethodInvocation invocation, ITypeBinding typeBinding) {
  if (typeBinding == null) return null;
  for (IMethodBinding iMethodBinding : typeBinding.getDeclaredMethods()) {
    if (invocation.resolveMethodBinding() == iMethodBinding)
      return typeBinding.getTypeDeclaration();
  }
  ITypeBinding expressionType = getExpressionType(invocation, typeBinding.getSuperclass());
  if (expressionType != null) {
    return expressionType;
  }
  for (ITypeBinding interfaceBinding : typeBinding.getInterfaces()) {
    expressionType = getExpressionType(invocation, interfaceBinding);
    if (expressionType != null) {
      return expressionType;
    }
  }
  return null;
}
项目:che    文件:AccessAnalyzer.java   
private MethodInvocation createInvocation(AST ast, Expression operand, String operator) {
  Expression receiver = getReceiver(operand);
  MethodInvocation invocation = ast.newMethodInvocation();
  invocation.setName(ast.newSimpleName(fSetter));
  if (receiver != null)
    invocation.setExpression((Expression) fRewriter.createCopyTarget(receiver));
  InfixExpression argument = ast.newInfixExpression();
  invocation.arguments().add(argument);
  if ("++".equals(operator)) { // $NON-NLS-1$
    argument.setOperator(InfixExpression.Operator.PLUS);
  } else if ("--".equals(operator)) { // $NON-NLS-1$
    argument.setOperator(InfixExpression.Operator.MINUS);
  } else {
    Assert.isTrue(false, "Should not happen"); // $NON-NLS-1$
  }
  MethodInvocation getter = ast.newMethodInvocation();
  getter.setName(ast.newSimpleName(fGetter));
  if (receiver != null) getter.setExpression((Expression) fRewriter.createCopyTarget(receiver));
  argument.setLeftOperand(getter);
  argument.setRightOperand(ast.newNumberLiteral("1")); // $NON-NLS-1$

  fReferencingGetter = true;
  fReferencingSetter = true;

  return invocation;
}
项目:Slicer    文件:BDDVisitor.java   
/**
 * If we are creating a conservative slice, we treat both
 * objects on which we call methods as well as arguments
 * for method calls as dependencies. This makes the
 * assumption that the method will modify the caller
 * and the arguments.
 * @param node
 * @return
 */
@Override 
public boolean visit(MethodInvocation node){
    if(this.options.contains(Slicer.Options.CONSERVATIVE)){
        /* The expression part (eg. 'result.setFast(arg1, arg2)' expression = 'result' */
        Expression expression = node.getExpression();
        this.visitExpression(expression, new NoBindingsMethodVisitor(this.aliases));
        if(this.result) return false; 

        /* The argument (eg. 'result.setFast(arg1, arg2)' arguments = {'arg1', 'arg2'}. */
        List<Expression> arguments = node.arguments();
        for(Expression argument : arguments){
            this.visitExpression(argument, new NoBindingsAssignmentVisitor(this.aliases));
        }
    }
    return false;
}
项目:che    文件:GenerateForLoopAssistProposal.java   
/**
 * Generates the initializer for an iterator based <code>for</code> loop, which declares and
 * initializes the variable to loop over.
 *
 * @param rewrite the instance of {@link ASTRewrite}
 * @param loopVariableName the proposed name of the loop variable
 * @return a {@link VariableDeclarationExpression} to use as initializer
 */
private VariableDeclarationExpression getIteratorBasedForInitializer(
    ASTRewrite rewrite, SimpleName loopVariableName) {
  AST ast = rewrite.getAST();
  IMethodBinding iteratorMethodBinding =
      Bindings.findMethodInHierarchy(
          fExpressionType, "iterator", new ITypeBinding[] {}); // $NON-NLS-1$
  // initializing fragment
  VariableDeclarationFragment varDeclarationFragment = ast.newVariableDeclarationFragment();
  varDeclarationFragment.setName(loopVariableName);
  MethodInvocation iteratorExpression = ast.newMethodInvocation();
  iteratorExpression.setName(ast.newSimpleName(iteratorMethodBinding.getName()));
  iteratorExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));
  varDeclarationFragment.setInitializer(iteratorExpression);

  // declaration
  VariableDeclarationExpression varDeclarationExpression =
      ast.newVariableDeclarationExpression(varDeclarationFragment);
  varDeclarationExpression.setType(
      getImportRewrite()
          .addImport(
              iteratorMethodBinding.getReturnType(),
              ast,
              new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));

  return varDeclarationExpression;
}
项目:evosuite    文件:JUnitCodeGenerator.java   
@SuppressWarnings("unchecked")
@Override
public void createCollectionInitStmt(final CaptureLog log, final int logRecNo) 
{
    final int      oid          = log.objectIds.get(logRecNo);
    final Object[] params       = log.params.get(logRecNo);
    String         collTypeName = log.oidClassNames.get(log.oidRecMapping.get(oid));
    final Class<?> collType     = getClassForName(collTypeName);

    final String varName;

    // -- determine if an alternative collection must be used for code generation
    final boolean isPrivate = java.lang.reflect.Modifier.isPrivate(collType.getModifiers());
    if(isPrivate || ! hasDefaultConstructor(collType))
    {
        if(Set.class.isAssignableFrom(collType))
        {
            collTypeName = HashSet.class.getName();
        }
        else if (List.class.isAssignableFrom(collType))
        {
            collTypeName = ArrayList.class.getName();
        }
        else if(Queue.class.isAssignableFrom(collType))
        {
            collTypeName = ArrayDeque.class.getName();
        }
        else
        {
            throw new RuntimeException("Collection " + collType + " is not supported");
        }
    }

    // -- create code for instantiating collection
    varName = this.createNewVarName(oid, collTypeName);

    final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
    final SimpleName varNameExpr = ast.newSimpleName(varName); 
    vd.setName(varNameExpr);    

    final ClassInstanceCreation ci = ast.newClassInstanceCreation();
        ci.setType(this.createAstType(collTypeName, ast));
        vd.setInitializer(ci);

    final VariableDeclarationStatement stmt = ast.newVariableDeclarationStatement(vd);
    stmt.setType(this.createAstType(collTypeName, ast));

    methodBlock.statements().add(stmt); 

    // --- create code for filling the collection
    Integer paramOID;
    MethodInvocation mi;
    for(int i = 0; i < params.length; i++)
    {
        mi = ast.newMethodInvocation();
        mi.setName(ast.newSimpleName("add"));

        paramOID = (Integer) params[i];
        if(paramOID == null)
        {
            mi.arguments().add(ast.newNullLiteral());
        }
        else
        {
            mi.arguments().add(ast.newSimpleName(this.oidToVarMapping.get(paramOID)));
        }

        methodBlock.statements().add(mi);   
    }
}
项目:evosuite    文件:JUnitCodeGenerator.java   
@Override
public void createMapInitStmt(final CaptureLog log, final int logRecNo) {
    final int      oid          = log.objectIds.get(logRecNo);
    final Object[] params       = log.params.get(logRecNo);
    String         collTypeName = log.oidClassNames.get(log.oidRecMapping.get(oid));
    final Class<?> collType     = getClassForName(collTypeName);


    final String varName;

    // -- determine if an alternative collection must be used for code generation
    final boolean isPrivate = java.lang.reflect.Modifier.isPrivate(collType.getModifiers());
    if(isPrivate || ! hasDefaultConstructor(collType))
    {
        collTypeName = HashMap.class.getName();
    }

    // -- create code for instantiating collection
    varName = this.createNewVarName(oid, collTypeName);

    final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
    final SimpleName varNameExpr = ast.newSimpleName(varName); 
    vd.setName(varNameExpr);    

    final ClassInstanceCreation ci = ast.newClassInstanceCreation();
        ci.setType(this.createAstType(collTypeName, ast));
        vd.setInitializer(ci);

    final VariableDeclarationStatement stmt = ast.newVariableDeclarationStatement(vd);
    stmt.setType(this.createAstType(collTypeName, ast));

    methodBlock.statements().add(stmt); 

    // --- create code for filling the collection
    Integer valueOID;
    Integer keyOID;

    MethodInvocation mi;
    for(int i = 0; i + 1< params.length; i+=2)
    {
        mi = ast.newMethodInvocation();
        mi.setName(ast.newSimpleName("put"));

        keyOID = (Integer) params[i];
        mi.arguments().add(ast.newSimpleName(this.oidToVarMapping.get(keyOID)));

        valueOID = (Integer) params[i + 1];
        if(valueOID == null)
        {
            mi.arguments().add(ast.newNullLiteral());
        }
        else
        {
            mi.arguments().add(ast.newSimpleName(this.oidToVarMapping.get(valueOID)));
        }

        methodBlock.statements().add(mi);   
    }
}
项目:junit2spock    文件:AssertTrueFeature.java   
@Override
public Expression apply(Object object, MethodInvocation methodInvocation) {
    List arguments = methodInvocation.arguments();
    if (arguments.size() == 1) {
        return argumentAsExpression(arguments.get(0));
    }
    if (arguments.size() == 2) {
        return argumentAsExpression(arguments.get(1));
    }
    throw new UnsupportedOperationException("Supported only 1-, 2-arity assertTrue invocation");
}
项目:junit2spock    文件:AssertEqualsFeature.java   
@Override
public InfixExpression apply(Object object, MethodInvocation methodInvocation) {
    List arguments = methodInvocation.arguments();
    if (arguments.size() == 2) {
        return astNodeFactory.infixExpression(EQUALS,
                argumentAsExpression(arguments.get(1)),
                argumentAsExpression(arguments.get(0)));
    }
    if (arguments.size() == 3) {
        return astNodeFactory.infixExpression(EQUALS,
                argumentAsExpression(arguments.get(2)),
                argumentAsExpression(arguments.get(1)));
    }
    throw new UnsupportedOperationException("Supported only 2-, 3-arity assertEquals/assertArrayEquals invocation");
}
项目:junit2spock    文件:AssertNullFeature.java   
@Override
public InfixExpression apply(Object object, MethodInvocation methodInvocation) {
    List arguments = methodInvocation.arguments();
    if (arguments.size() == 1) {
        return astNodeFactory.infixExpression(EQUALS,
                argumentAsExpression(arguments.get(0)),
                astNodeFactory.nullLiteral());
    }
    if (arguments.size() == 2) {
        return astNodeFactory.infixExpression(EQUALS,
                argumentAsExpression(arguments.get(1)),
                astNodeFactory.nullLiteral());
    }
    throw new UnsupportedOperationException("Supported only 1-, 2-arity assertNull invocation");
}
项目:junit2spock    文件:AssertNotNullFeature.java   
@Override
public InfixExpression apply(Object object, MethodInvocation methodInvocation) {
    List arguments = methodInvocation.arguments();
    if (arguments.size() == 1) {
        return astNodeFactory.infixExpression(NOT_EQUALS,
                argumentAsExpression(arguments.get(0)),
                astNodeFactory.nullLiteral());
    }
    if (arguments.size() == 2) {
        return astNodeFactory.infixExpression(NOT_EQUALS,
                argumentAsExpression(arguments.get(1)),
                astNodeFactory.nullLiteral());
    }
    throw new UnsupportedOperationException("Supported only 1-, 2-arity assertNotNull invocation");
}
项目:junit2spock    文件:AssertFalseFeature.java   
@Override
public Expression apply(Object object, MethodInvocation methodInvocation) {
    List arguments = methodInvocation.arguments();
    if (arguments.size() == 1) {
        return astNodeFactory.prefixExpression(NOT, argumentAsExpression(arguments.get(0)));
    }
    if (arguments.size() == 2) {
        return astNodeFactory.prefixExpression(NOT, argumentAsExpression(arguments.get(1)));
    }
    throw new UnsupportedOperationException("Supported only 1-, 2-arity assertFalse invocation");
}
项目:junit2spock    文件:MockitoVerifyNoMoreInteractionsFeature.java   
@Override
public InfixExpression apply(Object object, MethodInvocation verifyMethodInvocation) {
    List arguments = verifyMethodInvocation.arguments();
    return nodeFactory.infixExpression(TIMES,
            nodeFactory.numberLiteral("0"),
            nodeFactory.fieldAccess("_", nodeFactory.clone((Expression) arguments.get(0))));
}
项目:junit2spock    文件:MockitoVerifyFeature.java   
@Override
public InfixExpression apply(Object object, MethodInvocation verifyMethodInvocation) {
    List arguments = verifyMethodInvocation.arguments();
    MethodInvocation parentMethodInvocation = (MethodInvocation) verifyMethodInvocation.getParent();
    return nodeFactory.infixExpression(TIMES,
            cardinality(arguments.size() == 2 ? Optional.of(arguments.get(1)) : empty()),
            nodeFactory.methodInvocation(parentMethodInvocation.getName().getFullyQualifiedName(),
                    (List<Expression>) parentMethodInvocation.arguments().stream()
                            .map(matcherHandler::applyMatchers).collect(toList()),
                    nodeFactory.clone((Expression) arguments.get(0))));
}
项目:RefDiff    文件:DependenciesAstVisitor.java   
@Override
public final boolean visit(MethodInvocation node) {
    IMethodBinding methodBinding = node.resolveMethodBinding();
    if (methodBinding != null) {
        handleTypeBinding(node, methodBinding.getDeclaringClass(), false);
        handleMethodBinding(node, methodBinding);
    }
    return true;
}
项目:RefDiff    文件:DependenciesAstVisitor.java   
@Override
public final boolean visit(MethodInvocation node) {
    IMethodBinding methodBinding = node.resolveMethodBinding();
    if (methodBinding != null) {
        handleTypeBinding(node, methodBinding.getDeclaringClass(), false);
        handleMethodBinding(node, methodBinding);
    }
    return true;
}
项目:pandionj    文件:VarParser.java   
@Override
public boolean visit(MethodInvocation node) {
    List<?> arguments = node.arguments();
    for(int i = 0; i < arguments.size(); i++) {
        Object arg = arguments.get(i);
        if(arg instanceof SimpleName) {
            VariableInfo varInfo = current.getVariable(arg.toString());
            if(varInfo != null)
                varInfo.addOperation(VariableOperation.Type.PARAM, node.getName().toString(), arguments.size(), i);
        }
    }
    return true;
}
项目:SparkBuilderGenerator    文件:StaticMethodInvocationFragment.java   
public MethodInvocation createStaticMethodInvocation(AST ast, String className, String methodName) {
    SimpleName typeName = ast.newSimpleName(className);

    MethodInvocation methodInvocation = ast.newMethodInvocation();
    methodInvocation.setName(ast.newSimpleName(methodName));
    methodInvocation.setExpression(typeName);

    return methodInvocation;
}
项目:SparkBuilderGenerator    文件:NewBuilderAndWithMethodCallCreationFragment.java   
public Block createReturnBlock(AST ast, TypeDeclaration builderType, String withName, String parameterName) {
    Block builderMethodBlock = ast.newBlock();
    ReturnStatement returnStatement = ast.newReturnStatement();
    ClassInstanceCreation newClassInstanceCreation = ast.newClassInstanceCreation();
    newClassInstanceCreation.setType(ast.newSimpleType(ast.newName(builderType.getName().toString())));

    MethodInvocation withMethodInvocation = ast.newMethodInvocation();
    withMethodInvocation.setExpression(newClassInstanceCreation);
    withMethodInvocation.setName(ast.newSimpleName(withName));
    withMethodInvocation.arguments().add(ast.newSimpleName(parameterName));

    returnStatement.setExpression(withMethodInvocation);
    builderMethodBlock.statements().add(returnStatement);
    return builderMethodBlock;
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
/**
 * Returns whether an expression at the given location needs explicit boxing.
 *
 * @param expression the expression
 * @return <code>true</code> iff an expression at the given location needs explicit boxing
 * @since 3.6
 */
private static boolean needsExplicitBoxing(Expression expression) {
    StructuralPropertyDescriptor locationInParent= expression.getLocationInParent();
    if (locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
        return needsExplicitBoxing((ParenthesizedExpression) expression.getParent());
    }

    if (locationInParent == ClassInstanceCreation.EXPRESSION_PROPERTY
            || locationInParent == FieldAccess.EXPRESSION_PROPERTY
            || locationInParent == MethodInvocation.EXPRESSION_PROPERTY) {
        return true;
    }

    return false;
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
/**
 * Returns the receiver's type binding of the given method invocation.
 *
 * @param invocation method invocation to resolve type of
 * @return the type binding of the receiver
 */
public static ITypeBinding getReceiverTypeBinding(MethodInvocation invocation) {
    ITypeBinding result= null;
    Expression exp= invocation.getExpression();
    if(exp != null) {
        return exp.resolveTypeBinding();
    }
    else {
        AbstractTypeDeclaration type= (AbstractTypeDeclaration)getParent(invocation, AbstractTypeDeclaration.class);
        if (type != null) {
            return type.resolveBinding();
        }
    }
    return result;
}
项目: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;
}
项目:eclipse.jdt.ls    文件:ExtractMethodRefactoring.java   
@Override
public boolean visit(MethodInvocation node) {
    Expression exp = node.getExpression();
    if (exp != null) {
        fIgnore.add(node.getName());
    }
    return true;
}
项目:eclipse.jdt.ls    文件:CastCorrectionProposal.java   
private static boolean needsOuterParantheses(ASTNode nodeToCast) {
    ASTNode parent= nodeToCast.getParent();
    if (parent instanceof MethodInvocation) {
        if (((MethodInvocation)parent).getExpression() == nodeToCast) {
            return true;
        }
    } else if (parent instanceof QualifiedName) {
        if (((QualifiedName)parent).getQualifier() == nodeToCast) {
            return true;
        }
    } else if (parent instanceof FieldAccess) {
        if (((FieldAccess)parent).getExpression() == nodeToCast) {
            return true;
        }
    }
    return false;
}
项目:eclipse.jdt.ls    文件:NewVariableCorrectionProposal.java   
private Type evaluateVariableType(AST ast, ImportRewrite imports, ImportRewriteContext importRewriteContext, IBinding targetContext, TypeLocation location) {
    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) {
                return imports.addImport(bindings[0], ast, importRewriteContext, location);
            }
        }
    }

    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$
            }
        }

        return imports.addImport(binding, ast, importRewriteContext, location);
    }
    // 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$
}
项目:code    文件:ExpressionVisitor.java   
public ExpressionVisitor(ASTNode enclosingDeclartion, BaseTraceability trace) {
    AstNode expression = trace.getExpression();
    if(expression instanceof ast.ClassInstanceCreation){
        expressionType = ExpressionType.CLASS_INSTANCE_CREATION;
        expressionToFind =((ast.ClassInstanceCreation) expression).complexExpression;
    }else if(expression instanceof ast.FieldWrite){
        expressionType = ExpressionType.FIELD_WRITE;
        expressionToFind = ((ast.FieldWrite) expression).complexExpression;
    }else if(expression instanceof ast.FieldAccess){
        expressionType = ExpressionType.FIELD_ACCESS;
        expressionToFind = ((ast.FieldAccess) expression).complexExpression;
    }else if(expression instanceof ast.MethodInvocation){
        expressionToFind =((ast.MethodInvocation) expression).complexExpression;
        expressionType = ExpressionType.METHOD_INVOCATION;
    }
    enclosingDeclaration = enclosingDeclartion;
    enclosingDeclaration.accept(this);
}
项目:Sparrow    文件:OutCodeVisitor.java   
@Override
public boolean visit(MethodInvocation loc) {
    if (currentMethod == null)
        return false;
    if (loc.resolveMethodBinding() == null)
        return false;
    if (loc.resolveMethodBinding().getMethodDeclaration() == null || loc.resolveMethodBinding().getMethodDeclaration().getJavaElement() == null)
        return true;
    if (loc.resolveMethodBinding().getMethodDeclaration().getJavaElement().isReadOnly())
        return true;
    addCalledMethod(loc.resolveMethodBinding().getMethodDeclaration());
    return true;
}
项目:Migrate-Skeletal-Implementation-to-Interface-Refactoring    文件:MethodReceiverAnalysisVisitor.java   
@Override
public boolean visit(MethodInvocation methodInvocation) {
    IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();

    if (methodBinding != null) {
        IJavaElement javaElement = methodBinding.getJavaElement();

        if (javaElement == null)
            MigrateSkeletalImplementationToInterfaceRefactoringProcessor
                    .logWarning("Could not get Java element from binding: " + methodBinding + " while processing: "
                            + methodInvocation);
        else if (javaElement.equals(accessedMethod)) {
            Expression expression = methodInvocation.getExpression();
            expression = (Expression) Util.stripParenthesizedExpressions(expression);

            // FIXME: It's not really that the expression is a `this`
            // expression but that the type of the expression comes from
            // a
            // `this` expression. In other words, we may need to climb
            // the
            // AST.
            if (expression == null || expression.getNodeType() == ASTNode.THIS_EXPRESSION)
                this.encounteredThisReceiver = true;
        }
    }
    return super.visit(methodInvocation);
}
项目:Ref-Finder    文件:ASTVisitorAtomicChange.java   
public boolean visit(MethodInvocation node)
{
  IMethodBinding mmtb = node.resolveMethodBinding();
  if (this.mtbStack.isEmpty()) {
    return true;
  }
  try
  {
    if (node.getExpression() != null) {
      if (mmtb.getDeclaringClass().getQualifiedName().startsWith("java.awt.geom.Path2D"))
      {
        Expression e = node.getExpression();
        ITypeBinding itb = e.resolveTypeBinding();
        this.facts.add(Fact.makeCallsFact(getQualifiedName((IMethodBinding)this.mtbStack.peek()), 
          getQualifiedName(itb) + "#" + getSimpleName(mmtb)));
        break label179;
      }
    }
    this.facts.add(Fact.makeCallsFact(getQualifiedName((IMethodBinding)this.mtbStack.peek()), 
      getQualifiedName(mmtb)));
  }
  catch (Exception localException)
  {
    System.err.println("Cannot resolve method invocation \"" + 
      node.getName().toString() + "\"");
  }
  label179:
  return true;
}
项目:Constants-to-Enum-Eclipse-Plugin    文件:ConvertConstantsToEnumRefactoring.java   
private RefactoringStatus rewriteInfixExpression(ASTRewrite astRewrite,
        ImportRewrite importRewrite, InfixExpression ie,
        String fullyQualifiedTypeName) {
    final RefactoringStatus status = new RefactoringStatus();
    final AST ast = ie.getAST();

    final Expression leftExpCopy = (Expression) ASTNode.copySubtree(ast,
            ie.getLeftOperand());
    final Expression rightExpCopy = (Expression) ASTNode.copySubtree(ast,
            ie.getRightOperand());

    final NumberLiteral zero = ast.newNumberLiteral();
    astRewrite.replace(ie.getRightOperand(), zero, null);

    final MethodInvocation newInvocation = ast.newMethodInvocation();
    newInvocation.setExpression(leftExpCopy);
    newInvocation.setName(ast.newSimpleName("compareTo")); //$NON-NLS-1$
    newInvocation.arguments().add(rightExpCopy);

    astRewrite.replace(ie.getLeftOperand(), newInvocation, null);

    if (((ASTNode) newInvocation.arguments().get(0)).getNodeType() == ASTNode.SIMPLE_NAME
            && this.fieldsToRefactor.contains(((SimpleName) ie
                    .getRightOperand()).resolveBinding().getJavaElement()))
        this.rewriteReference(astRewrite, importRewrite,
                (SimpleName) newInvocation.arguments().get(0),
                fullyQualifiedTypeName);

    if (((ASTNode) newInvocation.getExpression()).getNodeType() == ASTNode.SIMPLE_NAME
            && this.fieldsToRefactor.contains(((SimpleName) ie
                    .getLeftOperand()).resolveBinding().getJavaElement()))
        this.rewriteReference(astRewrite, importRewrite,
                (SimpleName) newInvocation.getExpression(),
                fullyQualifiedTypeName);

    return status;
}
项目:che    文件: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;
}
项目:che    文件:LambdaExpressionsFix.java   
@Override
public boolean visit(MethodInvocation node) {
  IMethodBinding binding = node.resolveMethodBinding();
  if (binding != null
      && !JdtFlags.isStatic(binding)
      && node.getExpression() == null
      && Bindings.isSuperType(binding.getDeclaringClass(), fFunctionalInterface, false))
    throw new AbortSearchException();
  return true;
}
项目:che    文件:CodeStyleFix.java   
/** {@inheritDoc} */
@Override
public boolean visit(MethodInvocation node) {
  if (!fFindUnqualifiedMethodAccesses && !fFindUnqualifiedStaticMethodAccesses) return true;

  if (node.getExpression() != null) return true;

  IBinding binding = node.getName().resolveBinding();
  if (!(binding instanceof IMethodBinding)) return true;

  handleMethod(node.getName(), (IMethodBinding) binding);
  return true;
}
项目:che    文件:CodeStyleFix.java   
/** {@inheritDoc} */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model)
    throws CoreException {
  TextEditGroup group =
      createTextEditGroup(
          FixMessages.CodeStyleFix_ChangeAccessUsingDeclaring_description, cuRewrite);

  if (fQualifier instanceof MethodInvocation || fQualifier instanceof ClassInstanceCreation)
    extractQualifier(fQualifier, cuRewrite, group);

  Type type =
      importType(
          fDeclaringTypeBinding, fQualifier, cuRewrite.getImportRewrite(), cuRewrite.getRoot());
  cuRewrite.getASTRewrite().replace(fQualifier, type, group);
}