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

The following examples show how to use com.sun.tools.javac.tree.JCTree#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: CheckAttributedTree.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void scan(JCTree tree) {
    if (tree == null ||
            excludeTags.contains(treeUtil.nameFromTag(tree.getTag()))) {
        return;
    }

    Info self = new Info(tree, endPosTable);
    if (mandatoryType(tree)) {
        check(tree.type != null,
                "'null' field 'type' found in tree ", self);
        if (tree.type==null)
            Thread.dumpStack();
    }

    Field errField = checkFields(tree);
    if (errField!=null) {
        check(false,
                "'null' field '" + errField.getName() + "' found in tree ", self);
    }

    Info prevEncl = encl;
    encl = self;
    tree.accept(this);
    encl = prevEncl;
}
 
Example 2
Source File: ButterKnifeProcessor.java    From butterknife with Apache License 2.0 6 votes vote down vote up
private Map<Integer, Id> elementToIds(Element element, Class<? extends Annotation> annotation,
    int[] values) {
  Map<Integer, Id> resourceIds = new LinkedHashMap<>();
  JCTree tree = (JCTree) trees.getTree(element, getMirror(element, annotation));
  if (tree != null) { // tree can be null if the references are compiled types and not source
    rScanner.reset();
    tree.accept(rScanner);
    resourceIds = rScanner.resourceIds;
  }

  // Every value looked up should have an Id
  for (int value : values) {
    resourceIds.putIfAbsent(value, new Id(value));
  }
  return resourceIds;
}
 
Example 3
Source File: CheckAttributedTree.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void scan(JCTree tree) {
    if (tree == null ||
            excludeTags.contains(treeUtil.nameFromTag(tree.getTag()))) {
        return;
    }

    Info self = new Info(tree, endPosTable);
    if (mandatoryType(tree)) {
        check(tree.type != null,
                "'null' field 'type' found in tree ", self);
        if (tree.type==null)
            new Throwable().printStackTrace();
    }

    Field errField = checkFields(tree);
    if (errField!=null) {
        check(false,
                "'null' field '" + errField.getName() + "' found in tree ", self);
    }

    Info prevEncl = encl;
    encl = self;
    tree.accept(this);
    encl = prevEncl;
}
 
Example 4
Source File: WidthEstimator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void width(JCTree tree, int prec) {
if (tree != null) {
    int prevPrec = this.prec;
    this.prec = prec;
    tree.accept(this);
    this.prec = prevPrec;
}
   }
 
Example 5
Source File: ArgumentAttr.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Main entry point for attributing an argument with given tree and attribution environment.
 */
Type attribArg(JCTree tree, Env<AttrContext> env) {
    Env<AttrContext> prevEnv = this.env;
    try {
        this.env = env;
        tree.accept(this);
        return result;
    } finally {
        this.env = prevEnv;
    }
}
 
Example 6
Source File: Enter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Visitor method: enter all classes in given tree, catching any
 *  completion failure exceptions. Return the tree's type.
 *
 *  @param tree    The tree to be visited.
 *  @param env     The environment visitor argument.
 */
Type classEnter(JCTree tree, Env<AttrContext> env) {
    Env<AttrContext> prevEnv = this.env;
    try {
        this.env = env;
        annotate.blockAnnotations();
        tree.accept(this);
        return result;
    }  catch (CompletionFailure ex) {
        return chk.completionError(tree.pos(), ex);
    } finally {
        annotate.unblockAnnotations();
        this.env = prevEnv;
    }
}
 
Example 7
Source File: DPrinter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected void printTree(String label, JCTree tree) {
    if (tree == null) {
        printNull(label);
    } else {
        indent();
        String ext;
        try {
            ext = tree.getKind().name();
        } catch (Throwable t) {
            ext = "n/a";
        }
        out.print(label + ": " + info(tree.getClass(), tree.getTag(), ext));
        if (showPositions) {
            // We can always get start position, but to get end position
            // and/or line+offset, we would need a JCCompilationUnit
            out.print(" pos:" + tree.pos);
        }
        if (showTreeTypes && tree.type != null)
            out.print(" type:" + toString(tree.type));
        Symbol sym;
        if (showTreeSymbols && (sym = TreeInfo.symbolFor(tree)) != null)
            out.print(" sym:" + toString(sym));
        out.println();

        indent(+1);
        if (showSrc) {
            indent();
            out.println("src: " + Pretty.toSimpleString(tree, maxSrcLength));
        }
        tree.accept(treeVisitor);
        indent(-1);
    }
}
 
Example 8
Source File: DPrinter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected void printTree(String label, JCTree tree) {
    if (tree == null) {
        printNull(label);
    } else {
        indent();
        String ext;
        try {
            ext = tree.getKind().name();
        } catch (Throwable t) {
            ext = "n/a";
        }
        out.print(label + ": " + info(tree.getClass(), tree.getTag(), ext));
        if (showPositions) {
            // We can always get start position, but to get end position
            // and/or line+offset, we would need a JCCompilationUnit
            out.print(" pos:" + tree.pos);
        }
        if (showTreeTypes && tree.type != null)
            out.print(" type:" + toString(tree.type));
        Symbol sym;
        if (showTreeSymbols && (sym = TreeInfo.symbolFor(tree)) != null)
            out.print(" sym:" + toString(sym));
        out.println();

        indent(+1);
        if (showSrc) {
            indent();
            out.println("src: " + Pretty.toSimpleString(tree, maxSrcLength));
        }
        tree.accept(treeVisitor);
        indent(-1);
    }
}
 
Example 9
Source File: MemberEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Enter field and method definitions and process import
 *  clauses, catching any completion failure exceptions.
 */
protected void memberEnter(JCTree tree, Env<AttrContext> env) {
    Env<AttrContext> prevEnv = this.env;
    try {
        this.env = env;
        tree.accept(this);
    }  catch (CompletionFailure ex) {
        chk.completionError(tree.pos(), ex);
    } finally {
        this.env = prevEnv;
    }
}
 
Example 10
Source File: WidthEstimator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public int estimateWidth(JCTree t, int maxwidth) {
width = 0;
this.maxwidth = maxwidth;
t.accept(this);
return width;
   }
 
Example 11
Source File: TreePosTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void scan(JCTree tree) {
    if (tree == null)
        return;

    Info self = new Info(tree, endPosTable);
    if (check(encl, self)) {
        // Modifiers nodes are present throughout the tree even where
        // there is no corresponding source text.
        // Redundant semicolons in a class definition can cause empty
        // initializer blocks with no positions.
        if ((self.tag == MODIFIERS || self.tag == BLOCK)
                && self.pos == NOPOS) {
            // If pos is NOPOS, so should be the start and end positions
            check("start == NOPOS", encl, self, self.start == NOPOS);
            check("end == NOPOS", encl, self, self.end == NOPOS);
        } else {
            // For this node, start , pos, and endpos should be all defined
            check("start != NOPOS", encl, self, self.start != NOPOS);
            check("pos != NOPOS", encl, self, self.pos != NOPOS);
            check("end != NOPOS", encl, self, self.end != NOPOS);
            // The following should normally be ordered
            // encl.start <= start <= pos <= end <= encl.end
            // In addition, the position of the enclosing node should be
            // within this node.
            // The primary exceptions are for array type nodes, because of the
            // need to support legacy syntax:
            //    e.g.    int a[];    int[] b[];    int f()[] { return null; }
            // and because of inconsistent nesting of left and right of
            // array declarations:
            //    e.g.    int[][] a = new int[2][];
            if (!(encl.tag == REFERENCE && self.tag == ANNOTATED_TYPE)) {
            check("encl.start <= start", encl, self, encl.start <= self.start);
            }
            check("start <= pos", encl, self, self.start <= self.pos);
            if (!( (self.tag == TYPEARRAY ||
                    isAnnotatedArray(self.tree))
                    && (encl.tag == VARDEF ||
                        encl.tag == METHODDEF ||
                        encl.tag == TYPEARRAY ||
                        isAnnotatedArray(encl.tree))
                   ||
                    encl.tag == ANNOTATED_TYPE && self.tag == SELECT
                   ||
                    encl.tag == REFERENCE && self.tag == ANNOTATED_TYPE
                 )) {
                check("encl.pos <= start || end <= encl.pos",
                        encl, self, encl.pos <= self.start || self.end <= encl.pos);
            }
            check("pos <= end", encl, self, self.pos <= self.end);
            if (!( (self.tag == TYPEARRAY || isAnnotatedArray(self.tree)) &&
                    (encl.tag == TYPEARRAY || isAnnotatedArray(encl.tree))
                   ||
                    encl.tag == MODIFIERS && self.tag == ANNOTATION
                 ) ) {
                check("end <= encl.end", encl, self, self.end <= encl.end);
            }
        }
    }

    Info prevEncl = encl;
    encl = self;
    tree.accept(this);
    encl = prevEncl;
}
 
Example 12
Source File: JavadocMemberEnter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void scan(JCTree tree) {
    // short circuit scan when end result is definitely false
    if (maybeConstantExpr && tree != null)
        tree.accept(this);
}
 
Example 13
Source File: JavadocMemberEnter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void scan(JCTree tree) {
    // short circuit scan when end result is definitely false
    if (maybeConstantExpr && tree != null)
        tree.accept(this);
}
 
Example 14
Source File: JavadocMemberEnter.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void scan(JCTree tree) {
    // short circuit scan when end result is definitely false
    if (maybeConstantExpr && tree != null)
        tree.accept(this);
}
 
Example 15
Source File: DanglingElseChecker.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public boolean hasDanglingElse(JCTree t) {
if(t==null) return false;
foundDanglingElse = false;
t.accept(this);
return foundDanglingElse;
   }
 
Example 16
Source File: JavadocMemberEnter.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void scan(JCTree tree) {
    // short circuit scan when end result is definitely false
    if (maybeConstantExpr && tree != null)
        tree.accept(this);
}
 
Example 17
Source File: ArgumentAttr.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void visitTree(JCTree that) {
    //delegates to Attr
    that.accept(attr);
    result = attr.result;
}
 
Example 18
Source File: TreePosTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void scan(JCTree tree) {
    if (tree == null)
        return;

    Info self = new Info(tree, endPosTable);
    if (check(encl, self)) {
        // Modifiers nodes are present throughout the tree even where
        // there is no corresponding source text.
        // Redundant semicolons in a class definition can cause empty
        // initializer blocks with no positions.
        if ((self.tag == MODIFIERS || self.tag == BLOCK)
                && self.pos == NOPOS) {
            // If pos is NOPOS, so should be the start and end positions
            check("start == NOPOS", encl, self, self.start == NOPOS);
            check("end == NOPOS", encl, self, self.end == NOPOS);
        } else {
            // For this node, start , pos, and endpos should be all defined
            check("start != NOPOS", encl, self, self.start != NOPOS);
            check("pos != NOPOS", encl, self, self.pos != NOPOS);
            check("end != NOPOS", encl, self, self.end != NOPOS);
            // The following should normally be ordered
            // encl.start <= start <= pos <= end <= encl.end
            // In addition, the position of the enclosing node should be
            // within this node.
            // The primary exceptions are for array type nodes, because of the
            // need to support legacy syntax:
            //    e.g.    int a[];    int[] b[];    int f()[] { return null; }
            // and because of inconsistent nesting of left and right of
            // array declarations:
            //    e.g.    int[][] a = new int[2][];
            check("encl.start <= start", encl, self, encl.start <= self.start);
            check("start <= pos", encl, self, self.start <= self.pos);
            if (!( (self.tag == TYPEARRAY ||
                    isAnnotatedArray(self.tree))
                    && (encl.tag == VARDEF ||
                        encl.tag == METHODDEF ||
                        encl.tag == TYPEARRAY ||
                        isAnnotatedArray(encl.tree))
                   ||
                    encl.tag == ANNOTATED_TYPE && self.tag == SELECT
                 )) {
                check("encl.pos <= start || end <= encl.pos",
                        encl, self, encl.pos <= self.start || self.end <= encl.pos);
            }
            check("pos <= end", encl, self, self.pos <= self.end);
            if (!( (self.tag == TYPEARRAY || isAnnotatedArray(self.tree)) &&
                    (encl.tag == TYPEARRAY || isAnnotatedArray(encl.tree))
                   ||
                    encl.tag == MODIFIERS && self.tag == ANNOTATION
                 ) ) {
                check("end <= encl.end", encl, self, self.end <= encl.end);
            }
        }
    }

    Info prevEncl = encl;
    encl = self;
    tree.accept(this);
    encl = prevEncl;
}
 
Example 19
Source File: ArgumentAttr.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visitTree(JCTree that) {
    //delegates to Attr
    that.accept(attr);
    result = attr.result;
}
 
Example 20
Source File: TreePosTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void scan(JCTree tree) {
    if (tree == null)
        return;

    Info self = new Info(tree, endPosTable);
    if (check(encl, self)) {
        // Modifiers nodes are present throughout the tree even where
        // there is no corresponding source text.
        // Redundant semicolons in a class definition can cause empty
        // initializer blocks with no positions.
        if ((self.tag == MODIFIERS || self.tag == BLOCK)
                && self.pos == NOPOS) {
            // If pos is NOPOS, so should be the start and end positions
            check("start == NOPOS", encl, self, self.start == NOPOS);
            check("end == NOPOS", encl, self, self.end == NOPOS);
        } else {
            // For this node, start , pos, and endpos should be all defined
            check("start != NOPOS", encl, self, self.start != NOPOS);
            check("pos != NOPOS", encl, self, self.pos != NOPOS);
            check("end != NOPOS", encl, self, self.end != NOPOS);
            // The following should normally be ordered
            // encl.start <= start <= pos <= end <= encl.end
            // In addition, the position of the enclosing node should be
            // within this node.
            // The primary exceptions are for array type nodes, because of the
            // need to support legacy syntax:
            //    e.g.    int a[];    int[] b[];    int f()[] { return null; }
            // and because of inconsistent nesting of left and right of
            // array declarations:
            //    e.g.    int[][] a = new int[2][];
            check("encl.start <= start", encl, self, encl.start <= self.start);
            check("start <= pos", encl, self, self.start <= self.pos);
            if (!( (self.tag == TYPEARRAY ||
                    isAnnotatedArray(self.tree))
                    && (encl.tag == VARDEF ||
                        encl.tag == METHODDEF ||
                        encl.tag == TYPEARRAY ||
                        isAnnotatedArray(encl.tree))
                   ||
                    encl.tag == ANNOTATED_TYPE && self.tag == SELECT
                 )) {
                check("encl.pos <= start || end <= encl.pos",
                        encl, self, encl.pos <= self.start || self.end <= encl.pos);
            }
            check("pos <= end", encl, self, self.pos <= self.end);
            if (!( (self.tag == TYPEARRAY || isAnnotatedArray(self.tree)) &&
                    (encl.tag == TYPEARRAY || isAnnotatedArray(encl.tree))
                   ||
                    encl.tag == MODIFIERS && self.tag == ANNOTATION
                 ) ) {
                check("end <= encl.end", encl, self, self.end <= encl.end);
            }
        }
    }

    Info prevEncl = encl;
    encl = self;
    tree.accept(this);
    encl = prevEncl;
}