Skip to content
Merged
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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ asm = "9.8"
gson = "2.10.1"

stitch = "0.6.2"
tiny-remapper = "0.11.2"
tiny-remapper = "0.12.0"
access-widener = "2.1.0"
mapping-io = "0.7.1"
lorenz-tiny = "4.0.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import com.google.gson.reflect.TypeToken;
import org.gradle.api.Project;
import org.jetbrains.annotations.Nullable;
import org.objectweb.asm.commons.AnnotationRemapper;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.TypeAnnotationNode;

Expand Down Expand Up @@ -142,13 +141,13 @@ public AnnotationsData remap(TinyRemapper remapper, String newNamespace) {

static AnnotationNode remap(AnnotationNode node, TinyRemapper remapper) {
AnnotationNode remapped = new AnnotationNode(remapper.getEnvironment().getRemapper().mapDesc(node.desc));
node.accept(new AnnotationRemapper(node.desc, remapped, remapper.getEnvironment().getRemapper()));
node.accept(remapper.createAnnotationRemapperVisitor(remapped, node.desc));
return remapped;
}

static TypeAnnotationNode remap(TypeAnnotationNode node, TinyRemapper remapper) {
TypeAnnotationNode remapped = new TypeAnnotationNode(node.typeRef, node.typePath, remapper.getEnvironment().getRemapper().mapDesc(node.desc));
node.accept(new AnnotationRemapper(node.desc, remapped, remapper.getEnvironment().getRemapper()));
node.accept(remapper.createAnnotationRemapperVisitor(remapped, node.desc));
return remapped;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,59 +24,49 @@

package net.fabricmc.loom.test.unit.layeredmappings

import java.nio.file.Path

import groovy.transform.CompileStatic
import org.intellij.lang.annotations.Language
import spock.lang.Specification

import net.fabricmc.loom.configuration.providers.mappings.extras.annotations.AnnotationsData
import net.fabricmc.loom.test.unit.service.mocks.MockTinyRemapper
import net.fabricmc.tinyremapper.api.TrClass
import net.fabricmc.tinyremapper.api.TrField
import net.fabricmc.tinyremapper.api.TrMethod

import static org.mockito.Mockito.*
import net.fabricmc.tinyremapper.IMappingProvider
import net.fabricmc.tinyremapper.TinyRemapper

class AnnotationsDataRemapTest extends Specification {
def "remap annotations data"() {
given:
def reader = new BufferedReader(new StringReader(ANNOTATIONS))
def annotationsData = AnnotationsData.read(reader)

def mockTr = new MockTinyRemapper()

when(mockTr.remapper.map("pkg/Foo")).thenReturn("mapped/pkg/FooMapped")
when(mockTr.remapper.map("pkg/Bar")).thenReturn("mapped/pkg/BarMapped")

when(mockTr.remapper.map("pkg/Annotation1")).thenReturn("mapped/pkg/Annotation1Mapped")
when(mockTr.remapper.map("pkg/Annotation2")).thenReturn("mapped/pkg/Annotation2Mapped")
when(mockTr.remapper.map("pkg/Annotation3")).thenReturn("mapped/pkg/Annotation3Mapped")
when(mockTr.remapper.map("pkg/Annotation4")).thenReturn("mapped/pkg/Annotation4Mapped")
when(mockTr.remapper.map("pkg/Annotation5")).thenReturn("mapped/pkg/Annotation5Mapped")
when(mockTr.remapper.map("pkg/Annotation6")).thenReturn("mapped/pkg/Annotation6Mapped")
when(mockTr.remapper.map("pkg/Annotation7")).thenReturn("mapped/pkg/Annotation7Mapped")
when(mockTr.remapper.map("pkg/Annotation8")).thenReturn("mapped/pkg/Annotation8Mapped")

when(mockTr.remapper.map("pkg/MyEnum")).thenReturn("mapped/pkg/MyEnumMapped")
def remapper = TinyRemapper.newRemapper()
.withMappings { mappings ->
mappings.acceptClass('net/fabricmc/loom/test/unit/layeredmappings/AnnotationsDataRemapTest$Foo', 'mapped/pkg/FooMapped')
mappings.acceptClass('pkg/Bar', 'mapped/pkg/BarMapped')

when(mockTr.remapper.map("baz")).thenReturn("mapped/baz")
mappings.acceptClass('pkg/Annotation1', 'mapped/pkg/Annotation1Mapped')
mappings.acceptClass('pkg/Annotation2', 'mapped/pkg/Annotation2Mapped')
mappings.acceptClass('pkg/Annotation3', 'mapped/pkg/Annotation3Mapped')
mappings.acceptClass('pkg/Annotation4', 'mapped/pkg/Annotation4Mapped')
mappings.acceptClass('pkg/Annotation5', 'mapped/pkg/Annotation5Mapped')
mappings.acceptClass('pkg/Annotation6', 'mapped/pkg/Annotation6Mapped')
mappings.acceptClass('pkg/Annotation7', 'mapped/pkg/Annotation7Mapped')
mappings.acceptClass('pkg/Annotation8', 'mapped/pkg/Annotation8Mapped')

when(mockTr.remapper.mapFieldName("pkg/Foo", "bar", "Lbaz;")).thenReturn("barRenamed")
when(mockTr.remapper.mapMethodName("pkg/Foo", "bar", "()V")).thenReturn("barMethodRenamed")
mappings.acceptClass('pkg/MyEnum', 'mapped/pkg/MyEnumMapped')

def mockClass = mock(TrClass.class)
when(mockTr.trEnvironment.getClass("pkg/Foo")).thenReturn(mockClass)
mappings.acceptClass('baz', 'mapped/baz')

def mockField = mock(TrField.class)
when(mockField.name).thenReturn("bar")
when(mockField.desc).thenReturn("Lbaz;")
when(mockClass.fields).thenReturn([mockField])
mappings.acceptField(new IMappingProvider.Member('net/fabricmc/loom/test/unit/layeredmappings/AnnotationsDataRemapTest$Foo', 'bar', 'Lnet/fabricmc/loom/test/unit/layeredmappings/AnnotationsDataRemapTest$Foo;'), 'barRenamed')
mappings.acceptMethod(new IMappingProvider.Member('net/fabricmc/loom/test/unit/layeredmappings/AnnotationsDataRemapTest$Foo', 'bar', '()V'), 'barMethodRenamed')
}
.build()

def mockMethod = mock(TrMethod.class)
when(mockMethod.name).thenReturn("bar")
when(mockMethod.desc).thenReturn("()V")
when(mockClass.methods).thenReturn([mockMethod])
remapper.readClassPath(Path.of(Foo.class.protectionDomain.codeSource.location.toURI()))

when:
def remapped = annotationsData.remap(mockTr.tinyRemapper, "mapped")
def remapped = annotationsData.remap(remapper, "mapped")

then:
def json = AnnotationsData.GSON.newBuilder()
Expand All @@ -88,12 +78,20 @@ class AnnotationsDataRemapTest extends Specification {
json == REMAPPED_ANNOTATIONS.trim()
}

@CompileStatic
class Foo {
Foo bar

void bar() {
}
}

@Language("JSON")
private static final String ANNOTATIONS = """
{
"version": 1,
"classes": {
"pkg/Foo": {
"net/fabricmc/loom/test/unit/layeredmappings/AnnotationsDataRemapTest${'$'}Foo": {
"remove": [
"pkg/Annotation1",
"pkg/Annotation2",
Expand Down Expand Up @@ -147,7 +145,7 @@ class AnnotationsDataRemapTest extends Specification {
}
],
"fields": {
"bar:Lbaz;": {
"bar:Lnet/fabricmc/loom/test/unit/layeredmappings/AnnotationsDataRemapTest${'$'}Foo;": {
"remove": [
"pkg/Annotation8"
]
Expand Down Expand Up @@ -231,7 +229,7 @@ class AnnotationsDataRemapTest extends Specification {
}
],
"fields": {
"barRenamed:Lmapped/baz;": {
"barRenamed:Lmapped/pkg/FooMapped;": {
"remove": [
"mapped/pkg/Annotation8Mapped"
]
Expand Down