Package lombok.ast

Examples of lombok.ast.Node


      ConstructorInvocation inv = new ConstructorInvocation();
      fillList(node.getArguments(), inv.rawArguments());
      fillList(node.getTypeArguments(), inv.rawConstructorTypeArguments(), FlagKey.TYPE_REFERENCE);
      inv.rawTypeReference(toTree(node.getIdentifier(), FlagKey.TYPE_REFERENCE));
      inv.rawQualifier(toTree(node.getEnclosingExpression()));
      Node n = toTree(node.getClassBody());
      if (n instanceof TypeDeclaration) {
        NormalTypeBody body = ((ClassDeclaration) n).astBody();
        if (body != null) body.unparent();
        inv.rawAnonymousClassBody(setPos(node.getClassBody(), body));
      }
View Full Code Here


      expr.astOperator(JcTreeBuilder.BINARY_OPERATORS.inverse().get(getTag(node)));
      set(node, expr);
    }
   
    @Override public void visitExec(JCExpressionStatement node) {
      Node expr = toTree(node.getExpression());
      if (expr instanceof SuperConstructorInvocation || expr instanceof AlternateConstructorInvocation) {
        setConversionPositionInfo(expr, "exec", getPosition(node));
        set(node, expr);
        return;
      }
View Full Code Here

    @Override public void visitForLoop(JCForLoop node) {
      For f = new For();
      f.rawCondition(toTree(node.getCondition()));
      f.rawStatement(toTree(node.getStatement()));
      for (JCExpressionStatement upd : node.getUpdate()) {
        Node updateNode = toTree(upd.getExpression());
        setConversionPositionInfo(updateNode, "exec", getPosition(upd));
        f.rawUpdates().addToEnd(updateNode);
      }
      List<JCStatement> initializers = node.getInitializer();
      // Multiple vardefs in a row need to trigger the JCVD version AND be washed through fillList to be turned into 1 VD.
      if (!initializers.isEmpty() && initializers.get(0) instanceof JCVariableDecl) {
        Block tmp = new Block();
        fillList(initializers, tmp.rawContents(), FlagKey.VARDEF_IS_DEFINITION);
        Node varDecl = tmp.rawContents().first();
        if (varDecl != null) varDecl.unparent();
        f.rawVariableDeclaration(varDecl);
      } else {
        for (JCStatement init : initializers) {
          if (init instanceof JCExpressionStatement) {
            Node initNode = toTree(((JCExpressionStatement) init).getExpression());
            setConversionPositionInfo(initNode, "exec", getPosition(init));
            f.rawExpressionInits().addToEnd(initNode);
          } else {
            f.rawExpressionInits().addToEnd(toTree(init));
          }
View Full Code Here

        Object nativeNode = node.getNativeNode();
        if (nativeNode != null) {
            return nativeNode;
        }

        Node parent = node.getParent();
        // The ECJ native nodes are sometimes spotty; for example, for a
        // MethodInvocation node we can have a null native node, but its
        // parent expression statement will point to the real MessageSend node
        if (parent != null) {
            nativeNode = parent.getNativeNode();
            if (nativeNode != null) {
                return nativeNode;
            }
        }
View Full Code Here

        Object nativeNode = node.getNativeNode();
        if (nativeNode != null) {
            return nativeNode;
        }

        Node parent = node.getParent();
        // The ECJ native nodes are sometimes spotty; for example, for a
        // MethodInvocation node we can have a null native node, but its
        // parent expression statement will point to the real MessageSend node
        if (parent != null) {
            nativeNode = parent.getNativeNode();
            if (nativeNode != null) {
                return nativeNode;
            }
        }
View Full Code Here

    formatter.nameNextElement("operand");
    visit(node.rawCondition());
    formatter.append(")");
    formatter.space();
   
    Node body = node.rawBody();
    if (!(body instanceof Block)) {
      visit(body);
      formatter.closeBlock();
      return true;
    }
View Full Code Here

    ListBuffer<CommentInfo> javadocs = ListBuffer.lb();
    for (CommentInfo commentInfo : comments) {
      if (commentInfo.isJavadoc()) javadocs.append(commentInfo);
    }
   
    Node result = getResult();
    if (javadocs.isEmpty()) return result;
   
    val nodePositions = new TreeMap<Integer, Node>();
    result.accept(new ForwardingAstVisitor() {
      private void addToMap(Node positionNode, Node linked) {
        if (positionNode == null) return;
       
        int start = positionNode.getPosition().getStart();
        if (start == -1) return;
       
        if (linked instanceof JavadocContainer || !nodePositions.containsKey(start)) {
          nodePositions.put(start, linked);
        }
      }
     
      private void addToMap(StrictListAccessor<?, ?> nodes, Node linked) {
        if (nodes == null) return;
       
        for (Node node : nodes) {
          addToMap(node, linked);
        }
      }
     
      @Override public boolean visitNode(Node node) {
        int start = node.getPosition().getStart();
       
        addToMap(node, node);
        try {
          if (node instanceof VariableDeclaration) {
            addToMap(((VariableDeclaration)node).astDefinition().astModifiers(), node);
            addToMap(((VariableDeclaration)node).astDefinition().astModifiers().astAnnotations(), node);
            addToMap(((VariableDeclaration)node).astDefinition().astTypeReference(), node);
            addToMap(((VariableDeclaration)node).astDefinition().astVariables().first().astName(), node);
          } else if (node instanceof TypeDeclaration) {
            addToMap(((TypeDeclaration)node).astModifiers(), node);
            addToMap(((TypeDeclaration)node).astModifiers().astAnnotations(), node);
          } else if (node instanceof MethodDeclaration) {
            addToMap(((MethodDeclaration)node).astModifiers(), node);
            addToMap(((MethodDeclaration)node).astModifiers().astAnnotations(), node);
            addToMap(((MethodDeclaration)node).astTypeVariables().first(), node);
            addToMap(((MethodDeclaration)node).astReturnTypeReference(), node);
            addToMap(((MethodDeclaration)node).astMethodName(), node);
          } else if (node instanceof ConstructorDeclaration) {
            addToMap(((ConstructorDeclaration)node).astModifiers(), node);
            addToMap(((ConstructorDeclaration)node).astModifiers().astAnnotations(), node);
            addToMap(((ConstructorDeclaration)node).astTypeVariables().first(), node);
            addToMap(((ConstructorDeclaration)node).astTypeName(), node);
          } else if (node instanceof EnumConstant) {
            addToMap(((EnumConstant)node).astName(), node);
            addToMap(((EnumConstant)node).astAnnotations(), node);
          } else if (node instanceof AnnotationMethodDeclaration) {
            addToMap(((AnnotationMethodDeclaration)node).astModifiers(), node);
            addToMap(((AnnotationMethodDeclaration)node).astModifiers().astAnnotations(), node);
            addToMap(((AnnotationMethodDeclaration)node).astReturnTypeReference(), node);
            addToMap(((AnnotationMethodDeclaration)node).astMethodName(), node);
          } else if (node instanceof PackageDeclaration) {
            addToMap(((PackageDeclaration)node).astAnnotations(), node);
          }
        } catch (NullPointerException e) {
          // Syntax errors in file - javadoc won't get linked up correctly.
        }
       
        if (node instanceof JavadocContainer || !nodePositions.containsKey(start)) {
          nodePositions.put(start, node);
        }
       
        return false;
      }
    });
   
    for (CommentInfo javadoc : javadocs) {
      try {
        Integer key = nodePositions.tailMap(javadoc.endPos).firstKey();
        Node node = nodePositions.get(key);
        if (node instanceof JavadocContainer) {
          attachJavadocToNode(javadoc, (JavadocContainer) node);
        }
      } catch (NoSuchElementException e) {
        // Then the javadoc obviously is 'floating', as its the last thing in the file.
View Full Code Here

      map.put(node, structure);
    }
  }
 
  private void buildSourceStructures(org.parboiled.Node<Node> pNode, Node owner, ListMultimap<Node, SourceStructure> map) {
    Node target = registeredStructures.remove(pNode);
    if (target != null || pNode.getChildren().isEmpty()) {
      int start = pNode.getStartIndex();
      int end = pNode.getEndIndex();
      String text = preprocessed.substring(start, end);
      SourceStructure structure = new SourceStructure(new Position(start, end), text);
      if (target != null) addSourceStructure(map, target, structure);
      else if (pNode.getValue() != null && !(pNode.getValue() instanceof TemporaryNode)) addSourceStructure(map, pNode.getValue(), structure);
      else if (owner != null) addSourceStructure(map, owner, structure);
    } else {
      Node possibleOwner = pNode.getValue();
      if (possibleOwner instanceof TemporaryNode) possibleOwner = null;
      for (org.parboiled.Node<Node> child : pNode.getChildren()) {
        if (child.getValue() == null || child.getValue() instanceof TemporaryNode) continue;
        /* If the next if holds true, then we aren't the true generator; the child generated the node and this pNode adopted it */
        if (child.getValue() == possibleOwner) possibleOwner = null;
View Full Code Here

    final TreeMap<Integer, Node> startPosMap = Maps.newTreeMap();
    for (Node node : nodes) node.accept(new ForwardingAstVisitor() {
      @Override public boolean visitNode(Node node) {
        if (node.isGenerated()) return false;
        int startPos = node.getPosition().getStart();
        Node current = startPosMap.get(startPos);
        if (current == null || !(current instanceof JavadocContainer)) {
          startPosMap.put(startPos, node);
        }
       
        return false;
      }
    });
   
    for (Comment comment : comments) {
      if (!comment.isJavadoc()) continue;
      Map<Integer, Node> tailMap = startPosMap.tailMap(comment.getPosition().getEnd());
      if (tailMap.isEmpty()) continue;
      Node assoc = tailMap.values().iterator().next();
      if (!(assoc instanceof JavadocContainer)) continue;
      JavadocContainer jc = (JavadocContainer) assoc;
      if (jc.rawJavadoc() != null) {
        if (jc.rawJavadoc().getPosition().getEnd() >= comment.getPosition().getEnd()) continue;
      }
View Full Code Here

      org.parboiled.Node<Node> head,
      List<org.parboiled.Node<Node>> operatorsNodes,
      List<String> operators,
      List<org.parboiled.Node<Node>> tail) {
   
    Node currentLeft = head.getValue();
   
    for (int i = 0; i < operators.size(); i++) {
      currentLeft = new BinaryExpression()
          .rawLeft(currentLeft)
          .rawRight(tail.get(i).getValue()).rawOperator(operators.get(i));
View Full Code Here

TOP

Related Classes of lombok.ast.Node

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.