Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove dot format requirement for MappingResolver #483

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/net/fabricmc/loader/api/MappingResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public interface MappingResolver {
* Map a class name to the mapping currently used at runtime.
*
* @param namespace the namespace of the provided class name
* @param className the provided binary class name
* @param className the provided internal/binary class name
* @return the mapped class name, or {@code className} if no such mapping is present
*/
String mapClassName(String namespace, String className);
Expand All @@ -58,7 +58,7 @@ public interface MappingResolver {
* Unmap a class name to the mapping currently used at runtime.
*
* @param targetNamespace The target namespace for unmapping.
* @param className the provided binary class name of the mapping form currently used at runtime
* @param className the provided internal/binary class name of the mapping form currently used at runtime
* @return the mapped class name, or {@code className} if no such mapping is present
*/
String unmapClassName(String targetNamespace, String className);
Expand All @@ -67,7 +67,7 @@ public interface MappingResolver {
* Map a field name to the mapping currently used at runtime.
*
* @param namespace the namespace of the provided field name and descriptor
* @param owner the binary name of the owner class of the field
* @param owner the internal/binary name of the owner class of the field
* @param name the name of the field
* @param descriptor the descriptor of the field
* @return the mapped field name, or {@code name} if no such mapping is present
Expand All @@ -78,7 +78,7 @@ public interface MappingResolver {
* Map a method name to the mapping currently used at runtime.
*
* @param namespace the namespace of the provided method name and descriptor
* @param owner the binary name of the owner class of the method
* @param owner the internal/binary name of the owner class of the method
* @param name the name of the method
* @param descriptor the descriptor of the method
* @return the mapped method name, or {@code name} if no such mapping is present
Expand Down
31 changes: 7 additions & 24 deletions src/main/java/net/fabricmc/loader/impl/MappingResolverImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@ protected final NamespaceData getNamespaceData(String namespace) {

NamespaceData data = new NamespaceData();
TinyTree mappings = mappingsSupplier.get();
Map<String, String> classNameMap = new HashMap<>();

for (ClassDef classEntry : mappings.getClasses()) {
String fromClass = mapClassName(classNameMap, classEntry.getName(fromNamespace));
String toClass = mapClassName(classNameMap, classEntry.getName(targetNamespace));
String fromClass = classEntry.getName(fromNamespace);
String toClass = classEntry.getName(targetNamespace);

data.classNames.put(fromClass, toClass);
data.classNamesInverse.put(toClass, fromClass);

String mappedClassName = mapClassName(classNameMap, fromClass);
String mappedClassName = fromClass;

recordMember(fromNamespace, classEntry.getFields(), data.fieldNames, mappedClassName);
recordMember(fromNamespace, classEntry.getMethods(), data.methodNames, mappedClassName);
Expand All @@ -76,14 +75,6 @@ protected final NamespaceData getNamespaceData(String namespace) {
});
}

private static String replaceSlashesWithDots(String cname) {
return cname.replace('/', '.');
}

private String mapClassName(Map<String, String> classNameMap, String s) {
return classNameMap.computeIfAbsent(s, MappingResolverImpl::replaceSlashesWithDots);
}

private <T extends Descriptored> void recordMember(String fromNamespace, Collection<T> descriptoredList, Map<EntryTriple, String> putInto, String fromClass) {
for (T descriptored : descriptoredList) {
EntryTriple fromEntry = new EntryTriple(fromClass, descriptored.getName(fromNamespace), descriptored.getDescriptor(fromNamespace));
Expand All @@ -103,36 +94,28 @@ public String getCurrentRuntimeNamespace() {

@Override
public String mapClassName(String namespace, String className) {
if (className.indexOf('/') >= 0) {
throw new IllegalArgumentException("Class names must be provided in dot format: " + className);
}
className = className.replace('.', '/'); // maintain backwards compatibility with dotty format requirement

return getNamespaceData(namespace).classNames.getOrDefault(className, className);
}

@Override
public String unmapClassName(String namespace, String className) {
if (className.indexOf('/') >= 0) {
throw new IllegalArgumentException("Class names must be provided in dot format: " + className);
}
className = className.replace('.', '/'); // maintain backwards compatibility with dotty format requirement

return getNamespaceData(namespace).classNamesInverse.getOrDefault(className, className);
}

@Override
public String mapFieldName(String namespace, String owner, String name, String descriptor) {
if (owner.indexOf('/') >= 0) {
throw new IllegalArgumentException("Class names must be provided in dot format: " + owner);
}
owner = owner.replace('.', '/'); // maintain backwards compatibility with dotty format requirement

return getNamespaceData(namespace).fieldNames.getOrDefault(new EntryTriple(owner, name, descriptor), name);
}

@Override
public String mapMethodName(String namespace, String owner, String name, String descriptor) {
if (owner.indexOf('/') >= 0) {
throw new IllegalArgumentException("Class names must be provided in dot format: " + owner);
}
owner = owner.replace('.', '/'); // maintain backwards compatibility with dotty format requirement

return getNamespaceData(namespace).methodNames.getOrDefault(new EntryTriple(owner, name, descriptor), name);
}
Expand Down