package jetbrains.mps.baseLanguage.util.plugin.refactorings;

/*Generated by MPS */

import java.util.List;
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.mps.openapi.module.SearchScope;
import org.jetbrains.mps.openapi.util.ProgressMonitor;
import java.util.ArrayList;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.ide.findusages.model.SearchResults;
import jetbrains.mps.ide.findusages.view.FindUtils;
import jetbrains.mps.ide.findusages.model.SearchResult;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import org.jetbrains.mps.openapi.language.SProperty;

public class MethodRefactoringUtils {
  public MethodRefactoringUtils() {
  }
  public static List<SNode> findOverridingMethods(SearchScope scope, SNode method, ProgressMonitor progressMonitor) {
    List<SNode> results = new ArrayList<SNode>();
    if (SNodeOperations.isInstanceOf(method, CONCEPTS.InstanceMethodDeclaration$39)) {
      if (SPropertyOperations.getBoolean(method, PROPS.isFinal$eVPk) || SNodeOperations.isInstanceOf(SLinkOperations.getTarget(SNodeOperations.cast(method, CONCEPTS.InstanceMethodDeclaration$39), LINKS.visibility$Yyua), CONCEPTS.PrivateVisibility$l0)) {
        return results;
      }
      SearchResults<SNode> searchResults;
      if (SNodeOperations.isInstanceOf(SNodeOperations.getParent(method), CONCEPTS.Interface$db)) {
        searchResults = FindUtils.getSearchResults(progressMonitor, method, scope, "jetbrains.mps.baseLanguage.findUsages.InterfaceMethodImplementations_Finder");
      } else {
        searchResults = FindUtils.getSearchResults(progressMonitor, method, scope, "jetbrains.mps.baseLanguage.findUsages.OverridingMethods_Finder");
      }

      for (SearchResult<SNode> result : ListSequence.fromList(searchResults.getSearchResults())) {
        ListSequence.fromList(results).addElement(SNodeOperations.cast(result.getObject(), CONCEPTS.BaseMethodDeclaration$kD));
      }
    }
    if (SNodeOperations.isInstanceOf(method, CONCEPTS.ConceptMethodDeclaration$N0)) {
      SearchResults<SNode> searchResults = FindUtils.getSearchResults(progressMonitor, method, scope, "jetbrains.mps.lang.behavior.findUsages.OverridingMethods_Finder");
      for (SearchResult<SNode> result : ListSequence.fromList(searchResults.getSearchResults())) {
        ListSequence.fromList(results).addElement(SNodeOperations.cast(result.getObject(), CONCEPTS.BaseMethodDeclaration$kD));
      }
    }
    return results;
  }
  public static SearchResults findMethodUsages(SearchScope scope, SNode method, ProgressMonitor progressMonitor) {
    return FindUtils.getSearchResults(progressMonitor, method, scope, "jetbrains.mps.baseLanguage.findUsages.ExactMethodUsages_Finder");
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept InstanceMethodDeclaration$39 = MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b21dL, "jetbrains.mps.baseLanguage.structure.InstanceMethodDeclaration");
    /*package*/ static final SConcept PrivateVisibility$l0 = MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x10af9586f0cL, "jetbrains.mps.baseLanguage.structure.PrivateVisibility");
    /*package*/ static final SConcept Interface$db = MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101edd46144L, "jetbrains.mps.baseLanguage.structure.Interface");
    /*package*/ static final SConcept BaseMethodDeclaration$kD = MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, "jetbrains.mps.baseLanguage.structure.BaseMethodDeclaration");
    /*package*/ static final SConcept ConceptMethodDeclaration$N0 = MetaAdapterFactory.getConcept(0xaf65afd8f0dd4942L, 0x87d963a55f2a9db1L, 0x11d4348057eL, "jetbrains.mps.lang.behavior.structure.ConceptMethodDeclaration");
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink visibility$Yyua = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x112670d273fL, 0x112670d886aL, "visibility");
  }

  private static final class PROPS {
    /*package*/ static final SProperty isFinal$eVPk = MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0x113294bffd2L, "isFinal");
  }
}
