Skip to content

Commit

Permalink
Add a test with mutliple inheritance through interfaces.
Browse files Browse the repository at this point in the history
This test ensures that RTA uses topological order to choose which type the method is inherited from when an interface extends two interfaces defining the same method.

PiperOrigin-RevId: 212726860
  • Loading branch information
jDramaix authored and Copybara-Service committed Sep 12, 2018
1 parent a34b07d commit 138f5c8
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 0 deletions.
@@ -0,0 +1,11 @@
# Apache2
licenses(["notice"])

load("//tools/javatests/com/google/j2cl/tools/rta:rta_test.bzl", "rta_test")

rta_test(
name = "multipleinheritance",
targets = [":multipleinheritance_library"],
unused_members_golden_file = "unused_members.txt",
unused_types_golden_file = "unused_types.txt",
)
@@ -0,0 +1,32 @@
/*
* Copyright 2018 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
*
* https://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.j2cl.tools.rta.multipleinheritance;

import jsinterop.annotations.JsMethod;

class FooBarImpl implements IFooBar {
public void fooBar() {}

public void foo() {}

public void bar() {}

@JsMethod
public static void main() {
IBar iBar = new FooBarImpl();
iBar.fooBar();
}
}
@@ -0,0 +1,23 @@
/*
* Copyright 2018 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
*
* https://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.j2cl.tools.rta.multipleinheritance;

/** Redefines its parent method */
interface IBar extends IFoo {
void fooBar();

void bar();
}
@@ -0,0 +1,22 @@
/*
* Copyright 2018 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
*
* https://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.j2cl.tools.rta.multipleinheritance;

interface IFoo {
void fooBar();

void foo();
}
@@ -0,0 +1,25 @@
/*
* Copyright 2018 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
*
* https://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.j2cl.tools.rta.multipleinheritance;

/**
* This interface inherits 2 times the same method fooBar(). RTA uses the topological depth to
* choose which method IFooBar inherits. In this case IBar:fooBar(). If it's not the case (RTA finds
* that IFooBar inherits from IFoo:fooBar()), the algorithm will find that IFoo:fooBar() is
* overridden in IBar and IBar:fooBar() is overridden in IFoo through IFooBar and that introduces a
* circle.
*/
interface IFooBar extends IFoo, IBar {}
@@ -0,0 +1,13 @@
com.google.j2cl.tools.rta.multipleinheritance.FooBarImpl:m_foo__
com.google.j2cl.tools.rta.multipleinheritance.FooBarImpl:m_bar__

com.google.j2cl.tools.rta.multipleinheritance.IBar:m_fooBar__
com.google.j2cl.tools.rta.multipleinheritance.IBar:m_bar__
com.google.j2cl.tools.rta.multipleinheritance.IBar:$clinit

com.google.j2cl.tools.rta.multipleinheritance.IFoo:m_fooBar__
com.google.j2cl.tools.rta.multipleinheritance.IFoo:m_foo__
com.google.j2cl.tools.rta.multipleinheritance.IFoo:$clinit

com.google.j2cl.tools.rta.multipleinheritance.IFooBar:$clinit

@@ -0,0 +1 @@
# deliberately empty

0 comments on commit 138f5c8

Please sign in to comment.