Esempio n. 1
0
  private static boolean hasSideEffect(SimpleName reference) {
    ASTNode parent = reference.getParent();
    while (parent instanceof QualifiedName) {
      parent = parent.getParent();
    }
    if (parent instanceof FieldAccess) {
      parent = parent.getParent();
    }

    ASTNode node = null;
    int nameParentType = parent.getNodeType();
    if (nameParentType == ASTNode.ASSIGNMENT) {
      Assignment assignment = (Assignment) parent;
      node = assignment.getRightHandSide();
    } else if (nameParentType == ASTNode.SINGLE_VARIABLE_DECLARATION) {
      SingleVariableDeclaration decl = (SingleVariableDeclaration) parent;
      node = decl.getInitializer();
      if (node == null) return false;
    } else if (nameParentType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
      node = parent;
    } else {
      return false;
    }

    ArrayList<Expression> sideEffects = new ArrayList<Expression>();
    node.accept(new SideEffectFinder(sideEffects));
    return sideEffects.size() > 0;
  }
Esempio n. 2
0
  public IBinding[] getDeclarationsAfter(int offset, int flags) {
    try {
      org.eclipse.che.ide.ext.java.jdt.core.dom.NodeFinder finder =
          new org.eclipse.che.ide.ext.java.jdt.core.dom.NodeFinder(fRoot, offset, 0);
      ASTNode node = finder.getCoveringNode();
      if (node == null) {
        return null;
      }

      ASTNode declaration = findParentStatement(node);
      while (declaration instanceof Statement && declaration.getNodeType() != ASTNode.BLOCK) {
        declaration = declaration.getParent();
      }

      if (declaration instanceof Block) {
        DefaultBindingRequestor requestor = new DefaultBindingRequestor();
        DeclarationsAfterVisitor visitor =
            new DeclarationsAfterVisitor(node.getStartPosition(), flags, requestor);
        declaration.accept(visitor);
        List<IBinding> result = requestor.getResult();
        return result.toArray(new IBinding[result.size()]);
      }
      return NO_BINDING;
    } finally {
      clearLists();
    }
  }
Esempio n. 3
0
    private void visitBackwards(List<? extends ASTNode> list) {
      if (fBreak) return;

      for (int i = list.size() - 1; i >= 0; i--) {
        ASTNode curr = list.get(i);
        if (curr.getStartPosition() < fPosition) {
          curr.accept(this);
        }
      }
    }
Esempio n. 4
0
 private void removeVariableWithInitializer(
     ASTRewrite rewrite, ASTNode initializerNode, ASTNode statementNode, TextEditGroup group) {
   boolean performRemove = fForceRemove;
   if (!performRemove) {
     ArrayList<Expression> sideEffectNodes = new ArrayList<Expression>();
     initializerNode.accept(new SideEffectFinder(sideEffectNodes));
     performRemove = sideEffectNodes.isEmpty();
   }
   if (performRemove) {
     removeStatement(rewrite, statementNode, group);
     fRemovedAssignmentsCount++;
   } else {
     ASTNode initNode = rewrite.createMoveTarget(initializerNode);
     ExpressionStatement statement =
         rewrite.getAST().newExpressionStatement((Expression) initNode);
     rewrite.replace(statementNode, statement, null);
     fAlteredAssignmentsCount++;
   }
 }