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 JavadocFieldReference(char[] source, long pos) {
22 this.bits |= InsideJavadoc;
26 * Resolves type on a Block or Class scope.
28 private TypeBinding internalResolveType(Scope scope) {
30 this.constant = NotAConstant;
31 if (this.receiver == null) {
32 this.receiverType = scope.enclosingSourceType();
33 } else if (scope.kind == Scope.CLASS_SCOPE) {
34 this.receiverType = this.receiver.resolveType((ClassScope) scope);
36 this.receiverType = this.receiver.resolveType((BlockScope)scope);
38 if (this.receiverType == null) {
42 Binding fieldBinding = (this.receiver != null && this.receiver.isThis())
43 ? scope.classScope().getBinding(this.token, this.bits & RestrictiveFlagMASK, this, true /*resolve*/)
44 : scope.getField(this.receiverType, this.token, this);
45 if (!fieldBinding.isValidBinding()) {
46 // implicit lookup may discover issues due to static/constructor contexts. javadoc must be resilient
47 switch (fieldBinding.problemId()) {
48 case ProblemReasons.NonStaticReferenceInConstructorInvocation:
49 case ProblemReasons.NonStaticReferenceInStaticContext:
50 case ProblemReasons.InheritedNameHidesEnclosingName :
51 FieldBinding closestMatch = ((ProblemFieldBinding)fieldBinding).closestMatch;
52 if (closestMatch != null) {
53 fieldBinding = closestMatch; // ignore problem if can reach target field through it
57 if (!fieldBinding.isValidBinding() || !(fieldBinding instanceof FieldBinding)) {
58 if (this.receiverType instanceof ReferenceBinding) {
59 ReferenceBinding refBinding = (ReferenceBinding) this.receiverType;
60 MethodBinding[] bindings = refBinding.getMethods(this.token);
61 if (bindings == null) {
62 scope.problemReporter().javadocInvalidField(this.sourceStart, this.sourceEnd, fieldBinding, this.receiverType, scope.getDeclarationModifiers());
64 switch (bindings.length) {
66 scope.problemReporter().javadocInvalidField(this.sourceStart, this.sourceEnd, fieldBinding, this.receiverType, scope.getDeclarationModifiers());
72 scope.problemReporter().javadocAmbiguousMethodReference(this.sourceStart, this.sourceEnd, fieldBinding, scope.getDeclarationModifiers());
79 this.binding = (FieldBinding) fieldBinding;
81 if (isFieldUseDeprecated(this.binding, scope, (this.bits & IsStrictlyAssignedMASK) != 0)) {
82 scope.problemReporter().javadocDeprecatedField(this.binding, this, scope.getDeclarationModifiers());
84 return this.resolvedType = this.binding.type;
88 * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#isSuperAccess()
90 public boolean isSuperAccess() {
94 public StringBuffer printExpression(int indent, StringBuffer output) {
96 if (this.receiver != null) {
97 this.receiver.printExpression(0, output);
99 output.append('#').append(this.token);
104 * @see org.eclipse.jdt.internal.compiler.ast.Expression#resolveType(org.eclipse.jdt.internal.compiler.lookup.BlockScope)
106 public TypeBinding resolveType(BlockScope scope) {
107 return internalResolveType(scope);
111 * @see org.eclipse.jdt.internal.compiler.ast.Expression#resolveType(org.eclipse.jdt.internal.compiler.lookup.BlockScope)
113 public TypeBinding resolveType(ClassScope scope) {
114 return internalResolveType(scope);
118 * Redefine to capture javadoc specific signatures
119 * @see org.eclipse.jdt.internal.compiler.ast.ASTNode#traverse(org.eclipse.jdt.internal.compiler.ASTVisitor, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
121 public void traverse(ASTVisitor visitor, BlockScope scope) {
123 if (visitor.visit(this, scope)) {
124 if (this.receiver != null) {
125 this.receiver.traverse(visitor, scope);
128 visitor.endVisit(this, scope);