package jetbrains.mps.lang.pattern.behavior;

/*Generated by MPS */

import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.baseLanguage.behavior.Type__BehaviorDescriptor;
import jetbrains.mps.lang.smodel.typesystem.RulesUtil;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.lang.core.behavior.PropertyAttribute__BehaviorDescriptor;
import org.jetbrains.mps.openapi.persistence.PersistenceFacade;
import jetbrains.mps.smodel.builder.SNodeBuilder;
import jetbrains.mps.smodel.SNodePointer;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SProperty;
import org.jetbrains.mps.openapi.language.SReferenceLink;

public class PatternVarsUtil {
  public PatternVarsUtil() {
  }
  public static String getFieldName(SNode patternVar) {
    String prefix = "patternVar_";
    if (SNodeOperations.isInstanceOf(patternVar, CONCEPTS.PatternVariableDeclaration$ZH)) {
      return prefix + SPropertyOperations.getString(SNodeOperations.cast(patternVar, CONCEPTS.PatternVariableDeclaration$ZH), PROPS.varName$kQdS);
    }
    if (SNodeOperations.isInstanceOf(patternVar, CONCEPTS.LinkPatternVariableDeclaration$8a)) {
      return prefix + SPropertyOperations.getString(SNodeOperations.cast(patternVar, CONCEPTS.LinkPatternVariableDeclaration$8a), PROPS.varName$oF2a);
    }
    if (SNodeOperations.isInstanceOf(patternVar, CONCEPTS.PropertyPatternVariableDeclaration$aQ)) {
      return prefix + SPropertyOperations.getString(SNodeOperations.cast(patternVar, CONCEPTS.PropertyPatternVariableDeclaration$aQ), PROPS.varName$kQR3);
    }
    if (SNodeOperations.isInstanceOf(patternVar, CONCEPTS.ListPattern$1B)) {
      return prefix + SPropertyOperations.getString(SNodeOperations.cast(patternVar, CONCEPTS.ListPattern$1B), PROPS.varName$kQdS);
    }
    return null;
  }
  public static boolean fieldTypeHasParameter(SNode patternVar) {
    return SNodeOperations.isInstanceOf(patternVar, CONCEPTS.ListPattern$1B);
  }
  public static SNode getFieldTypeReference(SNode patternVar) {
    if (SNodeOperations.isInstanceOf(patternVar, CONCEPTS.ListPattern$1B)) {
      return createClassifierType_6maajz_a0a0a3();
    }
    if (SNodeOperations.isInstanceOf(patternVar, CONCEPTS.PatternVariableDeclaration$ZH)) {
      return createClassifierType_6maajz_a0a1a3();
    }
    if (SNodeOperations.isInstanceOf(patternVar, CONCEPTS.LinkPatternVariableDeclaration$8a)) {
      return createClassifierType_6maajz_a0a2a3();
    }
    if (SNodeOperations.isInstanceOf(patternVar, CONCEPTS.PropertyPatternVariableDeclaration$aQ)) {
      SNode propertyPatternVar = SNodeOperations.cast(patternVar, CONCEPTS.PropertyPatternVariableDeclaration$aQ);
      if (SPropertyOperations.getBoolean(propertyPatternVar, PROPS.enumUsageMigrated$64YW)) {
        return SNodeOperations.cast(Type__BehaviorDescriptor.getBoxedType_idhEwIzNC.invoke(Type__BehaviorDescriptor.getJavaType_idhEwIzO1.invoke(RulesUtil.datatypeBLType(SLinkOperations.getTarget(PropertyAttribute__BehaviorDescriptor.getPropertyDeclaration_id121FNPYBLc9.invoke(propertyPatternVar), LINKS.dataType$5j5Y)))), CONCEPTS.ClassifierType$bL);
      }
      return createClassifierType_6maajz_a2a3a3();
    }
    return null;
  }
  private static SNode createClassifierType_6maajz_a0a0a3() {
    PersistenceFacade facade = PersistenceFacade.getInstance();
    SNodeBuilder n0 = new SNodeBuilder().init(CONCEPTS.ClassifierType$bL);
    n0.setReference(LINKS.classifier$cxMr, new SNodePointer(facade.createModelReference("6354ebe7-c22a-4a0f-ac54-50b52ab9b065/java:java.util(JDK/)"), facade.createNodeId("~List")));
    return n0.getResult();
  }
  private static SNode createClassifierType_6maajz_a0a1a3() {
    PersistenceFacade facade = PersistenceFacade.getInstance();
    SNodeBuilder n0 = new SNodeBuilder().init(CONCEPTS.ClassifierType$bL);
    n0.setReference(LINKS.classifier$cxMr, new SNodePointer(facade.createModelReference("8865b7a8-5271-43d3-884c-6fd1d9cfdd34/java:org.jetbrains.mps.openapi.model(MPS.OpenAPI/)"), facade.createNodeId("~SNode")));
    return n0.getResult();
  }
  private static SNode createClassifierType_6maajz_a0a2a3() {
    PersistenceFacade facade = PersistenceFacade.getInstance();
    SNodeBuilder n0 = new SNodeBuilder().init(CONCEPTS.ClassifierType$bL);
    n0.setReference(LINKS.classifier$cxMr, new SNodePointer(facade.createModelReference("8865b7a8-5271-43d3-884c-6fd1d9cfdd34/java:org.jetbrains.mps.openapi.model(MPS.OpenAPI/)"), facade.createNodeId("~SNode")));
    return n0.getResult();
  }
  private static SNode createClassifierType_6maajz_a2a3a3() {
    PersistenceFacade facade = PersistenceFacade.getInstance();
    SNodeBuilder n0 = new SNodeBuilder().init(CONCEPTS.ClassifierType$bL);
    n0.setReference(LINKS.classifier$cxMr, new SNodePointer(facade.createModelReference("6354ebe7-c22a-4a0f-ac54-50b52ab9b065/java:java.lang(JDK/)"), facade.createNodeId("~String")));
    return n0.getResult();
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept PatternVariableDeclaration$ZH = MetaAdapterFactory.getConcept(0xd4615e3bd6714ba9L, 0xaf012b78369b0ba7L, 0x108a9cb4793L, "jetbrains.mps.lang.pattern.structure.PatternVariableDeclaration");
    /*package*/ static final SConcept LinkPatternVariableDeclaration$8a = MetaAdapterFactory.getConcept(0xd4615e3bd6714ba9L, 0xaf012b78369b0ba7L, 0x108d36d955aL, "jetbrains.mps.lang.pattern.structure.LinkPatternVariableDeclaration");
    /*package*/ static final SConcept PropertyPatternVariableDeclaration$aQ = MetaAdapterFactory.getConcept(0xd4615e3bd6714ba9L, 0xaf012b78369b0ba7L, 0x108a9cb4795L, "jetbrains.mps.lang.pattern.structure.PropertyPatternVariableDeclaration");
    /*package*/ static final SConcept ListPattern$1B = MetaAdapterFactory.getConcept(0xd4615e3bd6714ba9L, 0xaf012b78369b0ba7L, 0x108aa36731aL, "jetbrains.mps.lang.pattern.structure.ListPattern");
    /*package*/ static final SConcept ClassifierType$bL = MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, "jetbrains.mps.baseLanguage.structure.ClassifierType");
  }

  private static final class PROPS {
    /*package*/ static final SProperty varName$kQdS = MetaAdapterFactory.getProperty(0xd4615e3bd6714ba9L, 0xaf012b78369b0ba7L, 0x108a9cb4793L, 0x108a9cb4794L, "varName");
    /*package*/ static final SProperty varName$oF2a = MetaAdapterFactory.getProperty(0xd4615e3bd6714ba9L, 0xaf012b78369b0ba7L, 0x108d36d955aL, 0x108d36e0ea4L, "varName");
    /*package*/ static final SProperty varName$kQR3 = MetaAdapterFactory.getProperty(0xd4615e3bd6714ba9L, 0xaf012b78369b0ba7L, 0x108a9cb4795L, 0x108a9cb4796L, "varName");
    /*package*/ static final SProperty enumUsageMigrated$64YW = MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x2eb1ad060897da56L, 0x1081af3d7e9d6a2fL, "enumUsageMigrated");
  }

  private static final class LINKS {
    /*package*/ static final SReferenceLink dataType$5j5Y = MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086bL, 0xfc26f42fe5L, "dataType");
    /*package*/ static final SReferenceLink classifier$cxMr = MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, 0x101de490babL, "classifier");
  }
}
