A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / ImportReference.java
1 /***********************************************************************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made
3  * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4  * http://www.eclipse.org/legal/cpl-v10.html
5  * 
6  * Contributors: IBM Corporation - initial API and implementation
7  **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.ast;
9
10 import net.sourceforge.phpdt.internal.compiler.ASTVisitor;
11 import net.sourceforge.phpdt.internal.compiler.lookup.CompilationUnitScope;
12
13 import org.eclipse.core.resources.IFile;
14
15 public class ImportReference extends ASTNode {
16
17         public char[][] tokens;
18
19         // public long[] sourcePositions; //each entry is using the code :
20         // (start<<32) + end
21         public boolean onDemand = true; // most of the time
22
23         public final char[] includeSource;
24
25         public int declarationEnd;// doesn't include an potential trailing comment
26
27         public int declarationSourceStart;
28
29         public int declarationSourceEnd;
30
31         public boolean used;
32
33         private IFile fFile;
34
35         public ImportReference(char[][] sources, char[] sourceString, int start,
36                         int end, boolean d) { // char[][] sources , long[] poss ,
37                 // boolean d) {
38                 tokens = sources;
39                 // sourcePositions = poss ;
40                 includeSource = sourceString;
41                 onDemand = d;
42                 sourceEnd = end;// (int)(sourcePositions[sourcePositions.length-1] &
43                                                 // 0x00000000FFFFFFFF);
44                 sourceStart = start;// (int)(sourcePositions[0]>>>32) ;
45                 fFile = null;
46         }
47
48         /**
49          * @return char[][]
50          */
51         public char[][] getImportName() {
52                 return tokens;
53         }
54
55         public char[] getIncludeName() {
56                 return includeSource;
57         }
58
59         public StringBuffer print(int indent, StringBuffer output) {
60
61                 return print(indent, output, true);
62         }
63
64         public StringBuffer print(int tab, StringBuffer output, boolean withOnDemand) {
65
66                 /* when withOnDemand is false, only the name is printed */
67                 for (int i = 0; i < tokens.length; i++) {
68                         if (i > 0)
69                                 output.append('.');
70                         output.append(tokens[i]);
71                 }
72                 if (withOnDemand && onDemand) {
73                         output.append(".*"); //$NON-NLS-1$
74                 }
75                 return output;
76         }
77
78         public String toString(int tab) {
79
80                 return toString(tab, true);
81         }
82
83         public String toString(int tab, boolean withOnDemand) {
84                 /* when withOnDemand is false, only the name is printed */
85                 StringBuffer buffer = new StringBuffer();
86                 for (int i = 0; i < tokens.length; i++) {
87                         buffer.append(tokens[i]);
88                         if (i < (tokens.length - 1)) {
89                                 buffer.append("."); //$NON-NLS-1$
90                         }
91                 }
92                 if (withOnDemand && onDemand) {
93                         buffer.append(".*"); //$NON-NLS-1$
94                 }
95                 buffer.append(" - ");
96                 buffer.append(includeSource);
97                 return buffer.toString();
98                 // return new String(includeSource);
99         }
100
101         public void traverse(ASTVisitor visitor, CompilationUnitScope scope) {
102                 visitor.visit(this, scope);
103                 visitor.endVisit(this, scope);
104         }
105
106         /**
107          * @return Returns the filePath.
108          */
109         public IFile getFile() {
110                 return fFile;
111         }
112
113         /**
114          * @param filePath
115          *            The filePath to set.
116          */
117         public void setFile(IFile filePath) {
118                 fFile = filePath;
119         }
120 }