KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > ast > JavadocFieldReference


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-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.impl.Constant;
15 import org.eclipse.jdt.internal.compiler.lookup.*;
16
17 public class JavadocFieldReference extends FieldReference {
18
19     public int tagSourceStart, tagSourceEnd;
20     public int tagValue;
21     public MethodBinding methodBinding;
22
23     public JavadocFieldReference(char[] source, long pos) {
24         super(source, pos);
25         this.bits |= InsideJavadoc;
26     }
27     
28     /*
29     public Binding getBinding() {
30         if (this.methodBinding != null) {
31             return this.methodBinding;
32         }
33         return this.binding;
34     }
35     */

36
37     /*
38      * Resolves type on a Block or Class scope.
39      */

40     protected TypeBinding internalResolveType(Scope scope) {
41
42         this.constant = 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);
47         } else {
48             this.receiverType = this.receiver.resolveType((BlockScope)scope);
49         }
50         if (this.receiverType == null) {
51             return null;
52         }
53
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
66
}
67             }
68         }
69         // When there's no valid field binding, try to resolve possible method reference without parenthesis
70
if (!fieldBinding.isValidBinding() || !(fieldBinding instanceof FieldBinding)) {
71             if (this.receiverType instanceof ReferenceBinding) {
72                 ReferenceBinding refBinding = (ReferenceBinding) this.receiverType;
73                 MethodBinding[] methodBindings = refBinding.getMethods(this.token);
74                 if (methodBindings == null) {
75                     scope.problemReporter().javadocInvalidField(this.sourceStart, this.sourceEnd, fieldBinding, this.receiverType, scope.getDeclarationModifiers());
76                 } else {
77                     switch (methodBindings.length) {
78                         case 0:
79                             // no method was found: report problem
80
scope.problemReporter().javadocInvalidField(this.sourceStart, this.sourceEnd, fieldBinding, this.receiverType, scope.getDeclarationModifiers());
81                             break;
82                         case 1:
83                             // one method binding was found: store binding in specific field
84
this.methodBinding = methodBindings[0];
85                             break;
86                         default:
87                             // several method binding were found: store first binding in specific field and report ambiguous error
88
this.methodBinding = methodBindings[0];
89                             scope.problemReporter().javadocAmbiguousMethodReference(this.sourceStart, this.sourceEnd, fieldBinding, scope.getDeclarationModifiers());
90                             break;
91                     }
92                 }
93             }
94             return null;
95         }
96         this.binding = (FieldBinding) fieldBinding;
97
98         if (isFieldUseDeprecated(this.binding, scope, (this.bits & IsStrictlyAssigned) != 0)) {
99             scope.problemReporter().javadocDeprecatedField(this.binding, this, scope.getDeclarationModifiers());
100         }
101         return this.resolvedType = this.binding.type;
102     }
103     
104     public boolean isSuperAccess() {
105         return (this.bits & ASTNode.SuperAccess) != 0;
106     }
107
108     public StringBuffer JavaDoc printExpression(int indent, StringBuffer JavaDoc output) {
109
110         if (this.receiver != null) {
111             this.receiver.printExpression(0, output);
112         }
113         output.append('#').append(this.token);
114         return output;
115     }
116
117     public TypeBinding resolveType(BlockScope scope) {
118         return internalResolveType(scope);
119     }
120
121     public TypeBinding resolveType(ClassScope scope) {
122         return internalResolveType(scope);
123     }
124
125     /* (non-Javadoc)
126      * Redefine to capture javadoc specific signatures
127      * @see org.eclipse.jdt.internal.compiler.ast.ASTNode#traverse(org.eclipse.jdt.internal.compiler.ASTVisitor, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
128      */

129     public void traverse(ASTVisitor visitor, BlockScope scope) {
130
131         if (visitor.visit(this, scope)) {
132             if (this.receiver != null) {
133                 this.receiver.traverse(visitor, scope);
134             }
135         }
136         visitor.endVisit(this, scope);
137     }
138     public void traverse(ASTVisitor visitor, ClassScope scope) {
139
140         if (visitor.visit(this, scope)) {
141             if (this.receiver != null) {
142                 this.receiver.traverse(visitor, scope);
143             }
144         }
145         visitor.endVisit(this, scope);
146     }
147 }
148
Popular Tags