Makefile fixup
[org.ibex.tool.git] / repo / org.ibex.tool / src / org / eclipse / jdt / internal / compiler / ast / JavadocFieldReference.java
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
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.lookup.*;
15
16 public class JavadocFieldReference extends FieldReference {
17
18         public int tagSourceStart, tagSourceEnd;
19
20         public JavadocFieldReference(char[] source, long pos) {
21                 super(source, pos);
22                 this.bits |= InsideJavadoc;
23         }
24
25         /*
26          * Resolves type on a Block or Class scope.
27          */
28         private TypeBinding internalResolveType(Scope scope) {
29
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);
35                 } else {
36                         this.receiverType = this.receiver.resolveType((BlockScope)scope);
37                 }
38                 if (this.receiverType == null) {
39                         return null;
40                 }
41
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
54                                         }
55                         }
56                 }                       
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());
63                                 } else {
64                                         switch (bindings.length) {
65                                                 case 0:
66                                                         scope.problemReporter().javadocInvalidField(this.sourceStart, this.sourceEnd, fieldBinding, this.receiverType, scope.getDeclarationModifiers());
67                                                         break;
68                                                 case 1:
69                                                         this.binding = null;
70                                                         break;
71                                                 default:
72                                                         scope.problemReporter().javadocAmbiguousMethodReference(this.sourceStart, this.sourceEnd, fieldBinding, scope.getDeclarationModifiers());
73                                                         break;
74                                         }
75                                 }
76                         }
77                         return null;
78                 }
79                 this.binding = (FieldBinding) fieldBinding;
80
81                 if (isFieldUseDeprecated(this.binding, scope, (this.bits & IsStrictlyAssignedMASK) != 0)) {
82                         scope.problemReporter().javadocDeprecatedField(this.binding, this, scope.getDeclarationModifiers());
83                 }
84                 return this.resolvedType = this.binding.type;
85         }
86         
87         /* (non-Javadoc)
88          * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#isSuperAccess()
89          */
90         public boolean isSuperAccess() {
91                 return false;
92         }
93
94         public StringBuffer printExpression(int indent, StringBuffer output) {
95
96                 if (this.receiver != null) {
97                         this.receiver.printExpression(0, output);
98                 }
99                 output.append('#').append(this.token);
100                 return output;
101         }
102
103         /* (non-Javadoc)
104          * @see org.eclipse.jdt.internal.compiler.ast.Expression#resolveType(org.eclipse.jdt.internal.compiler.lookup.BlockScope)
105          */
106         public TypeBinding resolveType(BlockScope scope) {
107                 return internalResolveType(scope);
108         }
109
110         /* (non-Javadoc)
111          * @see org.eclipse.jdt.internal.compiler.ast.Expression#resolveType(org.eclipse.jdt.internal.compiler.lookup.BlockScope)
112          */
113         public TypeBinding resolveType(ClassScope scope) {
114                 return internalResolveType(scope);
115         }
116
117         /* (non-Javadoc)
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)
120          */
121         public void traverse(ASTVisitor visitor, BlockScope scope) {
122
123                 if (visitor.visit(this, scope)) {
124                         if (this.receiver != null) {
125                                 this.receiver.traverse(visitor, scope);
126                         }
127                 }
128                 visitor.endVisit(this, scope);
129         }
130 }