added -J option to preserve unmodified files in preexisting jarfile
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / ast / QualifiedTypeReference.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 import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
16
17 public class QualifiedTypeReference extends TypeReference {
18
19         public char[][] tokens;
20         public long[] sourcePositions;
21
22         public QualifiedTypeReference(char[][] sources , long[] poss) {
23                 
24                 tokens = sources ;
25                 sourcePositions = poss ;
26                 sourceStart = (int) (sourcePositions[0]>>>32) ;
27                 sourceEnd = (int)(sourcePositions[sourcePositions.length-1] & 0x00000000FFFFFFFFL ) ;
28         }
29                 
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);
34         }
35
36         protected TypeBinding findNextTypeBinding(int tokenIndex, Scope scope, PackageBinding packageBinding) {
37                 try {
38                     if (this.resolvedType == null) {
39                                 this.resolvedType = scope.getType(this.tokens[tokenIndex], packageBinding);
40                     } else {
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());
48                                 }
49                         }
50                     return this.resolvedType;
51                 } catch (AbortCompilation e) {
52                         e.updateContext(this, scope.referenceCompilationUnit().compilationResult);
53                         throw e;
54                 }
55         }
56
57         protected TypeBinding getTypeBinding(Scope scope) {
58                 
59                 if (this.resolvedType != null)
60                         return this.resolvedType;
61
62                 Binding binding = scope.getPackage(this.tokens);
63                 if (binding != null && !binding.isValidBinding())
64                         return (ReferenceBinding) binding; // not found
65
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;
73                         
74                         if (isClassScope)
75                                 if (((ClassScope) scope).detectHierarchyCycle(this.resolvedType, this, null)) // must connect hierarchy to find inherited member types
76                                         return null;
77                         ReferenceBinding currentType = (ReferenceBinding) this.resolvedType;
78                         if (currentType.isGenericType()) {
79                                 qualifiedType = scope.environment().createRawType(currentType, qualifiedType);
80                         } else {
81                                 qualifiedType = (qualifiedType != null && (qualifiedType.isRawType() || qualifiedType.isParameterizedType()))
82                                                                                 ? scope.createParameterizedType((ReferenceBinding)currentType.erasure(), null, qualifiedType)
83                                                                                 : currentType;
84                         }
85                 }
86                 this.resolvedType = qualifiedType;
87                 return this.resolvedType;
88         }
89         
90         public char[][] getTypeName(){
91         
92                 return tokens;
93         }
94         
95         public StringBuffer printExpression(int indent, StringBuffer output) {
96                 
97                 for (int i = 0; i < tokens.length; i++) {
98                         if (i > 0) output.append('.');
99                         output.append(tokens[i]);
100                 }
101                 return output;
102         }
103         
104         public void traverse(ASTVisitor visitor, BlockScope scope) {
105                 
106                 visitor.visit(this, scope);
107                 visitor.endVisit(this, scope);
108         }
109         
110         public void traverse(ASTVisitor visitor, ClassScope scope) {
111                 
112                 visitor.visit(this, scope);
113                 visitor.endVisit(this, scope);
114         }
115 }