Example #1
0
  /**
   * Iterates over all model elements of the EPackages ({@link #getEPackages()}), including the
   * EPackages themselves.
   *
   * <p>Calls {@link AnnotationManager#getAnnotation(ENamedElement, EClass)} for each model element.
   * This ensures that an annotation is created for each model element. The {@link
   * #getAnnotationEClass(ENamedElement)} method is used to determine which type of annotation to
   * created for a model element.
   *
   * <p>The annotate method is the first step in the annotation process. The next method called is
   * the {@link #postAnnotate()} method.
   *
   * @param ePackages the EPackage instances to annotate
   * @param annotationManager the annotationManager is responsible for managing manual and
   *     automatically created annotations
   * @see ModelController#annotate()
   * @see #postAnnotate()
   */
  public void annotate(List<EPackage> ePackages, AnnotationManager annotationManager) {

    ExtensionPointUtils.readAnnotationsModelsFromExtensions();

    for (EPackage ePackage : ePackages) {

      // annotate the epackage itself
      {
        final EClass annotationEClass = getAnnotationEClass(ePackage);
        if (annotationEClass != null) {
          annotationManager.getAnnotation(ePackage, annotationEClass);
        }
      }

      // and then its content
      final Iterator<EObject> iterator = ePackage.eAllContents();
      while (iterator.hasNext()) {
        final Object object = iterator.next();
        if (object instanceof ENamedElement) {
          final ENamedElement eNamedElement = (ENamedElement) object;
          final EClass annotationEClass = getAnnotationEClass(eNamedElement);

          if (annotationEClass != null) {
            annotationManager.getAnnotation(eNamedElement, annotationEClass);
          }
        }
      }
    }
  }
Example #2
0
  /**
   * This method is called after all ModelAnnotators have created annotations and have fully
   * annotated the model.
   *
   * <p>This method calls the {@link Annotator#postAnnotating(EModelElementAnnotation)} method for
   * each model element annotation.
   *
   * @param ePackages the EPackage instances to annotate
   * @param annotationManager the annotationManager is responsible for managing manual and
   *     automatically created annotations
   */
  public void postAnnotate(List<EPackage> ePackages, AnnotationManager annotationManager) {
    // and then do the second step
    for (EPackage ePackage : ePackages) {

      // post annotate the epackage itself
      {
        final EClass annotationEClass = getAnnotationEClass(ePackage);
        if (annotationEClass != null) {
          final Annotator<ENamedElementAnnotation> annotator =
              annotationManager.getAnnotator(annotationEClass);
          final ENamedElementAnnotation annotation =
              annotationManager.getAnnotation(ePackage, annotationEClass);
          if (annotator != null) {
            annotator.postAnnotating(annotation);
          }
        }
      }

      // and then its content
      final Iterator<EObject> iterator = ePackage.eAllContents();
      while (iterator.hasNext()) {
        final Object object = iterator.next();
        if (object instanceof ENamedElement) {
          final ENamedElement eNamedElement = (ENamedElement) object;
          final EClass annotationEClass = getAnnotationEClass(eNamedElement);
          if (annotationEClass != null) {
            final Annotator<ENamedElementAnnotation> annotator =
                annotationManager.getAnnotator(annotationEClass);
            final ENamedElementAnnotation annotation =
                annotationManager.getAnnotation(eNamedElement, annotationEClass);
            if (annotator != null) {
              annotator.postAnnotating(annotation);
            }
          }
        }
      }
    }
  }