Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support method references to sibling classes in the default package. #106

Merged
merged 1 commit into from
Jan 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions end-to-end-tests/src/test/java/DefaultPackageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright © 2013-2016 Esko Luontola and other Retrolambda contributors
// This software is released under the Apache License 2.0.
// The license text is at http://www.apache.org/licenses/LICENSE-2.0

import org.junit.Test;

public final class DefaultPackageTest {
@Test
public void method_reference_to_sibling_class() {
SiblingClass sibling = new SiblingClass();
Runnable lambda = sibling::method;
lambda.run();
}
}

class SiblingClass {
void method() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ private boolean isOwnedMethodVisible(Handle implMethod) {
}

private boolean isNonOwnedMethodVisible(Handle implMethod) {
String classPackage = className.substring(0, className.lastIndexOf('/'));
String implPackage = implMethod.getOwner().substring(0, implMethod.getOwner().lastIndexOf('/'));
int classNameLastSlash = className.lastIndexOf('/');
String classPackage = classNameLastSlash == -1 ? "" : className.substring(0, classNameLastSlash);

int implMethodLastSlash = implMethod.getOwner().lastIndexOf('/');
String implPackage = implMethodLastSlash == -1 ? "" : implMethod.getOwner().substring(0, implMethodLastSlash);

if (classPackage.equals(implPackage)) {
return true; // All method visibilities in the same package will be visible.
}
Expand Down