1 11 package org.eclipse.jdt.internal.compiler.lookup; 12 13 import org.eclipse.jdt.internal.compiler.ast.Wildcard; 14 15 21 public class ParameterizedMethodBinding extends MethodBinding { 22 23 protected MethodBinding originalMethod; 24 25 28 public ParameterizedMethodBinding(final ParameterizedTypeBinding parameterizedDeclaringClass, MethodBinding originalMethod) { 29 30 super( 31 originalMethod.modifiers, 32 originalMethod.selector, 33 originalMethod.returnType, 34 originalMethod.parameters, 35 originalMethod.thrownExceptions, 36 parameterizedDeclaringClass); 37 this.originalMethod = originalMethod; 38 this.tagBits = originalMethod.tagBits; 39 40 final TypeVariableBinding[] originalVariables = originalMethod.typeVariables; 41 Substitution substitution = null; 42 final int length = originalVariables.length; 43 final boolean isStatic = originalMethod.isStatic(); 44 if (length == 0) { 45 this.typeVariables = Binding.NO_TYPE_VARIABLES; 46 if (!isStatic) substitution = parameterizedDeclaringClass; 47 } else { 48 final TypeVariableBinding[] substitutedVariables = new TypeVariableBinding[length]; 50 for (int i = 0; i < length; i++) { TypeVariableBinding originalVariable = originalVariables[i]; 52 substitutedVariables[i] = new TypeVariableBinding(originalVariable.sourceName, this, originalVariable.rank); 53 } 54 this.typeVariables = substitutedVariables; 55 56 substitution = new Substitution() { 58 public LookupEnvironment environment() { 59 return parameterizedDeclaringClass.environment; 60 } 61 public boolean isRawSubstitution() { 62 return !isStatic && parameterizedDeclaringClass.isRawSubstitution(); 63 } 64 public TypeBinding substitute(TypeVariableBinding typeVariable) { 65 if (typeVariable.rank < length && originalVariables[typeVariable.rank] == typeVariable) { 67 return substitutedVariables[typeVariable.rank]; 68 } 69 if (!isStatic) 70 return parameterizedDeclaringClass.substitute(typeVariable); 71 return typeVariable; 72 } 73 }; 74 75 for (int i = 0; i < length; i++) { 77 TypeVariableBinding originalVariable = originalVariables[i]; 78 TypeVariableBinding substitutedVariable = substitutedVariables[i]; 79 TypeBinding substitutedSuperclass = Scope.substitute(substitution, originalVariable.superclass); 80 ReferenceBinding[] substitutedInterfaces = Scope.substitute(substitution, originalVariable.superInterfaces); 81 if (originalVariable.firstBound != null) { 82 substitutedVariable.firstBound = originalVariable.firstBound == originalVariable.superclass 83 ? substitutedSuperclass : substitutedInterfaces[0]; 85 } 86 switch (substitutedSuperclass.kind()) { 87 case Binding.ARRAY_TYPE : 88 substitutedVariable.superclass = parameterizedDeclaringClass.environment.getResolvedType(TypeConstants.JAVA_LANG_OBJECT, null); 89 substitutedVariable.superInterfaces = substitutedInterfaces; 90 break; 91 default: 92 if (substitutedSuperclass.isInterface()) { 93 substitutedVariable.superclass = parameterizedDeclaringClass.environment.getResolvedType(TypeConstants.JAVA_LANG_OBJECT, null); 94 int interfaceCount = substitutedInterfaces.length; 95 System.arraycopy(substitutedInterfaces, 0, substitutedInterfaces = new ReferenceBinding[interfaceCount+1], 1, interfaceCount); 96 substitutedInterfaces[0] = (ReferenceBinding) substitutedSuperclass; 97 substitutedVariable.superInterfaces = substitutedInterfaces; 98 } else { 99 substitutedVariable.superclass = (ReferenceBinding) substitutedSuperclass; substitutedVariable.superInterfaces = substitutedInterfaces; 101 } 102 } 103 } 104 } 105 if (substitution != null) { 106 this.returnType = Scope.substitute(substitution, this.returnType); 107 this.parameters = Scope.substitute(substitution, this.parameters); 108 this.thrownExceptions = Scope.substitute(substitution, this.thrownExceptions); 109 } 110 } 111 112 116 public ParameterizedMethodBinding(final ReferenceBinding declaringClass, MethodBinding originalMethod, char[][] alternateParamaterNames, final LookupEnvironment environment) { 117 118 super( 119 originalMethod.modifiers, 120 originalMethod.selector, 121 originalMethod.returnType, 122 originalMethod.parameters, 123 originalMethod.thrownExceptions, 124 declaringClass); 125 this.originalMethod = originalMethod; 126 this.tagBits = originalMethod.tagBits; 127 128 final TypeVariableBinding[] originalVariables = originalMethod.typeVariables; 129 Substitution substitution = null; 130 final int length = originalVariables.length; 131 if (length == 0) { 132 this.typeVariables = Binding.NO_TYPE_VARIABLES; 133 } else { 134 final TypeVariableBinding[] substitutedVariables = new TypeVariableBinding[length]; 136 for (int i = 0; i < length; i++) { TypeVariableBinding originalVariable = originalVariables[i]; 138 substitutedVariables[i] = new TypeVariableBinding( 139 alternateParamaterNames == null ? 140 originalVariable.sourceName : 141 alternateParamaterNames[i], 142 this, 143 originalVariable.rank); 144 } 145 this.typeVariables = substitutedVariables; 146 147 substitution = new Substitution() { 149 public LookupEnvironment environment() { 150 return environment; 151 } 152 public boolean isRawSubstitution() { 153 return false; 154 } 155 public TypeBinding substitute(TypeVariableBinding typeVariable) { 156 if (typeVariable.rank < length && originalVariables[typeVariable.rank] == typeVariable) { 158 return substitutedVariables[typeVariable.rank]; 159 } 160 return typeVariable; 161 } 162 }; 163 164 for (int i = 0; i < length; i++) { 166 TypeVariableBinding originalVariable = originalVariables[i]; 167 TypeVariableBinding substitutedVariable = substitutedVariables[i]; 168 TypeBinding substitutedSuperclass = Scope.substitute(substitution, originalVariable.superclass); 169 ReferenceBinding[] substitutedInterfaces = Scope.substitute(substitution, originalVariable.superInterfaces); 170 if (originalVariable.firstBound != null) { 171 substitutedVariable.firstBound = originalVariable.firstBound == originalVariable.superclass 172 ? substitutedSuperclass : substitutedInterfaces[0]; 174 } 175 switch (substitutedSuperclass.kind()) { 176 case Binding.ARRAY_TYPE : 177 substitutedVariable.superclass = environment.getResolvedType(TypeConstants.JAVA_LANG_OBJECT, null); 178 substitutedVariable.superInterfaces = substitutedInterfaces; 179 break; 180 default: 181 if (substitutedSuperclass.isInterface()) { 182 substitutedVariable.superclass = environment.getResolvedType(TypeConstants.JAVA_LANG_OBJECT, null); 183 int interfaceCount = substitutedInterfaces.length; 184 System.arraycopy(substitutedInterfaces, 0, substitutedInterfaces = new ReferenceBinding[interfaceCount+1], 1, interfaceCount); 185 substitutedInterfaces[0] = (ReferenceBinding) substitutedSuperclass; 186 substitutedVariable.superInterfaces = substitutedInterfaces; 187 } else { 188 substitutedVariable.superclass = (ReferenceBinding) substitutedSuperclass; substitutedVariable.superInterfaces = substitutedInterfaces; 190 } 191 } 192 } 193 } 194 if (substitution != null) { 195 this.returnType = Scope.substitute(substitution, this.returnType); 196 this.parameters = Scope.substitute(substitution, this.parameters); 197 this.thrownExceptions = Scope.substitute(substitution, this.thrownExceptions); 198 } 199 } 200 201 public ParameterizedMethodBinding() { 202 } 204 205 208 public static ParameterizedMethodBinding instantiateGetClass(TypeBinding receiverType, MethodBinding originalMethod, Scope scope) { 209 ParameterizedMethodBinding method = new ParameterizedMethodBinding(); 210 method.modifiers = originalMethod.modifiers; 211 method.selector = originalMethod.selector; 212 method.declaringClass = originalMethod.declaringClass; 213 method.typeVariables = Binding.NO_TYPE_VARIABLES; 214 method.originalMethod = originalMethod; 215 method.parameters = originalMethod.parameters; 216 method.thrownExceptions = originalMethod.thrownExceptions; 217 ReferenceBinding genericClassType = scope.getJavaLangClass(); 218 LookupEnvironment environment = scope.environment(); 219 TypeBinding rawType = environment.convertToRawType(receiverType.erasure()); 220 method.returnType = environment.createParameterizedType( 221 genericClassType, 222 new TypeBinding[] { environment.createWildcard(genericClassType, 0, rawType, null , Wildcard.EXTENDS) }, 223 null); 224 return method; 225 } 226 227 230 public boolean hasSubstitutedParameters() { 231 return this.parameters != originalMethod.parameters; 232 } 233 234 237 public boolean hasSubstitutedReturnType() { 238 return this.returnType != originalMethod.returnType; 239 } 240 241 244 public MethodBinding original() { 245 return this.originalMethod.original(); 246 } 247 } 248 | Popular Tags |