mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-19 16:29:45 +00:00
Suppress AP warnings for known-unmappable packages such as java. & sun.
This commit is contained in:
1 parent
6efc4a563f
commit
dbe3a7e94d
2 files changed
+87
-5
No files matched your search
+8
-5
@@ -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,7 +293,7 @@ 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(), 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, SuppressedBy.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, SuppressedBy.MAPPING);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.obf.getReferenceManager().addMethodMapping(this.classRef, reference, targetMember, obfMethodData);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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("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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user