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
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.batch;
14 import java.io.IOException;
16 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
17 import net.sourceforge.phpdt.internal.compiler.util.Util;
19 public class CompilationUnit implements ICompilationUnit {
20 public char[] contents;
21 public char[] fileName;
22 public char[] mainTypeName;
25 public CompilationUnit(char[] contents, String fileName, String encoding) {
26 this.contents = contents;
27 if (File.separator.equals("/")) { //$NON-NLS-1$
28 if (fileName.indexOf("\\") != -1) { //$NON-NLS-1$
29 fileName = fileName.replace('\\', File.separatorChar);
32 // the file separator is \
33 if (fileName.indexOf('/') != -1) {
34 fileName = fileName.replace('/', File.separatorChar);
37 this.fileName = fileName.toCharArray();
39 int start = fileName.lastIndexOf("/") + 1; //$NON-NLS-1$
40 if (start == 0 || start < fileName.lastIndexOf("\\")) //$NON-NLS-1$
41 start = fileName.lastIndexOf("\\") + 1; //$NON-NLS-1$
43 int end = fileName.lastIndexOf("."); //$NON-NLS-1$
45 end = fileName.length();
47 this.mainTypeName = fileName.substring(start, end).toCharArray();
48 this.encoding = encoding;
50 public char[] getContents() {
52 return contents; // answer the cached source
54 // otherwise retrieve it
56 return Util.getFileCharContent(new File(new String(fileName)), encoding);
57 } catch (IOException e) {
61 public char[] getFileName() {
64 public char[] getMainTypeName() {
67 public char[][] getPackageName() {
70 public String toString() {
71 return "CompilationUnit[" + new String(fileName) + "]"; //$NON-NLS-2$ //$NON-NLS-1$