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; }
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)); }
public void stopListening() { if (!SModelStereotype.isStubModelStereotype(myModel.getStereotype())) { ModelGenerationStatusManager.getInstance().removeGenerationStatusListener(myStatusListener); } myModel.removeModelListener(mySimpleModelListener); SModelEventsDispatcher.getInstance().unregisterListener(myEventsListener); }
public void startListening() { visitNode(myTreeNode); SModelEventsDispatcher.getInstance().registerListener(myEventsListener); myModel.addModelListener(mySimpleModelListener); if (!SModelStereotype.isStubModelStereotype(myModel.getStereotype())) { ModelGenerationStatusManager.getInstance().addGenerationStatusListener(myStatusListener); } }