Java Code Examples for com.sun.tools.javac.tree.JCTree#getTag()

The following examples show how to use com.sun.tools.javac.tree.JCTree#getTag() . 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: JavacTrees.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public Element getElement(TreePath path) {
    JCTree tree = (JCTree) path.getLeaf();
    Symbol sym = TreeInfo.symbolFor(tree);
    if (sym == null && TreeInfo.isDeclaration(tree)) {
        for (TreePath p = path; p != null; p = p.getParentPath()) {
            JCTree t = (JCTree) p.getLeaf();
            if (t.getTag() == JCTree.CLASSDEF) {
                JCClassDecl ct = (JCClassDecl) t;
                if (ct.sym != null) {
                    if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
                        attr.attribClass(ct.pos(), ct.sym);
                        sym = TreeInfo.symbolFor(tree);
                    }
                    break;
                }
            }
        }
    }
    return sym;
}
 
Example 2
Source File: Documentifier.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void documentifyBase(JCClassDecl base, boolean isTopLevel, boolean isFxStyle) {
    // add doc comment to class itself
    Comment comm = comment(docGen.getBaseComment(base, isTopLevel));
    curDocComments.putComment(base, comm);

    // add doc comments to members
    for (JCTree member : base.getMembers()) {
        switch (member.getTag()) {
            case VARDEF:
                documentifyField(base, (JCVariableDecl)member, isFxStyle);
                break;
            case METHODDEF:
                documentifyMethod(base, (JCMethodDecl)member, isFxStyle);
                break;
            case CLASSDEF:
                documentifyBase((JCClassDecl)member, false, isFxStyle);
                break;
        }
    }
}
 
Example 3
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Boolean expValue(JCTree exp) {
    while (exp.hasTag(PARENS))
        exp = ((JCParens)exp).expr;

    boolean eq;
    switch (exp.getTag()) {
    case EQ: eq = true;  break;
    case NE: eq = false; break;
    default:
        return null;
    }

    // we have a JCBinary(EQ|NE)
    // check if we have two literals (constants or null)
    JCBinary b = (JCBinary)exp;
    if (b.lhs.type.hasTag(BOT)) return expValueIsNull(eq, b.rhs);
    if (b.rhs.type.hasTag(BOT)) return expValueIsNull(eq, b.lhs);
    return null;
}
 
Example 4
Source File: JavacTrees.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public Element getElement(TreePath path) {
    JCTree tree = (JCTree) path.getLeaf();
    Symbol sym = TreeInfo.symbolFor(tree);
    if (sym == null && TreeInfo.isDeclaration(tree)) {
        for (TreePath p = path; p != null; p = p.getParentPath()) {
            JCTree t = (JCTree) p.getLeaf();
            if (t.getTag() == JCTree.CLASSDEF) {
                JCClassDecl ct = (JCClassDecl) t;
                if (ct.sym != null) {
                    if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
                        attr.attribClass(ct.pos(), ct.sym);
                        sym = TreeInfo.symbolFor(tree);
                    }
                    break;
                }
            }
        }
    }
    return sym;
}
 
Example 5
Source File: CheckAttributedTree.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
Info(JCTree tree, EndPosTable endPosTable) {
    this.tree = tree;
    tag = tree.getTag();
    start = TreeInfo.getStartPos(tree);
    pos = tree.pos;
    end = TreeInfo.getEndPos(tree, endPosTable);
}
 
Example 6
Source File: TreePosTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
Info(JCTree tree, EndPosTable endPosTable) {
    this.tree = tree;
    tag = tree.getTag();
    start = TreeInfo.getStartPos(tree);
    pos = tree.pos;
    end = TreeInfo.getEndPos(tree, endPosTable);
}
 
Example 7
Source File: TreePosTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
Info(JCTree tree, EndPosTable endPosTable) {
    this.tree = tree;
    tag = tree.getTag();
    start = TreeInfo.getStartPos(tree);
    pos = tree.pos;
    end = TreeInfo.getEndPos(tree, endPosTable);
}
 
Example 8
Source File: TreeFinder.java    From annotation-tools with MIT License 5 votes vote down vote up
/**
 * Scans the given tree with the given {@link Insertions} and returns
 * the mapping from source position to insertion text.
 *
 * <p>
 * <i>N.B.:</i> This method calls {@code scan()} internally.
 * </p>
 *
 * @param node the tree to scan
 * @param insertions the insertion criteria
 * @return the source position to insertion text mapping
 */
public SetMultimap<Pair<Integer, ASTPath>, Insertion>
getPositions(JCCompilationUnit node, Insertions insertions) {
  List<Insertion> list = new ArrayList<>();
  treePathCache.clear();
  if (annotator.Main.temporaryDebug) {
    System.out.println("insertions size: " + insertions.size());
    System.out.println("insertions.forOuterClass(\"\") size: " + insertions.forOuterClass(node, "").size());
    System.out.println("list pre-size: " + list.size());
  }
  list.addAll(insertions.forOuterClass(node, ""));
  if (annotator.Main.temporaryDebug) {
    System.out.println("list post-size: " + list.size());
  }
  for (JCTree decl : node.getTypeDecls()) {
    if (decl.getTag() == JCTree.Tag.CLASSDEF) {
      String name = ((JCClassDecl) decl).sym.className();
      Collection<Insertion> forClass = insertions.forOuterClass(node, name);
      if (annotator.Main.temporaryDebug) {
        System.out.println("insertions size: " + insertions.size());
        System.out.println("insertions.forOuterClass("+name+") size: " + forClass.size());
        System.out.println("list pre-size: " + list.size());
      }
      list.addAll(forClass);
      if (annotator.Main.temporaryDebug) {
        System.out.println("list post-size: " + list.size());
      }
    }
  }
  return getInsertionsByPosition(node, list);
}
 
Example 9
Source File: TreePosTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
Info(JCTree tree, EndPosTable endPosTable) {
    this.tree = tree;
    tag = tree.getTag();
    start = TreeInfo.getStartPos(tree);
    pos = tree.pos;
    end = TreeInfo.getEndPos(tree, endPosTable);
}
 
Example 10
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private VariableDeclarationExpression toResource(JCTree resourceTree) {
  if (resourceTree.getTag() == Tag.VARDEF) {
    return createVariableDeclarationExpression((JCVariableDecl) resourceTree);
  }
  checkArgument(resourceTree.getTag() == Tag.IDENT);
  return toResource((JCIdent) resourceTree);
}
 
Example 11
Source File: CheckAttributedTree.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
Info(JCTree tree, EndPosTable endPosTable) {
    this.tree = tree;
    tag = tree.getTag();
    start = TreeInfo.getStartPos(tree);
    pos = tree.pos;
    end = TreeInfo.getEndPos(tree, endPosTable);
}
 
Example 12
Source File: TreePosTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
Info(JCTree tree, EndPosTable endPosTable) {
    this.tree = tree;
    tag = tree.getTag();
    start = TreeInfo.getStartPos(tree);
    pos = tree.pos;
    end = TreeInfo.getEndPos(tree, endPosTable);
}
 
Example 13
Source File: VeryPretty.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Name fullName(JCTree tree) {
switch (tree.getTag()) {
case IDENT:
    return ((JCIdent) tree).name;
case SELECT:
           JCFieldAccess sel = (JCFieldAccess)tree;
    Name sname = fullName(sel.selected);
    return sname != null && sname.getByteLength() > 0 ? sname.append('.', sel.name) : sel.name;
default:
    return null;
}
   }
 
Example 14
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Set varargsElement field on a given tree (must be either a new class tree
 * or a method call tree)
 */
private void setVarargsIfNeeded(JCTree tree, Type varargsElement) {
    if (varargsElement != null) {
        switch (tree.getTag()) {
            case APPLY: ((JCMethodInvocation)tree).varargsElement = varargsElement; break;
            case NEWCLASS: ((JCNewClass)tree).varargsElement = varargsElement; break;
            case TYPECAST: setVarargsIfNeeded(((JCTypeCast) tree).expr, varargsElement); break;
            default: throw new AssertionError();
        }
    }
}
 
Example 15
Source File: CheckAttributedTree.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
Info(JCTree tree, EndPosTable endPosTable) {
    this.tree = tree;
    tag = tree.getTag();
    start = TreeInfo.getStartPos(tree);
    pos = tree.pos;
    end = TreeInfo.getEndPos(tree, endPosTable);
}
 
Example 16
Source File: TreePosTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
Info(JCTree tree, EndPosTable endPosTable) {
    this.tree = tree;
    tag = tree.getTag();
    start = TreeInfo.getStartPos(tree);
    pos = tree.pos;
    end = TreeInfo.getEndPos(tree, endPosTable);
}
 
Example 17
Source File: CheckAttributedTree.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
Info(JCTree tree, EndPosTable endPosTable) {
    this.tree = tree;
    tag = tree.getTag();
    start = TreeInfo.getStartPos(tree);
    pos = tree.pos;
    end = TreeInfo.getEndPos(tree, endPosTable);
}
 
Example 18
Source File: TreePosTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
Info(JCTree tree, EndPosTable endPosTable) {
    this.tree = tree;
    tag = tree.getTag();
    start = TreeInfo.getStartPos(tree);
    pos = tree.pos;
    end = TreeInfo.getEndPos(tree, endPosTable);
}
 
Example 19
Source File: TreePosTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
Info(JCTree tree, EndPosTable endPosTable) {
    this.tree = tree;
    tag = tree.getTag();
    start = TreeInfo.getStartPos(tree);
    pos = tree.pos;
    end = TreeInfo.getEndPos(tree, endPosTable);
}
 
Example 20
Source File: VeryPretty.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Is the given tree an enumerator definition? */
private static boolean isEnumerator(JCTree tree) {
    return tree.getTag() == JCTree.Tag.VARDEF && (((JCVariableDecl) tree).mods.flags & ENUM) != 0;
}