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

项目: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;
}
项目:che    文件:CodeStyleFix.java   
private void handleSimpleName(SimpleName node) {
  ASTNode firstExpression = node.getParent();
  if (firstExpression instanceof FieldAccess) {
    while (firstExpression instanceof FieldAccess) {
      firstExpression = ((FieldAccess) firstExpression).getExpression();
    }
    if (!(firstExpression instanceof SimpleName)) return;

    node = (SimpleName) firstExpression;
  } else if (firstExpression instanceof SuperFieldAccess) return;

  StructuralPropertyDescriptor parentDescription = node.getLocationInParent();
  if (parentDescription == VariableDeclarationFragment.NAME_PROPERTY
      || parentDescription == SwitchCase.EXPRESSION_PROPERTY) return;

  IBinding binding = node.resolveBinding();
  if (!(binding instanceof IVariableBinding)) return;

  handleVariable(node, (IVariableBinding) binding);
}
项目:SparkBuilderGenerator    文件:StagedBuilderWithMethodAdderFragment.java   
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;
}
项目:SparkBuilderGenerator    文件:RegularBuilderWithMethodAdderFragment.java   
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;
}
项目:eclipse.jdt.ls    文件:Bindings.java   
/**
 * Returns the binding of the variable written in an Assignment.
 * @param assignment The assignment
 * @return The binding or <code>null</code> if no bindings are available.
 */
public static IVariableBinding getAssignedVariable(Assignment assignment) {
    Expression leftHand = assignment.getLeftHandSide();
    switch (leftHand.getNodeType()) {
    case ASTNode.SIMPLE_NAME:
        return (IVariableBinding) ((SimpleName) leftHand).resolveBinding();
    case ASTNode.QUALIFIED_NAME:
        return (IVariableBinding) ((QualifiedName) leftHand).getName().resolveBinding();
    case ASTNode.FIELD_ACCESS:
        return ((FieldAccess) leftHand).resolveFieldBinding();
    case ASTNode.SUPER_FIELD_ACCESS:
        return ((SuperFieldAccess) leftHand).resolveFieldBinding();
    default:
        return null;
    }
}
项目: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    文件:SnippetFinder.java   
static boolean isLeftHandSideOfAssignment(ASTNode node) {
    Assignment assignment = (Assignment) ASTNodes.getParent(node, ASTNode.ASSIGNMENT);
    if (assignment != null) {
        Expression leftHandSide = assignment.getLeftHandSide();
        if (leftHandSide == node) {
            return true;
        }
        if (ASTNodes.isParent(node, leftHandSide)) {
            switch (leftHandSide.getNodeType()) {
                case ASTNode.SIMPLE_NAME:
                    return true;
                case ASTNode.FIELD_ACCESS:
                    return node == ((FieldAccess) leftHandSide).getName();
                case ASTNode.QUALIFIED_NAME:
                    return node == ((QualifiedName) leftHandSide).getName();
                case ASTNode.SUPER_FIELD_ACCESS:
                    return node == ((SuperFieldAccess) leftHandSide).getName();
                default:
                    return false;
            }
        }
    }
    return false;
}
项目: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;
}
项目:code    文件:Utils.java   
/**
 * for an assignment x = y returns the variable binding of x
 * 
 * @param varBinding
 * @param assignment
 * @return
 */
private static IVariableBinding getLeftHandSideVarBinding(Assignment assignment) {
    Expression leftHnsd = assignment.getLeftHandSide();
    if (leftHnsd instanceof SimpleName) {
        IBinding bind = ((SimpleName) leftHnsd).resolveBinding();
        if (bind instanceof IVariableBinding) {
            return ((IVariableBinding) bind).getVariableDeclaration();
        }
    }
    if (leftHnsd instanceof FieldAccess) {
        FieldAccess fa = (FieldAccess) leftHnsd;
        return fa.resolveFieldBinding();
    }
    // Leave it null - cannot determine actual domains for arrays
    // workaround for bugs related to objects created in complex expression
    // if (leftHnsd instanceof ArrayAccess) {
    // ArrayAccess aa = (ArrayAccess) leftHnsd;
    // return getArrayAccessVarBinding(aa);
    // }
    return null;
}
项目:code    文件:Utils.java   
/**
 * returns the name associated with an assignment instruction
 * 
 * @param instr
 * @return
 */
public static String getSimpleAssignName(AssignmentInstruction instr) {
    if (instr instanceof LoadLiteralInstruction)
        return ((LoadLiteralInstruction) instr).getLiteral().toString();
    ASTNode parentInstr = instr.getNode().getParent();

    if (parentInstr instanceof VariableDeclarationFragment) {
        return ((VariableDeclarationFragment) parentInstr).getName().getFullyQualifiedName();
    }
    if (parentInstr instanceof Assignment) {
        Expression leftHnsd = ((Assignment) parentInstr).getLeftHandSide();
        if (leftHnsd instanceof SimpleName) {
            return ((SimpleName) leftHnsd).getFullyQualifiedName();
        }
        else if (leftHnsd instanceof FieldAccess) {
            return ((FieldAccess) leftHnsd).getName().getFullyQualifiedName();
        }
    }
    throw new IllegalStateException("cannot find local variable associated with " + instr);
}
项目: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);
}
项目:che    文件:Bindings.java   
/**
 * Returns the binding of the variable written in an Assignment.
 *
 * @param assignment The assignment
 * @return The binding or <code>null</code> if no bindings are available.
 */
public static IVariableBinding getAssignedVariable(Assignment assignment) {
  Expression leftHand = assignment.getLeftHandSide();
  switch (leftHand.getNodeType()) {
    case ASTNode.SIMPLE_NAME:
      return (IVariableBinding) ((SimpleName) leftHand).resolveBinding();
    case ASTNode.QUALIFIED_NAME:
      return (IVariableBinding) ((QualifiedName) leftHand).getName().resolveBinding();
    case ASTNode.FIELD_ACCESS:
      return ((FieldAccess) leftHand).resolveFieldBinding();
    case ASTNode.SUPER_FIELD_ACCESS:
      return ((SuperFieldAccess) leftHand).resolveFieldBinding();
    default:
      return null;
  }
}
项目:che    文件:CodeStyleFix.java   
/** {@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);
}
项目:che    文件:ConvertAnonymousToNestedRefactoring.java   
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);
}
项目:che    文件:SnippetFinder.java   
private static boolean isLeftHandSideOfAssignment(ASTNode node) {
  Assignment assignment = (Assignment) ASTNodes.getParent(node, ASTNode.ASSIGNMENT);
  if (assignment != null) {
    Expression leftHandSide = assignment.getLeftHandSide();
    if (leftHandSide == node) {
      return true;
    }
    if (ASTNodes.isParent(node, leftHandSide)) {
      switch (leftHandSide.getNodeType()) {
        case ASTNode.SIMPLE_NAME:
          return true;
        case ASTNode.FIELD_ACCESS:
          return node == ((FieldAccess) leftHandSide).getName();
        case ASTNode.QUALIFIED_NAME:
          return node == ((QualifiedName) leftHandSide).getName();
        case ASTNode.SUPER_FIELD_ACCESS:
          return node == ((SuperFieldAccess) leftHandSide).getName();
        default:
          return false;
      }
    }
  }
  return false;
}
项目:che    文件:InlineConstantRefactoring.java   
private Name findConstantNameNode() {
  ASTNode node =
      NodeFinder.perform(fSelectionCuRewrite.getRoot(), fSelectionStart, fSelectionLength);
  if (node == null) return null;
  if (node instanceof FieldAccess) node = ((FieldAccess) node).getName();
  if (!(node instanceof Name)) return null;
  Name name = (Name) node;
  IBinding binding = name.resolveBinding();
  if (!(binding instanceof IVariableBinding)) return null;
  IVariableBinding variableBinding = (IVariableBinding) binding;
  if (!variableBinding.isField() || variableBinding.isEnumConstant()) return null;
  int modifiers = binding.getModifiers();
  if (!(Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers))) return null;

  return name;
}
项目:che    文件:ExpressionVariable.java   
public static IBinding resolveBinding(Expression expression) {
  if (expression instanceof Name) return ((Name) expression).resolveBinding();
  if (expression instanceof ParenthesizedExpression)
    return resolveBinding(((ParenthesizedExpression) expression).getExpression());
  else if (expression instanceof Assignment)
    return resolveBinding(((Assignment) expression).getLeftHandSide()); // TODO ???
  else if (expression instanceof MethodInvocation)
    return ((MethodInvocation) expression).resolveMethodBinding();
  else if (expression instanceof SuperMethodInvocation)
    return ((SuperMethodInvocation) expression).resolveMethodBinding();
  else if (expression instanceof FieldAccess)
    return ((FieldAccess) expression).resolveFieldBinding();
  else if (expression instanceof SuperFieldAccess)
    return ((SuperFieldAccess) expression).resolveFieldBinding();
  else if (expression instanceof ConditionalExpression)
    return resolveBinding(((ConditionalExpression) expression).getThenExpression());
  return null;
}
项目:che    文件:NullAnnotationsCorrectionProcessor.java   
private static SimpleName findProblemFieldName(ASTNode selectedNode, int problemID) {
  // if a field access occurs in an compatibility situation (assignment/return/argument)
  // with expected type declared @NonNull we first need to find the SimpleName inside:
  if (selectedNode instanceof FieldAccess) selectedNode = ((FieldAccess) selectedNode).getName();
  else if (selectedNode instanceof QualifiedName)
    selectedNode = ((QualifiedName) selectedNode).getName();

  if (selectedNode instanceof SimpleName) {
    SimpleName name = (SimpleName) selectedNode;
    if (problemID == IProblem.NullableFieldReference) return name;
    // not field dereference, but compatibility issue - is value a field reference?
    IBinding binding = name.resolveBinding();
    if ((binding instanceof IVariableBinding) && ((IVariableBinding) binding).isField())
      return name;
  }
  return null;
}
项目:petablox    文件:PetabloxAdapterNew.java   
public boolean visit(FieldAccess fa) {
    IVariableBinding v = fa.resolveFieldBinding();
    if(Modifier.isStatic(v.getModifiers()))
        return true;

    Expression base = fa.getExpression();
    ITypeBinding baseType = base.resolveTypeBinding();

    String chordSig, markerType;
    if(baseType.isArray()){
        assert fa.getName().getIdentifier().equals("length");
        markerType = "arraylen";
        chordSig = toPetabloxType(baseType);
    } else{
        markerType = "fieldexpr";
        chordSig =  chordSigFor(v);
    }
    writeSimpleMarker(markerType, chordSig, fa, base);

    return true;
}
项目:Slicer    文件:FDDVisitor.java   
/**
 * Add the variable to the node aliases.
 */
public boolean visit(FieldAccess node){
    /* All we really need from this is the variable binding. */
    IBinding binding = node.resolveFieldBinding();

    if(binding == null){
        if(this.aliases.contains(node.getName().toString())){
            this.result = true;
            return false;
        }

    }
    else if(binding instanceof IVariableBinding){
        if(this.aliases.contains(binding.getKey())){
            this.result = true;
            return false;
        }
    }

    return true;
}
项目:Slicer    文件:BDDSeedVisitor.java   
/**
 * Add the variable to the node aliases.
 */
public boolean visit(FieldAccess node){
    /* All we really need from this is the variable binding. */
    IBinding binding = node.resolveFieldBinding();

    if(binding == null){
        if(!seedVariables.contains(node.getName().toString()))
            seedVariables.add(node.getName().toString());
    }
    else if(binding instanceof IVariableBinding){
        if(!seedVariables.contains(binding.getKey()))
            seedVariables.add(binding.getKey());
    }

    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:Bindings.java   
/**
 * Returns the binding of the variable written in an Assignment.
 * @param assignment The assignment
 * @return The binding or <code>null</code> if no bindings are available.
 */
public static IVariableBinding getAssignedVariable(Assignment assignment) {
    Expression leftHand = assignment.getLeftHandSide();
    switch (leftHand.getNodeType()) {
        case ASTNode.SIMPLE_NAME:
            return (IVariableBinding) ((SimpleName) leftHand).resolveBinding();
        case ASTNode.QUALIFIED_NAME:
            return (IVariableBinding) ((QualifiedName) leftHand).getName().resolveBinding();
        case ASTNode.FIELD_ACCESS:
            return ((FieldAccess) leftHand).resolveFieldBinding();
        case ASTNode.SUPER_FIELD_ACCESS:
            return ((SuperFieldAccess) leftHand).resolveFieldBinding();
        default:
            return null;
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:MoveInnerToTopRefactoring.java   
private void modifyAccessToFieldsFromEnclosingInstance(CompilationUnitRewrite targetRewrite, SimpleName[] simpleNames, AbstractTypeDeclaration declaration) {
    IBinding binding= null;
    SimpleName simpleName= null;
    IVariableBinding variable= null;
    for (int index= 0; index < simpleNames.length; index++) {
        simpleName= simpleNames[index];
        binding= simpleName.resolveBinding();
        if (binding != null && binding instanceof IVariableBinding && !(simpleName.getParent() instanceof FieldAccess)) {
            variable= (IVariableBinding) binding;
            final FieldAccess access= simpleName.getAST().newFieldAccess();
            access.setExpression(createAccessExpressionToEnclosingInstanceFieldText(simpleName, variable, declaration));
            access.setName(simpleName.getAST().newSimpleName(simpleName.getIdentifier()));
            targetRewrite.getASTRewrite().replace(simpleName, access, null);
            targetRewrite.getImportRemover().registerRemovedNode(simpleName);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:MovedMemberAnalyzer.java   
@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);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CodeStyleFix.java   
/**
 * {@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);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ExtractConstantRefactoring.java   
private RefactoringStatus checkExpression() throws JavaModelException {
    RefactoringStatus result= new RefactoringStatus();
    result.merge(checkExpressionBinding());
    if(result.hasFatalError())
        return result;
    checkAllStaticFinal();

    IExpressionFragment selectedExpression= getSelectedExpression();
    Expression associatedExpression= selectedExpression.getAssociatedExpression();
    if (associatedExpression instanceof NullLiteral)
        result.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_null_literals));
    else if (!ConstantChecks.isLoadTimeConstant(selectedExpression))
        result.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_not_load_time_constant));
    else if (associatedExpression instanceof SimpleName) {
        if (associatedExpression.getParent() instanceof QualifiedName && associatedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY
                || associatedExpression.getParent() instanceof FieldAccess && associatedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
            return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_select_expression);
    }

    return result;
}
项目:Eclipse-Postfix-Code-Completion    文件:MoveInstanceMethodProcessor.java   
@Override
public boolean visit(final SimpleName node) {
    Assert.isNotNull(node);
    if (fAnonymousClass > 0) {
        if (!(node.getParent() instanceof FieldAccess)) {
            final IBinding binding= node.resolveBinding();
            if (binding instanceof IVariableBinding) {
                final IVariableBinding variable= (IVariableBinding) binding;
                final ITypeBinding declaring= variable.getDeclaringClass();
                if (declaring != null && Bindings.equals(declaring, fDeclaringType))
                    fResult.add(node);
            }
        }
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CodeStyleFix.java   
private void handleSimpleName(SimpleName node) {
    ASTNode firstExpression= node.getParent();
    if (firstExpression instanceof FieldAccess) {
        while (firstExpression instanceof FieldAccess) {
            firstExpression= ((FieldAccess)firstExpression).getExpression();
        }
        if (!(firstExpression instanceof SimpleName))
            return;

        node= (SimpleName)firstExpression;
    } else if (firstExpression instanceof SuperFieldAccess)
        return;

    StructuralPropertyDescriptor parentDescription= node.getLocationInParent();
    if (parentDescription == VariableDeclarationFragment.NAME_PROPERTY || parentDescription == SwitchCase.EXPRESSION_PROPERTY)
        return;

    IBinding binding= node.resolveBinding();
    if (!(binding instanceof IVariableBinding))
        return;

    handleVariable(node, (IVariableBinding) binding);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ExpressionVariable.java   
public static IBinding resolveBinding(Expression expression){
    if (expression instanceof Name)
        return ((Name)expression).resolveBinding();
    if (expression instanceof ParenthesizedExpression)
        return resolveBinding(((ParenthesizedExpression)expression).getExpression());
    else if (expression instanceof Assignment)
        return resolveBinding(((Assignment)expression).getLeftHandSide());//TODO ???
    else if (expression instanceof MethodInvocation)
        return ((MethodInvocation)expression).resolveMethodBinding();
    else if (expression instanceof SuperMethodInvocation)
        return ((SuperMethodInvocation)expression).resolveMethodBinding();
    else if (expression instanceof FieldAccess)
        return ((FieldAccess)expression).resolveFieldBinding();
    else if (expression instanceof SuperFieldAccess)
        return ((SuperFieldAccess)expression).resolveFieldBinding();
    else if (expression instanceof ConditionalExpression)
        return resolveBinding(((ConditionalExpression)expression).getThenExpression());
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:MoveInstanceMethodProcessor.java   
/**
 * 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;
}
项目:Eclipse-Postfix-Code-Completion    文件:ExtractTempRefactoring.java   
private RefactoringStatus checkExpression() throws JavaModelException {
    Expression selectedExpression= getSelectedExpression().getAssociatedExpression();
    if (selectedExpression != null) {
        final ASTNode parent= selectedExpression.getParent();
        if (selectedExpression instanceof NullLiteral) {
            return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
        } else if (selectedExpression instanceof ArrayInitializer) {
            return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
        } else if (selectedExpression instanceof Assignment) {
            if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression))
                return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
            else
                return null;
        } else if (selectedExpression instanceof SimpleName) {
            if ((((SimpleName) selectedExpression)).isDeclaration())
                return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
            if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
                return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
        } else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) {
            return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources);
        }
    }

    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:ExtractConstantRefactoring.java   
private RefactoringStatus checkExpression() throws JavaModelException {
    RefactoringStatus result= new RefactoringStatus();
    result.merge(checkExpressionBinding());
    if(result.hasFatalError())
        return result;
    checkAllStaticFinal();

    IExpressionFragment selectedExpression= getSelectedExpression();
    Expression associatedExpression= selectedExpression.getAssociatedExpression();
    if (associatedExpression instanceof NullLiteral)
        result.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_null_literals));
    else if (!ConstantChecks.isLoadTimeConstant(selectedExpression))
        result.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_not_load_time_constant));
    else if (associatedExpression instanceof SimpleName) {
        if (associatedExpression.getParent() instanceof QualifiedName && associatedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY
                || associatedExpression.getParent() instanceof FieldAccess && associatedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
            return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractConstantRefactoring_select_expression);
    }

    return result;
}
项目:Eclipse-Postfix-Code-Completion    文件:ExpressionVariable.java   
public static IBinding resolveBinding(Expression expression){
    if (expression instanceof Name)
        return ((Name)expression).resolveBinding();
    if (expression instanceof ParenthesizedExpression)
        return resolveBinding(((ParenthesizedExpression)expression).getExpression());
    else if (expression instanceof Assignment)
        return resolveBinding(((Assignment)expression).getLeftHandSide());//TODO ???
    else if (expression instanceof MethodInvocation)
        return ((MethodInvocation)expression).resolveMethodBinding();
    else if (expression instanceof SuperMethodInvocation)
        return ((SuperMethodInvocation)expression).resolveMethodBinding();
    else if (expression instanceof FieldAccess)
        return ((FieldAccess)expression).resolveFieldBinding();
    else if (expression instanceof SuperFieldAccess)
        return ((SuperFieldAccess)expression).resolveFieldBinding();
    else if (expression instanceof ConditionalExpression)
        return resolveBinding(((ConditionalExpression)expression).getThenExpression());
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:IntroduceParameterObjectProcessor.java   
private void updateSimpleName(ASTRewrite rewriter, ParameterInfo pi, SimpleName node, List<SingleVariableDeclaration> enclosingParameters, IJavaProject project) {
    AST ast= rewriter.getAST();
    IBinding binding= node.resolveBinding();
    Expression replacementNode= fParameterObjectFactory.createFieldReadAccess(pi, getParameterName(), ast, project, false, null);
    if (binding instanceof IVariableBinding) {
        IVariableBinding variable= (IVariableBinding) binding;
        if (variable.isParameter() && variable.getName().equals(getNameInScope(pi, enclosingParameters))) {
            rewriter.replace(node, replacementNode, null);
        }
    } else {
        ASTNode parent= node.getParent();
        if (!(parent instanceof QualifiedName || parent instanceof FieldAccess || parent instanceof SuperFieldAccess)) {
            if (node.getIdentifier().equals(getNameInScope(pi, enclosingParameters))) {
                rewriter.replace(node, replacementNode, null);
            }
        }
    }
}
项目:jive    文件:ExpressionVisitor.java   
/**
 * [expression '.'] name
 */
@Override
public boolean visit(final FieldAccess node)
{
  // collect this reference
  final IResolvedNode rnode = processNode(node);
  // process the qualifier expression
  processRecursive(node.getExpression(), rnode);
  // collect variable reference
  if (rnode != null)
  {
    uses.add(rnode);
  }
  // visit children
  return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:CodeStyleFix.java   
/**
 * {@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);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ExtractTempRefactoring.java   
private RefactoringStatus checkExpression() throws JavaModelException {
    Expression selectedExpression= getSelectedExpression().getAssociatedExpression();
    if (selectedExpression != null) {
        final ASTNode parent= selectedExpression.getParent();
        if (selectedExpression instanceof NullLiteral) {
            return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
        } else if (selectedExpression instanceof ArrayInitializer) {
            return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
        } else if (selectedExpression instanceof Assignment) {
            if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression))
                return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
            else
                return null;
        } else if (selectedExpression instanceof SimpleName) {
            if ((((SimpleName) selectedExpression)).isDeclaration())
                return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
            if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
                return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
        } else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) {
            return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources);
        }
    }

    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件: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-Postfix-Code-Completion-Juno38    文件:MoveInnerToTopRefactoring.java   
@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;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:MoveInnerToTopRefactoring.java   
private void modifyAccessToFieldsFromEnclosingInstance(CompilationUnitRewrite targetRewrite, SimpleName[] simpleNames, AbstractTypeDeclaration declaration) {
    IBinding binding= null;
    SimpleName simpleName= null;
    IVariableBinding variable= null;
    for (int index= 0; index < simpleNames.length; index++) {
        simpleName= simpleNames[index];
        binding= simpleName.resolveBinding();
        if (binding != null && binding instanceof IVariableBinding && !(simpleName.getParent() instanceof FieldAccess)) {
            variable= (IVariableBinding) binding;
            final FieldAccess access= simpleName.getAST().newFieldAccess();
            access.setExpression(createAccessExpressionToEnclosingInstanceFieldText(simpleName, variable, declaration));
            access.setName(simpleName.getAST().newSimpleName(simpleName.getIdentifier()));
            targetRewrite.getASTRewrite().replace(simpleName, access, null);
            targetRewrite.getImportRemover().registerRemovedNode(simpleName);
        }
    }
}