Skip to content

Commit deda4ac

Browse files
committed
Initial commit
0 parents  commit deda4ac

18 files changed

Lines changed: 539 additions & 0 deletions

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/discord.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/uiDesigner.xml

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# RefWrapper
2+
3+
4+
<!-- ABOUT THE PROJECT -->
5+
## About The Project
6+
The project is dedicated to the topic of reflection in java. A convenient wrapper is provided for interacting with objects via proxy using reflections.
7+
8+
**When should it be applied?** When an object is loaded using another ClassLoader, the reflections mechanism is used to access the classes. The project solves the difficulties of using reflection in this case.
9+
10+
<!-- GETTING STARTED -->
11+
## Getting Started
12+
13+
1. Go to the release page and download the latest version of the project.
14+
2. Connect it as a jar library using the capabilities of your system to automate the build of applications
15+
16+
<!-- USAGE EXAMPLES -->
17+
## Usage
18+
19+
Let's say we have a sample.jar with the following contents:
20+
21+
```java
22+
//JavaObject
23+
class JavaObject {
24+
private Listener listener;
25+
public Listener getListener() {
26+
return listener;
27+
}
28+
private JavaObject() {
29+
listener = new Listener("sample");
30+
}
31+
public static JavaObject getInstance() {
32+
return new JavaObject();
33+
}
34+
}
35+
//Listener
36+
class Listener {
37+
public String name;
38+
public Listener(String name) {
39+
this.name = name;
40+
}
41+
public Entity createEntity(String name) {
42+
return new Entity(this.name + name);
43+
}
44+
}
45+
//Entity
46+
class Entity {
47+
public UUID uuid;
48+
public String name;
49+
public Entity(String name) {
50+
this.name = name;
51+
uuid = UUID.randomUUID();
52+
}
53+
}
54+
55+
56+
```
57+
58+
To connect sample.jar we use:
59+
```java
60+
public class Main {
61+
public static void main(String[] args) throws MalformedURLException, ClassNotFoundException {
62+
URLClassLoader urlClassLoader = new URLClassLoader("SampleLoader", new URL[]{
63+
new File("sample.jar").toURI().toURL()
64+
}, Main.class.getClassLoader());
65+
}
66+
}
67+
```
68+
69+
To access the classes we use:
70+
71+
```java
72+
@Wrapped
73+
public interface JavaObjectWrapper {
74+
75+
@Method("getInstance")
76+
JavaObjectWrapper getInstance();
77+
78+
@Method("getListener")
79+
ListenerWrapper getListener();
80+
}
81+
82+
@Wrapped
83+
public interface ListenerWrapper {
84+
85+
@Method("createEntity")
86+
EntityWrapper createEntity(String name);
87+
}
88+
89+
@Wrapped
90+
public interface EntityWrapper {
91+
92+
@Field("name")
93+
String getName();
94+
95+
@Field(value = "name", isSetter = true)
96+
void setName(String name);
97+
}
98+
99+
public class Main {
100+
public static void main(String[] args) throws MalformedURLException, ClassNotFoundException {
101+
URLClassLoader urlClassLoader = new URLClassLoader("sample", new URL[]{
102+
new File("sample.jar").toURI().toURL()
103+
}, Main.class.getClassLoader());
104+
105+
// Create static wrapper
106+
JavaPluginWrapper wrapper = WrapperFactory.createWrapper(JavaObjectWrapper.class, urlClassLoader, "space.ardyc.test.JavaObject");
107+
108+
// Get non-static instance
109+
JavaPluginWrapper object = wrapper.getInstance();
110+
111+
// Get listener object and call createEntity method
112+
EntityWrapper entity = object.getListener().createEntity("sample");
113+
114+
System.out.println(entity.getName()); // enabledsamepl
115+
116+
//Set field param
117+
entity.setName("none");
118+
System.out.println(entity.getName()); //none
119+
}
120+
}
121+
```

pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>space.ardyc</groupId>
8+
<artifactId>refwrapper</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>11</maven.compiler.source>
13+
<maven.compiler.target>11</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
</project>

0 commit comments

Comments
 (0)