added -J option to preserve unmodified files in preexisting jarfile
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / ast / ArrayQualifiedTypeReference.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.core.compiler.CharOperation;
14 import org.eclipse.jdt.internal.compiler.ASTVisitor;
15 import org.eclipse.jdt.internal.compiler.lookup.*;
16 import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
17
18 public class ArrayQualifiedTypeReference extends QualifiedTypeReference {
19         int dimensions;
20         
21         public ArrayQualifiedTypeReference(char[][] sources , int dim, long[] poss) {
22                 
23                 super( sources , poss);
24                 dimensions = dim ;
25         }
26         
27         public int dimensions() {
28                 
29                 return dimensions;
30         }
31
32         /**
33          * @return char[][]
34          */
35         public char [][] getParameterizedTypeName(){
36                 int dim = this.dimensions;
37                 char[] dimChars = new char[dim*2];
38                 for (int i = 0; i < dim; i++) {
39                         int index = i*2;
40                         dimChars[index] = '[';
41                         dimChars[index+1] = ']';
42                 }
43                 int length = this.tokens.length;
44                 char[][] qParamName = new char[length][];
45                 System.arraycopy(this.tokens, 0, qParamName, 0, length-1);
46                 qParamName[length-1] = CharOperation.concat(this.tokens[length-1], dimChars);
47                 return qParamName;
48         }       
49         
50         protected TypeBinding getTypeBinding(Scope scope) {
51                 
52                 if (this.resolvedType != null)
53                         return this.resolvedType;
54                 if (dimensions > 255) {
55                         scope.problemReporter().tooManyDimensions(this);
56                 }
57                 try {
58                         TypeBinding leafComponentType = scope.getType(this.tokens, this.tokens.length);
59                         return scope.createArrayType(leafComponentType, dimensions);
60                 } catch (AbortCompilation e) {
61                         e.updateContext(this, scope.referenceCompilationUnit().compilationResult);
62                         throw e;
63                 }
64         }
65         
66         public StringBuffer printExpression(int indent, StringBuffer output){
67                 
68                 super.printExpression(indent, output);
69                 if ((this.bits & IsVarArgs) != 0) {
70                         for (int i= 0 ; i < dimensions - 1; i++) {
71                                 output.append("[]"); //$NON-NLS-1$
72                         }
73                         output.append("..."); //$NON-NLS-1$
74                 } else {
75                         for (int i= 0 ; i < dimensions; i++) {
76                                 output.append("[]"); //$NON-NLS-1$
77                         }
78                 }
79                 return output;
80         }
81         
82         public void traverse(ASTVisitor visitor, BlockScope scope) {
83                 
84                 visitor.visit(this, scope);
85                 visitor.endVisit(this, scope);
86         }
87         
88         public void traverse(ASTVisitor visitor, ClassScope scope) {
89                 
90                 visitor.visit(this, scope);
91                 visitor.endVisit(this, scope);
92         }
93 }