1 11 package org.eclipse.jdt.internal.core.search; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.core.resources.ResourcesPlugin; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IPath; 17 import org.eclipse.core.runtime.Path; 18 import org.eclipse.jdt.core.JavaModelException; 19 import org.eclipse.jdt.core.search.IJavaSearchScope; 20 import org.eclipse.jdt.core.search.SearchDocument; 21 import org.eclipse.jdt.core.search.SearchParticipant; 22 import org.eclipse.jdt.internal.core.search.processing.JobManager; 23 import org.eclipse.jdt.internal.core.util.Util; 24 25 public class JavaSearchDocument extends SearchDocument { 26 27 private IFile file; 28 protected byte[] byteContents; 29 protected char[] charContents; 30 31 public JavaSearchDocument(String documentPath, SearchParticipant participant) { 32 super(documentPath, participant); 33 } 34 public JavaSearchDocument(java.util.zip.ZipEntry zipEntry, IPath zipFilePath, byte[] contents, SearchParticipant participant) { 35 super(zipFilePath + IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR + zipEntry.getName(), participant); 36 this.byteContents = contents; 37 } 38 39 public byte[] getByteContents() { 40 if (this.byteContents != null) return this.byteContents; 41 try { 42 return Util.getResourceContentsAsByteArray(getFile()); 43 } catch (JavaModelException e) { 44 if (BasicSearchEngine.VERBOSE || JobManager.VERBOSE) { e.printStackTrace(); 46 } 47 return null; 48 } 49 } 50 public char[] getCharContents() { 51 if (this.charContents != null) return this.charContents; 52 try { 53 return Util.getResourceContentsAsCharArray(getFile()); 54 } catch (JavaModelException e) { 55 if (BasicSearchEngine.VERBOSE || JobManager.VERBOSE) { e.printStackTrace(); 57 } 58 return null; 59 } 60 } 61 public String getEncoding() { 62 IFile resource = getFile(); 64 if (resource != null) { 65 try { 66 return resource.getCharset(); 67 } 68 catch(CoreException ce) { 69 try { 70 return ResourcesPlugin.getWorkspace().getRoot().getDefaultCharset(); 71 } catch (CoreException e) { 72 } 74 } 75 } 76 return null; 77 } 78 private IFile getFile() { 79 if (this.file == null) 80 this.file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(getPath())); 81 return this.file; 82 } 83 public String toString() { 84 return "SearchDocument for " + getPath(); } 86 } 87 | Popular Tags |