package jetbrains.mps.lang.structure.pluginSolution.plugin; /*Generated by MPS */ import jetbrains.mps.refactoring.participant.RefactoringParticipantBase; import jetbrains.mps.baseLanguage.tuples.runtime.Tuples; import org.jetbrains.mps.openapi.model.SNodeReference; import org.jetbrains.mps.openapi.model.SNode; import jetbrains.mps.refactoring.participant.MoveNodeRefactoringParticipant; import jetbrains.mps.smodel.structure.Extension; import org.jetbrains.mps.openapi.language.SAbstractConcept; import org.jetbrains.mps.openapi.language.SProperty; import org.jetbrains.mps.openapi.language.SContainmentLink; import org.jetbrains.mps.openapi.language.SReferenceLink; import jetbrains.mps.refactoring.participant.RefactoringSession; import jetbrains.mps.smodel.Language; import java.util.Map; import org.jetbrains.mps.openapi.module.SModuleReference; import jetbrains.mps.internal.collections.runtime.MapSequence; import java.util.HashMap; import org.jetbrains.mps.openapi.model.SModel; import jetbrains.mps.smodel.LanguageAspect; import jetbrains.mps.smodel.SModelInternal; import org.jetbrains.mps.openapi.model.SModelReference; import jetbrains.mps.internal.collections.runtime.ListSequence; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.internal.collections.runtime.ITranslator2; import org.jetbrains.mps.openapi.model.SReference; import jetbrains.mps.internal.collections.runtime.ISelector; import jetbrains.mps.smodel.SModelOperations; import org.jetbrains.annotations.NotNull; import jetbrains.mps.lang.typesystem.runtime.HUtil; import jetbrains.mps.lang.migration.util.NodeReferenceUtil; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import org.jetbrains.mps.openapi.persistence.PersistenceFacade; import jetbrains.mps.smodel.SModelUtil_new; import java.util.List; import jetbrains.mps.refactoring.participant.RefactoringParticipant; import org.jetbrains.mps.openapi.module.SRepository; import java.util.ArrayList; import org.jetbrains.mps.openapi.module.SearchScope; import jetbrains.mps.lang.core.plugin.UpdateModelImports; import jetbrains.mps.ide.findusages.model.SearchResults; import jetbrains.mps.ide.findusages.model.SearchResult; import org.jetbrains.mps.openapi.module.SModule; public class LanguageStructureMigrationParticipant<I, F> extends RefactoringParticipantBase<Tuples._2<I, SNodeReference>, Tuples._2<F, SNodeReference>, SNode, SNode> implements MoveNodeRefactoringParticipant<Tuples._2<I, SNodeReference>, Tuples._2<F, SNodeReference>> { private StructureSpecialization<I, F> myStructureSpecialization; public LanguageStructureMigrationParticipant(StructureSpecialization<I, F> structureSpecialization) { myStructureSpecialization = structureSpecialization; } public static class MoveConceptMigration_extension extends Extension.Default<MoveNodeRefactoringParticipant<?, ?>> { public MoveConceptMigration_extension() { super("jetbrains.mps.refactoring.participant.MoveNodeParticipantEP"); } public MoveNodeRefactoringParticipant<?, ?> get() { return new LanguageStructureMigrationParticipant<SAbstractConcept, SAbstractConcept>(new MoveAbstractConceptSpecialization()); } } public static class MovePropertyMigration_extension extends Extension.Default<MoveNodeRefactoringParticipant<?, ?>> { public MovePropertyMigration_extension() { super("jetbrains.mps.refactoring.participant.MoveNodeParticipantEP"); } public MoveNodeRefactoringParticipant<?, ?> get() { return new LanguageStructureMigrationParticipant<SProperty, SProperty>(new MovePropertySpecialization()); } } public static class MoveContainmentLinkMigration_extension extends Extension.Default<MoveNodeRefactoringParticipant<?, ?>> { public MoveContainmentLinkMigration_extension() { super("jetbrains.mps.refactoring.participant.MoveNodeParticipantEP"); } public MoveNodeRefactoringParticipant<?, ?> get() { return new LanguageStructureMigrationParticipant<SContainmentLink, SContainmentLink>(new MoveContainmentLinkSpecialization()); } } public static class MoveReferenceLinkMigration_extension extends Extension.Default<MoveNodeRefactoringParticipant<?, ?>> { public MoveReferenceLinkMigration_extension() { super("jetbrains.mps.refactoring.participant.MoveNodeParticipantEP"); } public MoveNodeRefactoringParticipant<?, ?> get() { return new LanguageStructureMigrationParticipant<SReferenceLink, SReferenceLink>(new MoveReferenceLinkSpecialization()); } } public MoveNodeRefactoringParticipant.MoveNodeRefactoringDataCollector<Tuples._2<I, SNodeReference>, Tuples._2<F, SNodeReference>> getDataCollector() { return myStructureSpecialization; } public static class MigrationBuilder { private static final String myId = "refactoringSession.migrationBuilder"; public static LanguageStructureMigrationParticipant.MigrationBuilder getBuilder(RefactoringSession session, Language module) { Map<SModuleReference, LanguageStructureMigrationParticipant.MigrationBuilder> moduleBuilders = (Map<SModuleReference, LanguageStructureMigrationParticipant.MigrationBuilder>) session.getObject(LanguageStructureMigrationParticipant.MigrationBuilder.myId); if (moduleBuilders == null) { moduleBuilders = MapSequence.fromMap(new HashMap<SModuleReference, LanguageStructureMigrationParticipant.MigrationBuilder>()); session.putObject(LanguageStructureMigrationParticipant.MigrationBuilder.myId, moduleBuilders); } LanguageStructureMigrationParticipant.MigrationBuilder builder = MapSequence.fromMap(moduleBuilders).get(module.getModuleReference()); if (builder == null) { builder = new LanguageStructureMigrationParticipant.MigrationBuilder(session, module); MapSequence.fromMap(moduleBuilders).put(module.getModuleReference(), builder); } return builder; } private SNode myRefactoringStep; public MigrationBuilder(RefactoringSession session, final Language language) { final int languageVersion = language.getLanguageVersion(); myRefactoringStep = createPureMigrationScript_kz6lmo_a0b0d11(languageVersion, "MigrationScript_" + languageVersion); session.registerChange(new Runnable() { public void run() { SModel migrationModel = LanguageAspect.MIGRATION.getOrCreate(language); SModelInternal sm = (SModelInternal) (SModel) migrationModel; for (SModelReference reference : ListSequence.fromList(SNodeOperations.getNodeDescendants(myRefactoringStep, null, true, new SAbstractConcept[]{})).translate(new ITranslator2<SNode, SReference>() { public Iterable<SReference> translate(SNode it) { return SNodeOperations.getReferences(it); } }).select(new ISelector<SReference, SModelReference>() { public SModelReference select(SReference it) { return it.getTargetSModelReference(); } }).distinct()) { if (!(SModelOperations.getImportedModelUIDs(migrationModel).contains(reference))) { sm.addModelImport(reference); } } jetbrains.mps.lang.smodel.generator.smodelAdapter.SModelOperations.addRootNode(migrationModel, myRefactoringStep); language.setLanguageVersion(languageVersion + 1); } }); } public void addPart(@NotNull SNode initialStateNode, @NotNull SNode finalStateNode, SNode specialization) { addPart(createMoveNodeMigrationPart_kz6lmo_a0a0e11(SNodeOperations.cast(HUtil.copyIfNecessary(NodeReferenceUtil.makeReflection(initialStateNode)), MetaAdapterFactory.getConcept(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x2b3f57492c1648ccL, "jetbrains.mps.lang.migration.structure.AbstractNodeReference")), SNodeOperations.cast(HUtil.copyIfNecessary(NodeReferenceUtil.makeReflection(finalStateNode)), MetaAdapterFactory.getConcept(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x2b3f57492c1648ccL, "jetbrains.mps.lang.migration.structure.AbstractNodeReference")), SNodeOperations.cast(HUtil.copyIfNecessary(specialization), MetaAdapterFactory.getConcept(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x2b3f57492c165c5dL, "jetbrains.mps.lang.migration.structure.MoveNodeSpecialization")))); } public void addPart(SNode migrationPart) { ListSequence.fromList(SLinkOperations.getChildren(myRefactoringStep, MetaAdapterFactory.getContainmentLink(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x67236d4a5836cabbL, 0x67236d4a5836d7f3L, "part"))).addElement(migrationPart); } private static SNode createPureMigrationScript_kz6lmo_a0b0d11(Object p0, Object p1) { PersistenceFacade facade = PersistenceFacade.getInstance(); SNode n1 = SModelUtil_new.instantiateConceptDeclaration(MetaAdapterFactory.getConcept(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x67236d4a5836cabbL, "jetbrains.mps.lang.migration.structure.PureMigrationScript"), null, null, false); n1.setProperty(MetaAdapterFactory.getProperty(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x67236d4a5836cabbL, 0x67236d4a5836cabcL, "fromVersion"), p0 + ""); n1.setProperty(MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name"), p1 + ""); return n1; } private static SNode createMoveNodeMigrationPart_kz6lmo_a0a0e11(Object p0, Object p1, Object p2) { PersistenceFacade facade = PersistenceFacade.getInstance(); SNode n1 = SModelUtil_new.instantiateConceptDeclaration(MetaAdapterFactory.getConcept(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x67236d4a5830221eL, "jetbrains.mps.lang.migration.structure.MoveNodeMigrationPart"), null, null, false); if (p0 != null) { n1.addChild(MetaAdapterFactory.getContainmentLink(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x67236d4a5830221eL, 0x67236d4a58343d15L, "fromNode"), (SNode) p0); } if (p1 != null) { n1.addChild(MetaAdapterFactory.getContainmentLink(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x67236d4a5830221eL, 0x67236d4a58343d17L, "toNode"), (SNode) p1); } if (p2 != null) { n1.addChild(MetaAdapterFactory.getContainmentLink(0x9074634404fd4286L, 0x97d5b46ae6a81709L, 0x67236d4a5830221eL, 0x2b3f57492c165c59L, "specialization"), (SNode) p2); } return n1; } } public List<RefactoringParticipant.Option> getAvailableOptions(Tuples._2<I, SNodeReference> initialState, SRepository repository) { if (initialState != null) { return ListSequence.fromListAndArray(new ArrayList<RefactoringParticipant.Option>(), OPTION); } else { return ListSequence.fromList(new ArrayList<RefactoringParticipant.Option>()); } } public static final RefactoringParticipant.Option OPTION = new RefactoringParticipant.Option("moveNode.options.writeMigrationScript", "Write migration script"); public List<RefactoringParticipant.Change<Tuples._2<I, SNodeReference>, Tuples._2<F, SNodeReference>>> getChanges(final Tuples._2<I, SNodeReference> initialState, SRepository repository, final List<RefactoringParticipant.Option> selectedOptions, SearchScope searchScope) { if (initialState == null || !(ListSequence.fromList(selectedOptions).contains(OPTION))) { return ListSequence.fromList(new ArrayList<RefactoringParticipant.Change<Tuples._2<I, SNodeReference>, Tuples._2<F, SNodeReference>>>()); } final boolean updateModelImports = ListSequence.fromList(selectedOptions).contains(UpdateModelImports.OPTION); final Language sourceModule = as_kz6lmo_a0a2a61(check_kz6lmo_a0a2a61(check_kz6lmo_a0a0c0q(initialState._1().resolve(repository))), Language.class); final SearchResults results = new SearchResults(); if (sourceModule != null) { results.add(new SearchResult<SModule>(sourceModule, "migration script")); } // todo: write guard migration with 'execute after' RefactoringParticipant.Change<Tuples._2<I, SNodeReference>, Tuples._2<F, SNodeReference>> change = new MoveNodeRefactoringParticipant.ChangeBase<Tuples._2<I, SNodeReference>, Tuples._2<F, SNodeReference>>() { public SearchResults getSearchResults() { return results; } public RefactoringParticipant.KeepOldNodes needsToPreserveOldNode() { return RefactoringParticipant.KeepOldNodes.KEEP; } public void confirm(Tuples._2<F, SNodeReference> finalState, SRepository repository, RefactoringSession refactoringSession) { Language sourceModule = as_kz6lmo_a0a0a2a0a0j0q(check_kz6lmo_a0a0a2a0a0j0q(check_kz6lmo_a0a0a0c0a0a9a61(initialState._1().resolve(repository))), Language.class); Language targetModule = as_kz6lmo_a0a1a2a0a0j0q(check_kz6lmo_a0a1a2a0a0j0q(check_kz6lmo_a0a0b0c0a0a9a61(finalState._1().resolve(repository))), Language.class); if (sourceModule != null) { LanguageStructureMigrationParticipant.MigrationBuilder logBuilder = LanguageStructureMigrationParticipant.MigrationBuilder.getBuilder(refactoringSession, sourceModule); myStructureSpecialization.confirm(selectedOptions, initialState, finalState, repository, logBuilder, updateModelImports); } } }; return ListSequence.fromListAndArray(new ArrayList<RefactoringParticipant.Change<Tuples._2<I, SNodeReference>, Tuples._2<F, SNodeReference>>>(), change); } private static SModule check_kz6lmo_a0a2a61(SModel checkedDotOperand) { if (null != checkedDotOperand) { return checkedDotOperand.getModule(); } return null; } private static SModel check_kz6lmo_a0a0c0q(SNode checkedDotOperand) { if (null != checkedDotOperand) { return checkedDotOperand.getModel(); } return null; } private static SModule check_kz6lmo_a0a0a2a0a0j0q(SModel checkedDotOperand) { if (null != checkedDotOperand) { return checkedDotOperand.getModule(); } return null; } private static SModel check_kz6lmo_a0a0a0c0a0a9a61(SNode checkedDotOperand) { if (null != checkedDotOperand) { return checkedDotOperand.getModel(); } return null; } private static SModule check_kz6lmo_a0a1a2a0a0j0q(SModel checkedDotOperand) { if (null != checkedDotOperand) { return checkedDotOperand.getModule(); } return null; } private static SModel check_kz6lmo_a0a0b0c0a0a9a61(SNode checkedDotOperand) { if (null != checkedDotOperand) { return checkedDotOperand.getModel(); } return null; } private static <T> T as_kz6lmo_a0a2a61(Object o, Class<T> type) { return (type.isInstance(o) ? (T) o : null); } private static <T> T as_kz6lmo_a0a0a2a0a0j0q(Object o, Class<T> type) { return (type.isInstance(o) ? (T) o : null); } private static <T> T as_kz6lmo_a0a1a2a0a0j0q(Object o, Class<T> type) { return (type.isInstance(o) ? (T) o : null); } }