1 11 package org.eclipse.jdt.internal.core.search.indexing; 12 13 import org.eclipse.core.resources.IProject; 14 import org.eclipse.core.resources.ResourcesPlugin; 15 import org.eclipse.core.runtime.IPath; 16 import org.eclipse.core.runtime.Path; 17 import org.eclipse.jdt.core.JavaCore; 18 import org.eclipse.jdt.core.search.SearchDocument; 19 import org.eclipse.jdt.internal.compiler.SourceElementParser; 20 import org.eclipse.jdt.internal.compiler.util.SuffixConstants; 21 import org.eclipse.jdt.internal.core.JavaModelManager; 22 import org.eclipse.jdt.internal.core.jdom.CompilationUnit; 23 import org.eclipse.jdt.internal.core.search.processing.JobManager; 24 25 38 public class SourceIndexer extends AbstractIndexer implements SuffixConstants { 39 40 public SourceIndexer(SearchDocument document) { 41 super(document); 42 } 43 public void indexDocument() { 44 SourceIndexerRequestor requestor = new SourceIndexerRequestor(this); 46 String documentPath = this.document.getPath(); 47 SourceElementParser parser = ((InternalSearchDocument) this.document).parser; 48 if (parser == null) { 49 IPath path = new Path(documentPath); 50 IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)); 51 parser = JavaModelManager.getJavaModelManager().indexManager.getSourceElementParser(JavaCore.create(project), requestor); 52 } else { 53 parser.requestor = requestor; 54 } 55 56 char[] source = null; 58 char[] name = null; 59 try { 60 source = document.getCharContents(); 61 name = documentPath.toCharArray(); 62 } catch(Exception e){ 63 } 65 if (source == null || name == null) return; CompilationUnit compilationUnit = new CompilationUnit(source, name); 67 try { 68 parser.parseCompilationUnit(compilationUnit, true); 69 } catch (Exception e) { 70 if (JobManager.VERBOSE) { 71 e.printStackTrace(); 72 } 73 } 74 } 75 } 76 | Popular Tags |