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

Add .match file reader #33

Draft
wants to merge 15 commits into
base: dev
Choose a base branch
from
Draft
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
99 changes: 85 additions & 14 deletions src/main/java/net/fabricmc/mappingio/FlatMappingVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,34 @@ default boolean visitContent() throws IOException {
}

boolean visitClass(String srcName, String[] dstNames) throws IOException;
void visitClassMetadata(String srcName, String[] dstNames, String propertyKey, String[] propertyValues) throws IOException;
void visitClassComment(String srcName, String[] dstNames, String comment) throws IOException;

boolean visitField(String srcClsName, String srcName, String srcDesc,
String[] dstClsNames, String[] dstNames, String[] dstDescs) throws IOException;
void visitFieldMetadata(String srcClsName, String srcName, String srcDesc,
String[] dstClsNames, String[] dstNames, String[] dstDescs,
String propertyKey, String[] propertyValues) throws IOException;
void visitFieldComment(String srcClsName, String srcName, String srcDesc,
String[] dstClsNames, String[] dstNames, String[] dstDescs,
String comment) throws IOException;

boolean visitMethod(String srcClsName, String srcName, String srcDesc,
String[] dstClsNames, String[] dstNames, String[] dstDescs) throws IOException;
void visitMethodMetadata(String srcClsName, String srcName, String srcDesc,
String[] dstClsNames, String[] dstNames, String[] dstDescs,
String propertyKey, String[] propertyValues) throws IOException;
void visitMethodComment(String srcClsName, String srcName, String srcDesc,
String[] dstClsNames, String[] dstNames, String[] dstDescs,
String comment) throws IOException;

boolean visitMethodArg(String srcClsName, String srcMethodName, String srcMethodDesc,
int argPosition, int lvIndex, String srcArgName,
String[] dstClsNames, String[] dstMethodNames, String[] dstMethodDescs, String[] dstArgNames) throws IOException;
void visitMethodArgMetadata(String srcClsName, String srcMethodName, String srcMethodDesc,
int argPosition, int lvIndex, String srcArgName,
String[] dstClsNames, String[] dstMethodNames, String[] dstMethodDescs, String[] dstArgNames,
String propertyKey, String[] propertyValues) throws IOException;
void visitMethodArgComment(String srcClsName, String srcMethodName, String srcMethodDesc,
int argPosition, int lvIndex, String srcArgName,
String[] dstClsNames, String[] dstMethodNames, String[] dstMethodDescs, String[] dstArgNames,
Expand All @@ -82,6 +93,10 @@ void visitMethodArgComment(String srcClsName, String srcMethodName, String srcMe
boolean visitMethodVar(String srcClsName, String srcMethodName, String srcMethodDesc,
int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, String srcVarName,
String[] dstClsNames, String[] dstMethodNames, String[] dstMethodDescs, String[] dstVarNames) throws IOException;
void visitMethodVarMetadata(String srcClsName, String srcMethodName, String srcMethodDesc,
int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, String srcVarName,
String[] dstClsNames, String[] dstMethodNames, String[] dstMethodDescs, String[] dstVarNames,
String propertyKey, String[] propertyValues) throws IOException;
void visitMethodVarComment(String srcClsName, String srcMethodName, String srcMethodDesc,
int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, String srcVarName,
String[] dstClsNames, String[] dstMethodNames, String[] dstMethodDescs, String[] dstVarNames,
Expand Down Expand Up @@ -135,37 +150,53 @@ default boolean visitMethodVar(String srcClsName, String srcMethodName, String s

// convenience / potentially higher efficiency visit methods for only one dst name

// Class
default boolean visitClass(String srcName, String dstName) throws IOException {
return visitClass(srcName, toArray(dstName));
}

default void visitClassMetadata(String srcName, String propertyKey, String[] propertyValues) throws IOException {
visitClassMetadata(srcName, (String) null, propertyKey, propertyValues);
}
default void visitClassMetadata(String srcName, String dstName, String propertyKey, String[] propertyValues) throws IOException {
visitClassMetadata(srcName, toArray(dstName), propertyKey, propertyValues);
}
default void visitClassComment(String srcName, String comment) throws IOException {
visitClassComment(srcName, (String) null, comment);
}

default void visitClassComment(String srcName, String dstName, String comment) throws IOException {
visitClassComment(srcName, toArray(dstName), comment);
}

// Field
default boolean visitField(String srcClsName, String srcName, String srcDesc,
String dstName) throws IOException {
return visitField(srcClsName, srcName, srcDesc,
null, dstName, null);
}

default boolean visitField(String srcClsName, String srcName, String srcDesc,
String dstClsName, String dstName, String dstDesc) throws IOException {
return visitField(srcClsName, srcName, srcDesc,
toArray(dstClsName), toArray(dstName), toArray(dstDesc));
}

default void visitFieldMetadata(String srcClsName, String srcName, String srcDesc,
String propertyKey, String[] propertyValues) throws IOException {
visitFieldMetadata(srcClsName, srcName, srcDesc,
(String) null, null, null,
propertyKey, propertyValues);
}
default void visitFieldMetadata(String srcClsName, String srcName, String srcDesc,
String dstClsName, String dstName, String dstDesc,
String propertyKey, String[] propertyValues) throws IOException {
visitFieldMetadata(srcClsName, srcName, srcDesc,
toArray(dstClsName), toArray(dstName), toArray(dstDesc),
propertyKey, propertyValues);
}
default void visitFieldComment(String srcClsName, String srcName, String srcDesc,
String comment) throws IOException {
visitFieldComment(srcClsName, srcName, srcDesc,
(String) null, null, null,
comment);
}

default void visitFieldComment(String srcClsName, String srcName, String srcDesc,
String dstClsName, String dstName, String dstDesc,
String comment) throws IOException {
Expand All @@ -174,25 +205,36 @@ default void visitFieldComment(String srcClsName, String srcName, String srcDesc
comment);
}

// Method
default boolean visitMethod(String srcClsName, String srcName, String srcDesc,
String dstName) throws IOException {
return visitMethod(srcClsName, srcName, srcDesc,
null, dstName, null);
}

default boolean visitMethod(String srcClsName, String srcName, String srcDesc,
String dstClsName, String dstName, String dstDesc) throws IOException {
return visitMethod(srcClsName, srcName, srcDesc,
toArray(dstClsName), toArray(dstName), toArray(dstDesc));
}

default void visitMethodMetadata(String srcClsName, String srcName, String srcDesc,
String propertyKey, String[] propertyValues) throws IOException {
visitMethodMetadata(srcClsName, srcName, srcDesc,
(String) null, null, null,
propertyKey, propertyValues);
}
default void visitMethodMetadata(String srcClsName, String srcName, String srcDesc,
String dstClsName, String dstName, String dstDesc,
String propertyKey, String[] propertyValues) throws IOException {
visitMethodMetadata(srcClsName, srcName, srcDesc,
toArray(dstClsName), toArray(dstName), toArray(dstDesc),
propertyKey, propertyValues);
}
default void visitMethodComment(String srcClsName, String srcName, String srcDesc,
String comment) throws IOException {
visitMethodComment(srcClsName, srcName, srcDesc,
(String) null, null, null,
comment);
}

default void visitMethodComment(String srcClsName, String srcName, String srcDesc,
String dstClsName, String dstName, String dstDesc,
String comment) throws IOException {
Expand All @@ -201,22 +243,37 @@ default void visitMethodComment(String srcClsName, String srcName, String srcDes
comment);
}

// Method Arg
default boolean visitMethodArg(String srcClsName, String srcMethodName, String srcMethodDesc,
int argPosition, int lvIndex, String srcArgName,
String dstArgName) throws IOException {
return visitMethodArg(srcClsName, srcMethodName, srcMethodDesc,
argPosition, lvIndex, srcArgName,
null, null, null, dstArgName);
}

default boolean visitMethodArg(String srcClsName, String srcMethodName, String srcMethodDesc,
int argPosition, int lvIndex, String srcArgName,
String dstClsName, String dstMethodName, String dstMethodDesc, String dstArgName) throws IOException {
return visitMethodArg(srcClsName, srcMethodName, srcMethodDesc,
argPosition, lvIndex, srcArgName,
toArray(dstClsName), toArray(dstMethodName), toArray(dstMethodDesc), toArray(dstArgName));
}

default void visitMethodArgMetadata(String srcClsName, String srcMethodName, String srcMethodDesc,
int argPosition, int lvIndex, String srcArgName,
String propertyKey, String[] propertyValues) throws IOException {
visitMethodArgMetadata(srcClsName, srcMethodName, srcMethodDesc,
argPosition, lvIndex, srcArgName,
(String) null, null, null, null,
propertyKey, propertyValues);
}
default void visitMethodArgMetadata(String srcClsName, String srcMethodName, String srcMethodDesc,
int argPosition, int lvIndex, String srcArgName,
String dstClsName, String dstMethodName, String dstMethodDesc, String dstArgName,
String propertyKey, String[] propertyValues) throws IOException {
visitMethodArgMetadata(srcClsName, srcMethodName, srcMethodDesc, argPosition, lvIndex, srcArgName,
toArray(dstClsName), toArray(dstMethodName), toArray(dstMethodDesc), toArray(dstArgName),
propertyKey, propertyValues);
}
default void visitMethodArgComment(String srcClsName, String srcMethodName, String srcMethodDesc,
int argPosition, int lvIndex, String srcArgName,
String comment) throws IOException {
Expand All @@ -225,7 +282,6 @@ default void visitMethodArgComment(String srcClsName, String srcMethodName, Stri
(String) null, null, null, null,
comment);
}

default void visitMethodArgComment(String srcClsName, String srcMethodName, String srcMethodDesc,
int argPosition, int lvIndex, String srcArgName,
String dstClsName, String dstMethodName, String dstMethodDesc, String dstArgName,
Expand All @@ -235,22 +291,38 @@ default void visitMethodArgComment(String srcClsName, String srcMethodName, Stri
comment);
}

// Method Var
default boolean visitMethodVar(String srcClsName, String srcMethodName, String srcMethodDesc,
int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, String srcVarName,
String dstVarName) throws IOException {
return visitMethodVar(srcClsName, srcMethodName, srcMethodDesc,
lvtRowIndex, lvIndex, startOpIdx, endOpIdx, srcVarName,
null, null, null, dstVarName);
}

default boolean visitMethodVar(String srcClsName, String srcMethodName, String srcMethodDesc,
int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, String srcVarName,
String dstClsName, String dstMethodName, String dstMethodDesc, String dstVarName) throws IOException {
return visitMethodVar(srcClsName, srcMethodName, srcMethodDesc,
lvtRowIndex, lvIndex, startOpIdx, endOpIdx, srcVarName,
toArray(dstClsName), toArray(dstMethodName), toArray(dstMethodDesc), toArray(dstVarName));
}

default void visitMethodVarMetadata(String srcClsName, String srcMethodName, String srcMethodDesc,
int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, String srcVarName,
String propertyKey, String[] propertyValues) throws IOException {
visitMethodVarMetadata(srcClsName, srcMethodName, srcMethodDesc,
lvtRowIndex, lvIndex, startOpIdx, endOpIdx, srcVarName,
(String) null, null, null, null,
propertyKey, propertyValues);
}
default void visitMethodVarMetadata(String srcClsName, String srcMethodName, String srcMethodDesc,
int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, String srcVarName,
String dstClsName, String dstMethodName, String dstMethodDesc, String dstVarName,
String propertyKey, String[] propertyValues) throws IOException {
visitMethodVarMetadata(srcClsName, srcMethodName, srcMethodDesc,
lvtRowIndex, lvIndex, startOpIdx, endOpIdx, srcVarName,
toArray(dstClsName), toArray(dstMethodName), toArray(dstMethodDesc), toArray(dstVarName),
propertyKey, propertyValues);
}
default void visitMethodVarComment(String srcClsName, String srcMethodName, String srcMethodDesc,
int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, String srcVarName,
String comment) throws IOException {
Expand All @@ -259,7 +331,6 @@ default void visitMethodVarComment(String srcClsName, String srcMethodName, Stri
(String) null, null, null, null,
comment);
}

default void visitMethodVarComment(String srcClsName, String srcMethodName, String srcMethodDesc,
int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, String srcVarName,
String dstClsName, String dstMethodName, String dstMethodDesc, String dstVarName,
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/net/fabricmc/mappingio/MappingReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.enigma.EnigmaDirReader;
import net.fabricmc.mappingio.format.enigma.EnigmaFileReader;
import net.fabricmc.mappingio.format.match.MatchFileReader;
import net.fabricmc.mappingio.format.proguard.ProGuardFileReader;
import net.fabricmc.mappingio.format.srg.SrgFileReader;
import net.fabricmc.mappingio.format.tiny.Tiny1FileReader;
Expand Down Expand Up @@ -75,6 +76,8 @@ public static MappingFormat detectFormat(Reader reader) throws IOException {
case "MD:":
case "FD:":
return MappingFormat.SRG_FILE;
case "Mat":
return MappingFormat.MATCH_FILE;
}

String headerStr = String.valueOf(buffer, 0, pos);
Expand Down Expand Up @@ -200,6 +203,9 @@ public static void read(Reader reader, MappingFormat format, MappingVisitor visi
case PROGUARD_FILE:
ProGuardFileReader.read(reader, visitor);
break;
case MATCH_FILE:
MatchFileReader.read(reader, visitor);
break;
default:
throw new IllegalStateException();
}
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/net/fabricmc/mappingio/MappingVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
* <ul><li>overall: header -> content -> End -> overall
* <li>header: Header -> Namespaces [-> Metadata]*
* <li>content: Content [-> class|Metadata]*
* <li>class: Class [-> DstName]* -> ElementContent [-> field|method|Comment]*
* <li>field: Field [-> DstName|DstDesc]* -> ElementContent [-> Comment]
* <li>method: Method [-> DstName|DstDesc]* -> ElementContent [-> arg|var|Comment]*
* <li>arg: Arg [-> DstName]* -> ElementContent [-> Comment]
* <li>var: Var [-> DstName]* -> ElementContent [-> Comment]
* <li>class: Class [-> DstName]* -> ElementContent [-> ElementMetadata|field|method|Comment]*
* <li>field: Field [-> DstName|DstDesc]* -> ElementContent [-> ElementMetadata|Comment]*
* <li>method: Method [-> DstName|DstDesc]* -> ElementContent [-> ElementMetadata|arg|var|Comment]*
* <li>arg: Arg [-> DstName]* -> ElementContent [-> ElementMetadata|Comment]*
* <li>var: Var [-> DstName]* -> ElementContent [-> ElementMetadata|Comment]*
* </ul>
*
* <p>The elements with a skip-return (Header/Content/Class/Field/Method/Arg/Var/ElementContent) abort processing the
Expand Down Expand Up @@ -118,6 +118,11 @@ default boolean visitElementContent(MappedElementKind targetKind) throws IOExcep
return true;
}

/**
* Metadata for the specified element (last content-visited or any parent).
*/
default void visitElementMetadata(MappedElementKind targetKind, String key, int namespace, String value) throws IOException { }

/**
* Comment for the specified element (last content-visited or any parent).
*
Expand Down
Loading
Loading