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


Java FieldAccess.getExpression方法代码示例

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


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

示例1: rewrite

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
protected void rewrite(FieldAccess node, ITypeBinding type) {
	Expression exp= node.getExpression();
	if (exp == null) {
		ImportRewriteContext context= new ContextSensitiveImportRewriteContext(node, fCuRewrite.getImportRewrite());
		Type result= fCuRewrite.getImportRewrite().addImport(type, fCuRewrite.getAST(), context);
		fCuRewrite.getImportRemover().registerAddedImport(type.getQualifiedName());
		exp= ASTNodeFactory.newName(fCuRewrite.getAST(), ASTFlattener.asString(result));
		fCuRewrite.getASTRewrite().set(node, FieldAccess.EXPRESSION_PROPERTY, exp,  fCuRewrite.createGroupDescription(REFERENCE_UPDATE));
		fNeedsImport= true;
	} else if (exp instanceof Name) {
		rewriteName((Name)exp, type);
	} else {
		rewriteExpression(node, exp, type);
	}
	fProcessed.add(node.getName());
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:MoveStaticMemberAnalyzer.java

示例2: visit

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
@Override
public boolean visit(FieldAccess node) {
	IBinding binding= node.resolveFieldBinding();
	if (isSourceAccess(binding)) {
		if (isMovedMember(binding)) {
			if (node.getExpression() != null)
				rewrite(node, fTarget);
		} else
			rewrite(node, fSource);

	} else if (isTargetAccess(binding)) {
		fCuRewrite.getASTRewrite().remove(node.getExpression(), null);
		fCuRewrite.getImportRemover().registerRemovedNode(node.getExpression());
	}
	return super.visit(node);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:MovedMemberAnalyzer.java

示例3: isTargetAccess

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
/**
 * Is the specified name a target access?
 *
 * @param name
 *            the name to check
 * @return <code>true</code> if this name is a target access,
 *         <code>false</code> otherwise
 */
protected boolean isTargetAccess(final Name name) {
	Assert.isNotNull(name);
	final IBinding binding= name.resolveBinding();
	if (Bindings.equals(fTarget, binding))
		return true;
	if (name.getParent() instanceof FieldAccess) {
		final FieldAccess access= (FieldAccess) name.getParent();
		final Expression expression= access.getExpression();
		if (expression instanceof Name)
			return isTargetAccess((Name) expression);
	} else if (name instanceof QualifiedName) {
		final QualifiedName qualified= (QualifiedName) name;
		if (qualified.getQualifier() != null)
			return isTargetAccess(qualified.getQualifier());
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:MoveInstanceMethodProcessor.java

示例4: visit

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
@Override
public boolean visit(FieldAccess node) {
	Expression exp = node.getExpression();
	if (exp != null) {
		fIgnore.add(node.getName());
	}
	return true;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:9,代码来源:ExtractMethodRefactoring.java

示例5: createToStaticAccessOperations

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
private static ToStaticAccessOperation[] createToStaticAccessOperations(
    CompilationUnit astRoot,
    HashMap<ASTNode, Block> createdBlocks,
    IProblemLocation problem,
    boolean conservative) {
  ASTNode selectedNode = problem.getCoveringNode(astRoot);
  if (selectedNode == null) {
    return null;
  }

  Expression qualifier = null;
  IBinding accessBinding = null;

  if (selectedNode instanceof SimpleName) {
    selectedNode = selectedNode.getParent();
  }
  if (selectedNode instanceof QualifiedName) {
    QualifiedName name = (QualifiedName) selectedNode;
    qualifier = name.getQualifier();
    accessBinding = name.resolveBinding();
  } else if (selectedNode instanceof MethodInvocation) {
    MethodInvocation methodInvocation = (MethodInvocation) selectedNode;
    qualifier = methodInvocation.getExpression();
    accessBinding = methodInvocation.getName().resolveBinding();
  } else if (selectedNode instanceof FieldAccess) {
    FieldAccess fieldAccess = (FieldAccess) selectedNode;
    qualifier = fieldAccess.getExpression();
    accessBinding = fieldAccess.getName().resolveBinding();
  }

  if (accessBinding != null && qualifier != null) {
    if (conservative && ASTResolving.findParentStatement(qualifier) == null) return null;

    ToStaticAccessOperation declaring = null;
    ITypeBinding declaringTypeBinding = getDeclaringTypeBinding(accessBinding);
    if (declaringTypeBinding != null) {
      declaringTypeBinding =
          declaringTypeBinding.getTypeDeclaration(); // use generic to avoid any type arguments

      declaring = new ToStaticAccessOperation(declaringTypeBinding, qualifier, createdBlocks);
    }
    ToStaticAccessOperation instance = null;
    ITypeBinding instanceTypeBinding =
        Bindings.normalizeTypeBinding(qualifier.resolveTypeBinding());
    if (instanceTypeBinding != null) {
      instanceTypeBinding =
          instanceTypeBinding.getTypeDeclaration(); // use generic to avoid any type arguments
      if (instanceTypeBinding.getTypeDeclaration() != declaringTypeBinding) {
        instance = new ToStaticAccessOperation(instanceTypeBinding, qualifier, createdBlocks);
      }
    }
    if (declaring != null && instance != null) {
      return new ToStaticAccessOperation[] {declaring, instance};
    } else {
      return new ToStaticAccessOperation[] {declaring};
    }
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:60,代码来源:CodeStyleFix.java

示例6: create

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
@Override
public ITypeConstraint[] create(FieldAccess access) {
  Expression expression = access.getExpression();
  SimpleName name = access.getName();
  IBinding binding = name.resolveBinding();
  if (!(binding instanceof IVariableBinding)) return new ITypeConstraint[0];
  IVariableBinding vb = (IVariableBinding) binding;
  return createConstraintsForAccessToField(vb, expression, access);
}
 
开发者ID:eclipse,项目名称:che,代码行数:10,代码来源:FullConstraintCreator.java

示例7: visit

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
@Override
public final boolean visit(final FieldAccess node) {
	Assert.isNotNull(node);
	final Expression expression= node.getExpression();
	final IVariableBinding variable= node.resolveFieldBinding();
	final AST ast= fRewrite.getAST();
	if (expression instanceof ThisExpression) {
		if (Bindings.equals(fTarget, variable)) {
			if (fAnonymousClass > 0) {
				final ThisExpression target= ast.newThisExpression();
				target.setQualifier(ast.newSimpleName(fTargetType.getElementName()));
				fRewrite.replace(node, target, null);
			} else
				fRewrite.replace(node, ast.newThisExpression(), null);
			return false;
		} else {
			expression.accept(this);
			return false;
		}
	} else if (expression instanceof FieldAccess) {
		final FieldAccess access= (FieldAccess) expression;
		final IBinding binding= access.getName().resolveBinding();
		if (access.getExpression() instanceof ThisExpression && Bindings.equals(fTarget, binding)) {
			ASTNode newFieldAccess= getFieldReference(node.getName(), fRewrite);
			fRewrite.replace(node, newFieldAccess, null);
			return false;
		}
	} else if (expression != null) {
		expression.accept(this);
		return false;
	}
	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:34,代码来源:MoveInstanceMethodProcessor.java

示例8: visit

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
@Override
public boolean visit(FieldAccess node) {
	Expression exp= node.getExpression();
	if (exp != null)
		fIgnore.add(node.getName());
	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:8,代码来源:ExtractMethodRefactoring.java

示例9: create

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
@Override
public ITypeConstraint[] create(FieldAccess access){
	Expression expression= access.getExpression();
	SimpleName name= access.getName();
	IBinding binding= name.resolveBinding();
	if (! (binding instanceof IVariableBinding))
		return new ITypeConstraint[0];
	IVariableBinding vb= (IVariableBinding)binding;
	return createConstraintsForAccessToField(vb, expression, access);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:11,代码来源:FullConstraintCreator.java

示例10: acceptSearchMatch

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
@SuppressWarnings("restriction")
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
	if (match.isInsideDocComment())
		return;

	// get the AST node corresponding to the field
	// access. It should be some kind of name
	// (simple of qualified).
	ASTNode node = ASTNodeSearchUtil.getAstNode(match,
			processor.getCompilationUnit(((IMember) match.getElement()).getTypeRoot(),
					new SubProgressMonitor(monitor.orElseGet(NullProgressMonitor::new), IProgressMonitor.UNKNOWN)));

	// examine the node's parent.
	ASTNode parent = node.getParent();

	switch (parent.getNodeType()) {
	case ASTNode.FIELD_ACCESS: {
		FieldAccess fieldAccess = (FieldAccess) parent;

		// the expression is the LHS of the
		// selection operator.
		Expression expression = fieldAccess.getExpression();

		if (expression == null || expression.getNodeType() == ASTNode.THIS_EXPRESSION)
			// either there is nothing on the LHS
			// or it's this, in which case we fail.
			this.accessesFieldsFromImplicitParameter = true;
		break;
	}
	case ASTNode.SUPER_FIELD_ACCESS: {
		// super will also tell us that it's an
		// instance field access of this.
		this.accessesFieldsFromImplicitParameter = true;
		break;
	}
	default: {
		// it must be an unqualified field access,
		// meaning that it's an instance field access of this.
		this.accessesFieldsFromImplicitParameter = true;
	}
	}
}
 
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:44,代码来源:FieldAccessAnalysisSearchRequestor.java

示例11: visit

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public boolean visit(final FieldAccess node) {
  if (!fRemoveFieldQualifiers) return true;

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

  final SimpleName name = node.getName();
  if (hasConflict(
      expression.getStartPosition(),
      name,
      ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY)) return true;

  Name qualifier = ((ThisExpression) expression).getQualifier();
  if (qualifier != null) {
    ITypeBinding outerClass = (ITypeBinding) qualifier.resolveBinding();
    if (outerClass == null) return true;

    IVariableBinding nameBinding = (IVariableBinding) name.resolveBinding();
    if (nameBinding == null) return true;

    ITypeBinding variablesDeclaringClass = nameBinding.getDeclaringClass();
    if (outerClass != variablesDeclaringClass)
      // be conservative: We have a reference to a field of an outer type, and this type
      // inherited
      // the field. It's possible that the inner type inherits the same field. We must not
      // remove
      // the qualifier in this case.
      return true;

    ITypeBinding enclosingTypeBinding = Bindings.getBindingOfParentType(node);
    if (enclosingTypeBinding == null
        || Bindings.isSuperType(variablesDeclaringClass, enclosingTypeBinding))
      // We have a reference to a field of an outer type, and this type inherited
      // the field. The inner type inherits the same field. We must not remove
      // the qualifier in this case.
      return true;
  }

  fOperations.add(
      new CompilationUnitRewriteOperation() {
        @Override
        public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model)
            throws CoreException {
          ASTRewrite rewrite = cuRewrite.getASTRewrite();
          TextEditGroup group =
              createTextEditGroup(
                  FixMessages.CodeStyleFix_removeThis_groupDescription, cuRewrite);
          rewrite.replace(node, rewrite.createCopyTarget(name), group);
        }
      });
  return super.visit(node);
}
 
开发者ID:eclipse,项目名称:che,代码行数:55,代码来源:CodeStyleFix.java

示例12: visit

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
@Override
public boolean visit(FieldAccess node) {
  Expression exp = node.getExpression();
  if (exp != null) fIgnore.add(node.getName());
  return true;
}
 
开发者ID:eclipse,项目名称:che,代码行数:7,代码来源:ExtractMethodRefactoring.java

示例13: visit

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public boolean visit(final FieldAccess node) {
	if (!fRemoveFieldQualifiers)
		return true;

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

	final SimpleName name= node.getName();
	if (hasConflict(expression.getStartPosition(), name, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY))
		return true;

	Name qualifier= ((ThisExpression) expression).getQualifier();
	if (qualifier != null) {
		ITypeBinding outerClass= (ITypeBinding) qualifier.resolveBinding();
		if (outerClass == null)
			return true;

		IVariableBinding nameBinding= (IVariableBinding) name.resolveBinding();
		if (nameBinding == null)
			return true;

		ITypeBinding variablesDeclaringClass= nameBinding.getDeclaringClass();
		if (outerClass != variablesDeclaringClass)
			//be conservative: We have a reference to a field of an outer type, and this type inherited
			//the field. It's possible that the inner type inherits the same field. We must not remove
			//the qualifier in this case.
			return true;
		
		ITypeBinding enclosingTypeBinding= Bindings.getBindingOfParentType(node);
		if (enclosingTypeBinding == null || Bindings.isSuperType(variablesDeclaringClass, enclosingTypeBinding))
			//We have a reference to a field of an outer type, and this type inherited
			//the field. The inner type inherits the same field. We must not remove
			//the qualifier in this case.
			return true;
	}

	fOperations.add(new CompilationUnitRewriteOperation() {
		@Override
		public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
			ASTRewrite rewrite= cuRewrite.getASTRewrite();
			TextEditGroup group= createTextEditGroup(FixMessages.CodeStyleFix_removeThis_groupDescription, cuRewrite);
			rewrite.replace(node, rewrite.createCopyTarget(name), group);
		}
	});
	return super.visit(node);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:52,代码来源:CodeStyleFix.java

示例14: createToStaticAccessOperations

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
private static ToStaticAccessOperation[] createToStaticAccessOperations(CompilationUnit astRoot, HashMap<ASTNode, Block> createdBlocks, IProblemLocation problem, boolean conservative) {
	ASTNode selectedNode= problem.getCoveringNode(astRoot);
	if (selectedNode == null) {
		return null;
	}

	Expression qualifier= null;
	IBinding accessBinding= null;

	if (selectedNode instanceof SimpleName) {
		selectedNode= selectedNode.getParent();
	}
	if (selectedNode instanceof QualifiedName) {
		QualifiedName name= (QualifiedName) selectedNode;
		qualifier= name.getQualifier();
		accessBinding= name.resolveBinding();
	} else if (selectedNode instanceof MethodInvocation) {
		MethodInvocation methodInvocation= (MethodInvocation) selectedNode;
		qualifier= methodInvocation.getExpression();
		accessBinding= methodInvocation.getName().resolveBinding();
	} else if (selectedNode instanceof FieldAccess) {
		FieldAccess fieldAccess= (FieldAccess) selectedNode;
		qualifier= fieldAccess.getExpression();
		accessBinding= fieldAccess.getName().resolveBinding();
	}

	if (accessBinding != null && qualifier != null) {
		if (conservative && ASTResolving.findParentStatement(qualifier) == null)
			return null;
		
		ToStaticAccessOperation declaring= null;
		ITypeBinding declaringTypeBinding= getDeclaringTypeBinding(accessBinding);
		if (declaringTypeBinding != null) {
			declaringTypeBinding= declaringTypeBinding.getTypeDeclaration(); // use generic to avoid any type arguments

			declaring= new ToStaticAccessOperation(declaringTypeBinding, qualifier, createdBlocks);
		}
		ToStaticAccessOperation instance= null;
		ITypeBinding instanceTypeBinding= Bindings.normalizeTypeBinding(qualifier.resolveTypeBinding());
		if (instanceTypeBinding != null) {
			instanceTypeBinding= instanceTypeBinding.getTypeDeclaration();  // use generic to avoid any type arguments
			if (instanceTypeBinding.getTypeDeclaration() != declaringTypeBinding) {
				instance= new ToStaticAccessOperation(instanceTypeBinding, qualifier, createdBlocks);
			}
		}
		if (declaring != null && instance != null) {
			return new ToStaticAccessOperation[] {declaring, instance};
		} else {
			return new ToStaticAccessOperation[] {declaring};
		}
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:54,代码来源:CodeStyleFix.java

示例15: isThisFieldAccess

import org.eclipse.jdt.core.dom.FieldAccess; //导入方法依赖的package包/类
private boolean isThisFieldAccess(FieldAccess access, String fieldName) {
    return (access.getExpression() instanceof ThisExpression) && access.getName().getIdentifier().equals(fieldName);
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:4,代码来源:CreateMutableCloneResolution.java


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