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.lookup.*;
15 import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
17 public class QualifiedTypeReference extends TypeReference {
19 public char[][] tokens;
20 public long[] sourcePositions;
22 public QualifiedTypeReference(char[][] sources , long[] poss) {
25 sourcePositions = poss ;
26 sourceStart = (int) (sourcePositions[0]>>>32) ;
27 sourceEnd = (int)(sourcePositions[sourcePositions.length-1] & 0x00000000FFFFFFFFL ) ;
30 public TypeReference copyDims(int dim){
31 //return a type reference copy of me with some dimensions
32 //warning : the new type ref has a null binding
33 return new ArrayQualifiedTypeReference(tokens, dim, sourcePositions);
36 protected TypeBinding findNextTypeBinding(int tokenIndex, Scope scope, PackageBinding packageBinding) {
38 if (this.resolvedType == null) {
39 this.resolvedType = scope.getType(this.tokens[tokenIndex], packageBinding);
41 this.resolvedType = scope.getMemberType(this.tokens[tokenIndex], (ReferenceBinding) this.resolvedType);
42 if (this.resolvedType instanceof ProblemReferenceBinding) {
43 ProblemReferenceBinding problemBinding = (ProblemReferenceBinding) this.resolvedType;
44 this.resolvedType = new ProblemReferenceBinding(
45 org.eclipse.jdt.core.compiler.CharOperation.subarray(this.tokens, 0, tokenIndex + 1),
46 problemBinding.original,
47 this.resolvedType.problemId());
50 return this.resolvedType;
51 } catch (AbortCompilation e) {
52 e.updateContext(this, scope.referenceCompilationUnit().compilationResult);
57 protected TypeBinding getTypeBinding(Scope scope) {
59 if (this.resolvedType != null)
60 return this.resolvedType;
62 Binding binding = scope.getPackage(this.tokens);
63 if (binding != null && !binding.isValidBinding())
64 return (ReferenceBinding) binding; // not found
66 PackageBinding packageBinding = binding == null ? null : (PackageBinding) binding;
67 boolean isClassScope = scope.kind == Scope.CLASS_SCOPE;
68 ReferenceBinding qualifiedType = null;
69 for (int i = packageBinding == null ? 0 : packageBinding.compoundName.length, max = this.tokens.length; i < max; i++) {
70 findNextTypeBinding(i, scope, packageBinding);
71 if (!this.resolvedType.isValidBinding())
72 return this.resolvedType;
75 if (((ClassScope) scope).detectHierarchyCycle(this.resolvedType, this, null)) // must connect hierarchy to find inherited member types
77 ReferenceBinding currentType = (ReferenceBinding) this.resolvedType;
78 if (currentType.isGenericType()) {
79 qualifiedType = scope.environment().createRawType(currentType, qualifiedType);
81 qualifiedType = (qualifiedType != null && (qualifiedType.isRawType() || qualifiedType.isParameterizedType()))
82 ? scope.createParameterizedType((ReferenceBinding)currentType.erasure(), null, qualifiedType)
86 this.resolvedType = qualifiedType;
87 return this.resolvedType;
90 public char[][] getTypeName(){
95 public StringBuffer printExpression(int indent, StringBuffer output) {
97 for (int i = 0; i < tokens.length; i++) {
98 if (i > 0) output.append('.');
99 output.append(tokens[i]);
104 public void traverse(ASTVisitor visitor, BlockScope scope) {
106 visitor.visit(this, scope);
107 visitor.endVisit(this, scope);
110 public void traverse(ASTVisitor visitor, ClassScope scope) {
112 visitor.visit(this, scope);
113 visitor.endVisit(this, scope);