src/share/classes/com/sun/tools/classfile/Type.java

Print this page




  46     protected static void append(StringBuilder sb, String prefix, List<? extends Type> types, String suffix) {
  47         sb.append(prefix);
  48         String sep = "";
  49         for (Type t: types) {
  50             sb.append(sep);
  51             sb.append(t);
  52             sep = ", ";
  53         }
  54         sb.append(suffix);
  55     }
  56 
  57     protected static void appendIfNotEmpty(StringBuilder sb, String prefix, List<? extends Type> types, String suffix) {
  58         if (types != null && types.size() > 0)
  59             append(sb, prefix, types, suffix);
  60     }
  61 
  62     public interface Visitor<R,P> {
  63         R visitSimpleType(SimpleType type, P p);
  64         R visitArrayType(ArrayType type, P p);
  65         R visitMethodType(MethodType type, P p);

  66         R visitClassSigType(ClassSigType type, P p);
  67         R visitClassType(ClassType type, P p);
  68         R visitTypeParamType(TypeParamType type, P p);
  69         R visitWildcardType(WildcardType type, P p);
  70     }
  71 
  72     /**
  73      * Represents a type signature with a simple name. The name may be that of a
  74      * primitive type, such "{@code int}, {@code float}, etc
  75      * or that of a type argument, such as {@code T}, {@code K}, {@code V}, etc.
  76      *
  77      * See:
  78      * JVMS 4.3.2
  79      *      BaseType:
  80      *          {@code B}, {@code C}, {@code D}, {@code F}, {@code I},
  81      *          {@code J}, {@code S}, {@code Z};
  82      *      VoidDescriptor:
  83      *          {@code V};
  84      * JVMS 4.3.4
  85      *      TypeVariableSignature:


 162             return visitor.visitMethodType(this, data);
 163         }
 164 
 165         @Override
 166         public String toString() {
 167             StringBuilder sb = new StringBuilder();
 168             appendIfNotEmpty(sb, "<", typeParamTypes, "> ");
 169             sb.append(returnType);
 170             append(sb, " (", paramTypes, ")");
 171             appendIfNotEmpty(sb, " throws ", throwsTypes, "");
 172             return sb.toString();
 173         }
 174 
 175         public final List<? extends TypeParamType> typeParamTypes;
 176         public final List<? extends Type> paramTypes;
 177         public final Type returnType;
 178         public final List<? extends Type> throwsTypes;
 179     }
 180 
 181     /**































 182      * Represents a class signature. These describe the signature of
 183      * a class that has type arguments.
 184      *
 185      * See:
 186      * JVMS 4.3.4
 187      *      ClassSignature:
 188      *          FormalTypeParameters_opt SuperclassSignature SuperinterfaceSignature*
 189      */
 190     public static class ClassSigType extends Type {
 191         public ClassSigType(List<TypeParamType> typeParamTypes, Type superclassType,
 192                 List<Type> superinterfaceTypes) {
 193             this.typeParamTypes = typeParamTypes;
 194             this.superclassType = superclassType;
 195             this.superinterfaceTypes = superinterfaceTypes;
 196         }
 197 
 198         public <R, D> R accept(Visitor<R, D> visitor, D data) {
 199             return visitor.visitClassSigType(this, data);
 200         }
 201 




  46     protected static void append(StringBuilder sb, String prefix, List<? extends Type> types, String suffix) {
  47         sb.append(prefix);
  48         String sep = "";
  49         for (Type t: types) {
  50             sb.append(sep);
  51             sb.append(t);
  52             sep = ", ";
  53         }
  54         sb.append(suffix);
  55     }
  56 
  57     protected static void appendIfNotEmpty(StringBuilder sb, String prefix, List<? extends Type> types, String suffix) {
  58         if (types != null && types.size() > 0)
  59             append(sb, prefix, types, suffix);
  60     }
  61 
  62     public interface Visitor<R,P> {
  63         R visitSimpleType(SimpleType type, P p);
  64         R visitArrayType(ArrayType type, P p);
  65         R visitMethodType(MethodType type, P p);
  66         R visitFunctionType(FunctionType type, P p);
  67         R visitClassSigType(ClassSigType type, P p);
  68         R visitClassType(ClassType type, P p);
  69         R visitTypeParamType(TypeParamType type, P p);
  70         R visitWildcardType(WildcardType type, P p);
  71     }
  72 
  73     /**
  74      * Represents a type signature with a simple name. The name may be that of a
  75      * primitive type, such "{@code int}, {@code float}, etc
  76      * or that of a type argument, such as {@code T}, {@code K}, {@code V}, etc.
  77      *
  78      * See:
  79      * JVMS 4.3.2
  80      *      BaseType:
  81      *          {@code B}, {@code C}, {@code D}, {@code F}, {@code I},
  82      *          {@code J}, {@code S}, {@code Z};
  83      *      VoidDescriptor:
  84      *          {@code V};
  85      * JVMS 4.3.4
  86      *      TypeVariableSignature:


 163             return visitor.visitMethodType(this, data);
 164         }
 165 
 166         @Override
 167         public String toString() {
 168             StringBuilder sb = new StringBuilder();
 169             appendIfNotEmpty(sb, "<", typeParamTypes, "> ");
 170             sb.append(returnType);
 171             append(sb, " (", paramTypes, ")");
 172             appendIfNotEmpty(sb, " throws ", throwsTypes, "");
 173             return sb.toString();
 174         }
 175 
 176         public final List<? extends TypeParamType> typeParamTypes;
 177         public final List<? extends Type> paramTypes;
 178         public final Type returnType;
 179         public final List<? extends Type> throwsTypes;
 180     }
 181 
 182     /**
 183      * Represents a method type signature.
 184      *
 185      * See;
 186      * JVMS ???
 187      *      FunctionTypeSignature:
 188      *          {@code #} ReturnType {@code (} TypeSignature* {@code)}
 189      */
 190     public static class FunctionType extends Type {
 191         public FunctionType(Type returnType,
 192                 List<? extends Type> parameterTypes) {
 193             this.returnType = returnType;
 194             this.parameterTypes = parameterTypes;
 195         }
 196 
 197         public <R, D> R accept(Visitor<R, D> visitor, D data) {
 198             return visitor.visitFunctionType(this, data);
 199         }
 200 
 201         @Override
 202         public String toString() {
 203             StringBuilder sb = new StringBuilder();
 204             sb.append('#').append(returnType);
 205             append(sb, "(", parameterTypes, ")");
 206             return sb.toString();
 207         }
 208 
 209         public final List<? extends Type> parameterTypes;
 210         public final Type returnType;
 211     }
 212     
 213     /**
 214      * Represents a class signature. These describe the signature of
 215      * a class that has type arguments.
 216      *
 217      * See:
 218      * JVMS 4.3.4
 219      *      ClassSignature:
 220      *          FormalTypeParameters_opt SuperclassSignature SuperinterfaceSignature*
 221      */
 222     public static class ClassSigType extends Type {
 223         public ClassSigType(List<TypeParamType> typeParamTypes, Type superclassType,
 224                 List<Type> superinterfaceTypes) {
 225             this.typeParamTypes = typeParamTypes;
 226             this.superclassType = superclassType;
 227             this.superinterfaceTypes = superinterfaceTypes;
 228         }
 229 
 230         public <R, D> R accept(Visitor<R, D> visitor, D data) {
 231             return visitor.visitClassSigType(this, data);
 232         }
 233