|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- /* *******************************************************************
- * Copyright (c) 1999-2001 Xerox Corporation,
- * 2002 Palo Alto Research Center, Incorporated (PARC).
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * ******************************************************************/
- package org.aspectj.util;
-
- /**
- * Encapsulate generic signature parsing
- *
- * @author Adrian Colyer
- * @author Andy Clement
- */
- public class GenericSignature {
-
- /**
- * structure holding a parsed class signature
- */
- public static class ClassSignature {
- public FormalTypeParameter[] formalTypeParameters = FormalTypeParameter.NONE;
- public ClassTypeSignature superclassSignature;
- public ClassTypeSignature[] superInterfaceSignatures = ClassTypeSignature.NONE;
-
- public String toString() {
- StringBuffer ret = new StringBuffer();
- ret.append(formalTypeParameters.toString());
- ret.append(superclassSignature.toString());
- for (int i = 0; i < superInterfaceSignatures.length; i++) {
- ret.append(superInterfaceSignatures[i].toString());
- }
- return ret.toString();
- }
- }
-
- public static class MethodTypeSignature {
- public FormalTypeParameter[] formalTypeParameters = new FormalTypeParameter[0];
- public TypeSignature[] parameters = new TypeSignature[0];
- public TypeSignature returnType;
- public FieldTypeSignature[] throwsSignatures = new FieldTypeSignature[0];
-
- public MethodTypeSignature(FormalTypeParameter[] aFormalParameterList, TypeSignature[] aParameterList,
- TypeSignature aReturnType, FieldTypeSignature[] aThrowsSignatureList) {
- this.formalTypeParameters = aFormalParameterList;
- this.parameters = aParameterList;
- this.returnType = aReturnType;
- this.throwsSignatures = aThrowsSignatureList;
- }
-
- public String toString() {
- StringBuffer sb = new StringBuffer();
- if (formalTypeParameters.length > 0) {
- sb.append("<");
- for (int i = 0; i < formalTypeParameters.length; i++) {
- sb.append(formalTypeParameters[i].toString());
- }
- sb.append(">");
- }
- sb.append("(");
- for (int i = 0; i < parameters.length; i++) {
- sb.append(parameters[i].toString());
- }
- sb.append(")");
- sb.append(returnType.toString());
- for (int i = 0; i < throwsSignatures.length; i++) {
- sb.append("^");
- sb.append(throwsSignatures[i].toString());
- }
- return sb.toString();
- }
- }
-
- /**
- * structure capturing a FormalTypeParameter from the Signature grammar
- */
- public static class FormalTypeParameter {
- public static final FormalTypeParameter[] NONE = new FormalTypeParameter[0];
- public String identifier;
- public FieldTypeSignature classBound;
- public FieldTypeSignature[] interfaceBounds;
-
- public String toString() {
- StringBuffer ret = new StringBuffer();
- ret.append("T");
- ret.append(identifier);
- ret.append(":");
- ret.append(classBound.toString());
- for (int i = 0; i < interfaceBounds.length; i++) {
- ret.append(":");
- ret.append(interfaceBounds[i].toString());
- }
- return ret.toString();
- }
- }
-
- public static abstract class TypeSignature {
- public boolean isBaseType() {
- return false;
- }
- }
-
- public static class BaseTypeSignature extends TypeSignature {
- private final String sig;
-
- public BaseTypeSignature(String aPrimitiveType) {
- sig = aPrimitiveType;
- }
-
- public boolean isBaseType() {
- return true;
- }
-
- public String toString() {
- return sig;
- }
- }
-
- public static abstract class FieldTypeSignature extends TypeSignature {
- public boolean isClassTypeSignature() {
- return false;
- }
-
- public boolean isTypeVariableSignature() {
- return false;
- }
-
- public boolean isArrayTypeSignature() {
- return false;
- }
- }
-
- public static class ClassTypeSignature extends FieldTypeSignature {
-
- public static final ClassTypeSignature[] NONE = new ClassTypeSignature[0];
- public String classSignature;
- public SimpleClassTypeSignature outerType;
- public SimpleClassTypeSignature[] nestedTypes;
-
- public ClassTypeSignature(String sig, String identifier) {
- this.classSignature = sig;
- this.outerType = new SimpleClassTypeSignature(identifier);
- this.nestedTypes = new SimpleClassTypeSignature[0];
- }
-
- public ClassTypeSignature(String sig, SimpleClassTypeSignature outer, SimpleClassTypeSignature[] inners) {
- this.classSignature = sig;
- this.outerType = outer;
- this.nestedTypes = inners;
- }
-
- public boolean isClassTypeSignature() {
- return true;
- }
-
- public String toString() {
- return classSignature;
- }
- }
-
- public static class TypeVariableSignature extends FieldTypeSignature {
- public String typeVariableName;
-
- public TypeVariableSignature(String typeVarToken) {
- this.typeVariableName = typeVarToken.substring(1);
- }
-
- public boolean isTypeVariableSignature() {
- return true;
- }
-
- public String toString() {
- return "T" + typeVariableName + ";";
- }
- }
-
- public static class ArrayTypeSignature extends FieldTypeSignature {
- public TypeSignature typeSig;
-
- public ArrayTypeSignature(TypeSignature aTypeSig) {
- this.typeSig = aTypeSig;
- }
-
- public boolean isArrayTypeSignature() {
- return true;
- }
-
- public String toString() {
- return "[" + typeSig.toString();
- }
- }
-
- public static class SimpleClassTypeSignature {
- public String identifier;
- public TypeArgument[] typeArguments;
-
- public SimpleClassTypeSignature(String identifier) {
- this.identifier = identifier;
- this.typeArguments = new TypeArgument[0];
- }
-
- public SimpleClassTypeSignature(String identifier, TypeArgument[] args) {
- this.identifier = identifier;
- this.typeArguments = args;
- }
-
- public String toString() {
- StringBuffer sb = new StringBuffer();
- sb.append(identifier);
- if (typeArguments.length > 0) {
- sb.append("<");
- for (int i = 0; i < typeArguments.length; i++) {
- sb.append(typeArguments[i].toString());
- }
- sb.append(">");
- }
- return sb.toString();
- }
- }
-
- public static class TypeArgument {
- public boolean isWildcard = false;
- public boolean isPlus = false;
- public boolean isMinus = false;
- public FieldTypeSignature signature; // null if isWildcard
-
- public TypeArgument() {
- isWildcard = true;
- }
-
- public TypeArgument(boolean plus, boolean minus, FieldTypeSignature aSig) {
- this.isPlus = plus;
- this.isMinus = minus;
- this.signature = aSig;
- }
-
- public String toString() {
- if (isWildcard)
- return "*";
- StringBuffer sb = new StringBuffer();
- if (isPlus)
- sb.append("+");
- if (isMinus)
- sb.append("-");
- sb.append(signature.toString());
- return sb.toString();
- }
- }
- }
|