org.spongepowered.asm.mixin.Mixin Java Examples
The following examples show how to use
org.spongepowered.asm.mixin.Mixin.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MixinProcessor.java From Mixin with MIT License | 6 votes |
private String getInvalidClassError(String name, ClassNode targetClassNode, MixinConfig ownedByConfig) { if (ownedByConfig.getClasses().contains(name)) { return String.format("Illegal classload request for %s. Mixin is defined in %s and cannot be referenced directly", name, ownedByConfig); } // AnnotationNode shadow = Annotations.getInvisible(targetClassNode, Shadow.class); // if (shadow != null) { // return String.format("Illegal classload request for UNRESOLVED @Shadow %s. " // + "The proxy was referenced outside a mixin or the mixin processor encountered an internal error.", name); // } AnnotationNode mixin = Annotations.getInvisible(targetClassNode, Mixin.class); if (mixin != null) { Variant variant = MixinInfo.getVariant(targetClassNode); if (variant == Variant.ACCESSOR) { return String.format("Illegal classload request for accessor mixin %s. The mixin is missing from %s which owns " + "package %s* and the mixin has not been applied.", name, ownedByConfig, ownedByConfig.getMixinPackage()); } } return String.format("%s is in a defined mixin package %s* owned by %s and cannot be referenced directly", name, ownedByConfig.getMixinPackage(), ownedByConfig); }
Example #2
Source File: AnnotatedMixin.java From Mixin with MIT License | 6 votes |
public AnnotatedMixin(IMixinAnnotationProcessor ap, TypeElement type) { this.typeProvider = ap.getTypeProvider(); this.obf = ap.getObfuscationManager(); this.mappings = this.obf.createMappingConsumer(); this.messager = ap; this.mixin = type; this.handle = new TypeHandle(type); this.methods = new ArrayList<ExecutableElement>(this.handle.<ExecutableElement>getEnclosedElements(ElementKind.METHOD)); this.virtual = this.handle.getAnnotation(Pseudo.class).exists(); this.annotation = this.handle.getAnnotation(Mixin.class); this.classRef = TypeUtils.getInternalName(type); this.primaryTarget = this.initTargets(); this.remap = this.annotation.getBoolean("remap", true) && this.targets.size() > 0; this.overwrites = new AnnotatedMixinElementHandlerOverwrite(ap, this); this.shadows = new AnnotatedMixinElementHandlerShadow(ap, this); this.injectors = new AnnotatedMixinElementHandlerInjector(ap, this); this.accessors = new AnnotatedMixinElementHandlerAccessor(ap, this); this.softImplements = new AnnotatedMixinElementHandlerSoftImplements(ap, this); }
Example #3
Source File: MixinInfo.java From Mixin with MIT License | 5 votes |
/** * Read the declared target class names from the {@link Mixin} annotation * * @param classNode mixin classnode * @param ignorePlugin true to suppress plugin filtering targets * @return target class list read from classNode */ protected List<DeclaredTarget> readDeclaredTargets(MixinClassNode classNode, boolean ignorePlugin) { if (classNode == null) { return Collections.<DeclaredTarget>emptyList(); } AnnotationNode mixin = Annotations.getInvisible(classNode, Mixin.class); if (mixin == null) { throw new InvalidMixinException(this, String.format("The mixin '%s' is missing an @Mixin annotation", this.className)); } IClassTracker tracker = this.service.getClassTracker(); List<DeclaredTarget> declaredTargets = new ArrayList<DeclaredTarget>(); for (Object target : this.readTargets(mixin)) { DeclaredTarget declaredTarget = DeclaredTarget.of(target, this); if (declaredTarget == null) { continue; } if (tracker != null && tracker.isClassLoaded(declaredTarget.name) && !this.isReloading()) { String message = String.format("Critical problem: %s target %s was loaded too early.", this, declaredTarget.name); if (this.parent.isRequired()) { throw new MixinTargetAlreadyLoadedException(this, message, declaredTarget.name); } this.logger.error(message); } if (this.shouldApplyMixin(ignorePlugin, declaredTarget.name)) { declaredTargets.add(declaredTarget); } } return declaredTargets; }
Example #4
Source File: MixinInfo.java From Mixin with MIT License | 5 votes |
/** * Read the priority from the {@link Mixin} annotation * * @param classNode mixin classnode * @return priority read from classNode */ protected int readPriority(ClassNode classNode) { if (classNode == null) { return this.parent.getDefaultMixinPriority(); } AnnotationNode mixin = Annotations.getInvisible(classNode, Mixin.class); if (mixin == null) { throw new InvalidMixinException(this, String.format("The mixin '%s' is missing an @Mixin annotation", this.className)); } Integer priority = Annotations.getValue(mixin, "priority"); return priority == null ? this.parent.getDefaultMixinPriority() : priority.intValue(); }
Example #5
Source File: MixinObfuscationProcessor.java From Mixin with MIT License | 5 votes |
/** * Searches and catalogues all annotated mixin classes * * @param roundEnv round environment */ protected void processMixins(RoundEnvironment roundEnv) { this.mixins.onPassStarted(); for (Element elem : roundEnv.getElementsAnnotatedWith(Mixin.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 or interface", elem); } } }