1 19 20 package org.netbeans.modules.retouche.source.usages; 21 22 import java.io.IOException ; 23 import java.io.PrintWriter ; 24 import java.util.HashMap ; 25 import java.util.HashSet ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.Set ; 29 import org.netbeans.api.gsf.Indexer; 30 import org.netbeans.api.gsf.ParserFile; 31 import org.netbeans.api.gsf.ParserResult; 32 import org.netbeans.api.retouche.source.ParserTaskImpl; 33 import org.netbeans.api.retouche.source.ParserTaskImpl; 34 import org.netbeans.modules.gsf.Language; 35 import org.netbeans.modules.gsf.LanguageRegistry; 36 import org.openide.filesystems.FileObject; 37 38 47 public class SourceAnalyser { 48 49 private final Index index; 50 private final Map <String , List <String >> references; 51 private final Set <String > toDelete; 52 53 54 public SourceAnalyser (final Index index) { 55 assert index != null; 56 this.index = index; 57 this.references = new HashMap <String , List <String >> (); 58 this.toDelete = new HashSet <String > (); 59 } 60 61 public final boolean isUpToDate(String resourceName, long resourceMTime) throws IOException { 62 return this.index.isUpToDate(resourceName, resourceMTime); 63 } 64 65 public void store () throws IOException { 66 } 67 68 public boolean isValid () throws IOException { 69 return this.index.isValid(true); 70 } 71 72 public void analyse (final Iterable <ParserResult> data, ParserTaskImpl jt, ParserFile sibling) throws IOException { 73 for (ParserResult result : data) { 79 FileObject fo = result.getFile().getFileObject(); 80 Language language = LanguageRegistry.getInstance().getLanguageByMimeType(fo.getMIMEType()); 81 if (language != null) { 82 Indexer indexer = language.getIndexer(); 83 if (indexer != null) { 84 indexer.updateIndex(index, result); 85 } 86 87 } 88 } 89 } 90 91 void analyseUnitAndStore (ParserResult result, final ParserTaskImpl jt) throws IOException { 92 FileObject fo = result.getFile().getFileObject(); 93 Language language = LanguageRegistry.getInstance().getLanguageByMimeType(fo.getMIMEType()); 94 if (language != null) { 95 Indexer indexer = language.getIndexer(); 96 if (indexer != null) { 97 indexer.updateIndex(index, result); 98 } 99 } 100 } 101 102 public void delete (final String className) throws IOException { 103 if (!this.index.isValid(false)) { 104 return; 105 } 106 this.toDelete.add(className); 107 } 108 } 109 | Popular Tags |