Skip to content

Commit

Permalink
https://github.com/manifold-systems/manifold/issues/349
Browse files Browse the repository at this point in the history
- support calls to non-public extension methods
  • Loading branch information
rsmckinney committed Apr 1, 2022
1 parent 88d1648 commit 2e78f53
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2022 - Manifold Systems LLC
*
* 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 License for the specific language governing permissions and
* limitations under the License.
*/

package manifold.ext;

import junit.framework.TestCase;

public class NonPublicExtensionMethodTest extends TestCase
{
public void testProtectedMethodDirectly()
{
Foo foo = new Foo();
assertEquals( "protected method", foo.callDirectly() );
}

public void testProtectedMethodIndirectly()
{
Foo foo = new Foo();
assertEquals( "protected method", foo.callIndirectly() );
}

static class Foo
{
public String callDirectly()
{
return myProtectedMethod();
}

public String callIndirectly()
{
return new Foo().myProtectedMethod();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2022 - Manifold Systems LLC
*
* 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 License for the specific language governing permissions and
* limitations under the License.
*/

package manifold.ext.extensions.java.lang.Object;

import manifold.ext.rt.api.Extension;
import manifold.ext.rt.api.This;

@Extension
public class MyObjectExt
{
protected static String myProtectedMethod( @This Object thiz )
{
return "protected method";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2520,6 +2520,13 @@ private JCTree.JCMethodInvocation replaceExtCall( JCTree.JCMethodInvocation tree
newArgs.add( 0, thisArg );
tree.args = List.from( newArgs );
}

boolean isPublic = (method.flags_field & Flags.AccessFlags) == PUBLIC;
if( !isPublic )
{
tree = replaceWithReflection( tree );
}

return tree;
}
else if( methodSelect instanceof JCTree.JCIdent )
Expand Down Expand Up @@ -2547,6 +2554,13 @@ else if( methodSelect instanceof JCTree.JCIdent )
newMethodSelect.type = method.type;
newMethodSelect.pos = tree.pos;
assignTypes( newMethodSelect.selected, method.owner );

boolean isPublic = (method.flags_field & Flags.AccessFlags) == PUBLIC;
if( !isPublic )
{
extCall = replaceWithReflection( extCall );
}

return extCall;
}
return tree;
Expand Down

0 comments on commit 2e78f53

Please sign in to comment.