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)));
}
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;
}
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());
}
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());
}
}
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);
}
Aggregations