Implement basic annotation system for injection
This commit is contained in:
parent
77aa2f6b2a
commit
7daab23efe
28
src/dev/w1zzrd/asm/AsmAnnotation.java
Normal file
28
src/dev/w1zzrd/asm/AsmAnnotation.java
Normal file
@ -0,0 +1,28 @@
|
||||
package dev.w1zzrd.asm;
|
||||
|
||||
import com.sun.istack.internal.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class AsmAnnotation {
|
||||
private final String annotationType;
|
||||
private final Map<String, Object> entries;
|
||||
|
||||
public AsmAnnotation(String annotationType, Map<String, Object> entries) {
|
||||
this.annotationType = annotationType;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public String getAnnotationType() {
|
||||
return annotationType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T> T getEntry(String name, Class<T> type) {
|
||||
return hasEntry(name) ? (T)entries.get(name) : null;
|
||||
}
|
||||
|
||||
public boolean hasEntry(String name) {
|
||||
return entries.containsKey(name);
|
||||
}
|
||||
}
|
10
src/dev/w1zzrd/asm/Inject.java
Normal file
10
src/dev/w1zzrd/asm/Inject.java
Normal file
@ -0,0 +1,10 @@
|
||||
package dev.w1zzrd.asm;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.CONSTRUCTOR, ElementType.METHOD})
|
||||
public @interface Inject { }
|
13
src/dev/w1zzrd/asm/InjectClass.java
Normal file
13
src/dev/w1zzrd/asm/InjectClass.java
Normal file
@ -0,0 +1,13 @@
|
||||
package dev.w1zzrd.asm;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
public @interface InjectClass {
|
||||
Class<?> value();
|
||||
boolean injectInterfaces() default true;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user