From 269746aa7843e41a7aa4dd3cf9da731dc18a7d43 Mon Sep 17 00:00:00 2001 From: Marc Englund Date: Wed, 29 Aug 2012 18:19:21 +0300 Subject: [PATCH] Applied patch fixing #9347 (mixin w/ args + nested blocks), includes test --- build/build.xml | 6 ++++++ sass/src/com/vaadin/sass/tree/BlockNode.java | 21 ++++++++++++++----- sass/src/com/vaadin/sass/util/Clonable.java | 7 +++++++ sass/src/com/vaadin/sass/util/DeepCopy.java | 15 ++++++++++++- tests/sass/resources/css/mixins.css | 5 +++++ tests/sass/resources/scss/mixins.scss | 11 ++++++++++ .../vaadin/sass/testcases/scss/Mixins.java | 10 +++++---- 7 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 sass/src/com/vaadin/sass/util/Clonable.java diff --git a/build/build.xml b/build/build.xml index 9d0ca0069c..01775520d0 100644 --- a/build/build.xml +++ b/build/build.xml @@ -664,6 +664,11 @@ + + + + + @@ -1382,6 +1387,7 @@ + diff --git a/sass/src/com/vaadin/sass/tree/BlockNode.java b/sass/src/com/vaadin/sass/tree/BlockNode.java index 2879cd57ea..685c3ac3f0 100644 --- a/sass/src/com/vaadin/sass/tree/BlockNode.java +++ b/sass/src/com/vaadin/sass/tree/BlockNode.java @@ -20,8 +20,10 @@ import org.w3c.css.sac.SelectorList; import com.vaadin.sass.parser.SelectorListImpl; import com.vaadin.sass.selector.SelectorUtil; +import com.vaadin.sass.util.Clonable; +import com.vaadin.sass.util.DeepCopy; -public class BlockNode extends Node { +public class BlockNode extends Node implements Clonable { private static final long serialVersionUID = 5742962631468325048L; @@ -62,12 +64,21 @@ public class BlockNode extends Node { } @Override - protected Object clone() throws CloneNotSupportedException { - SelectorListImpl clonedSelectorList = new SelectorListImpl(); + public Object clone() throws CloneNotSupportedException { + + SelectorListImpl clonedSelectorList = null; + + if (selectorList != null) { + clonedSelectorList = new SelectorListImpl(); for (int i = 0; i < selectorList.getLength(); i++) { clonedSelectorList.addSelector(selectorList.item(i)); } - return null; - // BlockNode clone = new BlockNode() } + final BlockNode clone = new BlockNode(clonedSelectorList); + for (Node child : getChildren()) { + clone.getChildren().add((Node) DeepCopy.copy(child)); + } + return clone; + } + } diff --git a/sass/src/com/vaadin/sass/util/Clonable.java b/sass/src/com/vaadin/sass/util/Clonable.java new file mode 100644 index 0000000000..639f158fb0 --- /dev/null +++ b/sass/src/com/vaadin/sass/util/Clonable.java @@ -0,0 +1,7 @@ +package com.vaadin.sass.util; + +public interface Clonable { + + public Object clone() throws CloneNotSupportedException; + +} diff --git a/sass/src/com/vaadin/sass/util/DeepCopy.java b/sass/src/com/vaadin/sass/util/DeepCopy.java index 712b8ecc11..23f8386714 100644 --- a/sass/src/com/vaadin/sass/util/DeepCopy.java +++ b/sass/src/com/vaadin/sass/util/DeepCopy.java @@ -35,7 +35,9 @@ public class DeepCopy { * Returns a copy of the object, or null if the object cannot be serialized. */ public static Object copy(Object orig) { + Object obj = null; + if (!(orig instanceof Clonable)) { try { // Write the object out to a byte array FastByteArrayOutputStream fbos = new FastByteArrayOutputStream(); @@ -46,7 +48,8 @@ public class DeepCopy { // Retrieve an input stream from the byte array and read // a copy of the object back in. - ObjectInputStream in = new ObjectInputStream(fbos.getInputStream()); + ObjectInputStream in = new ObjectInputStream( + fbos.getInputStream()); obj = in.readObject(); in.close(); } catch (IOException e) { @@ -55,6 +58,16 @@ public class DeepCopy { cnfe.printStackTrace(); } return obj; + } else { + try { + obj = ((Clonable) orig).clone(); + } catch (ClassCastException e2) { + // Can't clone, return obj as null + } catch (CloneNotSupportedException e2) { + // Can't clone, return obj as null + } + return obj; + } } } \ No newline at end of file diff --git a/tests/sass/resources/css/mixins.css b/tests/sass/resources/css/mixins.css index cd5c9b85aa..5c727c193b 100644 --- a/tests/sass/resources/css/mixins.css +++ b/tests/sass/resources/css/mixins.css @@ -8,6 +8,11 @@ font-weight: bold; } +.main .details { + font-size: 14px; + font-weight: bold; +} + .footer { border: 2px solid black; -webkit-border-radius: 10px; diff --git a/tests/sass/resources/scss/mixins.scss b/tests/sass/resources/scss/mixins.scss index f16c9a0e06..52e03d62c1 100644 --- a/tests/sass/resources/scss/mixins.scss +++ b/tests/sass/resources/scss/mixins.scss @@ -16,6 +16,7 @@ .main { @include rounded-borders(1px); @include font-settings; + @include main-details(14px); } .footer { @@ -41,4 +42,14 @@ } @include font-settings; } + +@mixin main-details($size){ + .details { + font: { + size : $size; + weight: bold; + } + } +} + @include layout; \ No newline at end of file diff --git a/tests/sass/src/com/vaadin/sass/testcases/scss/Mixins.java b/tests/sass/src/com/vaadin/sass/testcases/scss/Mixins.java index c801ab1437..05b3d3c83e 100644 --- a/tests/sass/src/com/vaadin/sass/testcases/scss/Mixins.java +++ b/tests/sass/src/com/vaadin/sass/testcases/scss/Mixins.java @@ -69,7 +69,7 @@ public class Mixins extends AbstractTestBase { Assert.assertEquals(4, mixinDefNode1.getChildren().size()); BlockNode mainBlockNode = (BlockNode) root.getChildren().get(2); - Assert.assertEquals(2, mainBlockNode.getChildren().size()); + Assert.assertEquals(3, mainBlockNode.getChildren().size()); MixinNode mixinNode0MainBlock = (MixinNode) mainBlockNode.getChildren() .get(0); Assert.assertEquals("rounded-borders", mixinNode0MainBlock.getName()); @@ -82,6 +82,11 @@ public class Mixins extends AbstractTestBase { Assert.assertEquals("font-settings", mixinNOde1MainBlock.getName()); Assert.assertTrue(mixinNOde1MainBlock.getArglist().isEmpty()); + MixinNode mixinNOde2MainBlock = (MixinNode) mainBlockNode.getChildren() + .get(2); + Assert.assertEquals("main-details", mixinNOde2MainBlock.getName()); + Assert.assertTrue(mixinNOde1MainBlock.getArglist().isEmpty()); + MixinNode mixinNode1MainBlock = (MixinNode) mainBlockNode.getChildren() .get(1); Assert.assertTrue(mixinNode1MainBlock.getArglist().isEmpty()); @@ -103,9 +108,6 @@ public class Mixins extends AbstractTestBase { Assert.assertTrue(root.getChildren().get(4).getChildren().get(3) instanceof MediaNode); Assert.assertTrue(root.getChildren().get(4).getChildren().get(4) instanceof MixinNode); - MixinNode topLevelMixin = (MixinNode) root.getChildren().get(5); - Assert.assertEquals("layout", topLevelMixin.getName()); - } @Test -- 2.39.5