package jetbrains.mps.lang.structure.pluginSolution.plugin; /*Generated by MPS */ import jetbrains.mps.refactoring.participant.RefactoringParticipantBase; import jetbrains.mps.baseLanguage.tuples.runtime.Tuples; import jetbrains.mps.lang.core.plugin.UpdateReferencesParticipantBase.NamedNodeReference; import org.jetbrains.mps.openapi.model.SNode; import jetbrains.mps.refactoring.participant.MoveNodeRefactoringParticipant; import jetbrains.mps.refactoring.participant.RefactoringParticipant; import org.jetbrains.mps.openapi.module.SModuleReference; import org.jetbrains.mps.openapi.module.SRepository; import jetbrains.mps.smodel.Language; import org.jetbrains.mps.openapi.model.SModel; import jetbrains.mps.smodel.LanguageAspect; import jetbrains.mps.internal.collections.runtime.ListSequence; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SModelOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import jetbrains.mps.internal.collections.runtime.IWhereFilter; import jetbrains.mps.lang.migration.behavior.IMigrationUnit__BehaviorDescriptor; import jetbrains.mps.smodel.structure.Extension; import java.util.List; import java.util.ArrayList; import org.jetbrains.mps.openapi.module.SearchScope; import jetbrains.mps.lang.core.plugin.UpdateReferencesParticipantBase; import jetbrains.mps.lang.smodel.query.runtime.CommandUtil; import jetbrains.mps.lang.smodel.query.runtime.QueryExecutionContext; import jetbrains.mps.internal.collections.runtime.CollectionSequence; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import jetbrains.mps.internal.collections.runtime.ISelector; import org.jetbrains.mps.openapi.module.SModule; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.ide.findusages.model.SearchResults; import jetbrains.mps.ide.findusages.model.SearchResult; import jetbrains.mps.refactoring.participant.RefactoringSession; import org.jetbrains.mps.openapi.persistence.PersistenceFacade; import jetbrains.mps.lang.typesystem.runtime.HUtil; import jetbrains.mps.lang.migration.util.NodeReferenceUtil; import jetbrains.mps.baseLanguage.tuples.runtime.MultiTuple; import jetbrains.mps.lang.migration.behavior.AbstractNodeReference__BehaviorDescriptor; import jetbrains.mps.lang.core.behavior.BaseConcept__BehaviorDescriptor; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations; import org.jetbrains.mps.openapi.model.SNodeReference; import jetbrains.mps.smodel.SModelUtil_new; public class WriteSubconceptMigrationParticipant extends RefactoringParticipantBase<Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef>, Void, SNode, SNode> implements MoveNodeRefactoringParticipant<Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef>, Void>, RefactoringParticipant.PersistentRefactoringParticipant<Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef>, Void, SNode, SNode> { public class MigrationScriptRef { private final SModuleReference languageRef; private final int version; public MigrationScriptRef(SModuleReference lRef, int v) { languageRef = lRef; version = v; } public SModuleReference getLanguage() { return languageRef; } public int getVersion() { return version; } public SNode resolve(SRepository repository) { Language resolve = ((Language) languageRef.resolve(repository)); SModel migrationModel = LanguageAspect.MIGRATION.get(resolve); return ListSequence.fromList(SModelOperations.roots(migrationModel, MetaAdapterFactory.getInterfaceConcept(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x47bb811da2acc4d6L, "jetbrains.mps.lang.migration.structure.IMigrationUnit"))).where(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return (int) IMigrationUnit__BehaviorDescriptor.fromVersion_id4uVwhQyFcnl.invoke(it) == version; } }).first(); } } public static class WriteSubconceptMigrationParticipant_extension extends Extension.Default<MoveNodeRefactoringParticipant<?, ?>> { public WriteSubconceptMigrationParticipant_extension() { super("jetbrains.mps.refactoring.participant.MoveNodeParticipantEP"); } public MoveNodeRefactoringParticipant<?, ?> get() { return new WriteSubconceptMigrationParticipant(); } } public static final RefactoringParticipant.Option OPTION = new RefactoringParticipant.Option("moveNode.options.handleSubconcepts", "Handle subconcepts"); public String getId() { return "moveNode.writeSubconceptMigration"; } @Override public List<RefactoringParticipant.Option> getAvailableOptions(Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef> initialState, SRepository repository) { return ListSequence.fromListAndArray(new ArrayList<RefactoringParticipant.Option>(), OPTION); } @Override public List<RefactoringParticipant.Change<Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef>, Void>> getChanges(final Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef> initialState, SRepository repository, List<RefactoringParticipant.Option> selectedOptions, SearchScope searchScope) { if (initialState == null || !(ListSequence.fromList(selectedOptions).contains(LanguageStructureMigrationParticipant.OPTION)) || !(ListSequence.fromList(selectedOptions).contains(UpdateReferencesParticipantBase.OPTION)) || !(ListSequence.fromList(selectedOptions).contains(OPTION)) || searchScope.resolve(initialState._1().getLanguage()) != null) { return ListSequence.fromList(new ArrayList<RefactoringParticipant.Change<Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef>, Void>>()); } { final SearchScope scope = CommandUtil.createScope(searchScope); QueryExecutionContext context = new QueryExecutionContext() { public SearchScope getDefaultSearchScope() { return scope; } }; List<SNode> subConcepts = ListSequence.fromList(new ArrayList<SNode>()); ListSequence.fromList(subConcepts).addSequence(CollectionSequence.fromCollection(CommandUtil.instances(CommandUtil.createConsoleScope(null, false, context), MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979ba0450L, "jetbrains.mps.lang.structure.structure.ConceptDeclaration"), false)).where(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return eq_8k3jue_a0a0a0a0a0a0a3a2a21(check_8k3jue_a0a0a0a0a0b0c0m(SLinkOperations.getTarget(it, MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979ba0450L, 0xf979be93cfL, "extends"))), initialState._0().reference()); } }).toListSequence()); ListSequence.fromList(subConcepts).addSequence(CollectionSequence.fromCollection(CommandUtil.instances(CommandUtil.createConsoleScope(null, false, context), MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103556dcafL, "jetbrains.mps.lang.structure.structure.InterfaceConceptDeclaration"), false)).where(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return ListSequence.fromList(SLinkOperations.getChildren(it, MetaAdapterFactory.getContainmentLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103556dcafL, 0x110356e9df4L, "extends"))).any(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return eq_8k3jue_a0a0a0a0a0a0a0a0a0a0a4a2a21(it.getReference(), initialState._0().reference()); } }); } }).toListSequence()); ListSequence.fromList(subConcepts).addSequence(CollectionSequence.fromCollection(CommandUtil.instances(CommandUtil.createConsoleScope(null, false, context), MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979ba0450L, "jetbrains.mps.lang.structure.structure.ConceptDeclaration"), false)).where(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return ListSequence.fromList(SLinkOperations.getChildren(it, MetaAdapterFactory.getContainmentLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979ba0450L, 0x110358d693eL, "implements"))).any(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return eq_8k3jue_a0a0a0a0a0a0a0a0a0a0a5a2a21(it.getReference(), initialState._0().reference()); } }); } }).toListSequence()); List<Language> subModules = ListSequence.fromList(subConcepts).select(new ISelector<SNode, SModule>() { public SModule select(SNode it) { return SNodeOperations.getModel(it).getModule(); } }).distinct().ofType(Language.class).toListSequence(); List<RefactoringParticipant.Change<Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef>, Void>> changes = ListSequence.fromList(subModules).select(new ISelector<Language, RefactoringParticipant.Change<Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef>, Void>>() { public RefactoringParticipant.Change<Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef>, Void> select(final Language subModule) { RefactoringParticipant.Change<Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef>, Void> change = new MoveNodeRefactoringParticipant.ChangeBase<Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef>, Void>() { public SearchResults getSearchResults() { SearchResults searchResults = new SearchResults(); searchResults.add(new SearchResult<SModule>(subModule, "induced migration script")); return searchResults; } public void confirm(Void finalState, SRepository repository, RefactoringSession refactoringSession) { LanguageStructureMigrationParticipant.MigrationBuilder migrationBuilder = LanguageStructureMigrationParticipant.MigrationBuilder.getBuilder(refactoringSession, subModule); migrationBuilder.addPart(createIncludeMigrationPart_8k3jue_a0a1a1a0a0a0a0a0a5a2a21(SNodeOperations.cast(initialState._1().resolve(repository), MetaAdapterFactory.getInterfaceConcept(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x47bb811da2acc4d6L, "jetbrains.mps.lang.migration.structure.IMigrationUnit")))); } }; return change; } }).toListSequence(); return changes; } } public SNode serializeInitialState(Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef> initialState) { return createConceptMigrationReference_8k3jue_a0a51(initialState._1().getVersion(), PersistenceFacade.getInstance().asString(initialState._1().getLanguage()), SNodeOperations.cast(HUtil.copyIfNecessary(NodeReferenceUtil.makeReflection(initialState._0().reference(), initialState._0().name())), MetaAdapterFactory.getConcept(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x2b3f57492c1648ccL, "jetbrains.mps.lang.migration.structure.AbstractNodeReference"))); } public Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef> deserializeInitialState(SNode serialized) { return MultiTuple.<NamedNodeReference,WriteSubconceptMigrationParticipant.MigrationScriptRef>from(new NamedNodeReference(AbstractNodeReference__BehaviorDescriptor.getNodeReference_id4uVwhQyQbdz.invoke(SLinkOperations.getTarget(serialized, MetaAdapterFactory.getContainmentLink(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x36182c4cf6238c95L, 0x36182c4cf6238c99L, "oldConcept"))), BaseConcept__BehaviorDescriptor.getPresentation_idhEwIMiw.invoke(SLinkOperations.getTarget(serialized, MetaAdapterFactory.getContainmentLink(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x36182c4cf6238c95L, 0x36182c4cf6238c99L, "oldConcept")))), new WriteSubconceptMigrationParticipant.MigrationScriptRef(PersistenceFacade.getInstance().createModuleReference(SPropertyOperations.getString(SLinkOperations.getTarget(serialized, MetaAdapterFactory.getContainmentLink(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x36182c4cf6238c95L, 0x36182c4cf6238c96L, "migrationScript")), MetaAdapterFactory.getProperty(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x66eed171c5f83bcaL, 0x66eed171c602da74L, "module"))), SPropertyOperations.getInteger(SLinkOperations.getTarget(serialized, MetaAdapterFactory.getContainmentLink(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x36182c4cf6238c95L, 0x36182c4cf6238c96L, "migrationScript")), MetaAdapterFactory.getProperty(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x66eed171c5f83bcaL, 0x66eed171c5f90222L, "fromVersion")))); } public SNode serializeFinalState(Void finalState) { return null; } public Void deserializeFinalState(SNode serialized) { return null; } private MoveNodeRefactoringParticipant.MoveNodeRefactoringDataCollector<Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef>, Void> myDataCollector = new MoveNodeRefactoringParticipant.MoveNodeRefactoringDataCollector<Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef>, Void>() { public Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef> beforeMove(SNode nodeToMove) { if (!(SNodeOperations.isInstanceOf(nodeToMove, MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103553c5ffL, "jetbrains.mps.lang.structure.structure.AbstractConceptDeclaration"))) || !(SNodeOperations.getModel(nodeToMove).getModule() instanceof Language)) { return null; } Language language = ((Language) SNodeOperations.getModel(nodeToMove).getModule()); return MultiTuple.<NamedNodeReference,WriteSubconceptMigrationParticipant.MigrationScriptRef>from(new NamedNodeReference(nodeToMove.getReference(), NodeReferenceUtil.getNodePresentation(nodeToMove)), new WriteSubconceptMigrationParticipant.MigrationScriptRef(language.getModuleReference(), language.getLanguageVersion())); } public Void afterMove(SNode movedNode) { return null; } }; public MoveNodeRefactoringParticipant.MoveNodeRefactoringDataCollector<Tuples._2<NamedNodeReference, WriteSubconceptMigrationParticipant.MigrationScriptRef>, Void> getDataCollector() { return myDataCollector; } private static boolean eq_8k3jue_a0a0a0a0a0a0a3a2a21(Object a, Object b) { return (a != null ? a.equals(b) : a == b); } private static SNodeReference check_8k3jue_a0a0a0a0a0b0c0m(SNode checkedDotOperand) { if (null != checkedDotOperand) { return checkedDotOperand.getReference(); } return null; } private static boolean eq_8k3jue_a0a0a0a0a0a0a0a0a0a0a4a2a21(Object a, Object b) { return (a != null ? a.equals(b) : a == b); } private static boolean eq_8k3jue_a0a0a0a0a0a0a0a0a0a0a5a2a21(Object a, Object b) { return (a != null ? a.equals(b) : a == b); } private static SNode createIncludeMigrationPart_8k3jue_a0a1a1a0a0a0a0a0a5a2a21(Object p0) { PersistenceFacade facade = PersistenceFacade.getInstance(); SNode n1 = SModelUtil_new.instantiateConceptDeclaration(MetaAdapterFactory.getConcept(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x267418e6b5c2b903L, "jetbrains.mps.lang.migration.structure.IncludeMigrationPart"), null, null, false); n1.setReferenceTarget(MetaAdapterFactory.getReferenceLink(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x267418e6b5c2b903L, 0x267418e6b5c2b960L, "target"), (SNode) p0); return n1; } private static SNode createConceptMigrationReference_8k3jue_a0a51(Object p0, Object p1, Object p2) { PersistenceFacade facade = PersistenceFacade.getInstance(); SNode n1 = SModelUtil_new.instantiateConceptDeclaration(MetaAdapterFactory.getConcept(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x36182c4cf6238c95L, "jetbrains.mps.lang.migration.structure.ConceptMigrationReference"), null, null, false); { SNode n2 = SModelUtil_new.instantiateConceptDeclaration(MetaAdapterFactory.getConcept(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x66eed171c5f83bcaL, "jetbrains.mps.lang.migration.structure.MigrationScriptReference"), null, null, false); n2.setProperty(MetaAdapterFactory.getProperty(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x66eed171c5f83bcaL, 0x66eed171c5f90222L, "fromVersion"), p0 + ""); n2.setProperty(MetaAdapterFactory.getProperty(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x66eed171c5f83bcaL, 0x66eed171c602da74L, "module"), p1 + ""); n1.addChild(MetaAdapterFactory.getContainmentLink(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x36182c4cf6238c95L, 0x36182c4cf6238c96L, "migrationScript"), n2); if (p2 != null) { n1.addChild(MetaAdapterFactory.getContainmentLink(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x36182c4cf6238c95L, 0x36182c4cf6238c99L, "oldConcept"), (SNode) p2); } } return n1; } }