test/tools/javac/failover/CheckAttributedTree.java

Print this page

        

*** 83,92 **** --- 83,94 ---- import java.util.Arrays; import java.util.HashSet; import java.util.Set; import javax.lang.model.element.Element; + import static com.sun.tools.javac.tree.JCTree.Tag.*; + /** * Utility and test program to check validity of tree positions for tree nodes. * The program can be run standalone, or as a jtreg test. In standalone mode, * errors can be displayed in a gui viewer. For info on command line args, * run program with no args.
*** 287,297 **** List<Pair<JCCompilationUnit, JCTree>> res = new ArrayList<>(); //System.out.println("Try to add pairs. Elems are " + analyzedElems); for (CompilationUnitTree t : trees) { JCCompilationUnit cu = (JCCompilationUnit)t; for (JCTree def : cu.defs) { ! if (def.getTag() == JCTree.CLASSDEF && analyzedElems.contains(((JCTree.JCClassDecl)def).sym)) { //System.out.println("Adding pair..."); res.add(new Pair<>(cu, def)); } } --- 289,299 ---- List<Pair<JCCompilationUnit, JCTree>> res = new ArrayList<>(); //System.out.println("Try to add pairs. Elems are " + analyzedElems); for (CompilationUnitTree t : trees) { JCCompilationUnit cu = (JCCompilationUnit)t; for (JCTree def : cu.defs) { ! if (def.hasTag(CLASSDEF) && analyzedElems.contains(((JCTree.JCClassDecl)def).sym)) { //System.out.println("Adding pair..."); res.add(new Pair<>(cu, def)); } }
*** 371,383 **** encl = prevEncl; } private boolean mandatoryType(JCTree that) { return that instanceof JCTree.JCExpression || ! that.getTag() == JCTree.VARDEF || ! that.getTag() == JCTree.METHODDEF || ! that.getTag() == JCTree.CLASSDEF; } private final List<String> excludedFields = Arrays.asList("varargsElement"); void check(boolean ok, String label, Info self) { --- 373,385 ---- encl = prevEncl; } private boolean mandatoryType(JCTree that) { return that instanceof JCTree.JCExpression || ! that.hasTag(VARDEF) || ! that.hasTag(METHODDEF) || ! that.hasTag(CLASSDEF); } private final List<String> excludedFields = Arrays.asList("varargsElement"); void check(boolean ok, String label, Info self) {
*** 427,437 **** * Utility class providing easy access to position and other info for a tree node. */ private class Info { Info() { tree = null; ! tag = JCTree.ERRONEOUS; start = 0; pos = 0; end = Integer.MAX_VALUE; } --- 429,439 ---- * Utility class providing easy access to position and other info for a tree node. */ private class Info { Info() { tree = null; ! tag = ERRONEOUS; start = 0; pos = 0; end = Integer.MAX_VALUE; }
*** 447,485 **** public String toString() { return treeUtil.nameFromTag(tree.getTag()) + "[start:" + start + ",pos:" + pos + ",end:" + end + "]"; } final JCTree tree; ! final int tag; final int start; final int pos; final int end; } /** * Names for tree tags. - * javac does not provide an API to convert tag values to strings, so this class uses - * reflection to determine names of public static final int values in JCTree. */ private static class TreeUtil { ! String nameFromTag(int tag) { ! if (names == null) { ! names = new HashMap<Integer, String>(); ! Class c = JCTree.class; ! for (Field f : c.getDeclaredFields()) { ! if (f.getType().equals(int.class)) { ! int mods = f.getModifiers(); ! if (Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods)) { ! try { ! names.put(f.getInt(null), f.getName()); ! } catch (IllegalAccessException e) { ! } ! } ! } ! } ! } ! String name = names.get(tag); return (name == null) ? "??" : name; } List<Field> getFieldsOfType(JCTree t, List<String> excludeNames, Class<?>... types) { List<Field> buf = new ArrayList<Field>(); --- 449,470 ---- public String toString() { return treeUtil.nameFromTag(tree.getTag()) + "[start:" + start + ",pos:" + pos + ",end:" + end + "]"; } final JCTree tree; ! final JCTree.Tag tag; final int start; final int pos; final int end; } /** * Names for tree tags. */ private static class TreeUtil { ! String nameFromTag(JCTree.Tag tag) { ! String name = tag.name(); return (name == null) ? "??" : name; } List<Field> getFieldsOfType(JCTree t, List<String> excludeNames, Class<?>... types) { List<Field> buf = new ArrayList<Field>();
*** 494,505 **** } } } return buf; } - - private Map<Integer, String> names; } /** * Thrown when errors are found parsing a java file. */ --- 479,488 ----