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

项目:eclipse.jdt.ls    文件:NecessaryParenthesesChecker.java   
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
    if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
        // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
        return false;
    }
    if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
            || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
            || locationInParent == ReturnStatement.EXPRESSION_PROPERTY
            || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
            || locationInParent == ForStatement.EXPRESSION_PROPERTY
            || locationInParent == WhileStatement.EXPRESSION_PROPERTY
            || locationInParent == DoStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.MESSAGE_PROPERTY
            || locationInParent == IfStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchCase.EXPRESSION_PROPERTY
            || locationInParent == ArrayAccess.INDEX_PROPERTY
            || locationInParent == ThrowStatement.EXPRESSION_PROPERTY
            || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
            || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
        return false;
    }
    return true;
}
项目:pandionj    文件:VarParser.java   
private Object[] accessExpressions(ArrayAccess node) {
    Object[] exp = new Object[indexDepth(node)+1];
    ArrayAccess a = node;
    int i = exp.length-1;
    do {
        Expression indexExp = a.getIndex();
        if(!(indexExp instanceof SimpleName)) // TODO no modifiers
            return null;

        exp[i] = indexExp.toString();
        Expression temp = a.getArray();
        a = temp instanceof ArrayAccess ? (ArrayAccess) temp : null;
        i--;            
    }
    while(i >= 0);
    return exp;
}
项目:pandionj    文件:TestParser.java   
@Override
public boolean visit(ArrayAccess node) {
    String arrayName = node.getArray().toString();
    List<String> iterators = iteratorsByArray.get(arrayName);
    if(iterators == null) {
        iterators= new ArrayList<>(); 
    }

    String iteratorName = node.getIndex().getNodeType() == ASTNode.INFIX_EXPRESSION ?
            filterIteratorName((InfixExpression) node.getIndex()) : node.getIndex().toString();
    if(!iterators.contains(iteratorName)) {
        isArrayPrimitiveFigure = true;
        iterators.add(iteratorName);
        allIterators.add(iteratorName);
        iteratorsByArray.put(arrayName, iterators);
        System.out.println("A variavel " + iteratorName + " est� a iterar sobre a array: " + node.getArray().toString());
    }

    return super.visit(node);
}
项目:code    文件:ValueFlowTransferFunctions.java   
@Override
public OOGContext transfer(LoadArrayInstruction instr, OOGContext value) {
    // System.out.println("LoadArray: " + instr.getNode() + " O=" +
    // value.getO());
    QualifiedClassName cthis = value.getO().getQCN();
    Variable recv = instr.getSourceArray();
    if (recv.resolveType().isArray()) {
        QualifiedClassName receiverClass = new QualifiedClassName(getRecvPreciseClass(recv, value.getO()), cthis);
        List<DomainP> receiverActualDomains = getReceiverActualDomains(recv, instr, value.getGamma(), cthis);
        if (receiverActualDomains != null) {
            ArrayAccess aa = (ArrayAccess) instr.getNode();
            List<DomainP> formalTKDomains = getArrayAccessActualDomains(aa, cthis);
            if (formalTKDomains != null) {
                ITypeBinding fieldKClass = instr.getSourceArray().resolveType().getElementType();
                value.getGamma().put(instr.getTarget(), formalTKDomains);
                QualifiedClassName labelClass = new QualifiedClassName(fieldKClass, cthis);
                Variable fk = instr.getArrayIndex();
                Variable l = instr.getTarget();
                addValueFlow(value, receiverClass, receiverActualDomains, labelClass, formalTKDomains, fk,  formalTKDomains, l );
            }
        }
    }
    return super.transfer(instr, value);
}
项目:che    文件:NecessaryParenthesesChecker.java   
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
  if (locationInParent instanceof ChildListPropertyDescriptor
      && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
    // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation
    // ...
    return false;
  }
  if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
      || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
      || locationInParent == ReturnStatement.EXPRESSION_PROPERTY
      || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
      || locationInParent == ForStatement.EXPRESSION_PROPERTY
      || locationInParent == WhileStatement.EXPRESSION_PROPERTY
      || locationInParent == DoStatement.EXPRESSION_PROPERTY
      || locationInParent == AssertStatement.EXPRESSION_PROPERTY
      || locationInParent == AssertStatement.MESSAGE_PROPERTY
      || locationInParent == IfStatement.EXPRESSION_PROPERTY
      || locationInParent == SwitchStatement.EXPRESSION_PROPERTY
      || locationInParent == SwitchCase.EXPRESSION_PROPERTY
      || locationInParent == ArrayAccess.INDEX_PROPERTY
      || locationInParent == ThrowStatement.EXPRESSION_PROPERTY
      || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
      || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
    return false;
  }
  return true;
}
项目:che    文件:GenerateForLoopAssistProposal.java   
/**
 * Creates an {@link Assignment} as first expression appearing in a <code>for</code> loop's body.
 * This Assignment declares a local variable and initializes it using the array'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 Assignment getForBodyAssignment(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
  ArrayAccess access = ast.newArrayAccess();
  access.setArray((Expression) rewrite.createCopyTarget(fCurrentExpression));
  SimpleName indexName = ast.newSimpleName(loopVariableName.getIdentifier());
  addLinkedPosition(
      rewrite.track(indexName), LinkedPositionGroup.NO_STOP, indexName.getIdentifier());
  access.setIndex(indexName);
  assignResolvedVariable.setRightHandSide(access);

  assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);

  return assignResolvedVariable;
}
项目:evosuite    文件:TestExtractingVisitor.java   
private VariableReference retrieveVariableReference(ArrayAccess arrayAccess) {
    Expression expr = arrayAccess.getArray();
    List<Integer> indices = new ArrayList<Integer>();
    // TODO This is a shortcut
    // we need a variable reference for the index value
    indices.add(getArrayIndex(arrayAccess.getIndex()));
    while (expr instanceof ArrayAccess) {
        ArrayAccess current = (ArrayAccess) expr;
        expr = current.getArray();
        indices.add(getArrayIndex(current.getIndex()));
    }
    Collections.reverse(indices);
    VariableReference varRef = retrieveVariableReference(expr, null);
    ArrayReference arrayReference = (ArrayReference) varRef;
    assert indices.size() == arrayReference.getArrayDimensions();
    ArrayIndex arrayIndex = new ArrayIndex(testCase.getReference(), arrayReference,
            indices);
    return arrayIndex;
}
项目:evosuite    文件:JUnitCodeGenerator.java   
@Override
public void createArrayInitStmt(final CaptureLog log, final int logRecNo) {
    final int  oid  = log.objectIds.get(logRecNo);

    final Object[] params      = log.params.get(logRecNo);
    final String   arrTypeName = log.oidClassNames.get(log.oidRecMapping.get(oid));
    final Class<?> arrType     = getClassForName(arrTypeName);

    // --- create array instance creation e.g. int[] var = new int[10];

    final ArrayType     arrAstType      = (ArrayType) createAstArrayType(arrTypeName, ast);
    final ArrayCreation arrCreationExpr = ast.newArrayCreation();
    arrCreationExpr.setType(arrAstType);
    arrCreationExpr.dimensions().add(ast.newNumberLiteral(String.valueOf(params.length)));

    final String                      arrVarName = this.createNewVarName(oid, arrTypeName);
    final VariableDeclarationFragment vd         = ast.newVariableDeclarationFragment();
    final SimpleName arrVarNameExpr = ast.newSimpleName(arrVarName); 
    vd.setName(arrVarNameExpr); 
    vd.setInitializer(arrCreationExpr);

    final VariableDeclarationStatement varDeclStmt = ast.newVariableDeclarationStatement(vd);
    varDeclStmt.setType(this.createAstType(arrTypeName, ast));

    methodBlock.statements().add(varDeclStmt);  

    // create array access statements var[0] = var1;
    Integer paramOID;
    Assignment assign;
    ArrayAccess arrAccessExpr;

    for(int i = 0; i < params.length; i++)
    {
        assign       = ast.newAssignment();
        arrAccessExpr = ast.newArrayAccess();
        arrAccessExpr.setIndex(ast.newNumberLiteral(String.valueOf(i)));
        arrAccessExpr.setArray(arrVarNameExpr);

        assign.setLeftHandSide(arrAccessExpr);

        paramOID = (Integer) params[i];
        if(paramOID == null)
        {
           assign.setRightHandSide(ast.newNullLiteral());
        }
        else
        {
            assign.setRightHandSide(ast.newSimpleName(this.oidToVarMapping.get(paramOID)));
        }

        methodBlock.statements().add(assign);   
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:NecessaryParenthesesChecker.java   
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
    if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
        // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
        return false;
    }
    if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
            || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
            || locationInParent == ReturnStatement.EXPRESSION_PROPERTY
            || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
            || locationInParent == ForStatement.EXPRESSION_PROPERTY
            || locationInParent == WhileStatement.EXPRESSION_PROPERTY
            || locationInParent == DoStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.MESSAGE_PROPERTY
            || locationInParent == IfStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchCase.EXPRESSION_PROPERTY
            || locationInParent == ArrayAccess.INDEX_PROPERTY
            || locationInParent == ThrowStatement.EXPRESSION_PROPERTY
            || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
            || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
        return false;
    }
    return true;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:NecessaryParenthesesChecker.java   
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
    if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
        // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
        return false;
    }
    if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
            || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
            || locationInParent == ReturnStatement.EXPRESSION_PROPERTY
            || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
            || locationInParent == ForStatement.EXPRESSION_PROPERTY
            || locationInParent == WhileStatement.EXPRESSION_PROPERTY
            || locationInParent == DoStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.MESSAGE_PROPERTY
            || locationInParent == IfStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchCase.EXPRESSION_PROPERTY
            || locationInParent == ArrayAccess.INDEX_PROPERTY
            || locationInParent == ThrowStatement.EXPRESSION_PROPERTY
            || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
            || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
        return false;
    }
    return true;
}
项目:pandionj    文件:ArrayParser.java   
@Override
public boolean visit(ArrayAccess node) {
    Expression indexExp = node.getIndex();
    if(indexExp instanceof SimpleName) {
        SimpleName varName = (SimpleName) indexExp;
        System.out.println(node + " : " + varName.getIdentifier());
    }
    return super.visit(node);
}
项目:eclipse.jdt.ls    文件:FlowAnalyzer.java   
@Override
public void endVisit(ArrayAccess node) {
    if (skipNode(node)) {
        return;
    }
    processSequential(node, node.getArray(), node.getIndex());
}
项目:eclipse.jdt.ls    文件:OperatorPrecedence.java   
/**
 * Returns the precedence of the expression. Expression
 * with higher precedence are executed before expressions
 * with lower precedence.
 * i.e. in:
 * <br><code> int a= ++3--;</code></br>
 *
 * the  precedence order is
 * <ul>
 * <li>3</li>
 * <li>++</li>
 * <li>--</li>
 * <li>=</li>
 * </ul>
 * 1. 3 -(++)-> 4<br>
 * 2. 4 -(--)-> 3<br>
 * 3. 3 -(=)-> a<br>
 *
 * @param expression the expression to determine the precedence for
 * @return the precedence the higher to stronger the binding to its operand(s)
 */
public static int getExpressionPrecedence(Expression expression) {
    if (expression instanceof InfixExpression) {
        return getOperatorPrecedence(((InfixExpression)expression).getOperator());
    } else if (expression instanceof Assignment) {
        return ASSIGNMENT;
    } else if (expression instanceof ConditionalExpression) {
        return CONDITIONAL;
    } else if (expression instanceof InstanceofExpression) {
        return RELATIONAL;
    } else if (expression instanceof CastExpression) {
        return TYPEGENERATION;
    } else if (expression instanceof ClassInstanceCreation) {
        return POSTFIX;
    } else if (expression instanceof PrefixExpression) {
        return PREFIX;
    } else if (expression instanceof FieldAccess) {
        return POSTFIX;
    } else if (expression instanceof MethodInvocation) {
        return POSTFIX;
    } else if (expression instanceof ArrayAccess) {
        return POSTFIX;
    } else if (expression instanceof PostfixExpression) {
        return POSTFIX;
    }
    return Integer.MAX_VALUE;
}
项目:code    文件:NodesOOGTransferFunctions.java   
protected List<DomainP> getArrayAccessActualDomains(ArrayAccess aa, QualifiedClassName cthis) {
    List<DomainP> listP = new ArrayList<DomainP>();
    IVariableBinding arrVarBinding = Utils.getArrayAccessVarBinding(aa);
    if (arrVarBinding==null){
        System.err.println("WARNING: could not handle complex array expression");
        return listP;
    }
    AnnotationInfo info = VariableDeclAnnotationInfo.getInfo(arrVarBinding);
    if (info == null) {
    List<ICrystalAnnotation> annots = pointsToAnalysis.getAnnoDB().getAnnosForVariable(arrVarBinding);      
    for (ICrystalAnnotation iCrystalAnnotation : annots) {
        if (iCrystalAnnotation.getName().endsWith(Constants.DOMAIN)) {
            Object val = iCrystalAnnotation.getObject("value");
            String annot = "";

            // NOTE: IMemberValuePairBinding.getValue() sometimes returns a
            // String, sometimes an Object[]!
            if (val instanceof String) {
                annot = (String) val;
            } else if (val instanceof Object[]) {
                Object[] arrVal = (Object[]) val;
                annot = (String) arrVal[0];
            }
            AnnotationInfo anInfo = AnnotationInfo.parseAnnotation(annot);
            VariableDeclAnnotationInfo.putInfo(arrVarBinding, anInfo);
            return Utils.getListDomainP(cthis, anInfo);
        }
    }
    }
    return Utils.getListDomainP(cthis, info);
}
项目:code    文件:Utils.java   
/**
 * @param varBinding
 * @param arrayAccess
 * @return
 */
public static IVariableBinding getArrayAccessVarBinding(ArrayAccess arrayAccess) {
    IVariableBinding varBinding = null;
    Expression array = arrayAccess.getArray();
    if (array instanceof SimpleName) {
        IBinding bind = ((SimpleName) array).resolveBinding();
        if (bind instanceof IVariableBinding) {
            varBinding = ((IVariableBinding) bind).getVariableDeclaration();
        }
    }
    else if (array instanceof ArrayAccess) {
        return getArrayAccessVarBinding((ArrayAccess) array);
    }
    return varBinding;
}
项目:che    文件:InferTypeArgumentsConstraintCreator.java   
@Override
public void endVisit(ArrayAccess node) {
  if (node.resolveBoxing()) {
    ImmutableTypeVariable2 boxed =
        fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
    setConstraintVariable(node, boxed);
    return;
  }

  ConstraintVariable2 arrayCv = getConstraintVariable(node.getArray());
  if (arrayCv == null) return;

  ArrayElementVariable2 arrayElementCv = fTCModel.getArrayElementVariable(arrayCv);
  setConstraintVariable(node, arrayElementCv);
}
项目:che    文件:SourceAnalyzer.java   
@Override
public boolean visit(ArrayAccess node) {
  Expression array = node.getArray();
  if (array instanceof SimpleName
      && fParameter.isEqualTo(((SimpleName) array).resolveBinding())) {
    fArrayAccess = true;
  }
  return true;
}
项目:che    文件:OperatorPrecedence.java   
/**
 * Returns the precedence of the expression. Expression with higher precedence are executed before
 * expressions with lower precedence. i.e. in: <br>
 * <code> int a= ++3--;</code></br>
 *
 * <p>the precedence order is
 *
 * <ul>
 *   <li>3
 *   <li>++
 *   <li>--
 *   <li>=
 * </ul>
 *
 * 1. 3 -(++)-> 4<br>
 * 2. 4 -(--)-> 3<br>
 * 3. 3 -(=)-> a<br>
 *
 * @param expression the expression to determine the precedence for
 * @return the precedence the higher to stronger the binding to its operand(s)
 */
public static int getExpressionPrecedence(Expression expression) {
  if (expression instanceof InfixExpression) {
    return getOperatorPrecedence(((InfixExpression) expression).getOperator());
  } else if (expression instanceof Assignment) {
    return ASSIGNMENT;
  } else if (expression instanceof ConditionalExpression) {
    return CONDITIONAL;
  } else if (expression instanceof InstanceofExpression) {
    return RELATIONAL;
  } else if (expression instanceof CastExpression) {
    return TYPEGENERATION;
  } else if (expression instanceof ClassInstanceCreation) {
    return POSTFIX;
  } else if (expression instanceof PrefixExpression) {
    return PREFIX;
  } else if (expression instanceof FieldAccess) {
    return POSTFIX;
  } else if (expression instanceof MethodInvocation) {
    return POSTFIX;
  } else if (expression instanceof ArrayAccess) {
    return POSTFIX;
  } else if (expression instanceof PostfixExpression) {
    return POSTFIX;
  }
  return Integer.MAX_VALUE;
}
项目:Eclipse-Postfix-Code-Completion    文件:InferTypeArgumentsConstraintCreator.java   
@Override
public void endVisit(ArrayAccess node) {
    if (node.resolveBoxing()) {
        ImmutableTypeVariable2 boxed= fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
        setConstraintVariable(node, boxed);
        return;
    }

    ConstraintVariable2 arrayCv= getConstraintVariable(node.getArray());
    if (arrayCv == null)
        return;

    ArrayElementVariable2 arrayElementCv= fTCModel.getArrayElementVariable(arrayCv);
    setConstraintVariable(node, arrayElementCv);
}
项目:Eclipse-Postfix-Code-Completion    文件:SourceAnalyzer.java   
@Override
public boolean visit(ArrayAccess node) {
    Expression array= node.getArray();
    if (array instanceof SimpleName && fParameter.isEqualTo(((SimpleName)array).resolveBinding())) {
        fArrayAccess= true;
    }
    return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:OperatorPrecedence.java   
/**
 * Returns the precedence of the expression. Expression
 * with higher precedence are executed before expressions
 * with lower precedence.
 * i.e. in:
 * <br><code> int a= ++3--;</code></br>
 *
 * the  precedence order is
 * <ul>
 * <li>3</li>
 * <li>++</li>
 * <li>--</li>
 * <li>=</li>
 * </ul>
 * 1. 3 -(++)-> 4<br>
 * 2. 4 -(--)-> 3<br>
 * 3. 3 -(=)-> a<br>
 *
 * @param expression the expression to determine the precedence for
 * @return the precedence the higher to stronger the binding to its operand(s)
 */
public static int getExpressionPrecedence(Expression expression) {
    if (expression instanceof InfixExpression) {
        return getOperatorPrecedence(((InfixExpression)expression).getOperator());
    } else if (expression instanceof Assignment) {
        return ASSIGNMENT;
    } else if (expression instanceof ConditionalExpression) {
        return CONDITIONAL;
    } else if (expression instanceof InstanceofExpression) {
        return RELATIONAL;
    } else if (expression instanceof CastExpression) {
        return TYPEGENERATION;
    } else if (expression instanceof ClassInstanceCreation) {
        return POSTFIX;
    } else if (expression instanceof PrefixExpression) {
        return PREFIX;
    } else if (expression instanceof FieldAccess) {
        return POSTFIX;
    } else if (expression instanceof MethodInvocation) {
        return POSTFIX;
    } else if (expression instanceof ArrayAccess) {
        return POSTFIX;
    } else if (expression instanceof PostfixExpression) {
        return POSTFIX;
    }
    return Integer.MAX_VALUE;
}
项目:Eclipse-Postfix-Code-Completion    文件:GenerateForLoopAssistProposal.java   
/**
 * Creates an {@link Assignment} as first expression appearing in a <code>for</code> loop's
 * body. This Assignment declares a local variable and initializes it using the array'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 Assignment getForBodyAssignment(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
    ArrayAccess access= ast.newArrayAccess();
    access.setArray((Expression) rewrite.createCopyTarget(fCurrentExpression));
    SimpleName indexName= ast.newSimpleName(loopVariableName.getIdentifier());
    addLinkedPosition(rewrite.track(indexName), LinkedPositionGroup.NO_STOP, indexName.getIdentifier());
    access.setIndex(indexName);
    assignResolvedVariable.setRightHandSide(access);

    assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);

    return assignResolvedVariable;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:InferTypeArgumentsConstraintCreator.java   
@Override
public void endVisit(ArrayAccess node) {
    if (node.resolveBoxing()) {
        ImmutableTypeVariable2 boxed= fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
        setConstraintVariable(node, boxed);
        return;
    }

    ConstraintVariable2 arrayCv= getConstraintVariable(node.getArray());
    if (arrayCv == null)
        return;

    ArrayElementVariable2 arrayElementCv= fTCModel.getArrayElementVariable(arrayCv);
    setConstraintVariable(node, arrayElementCv);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SourceAnalyzer.java   
@Override
public boolean visit(ArrayAccess node) {
    Expression array= node.getArray();
    if (array instanceof SimpleName && fParameter.isEqualTo(((SimpleName)array).resolveBinding())) {
        fArrayAccess= true;
    }
    return true;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:OperatorPrecedence.java   
/**
 * Returns the precedence of the expression. Expression
 * with higher precedence are executed before expressions
 * with lower precedence.
 * i.e. in:
 * <br><code> int a= ++3--;</code></br>
 *
 * the  precedence order is
 * <ul>
 * <li>3</li>
 * <li>++</li>
 * <li>--</li>
 * <li>=</li>
 * </ul>
 * 1. 3 -(++)-> 4<br>
 * 2. 4 -(--)-> 3<br>
 * 3. 3 -(=)-> a<br>
 *
 * @param expression the expression to determine the precedence for
 * @return the precedence the higher to stronger the binding to its operand(s)
 */
public static int getExpressionPrecedence(Expression expression) {
    if (expression instanceof InfixExpression) {
        return getOperatorPrecedence(((InfixExpression)expression).getOperator());
    } else if (expression instanceof Assignment) {
        return ASSIGNMENT;
    } else if (expression instanceof ConditionalExpression) {
        return CONDITIONAL;
    } else if (expression instanceof InstanceofExpression) {
        return RELATIONAL;
    } else if (expression instanceof CastExpression) {
        return TYPEGENERATION;
    } else if (expression instanceof ClassInstanceCreation) {
        return POSTFIX;
    } else if (expression instanceof PrefixExpression) {
        return PREFIX;
    } else if (expression instanceof FieldAccess) {
        return POSTFIX;
    } else if (expression instanceof MethodInvocation) {
        return POSTFIX;
    } else if (expression instanceof ArrayAccess) {
        return POSTFIX;
    } else if (expression instanceof PostfixExpression) {
        return POSTFIX;
    }
    return Integer.MAX_VALUE;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ASTFlattener.java   
@Override
public boolean visit(ArrayAccess node) {
    node.getArray().accept(this);
    this.fBuffer.append("[");//$NON-NLS-1$
    node.getIndex().accept(this);
    this.fBuffer.append("]");//$NON-NLS-1$
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:NaiveASTFlattener.java   
public boolean visit(ArrayAccess node) {
    node.getArray().accept(this);
    this.buffer.append("[");//$NON-NLS-1$
    node.getIndex().accept(this);
    this.buffer.append("]");//$NON-NLS-1$
    return false;
}
项目:jive    文件:StatementVisitor.java   
private boolean isNamedDataMember(final Expression exp)
{
  if (exp instanceof FieldAccess)
  {
    // always has a name
    return true;
  }
  if (exp instanceof SuperFieldAccess)
  {
    // always has a name
    return true;
  }
  if (exp instanceof ArrayAccess)
  {
    // true only if the array expression is a named data member
    return isNamedDataMember(((ArrayAccess) exp).getArray());
  }
  if (exp instanceof QualifiedName)
  {
    // is a name
    return true;
  }
  if (exp instanceof SimpleName)
  {
    // is a name
    return true;
  }
  // does not have a name
  return false;
}
项目:jive    文件:StatementVisitor.java   
/**
 * An expression like "foo.this" can only be represented as a this expression (ThisExpression)
 * containing a simple name. "this" is a keyword, and therefore invalid as an identifier.
 * 
 * An expression like "this.foo" can only be represented as a field access expression
 * (FieldAccess) containing a this expression and a simple name. Again, this is because "this" is
 * a keyword, and therefore invalid as an identifier.
 * 
 * An expression with "super" can only be represented as a super field access expression
 * (SuperFieldAccess). "super" is a also keyword, and therefore invalid as an identifier.
 * 
 * An expression like "foo.bar" can be represented either as a qualified name (QualifiedName) or
 * as a field access expression (FieldAccess) containing simple names. Either is acceptable, and
 * there is no way to choose between them without information about what the names resolve to
 * (ASTParser may return either).
 * 
 * Other expressions ending in an identifier, such as "foo().bar" can only be represented as field
 * access expressions (FieldAccess).
 */
private Expression lhsDef(final Expression lhs)
{
  if (lhs instanceof FieldAccess)
  {
    return ((FieldAccess) lhs).getName();
  }
  if (lhs instanceof SuperFieldAccess)
  {
    return ((SuperFieldAccess) lhs).getName();
  }
  if (lhs instanceof QualifiedName)
  {
    return ((QualifiedName) lhs).getName();
  }
  if (lhs instanceof SimpleName)
  {
    return lhs;
  }
  // multi-dimensional array access
  if (lhs instanceof ArrayAccess)
  {
    return lhsDef(((ArrayAccess) lhs).getArray());
  }
  throw new IllegalStateException("Unexpected LHS expression node: " + lhs.getClass().getName()
      + " --> " + lhs.toString());
}
项目:ESPSecurityPlugin    文件:SourceSinkAnalyser.java   
private boolean expressionContainsTaintedVariable(Expression node) {
    if(node instanceof SimpleName) {
        return expressionContainsTaintedVariable((SimpleName) node);
    } else if (node instanceof ArrayAccess) {
        return expressionContainsTaintedVariable((ArrayAccess)node);
    } else if (node instanceof ArrayCreation) {
        return expressionContainsTaintedVariable((ArrayCreation)node);
    } else if (node instanceof CastExpression) {
        return expressionContainsTaintedVariable((CastExpression) node);
    } else if (node instanceof ClassInstanceCreation) {
        return expressionContainsTaintedVariable((ClassInstanceCreation)node);
    } else if (node instanceof ConditionalExpression) {
        return expressionContainsTaintedVariable((ConditionalExpression)node);
    } else if(node instanceof FieldAccess) {
        return expressionContainsTaintedVariable((FieldAccess)node);
    } else if(node instanceof InfixExpression) {
        return expressionContainsTaintedVariable((InfixExpression) node);
    } else if(node instanceof MethodInvocation) {
        return expressionContainsTaintedVariable((MethodInvocation) node);
    }  else if(node instanceof ParenthesizedExpression) {
        return expressionContainsTaintedVariable((ParenthesizedExpression) node);
    } else if(node instanceof PostfixExpression) {
        return expressionContainsTaintedVariable((PostfixExpression) node);
    } else if(node instanceof PrefixExpression) {
        return expressionContainsTaintedVariable((PrefixExpression) node);
    } else if(node instanceof SuperMethodInvocation) {
        return expressionContainsTaintedVariable((SuperMethodInvocation) node);
    }

    return false;
}
项目:ESPSecurityPlugin    文件:SourceSinkAnalyser.java   
protected Collection<String> expressionToString(Expression expression) {

    Collection<String> result = new Vector<String>(1); // Will 1 be most common case?

    if(expression == null) {
        return result;
    }

    if(expression instanceof ArrayAccess) {
        result.addAll(expressionToString(((ArrayAccess) expression).getArray()));
    }  else if(expression instanceof Assignment) {
        result.addAll(expressionToString(((Assignment) expression).getLeftHandSide()));
    } else if(expression instanceof CastExpression) {
        result.addAll(expressionToString(((CastExpression) expression).getExpression()));
    }else if(expression instanceof ClassInstanceCreation) {
        // TODO determine if .getExpression() needs to be analysed.can't tell looking at docs
        result.addAll(expressionToSimpleName(CastUtils.castList(Expression.class, ((ClassInstanceCreation) expression).arguments())));
    }  else if(expression instanceof ConditionalExpression) {
        // TODO what can I put in an if statement? assignment?
        result.addAll(expressionToString(((ConditionalExpression) expression).getThenExpression()));
        result.addAll(expressionToString(((ConditionalExpression) expression).getElseExpression()));
    } else if(expression instanceof MethodInvocation) {
        result.addAll(expressionToSimpleName(CastUtils.castList(Expression.class, ((MethodInvocation) expression).arguments())));
        result.addAll(expressionToString(((MethodInvocation) expression).getExpression()));
    }  else if(expression instanceof QualifiedName) {
        result.add(((QualifiedName) expression).getName().getIdentifier());
    }  else if(expression instanceof SimpleName) {
        result.add(((SimpleName)expression).getIdentifier());
    }   else if(expression instanceof ParenthesizedExpression) {
        result.addAll(expressionToString(((ParenthesizedExpression) expression).getExpression()));
    }  else if(expression instanceof PostfixExpression) {
        result.addAll(expressionToString(((PostfixExpression) expression).getOperand()));
    }  else if(expression instanceof PrefixExpression) {
        result.addAll(expressionToString(((PrefixExpression) expression).getOperand()));
    }  else if (expression instanceof SuperMethodInvocation) {
        result.addAll(expressionToSimpleName(CastUtils.castList(Expression.class, ((SuperMethodInvocation) expression).arguments())));
    } 

    return result;
}
项目:j2d    文件:J2dVisitor.java   
@Override
public boolean visit(ArrayAccess node) {
    //System.out.println("Found: " + node.getClass() + " " + node);
    node.getArray().accept(this);
    print("[");
    node.getIndex().accept(this);
    print("]");
    return false;
}
项目:eclipse.jdt.ls    文件:Bindings.java   
/**
 * Resolve the binding (<em>not</em> the type binding) for the expression or a nested expression
 * (e.g. nested in parentheses, cast, ...).
 *
 * @param expression an expression node
 * @param goIntoCast iff <code>true</code>, go into a CastExpression's expression to resolve
 * @return the expression binding, or <code>null</code> if the expression has no binding or the
 *         binding could not be resolved
 *
 * @since 3.5
 */
public static IBinding resolveExpressionBinding(Expression expression, boolean goIntoCast) {
    //TODO: search for callers of resolve*Binding() methods and replace with call to this method

    // similar to StubUtility#getVariableNameSuggestions(int, IJavaProject, ITypeBinding, Expression, Collection)
    switch (expression.getNodeType()) {
    case ASTNode.SIMPLE_NAME:
    case ASTNode.QUALIFIED_NAME:
        return ((Name) expression).resolveBinding();

    case ASTNode.FIELD_ACCESS:
        return ((FieldAccess) expression).resolveFieldBinding();
    case ASTNode.SUPER_FIELD_ACCESS:
        return ((SuperFieldAccess) expression).resolveFieldBinding();

    case ASTNode.METHOD_INVOCATION:
        return ((MethodInvocation) expression).resolveMethodBinding();
    case ASTNode.SUPER_METHOD_INVOCATION:
        return ((SuperMethodInvocation) expression).resolveMethodBinding();
    case ASTNode.CLASS_INSTANCE_CREATION:
        return ((ClassInstanceCreation) expression).resolveConstructorBinding();

    case ASTNode.MARKER_ANNOTATION:
    case ASTNode.SINGLE_MEMBER_ANNOTATION:
    case ASTNode.NORMAL_ANNOTATION:
        return ((Annotation) expression).resolveAnnotationBinding();

    case ASTNode.ARRAY_ACCESS:
        return resolveExpressionBinding(((ArrayAccess) expression).getArray(), goIntoCast);
    case ASTNode.CAST_EXPRESSION:
        if (goIntoCast) {
            return resolveExpressionBinding(((CastExpression) expression).getExpression(), true);
        } else {
            return null;
        }
    case ASTNode.PARENTHESIZED_EXPRESSION:
        return resolveExpressionBinding(((ParenthesizedExpression) expression).getExpression(), goIntoCast);
    case ASTNode.PREFIX_EXPRESSION:
        return resolveExpressionBinding(((PrefixExpression) expression).getOperand(), goIntoCast);
    case ASTNode.POSTFIX_EXPRESSION:
        return resolveExpressionBinding(((PostfixExpression) expression).getOperand(), goIntoCast);
    default:
        return null;
    }
}
项目:eclipse.jdt.ls    文件:NecessaryParenthesesChecker.java   
/**
 * Does the <code>expression</code> need parentheses when inserted into <code>parent</code> at
 * <code>locationInParent</code> ?
 *
 * @param expression the expression
 * @param parent the parent node
 * @param locationInParent location of expression in the parent
 * @param leftOperandType the type of the left operand in <code>parent</code> if
 *            <code>parent</code> is an infix expression with no bindings and
 *            <code>expression</code> is the right operand in it, <code>null</code> otherwise
 * @return <code>true</code> if <code>expression</code> needs parentheses, <code>false</code>
 *         otherwise.
 *
 * @since 3.9
 */
private static boolean needsParentheses(Expression expression, ASTNode parent, StructuralPropertyDescriptor locationInParent, ITypeBinding leftOperandType) {
    if (!expressionTypeNeedsParentheses(expression)) {
        return false;
    }

    if (!locationNeedsParentheses(locationInParent)) {
        return false;
    }

    if (parent instanceof Expression) {
        Expression parentExpression= (Expression)parent;

        if (expression instanceof PrefixExpression) { // see bug 405096
            return needsParenthesesForPrefixExpression(parentExpression, ((PrefixExpression) expression).getOperator());
        }

        if (expression instanceof ArrayCreation) { // see bug 394721
            return parentExpression instanceof ArrayAccess && ((ArrayCreation) expression).getInitializer() == null;
        }

        int expressionPrecedence= OperatorPrecedence.getExpressionPrecedence(expression);
        int parentPrecedence= OperatorPrecedence.getExpressionPrecedence(parentExpression);

        if (expressionPrecedence > parentPrecedence) {
            //(opEx) opParent and opEx binds more -> parentheses not needed
            return false;
        }

        if (expressionPrecedence < parentPrecedence) {
            //(opEx) opParent and opEx binds less -> parentheses needed
            return true;
        }

        //(opEx) opParent binds equal

        if (parentExpression instanceof InfixExpression) {
            return needsParenthesesInInfixExpression(expression, (InfixExpression) parentExpression, locationInParent, leftOperandType);
        }

        if (parentExpression instanceof ConditionalExpression && locationInParent == ConditionalExpression.EXPRESSION_PROPERTY) {
            return true;
        }

        return false;
    }

    return true;
}
项目:eclipse.jdt.ls    文件:ASTResolving.java   
public static Type guessTypeForReference(AST ast, ASTNode node) {
    ASTNode parent= node.getParent();
    while (parent != null) {
        switch (parent.getNodeType()) {
        case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
            if (((VariableDeclarationFragment) parent).getInitializer() == node) {
                return ASTNodeFactory.newType(ast, (VariableDeclaration) parent);
            }
            return null;
        case ASTNode.SINGLE_VARIABLE_DECLARATION:
            if (((VariableDeclarationFragment) parent).getInitializer() == node) {
                return ASTNodeFactory.newType(ast, (VariableDeclaration) parent);
            }
            return null;
        case ASTNode.ARRAY_ACCESS:
            if (!((ArrayAccess) parent).getIndex().equals(node)) {
                Type type= guessTypeForReference(ast, parent);
                if (type != null) {
                    return ASTNodeFactory.newArrayType(type);
                }
            }
            return null;
        case ASTNode.FIELD_ACCESS:
            if (node.equals(((FieldAccess) parent).getName())) {
                node= parent;
                parent= parent.getParent();
            } else {
                return null;
            }
            break;
        case ASTNode.SUPER_FIELD_ACCESS:
        case ASTNode.PARENTHESIZED_EXPRESSION:
            node= parent;
            parent= parent.getParent();
            break;
        case ASTNode.QUALIFIED_NAME:
            if (node.equals(((QualifiedName) parent).getName())) {
                node= parent;
                parent= parent.getParent();
            } else {
                return null;
            }
            break;
        default:
            return null;
        }
    }
    return null;
}
项目:code    文件:DfOOGTransferFunctions.java   
@Override
public OOGContext transfer(LoadArrayInstruction instr, OOGContext value) {
    // System.out.println("LoadArray: " + instr.getNode() + " O=" +
    // value.getO());
    QualifiedClassName cthis = value.getO().getQCN();
    Variable recv = instr.getSourceArray();
    if (recv.resolveType().isArray()) {
        QualifiedClassName receiverClass = new QualifiedClassName(getRecvPreciseClass(recv, value.getO()), cthis);
        List<DomainP> receiverActualDomains = getReceiverActualDomains(recv, instr, value.getGamma(), cthis);
        if (receiverActualDomains!=null){
            ArrayAccess aa = (ArrayAccess) instr.getNode();
            List<DomainP> formalTKDomains = getArrayAccessActualDomains(aa, cthis);
            if (Utils.getArrayAccessVarBinding(aa)==null){
                int debug = 0;
                debug++;
                Expression array = aa.getArray();
                Variable accessedArrayOperand = instr.getAccessedArrayOperand();
                List<DomainP> list = value.getGamma().get(accessedArrayOperand);
            }
            if (formalTKDomains != null) {
                ITypeBinding fieldKClass = instr.getSourceArray().resolveType().getElementType();
                //value.getGamma().put(instr.getTarget(), formalTKDomains);
                TraceabilityEntry tLink = traceabilityFactory.createTraceability(instr, value.getO());
                QualifiedClassName labelClass = new QualifiedClassName(fieldKClass, cthis);             
                if (!auxImport(value, receiverClass, receiverActualDomains, labelClass, formalTKDomains, tLink))
                    this.pointsToAnalysis.addWarning(instr.getNode(), IMPORT_EDGE_NOT_ADDED);
                else{
                    //do nothing;
                }
            } else {
                // cannot find formal domains for the array
                throw new IllegalStateException("Domains not found for the array: " + instr.getNode());
            }
        } else {
            // this should never happen
        }
    }
    else{
        //cannot find actual domains for the receiver
        returnWarning(instr.getNode(),recv);
    }
    return super.transfer(instr, value);
}
项目:che    文件:Bindings.java   
/**
 * Resolve the binding (<em>not</em> the type binding) for the expression or a nested expression
 * (e.g. nested in parentheses, cast, ...).
 *
 * @param expression an expression node
 * @param goIntoCast iff <code>true</code>, go into a CastExpression's expression to resolve
 * @return the expression binding, or <code>null</code> if the expression has no binding or the
 *     binding could not be resolved
 * @see StubUtility#getVariableNameSuggestions(int, IJavaProject, ITypeBinding, Expression,
 *     java.util.Collection)
 * @since 3.5
 */
public static IBinding resolveExpressionBinding(Expression expression, boolean goIntoCast) {
  // TODO: search for callers of resolve*Binding() methods and replace with call to this method

  // similar to StubUtility#getVariableNameSuggestions(int, IJavaProject, ITypeBinding,
  // Expression, Collection)
  switch (expression.getNodeType()) {
    case ASTNode.SIMPLE_NAME:
    case ASTNode.QUALIFIED_NAME:
      return ((Name) expression).resolveBinding();

    case ASTNode.FIELD_ACCESS:
      return ((FieldAccess) expression).resolveFieldBinding();
    case ASTNode.SUPER_FIELD_ACCESS:
      return ((SuperFieldAccess) expression).resolveFieldBinding();

    case ASTNode.METHOD_INVOCATION:
      return ((MethodInvocation) expression).resolveMethodBinding();
    case ASTNode.SUPER_METHOD_INVOCATION:
      return ((SuperMethodInvocation) expression).resolveMethodBinding();
    case ASTNode.CLASS_INSTANCE_CREATION:
      return ((ClassInstanceCreation) expression).resolveConstructorBinding();

    case ASTNode.MARKER_ANNOTATION:
    case ASTNode.SINGLE_MEMBER_ANNOTATION:
    case ASTNode.NORMAL_ANNOTATION:
      return ((Annotation) expression).resolveAnnotationBinding();

    case ASTNode.ARRAY_ACCESS:
      return resolveExpressionBinding(((ArrayAccess) expression).getArray(), goIntoCast);
    case ASTNode.CAST_EXPRESSION:
      if (goIntoCast) {
        return resolveExpressionBinding(((CastExpression) expression).getExpression(), true);
      } else {
        return null;
      }
    case ASTNode.PARENTHESIZED_EXPRESSION:
      return resolveExpressionBinding(
          ((ParenthesizedExpression) expression).getExpression(), goIntoCast);
    case ASTNode.PREFIX_EXPRESSION:
      return resolveExpressionBinding(((PrefixExpression) expression).getOperand(), goIntoCast);
    case ASTNode.POSTFIX_EXPRESSION:
      return resolveExpressionBinding(((PostfixExpression) expression).getOperand(), goIntoCast);
    default:
      return null;
  }
}
项目:evosuite    文件:LoggingVisitor.java   
/** {@inheritDoc} */
@Override
public void endVisit(ArrayAccess node) {
    logger.warn("Method endVisitArrayAccess for " + node + " for " + node + " not implemented!");
    super.endVisit(node);
}
项目:evosuite    文件:LoggingVisitor.java   
/** {@inheritDoc} */
@Override
public boolean visit(ArrayAccess node) {
    logger.warn("Method visitArrayAccess for " + node + " for " + node + " not implemented!");
    return super.visit(node);
}
项目:Beagle    文件:NotRecursingAstVisitor.java   
@Override
public boolean visit(final ArrayAccess node) {
    return false;
}