package jetbrains.mps.samples.notesOrganizer.behavior;

/*Generated by MPS */

import jetbrains.mps.core.aspects.behaviour.BaseBHDescriptor;
import jetbrains.mps.logging.Logger;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.core.aspects.behaviour.api.SMethod;
import java.awt.Color;
import jetbrains.mps.core.aspects.behaviour.SMethodBuilder;
import jetbrains.mps.core.aspects.behaviour.SJavaCompoundTypeImpl;
import jetbrains.mps.core.aspects.behaviour.AccessPrivileges;
import java.util.List;
import java.util.Arrays;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.mps.openapi.model.SNode;
import java.lang.reflect.Field;
import jetbrains.mps.core.aspects.behaviour.api.SConstructor;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.core.aspects.behaviour.api.BHMethodNotFoundException;

public final class Note__BehaviorDescriptor extends BaseBHDescriptor {
  private static final Logger LOG = Logger.getLogger(Note__BehaviorDescriptor.class);
  private static final SAbstractConcept CONCEPT = MetaAdapterFactory.getConcept(0x4b0f115a88684d72L, 0x8d6197071eaaa5f1L, 0x7ba12f0b163df32dL, "jetbrains.mps.samples.notesOrganizer.structure.Note");

  public static final SMethod<Color> findColor_id3o4bEdkAIk2 = new SMethodBuilder<Color>(new SJavaCompoundTypeImpl(Color.class)).name("findColor").modifiers(0, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(3892287256988935426L).languageId(0x8d6197071eaaa5f1L, 0x4b0f115a88684d72L).build2(SMethodBuilder.createJavaParameter(String.class, ""));

  private static final List<SMethod<?>> BH_METHODS = Arrays.<SMethod<?>>asList(findColor_id3o4bEdkAIk2);

  private static void ___init___(@NotNull SNode __thisNode__) {
  }

  /*package*/ static Color findColor_id3o4bEdkAIk2(@NotNull SNode __thisNode__, String colorName) {
    try {
      if (colorName != null) {
        Field field = Color.class.getField(colorName);
        if (field != null) {
          Object value = field.get(Color.class);
          return (value != null ? ((Color) value) : Color.black);
        }
      }
    } catch (NoSuchFieldException e) {
      if (LOG.isErrorLevel()) {
        LOG.error("", e);
      }
    } catch (IllegalAccessException e) {
      if (LOG.isErrorLevel()) {
        LOG.error("", e);
      }
    } catch (SecurityException e) {
      if (LOG.isErrorLevel()) {
        LOG.error("", e);
      }
    }
    return Color.black;
  }

  /*package*/ Note__BehaviorDescriptor() {
  }

  @Override
  protected void initNode(@NotNull SNode node, @NotNull SConstructor constructor, @Nullable Object[] parameters) {
    ___init___(node);
  }

  @Override
  protected <T> T invokeSpecial0(@NotNull SNode node, @NotNull SMethod<T> method, @Nullable Object[] parameters) {
    int methodIndex = BH_METHODS.indexOf(method);
    if (methodIndex < 0) {
      throw new BHMethodNotFoundException(this, method);
    }
    switch (methodIndex) {
      case 0:
        return (T) ((Color) findColor_id3o4bEdkAIk2(node, (String) parameters[0]));
      default:
        throw new BHMethodNotFoundException(this, method);
    }
  }

  @Override
  protected <T> T invokeSpecial0(@NotNull SAbstractConcept concept, @NotNull SMethod<T> method, @Nullable Object[] parameters) {
    int methodIndex = BH_METHODS.indexOf(method);
    if (methodIndex < 0) {
      throw new BHMethodNotFoundException(this, method);
    }
    switch (methodIndex) {
      default:
        throw new BHMethodNotFoundException(this, method);
    }
  }

  @NotNull
  @Override
  public List<SMethod<?>> getDeclaredMethods() {
    return BH_METHODS;
  }

  @NotNull
  @Override
  public SAbstractConcept getConcept() {
    return CONCEPT;
  }
}
