protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } { List<SNode> nodes = event.getData(MPSCommonDataKeys.NODES); boolean error = false; if (nodes != null) { for (SNode node : ListSequence.fromList(nodes)) { if (!(SNodeOperations.isInstanceOf( node, "jetbrains.mps.lang.core.structure.BaseConcept"))) { error = true; break; } } } if (error || nodes == null) { MapSequence.fromMap(_params).put("nodes", null); } else { MapSequence.fromMap(_params) .put("nodes", ListSequence.fromListWithValues(new ArrayList<SNode>(), nodes)); } } if (MapSequence.fromMap(_params).get("nodes") == null) { return false; } MapSequence.fromMap(_params).put("project", event.getData(MPSCommonDataKeys.MPS_PROJECT)); if (MapSequence.fromMap(_params).get("project") == null) { return false; } return true; }
public boolean isApplicable(AnActionEvent event, final Map<String, Object> _params) { List<SModel> models = ListSequence.fromListWithValues( new ArrayList<SModel>(), (Iterable<SModel>) VcsActionsUtil.getModels( ((VirtualFile[]) MapSequence.fromMap(_params).get("virtualFiles")))); if (!(VcsActionsUtil.isMakePluginInstalled()) || IMakeService.INSTANCE.get().isSessionActive() || ListSequence.fromList(models).isEmpty()) { return false; } String text = new MakeActionParameters( ((IOperationContext) MapSequence.fromMap(_params).get("context")), models, ListSequence.fromList(models).first(), null, null) .actionText(MakeOrRebuildModelsFromChangeList_Action.this.rebuild); if (text != null) { event.getPresentation().setText(text); return true; } return false; }
public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) { try { List<SModel> models = ListSequence.fromListWithValues( new ArrayList<SModel>(), (Iterable<SModel>) VcsActionsUtil.getModels( ((VirtualFile[]) MapSequence.fromMap(_params).get("virtualFiles")))); new MakeActionImpl( ((IOperationContext) MapSequence.fromMap(_params).get("context")), new MakeActionParameters( ((IOperationContext) MapSequence.fromMap(_params).get("context")), models, ListSequence.fromList(models).first(), null, null), MakeOrRebuildModelsFromChangeList_Action.this.rebuild) .executeAction(); } catch (Throwable t) { if (LOG.isEnabledFor(Priority.ERROR)) { LOG.error( "User's action execute method failed. Action:" + "MakeOrRebuildModelsFromChangeList", t); } } }
protected void validateImports() { SModelInternal modelInternal = (SModelInternal) myModel; for (SModuleReference devKit : ListSequence.fromListWithValues( new ArrayList<SModuleReference>(), modelInternal.importedDevkits())) { modelInternal.deleteDevKit(devKit); } for (SLanguage language : ListSequence.fromListWithValues( new ArrayList<SLanguage>(), modelInternal.importedLanguageIds())) { modelInternal.deleteLanguageId(language); } for (jetbrains.mps.smodel.SModel.ImportElement model : ListSequence.fromListWithValues( new ArrayList<jetbrains.mps.smodel.SModel.ImportElement>(), modelInternal.importedModels())) { modelInternal.deleteModelImport(model.getModelReference()); } addBuiltInImports(); TemporaryModels.getInstance().addMissingImports(myModel); }
@Override protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } { List<SNode> nodes = event.getData(MPSCommonDataKeys.NODES); if (nodes == null) { MapSequence.fromMap(_params).put("nodes", null); } else { MapSequence.fromMap(_params) .put("nodes", ListSequence.fromListWithValues(new ArrayList<SNode>(), nodes)); } if (nodes == null) { return false; } } return true; }
/*package*/ List<String> fetchExistingPackages( List<SNode> nlist, final Map<String, Object> _params) { Set<SModel> models = SetSequence.fromSetWithValues( new HashSet<SModel>(), ListSequence.fromList(nlist) .select( new ISelector<SNode, SModel>() { public SModel select(SNode n) { return SNodeOperations.getModel(n); } })); Set<String> packages = SetSequence.fromSetWithValues( new HashSet<String>(), SetSequence.fromSet(models) .translate( new ITranslator2<SModel, SNode>() { public Iterable<SNode> translate(SModel m) { return jetbrains.mps.lang.smodel.generator.smodelAdapter.SModelOperations .getRoots(m, "jetbrains.mps.lang.core.structure.BaseConcept"); } }) .select( new ISelector<SNode, String>() { public String select(SNode r) { return SPropertyOperations.getString(r, "virtualPackage"); } }) .where( new IWhereFilter<String>() { public boolean accept(String p) { return p != null; } })); List<String> result = ListSequence.fromListWithValues(new ArrayList<String>(), packages); Collections.sort(result); return result; }
@Override protected void doRefactoringAction() { final boolean needToRegenerate = myRegenerateLanguage.getModel().isSelected(); final String fqName = getCurrentValue(); if (MPSModuleRepository.getInstance().getModuleByFqName(fqName) != null) { setErrorText("Duplicate language name"); return; } if (!((SourceVersion.isName(fqName)))) { setErrorText("Language namespace should be valid Java package"); return; } final LanguageRenamer renamer = new LanguageRenamer(myProject, myLanguage, fqName); ModelAccess.instance() .runWriteActionInCommand( new Runnable() { public void run() { renamer.rename(needToRegenerate); renamer.update(); } }); if (needToRegenerate) { final Set<Language> langs = new LinkedHashSet<Language>(); ModelAccess.instance() .runReadAction( new Runnable() { @Override public void run() { langs.add(myLanguage); langs.addAll( ModuleRepositoryFacade.getInstance().getAllExtendingLanguages(myLanguage)); } }); for (final Language l : langs) { GenParameters params = ModelAccess.instance() .runReadAction( new Computable<GenParameters>() { @Override public GenParameters compute() { ModuleTestConfiguration languageConfig = new ModuleTestConfiguration(); languageConfig.setModuleRef(l.getModuleReference()); languageConfig.setName("tmp"); try { return languageConfig.getGenParams( myProject.getComponent(MPSProject.class), true); } catch (IllegalGeneratorConfigurationException e) { return null; } } }); if (params == null) { setErrorText("Rebuild configuration is invalid"); return; } ModuleContext context = new ModuleContext(myLanguage, ProjectHelper.toMPSProject(myProject)); MakeSession sess = new MakeSession(context); if (IMakeService.INSTANCE.get().openNewSession(sess)) { IMakeService.INSTANCE .get() .make( sess, new ModelsToResources( context, ListSequence.fromListWithValues( new ArrayList<SModel>(), (Iterable<SModel>) params.getModelDescriptors())) .resources(false)); } // GeneratorUIFacade.getInstance().generateModels(new ModuleContext(myLanguage, // myProject), params.getModelDescriptors(), // GeneratorUIFacade.getInstance().getDefaultGenerationHandler(), true, false); } } super.doRefactoringAction(); }
@Override public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) { final List<SModel> modelDescriptors = ListSequence.fromListWithValues( new ArrayList<SModel>(), Sequence.fromIterable( ((Iterable<SModel>) ((MPSProject) MapSequence.fromMap(_params).get("mpsProject")) .getProjectModels())) .where( new IWhereFilter<SModel>() { public boolean accept(SModel md) { return SModelStereotype.isUserModel(md); } })); ModelCheckerTool.getInstance(((Project) MapSequence.fromMap(_params).get("project"))) .checkModelsAndShowResult(modelDescriptors, new ReferenceableConceptsChecker()); // extra debug final Wrappers._int total = new Wrappers._int(); final Wrappers._int referenceable = new Wrappers._int(); final Map<String, Integer> used = MapSequence.fromMap(new HashMap<String, Integer>()); ((MPSProject) MapSequence.fromMap(_params).get("mpsProject")) .getModelAccess() .runReadAction( new Runnable() { public void run() { ListSequence.fromList(modelDescriptors) .visitAll( new IVisitor<SModel>() { public void visit(SModel it) { for (SNode n : it.getRootNodes()) { for (SNode i : SNodeOperations.getNodeDescendants( n, null, true, new SAbstractConcept[] {})) { SNode ccp = SNodeOperations.as( SNodeOperations.asNode(SNodeOperations.getConcept(i)), MetaAdapterFactory.getConcept( 0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979ba0450L, "jetbrains.mps.lang.structure.structure.ConceptDeclaration")); if (ccp != null) { total.value++; if (!(SPropertyOperations.hasValue( ccp, MetaAdapterFactory.getProperty( 0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979ba0450L, 0x4b014033eedc8a48L, "staticScope"), "none", null))) { referenceable.value++; String cname = ((String) BHReflection.invoke( ccp, SMethodTrimmedId.create( "getFqName", null, "hEwIO9y"))); if (MapSequence.fromMap(used).containsKey(cname)) { MapSequence.fromMap(used) .put(cname, MapSequence.fromMap(used).get(cname) + 1); } else { MapSequence.fromMap(used).put(cname, 1); } } } } } } }); } }); String[] usedNames = SetSequence.fromSet(MapSequence.fromMap(used).keySet()).toGenericArray(String.class); Arrays.sort( usedNames, new Comparator<String>() { public int compare(String a, String b) { return new Integer(MapSequence.fromMap(used).get(a)) .compareTo(MapSequence.fromMap(used).get(b)); } }); System.out.println( "" + referenceable.value + " out of " + total.value + " nodes are referenceable"); for (String s : usedNames) { System.out.println(MapSequence.fromMap(used).get(s) + " " + s); } }