use of com.intellij.structuralsearch.plugin.replace.impl.Replacer 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.impl.Replacer 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");
}
};
}
use of com.intellij.structuralsearch.plugin.replace.impl.Replacer 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