Compare commits

..

4 Commits

Author SHA1 Message Date
a338a4b9af - Moved ReflectUtils to reflections package 2025-09-29 15:29:51 +02:00
8e8f4c4149 Merge pull request 'Added reflections utility' (#1) from Maple/reflections:master into master
Reviewed-on: #1
2025-09-29 15:26:51 +02:00
109e94991e Merge branch 'master' into master 2025-09-29 15:24:54 +02:00
Tinglyyy
7f885db883 Added reflections utility 2025-09-29 15:11:21 +02:00
5 changed files with 105 additions and 3 deletions

2
.idea/misc.xml generated
View File

@@ -8,7 +8,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="23" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="23" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

10
pom.xml
View File

@@ -6,7 +6,7 @@
<groupId>dev.unlegitdqrk</groupId>
<artifactId>unlegitlibrary</artifactId>
<version>1.6.4</version>
<version>1.6.5</version>
<url>https://unlegitdqrk.dev/</url>
<description>Just a big library</description>
@@ -35,6 +35,14 @@
</developer>
</developers>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>
</dependencies>
<issueManagement>
<system>Issue Tracker</system>
<url>https://repo.unlegitdqrk.dev/UnlegitDqrk/unlegitlibrary/issues</url>

View File

@@ -0,0 +1,18 @@
// Author: maple
// date: 9/29/25
package dev.unlegitdqrk.unlegitlibrary.reflections;
import java.lang.reflect.ParameterizedType;
/**
* Implements utility for handling the Generic type
*/
public abstract class GenericReflectClass<T> {
protected final Class<T> persistentClass;
public GenericReflectClass() {
this.persistentClass = (Class<T>)
((ParameterizedType)getClass().getGenericSuperclass())
.getActualTypeArguments()[0];
}
}

View File

@@ -1,4 +1,12 @@
package dev.unlegitdqrk.unlegitlibrary.file;
/*
* Copyright (C) 2025 UnlegitDqrk - All Rights Reserved
*
* You are unauthorized to remove this copyright.
* You have to give Credits to the Author in your project and link this GitHub site: https://github.com/UnlegitDqrk
* See LICENSE-File if exists
*/
package dev.unlegitdqrk.unlegitlibrary.reflections;
import dev.unlegitdqrk.unlegitlibrary.utils.DefaultMethodsOverrider;

View File

@@ -0,0 +1,68 @@
// Author: maple
// date: 9/29/25
package dev.unlegitdqrk.unlegitlibrary.reflections.annotation.processing;
import dev.unlegitdqrk.unlegitlibrary.reflections.GenericReflectClass;
import org.reflections.Reflections;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Set;
public abstract class AnnotationProcessor<A extends Annotation> extends GenericReflectClass<A> {
protected Set<Class<?>> projectClasses;
protected Set<Class<?>> annotatedTypes;
protected Set<Method> annotatedMethods;
protected Set<Field> annotatedFields;
protected Set<Constructor> annotatedConstructors;
private final Reflections reflections;
public AnnotationProcessor(String packageName) {
super();
this.reflections = new Reflections(packageName);
// load local sets
this.reload();
}
/**
* reload local sets
*/
public void reload() {
this.projectClasses = this.reflections.getSubTypesOf(Object.class);
this.annotatedTypes = this.reflections.getTypesAnnotatedWith(this.persistentClass);
this.annotatedMethods = this.reflections.getMethodsAnnotatedWith(this.persistentClass);
this.annotatedFields = this.reflections.getFieldsAnnotatedWith(this.persistentClass);
this.annotatedConstructors = this.reflections.getConstructorsAnnotatedWith(this.persistentClass);
}
public void process() {
for(Class<?> type : this.annotatedTypes)
processType(type);
for(Method method : this.annotatedMethods)
processMethod(method);
for(Field field : this.annotatedFields)
processField(field);
for(Constructor constructor : this.annotatedConstructors)
processConstructor(constructor);
}
protected abstract void processType(Class<?> type);
protected abstract void processMethod(Method method);
protected abstract void processField(Field field);
protected abstract void processConstructor(Constructor constructor);
}