Organized imports
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / jdom / CompilationUnit.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 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 net.sourceforge.phpdt.internal.core.jdom;
12
13 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
14
15 import org.eclipse.core.resources.IResource;
16
17 /**
18  * Implements a very simple version of the ICompilationUnit.
19  * 
20  * <p>
21  * Please do not use outside of jdom.
22  * </p>
23  */
24 public class CompilationUnit implements ICompilationUnit {
25   protected char[] fContents;
26
27   protected char[] fFileName;
28
29   protected char[] fMainTypeName;
30
31   public CompilationUnit(char[] contents, char[] filename) {
32     fContents = contents;
33     fFileName = filename;
34
35     String file = new String(filename);
36     int start = file.lastIndexOf("/") + 1; //$NON-NLS-1$
37     if (start == 0 || start < file.lastIndexOf("\\")) //$NON-NLS-1$
38       start = file.lastIndexOf("\\") + 1; //$NON-NLS-1$
39
40     int end = file.lastIndexOf("."); //$NON-NLS-1$
41     if (end == -1)
42       end = file.length();
43
44     fMainTypeName = file.substring(start, end).toCharArray();
45   }
46
47   public char[] getContents() {
48     return fContents;
49   }
50
51   public char[] getFileName() {
52     return fFileName;
53   }
54
55   public char[] getMainTypeName() {
56     return fMainTypeName;
57   }
58
59   public char[][] getPackageName() {
60     return null;
61   }
62
63   public String toString() {
64     return "CompilationUnit[" + new String(fFileName) + "]"; //$NON-NLS-2$ //$NON-NLS-1$
65   }
66
67   /*
68    * (non-Javadoc)
69    * 
70    * @see net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit#getResource()
71    */
72   public IResource getResource() {
73     return null;
74   }
75 }