1 19 20 package org.netbeans.modules.tasklist.javadoc.ext; 21 22 import org.netbeans.modules.tasklist.providers.SuggestionContext; 23 import org.netbeans.modules.tasklist.javadoc.*; 24 import org.netbeans.modules.tasklist.client.SuggestionPerformer; 25 import org.netbeans.modules.tasklist.client.SuggestionAgent; 26 import org.netbeans.modules.tasklist.client.SuggestionManager; 27 import org.openide.cookies.SourceCookie; 28 import org.openide.src.*; 29 import org.openide.loaders.DataObject; 30 import org.openide.loaders.DataObjectNotFoundException; 31 import org.openide.text.NbDocument; 32 import org.openide.text.Line; 33 import org.openide.util.Utilities; 34 35 import javax.swing.text.StyledDocument ; 36 import javax.swing.*; 37 import java.util.List ; 38 import java.util.ArrayList ; 39 import java.util.Collections ; 40 import java.lang.reflect.Modifier ; 41 import java.awt.*; 42 43 49 public final class JavadocProxy { 50 51 57 public static List findErrors(DataObject dobj) { 58 SourceCookie sc = (SourceCookie)dobj.getCookie(SourceCookie.class); 59 60 if (sc == null) 64 return null; 65 66 AutoCommenter peer = new AutoCommenter(); 67 peer.elements = new ArrayList (); 68 69 SourceElement se = sc.getSource(); 70 if ( se != null ) { 71 ClassElement[] ces = se.getAllClasses(); 72 for( int j = 0; j < ces.length; j++ ){ 73 peer.addElements( ces[j] ); 74 } 75 } 76 77 ArrayList tasks = new ArrayList (30); 78 79 int modifierMask = Modifier.PUBLIC | Modifier.PROTECTED; 81 int errorMask = AutoCommenter.JDC_ERROR | AutoCommenter.JDC_MISSING; 82 boolean bpackage = false; 84 DefaultListModel model = peer.prepareListModel(modifierMask, bpackage, errorMask); 85 86 int n = model.size(); 87 for (int i = 0; i < n; i++) { 88 Object value = model.get(i); 89 final AutoCommenter.Element element = (AutoCommenter.Element)value; 90 if (element.getErrorNumber() == 91 AutoCommenter.JDC_OK) { 92 continue; 93 } 94 95 SuggestionPerformer action = new JavaDocSuggestionPerformer( 96 new ElementProxy(element), dobj 97 ); 98 99 DefaultListModel m2 = element.getErrorList(); 100 int m2n = m2.size(); 101 for (int j = 0; j < m2n; j++) { 102 Object v2 = m2.get(j); 103 String summary = element.getSrcElement().getName() + 104 ": " + v2.toString(); 106 107 MemberElement el = element.getSrcElement(); 108 SuggestionAgent s = SuggestionManager.getDefault().createSuggestion( 114 null, DocSuggester.TYPE, summary, null, DocSuggester.TYPE); 115 116 121 SourceCookie.Editor editor = 122 (SourceCookie.Editor)dobj.getCookie(SourceCookie.Editor.class); 123 javax.swing.text.Element textElement = editor.sourceToText(el); 124 if (textElement != null) { 125 StyledDocument document = editor.getDocument(); 126 if (document != null) { 127 int offset = textElement.getStartOffset(); 128 int lineNumber = NbDocument.findLineNumber(document, offset); 129 Line line = editor.getLineSet().getCurrent(lineNumber); 130 s.setLine(line); 131 } 132 } 133 155 156 if (element.isCorrectable()) { 157 if (element.getErrorNumber() == 158 AutoCommenter.JDC_MISSING) { 159 Image taskIcon = Utilities.loadImage("org/netbeans/modules/tasklist/javadoc/missing.gif"); s.setIcon(taskIcon); 163 } else { 164 Image taskIcon = Utilities.loadImage("org/netbeans/modules/tasklist/javadoc/fixable-error.gif"); s.setIcon(taskIcon); 166 s.setAction(action); 167 } 168 } else if (element.getErrorNumber() == 169 AutoCommenter.JDC_MISSING) { 170 Image taskIcon = Utilities.loadImage("org/netbeans/modules/tasklist/javadoc/missing.gif"); s.setIcon(taskIcon); 172 } 173 174 tasks.add(s.getSuggestion()); 175 } 176 } 177 return tasks; 178 179 } 180 181 public static class ElementProxy { 182 183 private AutoCommenter.Element peer; 184 185 public ElementProxy(AutoCommenter.Element peer) { 186 this.peer = peer; 187 } 188 189 190 public List getResolutionList() { 191 return Collections.EMPTY_LIST; 193 } 194 195 public JavaDoc getJavaDoc() { 196 return peer.getJavaDoc(); 197 } 198 199 public void viewSource() { 200 peer.viewSource(); 201 } 202 203 public void autoCorrect() throws SourceException { 204 peer.autoCorrect(); 205 } 206 207 } 208 209 210 270 } 271 | Popular Tags |