summaryrefslogtreecommitdiff
path: root/plugins/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/MatcherImplUtil.java
blob: ffc9ae78e8768f97bdfea8dfa42d0d8f4784c6ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.intellij.structuralsearch.impl.matcher;

import com.intellij.lang.Language;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.structuralsearch.MatchOptions;
import com.intellij.structuralsearch.StructuralSearchProfile;
import com.intellij.structuralsearch.StructuralSearchUtil;
import com.intellij.structuralsearch.impl.matcher.compiler.PatternCompiler;
import com.intellij.util.IncorrectOperationException;

/**
 * Created by IntelliJ IDEA.
 * User: Maxim.Mossienko
 * Date: Mar 19, 2004
 * Time: 6:56:25 PM
 * To change this template use File | Settings | File Templates.
 */
public class MatcherImplUtil {

  public static void transform(MatchOptions options) {
    if (options.hasVariableConstraints()) return;
    PatternCompiler.transformOldPattern(options);
  }

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

  public static PsiElement[] createSourceTreeFromText(String text,
                                                      PatternTreeContext context,
                                                      FileType fileType,
                                                      String extension,
                                                      Project project,
                                                      boolean physical) {
    if (fileType instanceof LanguageFileType) {
      Language language = ((LanguageFileType)fileType).getLanguage();
      StructuralSearchProfile profile = StructuralSearchUtil.getProfileByLanguage(language);
      if (profile != null) {
        return profile.createPatternTree(text, context, fileType, null, null, extension, project, physical);
      }
    }
    return PsiElement.EMPTY_ARRAY;
  }

  public static PsiElement[] createTreeFromText(String text,
                                                PatternTreeContext context,
                                                FileType fileType,
                                                Language language,
                                                String contextName,
                                                Project project,
                                                boolean physical) throws IncorrectOperationException {
    if (language == null && fileType instanceof LanguageFileType) {
      language = ((LanguageFileType)fileType).getLanguage();
    }
    if (language != null) {
      StructuralSearchProfile profile = StructuralSearchUtil.getProfileByLanguage(language);
      if (profile != null) {
        return profile.createPatternTree(text, context, fileType, language, contextName, null, project, physical);
      }
    }
    return PsiElement.EMPTY_ARRAY;
  }
}