aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/lll/proxies/PackageProxy.java
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-03-21 16:32:19 +0100
committer zaaarf <zaaarf@proton.me>2023-03-21 16:32:19 +0100
commit884cefead9e4fede7243650afc4f22f08f8e5090 (patch)
tree9a63d0638238f67ef6d3ed3379a0c63c76e03e75 /src/main/java/ftbsc/lll/proxies/PackageProxy.java
parent40686b8c929279bd486529fceae1d8dd7fa2735f (diff)
feat: expanded ClassProxies, now all fields and methods include classproxies to represent their parents (as well as parameters and return type for methods)
Diffstat (limited to 'src/main/java/ftbsc/lll/proxies/PackageProxy.java')
-rw-r--r--src/main/java/ftbsc/lll/proxies/PackageProxy.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/lll/proxies/PackageProxy.java b/src/main/java/ftbsc/lll/proxies/PackageProxy.java
new file mode 100644
index 0000000..fbfe6c0
--- /dev/null
+++ b/src/main/java/ftbsc/lll/proxies/PackageProxy.java
@@ -0,0 +1,51 @@
+package ftbsc.lll.proxies;
+
+/**
+ * A container for information about a package.
+ * @since 0.4.0
+ */
+public class PackageProxy extends QualifiableProxy {
+
+ /**
+ * The {@link PackageProxy} representing the root package.
+ */
+ public static final PackageProxy ROOT = new PackageProxy(null, "");
+
+ /**
+ * The protected constructor, called only from {@link PackageProxy#from(String)}.
+ * @param parent the {@link PackageProxy} representing the parent
+ * @param fqn the fully-qualified name of this package
+ */
+ protected PackageProxy(PackageProxy parent, String fqn) {
+ super(null, 0, parent, fqn);
+ }
+
+ /**
+ * Builds a {@link PackageProxy} from its fully-qualified name.
+ * @param fqn the fully-qualified name of the package
+ * @return the built {@link PackageProxy}
+ */
+ protected static PackageProxy from(String fqn) {
+ if(fqn == null || fqn.equals("")) return ROOT;
+ return new PackageProxy(from(extractParentFromFQN(fqn)), fqn);
+ }
+
+ /**
+ * Builds a {@link PackageProxy} from a reflective {@link Package} object.
+ * @param p the {@link Package} object
+ * @return the built {@link PackageProxy}
+ */
+ protected static PackageProxy from(Package p) {
+ return from(extractParentFromFQN(p.getName()));
+ }
+
+ /**
+ * Indicates whether the given object is a proxy for the same element as this.
+ * @param obj the object to perform
+ * @return true if it's equal
+ */
+ @Override
+ public boolean equals(Object obj) {
+ return obj instanceof PackageProxy && super.equals(obj);
+ }
+}