Skip to content

Commit

Permalink
Ban switching of JsProperty/JsMethod on overrides
Browse files Browse the repository at this point in the history
Change-Id: I8a32ab3f901d6dab047b329fc60455b9a27a0e24
  • Loading branch information
gkdn authored and Gerrit Code Review committed Nov 14, 2015
1 parent 538ff9e commit 5d563e5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Expand Up @@ -745,7 +745,7 @@ private JsMember createOrUpdateJsMember(JsMember jsMember, JMember member) {
} }
return new JsMember(member, member, jsMember == null ? null : jsMember.getter); return new JsMember(member, member, jsMember == null ? null : jsMember.getter);
default: default:
if (jsMember != null) { if (jsMember != null && !jsMember.isPropertyAccessor()) {
if (overrides(member, jsMember.member)) { if (overrides(member, jsMember.member)) {
jsMember.member = member; jsMember.member = member;
return jsMember; return jsMember;
Expand Down
Expand Up @@ -240,12 +240,12 @@ public void testCollidingJsPropertiesTwoSettersFails() throws Exception {
+ "cannot both use the same JavaScript name 'x'."); + "cannot both use the same JavaScript name 'x'.");
} }


public void testCollidingJsTypeAndJsPropertyGetterFails() throws Exception { public void testCollidingJsMethodAndJsPropertyGetterFails() throws Exception {
addSnippetImport("jsinterop.annotations.JsType"); addSnippetImport("jsinterop.annotations.JsMethod");
addSnippetImport("jsinterop.annotations.JsProperty"); addSnippetImport("jsinterop.annotations.JsProperty");
addSnippetClassDecl( addSnippetClassDecl(
"@JsType",
"public static interface IBuggy {", "public static interface IBuggy {",
" @JsMethod",
" boolean x(boolean foo);", " boolean x(boolean foo);",
" @JsProperty", " @JsProperty",
" int getX();", " int getX();",
Expand All @@ -262,12 +262,12 @@ public void testCollidingJsTypeAndJsPropertyGetterFails() throws Exception {
+ "cannot both use the same JavaScript name 'x'."); + "cannot both use the same JavaScript name 'x'.");
} }


public void testCollidingJsTypeAndJsPropertySetterFails() throws Exception { public void testCollidingJsMethodAndJsPropertySetterFails() throws Exception {
addSnippetImport("jsinterop.annotations.JsType"); addSnippetImport("jsinterop.annotations.JsMethod");
addSnippetImport("jsinterop.annotations.JsProperty"); addSnippetImport("jsinterop.annotations.JsProperty");
addSnippetClassDecl( addSnippetClassDecl(
"@JsType",
"public static interface IBuggy {", "public static interface IBuggy {",
" @JsMethod",
" boolean x(boolean foo);", " boolean x(boolean foo);",
" @JsProperty", " @JsProperty",
" void setX(int a);", " void setX(int a);",
Expand Down Expand Up @@ -859,6 +859,28 @@ public void testJsPropertyOverrideSucceeds()
assertBuggySucceeds(); assertBuggySucceeds();
} }


public void testMixingJsMethodJsPropertyFails()
throws Exception {
addSnippetImport("jsinterop.annotations.JsMethod");
addSnippetImport("jsinterop.annotations.JsProperty");
addSnippetClassDecl(
"public static class Super {",
" @JsMethod public int getY() { return 5; }",
" @JsProperty public void setZ(int z) {}",
"}",

"public static class Buggy extends Super {",
" @JsProperty(name = \"getY\") public int getY() { return 6; }",
" @JsMethod(name = \"z\") public void setZ(int z) {}",
"}");

assertBuggyFails(
"Line 10: 'int EntryPoint.Buggy.getY()' and 'int EntryPoint.Super.getY()' cannot "
+ "both use the same JavaScript name 'getY'.",
"Line 11: 'void EntryPoint.Buggy.setZ(int)' and 'void EntryPoint.Super.setZ(int)' cannot "
+ "both use the same JavaScript name 'z'.");
}

public void testMultiplePrivateConstructorsExportSucceeds() throws Exception { public void testMultiplePrivateConstructorsExportSucceeds() throws Exception {
addSnippetImport("jsinterop.annotations.JsType"); addSnippetImport("jsinterop.annotations.JsType");
addSnippetClassDecl( addSnippetClassDecl(
Expand Down

0 comments on commit 5d563e5

Please sign in to comment.