Ejemplo n.º 1
0
  /** Creates Annotations for FOP */
  private void createFOPAnnotations() throws BadLocationException {
    AnnotationModelEvent event = new AnnotationModelEvent(this);
    FSTModel model = project.getFSTModel();

    if (model == null) {
      composer.buildFSTModel();
      model = project.getFSTModel();
    }
    if (model == null) {
      return;
    }

    clear();

    if (file.getParent() instanceof IFolder) {
      if (isInBuildFolder((IFolder) file.getParent())) {
        /* annotations for generated files */
        FSTClass clazz = model.getClass(model.getAbsoluteClassName(file));
        if (clazz == null) {
          return;
        }
        if (!clazz.hasComposedLines) {
          clazz.hasComposedLines = true;
          composer.postCompile(null, file);
        }
        for (FSTFeature fstFeature : model.getFeatures()) {
          FSTRole role = clazz.getRole(fstFeature.getName());
          if (role == null) {
            continue;
          }
          for (FSTMethod m : role.getAllMethods()) {
            createFOPComposedAnnotations(event, fstFeature, m);
          }
          for (FSTField f : role.getAllFields()) {
            createFOPComposedAnnotations(event, fstFeature, f);
          }
        }
      } else {
        /* annotations for source files */
        String featureName = getFeature((IFolder) file.getParent());
        if (featureName != null) {
          FSTFeature fstFeature = model.getFeature(featureName);
          if (fstFeature != null) {
            // bar at the left of the editor
            final int color = fstFeature.getColor();
            for (int line = 0; line < document.getNumberOfLines(); line++) {
              Position position = new Position(document.getLineOffset(line), 1);
              ColorAnnotation cafh =
                  new ColorAnnotation(color, position, ColorAnnotation.TYPE_IMAGE);
              cafh.setText(fstFeature.getName());
              annotations.add(cafh);
              event.annotationAdded(cafh);
            }
          }
        }
      }
    }
  }