コード例 #1
0
 /*
  * @see org.eclipse.jface.text.source.AnnotationRulerColumn#setModel(org.eclipse.jface.text.source.IAnnotationModel)
  */
 public void setModel(IAnnotationModel model) {
   if (model instanceof IAnnotationModelExtension) {
     IAnnotationModelExtension extension = (IAnnotationModelExtension) model;
     model = extension.getAnnotationModel(ProjectionSupport.PROJECTION);
   }
   super.setModel(model);
 }
コード例 #2
0
  /**
   * Attaches a coverage annotation model for the given editor if the editor can be annotated. Does
   * nothing if the model is already attached.
   *
   * @param editor Editor to attach a annotation model to
   */
  public static boolean attach(ITextEditor editor) {
    IDocumentProvider provider = editor.getDocumentProvider();
    IEditorInput input = editor.getEditorInput();

    if (provider != null && input instanceof FileEditorInput) {
      IAnnotationModel model = provider.getAnnotationModel(input);

      if (model instanceof IAnnotationModelExtension) {
        IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;

        ColorAnnotationModel colormodel = (ColorAnnotationModel) modelex.getAnnotationModel(KEY);

        if (colormodel == null) {
          IFile file = ((FileEditorInput) input).getFile();
          IFeatureProject project = CorePlugin.getFeatureProject(file);
          if (project != null
              && project.getComposer() != null
              && project.getComposer().needColor()) {
            IDocument document = provider.getDocument(input);
            colormodel = new ColorAnnotationModel(document, file, project, editor);
            modelex.addAnnotationModel(KEY, colormodel);

            return true;
          }
        } else {
          colormodel.updateAnnotations(!editor.isDirty());
        }
      }
    }
    return false;
  }
コード例 #3
0
 /**
  * Detaches the coverage annotation model from the given editor. If the editor does not have a
  * model attached, this method does nothing.
  *
  * @param editor Editor to detach the annotation model from
  */
 public static void detach(ITextEditor editor) {
   IDocumentProvider provider = editor.getDocumentProvider();
   // there may be text editors without document providers (SF #1725100)
   if (provider == null) return;
   IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());
   if (!(model instanceof IAnnotationModelExtension)) return;
   IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;
   modelex.removeAnnotationModel(KEY);
 }
コード例 #4
0
  /**
   * Detaches the coverage annotation model from the given editor. If the editor does not have a
   * model attached, this method does nothing.
   *
   * @param editor Editor to detach the annotation model from
   */
  public static void detach(ITextEditor editor) {
    IDocumentProvider provider = editor.getDocumentProvider();
    if (provider != null) {
      IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());

      if (model instanceof IAnnotationModelExtension) {
        IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;

        modelex.removeAnnotationModel(KEY);
      }
    }
  }
コード例 #5
0
 private void replaceAnnotations(Annotation[] remove, Map<Annotation, Position> add) {
   final IAnnotationModel model = viewer.getAnnotationModel();
   if (model instanceof IAnnotationModelExtension) {
     final IAnnotationModelExtension eModel = (IAnnotationModelExtension) model;
     eModel.replaceAnnotations(remove, add);
   } else {
     for (final Annotation annotation : remove) {
       model.removeAnnotation(annotation);
     }
     for (final Annotation annotation : add.keySet()) {
       model.addAnnotation(annotation, add.get(annotation));
     }
   }
 }
コード例 #6
0
  void removeOccurrenceAnnotations() {
    fMarkOccurrenceModificationStamp = IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
    fMarkOccurrenceTargetRegion = null;

    final IDocumentProvider documentProvider = erlangEditor.getDocumentProvider();
    if (documentProvider == null) {
      return;
    }

    final IAnnotationModel annotationModel =
        documentProvider.getAnnotationModel(erlangEditor.getEditorInput());
    if (annotationModel == null || fOccurrenceAnnotations == null) {
      return;
    }

    synchronized (erlangEditor.getLockObject(annotationModel)) {
      if (annotationModel instanceof IAnnotationModelExtension) {
        ((IAnnotationModelExtension) annotationModel)
            .replaceAnnotations(fOccurrenceAnnotations, null);
      } else {
        for (int i = 0, length = fOccurrenceAnnotations.length; i < length; i++) {
          annotationModel.removeAnnotation(fOccurrenceAnnotations[i]);
        }
      }
      fOccurrenceAnnotations = null;
    }
  }
コード例 #7
0
  /**
   * Attaches a coverage annotation model for the given editor if the editor can be annotated. Does
   * nothing if the model is already attached.
   *
   * @param editor Editor to attach a annotation model to
   */
  public static void attach(ITextEditor editor) {
    IDocumentProvider provider = editor.getDocumentProvider();
    // there may be text editors without document providers (SF #1725100)
    if (provider == null) return;
    IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());
    if (!(model instanceof IAnnotationModelExtension)) return;
    IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;

    IDocument document = provider.getDocument(editor.getEditorInput());

    CoverageAnnotationModel coveragemodel =
        (CoverageAnnotationModel) modelex.getAnnotationModel(KEY);
    if (coveragemodel == null) {
      coveragemodel = new CoverageAnnotationModel(editor, document);
      modelex.addAnnotationModel(KEY, coveragemodel);
    }
  }
コード例 #8
0
  @SuppressWarnings("unchecked")
  @Override
  protected void createProblems(
      IProgressMonitor monitor,
      IDocument document,
      IRegion region,
      List<ValidationProblem> problems)
      throws CoreException {
    Object lockObject;
    if (annotationModel instanceof ISynchronizable) {
      lockObject = ((ISynchronizable) annotationModel).getLockObject();
    } else {
      lockObject = annotationModel;
    }
    synchronized (lockObject) {
      List<Annotation> toRemove = null;
      Iterator<Annotation> annotationIterator = annotationModel.getAnnotationIterator();
      while (annotationIterator.hasNext()) {
        Annotation annotation = annotationIterator.next();
        if (ValidationProblemAnnotation.isValidationAnnotation(annotation)) {
          Position position = annotationModel.getPosition(annotation);
          int offset = position.getOffset();
          if (overlaps(region, offset, position.getLength()) || offset >= document.getLength()) {
            if (toRemove == null) {
              toRemove = new ArrayList<Annotation>();
            }
            toRemove.add(annotation);
          }
        }
      }

      Map<Annotation, Position> annotationsToAdd = new HashMap<Annotation, Position>();
      for (ValidationProblem problem : problems) {
        annotationsToAdd.put(
            new ValidationProblemAnnotation(problem),
            new Position(problem.getOffset(), problem.getLength()));
      }

      if (toRemove != null && annotationModel instanceof IAnnotationModelExtension) {
        Annotation[] annotationsToRemove = toRemove.toArray(new Annotation[toRemove.size()]);
        ((IAnnotationModelExtension) annotationModel)
            .replaceAnnotations(annotationsToRemove, annotationsToAdd);
      } else {
        if (toRemove != null) {
          for (Annotation annotation : toRemove) {
            annotationModel.removeAnnotation(annotation);
          }
        }
        for (Map.Entry<Annotation, Position> entry : annotationsToAdd.entrySet()) {
          annotationModel.addAnnotation(entry.getKey(), entry.getValue());
        }
      }
    }
  }
コード例 #9
0
  public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
    if (oldInput != null) {
      annotationModel.disconnect(oldInput);
    }
    if (newInput != null && sourceViewer != null) {
      IAnnotationModel originalAnnotationModel = sourceViewer.getAnnotationModel();
      if (originalAnnotationModel instanceof IAnnotationModelExtension) {
        IAnnotationModelExtension annotationModelExtension =
            (IAnnotationModelExtension) originalAnnotationModel;
        annotationModelExtension.addAnnotationModel(
            ReviewsUiPlugin.PLUGIN_ID, originalAnnotationModel);
      } else {
        try {
          Class<SourceViewer> sourceViewerClazz = SourceViewer.class;
          Field declaredField2 = sourceViewerClazz.getDeclaredField("fVisualAnnotationModel");
          declaredField2.setAccessible(true);
          Method declaredMethod =
              sourceViewerClazz.getDeclaredMethod(
                  "createVisualAnnotationModel", IAnnotationModel.class);
          declaredMethod.setAccessible(true);
          originalAnnotationModel =
              (IAnnotationModel) declaredMethod.invoke(sourceViewer, annotationModel);
          declaredField2.set(sourceViewer, originalAnnotationModel);
          originalAnnotationModel.connect(newInput);
          sourceViewer.showAnnotations(true);

          createVerticalRuler(newInput, sourceViewerClazz);
          createOverviewRuler(newInput, sourceViewerClazz);
          createHighlighting(sourceViewerClazz);
        } catch (Throwable t) {
          StatusHandler.log(
              new Status(
                  IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, "Error attaching annotation model", t));
        }
      }
    }
  }
コード例 #10
0
    /*
     * @see Job#run(org.eclipse.core.runtime.IProgressMonitor)
     */
    public IStatus run(IProgressMonitor progressMonitor) {
      if (isCanceled(progressMonitor)) {
        return Status.CANCEL_STATUS;
      }

      ITextViewer textViewer = editor.getISourceViewer();
      if (textViewer == null) {
        return Status.CANCEL_STATUS;
      }

      IDocument document = textViewer.getDocument();
      if (document == null) {
        return Status.CANCEL_STATUS;
      }

      IDocumentProvider documentProvider = editor.getDocumentProvider();
      if (documentProvider == null) {
        return Status.CANCEL_STATUS;
      }

      IAnnotationModel annotationModel =
          documentProvider.getAnnotationModel(editor.getEditorInput());
      if (annotationModel == null) {
        return Status.CANCEL_STATUS;
      }

      int length = fLocations.length;
      Map<Annotation, Position> annotationMap = new HashMap<Annotation, Position>(length);
      for (int i = 0; i < length; i++) {

        if (isCanceled(progressMonitor)) {
          return Status.CANCEL_STATUS;
        }

        OccurrenceLocation occurrence = fLocations[i];
        Position position = new Position(occurrence.getOffset(), occurrence.getLength());

        String description = occurrence.getDescription();
        String annotationType =
            (occurrence.getFlags() == IOccurrencesFinder.F_WRITE_OCCURRENCE)
                ? WRITE_OCCURRENCE_ID
                : READ_OCCURRENCE_ID;

        /*
         * // create an annotation to mark the occurrence ReconcileAnnotationKey reconcileAnnotationKey = new
         * ReconcileAnnotationKey(null, PHPPartitionTypes.PHP_DEFAULT, ReconcileAnnotationKey.TOTAL);
         * TemporaryAnnotation annotation = new TemporaryAnnotation(position, annotationType, description,
         * reconcileAnnotationKey) {
         */
        /**
         * Paint the ruler annotation.
         *
         * @param gc
         * @param canvas
         * @param r
         */
        /*
         * @Override public void paint(GC gc, Canvas canvas, Rectangle r) { // TODO - Shalom: Change this image
         * location ImageUtilities.drawImage(PHPUiPlugin.getImageDescriptorRegistry().get(
         * PHPPluginImages.DESC_OBJS_OCCURRENCES), gc, canvas, r, SWT.CENTER, SWT.TOP); } };
         */
        Annotation annotation = new Annotation(annotationType, false, description);
        annotationMap.put(annotation, position);
      }

      if (isCanceled(progressMonitor)) return Status.CANCEL_STATUS;

      synchronized (getAnnotationModelLock(annotationModel)) {
        if (annotationModel instanceof IAnnotationModelExtension) {
          ((IAnnotationModelExtension) annotationModel)
              .replaceAnnotations(fOccurrenceAnnotations, annotationMap);
        } else {
          removeOccurrenceAnnotations();
          for (Map.Entry<Annotation, Position> entry : annotationMap.entrySet()) {
            annotationModel.addAnnotation(entry.getKey(), entry.getValue());
          }
        }
        fOccurrenceAnnotations =
            annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
      }

      return Status.OK_STATUS;
    }
コード例 #11
0
    /*
     * @see Job#run(org.eclipse.core.runtime.IProgressMonitor)
     */
    @Override
    public IStatus run(final IProgressMonitor progressMonitor) {
      findRefs(module, selection, fHasChanged);
      if (fRefs == null) {
        return Status.CANCEL_STATUS;
      }

      if (isCanceled(progressMonitor)) {
        return Status.CANCEL_STATUS;
      }

      final ITextViewer textViewer = erlangEditor.getViewer();
      if (textViewer == null) {
        return Status.CANCEL_STATUS;
      }

      final IDocument document = textViewer.getDocument();
      if (document == null) {
        return Status.CANCEL_STATUS;
      }

      final IDocumentProvider documentProvider = erlangEditor.getDocumentProvider();
      if (documentProvider == null) {
        return Status.CANCEL_STATUS;
      }

      final IAnnotationModel annotationModel =
          documentProvider.getAnnotationModel(erlangEditor.getEditorInput());
      if (annotationModel == null) {
        return Status.CANCEL_STATUS;
      }

      // Add occurrence annotations
      final HashMap<Annotation, Position> annotationMap =
          new HashMap<Annotation, Position>(fRefs.size());
      for (final MarkOccurencesHandler.ErlangRef ref : fRefs) {
        if (isCanceled(progressMonitor)) {
          return Status.CANCEL_STATUS;
        }

        final Position position = new Position(ref.getOffset(), ref.getLength());

        final String description = ref.getDescription();
        final String annotationType =
            ref.isDef()
                ? "org.erlide.ui.occurrences.definition" //$NON-NLS-1$
                : "org.erlide.ui.occurrences";

        annotationMap.put(new Annotation(annotationType, false, description), position);
      }

      if (isCanceled(progressMonitor)) {
        return Status.CANCEL_STATUS;
      }

      synchronized (erlangEditor.getLockObject(annotationModel)) {
        if (annotationModel instanceof IAnnotationModelExtension) {
          ((IAnnotationModelExtension) annotationModel)
              .replaceAnnotations(
                  erlangEditor.markOccurencesHandler.fOccurrenceAnnotations, annotationMap);
        } else {
          erlangEditor.markOccurencesHandler.removeOccurrenceAnnotations();
          for (final Map.Entry<Annotation, Position> mapEntry : annotationMap.entrySet()) {
            annotationModel.addAnnotation(mapEntry.getKey(), mapEntry.getValue());
          }
        }
        erlangEditor.markOccurencesHandler.fOccurrenceAnnotations =
            annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
      }

      return Status.OK_STATUS;
    }