/**
   * Builds the FSTModel of the feature project and creates a list of all directives with valid
   * colors
   *
   * @return the directive list
   */
  private void createDirectiveList() {
    directiveMap.clear();
    validDirectiveList.clear();
    FSTModel model = project.getFSTModel();
    if (model == null) {
      composer.buildFSTModel();
      model = project.getFSTModel();
    }
    if (model == null) {
      return;
    }

    int index = 0;
    for (FSTFeature fstFeature : model.getFeatures()) {
      for (FSTRole role : fstFeature.getRoles()) {
        if (file.equals(role.getFile())) {
          for (FSTDirective dir : role.getDirectives()) {
            directiveMap.put(dir.getId(), dir);
            index++;
          }
        }
      }
    }

    for (int i = 0; i < index; i++) {
      FSTDirective dir = directiveMap.get(i);
      if (dir != null && ColorList.isValidColor(dir.getColor())) {
        validDirectiveList.add(dir);
      }
    }
  }
Esempio n. 2
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);
            }
          }
        }
      }
    }
  }
Esempio n. 3
0
  /**
   * Builds the FSTModel of the feature project and creates a list of all directives with valid
   * colors
   *
   * @return the directive list
   */
  private void createDirectiveList() {
    directiveMap.clear();
    validDirectiveList.clear();
    FSTModel model = project.getFSTModel();
    if (model == null || model.getClasses().isEmpty()) {
      composer.buildFSTModel();
      model = project.getFSTModel();
    }
    if (model == null) {
      return;
    }

    for (FSTFeature fstFeature : model.getFeatures()) {
      for (FSTRole role : fstFeature.getRoles()) {
        if (file.equals(role.getFile())) {
          for (FSTDirective dir : role.getDirectives()) {
            directiveMap.put(dir.getId(), dir);
            validDirectiveList.add(dir);
          }
        }
      }
    }
  }
  @Override
  public boolean hasChildren(Object element) {
    if (element instanceof FSTClass) {
      for (FSTRole role : ((FSTClass) element).getRoles()) {
        if (!role.getClassFragment().getMethods().isEmpty()
            || !role.getClassFragment().getFields().isEmpty()
            || !role.getDirectives().isEmpty()
            || !role.getInnerClasses().isEmpty()) {
          return true;
        }
      }
      return false;
    }

    if (element instanceof FSTMethod) {
      FSTMethod fstMethod = (FSTMethod) element;
      FSTRole role = fstMethod.getRole();
      return role.getMethods().contains(element) || !fstMethod.getFSTDirectives().isEmpty();
    }
    if (element instanceof FSTField) return false;

    if (element instanceof FSTInvariant) return true;

    if (element instanceof FSTDirective) {
      return ((FSTDirective) element).getRoleElementChildren().length != 0;
    }
    if (element instanceof FSTClassFragment) {
      FSTClassFragment innerClass = (FSTClassFragment) element;
      if (!innerClass.getMethods().isEmpty()
          || !innerClass.getFields().isEmpty()
          || !innerClass.getInnerClasses().isEmpty()) {
        return true;
      }
    }

    return false;
  }
  @Override
  public Object[] getChildren(Object parentElement) {
    Object[] obj = null;
    if (parentElement instanceof FSTClass) {
      // get all fields, methods, directives and invariants
      final TreeSet<FSTMethod> methods = new TreeSet<FSTMethod>();
      final TreeSet<FSTField> fields = new TreeSet<FSTField>();
      final TreeSet<FSTInvariant> invariants = new TreeSet<FSTInvariant>();
      final TreeSet<FSTDirective> directives = new TreeSet<FSTDirective>();
      final TreeSet<FSTClassFragment> innerClasses = new TreeSet<FSTClassFragment>();

      for (FSTRole role : ((FSTClass) parentElement).getRoles()) {
        invariants.addAll(role.getClassFragment().getInvariants());
        for (FSTMethod fstMethod : role.getMethods()) {
          if (fstMethod.getParent() instanceof FSTClassFragment) methods.add(fstMethod);
        }
        fields.addAll(role.getFields());
        TreeSet<FSTDirective> roleDirectives = role.getDirectives();
        for (FSTDirective directive : roleDirectives) {
          if (directive.getParent() == null) {
            directives.add(directive);
          }
        }
        innerClasses.addAll(role.getInnerClasses());
      }

      obj =
          new IRoleElement
              [methods.size()
                  + fields.size()
                  + invariants.size()
                  + directives.size()
                  + innerClasses.size()];
      int pos = 0;
      System.arraycopy(invariants.toArray(), 0, obj, pos, invariants.size());
      System.arraycopy(fields.toArray(), 0, obj, pos += invariants.size(), fields.size());
      System.arraycopy(methods.toArray(), 0, obj, pos += fields.size(), methods.size());
      System.arraycopy(directives.toArray(), 0, obj, pos += methods.size(), directives.size());
      System.arraycopy(
          innerClasses.toArray(), 0, obj, pos += directives.size(), innerClasses.size());

      return filter(obj);
    } else if (parentElement instanceof FSTMethod) {
      // get all the roles that belong to a method

      Set<FSTRole> roleList = new HashSet<FSTRole>();
      Set<FSTMethod> methods = new HashSet<FSTMethod>();
      for (FSTRole role : ((FSTMethod) parentElement).getRole().getFSTClass().getRoles()) {
        for (FSTMethod m : role.getAllMethods()) {
          if ( // m.isOwn(role.file) &&
          // ((FSTMethod)parentElement).isOwn(role.file) &&
          m.getFullName().equals(((FSTMethod) parentElement).getFullName())) {
            if (m.hasContract()) {
              roleList.add(
                  new FSTContractedRole(role.getFile(), role.getFeature(), role.getFSTClass()));
            } else {
              roleList.add(role);
            }
            methods.add(m);
            break;
          }
        }
      }

      List<String> featureOrder =
          CorePlugin.getFeatureProject(((FSTMethod) parentElement).getRole().getFile())
              .getFeatureModel()
              .getFeatureOrderList();

      if (((FSTMethod) parentElement).getFSTDirectives().size() == 0) {
        obj = new FSTRole[roleList.size()];
        int index = 0;
        for (String featureName : featureOrder) {

          for (Iterator<FSTRole> it = roleList.iterator(); it.hasNext(); ) {
            FSTRole next = it.next();
            if (next.getFeature().getName().equals(featureName)) {
              obj[index++] = next;
              it.remove();
              break;
            }
          }
        }
      } else {
        List<FSTDirective> dirs = new ArrayList<>();
        for (FSTRole role : roleList) {
          if (role.getMethods().contains(parentElement)) {
            // equals works correct?
            for (FSTMethod method : role.getMethods()) {
              if (method.equals(parentElement)) {
                dirs.addAll(method.getFSTDirectives());
                break;
              }
            }
          }
        }
        return dirs.toArray();
      }

    } else if (parentElement instanceof FSTInvariant) {
      // get all the roles that belong to an invariant
      LinkedList<FSTRole> roleList = new LinkedList<FSTRole>();
      for (FSTRole role : ((FSTInvariant) parentElement).getRole().getFSTClass().getRoles()) {
        for (FSTInvariant i : role.getClassFragment().getInvariants()) {
          if (((FSTInvariant) parentElement).getFullName().equals(i.getFullName())) {
            roleList.add(role);
            break;
          }
        }
      }

      return filter(roleList.toArray());
    } else if (parentElement instanceof FSTField) {
      // get all the roles that belong to a field
      LinkedList<FSTRole> roleList = new LinkedList<FSTRole>();
      for (FSTRole role : ((FSTField) parentElement).getRole().getFSTClass().getRoles()) {
        for (FSTField f : role.getAllFields()) {
          if (f.getFullName().equals(((FSTField) parentElement).getFullName())) {
            roleList.add(role);
            break;
          }
        }
      }
      return filter(roleList.toArray());
    } else if (parentElement instanceof FSTDirective) {
      return ((FSTDirective) parentElement).getRoleElementChildren();
    } else if (parentElement instanceof FSTClassFragment) {
      final TreeSet<FSTMethod> methods = new TreeSet<FSTMethod>();
      final TreeSet<FSTField> fields = new TreeSet<FSTField>();
      final TreeSet<FSTClassFragment> innerClasses = new TreeSet<FSTClassFragment>();
      final TreeSet<FSTInvariant> invariants = new TreeSet<FSTInvariant>();

      FSTClassFragment innerClassCast = (FSTClassFragment) parentElement;

      invariants.addAll(innerClassCast.getInvariants());
      LinkedList<FSTClassFragment> allFragments =
          innerClassCast.getRole().getAllEqualFSTFragments(innerClassCast);
      for (FSTClassFragment fstClassFragment : allFragments) {
        methods.addAll(fstClassFragment.getMethods());
        fields.addAll(fstClassFragment.getFields());
      }
      innerClasses.addAll(innerClassCast.getInnerClasses());

      obj =
          new IRoleElement
              [methods.size() + fields.size() + invariants.size() + innerClasses.size()];
      int pos = 0;
      System.arraycopy(invariants.toArray(), 0, obj, pos, invariants.size());
      System.arraycopy(fields.toArray(), 0, obj, pos += invariants.size(), fields.size());
      System.arraycopy(methods.toArray(), 0, obj, pos += fields.size(), methods.size());
      System.arraycopy(innerClasses.toArray(), 0, obj, pos += methods.size(), innerClasses.size());
    }

    return filter(obj);
  }