mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-28 22:48:44 +00:00
Merge remote-tracking branch 'remotes/upstream/0.8' into fabric-0.8
# Conflicts: # build.gradle # src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java # src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
This commit is contained in:
commit
57eefe4e22
66 files changed
+2081
-806
No files matched your search
@@ -28,7 +28,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.processing.Messager;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
@@ -44,6 +43,7 @@ import org.spongepowered.tools.obfuscation.AnnotatedMixinElementHandlerAccessor.
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinElementHandlerInjector.AnnotatedElementInjectionPoint;
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinElementHandlerInjector.AnnotatedElementInjector;
|
||||
import org.spongepowered.tools.obfuscation.AnnotatedMixinElementHandlerOverwrite.AnnotatedElementOverwrite;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMessagerSuppressible;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinValidator;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinValidator.ValidationPass;
|
||||
@@ -68,7 +68,7 @@ class AnnotatedMixin {
|
||||
/**
|
||||
* Messager
|
||||
*/
|
||||
private final Messager messager;
|
||||
private final IMessagerSuppressible messager;
|
||||
|
||||
/**
|
||||
* Type handle provider
|
||||
@@ -215,21 +215,22 @@ class AnnotatedMixin {
|
||||
|
||||
// Private targets, referenced by name
|
||||
try {
|
||||
for (String privateTarget : this.annotation.<String>getList("targets")) {
|
||||
TypeHandle type = this.typeProvider.getTypeHandle(privateTarget);
|
||||
for (String softTarget : this.annotation.<String>getList("targets")) {
|
||||
TypeHandle type = this.typeProvider.getTypeHandle(softTarget);
|
||||
if (this.targets.contains(type)) {
|
||||
continue;
|
||||
}
|
||||
if (this.virtual) {
|
||||
type = this.typeProvider.getSimulatedHandle(privateTarget, this.mixin.asType());
|
||||
type = this.typeProvider.getSimulatedHandle(softTarget, this.mixin.asType());
|
||||
} else if (type == null) {
|
||||
this.printMessage(Kind.ERROR, "Mixin target " + privateTarget + " could not be found", this);
|
||||
this.printMessage(Kind.ERROR, "Mixin target " + softTarget + " could not be found", this);
|
||||
return null;
|
||||
} else if (type.isPublic()) {
|
||||
this.printMessage(Kind.WARNING, "Mixin target " + privateTarget + " is public and must be specified in value", this);
|
||||
SuppressedBy suppressedBy = (type.getPackage().isUnnamed()) ? SuppressedBy.DEFAULT_PACKAGE : null;
|
||||
this.printMessage(Kind.WARNING, "Mixin target " + softTarget + " is public and must be specified in value", this, suppressedBy);
|
||||
return null;
|
||||
}
|
||||
this.addSoftTarget(type, privateTarget);
|
||||
this.addSoftTarget(type, softTarget);
|
||||
if (primaryTarget == null) {
|
||||
primaryTarget = type;
|
||||
}
|
||||
@@ -251,6 +252,13 @@ class AnnotatedMixin {
|
||||
private void printMessage(Kind kind, CharSequence msg, AnnotatedMixin mixin) {
|
||||
this.messager.printMessage(kind, msg, this.mixin, this.annotation.asMirror());
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a suppressible message to the AP messager
|
||||
*/
|
||||
private void printMessage(Kind kind, CharSequence msg, AnnotatedMixin mixin, SuppressedBy suppressedBy) {
|
||||
this.messager.printMessage(kind, msg, this.mixin, this.annotation.asMirror(), suppressedBy);
|
||||
}
|
||||
|
||||
private void addSoftTarget(TypeHandle type, String reference) {
|
||||
ObfuscationData<String> obfClassData = this.obf.getDataProvider().getObfClass(type);
|
||||
|
||||
@@ -374,7 +374,7 @@ abstract class AnnotatedMixinElementHandler {
|
||||
this.ap.printMessage(Kind.ERROR, ex.getMessage(), method, annotation.asMirror());
|
||||
}
|
||||
} catch (InvalidConstraintException ex) {
|
||||
this.ap.printMessage(Kind.WARNING, ex.getMessage(), method, annotation.asMirror(), "constraints");
|
||||
this.ap.printMessage(Kind.WARNING, ex.getMessage(), method, annotation.asMirror(), SuppressedBy.CONSTRAINTS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,7 +421,7 @@ abstract class AnnotatedMixinElementHandler {
|
||||
this.validateMethodVisibility(method, annotation, type, target, targetMethod);
|
||||
}
|
||||
} else if (!merge) {
|
||||
this.printMessage(Kind.WARNING, "Cannot find target for " + type + " method in " + target, method, annotation, "target");
|
||||
this.printMessage(Kind.WARNING, "Cannot find target for " + type + " method in " + target, method, annotation, SuppressedBy.TARGET);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -436,9 +436,11 @@ abstract class AnnotatedMixinElementHandler {
|
||||
Visibility visMethod = TypeUtils.getVisibility(method);
|
||||
String visibility = "visibility of " + visTarget + " method in " + target;
|
||||
if (visTarget.ordinal() > visMethod.ordinal()) {
|
||||
this.printMessage(Kind.WARNING, visMethod + " " + type + " method cannot reduce " + visibility, method, annotation, "visibility");
|
||||
this.printMessage(Kind.WARNING, visMethod + " " + type + " method cannot reduce " + visibility, method, annotation,
|
||||
SuppressedBy.VISIBILITY);
|
||||
} else if (visTarget == Visibility.PRIVATE && visMethod.ordinal() > visTarget.ordinal()) {
|
||||
this.printMessage(Kind.WARNING, visMethod + " " + type + " method will upgrade " + visibility, method, annotation, "visibility");
|
||||
this.printMessage(Kind.WARNING, visMethod + " " + type + " method will upgrade " + visibility, method, annotation,
|
||||
SuppressedBy.VISIBILITY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,7 +471,8 @@ abstract class AnnotatedMixinElementHandler {
|
||||
}
|
||||
|
||||
if (targetField == null) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find target for " + type + " field in " + target, field, annotation.asMirror(), "target");
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find target for " + type + " field in " + target, field, annotation.asMirror(),
|
||||
SuppressedBy.TARGET);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -493,12 +496,13 @@ abstract class AnnotatedMixinElementHandler {
|
||||
|
||||
MethodHandle targetMethod = target.findMethod(nameRef.getName(), signature);
|
||||
if (targetMethod == null) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find target method for " + type + " in " + target, method, inject.asMirror(), "target");
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find target method for " + type + " in " + target, method, inject.asMirror(),
|
||||
SuppressedBy.TARGET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void printMessage(Kind kind, String msg, Element e, AnnotationHandle annotation, String suppressedBy) {
|
||||
private void printMessage(Kind kind, String msg, Element e, AnnotationHandle annotation, SuppressedBy suppressedBy) {
|
||||
if (annotation == null) {
|
||||
this.ap.printMessage(kind, msg, e, suppressedBy);
|
||||
} else {
|
||||
|
||||
+10
-7
@@ -45,6 +45,7 @@ import org.spongepowered.asm.mixin.injection.struct.InvalidMemberDescriptorExcep
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.ReferenceManager.ReferenceConflictException;
|
||||
import org.spongepowered.tools.obfuscation.ext.SpecialPackages;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor.CompilerEnvironment;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IReferenceManager;
|
||||
@@ -292,9 +293,9 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
String desc = member.toCtorDesc();
|
||||
MappingMethod m = new MappingMethod(target, ".", desc != null ? desc : "()V");
|
||||
ObfuscationData<MappingMethod> remapped = this.obf.getDataProvider().getRemappedMethod(m);
|
||||
if (remapped.isEmpty()) {
|
||||
if (remapped.isEmpty() && !SpecialPackages.isExcludedPackage(member.toCtorType())) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find class mapping for " + subject + " '" + target + "'", elem.getElement(),
|
||||
elem.getAnnotation().asMirror(), "mapping");
|
||||
elem.getAnnotation().asMirror(), SuppressedBy.MAPPING);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -345,19 +346,21 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
if (targetMember.isField()) {
|
||||
ObfuscationData<MappingField> obfFieldData = this.obf.getDataProvider().getObfFieldRecursive(targetMember);
|
||||
if (obfFieldData.isEmpty()) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find field mapping for " + subject + " '" + reference + "'", elem.getElement(),
|
||||
errorsOn, "mapping");
|
||||
if (targetMember.getOwner() == null || !SpecialPackages.isExcludedPackage(targetMember.getOwner())) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find field mapping for " + subject + " '" + reference + "'", elem.getElement(),
|
||||
errorsOn, SuppressedBy.MAPPING);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.obf.getReferenceManager().addFieldMapping(this.classRef, reference, targetMember, obfFieldData);
|
||||
} else {
|
||||
ObfuscationData<MappingMethod> obfMethodData = this.obf.getDataProvider().getObfMethodRecursive(targetMember);
|
||||
if (obfMethodData.isEmpty()) {
|
||||
if (targetMember.getOwner() == null || !targetMember.getOwner().startsWith("java/lang/")) {
|
||||
if (targetMember.getOwner() == null || !SpecialPackages.isExcludedPackage(targetMember.getOwner())) {
|
||||
this.ap.printMessage(Kind.WARNING, "Cannot find method mapping for " + subject + " '" + reference + "'", elem.getElement(),
|
||||
errorsOn, "mapping");
|
||||
return;
|
||||
errorsOn, SuppressedBy.MAPPING);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.obf.getReferenceManager().addMethodMapping(this.classRef, reference, targetMember, obfMethodData);
|
||||
}
|
||||
|
||||
+3
-3
@@ -86,16 +86,16 @@ class AnnotatedMixinElementHandlerOverwrite extends AnnotatedMixinElementHandler
|
||||
|
||||
String javadoc = this.ap.getJavadocProvider().getJavadoc(elem.getElement());
|
||||
if (javadoc == null) {
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing javadoc comment", elem.getElement(), "overwrite");
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing javadoc comment", elem.getElement(), SuppressedBy.OVERWRITE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!javadoc.toLowerCase(Locale.ROOT).contains("@author")) {
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing an @author tag", elem.getElement(), "overwrite");
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing an @author tag", elem.getElement(), SuppressedBy.OVERWRITE);
|
||||
}
|
||||
|
||||
if (!javadoc.toLowerCase(Locale.ROOT).contains("@reason")) {
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing an @reason tag", elem.getElement(), "overwrite");
|
||||
this.ap.printMessage(overwriteErrorKind, "@Overwrite is missing an @reason tag", elem.getElement(), SuppressedBy.OVERWRITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
import org.spongepowered.asm.util.ITokenProvider;
|
||||
import org.spongepowered.asm.util.VersionNumber;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IJavadocProvider;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinValidator;
|
||||
@@ -83,6 +84,8 @@ import com.google.common.collect.ImmutableList.Builder;
|
||||
final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider, ITypeHandleProvider, IJavadocProvider {
|
||||
|
||||
private static final String MAPID_SYSTEM_PROPERTY = "mixin.target.mapid";
|
||||
|
||||
private static final String RECOMMENDED_MIXINGRADLE_VERSION = "0.7";
|
||||
|
||||
/**
|
||||
* Singleton instances for each ProcessingEnvironment
|
||||
@@ -143,6 +146,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
this.processingEnv = processingEnv;
|
||||
|
||||
this.printMessage(Kind.NOTE, "SpongePowered MIXIN Annotation Processor Version=" + MixinBootstrap.VERSION);
|
||||
this.checkPluginVersion(this.getOption(SupportedOptions.PLUGIN_VERSION));
|
||||
|
||||
this.targets = this.initTargetMap();
|
||||
this.obf = new ObfuscationManager(this);
|
||||
@@ -152,10 +156,28 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
new ParentValidator(this),
|
||||
new TargetValidator(this)
|
||||
);
|
||||
|
||||
|
||||
this.initTokenCache(this.getOption(SupportedOptions.TOKENS));
|
||||
}
|
||||
|
||||
/**
|
||||
* If MixinGradle is in use, check the version. This will allow us to notify
|
||||
* the user if the version of MixinGradle is out of date relative to the
|
||||
* Mixin library version
|
||||
*/
|
||||
private void checkPluginVersion(String version) {
|
||||
if (version == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
VersionNumber pluginVersion = VersionNumber.parse(version);
|
||||
VersionNumber recommendedVersion = VersionNumber.parse(AnnotatedMixins.RECOMMENDED_MIXINGRADLE_VERSION);
|
||||
if (pluginVersion.compareTo(recommendedVersion) < 0) {
|
||||
this.printMessage(Kind.WARNING, String.format("MixinGradle version %s is out of date. Update to the recommended version %s",
|
||||
pluginVersion, recommendedVersion));
|
||||
}
|
||||
}
|
||||
|
||||
protected TargetMap initTargetMap() {
|
||||
TargetMap targets = TargetMap.create(System.getProperty(AnnotatedMixins.MAPID_SYSTEM_PROPERTY));
|
||||
System.setProperty(AnnotatedMixins.MAPID_SYSTEM_PROPERTY, targets.getSessionId());
|
||||
@@ -513,11 +535,11 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
return annotation.getBoolean("remap", mixinClass.remap());
|
||||
}
|
||||
|
||||
private static boolean shouldSuppress(Element element, String suppressedBy) {
|
||||
private static boolean shouldSuppress(Element element, SuppressedBy suppressedBy) {
|
||||
if (element == null || suppressedBy == null) {
|
||||
return false;
|
||||
}
|
||||
if (AnnotationHandle.of(element, SuppressWarnings.class).<String>getList().contains(suppressedBy)) {
|
||||
if (AnnotationHandle.of(element, SuppressWarnings.class).<String>getList().contains(suppressedBy.getToken())) {
|
||||
return true;
|
||||
}
|
||||
return AnnotatedMixins.shouldSuppress(element.getEnclosingElement(), suppressedBy);
|
||||
@@ -545,7 +567,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
* Print a message to the AP messager
|
||||
*/
|
||||
@Override
|
||||
public void printMessage(Kind kind, CharSequence msg, Element element, String suppressedBy) {
|
||||
public void printMessage(Kind kind, CharSequence msg, Element element, SuppressedBy suppressedBy) {
|
||||
if (kind != Kind.WARNING || !AnnotatedMixins.shouldSuppress(element, suppressedBy)) {
|
||||
this.processingEnv.getMessager().printMessage(kind, msg, element);
|
||||
}
|
||||
@@ -563,7 +585,7 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
* Print a message to the AP messager
|
||||
*/
|
||||
@Override
|
||||
public void printMessage(Kind kind, CharSequence msg, Element element, AnnotationMirror annotation, String suppressedBy) {
|
||||
public void printMessage(Kind kind, CharSequence msg, Element element, AnnotationMirror annotation, SuppressedBy suppressedBy) {
|
||||
if (kind != Kind.WARNING || !AnnotatedMixins.shouldSuppress(element, suppressedBy)) {
|
||||
this.processingEnv.getMessager().printMessage(kind, msg, element, annotation);
|
||||
}
|
||||
@@ -581,7 +603,8 @@ final class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider
|
||||
* Print a message to the AP messager
|
||||
*/
|
||||
@Override
|
||||
public void printMessage(Kind kind, CharSequence msg, Element element, AnnotationMirror annotation, AnnotationValue value, String suppressedBy) {
|
||||
public void printMessage(Kind kind, CharSequence msg, Element element, AnnotationMirror annotation, AnnotationValue value,
|
||||
SuppressedBy suppressedBy) {
|
||||
if (kind != Kind.WARNING || !AnnotatedMixins.shouldSuppress(element, suppressedBy)) {
|
||||
this.processingEnv.getMessager().printMessage(kind, msg, element, annotation, value);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ public final class SupportedOptions {
|
||||
public static final String DEFAULT_OBFUSCATION_ENV = "defaultObfuscationEnv";
|
||||
public static final String DEPENDENCY_TARGETS_FILE = "dependencyTargetsFile";
|
||||
public static final String MAPPING_TYPES = "mappingTypes";
|
||||
public static final String PLUGIN_VERSION = "pluginVersion";
|
||||
|
||||
private SupportedOptions() {}
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
/**
|
||||
* A centralised list of tokens supported by the AP for use in
|
||||
* {@link SuppressWarnings} annotations. Collected here mainly for
|
||||
* self-documentation purposes.
|
||||
*/
|
||||
public enum SuppressedBy {
|
||||
|
||||
/**
|
||||
* Suppress warnings for constraint violations
|
||||
*/
|
||||
CONSTRAINTS("constraints"),
|
||||
|
||||
/**
|
||||
* Suppress warnings about overwrite visibility upgrading/downgrading target
|
||||
* visibility
|
||||
*/
|
||||
VISIBILITY("visibility"),
|
||||
|
||||
/**
|
||||
* Suppress warnings when an injector target cannot be found
|
||||
*/
|
||||
TARGET("target"),
|
||||
|
||||
/**
|
||||
* Suppress warnings when a class, method or field mapping cannot be located
|
||||
*/
|
||||
MAPPING("mapping"),
|
||||
|
||||
/**
|
||||
* Suppress warnings for when an <tt>@Overwrite</tt> method is missing
|
||||
* javadoc, or author or reason tags
|
||||
*/
|
||||
OVERWRITE("overwrite"),
|
||||
|
||||
/**
|
||||
* Suppress warnings when a mixin target specified by name is located in the
|
||||
* default package
|
||||
*/
|
||||
DEFAULT_PACKAGE("default-package");
|
||||
|
||||
private final String token;
|
||||
|
||||
private SuppressedBy(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string token which is used in the {@link SuppressWarnings}
|
||||
* annotation
|
||||
*/
|
||||
public String getToken() {
|
||||
return this.token;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation.ext;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Centralised registry of packages with special handling by the AP. This is
|
||||
* public and centralised
|
||||
*/
|
||||
public final class SpecialPackages {
|
||||
|
||||
private static final Set<String> suppressWarningsForPackages = new HashSet<String>();
|
||||
|
||||
static {
|
||||
SpecialPackages.addExcludedPackage("java.");
|
||||
SpecialPackages.addExcludedPackage("javax.");
|
||||
SpecialPackages.addExcludedPackage("sun.");
|
||||
SpecialPackages.addExcludedPackage("com.sun.");
|
||||
}
|
||||
|
||||
private SpecialPackages() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a package to exclude from remapping warnings. This only suppresses
|
||||
* warnings if a mapping is not found and does not attempt to short-circuit
|
||||
* the mapping process. Thus if a mapping is present for the element in
|
||||
* question then the behaviour is preserved. Adding a package here simply
|
||||
* suppresses warnings if no mapping is found.
|
||||
*
|
||||
* @param packageName Package name, including trailing period or slash
|
||||
*/
|
||||
public static final void addExcludedPackage(String packageName) {
|
||||
String internalName = packageName.replace('.', '/');
|
||||
if (!internalName.endsWith("/")) {
|
||||
internalName += "/";
|
||||
}
|
||||
SpecialPackages.suppressWarningsForPackages.add(internalName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a package is in the exclusion set.
|
||||
*
|
||||
* @param internalName Internal class or package name
|
||||
* @return true if warnings for the supplied package should be suppressed
|
||||
*/
|
||||
public static boolean isExcludedPackage(String internalName) {
|
||||
for (String prefix : SpecialPackages.suppressWarningsForPackages) {
|
||||
if (internalName.startsWith(prefix)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+5
-3
@@ -30,6 +30,8 @@ import javax.lang.model.element.AnnotationValue;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
import org.spongepowered.tools.obfuscation.SuppressedBy;
|
||||
|
||||
/**
|
||||
* An extended {@link Messager} which supports messages that can be suppressed
|
||||
* using the standard Java {@link SuppressWarnings} annotation.
|
||||
@@ -46,7 +48,7 @@ public interface IMessagerSuppressible extends Messager {
|
||||
* @param suppressedBy the {@link SuppressWarnings} value which will silence
|
||||
* this message
|
||||
*/
|
||||
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, String suppressedBy);
|
||||
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, SuppressedBy suppressedBy);
|
||||
|
||||
/**
|
||||
* Prints a message of the specified kind at the location of the
|
||||
@@ -59,7 +61,7 @@ public interface IMessagerSuppressible extends Messager {
|
||||
* @param suppressedBy the {@link SuppressWarnings} value which will silence
|
||||
* this message
|
||||
*/
|
||||
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, String suppressedBy);
|
||||
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, SuppressedBy suppressedBy);
|
||||
|
||||
/**
|
||||
* Prints a message of the specified kind at the location of the
|
||||
@@ -74,7 +76,7 @@ public interface IMessagerSuppressible extends Messager {
|
||||
* @param suppressedBy the {@link SuppressWarnings} value which will silence
|
||||
* this message
|
||||
*/
|
||||
void printMessage(Diagnostic.Kind kind,CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v, String suppressedBy);
|
||||
void printMessage(Diagnostic.Kind kind,CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v, SuppressedBy suppressedBy);
|
||||
|
||||
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class MappingWriterTSrg extends MappingWriterSrg {
|
||||
|
||||
@Override
|
||||
protected String formatFieldMapping(Pair<MappingField> field) {
|
||||
return String.format("%s %s %s %s", field.from.getOwner(), field.from.getSimpleName(), field.to.getSimpleName());
|
||||
return String.format("%s %s %s", field.from.getOwner(), field.from.getSimpleName(), field.to.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user