Skip to content

Commit

Permalink
Merge pull request #106 from JakeWharton/jw/default-package
Browse files Browse the repository at this point in the history
Support method references to sibling classes in the default package.
  • Loading branch information
luontola authored Jan 10, 2017
2 parents 6fb044f + f0eea0d commit 1b1c607
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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

0 comments on commit 1b1c607

Please sign in to comment.