Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.ArrayAccess


     * @param aname
     * @param iname
     * @return array access
     */
    public ArrayAccessBuilder buildArrayIndexAccess(String aname, String iname) {
        ArrayAccess access = getAST().newArrayAccess();
        access.setArray(getAST().newSimpleName(aname));
        access.setIndex(getAST().newSimpleName(iname));
        return new ArrayAccessBuilder(this, access);
    }
View Full Code Here


  @Test
  public void testArrayRead() throws Exception {
    CompilationUnit cu = EclipseTACSimpleTestDriver.parseCode("ArrayRead", ARRAY_READ);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(cu);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    ArrayAccess read = (ArrayAccess) EclipseTACSimpleTestDriver.getLastStatementReturn(m).getExpression();
    TACInstruction instr = tac.instruction(read);
    Assert.assertTrue(instr != null);
    Assert.assertTrue(instr instanceof LoadArrayInstruction);
    LoadArrayInstruction load = (LoadArrayInstruction) instr;
   
    Assert.assertEquals(tac.variable(read.getArray()), load.getSourceArray());
    Assert.assertTrue(load.getSourceArray() instanceof SourceVariable);
    Assert.assertEquals("a", load.getSourceArray().getSourceString());
   
    Assert.assertEquals(tac.variable(read.getIndex()), load.getArrayIndex());
    Assert.assertTrue(load.getArrayIndex() instanceof SourceVariable);
    Assert.assertEquals("index", load.getArrayIndex().getSourceString());
  }
View Full Code Here

        // field.
        Expression field = ast.newSimpleName(fieldName);

        if (indices > 0) {
            for (int i = 0; i < indices; i++) {
                ArrayAccess arrayAccess = ast.newArrayAccess();
                arrayAccess.setArray(field);
                arrayAccess.setIndex(ast.newSimpleName("index" + i));
                field = arrayAccess;
            }
        }

        // Set the field as the next argument.
View Full Code Here

        // field.
        Expression field = ast.newSimpleName(fieldName);

        if (indices > 0) {
            for (int i = 0; i < indices; i++) {
                ArrayAccess arrayAccess = ast.newArrayAccess();
                arrayAccess.setArray(field);
                arrayAccess.setIndex(ast.newSimpleName("index" + i));
                field = arrayAccess;
            }
        }

        // Set the field as the next argument.
View Full Code Here

        // Check if we need to refactor the argument.
        boolean needRefactor = type.isArray();

        if (node instanceof ArrayAccess) {
            ArrayAccess arrayAccess = (ArrayAccess) node;

            while (arrayAccess.getArray() instanceof ArrayAccess) {
                arrayAccess = (ArrayAccess) arrayAccess.getArray();
                arrayType = arrayType.addOneDimension();
            }

            array = arrayAccess.getArray();
            arrayType = arrayType.addOneDimension();

            if (array instanceof MethodInvocation) {
                needRefactor = false;
            }
        }

        if (needRefactor) {
            // Refactor the expression.
            AST ast = node.getAST();
            //CompilationUnit root = (CompilationUnit) node.getRoot();
            //String typeClassName = getClassName(typeName, state, root);

            int nIndices = 0;

            Expression nodeIterator = node;

            while (nodeIterator instanceof ParenthesizedExpression) {
                nodeIterator = ((ParenthesizedExpression) nodeIterator)
                        .getExpression();
            }

            List indices = new LinkedList();

            while (nodeIterator instanceof ArrayAccess) {
                nIndices++;

                ArrayAccess arrayAccess = (ArrayAccess) nodeIterator;
                indices
                        .add(0, ASTNode
                                .copySubtree(ast, arrayAccess.getIndex()));
                nodeIterator = arrayAccess.getArray();

                while (nodeIterator instanceof ParenthesizedExpression) {
                    nodeIterator = ((ParenthesizedExpression) nodeIterator)
                            .getExpression();
                }
View Full Code Here

        // If left-hand side is an array access, store the indices.
        List indices = new LinkedList();

        while (leftHand instanceof ArrayAccess) {
            ArrayAccess arrayAccess = (ArrayAccess) leftHand;
            indices.add(0, ASTNode.copySubtree(ast, arrayAccess.getIndex()));
            leftHand = arrayAccess.getArray();

            while (leftHand instanceof ParenthesizedExpression) {
                leftHand = ((ParenthesizedExpression) leftHand).getExpression();
            }
        }
View Full Code Here

    else if(e instanceof CastExpression){
      CastExpression cex=(CastExpression)e;
      processExpression(parent, cex.getExpression(), cu, resource, stack, monitor, HistoryDefinitionLocation.UNDEFINED,false);
    }
    else if(e instanceof ArrayAccess) {
      ArrayAccess ae=(ArrayAccess)e;
     
      HistoryDefinitionLocation arrAccess;
      if(!first){
        arrAccess= new HistoryDefinitionLocation(
          e.toString(),
          resource,
          cu.getLineNumber(e.getStartPosition()),
          e,
          parent, HistoryDefinitionLocation.ARRAYACCESS);
      }
      else arrAccess=parent;
      if(registerExpansion(arrAccess))
        processExpression(arrAccess, ae.getArray(),  cu, resource, stack, monitor, HistoryDefinitionLocation.ARRAYACCESS,false);
     
    }
    else if(e instanceof ClassInstanceCreation)
    {
      ClassInstanceCreation c=(ClassInstanceCreation)e;
View Full Code Here

      addHistoryEntry(dl);
      fContentProvider.addElement(dl);
      refresh();
      }
     else if(covering instanceof ArrayAccess) {
       ArrayAccess ae=(ArrayAccess)covering;
       HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
      ae.toString(),
            (IFile)resource,
            unit.getLineNumber(0),
            covering,null, HistoryDefinitionLocation.ARRAYACCESS);
        processExpression(dl, ae, unit, resource, new LinkedList<MethodInvocation>(), monitor, HistoryDefinitionLocation.INITIAL,true);
        setCurrentInput(dl);
        addHistoryEntry(dl);   
        fContentProvider.addElement(dl);
       
        refresh();
       
      }
       else if(covering instanceof CastExpression) {
         CastExpression ae=(CastExpression)covering;
         HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
              ae.toString(),
              (IFile)resource,
              unit.getLineNumber(0),
              covering,null, HistoryDefinitionLocation.INITIAL);
          processExpression(dl, ae, unit, resource, new LinkedList<MethodInvocation>(), monitor, HistoryDefinitionLocation.CALL,true);
          setCurrentInput(dl);
          addHistoryEntry(dl);
          fContentProvider.addElement(dl);
          refresh();
        }
       else if(covering instanceof ClassInstanceCreation) {
         ClassInstanceCreation ae=(ClassInstanceCreation)covering;
         HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
              ae.toString(),
              (IFile)resource,
              unit.getLineNumber(0),
              covering,null, HistoryDefinitionLocation.CLASS_INSTANCE_CREATION);
          processExpression(dl, ae, unit, resource, new LinkedList<MethodInvocation>(), monitor, HistoryDefinitionLocation.CALL,true);
          setCurrentInput(dl);
View Full Code Here

      break;
    }

    case ASTNode.ARRAY_ACCESS: {
      final ArrayAccess access = (ArrayAccess) node;
      // if coming up from the index.
      if (containedIn(access.getIndex(), this.name))
        throw new DefinitelyNotEnumerizableException(
            Messages.ASTNodeProcessor_IllegalNodeContext, node);
      else
        this.process(node.getParent());
      break;
View Full Code Here

      }
      break;
    }

    case ASTNode.ARRAY_ACCESS: {
      final ArrayAccess access = (ArrayAccess) node;
      this.processExpression(access.getArray());
      break;
    }

    case ASTNode.ARRAY_CREATION: {
      final ArrayCreation creation = (ArrayCreation) node;
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.ArrayAccess

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.