Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2011 IBM Corporation and others. 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 Contributors: IBM Corporation - initial API and implementation Stephan Herrmann - Contribution for bug 186342 - [compiler][null] Using annotations for null checking /
 
 package org.eclipse.jdt.internal.compiler.lookup;
 
Binding denoting a method after type parameter substitutions got performed. On parameterized type bindings, all methods got substituted, regardless whether their signature did involve generics or not, so as to get the proper declaringClass for these methods.
 
 public class ParameterizedMethodBinding extends MethodBinding {
 
Create method of parameterized type, substituting original parameters/exception/return type with type arguments.
 
 	public ParameterizedMethodBinding(final ParameterizedTypeBinding parameterizedDeclaringClassMethodBinding originalMethod) {
 		super(
 				originalMethod.modifiers,
 				originalMethod.selector,
 				originalMethod.returnType,
 				originalMethod.parameters,
 				originalMethod.thrownExceptions,
 				parameterizedDeclaringClass);
 		this. = originalMethod;
 		/* missing type bit cannot be copied as is it might come from the return type or a parameter type that
 		 * is substituted by a raw type.
 		 */
 		this. = originalMethod.tagBits & ~.;
 		this. = originalMethod.parameterNonNullness;
 
 		final TypeVariableBinding[] originalVariables = originalMethod.typeVariables;
 		Substitution substitution = null;
 		final int length = originalVariables.length;
 		final boolean isStatic = originalMethod.isStatic();
 		if (length == 0) {
 			if (!isStaticsubstitution = parameterizedDeclaringClass;
 		} else {
 			// at least fix up the declaringElement binding + bound substitution if non static
 			final TypeVariableBinding[] substitutedVariables = new TypeVariableBinding[length];
 			for (int i = 0; i < lengthi++) { // copy original type variable to relocate
 				TypeVariableBinding originalVariable = originalVariables[i];
 				substitutedVariables[i] = new TypeVariableBinding(originalVariable.sourceNamethisoriginalVariable.rankparameterizedDeclaringClass.environment);
 			}
 			this. = substitutedVariables;
 
 			// need to substitute old var refs with new ones (double substitution: declaringClass + new type variables)
 			substitution = new Substitution() {
 					return parameterizedDeclaringClass.environment;
 				}
 				public boolean isRawSubstitution() {
 					return !isStatic && parameterizedDeclaringClass.isRawSubstitution();
 				}
 				public TypeBinding substitute(TypeVariableBinding typeVariable) {
 					// check this variable can be substituted given copied variables
 					if (typeVariable.rank < length && originalVariables[typeVariable.rank] == typeVariable) {
 						return substitutedVariables[typeVariable.rank];
 					}
 					if (!isStatic)
 						return parameterizedDeclaringClass.substitute(typeVariable);
 					return typeVariable;
 				}
 			};
 
 			// initialize new variable bounds
 			for (int i = 0; i < lengthi++) {
 				TypeVariableBinding originalVariable = originalVariables[i];
 				TypeVariableBinding substitutedVariable = substitutedVariables[i];
 				TypeBinding substitutedSuperclass = Scope.substitute(substitutionoriginalVariable.superclass);
 				ReferenceBinding[] substitutedInterfaces = Scope.substitute(substitutionoriginalVariable.superInterfaces);
 				if (originalVariable.firstBound != null) {
 					substitutedVariable.firstBound = originalVariable.firstBound == originalVariable.superclass
 						? substitutedSuperclass // could be array type or interface
 						: substitutedInterfaces[0];
 				}
 				switch (substitutedSuperclass.kind()) {
 					case . :
 						substitutedVariable.superclass = parameterizedDeclaringClass.environment.getResolvedType(.null);
 						substitutedVariable.superInterfaces = substitutedInterfaces;
 						break;
 					default:
 						if (substitutedSuperclass.isInterface()) {
 							substitutedVariable.superclass = parameterizedDeclaringClass.environment.getResolvedType(.null);
 							int interfaceCount = substitutedInterfaces.length;
 							System.arraycopy(substitutedInterfaces, 0, substitutedInterfaces = new ReferenceBinding[interfaceCount+1], 1, interfaceCount);
							substitutedInterfaces[0] = (ReferenceBindingsubstitutedSuperclass;
							substitutedVariable.superInterfaces = substitutedInterfaces;
else {
							substitutedVariable.superclass = (ReferenceBindingsubstitutedSuperclass// typeVar was extending other typeVar which got substituted with interface
							substitutedVariable.superInterfaces = substitutedInterfaces;
						}
				}
			}
		}
		if (substitution != null) {
			this. = Scope.substitute(substitutionthis.);
			this. = Scope.substitute(substitutionthis.);
			this. = Scope.substitute(substitutionthis.);
			// error case where exception type variable would have been substituted by a non-reference type (207573)
		}
		checkMissingType: {
			if ((this. & .) != 0)
				break checkMissingType;
			if ((this.. & .) != 0) {
				break checkMissingType;
			}
			for (int i = 0, max = this..lengthi < maxi++) {
				if ((this.[i]. & .) != 0) {
					break checkMissingType;
				}
			}
			for (int i = 0, max = this..lengthi < maxi++) {
				if ((this.[i]. & .) != 0) {
					break checkMissingType;
				}
			}
		}
	}

Create method of parameterized type, substituting original parameters/exception/return type with type arguments. This is a CODE ASSIST method ONLY.
	public ParameterizedMethodBinding(final ReferenceBinding declaringClassMethodBinding originalMethodchar[][] alternateParamaterNamesfinal LookupEnvironment environment) {
		super(
				originalMethod.modifiers,
				originalMethod.selector,
				 originalMethod.returnType,
				originalMethod.parameters,
				originalMethod.thrownExceptions,
				declaringClass);
		this. = originalMethod;
		/* missing type bit cannot be copied as is it might come from the return type or a parameter type that
		 * is substituted by a raw type.
		 */
		this. = originalMethod.tagBits & ~.;
		this. = originalMethod.parameterNonNullness;
		final TypeVariableBinding[] originalVariables = originalMethod.typeVariables;
		Substitution substitution = null;
		final int length = originalVariables.length;
		if (length == 0) {
else {
			// at least fix up the declaringElement binding + bound substitution if non static
			final TypeVariableBinding[] substitutedVariables = new TypeVariableBinding[length];
			for (int i = 0; i < lengthi++) { // copy original type variable to relocate
				TypeVariableBinding originalVariable = originalVariables[i];
				substitutedVariables[i] = new TypeVariableBinding(
						alternateParamaterNames == null ?
								originalVariable.sourceName :
								alternateParamaterNames[i],
							this,
							originalVariable.rank,
							environment);
			}
			this. = substitutedVariables;
			// need to substitute old var refs with new ones (double substitution: declaringClass + new type variables)
			substitution = new Substitution() {
					return environment;
				}
				public boolean isRawSubstitution() {
					return false;
				}
				public TypeBinding substitute(TypeVariableBinding typeVariable) {
			        // check this variable can be substituted given copied variables
			        if (typeVariable.rank < length && originalVariables[typeVariable.rank] == typeVariable) {
						return substitutedVariables[typeVariable.rank];
			        }
			        return typeVariable;
				}
			};
			// initialize new variable bounds
			for (int i = 0; i < lengthi++) {
				TypeVariableBinding originalVariable = originalVariables[i];
				TypeVariableBinding substitutedVariable = substitutedVariables[i];
				TypeBinding substitutedSuperclass = Scope.substitute(substitutionoriginalVariable.superclass);
				ReferenceBinding[] substitutedInterfaces = Scope.substitute(substitutionoriginalVariable.superInterfaces);
				if (originalVariable.firstBound != null) {
					substitutedVariable.firstBound = originalVariable.firstBound == originalVariable.superclass
substitutedSuperclass // could be array type or interface
substitutedInterfaces[0];
				}
				switch (substitutedSuperclass.kind()) {
						substitutedVariable.superclass = environment.getResolvedType(.null);
						substitutedVariable.superInterfaces = substitutedInterfaces;
						break;
					default:
						if (substitutedSuperclass.isInterface()) {
							substitutedVariable.superclass = environment.getResolvedType(.null);
							int interfaceCount = substitutedInterfaces.length;
							System.arraycopy(substitutedInterfaces, 0, substitutedInterfaces = new ReferenceBinding[interfaceCount+1], 1, interfaceCount);
							substitutedInterfaces[0] = (ReferenceBindingsubstitutedSuperclass;
							substitutedVariable.superInterfaces = substitutedInterfaces;
else {
							substitutedVariable.superclass = (ReferenceBindingsubstitutedSuperclass// typeVar was extending other typeVar which got substituted with interface
							substitutedVariable.superInterfaces = substitutedInterfaces;
						}
				}
			}
		}
		if (substitution != null) {
			this. = Scope.substitute(substitutionthis.);
			this. = Scope.substitute(substitutionthis.);
			this. = Scope.substitute(substitutionthis.);
		    // error case where exception type variable would have been substituted by a non-reference type (207573)
		    if (this. == nullthis. = .;
		}
		checkMissingType: {
			if ((this. & .) != 0)
				break checkMissingType;
			if ((this.. & .) != 0) {
				break checkMissingType;
			}
			for (int i = 0, max = this..lengthi < maxi++) {
				if ((this.[i]. & .) != 0) {
					break checkMissingType;
				}
			}
			for (int i = 0, max = this..lengthi < maxi++) {
				if ((this.[i]. & .) != 0) {
					break checkMissingType;
				}
			}
		}
	}
		// no init
	}

The type of x.getClass() is substituted from 'Class<? extends Object>' into: 'Class<? extends raw(X)>
	public static ParameterizedMethodBinding instantiateGetClass(TypeBinding receiverTypeMethodBinding originalMethodScope scope) {
		method.modifiers = originalMethod.modifiers;
		method.selector = originalMethod.selector;
		method.declaringClass = originalMethod.declaringClass;
		method.typeVariables = .;
		method.originalMethod = originalMethod;
		method.parameters = originalMethod.parameters;
		method.thrownExceptions = originalMethod.thrownExceptions;
		method.tagBits = originalMethod.tagBits;
		ReferenceBinding genericClassType = scope.getJavaLangClass();
		LookupEnvironment environment = scope.environment();
		TypeBinding rawType = environment.convertToRawType(receiverType.erasure(), false /*do not force conversion of enclosing types*/);
		method.returnType = environment.createParameterizedType(
			genericClassType,
			new TypeBinding[] {  environment.createWildcard(genericClassType, 0, rawTypenull /*no extra bound*/.) },
			null);
		if ((method.returnType.tagBits & .) != 0) {
			method.tagBits |=  .;
		}
		return method;
	}

Returns true if some parameters got substituted.
	public boolean hasSubstitutedParameters() {
		return this. != this..;
	}

Returns true if the return type got substituted.
	public boolean hasSubstitutedReturnType() {
		return this. != this..;
	}

Returns the original method (as opposed to parameterized instances)
	public MethodBinding original() {
		return this..original();
	}
New to GrepCode? Check out our FAQ X