Search in sources :

Example 1 with ReplaceOptions

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

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

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

the class ReplaceDialog method setValuesToConfig.

@Override
protected void setValuesToConfig(Configuration config) {
    super.setValuesToConfig(config);
    final ReplaceConfiguration replaceConfiguration = (ReplaceConfiguration) config;
    final ReplaceOptions options = replaceConfiguration.getOptions();
    options.setMatchOptions(replaceConfiguration.getMatchOptions());
    options.setReplacement(replaceCriteriaEdit.getDocument().getText());
    options.setToShortenFQN(shortenFQN.isSelected());
    options.setToReformatAccordingToStyle(formatAccordingToStyle.isSelected());
    options.setToUseStaticImport(useStaticImport.isSelected());
}
Also used : ReplaceOptions(com.intellij.structuralsearch.plugin.replace.ReplaceOptions)

Example 4 with ReplaceOptions

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

the class ReplaceDialog method setValuesFromConfig.

@Override
public void setValuesFromConfig(Configuration configuration) {
    if (configuration instanceof ReplaceConfiguration) {
        final ReplaceConfiguration config = (ReplaceConfiguration) configuration;
        final ReplaceOptions options = config.getOptions();
        super.setValuesFromConfig(config);
        UIUtil.setContent(replaceCriteriaEdit, config.getOptions().getReplacement(), 0, replaceCriteriaEdit.getDocument().getTextLength(), searchContext.getProject());
        shortenFQN.setSelected(options.isToShortenFQN());
        formatAccordingToStyle.setSelected(options.isToReformatAccordingToStyle());
        useStaticImport.setSelected(options.isToUseStaticImport());
        ReplaceOptions newReplaceOptions = ((ReplaceConfiguration) model.getConfig()).getOptions();
        newReplaceOptions.clearVariableDefinitions();
        for (ReplacementVariableDefinition def : options.getReplacementVariableDefinitions()) {
            newReplaceOptions.addVariableDefinition((ReplacementVariableDefinition) def.clone());
        }
    } else {
        super.setValuesFromConfig(configuration);
        UIUtil.setContent(replaceCriteriaEdit, configuration.getMatchOptions().getSearchPattern(), 0, replaceCriteriaEdit.getDocument().getTextLength(), searchContext.getProject());
    }
}
Also used : ReplacementVariableDefinition(com.intellij.structuralsearch.ReplacementVariableDefinition) ReplaceOptions(com.intellij.structuralsearch.plugin.replace.ReplaceOptions)

Example 5 with ReplaceOptions

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

the class StructuralReplaceTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    StructuralSearchUtil.ourUseUniversalMatchingAlgorithm = false;
    LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_4);
    options = new ReplaceOptions();
    options.setMatchOptions(new MatchOptions());
    replacer = new Replacer(getProject(), null);
}
Also used : ReplaceOptions(com.intellij.structuralsearch.plugin.replace.ReplaceOptions) Replacer(com.intellij.structuralsearch.plugin.replace.impl.Replacer)

Aggregations

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