KickJava   Java API By Example, From Geeks To Geeks.

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


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.Binding;
16 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
17 import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
18 import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
19 import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
20 import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
21 import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
22 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
23 import org.eclipse.jdt.internal.compiler.lookup.Scope;
24 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
25
26
27 public class JavadocSingleTypeReference extends SingleTypeReference {
28     
29     public int tagSourceStart, tagSourceEnd;
30     public PackageBinding packageBinding;
31
32     public JavadocSingleTypeReference(char[] source, long pos, int tagStart, int tagEnd) {
33         super(source, pos);
34         this.tagSourceStart = tagStart;
35         this.tagSourceEnd = tagEnd;
36         this.bits |= ASTNode.InsideJavadoc;
37     }
38
39     protected void reportInvalidType(Scope scope) {
40         scope.problemReporter().javadocInvalidType(this, this.resolvedType, scope.getDeclarationModifiers());
41     }
42     protected void reportDeprecatedType(TypeBinding type, Scope scope) {
43         scope.problemReporter().javadocDeprecatedType(type, this, scope.getDeclarationModifiers());
44     }
45
46     /* (non-Javadoc)
47      * Redefine to capture javadoc specific signatures
48      * @see org.eclipse.jdt.internal.compiler.ast.ASTNode#traverse(org.eclipse.jdt.internal.compiler.ASTVisitor, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
49      */

50     public void traverse(ASTVisitor visitor, BlockScope scope) {
51         visitor.visit(this, scope);
52         visitor.endVisit(this, scope);
53     }
54     
55     public void traverse(ASTVisitor visitor, ClassScope scope) {
56         visitor.visit(this, scope);
57         visitor.endVisit(this, scope);
58     }
59
60     /*
61      * We need to modify resolving behavior to handle package references
62      */

63     TypeBinding internalResolveType(Scope scope) {
64         // handle the error here
65
this.constant = Constant.NotAConstant;
66         if (this.resolvedType != null)// is a shared type reference which was already resolved
67
return this.resolvedType.isValidBinding() ? this.resolvedType : null; // already reported error
68

69         this.resolvedType = getTypeBinding(scope);
70         if (!this.resolvedType.isValidBinding()) {
71             char[][] tokens = { this.token };
72             Binding binding = scope.getTypeOrPackage(tokens);
73             if (binding instanceof PackageBinding) {
74                 this.packageBinding = (PackageBinding) binding;
75             } else {
76                 if (this.resolvedType.problemId() == ProblemReasons.NonStaticReferenceInStaticContext) {
77                     ReferenceBinding closestMatch = ((ProblemReferenceBinding)this.resolvedType).closestMatch();
78                     if (closestMatch != null && closestMatch.isTypeVariable()) {
79                         this.resolvedType = closestMatch; // ignore problem as we want report specific javadoc one instead
80
return this.resolvedType;
81                     }
82                 }
83                 reportInvalidType(scope);
84             }
85             return null;
86         }
87         if (isTypeUseDeprecated(this.resolvedType, scope))
88             reportDeprecatedType(this.resolvedType, scope);
89         if (this.resolvedType instanceof ParameterizedTypeBinding) {
90             this.resolvedType = ((ParameterizedTypeBinding)this.resolvedType).genericType();
91         }
92         return this.resolvedType;
93     }
94
95     /* (non-Javadoc)
96      * @see org.eclipse.jdt.internal.compiler.ast.Expression#resolveType(org.eclipse.jdt.internal.compiler.lookup.BlockScope)
97      * We need to override to handle package references
98      */

99     public TypeBinding resolveType(BlockScope blockScope, boolean checkBounds) {
100         return internalResolveType(blockScope);
101     }
102
103     public TypeBinding resolveType(ClassScope classScope) {
104         return internalResolveType(classScope);
105     }
106 }
107
Popular Tags