1 11 package org.eclipse.jdt.internal.compiler.batch; 12 13 import java.io.File ; 14 import java.io.IOException ; 15 16 import org.eclipse.jdt.core.compiler.CharOperation; 17 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; 18 import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit; 19 import org.eclipse.jdt.internal.compiler.util.Util; 20 21 public class CompilationUnit implements ICompilationUnit { 22 public char[] contents; 23 public char[] fileName; 24 public char[] mainTypeName; 25 String encoding; 26 public String destinationPath; 27 35 public CompilationUnit(char[] contents, String fileName, String encoding) { 36 this(contents, fileName, encoding, null); 37 } 38 public CompilationUnit(char[] contents, String fileName, String encoding, 39 String destinationPath) { 40 this.contents = contents; 41 char[] fileNameCharArray = fileName.toCharArray(); 42 switch(File.separatorChar) { 43 case '/' : 44 if (CharOperation.indexOf('\\', fileNameCharArray) != -1) { 45 CharOperation.replace(fileNameCharArray, '\\', '/'); 46 } 47 break; 48 case '\\' : 49 if (CharOperation.indexOf('/', fileNameCharArray) != -1) { 50 CharOperation.replace(fileNameCharArray, '/', '\\'); 51 } 52 } 53 this.fileName = fileNameCharArray; 54 int start = CharOperation.lastIndexOf(File.separatorChar, fileNameCharArray) + 1; 55 56 int end = CharOperation.lastIndexOf('.', fileNameCharArray); 57 if (end == -1) { 58 end = fileNameCharArray.length; 59 } 60 61 this.mainTypeName = CharOperation.subarray(fileNameCharArray, start, end); 62 this.encoding = encoding; 63 this.destinationPath = destinationPath; 64 } 65 public char[] getContents() { 66 if (this.contents != null) 67 return this.contents; 69 try { 71 return Util.getFileCharContent(new File (new String (this.fileName)), this.encoding); 72 } catch (IOException e) { 73 this.contents = CharOperation.NO_CHAR; throw new AbortCompilationUnit(null, e, this.encoding); 75 } 76 } 77 80 public char[] getFileName() { 81 return this.fileName; 82 } 83 public char[] getMainTypeName() { 84 return this.mainTypeName; 85 } 86 public char[][] getPackageName() { 87 return null; 88 } 89 public String toString() { 90 return "CompilationUnit[" + new String (this.fileName) + "]"; } 92 } 93 | Popular Tags |