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