added -J option to preserve unmodified files in preexisting jarfile
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / ast / ImportReference.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
16 public class ImportReference extends ASTNode {
17
18         public char[][] tokens;
19         public long[] sourcePositions; //each entry is using the code : (start<<32) + end
20         public boolean onDemand = true; //most of the time
21         public int declarationEnd; // doesn't include an potential trailing comment
22         public int declarationSourceStart;
23         public int declarationSourceEnd;
24         public boolean used;
25         public int modifiers; // 1.5 addition for static imports
26         public Annotation[] annotations;
27
28         public ImportReference(
29                         char[][] tokens,
30                         long[] sourcePositions,
31                         boolean onDemand,
32                         int modifiers) {
33
34                 this.tokens = tokens;
35                 this.sourcePositions = sourcePositions;
36                 this.onDemand = onDemand;
37                 this.sourceEnd = (int) (sourcePositions[sourcePositions.length-1] & 0x00000000FFFFFFFF);
38                 this.sourceStart = (int) (sourcePositions[0] >>> 32);
39                 this.modifiers = modifiers;
40         }
41         
42         public boolean isStatic() {
43                 return (this.modifiers & AccStatic) != 0;
44         }
45
46         /**
47          * @return char[][]
48          */
49         public char[][] getImportName() {
50
51                 return tokens;
52         }
53
54         public StringBuffer print(int indent, StringBuffer output) {
55
56                 return print(indent, output, true);
57         }
58
59         public StringBuffer print(int tab, StringBuffer output, boolean withOnDemand) {
60
61                 /* when withOnDemand is false, only the name is printed */
62                 for (int i = 0; i < tokens.length; i++) {
63                         if (i > 0) output.append('.');
64                         output.append(tokens[i]);
65                 }
66                 if (withOnDemand && onDemand) {
67                         output.append(".*"); //$NON-NLS-1$
68                 }
69                 return output;
70         }
71
72         public void traverse(ASTVisitor visitor, CompilationUnitScope scope) {
73
74                 visitor.visit(this, scope);
75                 if (this.annotations != null) {
76                         int annotationsLength = this.annotations.length;
77                         for (int i = 0; i < annotationsLength; i++)
78                                 this.annotations[i].traverse(visitor, scope);
79                 }
80                 visitor.endVisit(this, scope);
81         }
82 }