IntPairAttributeParser now actually parses

Review by jgw
http://gwt-code-reviews.appspot.com/132811

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@7432 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/uibinder/attributeparsers/AttributeParsers.java b/user/src/com/google/gwt/uibinder/attributeparsers/AttributeParsers.java
index 70af3f9..5b0c9c3 100644
--- a/user/src/com/google/gwt/uibinder/attributeparsers/AttributeParsers.java
+++ b/user/src/com/google/gwt/uibinder/attributeparsers/AttributeParsers.java
@@ -69,7 +69,7 @@
       addAttributeParser(DOUBLE, doubleParser);
       addAttributeParser(Double.class.getCanonicalName(), doubleParser);
       
-      addAttributeParser("int,int", new IntPairParser());
+      addAttributeParser("int,int", new IntPairAttributeParser(intParser, logger));
       
       addAttributeParser(HORIZ_CONSTANT, new HorizontalAlignmentConstantParser(
           converter, types.parse(HORIZ_CONSTANT), logger));
diff --git a/user/src/com/google/gwt/uibinder/attributeparsers/IntPairAttributeParser.java b/user/src/com/google/gwt/uibinder/attributeparsers/IntPairAttributeParser.java
new file mode 100644
index 0000000..1bb1238
--- /dev/null
+++ b/user/src/com/google/gwt/uibinder/attributeparsers/IntPairAttributeParser.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2007 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.uibinder.attributeparsers;
+
+import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.uibinder.rebind.MortalLogger;
+
+/**
+ * Parses a pair of integer values.
+ */
+class IntPairAttributeParser implements AttributeParser {
+
+  private final IntAttributeParser intParser;
+  private final MortalLogger logger;
+  
+  IntPairAttributeParser(IntAttributeParser intParser, MortalLogger logger) {
+    this.intParser = intParser;
+    this.logger = logger;
+  }
+  
+  public String parse(String value) throws UnableToCompleteException {
+    String[] values = value.split(",");
+    if (values.length != 2) {
+      die(value);
+    }
+    
+    String left = intParser.parse(values[0].trim());
+    String right = intParser.parse(values[1].trim());
+    return String.format("%s, %s", left, right);
+  }
+
+  private void die(String value) throws UnableToCompleteException {
+    logger.die("Unable to parse \"%s\" as a pair of integers", value);
+  }
+}
diff --git a/user/src/com/google/gwt/uibinder/attributeparsers/IntPairParser.java b/user/src/com/google/gwt/uibinder/attributeparsers/IntPairParser.java
deleted file mode 100644
index 921942b..0000000
--- a/user/src/com/google/gwt/uibinder/attributeparsers/IntPairParser.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2007 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.uibinder.attributeparsers;
-
-/**
- * Parses a pair of integer values.
- */
-class IntPairParser implements AttributeParser {
-
-  public String parse(String value) {
-    // TODO(jgw): parse & validate
-    return value;
-  }
-}
diff --git a/user/src/com/google/gwt/uibinder/attributeparsers/LengthAttributeParser.java b/user/src/com/google/gwt/uibinder/attributeparsers/LengthAttributeParser.java
index d111e67..21743df 100644
--- a/user/src/com/google/gwt/uibinder/attributeparsers/LengthAttributeParser.java
+++ b/user/src/com/google/gwt/uibinder/attributeparsers/LengthAttributeParser.java
@@ -39,7 +39,7 @@
   private final DoubleAttributeParser doubleParser;
   private final EnumAttributeParser enumParser;
 
-  public LengthAttributeParser(DoubleAttributeParser doubleParser,
+  LengthAttributeParser(DoubleAttributeParser doubleParser,
       EnumAttributeParser enumParser, MortalLogger logger) {
     this.doubleParser = doubleParser;
     this.enumParser = enumParser;
diff --git a/user/test/com/google/gwt/uibinder/UiBinderJreSuite.java b/user/test/com/google/gwt/uibinder/UiBinderJreSuite.java
index f61d522..9ff047d 100644
--- a/user/test/com/google/gwt/uibinder/UiBinderJreSuite.java
+++ b/user/test/com/google/gwt/uibinder/UiBinderJreSuite.java
@@ -18,6 +18,7 @@
 import com.google.gwt.uibinder.attributeparsers.CssNameConverterTest;
 import com.google.gwt.uibinder.attributeparsers.FieldReferenceConverterTest;
 import com.google.gwt.uibinder.attributeparsers.IntAttributeParserTest;
+import com.google.gwt.uibinder.attributeparsers.IntPairAttributeParserTest;
 import com.google.gwt.uibinder.attributeparsers.LengthAttributeParserTest;
 import com.google.gwt.uibinder.attributeparsers.StrictAttributeParserTest;
 import com.google.gwt.uibinder.attributeparsers.StringAttributeParserTest;
@@ -63,6 +64,7 @@
     // attributeparsers
     suite.addTestSuite(CssNameConverterTest.class);
     suite.addTestSuite(IntAttributeParserTest.class);
+    suite.addTestSuite(IntPairAttributeParserTest.class);
     suite.addTestSuite(FieldReferenceConverterTest.class);
     suite.addTestSuite(StrictAttributeParserTest.class);
     suite.addTestSuite(StringAttributeParserTest.class);
diff --git a/user/test/com/google/gwt/uibinder/attributeparsers/IntPairAttributeParserTest.java b/user/test/com/google/gwt/uibinder/attributeparsers/IntPairAttributeParserTest.java
new file mode 100644
index 0000000..25ff237
--- /dev/null
+++ b/user/test/com/google/gwt/uibinder/attributeparsers/IntPairAttributeParserTest.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2010 Google Inc.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.uibinder.attributeparsers;
+
+import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.core.ext.typeinfo.TypeOracle;
+import com.google.gwt.dev.javac.CompilationState;
+import com.google.gwt.dev.javac.CompilationStateBuilder;
+import com.google.gwt.uibinder.rebind.MortalLogger;
+import com.google.gwt.uibinder.test.UiJavaResources;
+
+import junit.framework.TestCase;
+
+/**
+ * Eponymous test class.
+ */
+public class IntPairAttributeParserTest extends TestCase {
+  private IntPairAttributeParser parser;
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+
+    MortalLogger logger = MortalLogger.NULL;
+
+    CompilationState state = CompilationStateBuilder.buildFrom(
+        logger.getTreeLogger(), UiJavaResources.getUiResources());
+    TypeOracle types = state.getTypeOracle();
+
+    FieldReferenceConverter converter = new FieldReferenceConverter(null);
+    IntAttributeParser intParser = new IntAttributeParser(converter,
+        types.parse("int"), logger);
+
+    parser = new IntPairAttributeParser(intParser, logger);
+  }
+
+  public void testGood() throws UnableToCompleteException {
+    assertEquals("1, 1", parser.parse("1, 1"));
+    assertEquals("123, 456", parser.parse("123, 456"));
+    assertEquals("(int)able.baker(), (int)charlie.delta()",
+        parser.parse("{able.baker}, {charlie.delta}"));
+    assertEquals("0001, 0002", parser.parse("0001, 0002"));
+  }
+
+  public void testBad() {
+    try {
+      parser.parse("fnord");
+      fail("Expected UnableToCompleteException");
+    } catch (UnableToCompleteException e) {
+      /* pass */
+    }
+
+    try {
+      parser.parse("1, 2, 3");
+      fail("Expected UnableToCompleteException");
+    } catch (UnableToCompleteException e) {
+      /* pass */
+    }
+
+    try {
+      parser.parse("1");
+      fail("Expected UnableToCompleteException");
+    } catch (UnableToCompleteException e) {
+      /* pass */
+    }
+
+    try {
+      parser.parse("1.2, 3.4");
+      fail("Expected UnableToCompleteException");
+    } catch (UnableToCompleteException e) {
+      /* pass */
+    }
+  }
+}
diff --git a/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java b/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java
index 630137b..e20349a 100644
--- a/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java
+++ b/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java
@@ -453,6 +453,11 @@
     assertEquals("expected style name", widget.getStyleName());
   }
 
+  public void testIntPair() {
+    assertEquals(100, widgetUi.sideBarWidget.getOffsetWidth());
+    assertEquals(150, widgetUi.sideBarWidget.getOffsetHeight());
+  }
+  
   public void testDataResource() {
     assertNotNull(widgetUi.heartCursorResource.getUrl());
   }
diff --git a/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.java b/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.java
index 1aa457e..ca6cdb0 100644
--- a/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.java
+++ b/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.java
@@ -100,6 +100,7 @@
   @UiField Tree myTree;
   @UiField Element nonStandardElement;
   @UiField DockPanel root;
+  @UiField Widget sideBarWidget;
   @UiField DivElement sideBar;
   @UiField SpanElement spanInMsg;
   @UiField Element tmElement;
diff --git a/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml b/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml
index bb063e0..fb21f67 100644
--- a/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml
+++ b/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml
@@ -152,7 +152,7 @@
     </gwt:HTML>
   </gwt:Dock>
   <gwt:Dock direction='WEST'>
-    <gwt:HTML>
+    <gwt:HTML ui:field='sideBarWidget' pixelSize="100, 150">
       <div ui:field="sideBar"
       style='border: 4px solid gray; padding: 4px; margin: 4px;'
       >This could<br/>