package jetbrains.mps.baseLanguage.util.plugin.refactorings; /*Generated by MPS */ import org.jetbrains.mps.openapi.model.SNode; import java.util.List; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SConceptOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import jetbrains.mps.internal.collections.runtime.ListSequence; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import jetbrains.mps.typesystem.inference.TypeChecker; import jetbrains.mps.smodel.behaviour.BHReflection; import jetbrains.mps.core.aspects.behaviour.SMethodTrimmedId; import jetbrains.mps.lang.typesystem.runtime.HUtil; public class AbstractExtractMethodRefactoringProcessor implements IExtractMethodRefactoringProcessor { protected SNode myNode; protected List<SNode> myNodesToRefactor; protected boolean isStatic; public AbstractExtractMethodRefactoringProcessor(SNode node, List<SNode> nodesToRefactor) { this.myNode = node; this.myNodesToRefactor = nodesToRefactor; } @Override public void addMethod(SNode method) { universalAddMethod(this.myNode, method); } @Override public SNode createNewMethod() { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, "jetbrains.mps.baseLanguage.structure.BaseMethodDeclaration")); } @Override public SNode createMethodCall(SNode methodDeclaration, List<SNode> parameteres) { return null; } @Override public SNode getContainerMethod() { SNode node = ListSequence.fromList(this.myNodesToRefactor).first(); while (node != null) { if (SNodeOperations.isInstanceOf(node, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, "jetbrains.mps.baseLanguage.structure.BaseMethodDeclaration"))) { return node; } if (SNodeOperations.isInstanceOf(node, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x108bbca0f48L, "jetbrains.mps.baseLanguage.structure.ConceptFunction"))) { return node; } node = SNodeOperations.getParent(node); } throw new IllegalStateException("can't be applied in this case"); } @Override public SNode getContainerReturnType() { SNode containerMethod = this.getContainerMethod(); if (SNodeOperations.isInstanceOf(containerMethod, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, "jetbrains.mps.baseLanguage.structure.BaseMethodDeclaration"))) { return SNodeOperations.copyNode(SLinkOperations.getTarget(SNodeOperations.cast(containerMethod, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, "jetbrains.mps.baseLanguage.structure.BaseMethodDeclaration")), MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0xf8cc56b1fdL, "returnType"))); } if (SNodeOperations.isInstanceOf(containerMethod, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x108bbca0f48L, "jetbrains.mps.baseLanguage.structure.ConceptFunction"))) { return TypeChecker.getInstance().getRuntimeSupport().coerce_(((SNode) BHReflection.invoke(SNodeOperations.cast(containerMethod, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x108bbca0f48L, "jetbrains.mps.baseLanguage.structure.ConceptFunction")), SMethodTrimmedId.create("getExpectedReturnType", null, "hEwIGRD"))), HUtil.createMatchingPatternByConcept(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c37f506dL, "jetbrains.mps.baseLanguage.structure.Type")), true); } return null; } public void setStatic(boolean isStatic) { this.isStatic = isStatic; } public static void universalAddMethod(SNode container, SNode method) { MoveRefactoringUtils.addNodeAtLink(container, method); } }