1 /*******************************************************************************
2  * Copyright (c) 2000, 2010 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-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.classfmt.ClassFileConstants;
15 import org.eclipse.jdt.internal.compiler.lookup.*;
16 
17 public class ImportReference extends ASTNode {
18 
19 	public char[][] tokens;
20 	public long[] sourcePositions; //each entry is using the code : (start<<32) + end
21 	public int declarationEnd; // doesn't include an potential trailing comment
22 	public int declarationSourceStart;
23 	public int declarationSourceEnd;
24 	public int modifiers; // 1.5 addition for static imports
25 	public Annotation[] annotations;
26 	// star end position
27 	public int trailingStarPosition;
28 
ImportReference( char[][] tokens, long[] sourcePositions, boolean onDemand, int modifiers)29 	public ImportReference(
30 			char[][] tokens,
31 			long[] sourcePositions,
32 			boolean onDemand,
33 			int modifiers) {
34 
35 		this.tokens = tokens;
36 		this.sourcePositions = sourcePositions;
37 		if (onDemand) {
38 			this.bits |= ASTNode.OnDemand;
39 		}
40 		this.sourceEnd = (int) (sourcePositions[sourcePositions.length-1] & 0x00000000FFFFFFFF);
41 		this.sourceStart = (int) (sourcePositions[0] >>> 32);
42 		this.modifiers = modifiers;
43 	}
44 
isStatic()45 	public boolean isStatic() {
46 		return (this.modifiers & ClassFileConstants.AccStatic) != 0;
47 	}
48 
49 	/**
50 	 * @return char[][]
51 	 */
getImportName()52 	public char[][] getImportName() {
53 
54 		return this.tokens;
55 	}
56 
print(int indent, StringBuffer output)57 	public StringBuffer print(int indent, StringBuffer output) {
58 
59 		return print(indent, output, true);
60 	}
61 
print(int tab, StringBuffer output, boolean withOnDemand)62 	public StringBuffer print(int tab, StringBuffer output, boolean withOnDemand) {
63 
64 		/* when withOnDemand is false, only the name is printed */
65 		for (int i = 0; i < this.tokens.length; i++) {
66 			if (i > 0) output.append('.');
67 			output.append(this.tokens[i]);
68 		}
69 		if (withOnDemand && ((this.bits & ASTNode.OnDemand) != 0)) {
70 			output.append(".*"); //$NON-NLS-1$
71 		}
72 		return output;
73 	}
74 
traverse(ASTVisitor visitor, CompilationUnitScope scope)75 	public void traverse(ASTVisitor visitor, CompilationUnitScope scope) {
76 		// annotations are traversed during the compilation unit traversal using a class scope
77 		visitor.visit(this, scope);
78 		visitor.endVisit(this, scope);
79 	}
80 }
81