Пример #1
0
 /**
  * This method is called, when the document is saved or when the document and the number of lines
  * are changed.
  *
  * <p>It removes all annotations and creates new.
  *
  * @param createNew true: builds new FSTModel false: only gets new FSTDirectives
  */
 private void updateAnnotations(boolean createNew) {
   if (!annotations.isEmpty()) {
     clear();
   }
   if (createNew) {
     annotatedPositions = new HashMap<Integer, Position>(docLines);
     if (project.getComposer().getGenerationMechanism()
         == Mechanism.FEATURE_ORIENTED_PROGRAMMING) {
       try {
         createFOPAnnotations();
       } catch (BadLocationException e) {
         CorePlugin.getDefault().logError(e);
       }
     } else {
       createDirectiveList();
       createAnnotations();
     }
   } else {
     if (project.getComposer().getGenerationMechanism()
         == Mechanism.FEATURE_ORIENTED_PROGRAMMING) {
       try {
         createFOPAnnotations();
       } catch (BadLocationException e) {
         CorePlugin.getDefault().logError(e);
       }
     }
     if (!directiveMap.isEmpty()) {
       annotatedPositions.clear();
       updateDirectives();
       createAnnotations();
     }
   }
 }
Пример #2
0
  private IFeatureModel generateFeatureModelOfVariants() {
    final IFeatureProject featureProject = CorePlugin.getFeatureProject(newProject);
    final IFeatureModel featureModel = featureProject.getFeatureModel();

    featureModel.reset();

    featureModel
        .getStructure()
        .setRoot(
            FMFactoryManager.getFactory(featureModel)
                .createFeature(featureModel, "Base")
                .getStructure());
    featureModel.getStructure().getRoot().changeToAlternative();
    featureModel.getStructure().getRoot().setAbstract(true);

    for (IProject project : projects)
      featureModel
          .getStructure()
          .getRoot()
          .addChild(
              FMFactoryManager.getFactory(featureModel)
                  .createFeature(featureModel, project.getName())
                  .getStructure());

    return featureModel;
  }
  /**
   * 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;
  }
  @Override
  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    if (newInput != null && (newInput instanceof IFile)) {
      IFeatureProject featureProject = CorePlugin.getFeatureProject((IFile) newInput);
      if (featureProject != null) model = featureProject.getFSTModel();

      if (viewer instanceof StructuredViewer) {
        ((StructuredViewer) viewer)
            .setSorter(
                new ViewerSorter() {
                  /* (non-Javadoc)
                   * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
                   */
                  @Override
                  public int compare(Viewer viewer, Object o1, Object o2) {
                    int startLineO1 = getLine(o1);
                    int startLineO2 = getLine(o2);

                    return startLineO1 - startLineO2;
                  }

                  private int getLine(Object o1) {
                    int startLineO1 = -1;

                    if (o1 instanceof FSTDirective) {
                      startLineO1 = ((FSTDirective) o1).getStartLine();
                    } else if (o1 instanceof RoleElement<?>) {
                      startLineO1 = ((RoleElement<?>) o1).getLine();
                    }
                    return startLineO1;
                  }
                });
      }
    }
  }
  @Override
  public Object[] getElements(Object inputElement) {
    if (inputElement == null || !(inputElement instanceof IFile)) {
      return new String[] {NO_FILE_FOUND};
    }

    final IFile file = (IFile) inputElement;
    final IFeatureProject featureProject = CorePlugin.getFeatureProject(file);

    if (featureProject != null) {
      model = featureProject.getFSTModel();

      if (model instanceof FSTModelForPP) {
        model = ((FSTModelForPP) model).getExtendedFst();
      }

      if (model != null) {
        FSTClass c = model.getClass(model.getAbsoluteClassName(file));

        if (c != null) {
          return new Object[] {c};
        }
      }
    }
    return new String[] {"Create signature is not enabled"};
  }
 private void initComboFeature() {
   container = sourceFolder != null ? sourceFolder.getFolder(comboFeature.getText()) : null;
   if (featureProject == null) {
     return;
   }
   comboFeature.removeAll();
   for (String s : featureProject.getFeatureModel().getConcreteFeatureNames()) comboFeature.add(s);
   if (feature != null) {
     comboFeature.setText(feature);
   } else {
     if (comboFeature.getItemCount() > 0) comboFeature.select(0);
   }
   Object obj = selection.getFirstElement();
   if (obj instanceof IResource) {
     IResource resource = (IResource) obj;
     boolean found = false;
     while (found == false && resource.getParent() != null) {
       if (resource.getParent().equals(sourceFolder)) {
         for (int i = 0; i < comboFeature.getItemCount(); i++)
           if (comboFeature.getItem(i).equals(resource.getName())) {
             comboFeature.select(i);
             found = true;
             break;
           }
       }
       resource = resource.getParent();
     }
   }
   if (comboFeature.getItemCount() == 1
       || !featureProject.getComposer().createFolderForFeatures()) {
     comboFeature.setEnabled(false);
   } else {
     comboFeature.setEnabled(true);
   }
 }
  /**
   * 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);
      }
    }
  }
Пример #8
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);
            }
          }
        }
      }
    }
  }
Пример #9
0
 private boolean isFeatureProject(String text) {
   boolean isFP = false;
   for (IFeatureProject feature : featureProjects) {
     if (text.equalsIgnoreCase(feature.getProjectName())) {
       isFP = true;
     }
   }
   return isFP;
 }
Пример #10
0
  private void checkcontainer(IFeatureProject featureProject, IResource resource) {
    sourceFolder = featureProject.getSourceFolder();

    if (resource.getParent().equals(sourceFolder)) {
      // TODO: ???
      container = sourceFolder.getFolder(comboFeature.getText());
    } else if (featureProject.getComposer().refines()) {
      buttonRefines.setSelection(isRefinement());
    }
  }
Пример #11
0
 /** Fills the class combo with class names of the same package at other features. */
 private void initComboClassName() {
   String c = comboClass.getText();
   Object obj = selection.getFirstElement();
   if (obj instanceof IFile) {
     String fileExtension = ((IFile) obj).getFileExtension();
     if (composer.extensions().contains(fileExtension)) {
       String fileName = ((IFile) obj).getName();
       c = fileName.substring(0, fileName.lastIndexOf('.'));
     }
   }
   comboClass.removeAll();
   LinkedList<String> inclusions = new LinkedList<String>();
   LinkedList<String> exclusions = new LinkedList<String>();
   if (featureProject.getComposer().hasFeatureFolder()) {
     try {
       for (IResource res : featureProject.getSourceFolder().members()) {
         if (res instanceof IFolder) {
           IFolder folder = (IFolder) res;
           if (folder.getName().equals(comboFeature.getText())) {
             exclusions = getClasses(folder);
           } else {
             for (String className : getClasses(folder)) {
               boolean added = false;
               if (!inclusions.contains(className)) {
                 int i = 0;
                 for (String name : inclusions) {
                   if (className.compareToIgnoreCase(name) < 0) {
                     inclusions.add(i, className);
                     added = true;
                     break;
                   }
                   i++;
                 }
                 if (!added) {
                   inclusions.add(className);
                 }
               }
             }
           }
         }
       }
     } catch (CoreException e) {
       UIPlugin.getDefault().logError(e);
     }
   }
   for (String className : inclusions) {
     if (!exclusions.contains(className)) {
       comboClass.add(className);
     }
   }
   comboClass.setText(c);
 }
Пример #12
0
 /**
  * Initializes the container collecting the supported languages.<br>
  * If a file was selected, the language of the file will be selected.
  */
 private void initComboLanguage() {
   composer = featureProject.getComposer();
   formats = composer.getTemplates();
   comboLanguage.removeAll();
   if (!formats.isEmpty()) {
     for (String[] format : formats) comboLanguage.add(format[0]);
     if (comboLanguage.getItemCount() <= 1) {
       comboLanguage.setEnabled(false);
     } else {
       comboLanguage.setEnabled(true);
     }
     Object element = selection.getFirstElement();
     if (element instanceof IFile) {
       String extension = ((IFile) element).getFileExtension();
       int i = 0;
       for (String[] template : composer.getTemplates()) {
         if (template[1].equals(extension)) {
           comboLanguage.select(i);
           return;
         }
         i++;
       }
     }
     if (composer.getId().equals(lastComposerID) && lastSelection < comboLanguage.getItemCount()) {
       comboLanguage.select(lastSelection);
     } else {
       comboLanguage.select(composer.getDefaultTemplateIndex());
     }
   }
 }
Пример #13
0
  /**
   * Initializes the combo containing all feature projects.<br>
   * Selects the feature project corresponding to the selected resource.
   */
  private void initComboProject() {
    final Object obj = selection.getFirstElement();
    // TODO: Check for projects in other languages than java
    if (obj instanceof JavaElement) {
      IProject project = ((JavaElement) obj).getJavaProject().getProject();
      featureProject = CorePlugin.getFeatureProject(project);
      if (featureProject != null) {
        comboProject.setText(featureProject.getProjectName());
        checkcontainer(featureProject, project);
      }
    } else if (obj instanceof IResource) {
      IResource resource = (IResource) obj;
      featureProject = CorePlugin.getFeatureProject(resource);
      if (featureProject != null) {
        comboProject.setText(featureProject.getProjectName());
        checkcontainer(featureProject, resource);
      }
    } else if (featureProject == null) {
      IWorkbenchWindow editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
      IEditorPart part = null;
      if (editor != null) {
        IWorkbenchPage page = editor.getActivePage();
        if (page != null) {
          part = page.getActiveEditor();
          if (part != null) {
            FileEditorInput inputFile = (FileEditorInput) part.getEditorInput();
            featureProject = CorePlugin.getFeatureProject(inputFile.getFile());

            if (featureProject != null) {
              IResource res =
                  ResourcesPlugin.getWorkspace()
                      .getRoot()
                      .findMember(featureProject.getProjectName());
              checkcontainer(featureProject, res);
            }
          }
        }
      }

      if (featureProject != null) {
        comboProject.setText(featureProject.getProjectName());
      }
    }
    comboProjectText = comboProject.getText();
  }
 @Override
 protected void endAction() {
   for (IFeatureProject project : projectList) {
     final Path path = Paths.get(project.getProject().getFile("model.fg").getLocationURI());
     final IRunner<IFeatureGraph> runner =
         LongRunningWrapper.getRunner(
             new FGBuilder(AdvancedNodeCreator.createSatInstance(project.getFeatureModel())));
     runner.addJobFinishedListener(
         new JobFinishListener<IFeatureGraph>() {
           @Override
           public void jobFinished(IJob<IFeatureGraph> finishedJob) {
             FileHandler.save(path, finishedJob.getResults(), new FeatureGraphFormat());
           }
         });
     runner.schedule();
   }
   projectList.clear();
 }
Пример #15
0
 /**
  * Checks whether the File is in the SourceFolder
  *
  * @param folder
  * @return Feature from the SourceFolder
  */
 private String getFeature(IFolder folder) {
   IContainer parent = folder.getParent();
   if (parent.equals(project.getSourceFolder())) {
     return folder.getName();
   }
   if (parent instanceof IFolder) {
     return getFeature((IFolder) parent);
   }
   return null;
 }
Пример #16
0
 /**
  * Checks whether the File is in the BuildFolder
  *
  * @param folder
  * @return true if BuildFolder or child of BuildFolder
  */
 private boolean isInBuildFolder(IFolder folder) {
   if (folder.equals(project.getBuildFolder())) {
     return true;
   }
   IContainer parent = folder.getParent();
   if (parent instanceof IFolder) {
     return isInBuildFolder((IFolder) parent);
   }
   return false;
 }
Пример #17
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);
          }
        }
      }
    }
  }
Пример #18
0
  /** Initializes all combo boxes. */
  private void initialize() {

    if (clss != null) {
      comboClass.setText(clss);
      if (clss.length() > 0) {
        classDirty = true;
      }
    }

    for (IFeatureProject feature : featureProjects) comboProject.add(feature.getProjectName());

    if (selection == null || selection.isEmpty()) return;

    initComboProject();

    if (featureProject != null) {
      initComboFeature();
      initComboLanguage();
      initComboPackages(sourceFolder, "");
      initTextModulename();
      initComboClassName();
      initRefinesButton();
    }
  }
Пример #19
0
 /**
  * Looks for the package of the selected resource.
  *
  * @param folder The selected folder or the folder containing the selected file.
  * @return The package name or "" if the selected resource is not at the source folder.
  */
 private String setPackage(IFolder folder) {
   String p = "";
   while (!featureProject.getProject().getFolder(folder.getName()).equals(folder)) {
     if (!composer.hasFeatureFolder()) {
       if (sourceFolder.equals(folder)) {
         return "".equals(p) ? p : p.substring(1);
       }
     } else if (sourceFolder.getFolder(folder.getName()).equals(folder)) {
       return "".equals(p) ? p : p.substring(1);
     } else {
       p = "." + folder.getName() + p;
       folder = (IFolder) folder.getParent();
     }
   }
   return "";
 }
Пример #20
0
 @Override
 public void addPages() {
   setWindowTitle(BUILD_PRODUCTS);
   page =
       new BuildProductsPage(
           featureProject.getProjectName(),
           featureProject,
           getGenerate(),
           toggleState,
           getAlgorithm(),
           getT(),
           getT_Interaction(),
           getOrder(),
           getTest(),
           getMax());
   addPage(page);
 }
  private ColorAnnotationModel(
      IDocument document, IFile file, IFeatureProject project, ITextEditor editor) {
    this.document = document;
    this.project = project;
    this.file = file;
    composer = project.getComposer();
    composer.initialize(project);

    docLines = document.getNumberOfLines();
    docLength = document.getLength();

    updateAnnotations(true);

    editor.addPropertyListener(
        new IPropertyListener() {
          @Override
          public void propertyChanged(Object source, int propId) {
            if (propId == IEditorPart.PROP_DIRTY && !((ITextEditor) source).isDirty()) {
              updateAnnotations(true);
            }
          }
        });
  }
Пример #22
0
  /**
   * Propagates all markers of the given file
   *
   * @param markers
   * @param file
   */
  private void propagateMarkers(AbstractCollection<IMarker> markers, IFile file) {
    if (!file.exists()) {
      return;
    }

    String content = getFileContent(file);
    LinkedList<FSTField> fields = new LinkedList<FSTField>();
    LinkedList<FSTMethod> methods = new LinkedList<FSTMethod>();
    IFeatureProject project = CorePlugin.getFeatureProject(file);
    if (project == null) {
      return;
    }
    FSTModel model = project.getFSTModel();
    if (model == null) {
      return;
    }
    for (FSTFeature f : model.getFeaturesMap().values()) {
      TreeMap<String, FSTClass> z = f.getClasses();
      String fileName = file.getName();
      if (z.containsKey(fileName)) {
        FSTClass c = z.get(fileName);
        for (FSTField field : c.getFields()) {
          fields.add(field);
        }
        for (FSTMethod method : c.getMethods()) {
          methods.add(method);
        }
      }
    }
    setElementLines(content, fields, methods);

    for (IMarker marker : markers) {
      if (!marker.exists()) {
        continue;
      }

      if (marker.getAttribute(IMarker.MESSAGE, "").startsWith("The import")) {
        propagateUnsupportedMarker(marker, file);
        continue;
      }
      int markerLine = marker.getAttribute(IMarker.LINE_NUMBER, -1);
      if (markerLine == -1) {
        continue;
      }

      boolean propagated = false;
      for (FSTField f : fields) {
        if (f.getEndLine() == -1) {
          continue;
        }
        int composedLine = f.getComposedLine();
        if (markerLine >= composedLine
            && markerLine <= composedLine + (f.getEndLine() - f.getBeginLine())) {
          propagateMarker(marker, f.getOwnFile(), f.getBeginLine() + markerLine - composedLine);
          propagated = true;
          break;
        }
      }

      if (propagated) {
        continue;
      }

      for (FSTMethod m : methods) {
        if (m.getEndLine() == -1) {
          continue;
        }
        int composedLine = m.getComposedLine();
        if (markerLine >= composedLine
            && markerLine <= composedLine + (m.getEndLine() - m.getBeginLine())) {
          propagateMarker(
              marker, m.getOwnFile(), m.getBeginLine() + markerLine - m.getComposedLine());
          propagated = true;
          break;
        }
      }

      if (propagated) {
        continue;
      }

      propagateUnsupportedMarker(marker, file);
    }
  }