private static String getAnnotationType(VisageLineBreakpoint b, boolean isConditional) {
   boolean isInvalid = b.getValidity() == VALIDITY.INVALID;
   String annotationType;
   if (b instanceof VisageLineBreakpoint) {
     annotationType =
         b.isEnabled()
             ? (isConditional
                 ? EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE
                 : EditorContext.BREAKPOINT_ANNOTATION_TYPE)
             : (isConditional
                 ? EditorContext.DISABLED_CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE
                 : EditorContext.DISABLED_BREAKPOINT_ANNOTATION_TYPE);
     //        } else if (b instanceof FieldBreakpoint) {
     //            annotationType = b.isEnabled () ?
     //                EditorContext.FIELD_BREAKPOINT_ANNOTATION_TYPE :
     //                EditorContext.DISABLED_FIELD_BREAKPOINT_ANNOTATION_TYPE;
     //        } else if (b instanceof MethodBreakpoint) {
     //            annotationType = b.isEnabled () ?
     //                EditorContext.METHOD_BREAKPOINT_ANNOTATION_TYPE :
     //                EditorContext.DISABLED_METHOD_BREAKPOINT_ANNOTATION_TYPE;
   } else {
     throw new IllegalStateException(b.toString());
   }
   if (isInvalid && b.isEnabled()) annotationType += "_broken";
   return annotationType;
 }
 public void annotate(final FileObject fo) {
   synchronized (breakpointToAnnotations) {
     if (annotatedFiles.contains(fo)) {
       // Already annotated
       return;
     }
     Set<VisageLineBreakpoint> annotatedBreakpoints = breakpointToAnnotations.keySet();
     for (Breakpoint breakpoint : DebuggerManager.getDebuggerManager().getBreakpoints()) {
       if (isAnnotatable(breakpoint)) {
         VisageLineBreakpoint b = (VisageLineBreakpoint) breakpoint;
         if (!annotatedBreakpoints.contains(b)) {
           b.addPropertyChangeListener(this);
           breakpointToAnnotations.put(b, new WeakSet<Annotation>());
           LineTranslations.getTranslations().registerForLineUpdates(b);
         }
         addAnnotationTo(b, fo);
       }
     }
     annotatedFiles.add(fo);
   }
   if (attachManagerListener) {
     attachManagerListener = false;
     DebuggerManager.getDebuggerManager()
         .addDebuggerListener(
             WeakListeners.create(
                 DebuggerManagerListener.class, this, DebuggerManager.getDebuggerManager()));
   }
 }
 public void breakpointAdded(Breakpoint breakpoint) {
   if (isAnnotatable(breakpoint)) {
     VisageLineBreakpoint b = (VisageLineBreakpoint) breakpoint;
     //            JPDABreakpoint b = (JPDABreakpoint) breakpoint;
     b.addPropertyChangeListener(this);
     RequestProcessor.getDefault().post(new AnnotationRefresh(b, false, true));
     //            if( b instanceof LineBreakpoint ) {
     VisageLineBreakpoint lb = (VisageLineBreakpoint) breakpoint;
     LineTranslations.getTranslations().registerForLineUpdates(lb);
     //            }
   }
 }
 // Is called under synchronized (breakpointToAnnotations)
 private void addAnnotationTo(VisageLineBreakpoint b, FileObject fo) {
   int[] lines = getAnnotationLines(b, fo);
   if (lines == null || lines.length == 0) {
     return;
   }
   String condition;
   if (b instanceof VisageLineBreakpoint) {
     condition = ((VisageLineBreakpoint) b).getCondition();
     //        } else if (b instanceof FieldBreakpoint) {
     //            condition = ((FieldBreakpoint) b).getCondition();
     //        } else if (b instanceof MethodBreakpoint) {
     //            condition = ((MethodBreakpoint) b).getCondition();
   } else {
     throw new IllegalStateException(b.toString());
   }
   boolean isConditional = (condition != null) && condition.trim().length() > 0;
   String annotationType = getAnnotationType(b, isConditional);
   DataObject dataObject;
   try {
     dataObject = DataObject.find(fo);
   } catch (DataObjectNotFoundException donfex) {
     donfex.printStackTrace();
     return;
   }
   LineCookie lc = dataObject.getCookie(LineCookie.class);
   if (lc == null) return;
   List<DebuggerBreakpointAnnotation> annotations = new ArrayList<DebuggerBreakpointAnnotation>();
   for (int l : lines) {
     try {
       Line line = lc.getLineSet().getCurrent(l - 1);
       DebuggerBreakpointAnnotation annotation =
           new DebuggerBreakpointAnnotation(annotationType, line, b.getLineBreakpoint());
       annotations.add(annotation);
     } catch (IndexOutOfBoundsException e) {
     } catch (IllegalArgumentException e) {
     }
   }
   if (annotations.size() == 0) {
     return;
   }
   Set<Annotation> bpAnnotations = breakpointToAnnotations.get(b);
   if (bpAnnotations == null) {
     breakpointToAnnotations.put(b, new WeakSet<Annotation>(annotations));
   } else {
     bpAnnotations.addAll(annotations);
     breakpointToAnnotations.put(b, bpAnnotations);
   }
 }
 /** @return The annotation lines or <code>null</code>. */
 private static int[] getAnnotationLines(VisageLineBreakpoint b, FileObject fo) {
   if (b instanceof VisageLineBreakpoint) {
     VisageLineBreakpoint lb = (VisageLineBreakpoint) b;
     try {
       if (fo.getURL().equals(new URL(lb.getURL()))) {
         return new int[] {lb.getLineNumber()};
       }
     } catch (MalformedURLException ex) {
       Exceptions.printStackTrace(ex);
     } catch (FileStateInvalidException ex) {
       Exceptions.printStackTrace(ex);
     }
     return null;
     //        } else if (b instanceof FieldBreakpoint) {
     //            FieldBreakpoint fb = (FieldBreakpoint) b;
     //            String className = fb.getClassName();
     //            String fieldName = fb.getFieldName();
     //            int line = EditorContextImpl.getFieldLineNumber(fo, className, fieldName);
     //            return new int[] { line };
     //        } else if (b instanceof MethodBreakpoint) {
     //            MethodBreakpoint mb = (MethodBreakpoint) b;
     //            String[] filters = mb.getClassFilters();
     //            int[] lns = new int[] {};
     //            for (int i = 0; i < filters.length; i++) {
     //                // TODO: annotate also other matched classes
     //                if (!filters[i].startsWith("*") && !filters[i].endsWith("*")) {
     //                    int[] newlns = EditorContextImpl.getMethodLineNumbers(
     //                            fo, filters[i], mb.getClassExclusionFilters(),
     //                            mb.getMethodName(),
     //                            mb.getMethodSignature());
     //                    if (lns.length == 0) {
     //                        lns = newlns;
     //                    } else {
     //                        int[] ln = new int[lns.length + newlns.length];
     //                        System.arraycopy(lns, 0, ln, 0, lns.length);
     //                        System.arraycopy(newlns, 0, ln, lns.length, newlns.length);
     //                        lns = ln;
     //                    }
     //                }
     //            }
     //            return lns;
   } else {
     throw new IllegalStateException(b.toString());
   }
 }