removed Makefile; lifted repo/org.ibex.tool/src/ to src/
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / ast / JavadocMessageSend.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.ast;
12
13 import org.eclipse.jdt.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.lookup.*;
15
16
17 public class JavadocMessageSend extends MessageSend {
18
19         public int tagSourceStart, tagSourceEnd;
20         public boolean superAccess = false;
21
22         public JavadocMessageSend(char[] name, long pos) {
23                 this.selector = name;
24                 this.nameSourcePosition = pos;
25                 this.sourceStart = (int) (this.nameSourcePosition >>> 32);
26                 this.sourceEnd = (int) this.nameSourcePosition;
27                 this.bits |= InsideJavadoc;
28         }
29         public JavadocMessageSend(char[] name, long pos, JavadocArgumentExpression[] arguments) {
30                 this(name, pos);
31                 this.arguments = arguments;
32         }
33
34         /*
35          * Resolves type on a Block or Class scope.
36          */
37         private TypeBinding internalResolveType(Scope scope) {
38                 // Answer the signature return type
39                 // Base type promotion
40                 this.constant = NotAConstant;
41                 if (this.receiver == null) {
42                         this.receiverType = scope.enclosingSourceType();
43                 } else if (scope.kind == Scope.CLASS_SCOPE) {
44                         this.receiverType = this.receiver.resolveType((ClassScope) scope);
45                 } else {
46                         this.receiverType = this.receiver.resolveType((BlockScope) scope);
47                 }
48
49                 // will check for null after args are resolved
50                 TypeBinding[] argumentTypes = NoParameters;
51                 if (this.arguments != null) {
52                         boolean argHasError = false; // typeChecks all arguments 
53                         int length = this.arguments.length;
54                         argumentTypes = new TypeBinding[length];
55                         for (int i = 0; i < length; i++){
56                                 Expression argument = this.arguments[i];
57                                 if (scope.kind == Scope.CLASS_SCOPE) {
58                                         argumentTypes[i] = argument.resolveType((ClassScope)scope);
59                                 } else {
60                                         argumentTypes[i] = argument.resolveType((BlockScope)scope);
61                                 }
62                                 if (argumentTypes[i] == null) {
63                                         argHasError = true;
64                                 }
65                         }
66                         if (argHasError) {
67                                 return null;
68                         }
69                 }
70
71                 // check receiver type
72                 if (this.receiverType == null) {
73                         return null;
74                 }
75                 this.qualifyingType = this.receiverType;
76                 this.superAccess = scope.enclosingSourceType().isCompatibleWith(this.receiverType);
77
78                 // base type cannot receive any message
79                 if (this.receiverType.isBaseType()) {
80                         scope.problemReporter().javadocErrorNoMethodFor(this, this.receiverType, argumentTypes, scope.getDeclarationModifiers());
81                         return null;
82                 }
83                 this.binding = (this.receiver != null && this.receiver.isThis())
84                         ? scope.getImplicitMethod(this.selector, argumentTypes, this)
85                         : scope.getMethod(this.receiverType, this.selector, argumentTypes, this);
86                 if (!this.binding.isValidBinding()) {
87                         // implicit lookup may discover issues due to static/constructor contexts. javadoc must be resilient
88                         switch (this.binding.problemId()) {
89                                 case ProblemReasons.NonStaticReferenceInConstructorInvocation:
90                                 case ProblemReasons.NonStaticReferenceInStaticContext:
91                                 case ProblemReasons.InheritedNameHidesEnclosingName : 
92                                         MethodBinding closestMatch = ((ProblemMethodBinding)this.binding).closestMatch;
93                                         if (closestMatch != null) {
94                                                 this.binding = closestMatch; // ignore problem if can reach target method through it
95                                         }
96                         }
97                 }
98                 if (!this.binding.isValidBinding()) {
99                         if (this.binding.declaringClass == null) {
100                                 if (this.receiverType instanceof ReferenceBinding) {
101                                         this.binding.declaringClass = (ReferenceBinding) this.receiverType;
102                                 } else { 
103                                         scope.problemReporter().javadocErrorNoMethodFor(this, this.receiverType, argumentTypes, scope.getDeclarationModifiers());
104                                         return null;
105                                 }
106                         }
107                         scope.problemReporter().javadocInvalidMethod(this, this.binding, scope.getDeclarationModifiers());
108                         // record the closest match, for clients who may still need hint about possible method match
109                         if (this.binding instanceof ProblemMethodBinding){
110                                 MethodBinding closestMatch = ((ProblemMethodBinding)this.binding).closestMatch;
111                                 if (closestMatch != null) this.codegenBinding = this.binding = closestMatch;
112                         }
113                         return this.resolvedType = this.binding == null ? null : this.binding.returnType;
114                 }
115                 if (isMethodUseDeprecated(this.binding, scope)) {
116                         scope.problemReporter().javadocDeprecatedMethod(this.binding, this, scope.getDeclarationModifiers());
117                 }
118
119                 return this.resolvedType = this.binding.returnType;
120         }
121         
122         /* (non-Javadoc)
123          * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#isSuperAccess()
124          */
125         public boolean isSuperAccess() {
126                 return this.superAccess;
127         }
128
129         public StringBuffer printExpression(int indent, StringBuffer output){
130         
131                 if (this.receiver != null) {
132                         this.receiver.printExpression(0, output);
133                 }
134                 output.append('#').append(this.selector).append('(');
135                 if (this.arguments != null) {
136                         for (int i = 0; i < this.arguments.length ; i ++) {     
137                                 if (i > 0) output.append(", "); //$NON-NLS-1$
138                                 this.arguments[i].printExpression(0, output);
139                         }
140                 }
141                 return output.append(')');
142         }
143
144         public TypeBinding resolveType(BlockScope scope) {
145                 return internalResolveType(scope);
146         }
147
148         public TypeBinding resolveType(ClassScope scope) {
149                 return internalResolveType(scope);
150         }
151
152         /* (non-Javadoc)
153          * Redefine to capture javadoc specific signatures
154          * @see org.eclipse.jdt.internal.compiler.ast.ASTNode#traverse(org.eclipse.jdt.internal.compiler.ASTVisitor, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
155          */
156         public void traverse(ASTVisitor visitor, BlockScope blockScope) {
157                 if (visitor.visit(this, blockScope)) {
158                         if (this.receiver != null) {
159                                 this.receiver.traverse(visitor, blockScope);
160                         }
161                         if (this.arguments != null) {
162                                 int argumentsLength = this.arguments.length;
163                                 for (int i = 0; i < argumentsLength; i++)
164                                         this.arguments[i].traverse(visitor, blockScope);
165                         }
166                 }
167                 visitor.endVisit(this, blockScope);
168         }
169 }