Roberto Lublinerman has uploaded a new change for review.
https://gwt-review.googlesource.com/3100
Change subject: Allow line breaks and other whitespace in jsni method
references.
......................................................................
Allow line breaks and other whitespace in jsni method references.
This allows for whitespace in the param list within jsni method references
so
long lines can be broken up.
Adds several test cases for JSNI references.
Original Author: Kelly Campbell <[email protected]>
Change-Id: Iecacf3b8be1e512a5fdf3132245091b4ebea9c68
---
M dev/core/src/com/google/gwt/dev/js/rhino/TokenStream.java
M dev/core/test/com/google/gwt/dev/js/TokenStreamTest.java
2 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/dev/core/src/com/google/gwt/dev/js/rhino/TokenStream.java
b/dev/core/src/com/google/gwt/dev/js/rhino/TokenStream.java
index 934eabb..a677b31 100644
--- a/dev/core/src/com/google/gwt/dev/js/rhino/TokenStream.java
+++ b/dev/core/src/com/google/gwt/dev/js/rhino/TokenStream.java
@@ -1343,6 +1343,15 @@
}
}
+ private void skipWhitespace() throws IOException {
+ int tmp;
+ do {
+ tmp = in.read();
+ } while (isJSSpace(tmp) || tmp == '\n');
+ // Reposition back to first non whitespace char.
+ in.unread();
+ }
+
private int jsniMatchReference() throws IOException {
// First, read the type name whose member is being accessed.
@@ -1359,9 +1368,11 @@
return ERROR;
}
addToString(c);
-
+
+ // Skip whitespace starting after ::.
+ skipWhitespace();
+
// Finish by reading the field or method signature.
- //
if (!jsniMatchMethodSignatureOrFieldName()) {
return ERROR;
}
@@ -1373,7 +1384,9 @@
private boolean jsniMatchParamListSignature() throws IOException {
// Assume the opening '(' has already been read.
// Read param type signatures until we see a closing ')'.
- //
+
+ skipWhitespace();
+
// First check for the special case of * as the parameter list,
indicating
// a wildcard
if (in.peek() == '*') {
@@ -1384,20 +1397,24 @@
addToString(in.read());
return true;
}
-
+
// Otherwise, loop through reading one param type at a time
do {
+ // Skip whitespace between parameters.
+ skipWhitespace();
+
int c = in.read();
+
if (c == ')') {
// Finished successfully.
//
addToString(c);
return true;
}
-
+
in.unread();
} while (jsniMatchParamTypeSignature());
-
+
// If we made it here, we can assume that there was an invalid type
// signature that was already reported and that the offending char
// was already unread.
@@ -1443,7 +1460,8 @@
private boolean jsniMatchMethodSignatureOrFieldName() throws
IOException {
int c = in.read();
-
+
+
// We must see an ident start here.
//
if (!Character.isJavaIdentifierStart((char)c)) {
diff --git a/dev/core/test/com/google/gwt/dev/js/TokenStreamTest.java
b/dev/core/test/com/google/gwt/dev/js/TokenStreamTest.java
index 9f8db11..dabb98d 100644
--- a/dev/core/test/com/google/gwt/dev/js/TokenStreamTest.java
+++ b/dev/core/test/com/google/gwt/dev/js/TokenStreamTest.java
@@ -1,12 +1,12 @@
/*
* Copyright 2009 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
@@ -55,6 +55,7 @@
assertGoodJsni("@org.group.Foo::bar(I)");
assertGoodJsni("@org.group.Foo::bar(IJ)");
assertGoodJsni("@org.group.Foo::bar(Lorg/group/Foo;)");
+ assertGoodJsni("@org.group.Foo::bar(Lorg/group/Foo;Lorg/group/Bar;)");
assertGoodJsni("@org.group.Foo::bar([I)");
// The following is currently tolerated
// assertBadJsni("@org.group.Foo::bar(Lorg/group/Foo)");
@@ -64,6 +65,18 @@
// Method refs with * as the parameter list
assertGoodJsni("@org.group.Foo::bar(*)");
assertBadJsni("@org.group.Foo::bar(*");
+
+ // Refs that span lines
+ assertGoodJsni("@org.group.Foo::bar(\nLorg/group/Foo;)");
+ assertGoodJsni("@org.group.Foo::bar(\nLorg/group/Foo;\n)");
+ assertGoodJsni("@org.group.Foo::bar(\n[I\n)");
+ assertGoodJsni("@org.group.Foo::bar(\nZ\nZ\n)");
+ assertGoodJsni("@org.group.Foo::bar(\nLorg/group/Foo;\nZ)");
+ assertGoodJsni("@org.group.Foo::\nbar()");
+
+
+ assertBadJsni("@org.group.Foo::bar(\nLorg/group/Foo;,\nZ)");
+ assertBadJsni("@org.group.Foo::bar(\nLorg/group/Foo,\nZ)");
// bad references
assertBadJsni("@");
@@ -85,6 +98,7 @@
private void assertGoodJsni(String jsniRef) throws IOException {
Token token = scanToken(jsniRef);
assertEquals(TokenStream.NAME, token.type);
- assertEquals(jsniRef, token.text);
+ // The token.text won't have any whitespace included.
+ assertEquals(jsniRef.replaceAll("\\s", ""), token.text);
}
}
--
To view, visit https://gwt-review.googlesource.com/3100
To unsubscribe, visit https://gwt-review.googlesource.com/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iecacf3b8be1e512a5fdf3132245091b4ebea9c68
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <[email protected]>
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
---
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.