Java Code Examples for org.eclipse.jdt.core.dom.VariableDeclarationFragment#accept()

The following examples show how to use org.eclipse.jdt.core.dom.VariableDeclarationFragment#accept() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationExpression it) {
  final Procedure2<VariableDeclarationFragment, Integer> _function = (VariableDeclarationFragment frag, Integer counter) -> {
    this.appendModifiers(it, it.modifiers());
    this.appendToBuffer(this._aSTFlattenerUtils.handleVariableDeclaration(it.modifiers()));
    this.appendSpaceToBuffer();
    it.getType().accept(this);
    this.appendSpaceToBuffer();
    frag.accept(this);
    int _size = it.fragments().size();
    int _minus = (_size - 1);
    boolean _lessThan = ((counter).intValue() < _minus);
    if (_lessThan) {
      this.appendToBuffer(",");
      this.appendSpaceToBuffer();
    }
  };
  IterableExtensions.<VariableDeclarationFragment>forEach(it.fragments(), _function);
  return false;
}
 
Example 2
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final FieldDeclaration it) {
  Javadoc _javadoc = it.getJavadoc();
  boolean _tripleNotEquals = (_javadoc != null);
  if (_tripleNotEquals) {
    it.getJavadoc().accept(this);
  }
  final Consumer<VariableDeclarationFragment> _function = (VariableDeclarationFragment frag) -> {
    this.appendModifiers(it, it.modifiers());
    boolean _isPackageVisibility = this._aSTFlattenerUtils.isPackageVisibility(Iterables.<Modifier>filter(it.modifiers(), Modifier.class));
    if (_isPackageVisibility) {
      ASTNode _parent = it.getParent();
      if ((_parent instanceof TypeDeclaration)) {
        ASTNode _parent_1 = it.getParent();
        boolean _isInterface = ((TypeDeclaration) _parent_1).isInterface();
        boolean _not = (!_isInterface);
        if (_not) {
          this.appendToBuffer("package ");
        }
      }
    }
    it.getType().accept(this);
    this.appendExtraDimensions(frag.getExtraDimensions());
    this.appendSpaceToBuffer();
    frag.accept(this);
  };
  it.fragments().forEach(_function);
  return false;
}
 
Example 3
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationStatement it) {
  boolean _isEmpty = IterableExtensions.isEmpty(Iterables.<Annotation>filter(it.modifiers(), Annotation.class));
  final boolean hasAnnotations = (!_isEmpty);
  final Consumer<VariableDeclarationFragment> _function = (VariableDeclarationFragment frag) -> {
    if (hasAnnotations) {
      this.appendToBuffer("/*FIXME Cannot add Annotation to Variable declaration. Java code: ");
    }
    final Function1<ASTNode, StringBuffer> _function_1 = (ASTNode it_1) -> {
      StringBuffer _xifexpression = null;
      if (hasAnnotations) {
        StringBuffer _xblockexpression = null;
        {
          this.appendToBuffer("*/");
          _xblockexpression = this.appendLineWrapToBuffer();
        }
        _xifexpression = _xblockexpression;
      }
      return _xifexpression;
    };
    this.appendModifiers(it, it.modifiers(), _function_1);
    this.appendToBuffer(this._aSTFlattenerUtils.handleVariableDeclaration(it.modifiers()));
    this.appendSpaceToBuffer();
    boolean _isMissingType = this.isMissingType(it.getType());
    boolean _not = (!_isMissingType);
    if (_not) {
      it.getType().accept(this);
    }
    this.appendExtraDimensions(frag.getExtraDimensions());
    this.appendSpaceToBuffer();
    frag.accept(this);
    this.appendSpaceToBuffer();
  };
  it.fragments().forEach(_function);
  return false;
}
 
Example 4
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean visit(final PostfixExpression node) {
  final AST dummyAST = AST.newAST(node.getAST().apiLevel());
  final PostfixExpression.Operator pfOperator = node.getOperator();
  Expression _operand = node.getOperand();
  if ((_operand instanceof ArrayAccess)) {
    Expression _operand_1 = node.getOperand();
    final ArrayAccess pfOperand = ((ArrayAccess) _operand_1);
    if ((Objects.equal(pfOperator, PostfixExpression.Operator.INCREMENT) || 
      Objects.equal(pfOperator, PostfixExpression.Operator.DECREMENT))) {
      final String arrayName = this.computeArrayName(pfOperand);
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("_postIndx_");
      _builder.append(arrayName);
      final String idxName = _builder.toString();
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("_postVal_");
      _builder_1.append(arrayName);
      final String tempVarName = _builder_1.toString();
      StringConcatenation _builder_2 = new StringConcatenation();
      _builder_2.append("{ var ");
      _builder_2.append(idxName);
      _builder_2.append("=");
      this.appendToBuffer(_builder_2.toString());
      pfOperand.getIndex().accept(this);
      StringConcatenation _builder_3 = new StringConcatenation();
      _builder_3.append(" ");
      _builder_3.append("var  ");
      this.appendToBuffer(_builder_3.toString());
      final VariableDeclarationFragment varDeclaration = dummyAST.newVariableDeclarationFragment();
      varDeclaration.setName(dummyAST.newSimpleName(tempVarName));
      ASTNode _copySubtree = ASTNode.copySubtree(dummyAST, pfOperand);
      final ArrayAccess arrayAccess = ((ArrayAccess) _copySubtree);
      arrayAccess.setIndex(dummyAST.newSimpleName(idxName));
      varDeclaration.setInitializer(arrayAccess);
      varDeclaration.accept(this);
      final InfixExpression infixOp = dummyAST.newInfixExpression();
      infixOp.setLeftOperand(dummyAST.newSimpleName(tempVarName));
      PostfixExpression.Operator _operator = node.getOperator();
      boolean _equals = Objects.equal(_operator, PostfixExpression.Operator.DECREMENT);
      if (_equals) {
        infixOp.setOperator(InfixExpression.Operator.MINUS);
      } else {
        infixOp.setOperator(InfixExpression.Operator.PLUS);
      }
      infixOp.setRightOperand(dummyAST.newNumberLiteral("1"));
      final Assignment assigment = dummyAST.newAssignment();
      ASTNode _copySubtree_1 = ASTNode.copySubtree(dummyAST, pfOperand);
      final ArrayAccess writeArray = ((ArrayAccess) _copySubtree_1);
      writeArray.setIndex(dummyAST.newSimpleName(idxName));
      assigment.setLeftHandSide(writeArray);
      ASTNode _copySubtree_2 = ASTNode.copySubtree(dummyAST, infixOp);
      assigment.setRightHandSide(((Expression) _copySubtree_2));
      assigment.accept(this);
      StringConcatenation _builder_4 = new StringConcatenation();
      String _xifexpression = null;
      boolean _needsReturnValue = this._aSTFlattenerUtils.needsReturnValue(node);
      if (_needsReturnValue) {
        _xifexpression = tempVarName;
      }
      _builder_4.append(_xifexpression);
      _builder_4.append(" }");
      this.appendToBuffer(_builder_4.toString());
      return false;
    }
  }
  node.getOperand().accept(this);
  this.appendToBuffer(pfOperator.toString());
  return false;
}