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


Java MethodInvocation.setExpression方法代碼示例

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


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

示例1: createUnobservedInitStmt

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
	@Override
	public void createUnobservedInitStmt(CaptureLog log, int logRecNo) 
	{
		PostProcessor.notifyRecentlyProcessedLogRecNo(logRecNo);
		
		// NOTE: PLAIN INIT: has always one non-null param
		// TODO: use primitives
		final int    oid     = log.objectIds.get(logRecNo);
//		final String type    = log.oidClassNames.get(log.oidRecMapping.get(oid));
		final Object value   = 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, log.oidClassNames.get(log.oidRecMapping.get(oid)), true)));
		
		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);
		vd.setInitializer(methodInvocation);
		
		final VariableDeclarationStatement vs = ast.newVariableDeclarationStatement(vd);
		vs.setType(this.createAstType("Object", ast));
				
		methodBlock.statements().add(vs);
	}
 
開發者ID:EvoSuite,項目名稱:evosuite,代碼行數:40,代碼來源:JUnitCodeGenerator.java

示例2: 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

示例3: 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

示例4: 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

示例5: createStaticMethodInvocation

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

示例6: createReturnBlock

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

示例7: rewriteInfixExpression

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
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;
}
 
開發者ID:ponder-lab,項目名稱:Constants-to-Enum-Eclipse-Plugin,代碼行數:38,代碼來源:ConvertConstantsToEnumRefactoring.java

示例8: generateIteratorBasedForRewrite

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
/**
 * Helper to generate an iterator based <code>for</code> loop to iterate over an {@link Iterable}.
 *
 * @param ast the {@link AST} instance to rewrite the loop to
 * @return the complete {@link ASTRewrite} object
 */
private ASTRewrite generateIteratorBasedForRewrite(AST ast) {
  ASTRewrite rewrite = ASTRewrite.create(ast);
  ForStatement loopStatement = ast.newForStatement();

  ITypeBinding loopOverType = extractElementType(ast);

  SimpleName loopVariableName =
      resolveLinkedVariableNameWithProposals(rewrite, "iterator", null, true); // $NON-NLS-1$
  loopStatement.initializers().add(getIteratorBasedForInitializer(rewrite, loopVariableName));

  MethodInvocation loopExpression = ast.newMethodInvocation();
  loopExpression.setName(ast.newSimpleName("hasNext")); // $NON-NLS-1$
  SimpleName expressionName = ast.newSimpleName(loopVariableName.getIdentifier());
  addLinkedPosition(
      rewrite.track(expressionName), LinkedPositionGroup.NO_STOP, expressionName.getIdentifier());
  loopExpression.setExpression(expressionName);

  loopStatement.setExpression(loopExpression);

  Block forLoopBody = ast.newBlock();
  Assignment assignResolvedVariable =
      getIteratorBasedForBodyAssignment(rewrite, loopOverType, loopVariableName);
  forLoopBody.statements().add(ast.newExpressionStatement(assignResolvedVariable));
  forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));

  loopStatement.setBody(forLoopBody);

  rewrite.replace(fCurrentNode, loopStatement, null);

  return rewrite;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:38,代碼來源:GenerateForLoopAssistProposal.java

示例9: getIteratorBasedForBodyAssignment

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
/**
 * Generates the Assignment in an iterator based for, used in the first statement of an iterator
 * based <code>for</code> loop body, to retrieve the next element of the {@link Iterable}
 * instance.
 *
 * @param rewrite the current instance of {@link ASTRewrite}
 * @param loopOverType the {@link ITypeBinding} of the loop variable
 * @param loopVariableName the name of the loop variable
 * @return an {@link Assignment}, which retrieves the next element of the {@link Iterable} using
 *     the active {@link Iterator}
 */
private Assignment getIteratorBasedForBodyAssignment(
    ASTRewrite rewrite, ITypeBinding loopOverType, SimpleName loopVariableName) {
  AST ast = rewrite.getAST();
  Assignment assignResolvedVariable = ast.newAssignment();

  // left hand side
  SimpleName resolvedVariableName =
      resolveLinkedVariableNameWithProposals(
          rewrite, loopOverType.getName(), loopVariableName.getIdentifier(), false);
  VariableDeclarationFragment resolvedVariableDeclarationFragment =
      ast.newVariableDeclarationFragment();
  resolvedVariableDeclarationFragment.setName(resolvedVariableName);
  VariableDeclarationExpression resolvedVariableDeclaration =
      ast.newVariableDeclarationExpression(resolvedVariableDeclarationFragment);
  resolvedVariableDeclaration.setType(
      getImportRewrite()
          .addImport(
              loopOverType,
              ast,
              new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));
  assignResolvedVariable.setLeftHandSide(resolvedVariableDeclaration);

  // right hand side
  MethodInvocation invokeIteratorNextExpression = ast.newMethodInvocation();
  invokeIteratorNextExpression.setName(ast.newSimpleName("next")); // $NON-NLS-1$
  SimpleName currentElementName = ast.newSimpleName(loopVariableName.getIdentifier());
  addLinkedPosition(
      rewrite.track(currentElementName),
      LinkedPositionGroup.NO_STOP,
      currentElementName.getIdentifier());
  invokeIteratorNextExpression.setExpression(currentElementName);
  assignResolvedVariable.setRightHandSide(invokeIteratorNextExpression);

  assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);

  return assignResolvedVariable;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:49,代碼來源:GenerateForLoopAssistProposal.java

示例10: generateIndexBasedForRewrite

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
/**
 * Helper to generate an index based <code>for</code> loop to iterate over a {@link List}
 * implementation.
 *
 * @param ast the current {@link AST} instance to generate the {@link ASTRewrite} for
 * @return an applicable {@link ASTRewrite} instance
 */
private ASTRewrite generateIndexBasedForRewrite(AST ast) {
  ASTRewrite rewrite = ASTRewrite.create(ast);

  ForStatement loopStatement = ast.newForStatement();
  SimpleName loopVariableName =
      resolveLinkedVariableNameWithProposals(rewrite, "int", null, true); // $NON-NLS-1$
  loopStatement.initializers().add(getForInitializer(ast, loopVariableName));

  MethodInvocation listSizeExpression = ast.newMethodInvocation();
  listSizeExpression.setName(ast.newSimpleName("size")); // $NON-NLS-1$
  Expression listExpression = (Expression) rewrite.createCopyTarget(fCurrentExpression);
  listSizeExpression.setExpression(listExpression);

  loopStatement.setExpression(
      getLinkedInfixExpression(
          rewrite,
          loopVariableName.getIdentifier(),
          listSizeExpression,
          InfixExpression.Operator.LESS));
  loopStatement
      .updaters()
      .add(getLinkedIncrementExpression(rewrite, loopVariableName.getIdentifier()));

  Block forLoopBody = ast.newBlock();
  forLoopBody
      .statements()
      .add(ast.newExpressionStatement(getIndexBasedForBodyAssignment(rewrite, loopVariableName)));
  forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));
  loopStatement.setBody(forLoopBody);
  rewrite.replace(fCurrentNode, loopStatement, null);

  return rewrite;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:41,代碼來源:GenerateForLoopAssistProposal.java

示例11: getIndexBasedForBodyAssignment

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
/**
 * Creates an {@link Assignment} as first expression appearing in an index based <code>for</code>
 * loop's body. This Assignment declares a local variable and initializes it using the {@link
 * List}'s current element identified by the loop index.
 *
 * @param rewrite the current {@link ASTRewrite} instance
 * @param loopVariableName the name of the index variable in String representation
 * @return a completed {@link Assignment} containing the mentioned declaration and initialization
 */
private Expression getIndexBasedForBodyAssignment(
    ASTRewrite rewrite, SimpleName loopVariableName) {
  AST ast = rewrite.getAST();
  ITypeBinding loopOverType = extractElementType(ast);

  Assignment assignResolvedVariable = ast.newAssignment();

  // left hand side
  SimpleName resolvedVariableName =
      resolveLinkedVariableNameWithProposals(
          rewrite, loopOverType.getName(), loopVariableName.getIdentifier(), false);
  VariableDeclarationFragment resolvedVariableDeclarationFragment =
      ast.newVariableDeclarationFragment();
  resolvedVariableDeclarationFragment.setName(resolvedVariableName);
  VariableDeclarationExpression resolvedVariableDeclaration =
      ast.newVariableDeclarationExpression(resolvedVariableDeclarationFragment);
  resolvedVariableDeclaration.setType(
      getImportRewrite()
          .addImport(
              loopOverType,
              ast,
              new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));
  assignResolvedVariable.setLeftHandSide(resolvedVariableDeclaration);

  // right hand side
  MethodInvocation invokeGetExpression = ast.newMethodInvocation();
  invokeGetExpression.setName(ast.newSimpleName("get")); // $NON-NLS-1$
  SimpleName indexVariableName = ast.newSimpleName(loopVariableName.getIdentifier());
  addLinkedPosition(
      rewrite.track(indexVariableName),
      LinkedPositionGroup.NO_STOP,
      indexVariableName.getIdentifier());
  invokeGetExpression.arguments().add(indexVariableName);
  invokeGetExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));
  assignResolvedVariable.setRightHandSide(invokeGetExpression);

  assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);

  return assignResolvedVariable;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:50,代碼來源:GenerateForLoopAssistProposal.java

示例12: instrumentStart

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public Statement instrumentStart(final CodeSection codeSection, final AST nodeFactory) {
	final EclipseStatementCreationHelper helper = new EclipseStatementCreationHelper(nodeFactory);
	final MethodInvocation startInvocation = nodeFactory.newMethodInvocation();
	startInvocation.setExpression(helper.getName("de", "uka", "ipd", "sdq", "beagle", "measurement", "kieker",
		"remote", "MeasurementCentral"));
	startInvocation.setName(nodeFactory.newSimpleName("startResourceDemand"));
	startInvocation.arguments().add(nodeFactory.newNumberLiteral("" + this.identifier.getIdOf(codeSection)));
	return nodeFactory.newExpressionStatement(startInvocation);
}
 
開發者ID:Beagle-PSE,項目名稱:Beagle,代碼行數:12,代碼來源:ResourceDemandInstrumentationStrategy.java

示例13: instrumentEnd

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@Override
public Statement instrumentEnd(final CodeSection codeSection, final AST nodeFactory) {
	final EclipseStatementCreationHelper helper = new EclipseStatementCreationHelper(nodeFactory);
	final MethodInvocation endInvocation = nodeFactory.newMethodInvocation();
	endInvocation.setExpression(helper.getName("de", "uka", "ipd", "sdq", "beagle", "measurement", "kieker",
		"remote", "MeasurementCentral"));
	endInvocation.setName(nodeFactory.newSimpleName("stopResourceDemand"));
	return nodeFactory.newExpressionStatement(endInvocation);
}
 
開發者ID:Beagle-PSE,項目名稱:Beagle,代碼行數:10,代碼來源:ResourceDemandInstrumentationStrategy.java

示例14: createCallNodes

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
private ASTNode[] createCallNodes(SnippetFinder.Match duplicate, int modifiers) {
	List<ASTNode> result = new ArrayList<>(2);

	IVariableBinding[] locals = fAnalyzer.getCallerLocals();
	for (int i = 0; i < locals.length; i++) {
		result.add(createDeclaration(locals[i], null));
	}

	MethodInvocation invocation = fAST.newMethodInvocation();
	invocation.setName(fAST.newSimpleName(fMethodName));
	ASTNode typeNode = ASTResolving.findParentType(fAnalyzer.getEnclosingBodyDeclaration());
	RefactoringStatus status = new RefactoringStatus();
	while (fDestination != typeNode) {
		fAnalyzer.checkInput(status, fMethodName, typeNode);
		if (!status.isOK()) {
			SimpleName destinationTypeName = fAST.newSimpleName(ASTNodes.getEnclosingType(fDestination).getName());
			if ((modifiers & Modifier.STATIC) == 0) {
				ThisExpression thisExpression = fAST.newThisExpression();
				thisExpression.setQualifier(destinationTypeName);
				invocation.setExpression(thisExpression);
			} else {
				invocation.setExpression(destinationTypeName);
			}
			break;
		}
		typeNode = typeNode.getParent();
	}

	List<Expression> arguments = invocation.arguments();
	for (int i = 0; i < fParameterInfos.size(); i++) {
		ParameterInfo parameter = fParameterInfos.get(i);
		arguments.add(ASTNodeFactory.newName(fAST, getMappedName(duplicate, parameter)));
	}
	if (fLinkedProposalModel != null) {
		LinkedProposalPositionGroup nameGroup = fLinkedProposalModel.getPositionGroup(KEY_NAME, true);
		nameGroup.addPosition(fRewriter.track(invocation.getName()), false);
	}

	ASTNode call;
	int returnKind = fAnalyzer.getReturnKind();
	switch (returnKind) {
		case ExtractMethodAnalyzer.ACCESS_TO_LOCAL:
			IVariableBinding binding = fAnalyzer.getReturnLocal();
			if (binding != null) {
				VariableDeclarationStatement decl = createDeclaration(getMappedBinding(duplicate, binding), invocation);
				call = decl;
			} else {
				Assignment assignment = fAST.newAssignment();
				assignment.setLeftHandSide(ASTNodeFactory.newName(fAST, getMappedBinding(duplicate, fAnalyzer.getReturnValue()).getName()));
				assignment.setRightHandSide(invocation);
				call = assignment;
			}
			break;
		case ExtractMethodAnalyzer.RETURN_STATEMENT_VALUE:
			ReturnStatement rs = fAST.newReturnStatement();
			rs.setExpression(invocation);
			call = rs;
			break;
		default:
			call = invocation;
	}

	if (call instanceof Expression && !fAnalyzer.isExpressionSelected()) {
		call = fAST.newExpressionStatement((Expression) call);
	}
	result.add(call);

	// We have a void return statement. The code looks like
	// extracted();
	// return;
	if (returnKind == ExtractMethodAnalyzer.RETURN_STATEMENT_VOID && !fAnalyzer.isLastStatementSelected()) {
		result.add(fAST.newReturnStatement());
	}
	return result.toArray(new ASTNode[result.size()]);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:76,代碼來源:ExtractMethodRefactoring.java

示例15: updateMethodInvocation

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
private RefactoringStatus updateMethodInvocation(
    MethodInvocation originalInvocation, IMember enclosing, CompilationUnitRewrite unitRewriter)
    throws JavaModelException {

  RefactoringStatus status = new RefactoringStatus();

  // If the method invocation utilizes type arguments, skip this
  // call as the new target method may have additional parameters
  if (originalInvocation.typeArguments().size() > 0)
    return createWarningAboutCall(
        enclosing,
        originalInvocation,
        RefactoringCoreMessages.IntroduceIndirectionRefactoring_call_warning_type_arguments);

  MethodInvocation newInvocation = unitRewriter.getAST().newMethodInvocation();
  List<Expression> newInvocationArgs = newInvocation.arguments();
  List<Expression> originalInvocationArgs = originalInvocation.arguments();

  // static call => always use a qualifier
  String qualifier = unitRewriter.getImportRewrite().addImport(fIntermediaryTypeBinding);
  newInvocation.setExpression(ASTNodeFactory.newName(unitRewriter.getAST(), qualifier));
  newInvocation.setName(unitRewriter.getAST().newSimpleName(getIntermediaryMethodName()));

  final Expression expression = originalInvocation.getExpression();

  if (!isStaticTarget()) {
    // Add the expression as the first parameter
    if (expression == null) {
      // There is no expression for this call. Use a (possibly qualified) "this" expression.
      ThisExpression expr = unitRewriter.getAST().newThisExpression();
      RefactoringStatus qualifierStatus =
          qualifyThisExpression(expr, originalInvocation, enclosing, unitRewriter);
      status.merge(qualifierStatus);
      if (qualifierStatus.hasEntries())
        // warning means don't include this invocation
        return status;
      newInvocationArgs.add(expr);
    } else {
      Expression expressionAsParam =
          (Expression) unitRewriter.getASTRewrite().createMoveTarget(expression);
      newInvocationArgs.add(expressionAsParam);
    }
  } else {
    if (expression != null) {
      // Check if expression is the type name. If not, there may
      // be side effects (e.g. inside methods) -> don't update
      if (!(expression instanceof Name) || ASTNodes.getTypeBinding((Name) expression) == null)
        return createWarningAboutCall(
            enclosing,
            originalInvocation,
            RefactoringCoreMessages
                .IntroduceIndirectionRefactoring_call_warning_static_expression_access);
    }
  }

  for (int i = 0; i < originalInvocationArgs.size(); i++) {
    Expression originalInvocationArg = originalInvocationArgs.get(i);
    Expression movedArg =
        (Expression) unitRewriter.getASTRewrite().createMoveTarget(originalInvocationArg);
    newInvocationArgs.add(movedArg);
  }

  unitRewriter
      .getASTRewrite()
      .replace(
          originalInvocation,
          newInvocation,
          unitRewriter.createGroupDescription(
              RefactoringCoreMessages
                  .IntroduceIndirectionRefactoring_group_description_replace_call));

  return status;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:74,代碼來源:IntroduceIndirectionRefactoring.java


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