src/share/classes/com/sun/tools/javac/tree/JCTree.java

changeset 1374
c002fdee76fd
parent 1358
fc123bdeddb8
child 1435
9b26c96f5138
equal deleted inserted replaced
1373:4a1c57a1c410 1374:c002fdee76fd
79 * @see Pretty 79 * @see Pretty
80 */ 80 */
81 public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition { 81 public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
82 82
83 /* Tree tag values, identifying kinds of trees */ 83 /* Tree tag values, identifying kinds of trees */
84 public enum Tag{ 84 public enum Tag {
85 /** For methods that return an invalid tag if a given condition is not met 85 /** For methods that return an invalid tag if a given condition is not met
86 */ 86 */
87 NO_TAG, 87 NO_TAG,
88 88
89 /** Toplevel nodes, of type TopLevel, representing entire source files. 89 /** Toplevel nodes, of type TopLevel, representing entire source files.
1910 1910
1911 /** 1911 /**
1912 * A constant value given literally. 1912 * A constant value given literally.
1913 */ 1913 */
1914 public static class JCLiteral extends JCExpression implements LiteralTree { 1914 public static class JCLiteral extends JCExpression implements LiteralTree {
1915 public int typetag; 1915 public TypeTag typetag;
1916 /** value representation */ 1916 /** value representation */
1917 public Object value; 1917 public Object value;
1918 protected JCLiteral(int typetag, Object value) { 1918 protected JCLiteral(TypeTag typetag, Object value) {
1919 this.typetag = typetag; 1919 this.typetag = typetag;
1920 this.value = value; 1920 this.value = value;
1921 } 1921 }
1922 @Override 1922 @Override
1923 public void accept(Visitor v) { v.visitLiteral(this); } 1923 public void accept(Visitor v) { v.visitLiteral(this); }
1924 1924
1925 public Kind getKind() { 1925 public Kind getKind() {
1926 switch (typetag) { 1926 return typetag.getKindLiteral();
1927 case TypeTags.INT: 1927 }
1928 return Kind.INT_LITERAL; 1928
1929 case TypeTags.LONG:
1930 return Kind.LONG_LITERAL;
1931 case TypeTags.FLOAT:
1932 return Kind.FLOAT_LITERAL;
1933 case TypeTags.DOUBLE:
1934 return Kind.DOUBLE_LITERAL;
1935 case TypeTags.BOOLEAN:
1936 return Kind.BOOLEAN_LITERAL;
1937 case TypeTags.CHAR:
1938 return Kind.CHAR_LITERAL;
1939 case TypeTags.CLASS:
1940 return Kind.STRING_LITERAL;
1941 case TypeTags.BOT:
1942 return Kind.NULL_LITERAL;
1943 default:
1944 throw new AssertionError("unknown literal kind " + this);
1945 }
1946 }
1947 public Object getValue() { 1929 public Object getValue() {
1948 switch (typetag) { 1930 switch (typetag) {
1949 case TypeTags.BOOLEAN: 1931 case BOOLEAN:
1950 int bi = (Integer) value; 1932 int bi = (Integer) value;
1951 return (bi != 0); 1933 return (bi != 0);
1952 case TypeTags.CHAR: 1934 case CHAR:
1953 int ci = (Integer) value; 1935 int ci = (Integer) value;
1954 char c = (char) ci; 1936 char c = (char) ci;
1955 if (c != ci) 1937 if (c != ci)
1956 throw new AssertionError("bad value for char literal"); 1938 throw new AssertionError("bad value for char literal");
1957 return c; 1939 return c;
1974 } 1956 }
1975 } 1957 }
1976 1958
1977 /** 1959 /**
1978 * Identifies a basic type. 1960 * Identifies a basic type.
1979 * @see TypeTags 1961 * @see TypeTag
1980 */ 1962 */
1981 public static class JCPrimitiveTypeTree extends JCExpression implements PrimitiveTypeTree { 1963 public static class JCPrimitiveTypeTree extends JCExpression implements PrimitiveTypeTree {
1982 /** the basic type id */ 1964 /** the basic type id */
1983 public int typetag; 1965 public TypeTag typetag;
1984 protected JCPrimitiveTypeTree(int typetag) { 1966 protected JCPrimitiveTypeTree(TypeTag typetag) {
1985 this.typetag = typetag; 1967 this.typetag = typetag;
1986 } 1968 }
1987 @Override 1969 @Override
1988 public void accept(Visitor v) { v.visitTypeIdent(this); } 1970 public void accept(Visitor v) { v.visitTypeIdent(this); }
1989 1971
1990 public Kind getKind() { return Kind.PRIMITIVE_TYPE; } 1972 public Kind getKind() { return Kind.PRIMITIVE_TYPE; }
1991 public TypeKind getPrimitiveTypeKind() { 1973 public TypeKind getPrimitiveTypeKind() {
1992 switch (typetag) { 1974 return typetag.getPrimitiveTypeKind();
1993 case TypeTags.BOOLEAN: 1975 }
1994 return TypeKind.BOOLEAN; 1976
1995 case TypeTags.BYTE:
1996 return TypeKind.BYTE;
1997 case TypeTags.SHORT:
1998 return TypeKind.SHORT;
1999 case TypeTags.INT:
2000 return TypeKind.INT;
2001 case TypeTags.LONG:
2002 return TypeKind.LONG;
2003 case TypeTags.CHAR:
2004 return TypeKind.CHAR;
2005 case TypeTags.FLOAT:
2006 return TypeKind.FLOAT;
2007 case TypeTags.DOUBLE:
2008 return TypeKind.DOUBLE;
2009 case TypeTags.VOID:
2010 return TypeKind.VOID;
2011 default:
2012 throw new AssertionError("unknown primitive type " + this);
2013 }
2014 }
2015 @Override 1977 @Override
2016 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 1978 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2017 return v.visitPrimitiveType(this, d); 1979 return v.visitPrimitiveType(this, d);
2018 } 1980 }
2019 @Override 1981 @Override
2159 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2121 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2160 return v.visitWildcard(this, d); 2122 return v.visitWildcard(this, d);
2161 } 2123 }
2162 @Override 2124 @Override
2163 public Tag getTag() { 2125 public Tag getTag() {
2164 return WILDCARD; 2126 return Tag.WILDCARD;
2165 } 2127 }
2166 } 2128 }
2167 2129
2168 public static class TypeBoundKind extends JCTree { 2130 public static class TypeBoundKind extends JCTree {
2169 public BoundKind kind; 2131 public BoundKind kind;
2360 JCTypeCast TypeCast(JCTree expr, JCExpression type); 2322 JCTypeCast TypeCast(JCTree expr, JCExpression type);
2361 JCInstanceOf TypeTest(JCExpression expr, JCTree clazz); 2323 JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);
2362 JCArrayAccess Indexed(JCExpression indexed, JCExpression index); 2324 JCArrayAccess Indexed(JCExpression indexed, JCExpression index);
2363 JCFieldAccess Select(JCExpression selected, Name selector); 2325 JCFieldAccess Select(JCExpression selected, Name selector);
2364 JCIdent Ident(Name idname); 2326 JCIdent Ident(Name idname);
2365 JCLiteral Literal(int tag, Object value); 2327 JCLiteral Literal(TypeTag tag, Object value);
2366 JCPrimitiveTypeTree TypeIdent(int typetag); 2328 JCPrimitiveTypeTree TypeIdent(TypeTag typetag);
2367 JCArrayTypeTree TypeArray(JCExpression elemtype); 2329 JCArrayTypeTree TypeArray(JCExpression elemtype);
2368 JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments); 2330 JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments);
2369 JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds); 2331 JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds);
2370 JCWildcard Wildcard(TypeBoundKind kind, JCTree type); 2332 JCWildcard Wildcard(TypeBoundKind kind, JCTree type);
2371 TypeBoundKind TypeBoundKind(BoundKind kind); 2333 TypeBoundKind TypeBoundKind(BoundKind kind);

mercurial