@Override public void postProcess(PsiElement affectedElement, ReplaceOptions options) { if (!affectedElement.isValid()) { return; } if (options.isToUseStaticImport()) { shortenWithStaticImports(affectedElement, 0, affectedElement.getTextLength()); } if (options.isToShortenFQN()) { final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(affectedElement.getProject()); codeStyleManager.shortenClassReferences(affectedElement, 0, affectedElement.getTextLength()); } }
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()); }
@Override public void checkReplacementPattern(Project project, ReplaceOptions options) { final CompiledPattern compiledPattern = PatternCompiler.compilePattern(project, options.getMatchOptions()); if (compiledPattern == null) { return; } final NodeIterator it = compiledPattern.getNodes(); if (!it.hasNext()) { return; } final PsiElement root = it.current().getParent(); if (!checkOptionalChildren(root) || !checkErrorElements(root)) { throw new UnsupportedPatternException(": Partial and expression patterns are not supported"); } }
public void setValuesFromConfig(Configuration configuration) { // replaceCriteriaEdit.putUserData(SubstitutionShortInfoHandler.CURRENT_CONFIGURATION_KEY, // 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()); } }