@Override
    protected void invalidateNode(SNode sNode) {
      NodePath affPath = NodePath.forSNode(sNode);
      SModel containingModel = sNode.getContainingModel();
      if (containingModel == null) return;

      SModelReference mref = containingModel.getReference();
      List<NodePath> nodePaths = nodePaths(mref);
      ListIterator<NodePath> npathIt = nodePaths.listIterator();
      while (npathIt.hasNext()) {
        NodePath path = npathIt.next();
        NodePath lcp = affPath.findLowestCommonParent(path);
        if (lcp != null) {
          if (lcp.equals(path)) break;
          // replace with the LCP and stop
          npathIt.remove();
          npathIt.add(lcp);
          break;
        }
      }
      if (!npathIt.hasNext()) {
        // not found -> just add
        nodePaths.add(affPath);
      }
    }
Exemple #2
0
  @Override
  public org.jetbrains.mps.openapi.model.SModel resolve(
      org.jetbrains.mps.openapi.model.SModelReference reference) {
    if (reference == null) {
      return null;
    }

    SModel model = SModelRepository.getInstance().getModelDescriptor(reference.getModelId());

    if (model == null) {
      return null;
    }

    synchronized (LOCK) {
      initialize();

      if (myVisibleModules.contains(model.getModule())) return model;

      for (Language l : myUsedLanguages) {
        if (l.getAccessoryModels().contains(model)) return model;
      }
    }

    return null;
  }
Exemple #3
0
 public static Collection<String> getUsedLanguageNamespaces(
     SModel model, boolean isTemplateModel) {
   if (isTemplateModel) {
     return getUsedLanguageNamespacesInTemplateModel(model);
   }
   if (SModelStereotype.isGeneratorModel(model)) {
     TemplateModelScanner templateModelScanner = new TemplateModelScanner(model);
     templateModelScanner.scan();
     Set<String> namespaces = new HashSet<String>(templateModelScanner.getQueryLanguages());
     for (SModuleReference ref :
         ((jetbrains.mps.smodel.SModelInternal) model).engagedOnGenerationLanguages()) {
       namespaces.add(ref.getModuleName());
     }
     return namespaces;
   }
   Set<String> namespaces = new HashSet<String>();
   for (SModuleReference ref :
       ((jetbrains.mps.smodel.SModelInternal) model).engagedOnGenerationLanguages()) {
     namespaces.add(ref.getModuleName());
   }
   for (SNode root : model.getRootNodes()) {
     namespaces.add(NameUtil.namespaceFromConceptFQName(root.getConcept().getId()));
     for (SNode child : jetbrains.mps.util.SNodeOperations.getDescendants(root, null)) {
       namespaces.add(NameUtil.namespaceFromConceptFQName(child.getConcept().getId()));
     }
   }
   // empty behavior model should have it's behavior aspect descriptor generated
   if (model.getModule() instanceof Language && LanguageAspect.BEHAVIOR.is(model)) {
     namespaces.add(BootstrapLanguages.BEHAVIOR.getModuleName());
   }
   return namespaces;
 }
 private void registerLanguageKeyMaps(Language language) {
   SModel editorModelDescriptor = LanguageAspect.EDITOR.get(language);
   SModel editorModel = (editorModelDescriptor != null ? editorModelDescriptor.getSModel() : null);
   List<KeyMap> keyMaps;
   if (editorModel != null) {
     keyMaps = ListSequence.fromList(new ArrayList<KeyMap>());
     for (SNode keyMapDeclaration :
         ListSequence.fromList(
             SModelOperations.getRoots(
                 editorModel, "jetbrains.mps.lang.editor.structure.CellKeyMapDeclaration"))) {
       try {
         Class<KeyMap> keyMapClass = findKeyMapClassByDeclaration(keyMapDeclaration);
         if (keyMapClass != null) {
           KeyMap keyMap = keyMapClass.newInstance();
           if (keyMap.isApplicableToEveryModel()) {
             ListSequence.fromList(keyMaps).addElement(keyMap);
           }
         }
       } catch (Throwable t) {
         LOG.error(t);
       }
     }
   } else {
     keyMaps = Collections.emptyList();
   }
   MapSequence.fromMap(myLanguagesToKeyMaps).put(language, keyMaps);
 }
Exemple #5
0
  private void rehighlightNode(@NotNull MPSTreeNode node, @NotNull Feature feature) {
    unhighlightNode(node);

    SModel model = SModelRepository.getInstance().getModelDescriptor(feature.getModelReference());
    if (model instanceof EditableSModel && !(model.isReadOnly())) {
      if (feature instanceof ModelFeature) {
        // do not try to compute changes in case we need only model status
        TreeMessage message = getMessage((ModelFeature) feature);
        if (message != null) {
          node.addTreeMessage(message);
        }
        return;
      }

      EditableSModel emd = (EditableSModel) model;
      myRegistry.getCurrentDifference(emd).setEnabled(true);

      ModelChange change = myMap.get(feature);
      if (change == null) {
        change = myMap.getAddedAncestorValue(feature);
      }
      if (change != null) {
        node.addTreeMessage(getMessage(change, emd));
      } else if (myMap.isAncestorOfAddedFeature(feature)) {
        node.addTreeMessage(getMessage(FileStatus.MODIFIED));
      }
    }
  }
  @Override
  public SearchResults find(SearchQuery query, @NotNull ProgressMonitor monitor) {
    SearchResults<SNode> searchResults = new SearchResults<SNode>();
    Object value = query.getObjectHolder().getObject();
    SModule module = null;
    if (value instanceof SModule) {
      module = ((SModule) value);
    } else if (value instanceof SModuleReference) {
      module = query.getScope().resolve(((SModuleReference) value));
    }
    if (!(module instanceof Language)) {
      return searchResults;
    }
    Language language = (Language) module;
    SModel structureModel = language.getStructureModelDescriptor();
    if (structureModel == null) {
      return searchResults;
    }
    if (!(structureModel.getRootNodes().iterator().hasNext())) {
      return searchResults;
    }
    List<SNode> roots = new LinkedList<SNode>();
    for (SNode root : structureModel.getRootNodes()) {
      roots.add(root);
    }
    searchResults.getSearchedNodes().addAll(roots);

    monitor.start("", IterableUtil.asCollection(structureModel.getRootNodes()).size() + 1);
    try {
      SearchResults<SModel> modelResults =
          FindUtils.getSearchResults(
              monitor.subTask(1),
              new SearchQuery(
                  structureModel.getReference(), GlobalScopeMinusTransient.getInstance()),
              new ModelImportsUsagesFinder());
      List<SModel> models = new ArrayList<SModel>();
      for (SearchResult<SModel> sModelSearchResult : modelResults.getSearchResults()) {
        models.add(sModelSearchResult.getObject());
      }
      SearchScope scope = new ModelsScope(models.toArray(new SModel[models.size()]));
      SearchResults<SNode> results = new SearchResults();
      for (SNode node : roots) {
        if (monitor.isCanceled()) {
          break;
        }
        results.addAll(
            FindUtils.getSearchResults(
                monitor.subTask(1),
                node,
                scope,
                "jetbrains.mps.lang.structure.findUsages.NodeUsages_Finder"));
        results.removeDuplicates();
      }
      searchResults.getSearchResults().addAll(results.getSearchResults());
      return searchResults;
    } finally {
      monitor.done();
    }
  }
Exemple #7
0
 @Override
 public void fileStatusChanged(@NotNull VirtualFile file) {
   IFile ifile = VirtualFileUtils.toIFile(file);
   SModel emd = SModelFileTracker.getInstance().findModel(ifile);
   if (emd != null) {
     rehighlightFeatureAndDescendants(new ModelFeature(emd.getReference()));
   }
 }
 @Override
 public boolean met(MPSTreeNode node) {
   if (!(node instanceof SModelTreeNode)) return false;
   SModelTreeNode modelNode = (SModelTreeNode) node;
   SModel modelDescriptor = modelNode.getSModelDescriptor();
   SModelReference modelReference = modelDescriptor.getReference();
   return modelReference.equals(myModel.getReference());
 }
Exemple #9
0
 public static SNode getBinaryOperationType(SNode leftType, SNode rightType, boolean mayBeString) {
   List<SNode> leastCommonSupertypes =
       SubtypingUtil.leastCommonSuperTypes(Arrays.asList(leftType, rightType), null);
   if (mayBeString) {
     SModel javaLangJavaStubModelDescriptor =
         SModelRepository.getInstance()
             .getModelDescriptor(SModelReference.fromString("java.lang@java_stub"));
     assert javaLangJavaStubModelDescriptor != null;
     SModel javaLang = javaLangJavaStubModelDescriptor.getSModel();
     SNode stringClass = SModelOperations.getRootByName(javaLang, "String");
     if (SNodeOperations.isInstanceOf(
                 leftType, "jetbrains.mps.baseLanguage.structure.ClassifierType")
             && SLinkOperations.getTarget(
                     (SNodeOperations.cast(
                         leftType, "jetbrains.mps.baseLanguage.structure.ClassifierType")),
                     "classifier",
                     false)
                 == stringClass
         || SNodeOperations.isInstanceOf(
                 rightType, "jetbrains.mps.baseLanguage.structure.ClassifierType")
             && SLinkOperations.getTarget(
                     (SNodeOperations.cast(
                         rightType, "jetbrains.mps.baseLanguage.structure.ClassifierType")),
                     "classifier",
                     false)
                 == stringClass) {
       SNode classifierType =
           SConceptOperations.createNewNode(
               "jetbrains.mps.baseLanguage.structure.ClassifierType", null);
       SLinkOperations.setTarget(
           classifierType,
           "classifier",
           SNodeOperations.cast(stringClass, "jetbrains.mps.baseLanguage.structure.Classifier"),
           false);
       return classifierType;
     }
   }
   if (leastCommonSupertypes.isEmpty()) {
     SNode runtimeErrorType =
         SConceptOperations.createNewNode(
             "jetbrains.mps.lang.typesystem.structure.RuntimeErrorType", null);
     SPropertyOperations.set(runtimeErrorType, "errorText", "incompatible types");
     return runtimeErrorType;
   }
   SNode type = leastCommonSupertypes.iterator().next();
   {
     IMatchingPattern pattern_j6k1pf_e0c =
         HUtil.createMatchingPatternByConceptFQName(
             "jetbrains.mps.baseLanguage.structure.PrimitiveType");
     SNode coercedNode_j6k1pf_e0c =
         TypeChecker.getInstance().getRuntimeSupport().coerce_(type, pattern_j6k1pf_e0c);
     if (coercedNode_j6k1pf_e0c != null) {
       return coercedNode_j6k1pf_e0c;
     } else {
       return type;
     }
   }
 }
  private static String asString(MappingConfig_AbstractRef mappingRef, boolean moreDetails) {
    if (mappingRef instanceof MappingConfig_RefAllLocal) {
      return "*";
    }
    if (mappingRef instanceof MappingConfig_RefAllGlobal) {
      return "[*:*]";
    }

    if (mappingRef instanceof MappingConfig_RefSet) {
      String s = "{";
      int count = ((MappingConfig_RefSet) mappingRef).getMappingConfigs().size();
      for (MappingConfig_AbstractRef mappingSimpleRef :
          ((MappingConfig_RefSet) mappingRef).getMappingConfigs()) {
        count--;
        s = s + asString(mappingSimpleRef, moreDetails);
        if (count > 0) s += ", ";
      }
      return s + "}";
    }

    if (mappingRef instanceof MappingConfig_SimpleRef) {
      final String modelUID = ((MappingConfig_SimpleRef) mappingRef).getModelUID();
      final String nodeID = ((MappingConfig_SimpleRef) mappingRef).getNodeID();
      final SModelReference modelReference =
          PersistenceFacade.getInstance().createModelReference(modelUID);
      String modelName =
          moreDetails
              ? SModelStereotype.withoutStereotype(modelReference.getModelName())
              : NameUtil.shortNameFromLongName(
                  SModelStereotype.withoutStereotype(modelReference.getModelName()));
      StringBuilder sb = new StringBuilder();
      sb.append(modelName);
      sb.append('.');
      if (nodeID.equals("*")) {
        return sb.append('*').toString();
      } else {
        SModel refModel = SModelRepository.getInstance().getModelDescriptor(modelReference);
        if (refModel != null) {
          SNodeId nodeId = PersistenceFacade.getInstance().createNodeId(nodeID);
          assert nodeId != null : "wrong node id string";
          SNode mappingConfig = refModel.getNode(nodeId);
          if (mappingConfig != null) {
            return sb.append(mappingConfig.getName()).toString();
          }
        }
      }
      return sb.append(nodeID).append("!unresolved!").toString();
    }

    if (mappingRef instanceof MappingConfig_ExternalRef) {
      SModuleReference generatorRef = ((MappingConfig_ExternalRef) mappingRef).getGenerator();
      MappingConfig_AbstractRef extMappingRef =
          ((MappingConfig_ExternalRef) mappingRef).getMappingConfig();
      return "[" + asString(generatorRef) + ":" + asString(extMappingRef, moreDetails) + "]";
    }

    return "???";
  }
  @Override
  public void findTargets(
      TargetKind kind,
      Collection<SModel> scope,
      Consumer<NavigationTarget> consumer,
      Consumer<SModel> processedConsumer) {
    final ID<Integer, List<SNodeDescriptor>> indexName = RootNodeNameIndex.NAME;
    final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();

    for (SModel sm : scope) {
      if (sm instanceof EditableSModel && ((EditableSModel) sm).isChanged()) {
        continue;
      }

      DataSource source = sm.getSource();
      if (!(source instanceof FileDataSource)) {
        continue;
      }

      IFile modelFile = ((FileDataSource) source).getFile();
      String ext = FileUtil.getExtension(modelFile.getName());
      if (ext == null
          || modelFile.isDirectory()
          || !(supportedExtensions.contains(ext.toLowerCase()))) {
        continue;
      }

      VirtualFile vf = VirtualFileUtils.getVirtualFile(modelFile);
      if (vf == null) continue; // e.g. model was deleted

      int fileId = FileBasedIndex.getFileId(vf);
      ConcreteFilesGlobalSearchScope fileScope =
          new ConcreteFilesGlobalSearchScope(Collections.singleton(vf));
      List<List<SNodeDescriptor>> descriptors =
          fileBasedIndex.getValues(indexName, fileId, fileScope);
      if (descriptors.isEmpty()) continue;

      boolean needToLoad = false;
      for (NavigationTarget snd : descriptors.get(0)) {
        PropertyConstraintsDescriptor descriptor =
            ConceptRegistry.getInstance()
                .getConstraintsDescriptor(snd.getConcept().getQualifiedName())
                .getProperty(SNodeUtil.property_INamedConcept_name);
        if (descriptor instanceof BasePropertyConstraintsDescriptor
            && !((BasePropertyConstraintsDescriptor) descriptor).isGetterDefault()) {
          needToLoad = true;
          break;
        }
      }

      if (!needToLoad) {
        for (SNodeDescriptor desc : descriptors.get(0)) {
          consumer.consume(desc);
        }
        processedConsumer.consume(sm);
      }
    }
  }
Exemple #12
0
 /**
  * @deprecated factory method that requires cast to implementation. why not API way to do the
  *     same?
  */
 @Deprecated
 @ToRemove(version = 3.3)
 public SModelReference update() {
   SModel sm = SModelRepository.getInstance().getModelDescriptor(this);
   if (sm == null) return this;
   SModelReference reference = (SModelReference) sm.getReference();
   return new SModelReference(
       reference.getModuleReference(), reference.getModelId(), reference.getModelName());
 }
Exemple #13
0
  public static void assertDeepModelEquals(SModel expectedModel, SModel actualModel) {
    ModelAccess.instance().checkReadAccess();

    assertSameImports(expectedModel, actualModel);
    assertSameModelImports(expectedModel, actualModel);
    assertSameLanguageAspects(expectedModel, actualModel);

    assertSameNodesCollections("root", expectedModel.getRootNodes(), actualModel.getRootNodes());
  }
Exemple #14
0
  @Override
  public Set<SReference> search(
      Set<SNode> nodes, @NotNull SearchScope scope, @NotNull ProgressMonitor monitor) {
    final HashSet<SReference> rv = new HashSet<SReference>();
    CollectConsumer<SReference> consumer = new CollectConsumer<SReference>(rv);
    Collection<FindUsagesParticipant> participants =
        PersistenceRegistry.getInstance().getFindUsagesParticipants();

    monitor.start("Finding usages...", participants.size() + 4);
    try {
      Collection<SModel> current = new LinkedHashSet<SModel>();
      Collection<SModel> simpleSearch = new LinkedHashSet<SModel>();
      for (SModel m : IterableUtil.asCollection(scope.getModels())) {
        if (m instanceof EditableSModel && ((EditableSModel) m).isChanged()) {
          simpleSearch.add(m);
        } else {
          current.add(m);
        }
      }

      for (FindUsagesParticipant participant : participants) {
        final Set<SModel> next = new HashSet<SModel>(current);
        participant.findUsages(
            current,
            nodes,
            consumer,
            new Consumer<SModel>() {
              @Override
              public void consume(SModel sModel) {
                assert !(sModel instanceof EditableSModel && ((EditableSModel) sModel).isChanged());
                next.remove(sModel);
              }
            });
        current = next;
        monitor.advance(1);
      }

      ProgressMonitor subMonitor = monitor.subTask(4, SubProgressKind.DEFAULT);
      subMonitor.start("", current.size() + simpleSearch.size());
      NodeUsageFinder nf = new NodeUsageFinder(nodes, consumer);
      showNoFastFindTipIfNeeded(current);
      current.addAll(simpleSearch);
      for (SModel m : current) {
        subMonitor.step(m.getModelName());
        nf.collectUsages(m);
        if (monitor.isCanceled()) {
          break;
        }
        subMonitor.advance(1);
      }
      subMonitor.done();
    } finally {
      monitor.done();
    }
    return rv;
  }
Exemple #15
0
  public static Collection<SModel> getModifiedModels(Collection<? extends SModel> models) {
    Set<SModel> result = new LinkedHashSet<SModel>();
    ModelGenerationStatusManager statusManager = ModelGenerationStatusManager.getInstance();
    for (SModel sm : models) {
      if (statusManager.generationRequired(sm)) {
        result.add(sm);
        continue;
      }

      // TODO regenerating all dependant models can be slow, option?
      if (!(SModelStereotype.DESCRIPTOR.equals(SModelStereotype.getStereotype(sm))
          || LanguageAspect.BEHAVIOR.is(sm)
          || LanguageAspect.CONSTRAINTS.is(sm))) {
        // temporary solution: only descriptor/behavior/constraints models
        continue;
      }

      final SRepository repository = sm.getRepository();
      if (repository == null) {
        // no idea how to treat a model which hands in the air; expect it to be editable and tell
        // isChanged if desires re-generation
        continue;
      }
      GenerationDependencies oldDependencies = GenerationDependenciesCache.getInstance().get(sm);
      // FIXME use SRepository to pick proper GenerationDependenciesCache instance
      if (oldDependencies == null) {
        // TODO turn on when generated file will be mandatory
        // result.add(sm);
        continue;
      }

      Map<String, String> externalHashes = oldDependencies.getExternalHashes();
      for (Entry<String, String> entry : externalHashes.entrySet()) {
        String modelReference = entry.getKey();
        SModel rmd =
            PersistenceFacade.getInstance()
                .createModelReference(modelReference)
                .resolve(repository);
        if (rmd == null) {
          result.add(sm);
          break;
        }
        String oldHash = entry.getValue();
        if (oldHash == null) {
          continue;
        }
        String newHash = statusManager.currentHash(rmd);
        if (newHash == null || !oldHash.equals(newHash)) {
          result.add(sm);
          break;
        }
      }
    }

    return result;
  }
Exemple #16
0
  private void fillCacheWithModels(Pair<SModuleReference, String> key, Iterable<SModel> models) {
    if (!myStubModulesCache.containsKey(key)) {
      myStubModulesCache.put(key, new HashSet<SModelReference>());
    }

    for (SModel model : models) {
      if (!model.getReference().getModelName().equals(key.o2)) continue;
      Set<SModelReference> modelsFromCache = myStubModulesCache.get(key);
      modelsFromCache.add(model.getReference());
    }
  }
Exemple #17
0
 public org.jetbrains.mps.openapi.model.SNode getRoot(int oneBasedIndex) {
   assert myModel != null : "call createModel() first";
   for (SNode r : myModel.getRootNodes()) {
     if (--oneBasedIndex > 0) {
       continue;
     }
     return r;
   }
   throw new IllegalArgumentException(
       Integer.toString(IterableUtil.asCollection(myModel.getRootNodes()).size()));
 }
  protected String calculateAdditionalText() {
    if (getNode() == null) {
      return null;
    }

    SModel model = SNodeOperations.getModel(getNode());
    if (model == null) {
      return null;
    }

    return model.getReference().getModelName();
  }
Exemple #19
0
  public SModel createModel(SModel originalModel) {
    String originalLong = SNodeOperations.getModelLongName(originalModel);
    String newModelName = originalLong + "@999";
    while (!isValidName(newModelName)) {
      newModelName += "_";
    }

    SModel result = new TestSModelDescriptor(newModelName, originalModel);

    myModels.put(result.getReference().getModelName(), result);
    return result;
  }
Exemple #20
0
  private void doUpdateModelsSet() {
    assertCanChange();

    for (SModel model : getModels()) {
      if (model instanceof EditableSModel && ((EditableSModel) model).isChanged()) {
        LOG.warn(
            "Trying to reload module "
                + getModuleName()
                + " which contains a non-saved model '"
                + model.getName()
                + "'. To prevent data loss, MPS will not update models in this module. "
                + "Please save your work and restart MPS. See MPS-18743 for details.");
        return;
      }
    }

    Set<ModelRoot> toRemove = new HashSet<ModelRoot>(mySModelRoots);
    Set<ModelRoot> toUpdate = new HashSet<ModelRoot>(mySModelRoots);
    Set<ModelRoot> toAttach = new HashSet<ModelRoot>();

    for (ModelRoot root : loadRoots()) {
      try {
        if (mySModelRoots.contains(root)) {
          toRemove.remove(root);
        } else {
          toAttach.add(root);
        }
      } catch (Exception e) {
        LOG.error(
            "Error loading models from root `"
                + root.getPresentation()
                + "'. Requested by: "
                + this,
            e);
      }
    }
    toUpdate.removeAll(toRemove);

    for (ModelRoot modelRoot : toRemove) {
      ((ModelRootBase) modelRoot).dispose();
    }
    mySModelRoots.removeAll(toRemove);
    for (ModelRoot modelRoot : toAttach) {
      ModelRootBase rootBase = (ModelRootBase) modelRoot;
      rootBase.setModule(this);
      mySModelRoots.add(modelRoot);
      rootBase.attach();
    }
    for (ModelRoot modelRoot : toUpdate) {
      ((ModelRootBase) modelRoot).update();
    }
  }
 @Override
 @Nullable
 public WarningPanel getWarningPanel(@NotNull SNode node, @NotNull Project project) {
   SModel model = node.getModel();
   if (model != null) {
     SModule module = model.getModule();
     if (module != null && module.isReadOnly()) {
       return new WarningPanel(
           this, "Warning: the node is in a read-only model. Your changes won't be saved");
     }
   }
   return null;
 }
  private boolean checkResolvedTarget(AbstractTemplateGenerator generator, SNode outputTargetNode) {
    Status status =
        generator
            .getReferentRoleValidator(myOutputSourceNode, myReferenceRole)
            .validate(outputTargetNode);
    if (status != null) {
      generator
          .getLogger()
          .error(
              myOutputSourceNode.getReference(),
              status.getMessage(getClass().getSimpleName()),
              getErrorDescriptions());
      return false;
    }

    SModel referentNodeModel = outputTargetNode.getModel();
    if (referentNodeModel != null && referentNodeModel != myOutputSourceNode.getModel()) {
      if (SModelStereotype.isGeneratorModel(referentNodeModel)) {
        // references to template nodes are not acceptable
        String msg = "bad reference, cannot refer to a generator model: %s for role '%s' in %s";
        generator
            .getLogger()
            .error(
                myOutputSourceNode.getReference(),
                String.format(
                    msg,
                    SNodeUtil.getDebugText(outputTargetNode),
                    myReferenceRole,
                    SNodeUtil.getDebugText(myOutputSourceNode)),
                getErrorDescriptions());
        return false;
      }
      if (referentNodeModel.getModule() instanceof TransientModelsModule) {
        // references to transient nodes in a model outside one being generated are not acceptable
        String msg =
            "bad reference, cannot refer to an external transient model: %s  for role '%s' in %s";
        generator
            .getLogger()
            .error(
                myOutputSourceNode.getReference(),
                String.format(
                    msg,
                    SNodeUtil.getDebugText(outputTargetNode),
                    myReferenceRole,
                    SNodeUtil.getDebugText(myOutputSourceNode)),
                getErrorDescriptions());
        return false;
      }
    }
    return true;
  }
Exemple #23
0
 @Override
 public SNode createDeclaration(ClassInfo ci) {
   String classname = ci.getDeclarationClass().getName();
   String name = this.myNamesMap.getNameForClass(ci.getDeclarationClass());
   if (ci.isInterface()) {
     SNode decl =
         Generator.GENERATOR.createInterfaceDeclaration(name, classname, ci.isDeprecated());
     myModel.addRootNode(decl);
     return decl;
   }
   SNode decl =
       Generator.GENERATOR.createDeclaration(
           name, classname, ci.isAbstract(), ci.canHaveInternalText(), ci.isDeprecated());
   myModel.addRootNode(decl);
   return decl;
 }
Exemple #24
0
  public void saveChanges() {
    if (!(myModelDescriptor instanceof EditableSModel)) {
      return;
    }

    addNewModels();
    removeUnusedModels();
    updateUsedLanguages();
    addNewDevKits();
    removeUnusedDevKits();
    addNewEngagedOnGenerationLanguages();
    removeUnusedEngagedOnGenerationLanguages();
    if (myModelDescriptor instanceof GeneratableSModel) {
      GeneratableSModel dmd = (GeneratableSModel) myModelDescriptor;
      if (dmd.isDoNotGenerate() != myDoNotGenerate) {
        dmd.setDoNotGenerate(myDoNotGenerate);
      }
      if (dmd.isGenerateIntoModelFolder() != myGenerateIntoModelFolder) {
        dmd.setGenerateIntoModelFolder(myGenerateIntoModelFolder);
      }
    }

    if (!(myModelDescriptor.getSource() instanceof NullDataSource)) {
      ((EditableSModel) myModelDescriptor).save();
    }

    new MissingDependenciesFixer(myModelDescriptor).fixModuleDependencies();
    // change of model properties might affect generation status. This explicit call is needed
    // unless model dispatch proper change events (which it does not at the moment), and project
    // pane
    // got no other means to find out it needs to update generation status
    ModelGenerationStatusManager.getInstance()
        .invalidateData(Collections.singleton(myModelDescriptor));
  }
  private static SModule getModuleForModel(MPSProject project, SModel model) {
    // language's and solution's own models (+generator models in language)
    SModule owner = model.getModule();
    SModule mainModule =
        owner instanceof Generator ? ((Generator) owner).getSourceLanguage() : owner;
    if (project.isProjectModule(mainModule)) return owner;

    // accessories models in languages
    /*
      //with this enabled, alt-f1 does not work in case node is in non-owned accessory model to a project language
      for (Language l : project.getProjectLanguages()) {
        if (l.isAccessoryModel(model.getSModelReference())) return l;
      }
    */

    // runtime models in languages
    for (Language l : project.getProjectModules(Language.class)) {
      for (SModuleReference depModule : l.getRuntimeModulesReferences()) {
        if (depModule.equals(mainModule.getModuleReference())) return owner;
      }
    }

    // accessories models in devkits

    // runtime models in devkits

    return owner;
  }
 @Override
 protected boolean acceptModel(SModel model) {
   if (SModelStereotype.isStubModelStereotype(SModelStereotype.getStereotype(model))) {
     return false;
   }
   return acceptModule(model.getModule());
 }
Exemple #27
0
 @NotNull
 public SModule getModule(SModel model) {
   if (myGenerationContext != null) {
     return myGenerationContext.getOriginalInputModel().getModule();
   }
   return model.getModule();
 }
 @Override
 protected void invalidateModel(SModel sModel) {
   SModelReference mref = sModel.getReference();
   List<NodePath> nodePaths = nodePaths(mref);
   nodePaths.clear();
   nodePaths.add(NodePath.EMPTY);
 }
Exemple #29
0
 private static boolean check_6q36mf_a0a5a0a0a0f93(
     SModelReference checkedDotOperand, SModel myModel) {
   if (null != checkedDotOperand) {
     return checkedDotOperand.equals(myModel.getReference());
   }
   return false;
 }
 public void insertOrReplace(SNode newNode) {
   if (isNodeInPlace()) {
     SNodeUtil.replaceWithAnother(node, newNode);
   } else {
     model.addRootNode(newNode);
   }
 }