1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.lookup;
13 import org.eclipse.jdt.internal.compiler.ast.Wildcard;
16 * Binding denoting a method after type parameter substitutions got performed.
17 * On parameterized type bindings, all methods got substituted, regardless whether
18 * their signature did involve generics or not, so as to get the proper declaringClass for
21 public class ParameterizedMethodBinding extends MethodBinding {
23 protected MethodBinding originalMethod;
26 * Create method of parameterized type, substituting original parameters/exception/return type with type arguments.
28 public ParameterizedMethodBinding(ParameterizedTypeBinding parameterizedDeclaringClass, MethodBinding originalMethod, boolean isStatic) {
31 originalMethod.modifiers,
32 originalMethod.selector,
33 isStatic // no substitution if original was static
34 ? originalMethod.returnType
35 : parameterizedDeclaringClass.substitute(originalMethod.returnType),
36 isStatic // no substitution if original was static
37 ? originalMethod.parameters
38 : Scope.substitute(parameterizedDeclaringClass, originalMethod.parameters),
39 isStatic // no substitution if original was static
40 ? originalMethod.thrownExceptions
41 : Scope.substitute(parameterizedDeclaringClass, originalMethod.thrownExceptions),
42 parameterizedDeclaringClass);
43 this.originalMethod = originalMethod;
44 this.typeVariables = originalMethod.typeVariables;
47 public ParameterizedMethodBinding() {
52 * parameterizedDeclaringUniqueKey dot selector originalMethodGenericSignature
53 * p.X<U> { void bar(U u) { new X<String>().bar("") } } --> Lp/X<Ljava/lang/String;>;.bar(TU;)V
55 public char[] computeUniqueKey() {
56 return computeUniqueKey(original());
60 * The type of x.getClass() is substituted from 'Class<? extends Object>' into: 'Class<? extends |X|> where |X| is X's erasure.
62 public static ParameterizedMethodBinding instantiateGetClass(TypeBinding receiverType, MethodBinding originalMethod, Scope scope) {
63 ParameterizedMethodBinding method = new ParameterizedMethodBinding();
64 method.modifiers = originalMethod.modifiers;
65 method.selector = originalMethod.selector;
66 method.declaringClass = originalMethod.declaringClass;
67 method.typeVariables = NoTypeVariables;
68 method.originalMethod = originalMethod;
69 method.parameters = originalMethod.parameters;
70 method.thrownExceptions = originalMethod.thrownExceptions;
71 ReferenceBinding genericClassType = scope.getJavaLangClass();
72 method.returnType = scope.createParameterizedType(
74 new TypeBinding[] { scope.environment().createWildcard(genericClassType, 0, receiverType.erasure(), Wildcard.EXTENDS) },
80 * Returns true if some parameters got substituted.
82 public boolean hasSubstitutedParameters() {
83 return this.parameters != originalMethod.parameters;
87 * Returns true if the return type got substituted.
89 public boolean hasSubstitutedReturnType() {
90 return this.returnType != originalMethod.returnType;
94 * Returns the original method (as opposed to parameterized instances)
96 public MethodBinding original() {
97 return this.originalMethod.original();