1 19 20 package org.netbeans.modules.tasklist.javadoc; 21 22 import java.awt.Image ; 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 import java.lang.reflect.Modifier ; 26 27 import org.openide.src.*; 28 import org.openide.cookies.SourceCookie; 29 import org.openide.loaders.DataObject; 30 import java.util.EventListener ; 31 import javax.swing.text.StyledDocument ; 32 import org.netbeans.modules.tasklist.client.Suggestion; 33 import org.netbeans.modules.tasklist.client.SuggestionManager; 34 import org.netbeans.modules.tasklist.client.SuggestionPerformer; 35 import org.netbeans.modules.tasklist.client.SuggestionAgent; 36 import org.netbeans.modules.tasklist.providers.SuggestionContext; 37 import org.netbeans.modules.tasklist.javadoc.ext.JavaTagNames; 38 import org.openide.text.Line; 39 import org.openide.text.NbDocument; 40 import org.openide.util.Utilities; 41 42 71 public final class AutoCommenter extends Object implements JavaTagNames { 72 public static final int JDC_OK = 1; 73 public static final int JDC_MISSING = 2; 74 public static final int JDC_ERROR = 4; 75 76 private ArrayList elements; 77 private final DataObject dataObject; 78 79 private AutoCommentChangeListener autoCommentChangeListener = null; 80 private SuggestionContext env; 81 private SuggestionManager man; 82 83 88 public AutoCommenter(SuggestionManager man, DataObject dobj, SuggestionContext env ) { 89 this.man = man; 90 dataObject = dobj; 91 this.env = env; 92 elements = new ArrayList (); 93 } 94 95 private void prepareListModel(ArrayList listModel, int mask, boolean pckg, int err_mask ) { 96 Iterator it = elements.iterator(); 97 98 while( it.hasNext() ) { 99 AutoCommenterElement el = (AutoCommenterElement)it.next(); 100 101 if ( acceptElement( el, mask, pckg, err_mask ) ) { 102 listModel.add( el ); 103 } 104 } 105 } 106 107 static boolean acceptElement(AutoCommenterElement el, int mask, boolean pckg, int err_mask ) { 108 if ((el.getErrorNumber() & err_mask) == 0) 110 return false; 111 112 int access = JavaDocUtils.getEffectiveAccess((MemberElement)el.getSrcElement()); 114 if (access == 0) 115 return pckg; 116 else 117 return (access & mask) > 0; 118 } 119 120 ArrayList prepareListModel( int mask, boolean pckg, int err_mask ) { 121 ArrayList dm = new ArrayList (); 122 prepareListModel( dm, mask, pckg, err_mask ); 123 return dm; 124 } 125 126 private void addElements( ClassElement classElement ) { 127 elements.add( new AutoCommenterClass( classElement ) ); 128 129 FieldElement[] fe = classElement.getFields(); 130 for( int i = 0; i < fe.length; i++ ) { 131 elements.add( new AutoCommenterField ( fe[i] ) ); 132 } 133 134 ConstructorElement[] ce = classElement.getConstructors(); 135 for( int i = 0; i < ce.length; i++ ) { 136 elements.add( new AutoCommenterConstructor ( ce[i] ) ); 137 } 138 139 MethodElement[] me = classElement.getMethods(); 140 for( int i = 0; i < me.length; i++ ) { 141 elements.add( new AutoCommenterMethod ( me[i] ) ); 142 } 143 144 150 } 151 152 public interface AutoCommentChangeListener extends EventListener { 153 public void listChanged(); 154 } 155 156 159 public synchronized void addAutoCommentChangeListener(AutoCommentChangeListener listener) throws java.util.TooManyListenersException { 160 if (autoCommentChangeListener != null) { 161 throw new java.util.TooManyListenersException (); 162 } 163 autoCommentChangeListener = listener; 164 } 165 166 169 public synchronized void removeAutoCommentChangeListener(AutoCommentChangeListener listener) { 170 autoCommentChangeListener = null; 171 } 172 173 public ArrayList findErrors() { 174 SourceCookie sc = (SourceCookie)dataObject.getCookie(SourceCookie.class); 175 176 if (sc == null) 180 return null; 181 182 SourceElement se = sc.getSource(); 183 if ( se != null ) { 184 ClassElement[] ces = se.getAllClasses(); 185 for( int j = 0; j < ces.length; j++ ){ 186 addElements( ces[j] ); 187 } 188 } 189 190 return findErrors_(); 191 } 192 193 private ArrayList findErrors_() { 194 ArrayList tasks = new ArrayList (30); 195 196 assert false : "Reimplemented in tasklist.javadoc.ext package"; 197 return tasks; 293 } 294 295 private boolean inheritsJavadoc(MethodElement method) { 296 ClassElement cl = method.getDeclaringClass(); 297 if (cl == null) { 298 return false; 299 } 300 MethodParameter[] params = method.getParameters(); 301 Type[] types = new Type[params.length]; 302 for (int i = 0; i < params.length; i++) { 303 types[i] = params[i].getType(); 304 } 305 boolean[] checkedObject = new boolean[] {false}; 306 boolean found = inheritsJavadoc(cl, method, method.getName(), types, checkedObject); 307 return found; 308 } 309 310 private boolean inheritsJavadoc(ClassElement cl, MethodElement self, 311 Identifier method, Type[] arguments, 312 boolean[] checkedObject) { 313 checkedObject[0] |= cl.getName().getFullName().equals("java.lang.Object"); 315 MethodElement mel = cl.getMethod(method, arguments); 317 if ((mel != null) && (mel != self)) { 318 JavaDoc javadoc = mel.getJavaDoc(); 320 if ((javadoc != null) && !javadoc.isEmpty()) { 321 return true; 322 } 323 } 324 325 Identifier[] interfaces = cl.getInterfaces(); 327 for (int j = 0; j < interfaces.length; j++) { 328 ClassElement icl = ClassElement.forName(interfaces[j].getFullName()); 329 if (icl == null) { 330 continue; 331 } 332 boolean found = inheritsJavadoc(icl, self, method, arguments, checkedObject); 333 if (found) { 334 return true; 335 } 336 } 337 338 Identifier scli = cl.getSuperclass(); 340 if (scli == null && !checkedObject[0]) { 341 scli = Identifier.create("java.lang.Object"); } 343 if (scli != null) { 344 ClassElement scl = ClassElement.forName(scli.getFullName()); 345 if (scl != null) { 346 boolean found = inheritsJavadoc(scl, self, method, arguments, checkedObject); 347 if (found) { 348 return true; 349 } 350 } 351 } 352 return false; 353 } 354 } 355 | Popular Tags |