deleted: export="true"
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / BasicCompilationUnit.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
12
13 import java.io.File;
14 import java.io.IOException;
15
16 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
17 import net.sourceforge.phpdt.internal.compiler.util.Util;
18
19 /**
20  * A basic implementation of <code>ICompilationUnit</code>
21  * for use in the <code>SourceMapper</code>.
22  * @see ICompilationUnit
23  */
24 public class BasicCompilationUnit implements ICompilationUnit {
25         protected char[] contents;
26         protected char[] fileName;
27         protected char[][] packageName;
28         protected char[] mainTypeName;
29         protected String encoding;
30         
31 public BasicCompilationUnit(char[] contents, char[][] packageName, String fileName, String encoding) {
32         this.contents = contents;
33         this.fileName = fileName.toCharArray();
34         this.packageName = packageName;
35
36         int start = fileName.lastIndexOf("/") + 1; //$NON-NLS-1$
37         if (start == 0 || start < fileName.lastIndexOf("\\")) //$NON-NLS-1$
38                 start = fileName.lastIndexOf("\\") + 1; //$NON-NLS-1$
39
40         int end = fileName.lastIndexOf("."); //$NON-NLS-1$
41         if (end == -1)
42                 end = fileName.length();
43
44         this.mainTypeName = fileName.substring(start, end).toCharArray();
45         this.encoding = encoding;
46 }
47 public char[] getContents() {
48         if (this.contents != null)
49                 return this.contents;   // answer the cached source
50
51         // otherwise retrieve it
52         try {
53                 return Util.getFileCharContent(new File(new String(fileName)), this.encoding);
54         } catch (IOException e) {
55         }
56         return new char[0];
57 }
58 public char[] getFileName() {
59         return this.fileName;
60 }
61 public char[] getMainTypeName() {
62         return this.mainTypeName;
63 }
64 public char[][] getPackageName() {
65         return this.packageName;
66 }
67 public String toString(){
68         return "CompilationUnit: "+new String(fileName); //$NON-NLS-1$
69 }
70 }