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.*;
16 public class JavadocFieldReference extends FieldReference {
18 public int tagSourceStart, tagSourceEnd;
20 public MethodBinding methodBinding;
21 public boolean superAccess = false;
23 public JavadocFieldReference(char[] source, long pos) {
25 this.bits |= InsideJavadoc;
29 public Binding getBinding() {
30 if (this.methodBinding != null) {
31 return this.methodBinding;
38 * Resolves type on a Block or Class scope.
40 private TypeBinding internalResolveType(Scope scope) {
42 this.constant = NotAConstant;
43 if (this.receiver == null) {
44 this.receiverType = scope.enclosingSourceType();
45 } else if (scope.kind == Scope.CLASS_SCOPE) {
46 this.receiverType = this.receiver.resolveType((ClassScope) scope);
48 this.receiverType = this.receiver.resolveType((BlockScope)scope);
50 if (this.receiverType == null) {
54 Binding fieldBinding = (this.receiver != null && this.receiver.isThis())
55 ? scope.classScope().getBinding(this.token, this.bits & RestrictiveFlagMASK, this, true /*resolve*/)
56 : scope.getField(this.receiverType, this.token, this);
57 if (!fieldBinding.isValidBinding()) {
58 // implicit lookup may discover issues due to static/constructor contexts. javadoc must be resilient
59 switch (fieldBinding.problemId()) {
60 case ProblemReasons.NonStaticReferenceInConstructorInvocation:
61 case ProblemReasons.NonStaticReferenceInStaticContext:
62 case ProblemReasons.InheritedNameHidesEnclosingName :
63 FieldBinding closestMatch = ((ProblemFieldBinding)fieldBinding).closestMatch;
64 if (closestMatch != null) {
65 fieldBinding = closestMatch; // ignore problem if can reach target field through it
69 if (!fieldBinding.isValidBinding() || !(fieldBinding instanceof FieldBinding)) {
70 if (this.receiverType instanceof ReferenceBinding) {
71 ReferenceBinding refBinding = (ReferenceBinding) this.receiverType;
72 MethodBinding[] methodBindings = refBinding.getMethods(this.token);
73 if (methodBindings == null) {
74 scope.problemReporter().javadocInvalidField(this.sourceStart, this.sourceEnd, fieldBinding, this.receiverType, scope.getDeclarationModifiers());
76 switch (methodBindings.length) {
78 scope.problemReporter().javadocInvalidField(this.sourceStart, this.sourceEnd, fieldBinding, this.receiverType, scope.getDeclarationModifiers());
81 this.methodBinding = methodBindings[0];
84 this.methodBinding = methodBindings[0];
85 scope.problemReporter().javadocAmbiguousMethodReference(this.sourceStart, this.sourceEnd, fieldBinding, scope.getDeclarationModifiers());
92 this.binding = (FieldBinding) fieldBinding;
94 if (isFieldUseDeprecated(this.binding, scope, (this.bits & IsStrictlyAssignedMASK) != 0)) {
95 scope.problemReporter().javadocDeprecatedField(this.binding, this, scope.getDeclarationModifiers());
97 return this.resolvedType = this.binding.type;
101 * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#isSuperAccess()
103 public boolean isSuperAccess() {
104 return this.superAccess;
107 public StringBuffer printExpression(int indent, StringBuffer output) {
109 if (this.receiver != null) {
110 this.receiver.printExpression(0, output);
112 output.append('#').append(this.token);
117 * @see org.eclipse.jdt.internal.compiler.ast.Expression#resolveType(org.eclipse.jdt.internal.compiler.lookup.BlockScope)
119 public TypeBinding resolveType(BlockScope scope) {
120 return internalResolveType(scope);
124 * @see org.eclipse.jdt.internal.compiler.ast.Expression#resolveType(org.eclipse.jdt.internal.compiler.lookup.BlockScope)
126 public TypeBinding resolveType(ClassScope scope) {
127 return internalResolveType(scope);
131 * Redefine to capture javadoc specific signatures
132 * @see org.eclipse.jdt.internal.compiler.ast.ASTNode#traverse(org.eclipse.jdt.internal.compiler.ASTVisitor, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
134 public void traverse(ASTVisitor visitor, BlockScope scope) {
136 if (visitor.visit(this, scope)) {
137 if (this.receiver != null) {
138 this.receiver.traverse(visitor, scope);
141 visitor.endVisit(this, scope);