KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > lookup > RawTypeBinding


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.lookup;
12
13 import org.eclipse.jdt.core.compiler.CharOperation;
14
15 /**
16  * Denote a raw type, i.e. a generic type referenced without any type arguments.
17  * e.g. X<T extends Exception> can be used a raw type 'X', in which case it
18  * will behave as X<Exception>
19  */

20 public class RawTypeBinding extends ParameterizedTypeBinding {
21     
22     /**
23      * Raw type arguments are erasure of respective parameter bounds. But we may not have resolved
24      * these bounds yet if creating raw types while supertype hierarchies are being connected.
25      * Therefore, use 'null' instead, and access these in a lazy way later on (when substituting).
26      */

27     public RawTypeBinding(ReferenceBinding type, ReferenceBinding enclosingType, LookupEnvironment environment){
28         super(type, null, enclosingType, environment);
29         if (enclosingType == null || (enclosingType.modifiers & ExtraCompilerModifiers.AccGenericSignature) == 0)
30             this.modifiers &= ~ExtraCompilerModifiers.AccGenericSignature; // only need signature if enclosing needs one
31
}
32     
33     public char[] computeUniqueKey(boolean isLeaf) {
34         StringBuffer JavaDoc sig = new StringBuffer JavaDoc(10);
35         if (isMemberType() && enclosingType().isParameterizedType()) {
36             char[] typeSig = enclosingType().computeUniqueKey(false/*not a leaf*/);
37             for (int i = 0; i < typeSig.length-1; i++) sig.append(typeSig[i]); // copy all but trailing semicolon
38
sig.append('.').append(sourceName()).append('<').append('>').append(';');
39         } else {
40              sig.append(genericType().computeUniqueKey(false/*not a leaf*/));
41              sig.insert(sig.length()-1, "<>"); //$NON-NLS-1$
42
}
43
44         int sigLength = sig.length();
45         char[] uniqueKey = new char[sigLength];
46         sig.getChars(0, sigLength, uniqueKey, 0);
47         return uniqueKey;
48     }
49     
50     /**
51      * @see org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding#createParameterizedMethod(org.eclipse.jdt.internal.compiler.lookup.MethodBinding)
52      */

53     public ParameterizedMethodBinding createParameterizedMethod(MethodBinding originalMethod) {
54         if (originalMethod.typeVariables == Binding.NO_TYPE_VARIABLES || originalMethod.isStatic()) {
55             return super.createParameterizedMethod(originalMethod);
56         }
57         return this.environment.createParameterizedGenericMethod(originalMethod, this);
58     }
59     
60     public int kind() {
61         return RAW_TYPE;
62     }
63     
64     /**
65      * @see org.eclipse.jdt.internal.compiler.lookup.TypeBinding#debugName()
66      */

67     public String JavaDoc debugName() {
68         StringBuffer JavaDoc nameBuffer = new StringBuffer JavaDoc(10);
69         nameBuffer.append(actualType().sourceName()).append("#RAW"); //$NON-NLS-1$
70
return nameBuffer.toString();
71     }
72
73     /**
74      * Ltype<param1 ... paramN>;
75      * LY<TT;>;
76      */

77     public char[] genericTypeSignature() {
78
79         if (this.genericTypeSignature == null) {
80             StringBuffer JavaDoc sig = new StringBuffer JavaDoc(10);
81             if (this.isMemberType() && this.enclosingType().isParameterizedType()) {
82                 char[] typeSig = this.enclosingType().genericTypeSignature();
83                 for (int i = 0; i < typeSig.length-1; i++) sig.append(typeSig[i]); // copy all but trailing semicolon
84
sig.append('.').append(this.sourceName()).append(';');
85                 int sigLength = sig.length();
86                 this.genericTypeSignature = new char[sigLength];
87                 sig.getChars(0, sigLength, this.genericTypeSignature, 0);
88             } else {
89                  this.genericTypeSignature = genericType().signature(); // erasure
90
}
91         }
92        return this.genericTypeSignature;
93     }
94     
95     public boolean isEquivalentTo(TypeBinding otherType) {
96         if (this == otherType)
97             return true;
98         if (otherType == null)
99             return false;
100         switch(otherType.kind()) {
101     
102             case Binding.WILDCARD_TYPE :
103                 return ((WildcardBinding) otherType).boundCheck(this);
104                 
105             case Binding.GENERIC_TYPE :
106             case Binding.PARAMETERIZED_TYPE :
107             case Binding.RAW_TYPE :
108                 return erasure() == otherType.erasure();
109         }
110         return false;
111     }
112     
113     public boolean isIntersectingWith(TypeBinding otherType) {
114         if (this == otherType)
115             return true;
116         if (otherType == null)
117             return false;
118         switch(otherType.kind()) {
119     
120             case Binding.GENERIC_TYPE :
121             case Binding.PARAMETERIZED_TYPE :
122             case Binding.RAW_TYPE :
123                 return erasure() == otherType.erasure();
124         }
125         return false;
126     }
127     
128     /**
129      * Raw type is not treated as a standard parameterized type
130      * @see org.eclipse.jdt.internal.compiler.lookup.TypeBinding#isParameterizedType()
131      */

132     public boolean isParameterizedType() {
133         return false;
134     }
135     public boolean isRawType() {
136         return true;
137     }
138     
139     protected void initializeArguments() {
140         TypeVariableBinding[] typeVariables = genericType().typeVariables();
141         int length = typeVariables.length;
142         TypeBinding[] typeArguments = new TypeBinding[length];
143         for (int i = 0; i < length; i++) {
144             // perform raw conversion on variable upper bound - could cause infinite regression if arguments were initialized lazily
145
typeArguments[i] = this.environment.convertToRawType(typeVariables[i].erasure());
146         }
147         this.arguments = typeArguments;
148     }
149     /**
150      * @see org.eclipse.jdt.internal.compiler.lookup.Binding#readableName()
151      */

152     public char[] readableName() /*java.lang.Object, p.X<T> */ {
153         char[] readableName;
154         if (isMemberType()) {
155             readableName = CharOperation.concat(enclosingType().readableName(), sourceName, '.');
156         } else {
157             readableName = CharOperation.concatWith(actualType().compoundName, '.');
158         }
159         return readableName;
160     }
161
162     /**
163      * @see org.eclipse.jdt.internal.compiler.lookup.Binding#shortReadableName()
164      */

165     public char[] shortReadableName() /*Object*/ {
166         char[] shortReadableName;
167         if (isMemberType()) {
168             shortReadableName = CharOperation.concat(enclosingType().shortReadableName(), sourceName, '.');
169         } else {
170             shortReadableName = actualType().sourceName;
171         }
172         return shortReadableName;
173     }
174 }
175
Popular Tags