package jetbrains.mps.ide.editor.util;

/*Generated by MPS */

import jetbrains.mps.annotations.GeneratedClass;
import org.jetbrains.annotations.NotNull;
import com.intellij.util.Function;
import org.jetbrains.mps.openapi.model.SNodeReference;
import org.jetbrains.mps.openapi.module.SRepository;
import jetbrains.mps.util.ModelComputeRunnable;
import jetbrains.mps.util.Computable;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPointerOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.smodel.behaviour.BHReflection;
import jetbrains.mps.core.aspects.behaviour.SMethodIdV2;
import org.jetbrains.mps.openapi.language.SInterfaceConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;

@GeneratedClass(node = "r:4e6037e6-9135-44f8-9403-04d79fc40f4a(jetbrains.mps.ide.editor.util)/6984321651747607765", model = "r:4e6037e6-9135-44f8-9403-04d79fc40f4a(jetbrains.mps.ide.editor.util)")
/*package*/ interface NamerFactory {
  @NotNull
  Function<SNodeReference, String> create(@NotNull final SRepository repository);

  NamerFactory DEFAULT_NAMER_FACTORY = new NamerFactory() {
    @NotNull
    @Override
    public Function<SNodeReference, String> create(@NotNull final SRepository repo) {
      return new Function<SNodeReference, String>() {
        public String fun(final SNodeReference ptr) {
          String name = new ModelComputeRunnable<String>(new Computable<String>() {
            @Override
            public String compute() {
              SNode resolved = SPointerOperations.resolveNode(ptr, repo);
              if (resolved != null) {
                if (SNodeOperations.isInstanceOf(resolved, CONCEPTS.INamedConcept$Kd)) {
                  return ((String) BHReflection.invoke0(SNodeOperations.cast(resolved, CONCEPTS.INamedConcept$Kd), CONCEPTS.INamedConcept$Kd, SMethodIdV2.create("getFqName", 1213877404258L, 0x553941aeb020c32eL)));
                }
                return ((SNode) resolved).getName();
              }
              return "";
            }
          }).runRead(repo.getModelAccess());
          return name;
        }
      };
    }
  };

  final class CONCEPTS {
    /*package*/ static final SInterfaceConcept INamedConcept$Kd = MetaAdapterFactory.getInterfaceConcept(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, "jetbrains.mps.lang.core.structure.INamedConcept");
  }
}
