I'm not quite sure how to go about reflecting a class that only has package-level access. I know how to reflect any class that has public access, but I cannot figure out how to reflect the following example:
public class Main {
public static void main(String[] args) {
test t = new test();
Constructor<one.oneimpl> con = one.oneimpl.class.getDeclaredConstructor(test.class);
oneimpl o = con.newInstance(t);
o.doIt();
}
}
======================
package one;
// implementation class for mimicking android api
class oneimpl extends one {
Test mTest;
private oneimpl(test t){mTest = t;}
public void doIt(){System.out.println("Do It!");}
public void dontDoit(){System.out.println("Don't Do It!");}
}
======================
package one;
// abstract class for mimicking android api
abstract class one {
public void doIt();
public void dontDoIt();
}
======================
package one;
// empty class for mimicking android api
public class test {}
As you can see, the class one
only has package-level access. This makes reflecting the class difficult for me. I continue to get compiler errors that states:
Main.java:4: error: oneimpl is not public in one; cannot be accessed from outside package
oneimpl o = con.newInstance(t);
I've reviewed a few posts, to solve this on my own, but even after reading most of the "similar questions", reading the AccessibilityObject
api, and reading generic reflection procedures it's still unclear to me how to achieve this.
Ultimately what I am trying to do is to reflect particular portions of the API to build objects so that soot/spark can build a proper call graph. I'm not actually working inside the android API.