1 package org.netbeans.modules.tasklist.i18n; 2 3 import java.text.MessageFormat ; 4 import java.util.ArrayList ; 5 import java.util.List ; 6 import javax.swing.text.Document ; 7 import javax.swing.text.StyledDocument ; 8 import org.netbeans.api.mdr.MDRepository; 9 import org.netbeans.jmi.javamodel.Element; 10 import org.netbeans.jmi.javamodel.Resource; 11 import org.netbeans.jmi.javamodel.StringLiteral; 12 import org.netbeans.modules.javacore.api.JavaModel; 13 import org.netbeans.modules.tasklist.client.Suggestion; 14 import org.netbeans.modules.tasklist.client.SuggestionAgent; 15 import org.netbeans.modules.tasklist.client.SuggestionManager; 16 import org.netbeans.modules.tasklist.client.SuggestionPerformer; 17 import org.netbeans.modules.tasklist.core.TLUtils; 18 import org.netbeans.modules.tasklist.core.util.TextPositionsMapper; 19 import org.netbeans.modules.tasklist.providers.SuggestionContext; 20 import org.openide.ErrorManager; 21 import org.openide.filesystems.FileObject; 22 import org.openide.loaders.DataObject; 23 import org.openide.loaders.DataObjectNotFoundException; 24 25 30 public class TranslateFileChecker { 31 34 public static class Error { 35 36 public int line; 37 38 39 public int column; 40 41 42 public String constant; 43 44 51 private Error(int line, int column, String constant) { 52 this.line = line; 53 this.column = column; 54 this.constant = constant; 55 } 56 } 57 58 private FileObject fo; 59 60 61 private List problems = new ArrayList (); 62 63 private TextPositionsMapper m; 64 65 public TranslateFileChecker(FileObject fo) { 66 this.fo = fo; 67 } 68 69 74 public Error [] run() { 75 String suffix = fo.getExt(); 76 if (!suffix.equalsIgnoreCase("java")) return new Error [0]; 78 79 MDRepository rep = JavaModel.getJavaRepository(); 82 rep.beginTrans(false); 84 try { 85 JavaModel.setClassPath(fo); 88 89 Resource res = JavaModel.getResource(fo); 91 m = new TextPositionsMapper(res.getSourceText()); 92 93 findErrors(res); 94 } finally { 95 rep.endTrans(); 98 } 99 100 return (Error []) problems.toArray(new Error [problems.size()]); 101 } 102 103 108 private void findErrors(Element el) { 109 List ch = el.getChildren(); 110 for (int i = 0; i < ch.size(); i++) { 111 Element e = (Element) ch.get(i); 112 if (e instanceof StringLiteral) { 113 int[] pos = new int[2]; 114 m.findPosition(e.getStartOffset(), pos); 115 String line = m.getLine(pos[0]); 116 117 if (line.indexOf("NOI18N") == -1) { 120 problems.add(new Error (pos[0], pos[1], 121 ((StringLiteral) e).getValue())); 122 } 123 } else { 124 findErrors(e); 125 } 126 } 127 } 128 } 129 | Popular Tags |