1.1 --- a/test/tools/javac/failover/CheckAttributedTree.java Sat Nov 05 00:02:33 2011 -0700 1.2 +++ b/test/tools/javac/failover/CheckAttributedTree.java Tue Nov 08 11:51:05 2011 -0800 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -85,6 +85,8 @@ 1.11 import java.util.Set; 1.12 import javax.lang.model.element.Element; 1.13 1.14 +import static com.sun.tools.javac.tree.JCTree.Tag.*; 1.15 + 1.16 /** 1.17 * Utility and test program to check validity of tree positions for tree nodes. 1.18 * The program can be run standalone, or as a jtreg test. In standalone mode, 1.19 @@ -289,7 +291,7 @@ 1.20 for (CompilationUnitTree t : trees) { 1.21 JCCompilationUnit cu = (JCCompilationUnit)t; 1.22 for (JCTree def : cu.defs) { 1.23 - if (def.getTag() == JCTree.CLASSDEF && 1.24 + if (def.hasTag(CLASSDEF) && 1.25 analyzedElems.contains(((JCTree.JCClassDecl)def).sym)) { 1.26 //System.out.println("Adding pair..."); 1.27 res.add(new Pair<>(cu, def)); 1.28 @@ -373,9 +375,9 @@ 1.29 1.30 private boolean mandatoryType(JCTree that) { 1.31 return that instanceof JCTree.JCExpression || 1.32 - that.getTag() == JCTree.VARDEF || 1.33 - that.getTag() == JCTree.METHODDEF || 1.34 - that.getTag() == JCTree.CLASSDEF; 1.35 + that.hasTag(VARDEF) || 1.36 + that.hasTag(METHODDEF) || 1.37 + that.hasTag(CLASSDEF); 1.38 } 1.39 1.40 private final List<String> excludedFields = Arrays.asList("varargsElement"); 1.41 @@ -429,7 +431,7 @@ 1.42 private class Info { 1.43 Info() { 1.44 tree = null; 1.45 - tag = JCTree.ERRONEOUS; 1.46 + tag = ERRONEOUS; 1.47 start = 0; 1.48 pos = 0; 1.49 end = Integer.MAX_VALUE; 1.50 @@ -449,7 +451,7 @@ 1.51 } 1.52 1.53 final JCTree tree; 1.54 - final int tag; 1.55 + final JCTree.Tag tag; 1.56 final int start; 1.57 final int pos; 1.58 final int end; 1.59 @@ -457,27 +459,10 @@ 1.60 1.61 /** 1.62 * Names for tree tags. 1.63 - * javac does not provide an API to convert tag values to strings, so this class uses 1.64 - * reflection to determine names of public static final int values in JCTree. 1.65 */ 1.66 private static class TreeUtil { 1.67 - String nameFromTag(int tag) { 1.68 - if (names == null) { 1.69 - names = new HashMap<Integer, String>(); 1.70 - Class c = JCTree.class; 1.71 - for (Field f : c.getDeclaredFields()) { 1.72 - if (f.getType().equals(int.class)) { 1.73 - int mods = f.getModifiers(); 1.74 - if (Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods)) { 1.75 - try { 1.76 - names.put(f.getInt(null), f.getName()); 1.77 - } catch (IllegalAccessException e) { 1.78 - } 1.79 - } 1.80 - } 1.81 - } 1.82 - } 1.83 - String name = names.get(tag); 1.84 + String nameFromTag(JCTree.Tag tag) { 1.85 + String name = tag.name(); 1.86 return (name == null) ? "??" : name; 1.87 } 1.88 1.89 @@ -496,8 +481,6 @@ 1.90 } 1.91 return buf; 1.92 } 1.93 - 1.94 - private Map<Integer, String> names; 1.95 } 1.96 1.97 /**