SSR: copy constructor forgot to copy additional constraints
authorBas Leijdekkers <basleijdekkers@gmail.com>
Mon, 10 Aug 2020 14:50:44 +0000 (16:50 +0200)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Mon, 10 Aug 2020 19:48:59 +0000 (19:48 +0000)
GitOrigin-RevId: 2965b9daf54d2f9d3d4afe06ee1981d045a75681

platform/structuralsearch/source/com/intellij/structuralsearch/MatchVariableConstraint.java
platform/structuralsearch/testSource/com/intellij/structuralsearch/MatchVariableConstraintTest.java

index 6a9cbc4dd22ff544240dd10b1462cce97bf4cce2..2f50edd68b66cecee1600d8b070c9a09138ff068 100644 (file)
@@ -116,6 +116,12 @@ public class MatchVariableConstraint extends NamedScriptableDefinition {
     invertContainsConstraint = constraint.invertContainsConstraint;
     invertWithinConstraint = constraint.invertWithinConstraint;
     contextConstraint = constraint.contextConstraint;
+    final Map<String, String> additionalConstraints = constraint.additionalConstraints;
+    if (additionalConstraints != null) {
+      for (Map.Entry<String, String> entry : additionalConstraints.entrySet()) {
+        putAdditionalConstraint(entry.getKey(), entry.getValue());
+      }
+    }
   }
 
   @Override
index 6058a4019aa008782cbf381313ccb7796a7b1381..f9619064d51ef943a1dd238120178528c7c0bac2 100644 (file)
@@ -34,7 +34,7 @@ public class MatchVariableConstraintTest extends LightPlatformTestCase {
                  JDOMUtil.writeElement(test));
   }
 
-  public void testAdditionalConstraints1() {
+  public void testAdditionalConstraints() {
     final MatchVariableConstraint constraint = new MatchVariableConstraint();
     assertNull(constraint.getAdditionalConstraint("hypergolic"));
     try {
@@ -60,9 +60,11 @@ public class MatchVariableConstraintTest extends LightPlatformTestCase {
     final MatchVariableConstraint constraint2 = new MatchVariableConstraint();
     constraint2.readExternal(element);
     assertEquals("test", constraint2.getAdditionalConstraint("test"));
+    final MatchVariableConstraint constraint3 = constraint2.copy();
+    assertEquals("test", constraint3.getAdditionalConstraint("test"));
     assertEquals(String.valueOf(constraint2.getAllAdditionalConstraints()), 1, constraint2.getAllAdditionalConstraints().size());
 
-    constraint.putAdditionalConstraint("test",null);
+    constraint.putAdditionalConstraint("test", null);
     assertTrue(constraint.equals(new MatchVariableConstraint()));
   }