4f45ff49f2824888ea0d5e76a29fc032cbb711ca
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / 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.phpeclipse.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 : (start<<32) + end
20   public boolean onDemand = true; //most of the time
21
22   public final char[] includeSource;
23
24   public int declarationEnd;// doesn't include an potential trailing comment
25
26   public int declarationSourceStart;
27
28   public int declarationSourceEnd;
29
30   public boolean used;
31
32   private IFile fFile;
33
34   public ImportReference(char[][] sources, char[] sourceString, int start, int end, boolean d) { // char[][] sources , long[] poss ,
35                                                                                                  // boolean d) {
36     tokens = sources;
37     //  sourcePositions = poss ;
38     includeSource = sourceString;
39     onDemand = d;
40     sourceEnd = end;//(int)(sourcePositions[sourcePositions.length-1] & 0x00000000FFFFFFFF);
41     sourceStart = start;//(int)(sourcePositions[0]>>>32) ;
42     fFile = null;
43   }
44
45   /**
46    * @return char[][]
47    */
48   public char[][] getImportName() {
49     return tokens;
50   }
51
52   public char[] getIncludeName() {
53     return includeSource;
54   }
55
56   public StringBuffer print(int indent, StringBuffer output) {
57
58     return print(indent, output, true);
59   }
60
61   public StringBuffer print(int tab, StringBuffer output, boolean withOnDemand) {
62
63     /* when withOnDemand is false, only the name is printed */
64     for (int i = 0; i < tokens.length; i++) {
65       if (i > 0)
66         output.append('.');
67       output.append(tokens[i]);
68     }
69     if (withOnDemand && onDemand) {
70       output.append(".*"); //$NON-NLS-1$
71     }
72     return output;
73   }
74
75   public String toString(int tab) {
76
77     return toString(tab, true);
78   }
79
80   public String toString(int tab, boolean withOnDemand) {
81     /* when withOnDemand is false, only the name is printed */
82     StringBuffer buffer = new StringBuffer();
83     for (int i = 0; i < tokens.length; i++) {
84       buffer.append(tokens[i]);
85       if (i < (tokens.length - 1)) {
86         buffer.append("."); //$NON-NLS-1$
87       }
88     }
89     if (withOnDemand && onDemand) {
90       buffer.append(".*"); //$NON-NLS-1$
91     }
92     buffer.append(" - ");
93     buffer.append(includeSource);
94     return buffer.toString();
95     //    return new String(includeSource);
96   }
97
98   public void traverse(ASTVisitor visitor, CompilationUnitScope scope) {
99     visitor.visit(this, scope);
100     visitor.endVisit(this, scope);
101   }
102
103   /**
104    * @return Returns the filePath.
105    */
106   public IFile getFile() {
107     return fFile;
108   }
109
110   /**
111    * @param filePath
112    *          The filePath to set.
113    */
114   public void setFile(IFile filePath) {
115     fFile = filePath;
116   }
117 }