public Object[] getAnnotations() { Document doc = txtEditorPane().getDocument(); DataObject dob = (DataObject)doc.getProperty(Document.StreamDescriptionProperty); // get line annotations Set set = ((LineCookie)dob.getCookie(LineCookie.class)).getLineSet(); Iterator iter = set.getLines().iterator(); List result = new ArrayList(); while(iter.hasNext()) { result.addAll(getAnnotations((Line)iter.next())); } // get parser annotations Class javaEditorClass = null; try { javaEditorClass = Class.forName("org.netbeans.modules.java.JavaEditor"); } catch (ClassNotFoundException e) { throw new JemmyException("Class JavaEditors not found.", e); } Object javaEditorInstance = dob.getCookie(javaEditorClass); if(javaEditorInstance != null) { ArrayList parserAnnotations; try { java.lang.reflect.Field annot = javaEditorClass.getDeclaredField("annotations"); annot.setAccessible(true); parserAnnotations = (ArrayList)annot.get(javaEditorInstance); } catch (Exception e) { throw new JemmyException("Get annotations field failed.", e); } result.addAll(parserAnnotations); } // return all line and parser annotations together return result.toArray(new Annotation[0]); }