Search in sources :

Example 1 with MatchOptions

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

the class TypeConversionDescriptor method replaceExpression.

@NotNull
public static PsiExpression replaceExpression(@NotNull PsiExpression expression, String stringToReplace, String replaceByString) {
    Project project = expression.getProject();
    final ReplaceOptions options = new ReplaceOptions();
    final MatchOptions matchOptions = options.getMatchOptions();
    matchOptions.setFileType(StdFileTypes.JAVA);
    final Replacer replacer = new Replacer(project, null);
    final String replacement = replacer.testReplace(expression.getText(), stringToReplace, replaceByString, options);
    return (PsiExpression) JavaCodeStyleManager.getInstance(project).shortenClassReferences(expression.replace(JavaPsiFacade.getInstance(project).getElementFactory().createExpressionFromText(replacement, expression)));
}
Also used : Project(com.intellij.openapi.project.Project) PsiExpression(com.intellij.psi.PsiExpression) MatchOptions(com.intellij.structuralsearch.MatchOptions) ReplaceOptions(com.intellij.structuralsearch.plugin.replace.ReplaceOptions) Replacer(com.intellij.structuralsearch.plugin.replace.impl.Replacer) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with MatchOptions

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

the class FindInFilesOptimizingSearchHelper method doAddSearchWordInText.

protected void doAddSearchWordInText(final String refname) {
    final MatchOptions options = context.getOptions();
    CacheManager.SERVICE.getInstance(myProject).processFilesWithWord(myFileProcessor, refname, UsageSearchContext.IN_PLAIN_TEXT, (GlobalSearchScope) options.getScope(), options.isCaseSensitiveMatch());
}
Also used : MatchOptions(com.intellij.structuralsearch.MatchOptions)

Example 3 with MatchOptions

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

the class FindInFilesOptimizingSearchHelper method doAddSearchWordInCode.

protected void doAddSearchWordInCode(final String refname) {
    final MatchOptions options = context.getOptions();
    CacheManager.SERVICE.getInstance(myProject).processFilesWithWord(myFileProcessor, refname, UsageSearchContext.IN_CODE, (GlobalSearchScope) options.getScope(), options.isCaseSensitiveMatch());
}
Also used : MatchOptions(com.intellij.structuralsearch.MatchOptions)

Example 4 with MatchOptions

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

the class SelectTemplateDialog method showPatternPreviewFromConfiguration.

private void showPatternPreviewFromConfiguration(@Nullable final Configuration configuration) {
    if (configuration == null) {
        myCardLayout.show(myPreviewPanel, SELECT_TEMPLATE_CARD);
        return;
    } else {
        myCardLayout.show(myPreviewPanel, PREVIEW_CARD);
    }
    final MatchOptions matchOptions = configuration.getMatchOptions();
    UIUtil.setContent(searchPatternEditor, matchOptions.getSearchPattern(), 0, searchPatternEditor.getDocument().getTextLength(), project);
    searchPatternEditor.putUserData(SubstitutionShortInfoHandler.CURRENT_CONFIGURATION_KEY, configuration);
    if (replace) {
        String replacement;
        if (configuration instanceof ReplaceConfiguration) {
            replacement = ((ReplaceConfiguration) configuration).getOptions().getReplacement();
        } else {
            replacement = configuration.getMatchOptions().getSearchPattern();
        }
        UIUtil.setContent(replacePatternEditor, replacement, 0, replacePatternEditor.getDocument().getTextLength(), project);
        replacePatternEditor.putUserData(SubstitutionShortInfoHandler.CURRENT_CONFIGURATION_KEY, configuration);
    }
}
Also used : MatchOptions(com.intellij.structuralsearch.MatchOptions) ReplaceConfiguration(com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration)

Example 5 with MatchOptions

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

the class StructuralSearchUsageTarget method getLongDescriptiveName.

@NotNull
@Override
public String getLongDescriptiveName() {
    final MatchOptions matchOptions = myConfiguration.getMatchOptions();
    final String pattern = matchOptions.getSearchPattern();
    final String scope = matchOptions.getScope().getDisplayName();
    final String result;
    if (myConfiguration instanceof ReplaceConfiguration) {
        final ReplaceConfiguration replaceConfiguration = (ReplaceConfiguration) myConfiguration;
        final String replacement = replaceConfiguration.getOptions().getReplacement();
        result = SSRBundle.message("replace.occurrences.of.0.with.1.in.2", pattern, replacement, scope);
    } else {
        result = SSRBundle.message("occurrences.of.0.in.1", pattern, scope);
    }
    return StringUtil.shortenTextWithEllipsis(result, 150, 0, true);
}
Also used : MatchOptions(com.intellij.structuralsearch.MatchOptions) ReplaceConfiguration(com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MatchOptions (com.intellij.structuralsearch.MatchOptions)8 ReplaceConfiguration (com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration)2 NotNull (org.jetbrains.annotations.NotNull)2 Project (com.intellij.openapi.project.Project)1 PsiExpression (com.intellij.psi.PsiExpression)1 MatchResult (com.intellij.structuralsearch.MatchResult)1 Matcher (com.intellij.structuralsearch.Matcher)1 ReplaceOptions (com.intellij.structuralsearch.plugin.replace.ReplaceOptions)1 Replacer (com.intellij.structuralsearch.plugin.replace.impl.Replacer)1