void (@NotNull Project project, @NotNull ReplaceOptions options) { try { final String search = options.getMatchOptions().getSearchPattern(); final String replacement = options.getReplacement(); final Template searchTemplate = TemplateManager.getInstance(project).createTemplate("" , "", search); final Template replaceTemplate = TemplateManager.getInstance(project).createTemplate("", "", replacement); final int segmentCount = replaceTemplate.getSegmentsCount(); for(int i = 0; i < segmentCount; i++) { final String replacementSegmentName = replaceTemplate.getSegmentName(i); final int segmentCount2 = searchTemplate.getSegmentsCount(); int j = 0; while (j < segmentCount2) { final String searchSegmentName = searchTemplate.getSegmentName(j); if (replacementSegmentName.equals(searchSegmentName)) break; // Reference to if (replacementSegmentName.startsWith(searchSegmentName) && replacementSegmentName.charAt(searchSegmentName.length()) == '_') { try { Integer.parseInt(replacementSegmentName.substring(searchSegmentName.length() + 1)); break; } catch (NumberFormatException ignore) {} } j++; } if (j == segmentCount2) { final ReplacementVariableDefinition definition = options.getVariableDefinition(replacementSegmentName); if (definition == null || definition.getScriptCodeConstraint().length() <= 2 /*empty quotes*/) { throw new MalformedPatternException(SSRBundle.message("replacement.variable.is.not.defined.message", replacementSegmentName)); } else { final String scriptText = StringUtil.unquoteString(definition.getScriptCodeConstraint()); try { ScriptSupport.buildScript(definition.getName(), scriptText, options.getMatchOptions()); } catch (MalformedPatternException e) { throw new MalformedPatternException( SSRBundle.message("replacement.variable.is.not.valid", replacementSegmentName, e.getLocalizedMessage()) ); } } } } final LanguageFileType fileType = options.getMatchOptions().getFileType(); final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(fileType); if (profile != null) { ReadAction.run(() -> profile.checkReplacementPattern(project, options)); } } catch (IncorrectOperationException ex) { throw new MalformedPatternException(SSRBundle.message("incorrect.pattern.message")); } }