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.ast;
13 import org.eclipse.jdt.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.lookup.*;
17 public class JavadocMessageSend extends MessageSend {
19 public int tagSourceStart, tagSourceEnd;
20 public boolean superAccess = false;
22 public JavadocMessageSend(char[] name, long pos) {
24 this.nameSourcePosition = pos;
25 this.sourceStart = (int) (this.nameSourcePosition >>> 32);
26 this.sourceEnd = (int) this.nameSourcePosition;
27 this.bits |= InsideJavadoc;
29 public JavadocMessageSend(char[] name, long pos, JavadocArgumentExpression[] arguments) {
31 this.arguments = arguments;
35 * Resolves type on a Block or Class scope.
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);
46 this.receiverType = this.receiver.resolveType((BlockScope) scope);
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);
60 argumentTypes[i] = argument.resolveType((BlockScope)scope);
62 if (argumentTypes[i] == null) {
71 // check receiver type
72 if (this.receiverType == null) {
75 this.qualifyingType = this.receiverType;
76 this.superAccess = scope.enclosingSourceType().isCompatibleWith(this.receiverType);
78 // base type cannot receive any message
79 if (this.receiverType.isBaseType()) {
80 scope.problemReporter().javadocErrorNoMethodFor(this, this.receiverType, argumentTypes, scope.getDeclarationModifiers());
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
98 if (!this.binding.isValidBinding()) {
99 if (this.binding.declaringClass == null) {
100 if (this.receiverType instanceof ReferenceBinding) {
101 this.binding.declaringClass = (ReferenceBinding) this.receiverType;
103 scope.problemReporter().javadocErrorNoMethodFor(this, this.receiverType, argumentTypes, scope.getDeclarationModifiers());
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;
113 return this.resolvedType = this.binding == null ? null : this.binding.returnType;
115 if (isMethodUseDeprecated(this.binding, scope)) {
116 scope.problemReporter().javadocDeprecatedMethod(this.binding, this, scope.getDeclarationModifiers());
119 return this.resolvedType = this.binding.returnType;
123 * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#isSuperAccess()
125 public boolean isSuperAccess() {
126 return this.superAccess;
129 public StringBuffer printExpression(int indent, StringBuffer output){
131 if (this.receiver != null) {
132 this.receiver.printExpression(0, output);
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);
141 return output.append(')');
144 public TypeBinding resolveType(BlockScope scope) {
145 return internalResolveType(scope);
148 public TypeBinding resolveType(ClassScope scope) {
149 return internalResolveType(scope);
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)
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);
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);
167 visitor.endVisit(this, blockScope);