1 19 package org.netbeans.modules.java.hints.infrastructure; 20 21 import com.sun.source.tree.Tree.Kind; 22 import com.sun.source.util.TreePath; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import java.util.Map ; 26 import org.netbeans.api.java.source.CompilationInfo; 27 import org.netbeans.api.java.source.support.CaretAwareJavaSourceTaskFactory; 28 import org.netbeans.modules.java.editor.semantic.ScanningCancellableTask; 29 import org.netbeans.modules.java.hints.spi.TreeRule; 30 import org.netbeans.spi.editor.hints.ErrorDescription; 31 import org.netbeans.spi.editor.hints.HintsController; 32 33 37 public class SuggestionsTask extends ScanningCancellableTask<CompilationInfo> { 38 39 public SuggestionsTask() { 40 } 41 42 public void run(CompilationInfo info) throws Exception { 43 Map <Kind, List <TreeRule>> suggestions = RulesManager.getInstance().getSuggestions(); 44 45 if (suggestions.isEmpty()) { 46 return ; 47 } 48 49 int position = CaretAwareJavaSourceTaskFactory.getLastPosition(info.getFileObject()); 50 List <ErrorDescription> result = new ArrayList <ErrorDescription>(); 51 52 if (position != (-1)) { 53 TreePath tp = info.getTreeUtilities().pathFor(position); 54 55 while (tp != null) { 56 if (isCancelled()) 57 return ; 58 59 Kind k = tp.getLeaf().getKind(); 60 List <TreeRule> rules = suggestions.get(k); 61 62 if (rules != null) { 63 for (TreeRule rule : rules) { 64 if (isCancelled()) 65 return ; 66 67 List <ErrorDescription> errors = rule.run(info, tp); 68 69 if (errors != null) { 70 result.addAll(errors); 71 } 72 } 73 } 74 75 tp = tp.getParentPath(); 76 } 77 } 78 79 if (isCancelled()) 80 return ; 81 82 HintsController.setErrors(info.getFileObject(), SuggestionsTask.class.getName(), result); 83 } 84 85 } 86 | Popular Tags |