當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodInvocation類代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.dom.MethodInvocation的典型用法代碼示例。如果您正苦於以下問題:Java MethodInvocation類的具體用法?Java MethodInvocation怎麽用?Java MethodInvocation使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MethodInvocation類屬於org.eclipse.jdt.core.dom包,在下文中一共展示了MethodInvocation類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createUnobservedInitStmt

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
@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);
}
 
開發者ID:EvoSuite,項目名稱:evosuite,代碼行數:36,代碼來源:CodeGenerator.java

示例2: needsOuterParantheses

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
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;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:18,代碼來源:CastCorrectionProposal.java

示例3: apply

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
@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");
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:18,代碼來源:MockitoThrowFeature.java

示例4: getNewCastTypeNode

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
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;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:36,代碼來源:CastCorrectionProposal.java

示例5: checkIteratorCondition

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
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;
  }
 
開發者ID:eclipse,項目名稱:che,代碼行數:26,代碼來源:ConvertIterableLoopOperation.java

示例6: getArgumentsProperty

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
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());
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:22,代碼來源:Invocations.java

示例7: getExpressionType

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
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;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:27,代碼來源:IntroduceIndirectionRefactoring.java

示例8: createInvocation

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
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;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:27,代碼來源:AccessAnalyzer.java

示例9: visit

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:qhanam,項目名稱:Slicer,代碼行數:26,代碼來源:BDDVisitor.java

示例10: getIteratorBasedForInitializer

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:35,代碼來源:GenerateForLoopAssistProposal.java

示例11: createCollectionInitStmt

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
@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);	
	}
}
 
開發者ID:EvoSuite,項目名稱:evosuite,代碼行數:71,代碼來源:JUnitCodeGenerator.java

示例12: createMapInitStmt

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
@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);	
	}
}
 
開發者ID:EvoSuite,項目名稱:evosuite,代碼行數:60,代碼來源:JUnitCodeGenerator.java

示例13: apply

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
@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");
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:12,代碼來源:AssertTrueFeature.java

示例14: apply

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
@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");
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:16,代碼來源:AssertEqualsFeature.java

示例15: apply

import org.eclipse.jdt.core.dom.MethodInvocation; //導入依賴的package包/類
@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");
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:16,代碼來源:AssertNullFeature.java


注:本文中的org.eclipse.jdt.core.dom.MethodInvocation類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。