コード例 #1
0
  protected Collection<String> getSuggestedSignatures(Object object) {
    // Get all .itf in project and MindPath
    List<String> suggestedSignatures = getInterfacesInProject();

    // Get imports list
    if (object instanceof EObject) {
      EObject parent = (EObject) object;
      while (parent != null && !(parent instanceof AdlDefinition)) {
        parent = parent.eContainer();
      }
      if (parent != null) {
        // To avoid concurrent modifications
        List<String> toRemove = new ArrayList<String>();
        List<String> toAdd = new ArrayList<String>();

        EList<ImportDefinition> imports = ((AdlDefinition) parent).getImports();
        // We can use simple name for all .itf already imported
        // And add it at the beggining of the list
        for (ImportDefinition imp : imports) {
          String name = imp.getImportName();
          for (String signature : suggestedSignatures) {
            if (name.startsWith(signature)) {
              toRemove.add(signature);
              signature = name.substring(name.lastIndexOf(".") + 1);
              toAdd.add(0, signature);
            }
          }
        }
        suggestedSignatures.removeAll(toRemove);
        suggestedSignatures.addAll(0, toAdd);
      }
    }

    return suggestedSignatures;
  }
コード例 #2
0
  @SuppressWarnings("unchecked")
  protected Collection<ImportDefinition> getSuggestedImports(Object object) {
    Collection<ImportDefinition> oldImports =
        (Collection<ImportDefinition>) super.getChoiceOfValues(object);

    Collection<String> oldDefinitions = new ArrayList<String>();
    for (ImportDefinition importDefinition : oldImports) {
      oldDefinitions.add(importDefinition.getImportName());
    }

    Collection<ImportDefinition> suggestedImports = new ArrayList<ImportDefinition>();

    // Find the list of files in the project to suggest imports
    List<String> definitions = getFilesInProject();
    switch (range) {
        // TODO check range to return different values
        // see https://minalogic.net/tracker/?func=detail&aid=1285&atid=190&group_id=123
    }

    // Remove the current definition
    // TODO
    definitions.remove(ModelToProjectUtil.INSTANCE.getCurrentFQN());
    // Remove definitions already added
    definitions.removeAll(oldDefinitions);

    for (String definition : definitions) {
      ImportDefinition newImport = AdlPackage.eINSTANCE.getAdlFactory().createImportDefinition();
      newImport.setImportName(definition);
      suggestedImports.add(newImport);
    }

    return suggestedImports;
  }