// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.structuralsearch.impl.matcher;

import com.intellij.lang.Language;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.impl.DebugUtil;
import com.intellij.structuralsearch.PatternContext;
import com.intellij.structuralsearch.StructuralSearchProfile;
import com.intellij.structuralsearch.StructuralSearchUtil;

/**
 * @author Maxim.Mossienko
 */
public class MatcherImplUtil {

  public static PsiElement[] createTreeFromText(String text, PatternTreeContext context, LanguageFileType fileType, Project project) {
    return createTreeFromText(text, context, fileType, null, null, project, false);
  }

  public static PsiElement[] createSourceTreeFromText(String text,
                                                      PatternTreeContext context,
                                                      LanguageFileType fileType,
                                                      Project project,
                                                      boolean physical) {
    final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByLanguage(fileType.getLanguage());
    if (profile != null) {
      final PsiElement[] tree = profile.createPatternTree(text, context, fileType, fileType.getLanguage(), null, project, physical);
      for (PsiElement branch : tree) {
        System.out.println(DebugUtil.psiToString(branch, false));
      }
      return tree;
    }
    return PsiElement.EMPTY_ARRAY;
  }

  public static PsiElement[] createTreeFromText(String text,
                                                PatternTreeContext context,
                                                LanguageFileType fileType,
                                                Language language,
                                                PatternContext patternContext,
                                                Project project,
                                                boolean physical) {
    if (language == null) {
      language = fileType.getLanguage();
    }
    final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByLanguage(language);
    if (profile != null) {
      final String contextId = patternContext == null ? null : patternContext.getId();
      final PsiElement[] tree = profile.createPatternTree(text, context, fileType, language, contextId, project, physical);
      for (PsiElement branch : tree) {
        System.out.println(DebugUtil.psiToString(branch, false));
      }
      return tree;
    }
    return PsiElement.EMPTY_ARRAY;
  }
}

@@ -363,48 +363,8 @@
 nt;%0A
-import com.intellij.psi.impl.DebugUtil;%0A
 impo
@@ -412,16 +412,16 @@
 ontext;%0A
+
 import c
@@ -1348,33 +1348,14 @@
     
-final PsiElement%5B%5D tree =
+return
  pro
@@ -1456,140 +1456,8 @@
 l);%0A
-      for (PsiElement branch : tree) %7B%0A        System.out.println(DebugUtil.psiToString(branch, false));%0A      %7D%0A      return tree;%0A
     
@@ -2285,33 +2285,14 @@
     
-final PsiElement%5B%5D tree =
+return
  pro
@@ -2384,140 +2384,8 @@
 l);%0A
-      for (PsiElement branch : tree) %7B%0A        System.out.println(DebugUtil.psiToString(branch, false));%0A      %7D%0A      return tree;%0A
     

revert debug output committed by mistake