mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-20 01:49:34 +00:00
Interface mixins dev
This commit is contained in:
1 parent
8c450d4282
commit
46e20b1f4e
19 files changed
+585
-150
No files matched your search
@@ -37,6 +37,7 @@ import java.util.Set;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.AnnotationValue;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
@@ -230,6 +231,11 @@ class AnnotatedMixin {
|
||||
*/
|
||||
private final TypeHandle handle;
|
||||
|
||||
/**
|
||||
* True if this is an interface mixin
|
||||
*/
|
||||
private final boolean isInterface;
|
||||
|
||||
/**
|
||||
* Specified targets
|
||||
*/
|
||||
@@ -266,11 +272,11 @@ class AnnotatedMixin {
|
||||
private final Map<ObfuscationType, Set<String>> methodMappings = new HashMap<ObfuscationType, Set<String>>();
|
||||
|
||||
public AnnotatedMixin(AnnotatedMixins mixins, TypeElement type) {
|
||||
|
||||
this.annotation = MirrorUtils.getAnnotation(type, Mixin.class);
|
||||
this.mixins = mixins;
|
||||
this.mixin = type;
|
||||
this.handle = new TypeHandle(type);
|
||||
this.isInterface = type.getKind() == ElementKind.INTERFACE;
|
||||
this.classRef = type.getQualifiedName().toString().replace('.', '/');
|
||||
|
||||
TypeHandle primaryTarget = this.initTargets();
|
||||
@@ -376,6 +382,13 @@ class AnnotatedMixin {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this is an interface mixin
|
||||
*/
|
||||
public boolean isInterface() {
|
||||
return this.isInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mixin's targets
|
||||
*/
|
||||
@@ -544,6 +557,10 @@ class AnnotatedMixin {
|
||||
* @return pending error message or null if no error condition
|
||||
*/
|
||||
public Message registerInjector(ExecutableElement method, AnnotationMirror inject, boolean remap) {
|
||||
if (this.isInterface) {
|
||||
this.mixins.printMessage(Kind.ERROR, "Injector in interface is unsupported", method);
|
||||
}
|
||||
|
||||
String originalReference = MirrorUtils.<String>getAnnotationValue(inject, "method");
|
||||
MemberInfo targetMember = MemberInfo.parse(originalReference);
|
||||
if (targetMember.name == null) {
|
||||
@@ -591,6 +608,10 @@ class AnnotatedMixin {
|
||||
* and process the references
|
||||
*/
|
||||
public int registerInjectionPoint(Element element, AnnotationMirror inject, AnnotationMirror at) {
|
||||
if (this.isInterface) {
|
||||
this.mixins.printMessage(Kind.ERROR, "Injector in interface is unsupported", element);
|
||||
}
|
||||
|
||||
if (!AnnotatedMixins.getRemapValue(at)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -61,10 +61,10 @@ public abstract class MixinProcessor extends AbstractProcessor {
|
||||
this.mixins.onPassStarted();
|
||||
|
||||
for (Element elem : roundEnv.getElementsAnnotatedWith(Mixin.class)) {
|
||||
if (elem.getKind() == ElementKind.CLASS) {
|
||||
if (elem.getKind() == ElementKind.CLASS || elem.getKind() == ElementKind.INTERFACE) {
|
||||
this.mixins.registerMixin((TypeElement)elem);
|
||||
} else {
|
||||
this.mixins.printMessage(Kind.ERROR, "Found an @Mixin annotation on an element which is not a class", elem);
|
||||
this.mixins.printMessage(Kind.ERROR, "Found an @Mixin annotation on an element which is not a class or interface", elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.util.Collection;
|
||||
import javax.annotation.processing.Messager;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
@@ -67,6 +68,25 @@ public class TargetValidator extends MixinValidator {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mixin.getKind() == ElementKind.INTERFACE) {
|
||||
this.validateInterfaceMixin(mixin, targets);
|
||||
} else {
|
||||
this.validateClassMixin(mixin, targets);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void validateInterfaceMixin(TypeElement mixin, Collection<TypeHandle> targets) {
|
||||
for (TypeHandle target : targets) {
|
||||
TypeElement targetType = target.getElement();
|
||||
if (targetType != null && !(targetType.getKind() == ElementKind.INTERFACE)) {
|
||||
this.error("Targetted type '" + target + " of " + mixin + " is not an interface", mixin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateClassMixin(TypeElement mixin, Collection<TypeHandle> targets) {
|
||||
TypeMirror superClass = mixin.getSuperclass();
|
||||
|
||||
for (TypeHandle target : targets) {
|
||||
@@ -75,8 +95,6 @@ public class TargetValidator extends MixinValidator {
|
||||
this.error("Superclass " + superClass + " of " + mixin + " was not found in the hierarchy of target class " + targetType, mixin);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean validateSuperClass(TypeMirror targetType, TypeMirror superClass) {
|
||||
|
||||
Reference in new issue
Block a user