import eclipse 3.1 M4 compiler
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / lookup / ParameterizedMethodBinding.java
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
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.internal.compiler.ast.Wildcard;
14
15 /**
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
19  * these methods.
20  */
21 public class ParameterizedMethodBinding extends MethodBinding {
22
23         protected MethodBinding originalMethod;
24
25         /**
26          * Create method of parameterized type, substituting original parameters/exception/return type with type arguments.
27          */
28         public ParameterizedMethodBinding(ParameterizedTypeBinding parameterizedDeclaringClass, MethodBinding originalMethod, boolean isStatic) {
29
30                 super(
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;
45         }
46
47         public ParameterizedMethodBinding() {
48                 // no init
49         }
50
51         /*
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
54          */
55         public char[] computeUniqueKey() {
56                 return computeUniqueKey(original());
57         }
58
59         /**
60          * The type of x.getClass() is substituted from 'Class<? extends Object>' into: 'Class<? extends |X|> where |X| is X's erasure.
61          */
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(
73                         genericClassType,
74                         new TypeBinding[] {  scope.environment().createWildcard(genericClassType, 0, receiverType.erasure(), Wildcard.EXTENDS) },
75                         null);
76                 return method;
77         }
78
79         /**
80          * Returns true if some parameters got substituted.
81          */
82         public boolean hasSubstitutedParameters() {
83                 return this.parameters != originalMethod.parameters;
84         }
85
86         /**
87          * Returns true if the return type got substituted.
88          */
89         public boolean hasSubstitutedReturnType() {
90                 return this.returnType != originalMethod.returnType;
91         }
92
93         /**
94          * Returns the original method (as opposed to parameterized instances)
95          */
96         public MethodBinding original() {
97                 return this.originalMethod.original();
98         }
99 }