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;
21 public boolean superAccess = false;
23 public JavadocMessageSend(char[] name, long pos) {
25 this.nameSourcePosition = pos;
26 this.sourceStart = (int) (this.nameSourcePosition >>> 32);
27 this.sourceEnd = (int) this.nameSourcePosition;
28 this.bits |= InsideJavadoc;
30 public JavadocMessageSend(char[] name, long pos, JavadocArgumentExpression[] arguments) {
32 this.arguments = arguments;
36 * Resolves type on a Block or Class scope.
38 private TypeBinding internalResolveType(Scope scope) {
39 // Answer the signature return type
40 // Base type promotion
41 this.constant = NotAConstant;
42 if (this.receiver == null) {
43 this.actualReceiverType = scope.enclosingSourceType();
44 } else if (scope.kind == Scope.CLASS_SCOPE) {
45 this.actualReceiverType = this.receiver.resolveType((ClassScope) scope);
47 this.actualReceiverType = this.receiver.resolveType((BlockScope) scope);
50 // will check for null after args are resolved
51 TypeBinding[] argumentTypes = NoParameters;
52 if (this.arguments != null) {
53 boolean argHasError = false; // typeChecks all arguments
54 int length = this.arguments.length;
55 argumentTypes = new TypeBinding[length];
56 for (int i = 0; i < length; i++){
57 Expression argument = this.arguments[i];
58 if (scope.kind == Scope.CLASS_SCOPE) {
59 argumentTypes[i] = argument.resolveType((ClassScope)scope);
61 argumentTypes[i] = argument.resolveType((BlockScope)scope);
63 if (argumentTypes[i] == null) {
72 // check receiver type
73 if (this.actualReceiverType == null) {
76 this.superAccess = scope.enclosingSourceType().isCompatibleWith(this.actualReceiverType);
78 // base type cannot receive any message
79 if (this.actualReceiverType.isBaseType()) {
80 scope.problemReporter().javadocErrorNoMethodFor(this, this.actualReceiverType, argumentTypes, scope.getDeclarationModifiers());
83 this.binding = (this.receiver != null && this.receiver.isThis())
84 ? scope.getImplicitMethod(this.selector, argumentTypes, this)
85 : scope.getMethod(this.actualReceiverType, 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.actualReceiverType instanceof ReferenceBinding) {
101 this.binding.declaringClass = (ReferenceBinding) this.actualReceiverType;
103 scope.problemReporter().javadocErrorNoMethodFor(this, this.actualReceiverType, 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.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);