当前位置: 首页>>代码示例>>Java>>正文


Java FieldAccess.setExpression方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.FieldAccess.setExpression方法的典型用法代码示例。如果您正苦于以下问题:Java FieldAccess.setExpression方法的具体用法?Java FieldAccess.setExpression怎么用?Java FieldAccess.setExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.dom.FieldAccess的用法示例。


在下文中一共展示了FieldAccess.setExpression方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createWithMethodBody

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
private Block createWithMethodBody(AST ast, BuilderField builderField) {
    String originalFieldName = builderField.getOriginalFieldName();
    String builderFieldName = builderField.getBuilderFieldName();

    Block newBlock = ast.newBlock();
    ReturnStatement builderReturnStatement = ast.newReturnStatement();
    builderReturnStatement.setExpression(ast.newThisExpression());

    Assignment newAssignment = ast.newAssignment();

    FieldAccess fieldAccess = ast.newFieldAccess();
    fieldAccess.setExpression(ast.newThisExpression());
    fieldAccess.setName(ast.newSimpleName(originalFieldName));
    newAssignment.setLeftHandSide(fieldAccess);
    newAssignment.setRightHandSide(ast.newSimpleName(builderFieldName));

    newBlock.statements().add(ast.newExpressionStatement(newAssignment));
    newBlock.statements().add(builderReturnStatement);
    return newBlock;
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:21,代码来源:StagedBuilderWithMethodAdderFragment.java

示例2: createWithMethodBody

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
private Block createWithMethodBody(AST ast, String originalFieldName, String builderFieldName) {
    Block newBlock = ast.newBlock();
    ReturnStatement builderReturnStatement = ast.newReturnStatement();
    builderReturnStatement.setExpression(ast.newThisExpression());

    Assignment newAssignment = ast.newAssignment();

    FieldAccess fieldAccess = ast.newFieldAccess();
    fieldAccess.setExpression(ast.newThisExpression());
    fieldAccess.setName(ast.newSimpleName(originalFieldName));
    newAssignment.setLeftHandSide(fieldAccess);
    newAssignment.setRightHandSide(ast.newSimpleName(builderFieldName));

    newBlock.statements().add(ast.newExpressionStatement(newAssignment));
    newBlock.statements().add(builderReturnStatement);
    return newBlock;
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:18,代码来源:RegularBuilderWithMethodAdderFragment.java

示例3: rewriteAST

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model)
    throws CoreException {
  ASTRewrite rewrite = cuRewrite.getASTRewrite();
  TextEditGroup group = createTextEditGroup(getDescription(), cuRewrite);
  AST ast = rewrite.getAST();

  FieldAccess fieldAccess = ast.newFieldAccess();

  ThisExpression thisExpression = ast.newThisExpression();
  if (fQualifier != null) thisExpression.setQualifier(ast.newName(fQualifier));

  fieldAccess.setExpression(thisExpression);
  fieldAccess.setName((SimpleName) rewrite.createMoveTarget(fName));

  rewrite.replace(fName, fieldAccess, group);
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:CodeStyleFix.java

示例4: newFieldAssignment

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
private Statement newFieldAssignment(
    AST ast, SimpleName fieldNameNode, Expression initializer, boolean useThisAccess) {
  Assignment assignment = ast.newAssignment();
  if (useThisAccess) {
    FieldAccess access = ast.newFieldAccess();
    access.setExpression(ast.newThisExpression());
    access.setName(fieldNameNode);
    assignment.setLeftHandSide(access);
  } else {
    assignment.setLeftHandSide(fieldNameNode);
  }
  assignment.setOperator(Assignment.Operator.ASSIGN);
  assignment.setRightHandSide(initializer);

  return ast.newExpressionStatement(assignment);
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:ConvertAnonymousToNestedRefactoring.java

示例5: visit

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
@Override
public boolean visit(final ClassInstanceCreation node) {
	Assert.isNotNull(node);
	if (fCreateInstanceField) {
		final AST ast= node.getAST();
		final Type type= node.getType();
		final ITypeBinding binding= type.resolveBinding();
		if (binding != null && binding.getDeclaringClass() != null && !Bindings.equals(binding, fTypeBinding) && fSourceRewrite.getRoot().findDeclaringNode(binding) != null) {
			if (!Modifier.isStatic(binding.getModifiers())) {
				Expression expression= null;
				if (fCodeGenerationSettings.useKeywordThis || fEnclosingInstanceFieldName.equals(fNameForEnclosingInstanceConstructorParameter)) {
					final FieldAccess access= ast.newFieldAccess();
					access.setExpression(ast.newThisExpression());
					access.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
					expression= access;
				} else
					expression= ast.newSimpleName(fEnclosingInstanceFieldName);
				if (node.getExpression() != null)
					fSourceRewrite.getImportRemover().registerRemovedNode(node.getExpression());
				fSourceRewrite.getASTRewrite().set(node, ClassInstanceCreation.EXPRESSION_PROPERTY, expression, fGroup);
			} else
				addTypeQualification(type, fSourceRewrite, fGroup);
		}
	}
	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:MoveInnerToTopRefactoring.java

示例6: generateQualifier

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
private Expression generateQualifier(String paramName, AST ast, boolean useSuper, Expression qualifier) {
	SimpleName paramSimpleName= ast.newSimpleName(paramName);
	if (useSuper) {
		SuperFieldAccess sf= ast.newSuperFieldAccess();
		sf.setName(paramSimpleName);
		if (qualifier instanceof Name) {
			sf.setQualifier((Name) qualifier);
		}
		return sf;
	}
	if (qualifier != null) {
		FieldAccess parameterAccess= ast.newFieldAccess();
		parameterAccess.setExpression(qualifier);
		parameterAccess.setName(paramSimpleName);
		return parameterAccess;
	}
	return paramSimpleName;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:19,代码来源:ParameterObjectFactory.java

示例7: generateForRewrite

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
/**
 * Helper to generate an index based <code>for</code> loop to iterate over an array.
 * 
 * @param ast the current {@link AST} instance to generate the {@link ASTRewrite} for
 * @return an applicable {@link ASTRewrite} instance
 */
private ASTRewrite generateForRewrite(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));

	FieldAccess getArrayLengthExpression= ast.newFieldAccess();
	getArrayLengthExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));
	getArrayLengthExpression.setName(ast.newSimpleName("length")); //$NON-NLS-1$

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

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

	return rewrite;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:29,代码来源:GenerateForLoopAssistProposal.java

示例8: createNoSideEffectProposal

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
private static ASTRewriteCorrectionProposal createNoSideEffectProposal(IInvocationContext context, SimpleName nodeToQualify, IVariableBinding fieldBinding, String label, int relevance) {
	AST ast= nodeToQualify.getAST();

	Expression qualifier;
	if (Modifier.isStatic(fieldBinding.getModifiers())) {
		ITypeBinding declaringClass= fieldBinding.getDeclaringClass();
		qualifier= ast.newSimpleName(declaringClass.getTypeDeclaration().getName());
	} else {
		qualifier= ast.newThisExpression();
	}

	ASTRewrite rewrite= ASTRewrite.create(ast);
	FieldAccess access= ast.newFieldAccess();
	access.setName((SimpleName) rewrite.createCopyTarget(nodeToQualify));
	access.setExpression(qualifier);
	rewrite.replace(nodeToQualify, access, null);


	Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
	return new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, relevance, image);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:LocalCorrectionsSubProcessor.java

示例9: rewriteAST

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
	ASTRewrite rewrite= cuRewrite.getASTRewrite();
	TextEditGroup group= createTextEditGroup(getDescription(), cuRewrite);
	AST ast= rewrite.getAST();

	FieldAccess fieldAccess= ast.newFieldAccess();

	ThisExpression thisExpression= ast.newThisExpression();
	if (fQualifier != null)
		thisExpression.setQualifier(ast.newName(fQualifier));

	fieldAccess.setExpression(thisExpression);
	fieldAccess.setName((SimpleName) rewrite.createMoveTarget(fName));

	rewrite.replace(fName, fieldAccess, group);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:CodeStyleFix.java

示例10: updateAndMoveBodyDeclarations

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
private void updateAndMoveBodyDeclarations(
    CompilationUnitRewrite rewriter,
    IVariableBinding[] bindings,
    String[] fieldNames,
    List<BodyDeclaration> newBodyDeclarations,
    MethodDeclaration newConstructorDecl) {
  final ASTRewrite astRewrite = rewriter.getASTRewrite();
  final AST ast = astRewrite.getAST();

  final boolean useThisAccess = useThisForFieldAccess();

  int fieldInsertIndex =
      newConstructorDecl != null
          ? newBodyDeclarations.lastIndexOf(newConstructorDecl)
          : newBodyDeclarations.size();

  for (Iterator<BodyDeclaration> iterator =
          fAnonymousInnerClassNode.bodyDeclarations().iterator();
      iterator.hasNext(); ) {
    BodyDeclaration body = iterator.next();

    for (int i = 0; i < bindings.length; i++) {
      SimpleName[] names = LinkedNodeFinder.findByBinding(body, bindings[i]);
      String fieldName = fieldNames[i];
      for (int k = 0; k < names.length; k++) {
        SimpleName newNode = ast.newSimpleName(fieldName);
        if (useThisAccess) {
          FieldAccess access = ast.newFieldAccess();
          access.setExpression(ast.newThisExpression());
          access.setName(newNode);
          astRewrite.replace(names[k], access, null);
        } else {
          astRewrite.replace(names[k], newNode, null);
        }
        addLinkedPosition(KEY_FIELD_NAME_EXT + i, newNode, astRewrite, false);
      }
    }
    if (body instanceof Initializer || body instanceof FieldDeclaration) {
      newBodyDeclarations.add(
          fieldInsertIndex++, (BodyDeclaration) astRewrite.createMoveTarget(body));
    } else {
      newBodyDeclarations.add((BodyDeclaration) astRewrite.createMoveTarget(body));
    }
  }

  if (newConstructorDecl != null) {
    // move initialization of existing fields to constructor if an outer is referenced
    List<Statement> bodyStatements = newConstructorDecl.getBody().statements();

    List<VariableDeclarationFragment> fieldsToInitializeInConstructor =
        getFieldsToInitializeInConstructor();
    for (Iterator<VariableDeclarationFragment> iter = fieldsToInitializeInConstructor.iterator();
        iter.hasNext(); ) {
      VariableDeclarationFragment fragment = iter.next();
      Expression initializer = fragment.getInitializer();
      Expression replacement =
          (Expression) astRewrite.get(fragment, VariableDeclarationFragment.INITIALIZER_PROPERTY);
      if (replacement == initializer) {
        replacement = (Expression) astRewrite.createMoveTarget(initializer);
      }
      astRewrite.remove(initializer, null);
      SimpleName fieldNameNode = ast.newSimpleName(fragment.getName().getIdentifier());
      bodyStatements.add(newFieldAssignment(ast, fieldNameNode, replacement, useThisAccess));
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:67,代码来源:ConvertAnonymousToNestedRefactoring.java

示例11: generateForRewrite

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
/**
 * Helper to generate an index based <code>for</code> loop to iterate over an array.
 *
 * @param ast the current {@link AST} instance to generate the {@link ASTRewrite} for
 * @return an applicable {@link ASTRewrite} instance
 */
private ASTRewrite generateForRewrite(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));

  FieldAccess getArrayLengthExpression = ast.newFieldAccess();
  getArrayLengthExpression.setExpression(
      (Expression) rewrite.createCopyTarget(fCurrentExpression));
  getArrayLengthExpression.setName(ast.newSimpleName("length")); // $NON-NLS-1$

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

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

  return rewrite;
}
 
开发者ID:eclipse,项目名称:che,代码行数:40,代码来源:GenerateForLoopAssistProposal.java

示例12: createQualifiedReadAccessExpressionForEnclosingInstance

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
private Expression createQualifiedReadAccessExpressionForEnclosingInstance(AST ast) {
	ThisExpression expression= ast.newThisExpression();
	expression.setQualifier(ast.newName(new String[] { fType.getElementName()}));
	FieldAccess access= ast.newFieldAccess();
	access.setExpression(expression);
	access.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
	return access;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:9,代码来源:MoveInnerToTopRefactoring.java

示例13: createReadAccessExpressionForEnclosingInstance

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
private Expression createReadAccessExpressionForEnclosingInstance(AST ast) {
	if (fCodeGenerationSettings.useKeywordThis || fEnclosingInstanceFieldName.equals(fNameForEnclosingInstanceConstructorParameter)) {
		final FieldAccess access= ast.newFieldAccess();
		access.setExpression(ast.newThisExpression());
		access.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
		return access;
	}
	return ast.newSimpleName(fEnclosingInstanceFieldName);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:10,代码来源:MoveInnerToTopRefactoring.java

示例14: getFieldReference

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
private ASTNode getFieldReference(SimpleName oldNameNode, ASTRewrite rewrite) {
	String name= oldNameNode.getIdentifier();
	AST ast= rewrite.getAST();
	if (isParameterName(name) || StubUtility.useThisForFieldAccess(fTargetRewrite.getCu().getJavaProject())) {
		FieldAccess fieldAccess= ast.newFieldAccess();
		fieldAccess.setExpression(ast.newThisExpression());
		fieldAccess.setName((SimpleName) rewrite.createMoveTarget(oldNameNode));
		return fieldAccess;
	}
	return rewrite.createMoveTarget(oldNameNode);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:12,代码来源:MoveInstanceMethodProcessor.java

示例15: createFieldAccess

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
private Expression createFieldAccess(ParameterInfo pi, AST ast, Expression qualifier) {
	if (qualifier instanceof Name) {
		Name name= (Name) qualifier; //create FQN for IPOR
		return ast.newName(JavaModelUtil.concatenateName(name.getFullyQualifiedName(), pi.getNewName()));
	}
	FieldAccess fa= ast.newFieldAccess();
	fa.setName(ast.newSimpleName(pi.getNewName()));
	fa.setExpression(qualifier);
	return fa;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:11,代码来源:ParameterObjectFactory.java


注:本文中的org.eclipse.jdt.core.dom.FieldAccess.setExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。