Search in sources :

Example 1 with ReplaceConfiguration

use of com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration in project intellij-community by JetBrains.

the class ConfigurationManager method readConfiguration.

public static Configuration readConfiguration(final Element childElement) {
    String s = childElement.getName();
    final Configuration config = s.equals(SEARCH_TAG_NAME) ? new SearchConfiguration() : s.equals(REPLACE_TAG_NAME) ? new ReplaceConfiguration() : null;
    if (config != null)
        config.readExternal(childElement);
    return config;
}
Also used : ReplaceConfiguration(com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration) ReplaceConfiguration(com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration)

Example 2 with ReplaceConfiguration

use of com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration in project intellij-community by JetBrains.

the class EditVarConstraintsDialog method getOrAddReplacementVariableDefinition.

private static ReplacementVariableDefinition getOrAddReplacementVariableDefinition(String varName, Configuration configuration) {
    ReplaceOptions replaceOptions = ((ReplaceConfiguration) configuration).getOptions();
    String realVariableName = stripReplacementVarDecoration(varName);
    ReplacementVariableDefinition variableDefinition = replaceOptions.getVariableDefinition(realVariableName);
    if (variableDefinition == null) {
        variableDefinition = new ReplacementVariableDefinition();
        variableDefinition.setName(realVariableName);
        replaceOptions.addVariableDefinition(variableDefinition);
    }
    return variableDefinition;
}
Also used : ReplaceOptions(com.intellij.structuralsearch.plugin.replace.ReplaceOptions) ReplaceConfiguration(com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration)

Example 3 with ReplaceConfiguration

use of com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration in project intellij-community by JetBrains.

the class SSBasedInspection method createQuickFix.

private static LocalQuickFix createQuickFix(final Project project, final MatchResult matchResult, final Configuration configuration) {
    if (!(configuration instanceof ReplaceConfiguration))
        return null;
    ReplaceConfiguration replaceConfiguration = (ReplaceConfiguration) configuration;
    final Replacer replacer = new Replacer(project, replaceConfiguration.getOptions());
    final ReplacementInfo replacementInfo = replacer.buildReplacement(matchResult);
    return new LocalQuickFix() {

        @Override
        @NotNull
        public String getName() {
            return SSRBundle.message("SSRInspection.replace.with", replacementInfo.getReplacement());
        }

        @Override
        public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
            PsiElement element = descriptor.getPsiElement();
            if (element != null) {
                replacer.replace(replacementInfo);
            }
        }

        @Override
        @NotNull
        public String getFamilyName() {
            return SSRBundle.message("SSRInspection.family.name");
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) Replacer(com.intellij.structuralsearch.plugin.replace.impl.Replacer) ReplacementInfo(com.intellij.structuralsearch.plugin.replace.ReplacementInfo) ReplaceConfiguration(com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement)

Example 4 with ReplaceConfiguration

use of com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration 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 ReplaceConfiguration

use of com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration 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

ReplaceConfiguration (com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration)6 MatchOptions (com.intellij.structuralsearch.MatchOptions)2 NotNull (org.jetbrains.annotations.NotNull)2 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 ReplaceOptions (com.intellij.structuralsearch.plugin.replace.ReplaceOptions)1 ReplacementInfo (com.intellij.structuralsearch.plugin.replace.ReplacementInfo)1 Replacer (com.intellij.structuralsearch.plugin.replace.impl.Replacer)1 ReplaceDialog (com.intellij.structuralsearch.plugin.replace.ui.ReplaceDialog)1