Skip to content

Commit

Permalink
Add per-element-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
NebelNidas committed Sep 20, 2023
1 parent b77f15f commit ebd43f0
Show file tree
Hide file tree
Showing 20 changed files with 728 additions and 117 deletions.
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
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

0 comments on commit ebd43f0

Please sign in to comment.