KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > jdom > CompilationUnit


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core.jdom;
12
13 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
14
15 /**
16  * Implements a very simple version of the ICompilationUnit.
17  *
18  * <p>Please do not use outside of jdom.</p>
19  */

20 public class CompilationUnit implements ICompilationUnit {
21     protected char[] fContents;
22     protected char[] fFileName;
23     protected char[] fMainTypeName;
24 public CompilationUnit(char[] contents, char[] filename) {
25     fContents = contents;
26     fFileName = filename;
27
28     String JavaDoc file = new String JavaDoc(filename);
29     int start = file.lastIndexOf("/") + 1; //$NON-NLS-1$
30
if (start == 0 || start < file.lastIndexOf("\\")) //$NON-NLS-1$
31
start = file.lastIndexOf("\\") + 1; //$NON-NLS-1$
32

33     int end = file.lastIndexOf("."); //$NON-NLS-1$
34
if (end == -1)
35         end = file.length();
36
37     fMainTypeName = file.substring(start, end).toCharArray();
38 }
39 public char[] getContents() {
40     return fContents;
41 }
42 /**
43  * @see org.eclipse.jdt.internal.compiler.env.IDependent#getFileName()
44  */

45 public char[] getFileName() {
46     return fFileName;
47 }
48 public char[] getMainTypeName() {
49     return fMainTypeName;
50 }
51 public char[][] getPackageName() {
52     return null;
53 }
54 public String JavaDoc toString() {
55     return "CompilationUnit[" + new String JavaDoc(fFileName) + "]"; //$NON-NLS-2$ //$NON-NLS-1$
56
}
57 }
58
Popular Tags