001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 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.core.compiler.CharOperation;
013: import org.eclipse.jdt.internal.compiler.ASTVisitor;
014: import org.eclipse.jdt.internal.compiler.lookup.*;
015: import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
016:
017: public class ArrayQualifiedTypeReference extends QualifiedTypeReference {
018: int dimensions;
019:
020: public ArrayQualifiedTypeReference(char[][] sources, int dim,
021: long[] poss) {
022:
023: super (sources, poss);
024: dimensions = dim;
025: }
026:
027: public int dimensions() {
028:
029: return dimensions;
030: }
031:
032: /**
033: * @return char[][]
034: */
035: public char[][] getParameterizedTypeName() {
036: int dim = this .dimensions;
037: char[] dimChars = new char[dim * 2];
038: for (int i = 0; i < dim; i++) {
039: int index = i * 2;
040: dimChars[index] = '[';
041: dimChars[index + 1] = ']';
042: }
043: int length = this .tokens.length;
044: char[][] qParamName = new char[length][];
045: System.arraycopy(this .tokens, 0, qParamName, 0, length - 1);
046: qParamName[length - 1] = CharOperation.concat(
047: this .tokens[length - 1], dimChars);
048: return qParamName;
049: }
050:
051: protected TypeBinding getTypeBinding(Scope scope) {
052:
053: if (this .resolvedType != null)
054: return this .resolvedType;
055: if (this .dimensions > 255) {
056: scope.problemReporter().tooManyDimensions(this );
057: }
058: LookupEnvironment env = scope.environment();
059: try {
060: env.missingClassFileLocation = this ;
061: TypeBinding leafComponentType = super .getTypeBinding(scope);
062: return this .resolvedType = scope.createArrayType(
063: leafComponentType, dimensions);
064: } catch (AbortCompilation e) {
065: e.updateContext(this ,
066: scope.referenceCompilationUnit().compilationResult);
067: throw e;
068: } finally {
069: env.missingClassFileLocation = null;
070: }
071: }
072:
073: public StringBuffer printExpression(int indent, StringBuffer output) {
074:
075: super .printExpression(indent, output);
076: if ((this .bits & IsVarArgs) != 0) {
077: for (int i = 0; i < dimensions - 1; i++) {
078: output.append("[]"); //$NON-NLS-1$
079: }
080: output.append("..."); //$NON-NLS-1$
081: } else {
082: for (int i = 0; i < dimensions; i++) {
083: output.append("[]"); //$NON-NLS-1$
084: }
085: }
086: return output;
087: }
088:
089: public void traverse(ASTVisitor visitor, BlockScope scope) {
090:
091: visitor.visit(this , scope);
092: visitor.endVisit(this , scope);
093: }
094:
095: public void traverse(ASTVisitor visitor, ClassScope scope) {
096:
097: visitor.visit(this, scope);
098: visitor.endVisit(this, scope);
099: }
100: }
|