langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java
author jjg
Fri, 29 Aug 2008 11:10:12 -0700
changeset 1206 3a05355982a9
parent 10 06bc494ca11e
child 1260 a772ba9ba43d
permissions -rw-r--r--
6597471: unused imports in javax.tools.JavaCompiler 6597531: unused imports and unused private const. in com.sun.tools.javac.Server.java Reviewed-by: mcimadamore Contributed-by: davide.angelocola@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2005 Sun Microsystems, Inc.  All Rights Reserved.
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.code;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.LinkedHashMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.Map;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import javax.lang.model.element.AnnotationMirror;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import javax.lang.model.element.AnnotationValue;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import javax.lang.model.element.AnnotationValueVisitor;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import javax.lang.model.type.DeclaredType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import static com.sun.tools.javac.code.TypeTags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
/** An annotation value.
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *  you write code that depends on this, you do so at your own risk.
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
public abstract class Attribute implements AnnotationValue {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    /** The type of the annotation element. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    public Type type;
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    public Attribute(Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
        this.type = type;
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    public abstract void accept(Visitor v);
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    public Object getValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    /** The value for an annotation element of primitive type or String. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    public static class Constant extends Attribute {
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
        public final Object value;
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        public void accept(Visitor v) { v.visitConstant(this); }
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        public Constant(Type type, Object value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
            super(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
            this.value = value;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
            return Constants.format(value, type);
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        public Object getValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
            return Constants.decode(value, type);
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            if (value instanceof String)
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
                return v.visitString((String) value, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
            if (value instanceof Integer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
                int i = (Integer) value;
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
                switch (type.tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
                case BOOLEAN:   return v.visitBoolean(i != 0, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
                case CHAR:      return v.visitChar((char) i, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
                case BYTE:      return v.visitByte((byte) i, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
                case SHORT:     return v.visitShort((short) i, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
                case INT:       return v.visitInt(i, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
            switch (type.tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
            case LONG:          return v.visitLong((Long) value, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
            case FLOAT:         return v.visitFloat((Float) value, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
            case DOUBLE:        return v.visitDouble((Double) value, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
            throw new AssertionError("Bad annotation element value: " + value);
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    /** The value for an annotation element of type java.lang.Class,
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     *  represented as a ClassSymbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    public static class Class extends Attribute {
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        public final Type type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        public void accept(Visitor v) { v.visitClass(this); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        public Class(Types types, Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
            super(makeClassType(types, type));
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
            this.type = type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        static Type makeClassType(Types types, Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
            Type arg = type.isPrimitive()
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
                ? types.boxedClass(type).type
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
                : types.erasure(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
            return new Type.ClassType(types.syms.classType.getEnclosingType(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
                                      List.of(arg),
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
                                      types.syms.classType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
            return type + ".class";
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        public Type getValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
            return type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
            return v.visitType(type, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    /** A compound annotation element value, the type of which is an
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     *  attribute interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    public static class Compound extends Attribute implements AnnotationMirror {
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        /** The attributes values, as pairs.  Each pair contains a
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
         *  reference to the accessing method in the attribute interface
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
         *  and the value to be returned when that method is called to
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
         *  access this attribute.
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        public final List<Pair<MethodSymbol,Attribute>> values;
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        public Compound(Type type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
                        List<Pair<MethodSymbol,Attribute>> values) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            super(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
            this.values = values;
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        public void accept(Visitor v) { v.visitCompound(this); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
         * Returns a string representation of this annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
         * String is of one of the forms:
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
         *     @com.example.foo(name1=val1, name2=val2)
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
         *     @com.example.foo(val)
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
         *     @com.example.foo
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
         * Omit parens for marker annotations, and omit "value=" when allowed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
            StringBuilder buf = new StringBuilder();
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
            buf.append("@");
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
            buf.append(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
            int len = values.length();
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
            if (len > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
                buf.append('(');
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
                boolean first = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
                for (Pair<MethodSymbol, Attribute> value : values) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
                    if (!first) buf.append(", ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
                    first = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
                    Name name = value.fst.name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
                    if (len > 1 || name != name.table.value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
                        buf.append(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
                        buf.append('=');
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
                    buf.append(value.snd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
                buf.append(')');
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
            return buf.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        public Attribute member(Name member) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
            for (Pair<MethodSymbol,Attribute> pair : values)
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
                if (pair.fst.name == member) return pair.snd;
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        public Attribute.Compound getValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
            return v.visitAnnotation(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        public DeclaredType getAnnotationType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
            return (DeclaredType) type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        public Map<MethodSymbol, Attribute> getElementValues() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
            Map<MethodSymbol, Attribute> valmap =
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
                new LinkedHashMap<MethodSymbol, Attribute>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
            for (Pair<MethodSymbol, Attribute> value : values)
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
                valmap.put(value.fst, value.snd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
            return valmap;
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
    /** The value for an annotation element of an array type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
    public static class Array extends Attribute {
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        public final Attribute[] values;
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        public Array(Type type, Attribute[] values) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
            super(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
            this.values = values;
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        public void accept(Visitor v) { v.visitArray(this); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
            StringBuilder buf = new StringBuilder();
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
            buf.append('{');
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
            boolean first = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
            for (Attribute value : values) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
                if (!first)
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
                    buf.append(", ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
                first = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
                buf.append(value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
            buf.append('}');
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
            return buf.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        public List<Attribute> getValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
            return List.from(values);
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
        public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
            return v.visitArray(getValue(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
    /** The value for an annotation element of an enum type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
    public static class Enum extends Attribute {
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        public VarSymbol value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        public Enum(Type type, VarSymbol value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
            super(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
            assert value != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
            this.value = value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        public void accept(Visitor v) { v.visitEnum(this); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
            return value.enclClass() + "." + value;     // qualified name
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        public VarSymbol getValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
            return value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
            return v.visitEnumConstant(value, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
    public static class Error extends Attribute {
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        public Error(Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
            super(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        public void accept(Visitor v) { v.visitError(this); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
            return "<error>";
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        public String getValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
            return toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
            return v.visitString(toString(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
    /** A visitor type for dynamic dispatch on the kind of attribute value. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
    public static interface Visitor {
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        void visitConstant(Attribute.Constant value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        void visitClass(Attribute.Class clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        void visitCompound(Attribute.Compound compound);
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        void visitArray(Attribute.Array array);
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        void visitEnum(Attribute.Enum e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        void visitError(Attribute.Error e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
}