Search in sources :

Example 1 with StructuralSearchProfile

use of com.intellij.structuralsearch.StructuralSearchProfile in project intellij-community by JetBrains.

the class ReplacementBuilder method process.

String process(MatchResult match, ReplacementInfoImpl replacementInfo, FileType type) {
    if (parameterizations == null) {
        return replacement;
    }
    final StringBuilder result = new StringBuilder(replacement);
    final HashMap<String, MatchResult> matchMap = new HashMap<>();
    fill(match, matchMap);
    final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(type);
    assert profile != null;
    int offset = 0;
    for (final ParameterInfo info : parameterizations) {
        MatchResult r = matchMap.get(info.getName());
        if (info.isReplacementVariable()) {
            offset = Replacer.insertSubstitution(result, offset, info, generateReplacement(info, match));
        } else if (r != null) {
            offset = profile.handleSubstitution(info, r, result, offset, matchMap);
        } else {
            offset = profile.handleNoSubstitution(info, offset, result);
        }
    }
    replacementInfo.variableMap = matchMap;
    return result.toString();
}
Also used : HashMap(java.util.HashMap) StructuralSearchProfile(com.intellij.structuralsearch.StructuralSearchProfile) MatchResult(com.intellij.structuralsearch.MatchResult)

Example 2 with StructuralSearchProfile

use of com.intellij.structuralsearch.StructuralSearchProfile in project intellij-community by JetBrains.

the class ReplacementPreviewDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    JComponent centerPanel = new JPanel(new BorderLayout());
    PsiFile file = null;
    final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(myFileType);
    if (profile != null) {
        file = profile.createCodeFragment(project, "", null);
    }
    if (file != null) {
        final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
        replacement = UIUtil.createEditor(document, project, true, null);
        DaemonCodeAnalyzer.getInstance(project).setHighlightingEnabled(file, false);
    } else {
        final EditorFactory factory = EditorFactory.getInstance();
        final Document document = factory.createDocument("");
        replacement = factory.createEditor(document, project, myFileType, false);
    }
    centerPanel.add(BorderLayout.NORTH, new JLabel(SSRBundle.message("replacement.code")));
    centerPanel.add(BorderLayout.CENTER, replacement.getComponent());
    centerPanel.setMaximumSize(new Dimension(640, 480));
    return centerPanel;
}
Also used : EditorFactory(com.intellij.openapi.editor.EditorFactory) StructuralSearchProfile(com.intellij.structuralsearch.StructuralSearchProfile) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document)

Example 3 with StructuralSearchProfile

use of com.intellij.structuralsearch.StructuralSearchProfile in project intellij-community by JetBrains.

the class GlobalCompilingVisitor method compile.

void compile(PsiElement[] elements, CompileContext context) {
    myCodeBlockLevel = 0;
    this.context = context;
    final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(context.getOptions().getFileType());
    assert profile != null;
    profile.compile(elements, this);
    if (context.getPattern().getStrategy() == null) {
        System.out.println();
    }
}
Also used : StructuralSearchProfile(com.intellij.structuralsearch.StructuralSearchProfile)

Example 4 with StructuralSearchProfile

use of com.intellij.structuralsearch.StructuralSearchProfile in project intellij-community by JetBrains.

the class MatcherImplUtil method createSourceTreeFromText.

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;
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) StructuralSearchProfile(com.intellij.structuralsearch.StructuralSearchProfile)

Aggregations

StructuralSearchProfile (com.intellij.structuralsearch.StructuralSearchProfile)4 Language (com.intellij.lang.Language)1 Document (com.intellij.openapi.editor.Document)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 PsiFile (com.intellij.psi.PsiFile)1 MatchResult (com.intellij.structuralsearch.MatchResult)1 HashMap (java.util.HashMap)1