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.flow.FlowContext;
15 import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
16 import org.eclipse.jdt.internal.compiler.lookup.*;
18 public abstract class TypeReference extends Expression {
20 public TypeReference() {
24 public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
28 // allows us to trap completion & selection nodes
29 public void aboutToResolve(Scope scope) {
30 // default implementation: do nothing
33 * Answer a base type reference (can be an array of base type).
35 public static final TypeReference baseTypeReference(int baseType, int dim) {
40 return new SingleTypeReference(VoidBinding.simpleName, 0);
42 return new SingleTypeReference(BooleanBinding.simpleName, 0);
44 return new SingleTypeReference(CharBinding.simpleName, 0);
46 return new SingleTypeReference(FloatBinding.simpleName, 0);
48 return new SingleTypeReference(DoubleBinding.simpleName, 0);
50 return new SingleTypeReference(ByteBinding.simpleName, 0);
52 return new SingleTypeReference(ShortBinding.simpleName, 0);
54 return new SingleTypeReference(IntBinding.simpleName, 0);
56 return new SingleTypeReference(LongBinding.simpleName, 0);
61 return new ArrayTypeReference(VoidBinding.simpleName, dim, 0);
63 return new ArrayTypeReference(BooleanBinding.simpleName, dim, 0);
65 return new ArrayTypeReference(CharBinding.simpleName, dim, 0);
67 return new ArrayTypeReference(FloatBinding.simpleName, dim, 0);
69 return new ArrayTypeReference(DoubleBinding.simpleName, dim, 0);
71 return new ArrayTypeReference(ByteBinding.simpleName, dim, 0);
73 return new ArrayTypeReference(ShortBinding.simpleName, dim, 0);
75 return new ArrayTypeReference(IntBinding.simpleName, dim, 0);
77 return new ArrayTypeReference(LongBinding.simpleName, dim, 0);
80 public void checkBounds(Scope scope) {
81 // only parameterized type references have bounds
83 public abstract TypeReference copyDims(int dim);
84 public int dimensions() {
89 * TODO (jerome) should merge back into #getTypeName()
91 public char [][] getParameterizedTypeName(){
94 protected abstract TypeBinding getTypeBinding(Scope scope);
98 public abstract char [][] getTypeName() ;
99 public boolean isTypeReference() {
102 public TypeBinding resolveSuperType(ClassScope scope) {
103 // assumes the implementation of resolveType(ClassScope) will call back to detect cycles
104 if (resolveType(scope) == null) return null;
106 if (this.resolvedType.isTypeVariable()) {
107 this.resolvedType = new ProblemReferenceBinding(getTypeName(), (ReferenceBinding) this.resolvedType, ProblemReasons.IllegalSuperTypeVariable);
108 reportInvalidType(scope);
111 return this.resolvedType;
114 public final TypeBinding resolveType(BlockScope blockScope) {
115 return resolveType(blockScope, true /* checkbounds if any */);
118 public TypeBinding resolveType(BlockScope blockScope, boolean checkBounds) {
119 // handle the error here
120 this.constant = NotAConstant;
121 if (this.resolvedType != null) // is a shared type reference which was already resolved
122 return this.resolvedType.isValidBinding() ? this.resolvedType : null; // already reported error
124 this.resolvedType = getTypeBinding(blockScope);
125 if (this.resolvedType == null)
126 return null; // detected cycle while resolving hierarchy
127 if (!this.resolvedType.isValidBinding()) {
128 reportInvalidType(blockScope);
131 if (isTypeUseDeprecated(this.resolvedType, blockScope))
132 reportDeprecatedType(blockScope);
133 return this.resolvedType = blockScope.convertToRawType(this.resolvedType);
135 public TypeBinding resolveType(ClassScope classScope) {
136 // handle the error here
137 this.constant = NotAConstant;
138 if (this.resolvedType != null) // is a shared type reference which was already resolved
139 return this.resolvedType.isValidBinding() ? this.resolvedType : null; // already reported error
141 this.resolvedType = getTypeBinding(classScope);
142 if (this.resolvedType == null)
143 return null; // detected cycle while resolving hierarchy
144 if (!this.resolvedType.isValidBinding()) {
145 reportInvalidType(classScope);
148 if (isTypeUseDeprecated(this.resolvedType, classScope))
149 reportDeprecatedType(classScope);
150 return this.resolvedType = classScope.convertToRawType(this.resolvedType);
153 public TypeBinding resolveTypeArgument(BlockScope blockScope, ReferenceBinding genericType, int rank) {
154 return resolveType(blockScope, true /* check bounds*/);
157 public TypeBinding resolveTypeArgument(ClassScope classScope, ReferenceBinding genericType, int rank) {
158 return resolveType(classScope);
161 protected void reportInvalidType(Scope scope) {
162 scope.problemReporter().invalidType(this, this.resolvedType);
164 protected void reportDeprecatedType(Scope scope) {
165 scope.problemReporter().deprecatedType(this.resolvedType, this);
167 public abstract void traverse(ASTVisitor visitor, ClassScope classScope);
168 public abstract void traverse(ASTVisitor visitor, BlockScope classScope);