001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.compiler.ast;
011:
012: import org.eclipse.jdt.internal.compiler.ASTVisitor;
013: import org.eclipse.jdt.internal.compiler.impl.Constant;
014: import org.eclipse.jdt.internal.compiler.lookup.Binding;
015: import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
016: import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
017: import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
018: import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
019: import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
020: import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
021: import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
022: import org.eclipse.jdt.internal.compiler.lookup.Scope;
023: import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
024:
025: public class JavadocSingleTypeReference extends SingleTypeReference {
026:
027: public int tagSourceStart, tagSourceEnd;
028: public PackageBinding packageBinding;
029:
030: public JavadocSingleTypeReference(char[] source, long pos,
031: int tagStart, int tagEnd) {
032: super (source, pos);
033: this .tagSourceStart = tagStart;
034: this .tagSourceEnd = tagEnd;
035: this .bits |= ASTNode.InsideJavadoc;
036: }
037:
038: protected void reportInvalidType(Scope scope) {
039: scope.problemReporter().javadocInvalidType(this ,
040: this .resolvedType, scope.getDeclarationModifiers());
041: }
042:
043: protected void reportDeprecatedType(TypeBinding type, Scope scope) {
044: scope.problemReporter().javadocDeprecatedType(type, this ,
045: scope.getDeclarationModifiers());
046: }
047:
048: /* (non-Javadoc)
049: * Redefine to capture javadoc specific signatures
050: * @see org.eclipse.jdt.internal.compiler.ast.ASTNode#traverse(org.eclipse.jdt.internal.compiler.ASTVisitor, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
051: */
052: public void traverse(ASTVisitor visitor, BlockScope scope) {
053: visitor.visit(this , scope);
054: visitor.endVisit(this , scope);
055: }
056:
057: public void traverse(ASTVisitor visitor, ClassScope scope) {
058: visitor.visit(this , scope);
059: visitor.endVisit(this , scope);
060: }
061:
062: /*
063: * We need to modify resolving behavior to handle package references
064: */
065: TypeBinding internalResolveType(Scope scope) {
066: // handle the error here
067: this .constant = Constant.NotAConstant;
068: if (this .resolvedType != null)// is a shared type reference which was already resolved
069: return this .resolvedType.isValidBinding() ? this .resolvedType
070: : null; // already reported error
071:
072: this .resolvedType = getTypeBinding(scope);
073: if (!this .resolvedType.isValidBinding()) {
074: char[][] tokens = { this .token };
075: Binding binding = scope.getTypeOrPackage(tokens);
076: if (binding instanceof PackageBinding) {
077: this .packageBinding = (PackageBinding) binding;
078: } else {
079: if (this .resolvedType.problemId() == ProblemReasons.NonStaticReferenceInStaticContext) {
080: ReferenceBinding closestMatch = ((ProblemReferenceBinding) this .resolvedType)
081: .closestMatch();
082: if (closestMatch != null
083: && closestMatch.isTypeVariable()) {
084: this .resolvedType = closestMatch; // ignore problem as we want report specific javadoc one instead
085: return this .resolvedType;
086: }
087: }
088: reportInvalidType(scope);
089: }
090: return null;
091: }
092: if (isTypeUseDeprecated(this .resolvedType, scope))
093: reportDeprecatedType(this .resolvedType, scope);
094: if (this .resolvedType instanceof ParameterizedTypeBinding) {
095: this .resolvedType = ((ParameterizedTypeBinding) this .resolvedType)
096: .genericType();
097: }
098: return this .resolvedType;
099: }
100:
101: /* (non-Javadoc)
102: * @see org.eclipse.jdt.internal.compiler.ast.Expression#resolveType(org.eclipse.jdt.internal.compiler.lookup.BlockScope)
103: * We need to override to handle package references
104: */
105: public TypeBinding resolveType(BlockScope blockScope,
106: boolean checkBounds) {
107: return internalResolveType(blockScope);
108: }
109:
110: public TypeBinding resolveType(ClassScope classScope) {
111: return internalResolveType(classScope);
112: }
113: }
|