diff --git a/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java b/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java index 1f251b47dca5..32b910b3b092 100644 --- a/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java +++ b/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java @@ -566,11 +566,8 @@ public final class JavaStructuralSearchProfile extends StructuralSearchProfile { final boolean searchIsExpression = targetNode != null ? getPresentableElement(targetNode) instanceof PsiExpression : isExpressionTemplate(compiledPattern.getVariableNodes(Configuration.CONTEXT_VAR_NAME)); - if (searchIsExpression != replaceIsExpression) { - throw new UnsupportedPatternException( - searchIsExpression ? SSRBundle.message("replacement.template.is.not.expression.error.message") : - SSRBundle.message("search.template.is.not.expression.error.message") - ); + if (searchIsExpression && !replaceIsExpression) { + throw new UnsupportedPatternException(SSRBundle.message("replacement.template.is.not.expression.error.message")); } } diff --git a/platform/structuralsearch/resources/messages/SSRBundle.properties b/platform/structuralsearch/resources/messages/SSRBundle.properties index 270a1aef8475..68bf32f82b57 100644 --- a/platform/structuralsearch/resources/messages/SSRBundle.properties +++ b/platform/structuralsearch/resources/messages/SSRBundle.properties @@ -245,9 +245,9 @@ script.tooltip.message=script reference.target.tooltip.message=reference{0,choice,0#=|1#\u2260}{1} replacement.variable.is.not.defined.message=Unknown search variable ''{0}'' or replacement variable ''{0}'' has no script replacement.variable.is.not.valid=Replacement variable ''{0}'' has script code problem: {1} -replacement.template.is.not.expression.error.message=An expression can not be replaced with a non-expression +replacement.template.is.not.expression.error.message=An expression cannot be replaced with a non-expression replacement.not.supported.for.filetype=Replacement is not supported for {0} file type -search.template.is.not.expression.error.message=A non-expression can not be replaced with an expression +search.template.is.not.expression.error.message=A non-expression cannot be replaced with an expression modify.editor.content.command.name=Modify Editor Content option.is.not.recognized.error.message=Constraint ''{0}'' not recognized diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralReplaceTest.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralReplaceTest.java index a6514053c0df..a0c3192e5c68 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralReplaceTest.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralReplaceTest.java @@ -1730,13 +1730,6 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { String s5 = "a=a;"; String s6 = "a=a"; - try { - replace(s4, s5, s6); - fail("Undefined no ; in replace"); - } - catch (UnsupportedPatternException ignored) { - } - try { replace(s4, s6, s5); fail("Undefined no ; in search"); @@ -2465,6 +2458,14 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { assertEquals("Should replace unmatched annotation parameters when matching just annotation", expected1d, replace(in1, "@SuppressWarnings", "@ SuppressWarnings")); + String what1 = "@SuppressWarnings(\"'value\")"; + String by = "$lower_case$"; + final ReplacementVariableDefinition variable = options.addNewVariableDefinition("lower_case"); + variable.setScriptCodeConstraint("value.getText().toLowerCase()"); + final String expected1e = "@SuppressWarnings(\"all\")\n" + + "public class A {}"; + assertEquals(expected1e, replace(in1, what1, by)); + final String in2 = """ class X {