aboutsummaryrefslogtreecommitdiff
path: root/javaplugin
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-12-07 13:26:03 +0100
committerLinnea Gräf <nea@nea.moe>2024-12-07 13:26:03 +0100
commitbf7795df22ca7892fae1238403feebb57c005562 (patch)
tree3a49db5bade38498f976321b6e9008203f2d4d3b /javaplugin
parentcdb5e60f52eea9030af9ca2d4a49913664023965 (diff)
downloadFirmament-bf7795df22ca7892fae1238403feebb57c005562.tar.gz
Firmament-bf7795df22ca7892fae1238403feebb57c005562.tar.bz2
Firmament-bf7795df22ca7892fae1238403feebb57c005562.zip
WIP: Port to compilation on 1.21.4
Diffstat (limited to 'javaplugin')
-rw-r--r--javaplugin/src/main/java/moe/nea/firmament/javaplugin/InitReplacer.java8
-rw-r--r--javaplugin/src/main/java/moe/nea/firmament/javaplugin/IntermediaryMethodReplacer.java7
-rw-r--r--javaplugin/src/main/java/moe/nea/firmament/javaplugin/MappingTree.java69
-rw-r--r--javaplugin/src/main/java/moe/nea/firmament/javaplugin/Utils.java2
4 files changed, 51 insertions, 35 deletions
diff --git a/javaplugin/src/main/java/moe/nea/firmament/javaplugin/InitReplacer.java b/javaplugin/src/main/java/moe/nea/firmament/javaplugin/InitReplacer.java
index a0d28ab..7ba3b44 100644
--- a/javaplugin/src/main/java/moe/nea/firmament/javaplugin/InitReplacer.java
+++ b/javaplugin/src/main/java/moe/nea/firmament/javaplugin/InitReplacer.java
@@ -59,6 +59,14 @@ public class InitReplacer extends TreeScanner<Void, Void> {
var target = plugin.utils.getAnnotationValue(jcAnnotation, "value");
var targetClass = plugin.utils.resolveClassLiteralExpression(target).tsym.flatName().toString();
var intermediaryClass = mappingTree.resolveClassToIntermediary(targetClass);
+ if (intermediaryClass == null){
+ plugin.utils.reportError(
+ compilationUnitTree.getSourceFile(),
+ jcNode.init,
+ "Unknown class name " + targetClass
+ );
+ return super.visitVariable(node, unused);
+ }
var remapper = treeMaker.Select(treeMaker.This(classTree.type), names.fromString("remapper"));
var remappingCall = treeMaker.Apply(
List.nil(),
diff --git a/javaplugin/src/main/java/moe/nea/firmament/javaplugin/IntermediaryMethodReplacer.java b/javaplugin/src/main/java/moe/nea/firmament/javaplugin/IntermediaryMethodReplacer.java
index d3040b7..cb87b20 100644
--- a/javaplugin/src/main/java/moe/nea/firmament/javaplugin/IntermediaryMethodReplacer.java
+++ b/javaplugin/src/main/java/moe/nea/firmament/javaplugin/IntermediaryMethodReplacer.java
@@ -57,7 +57,12 @@ public class IntermediaryMethodReplacer extends TreeScanner<Void, Void> {
}
var head = node.typeargs.head;
var resolved = plugin.utils.resolveClassName(head, compilationUnit);
- var mappedName = mappings.resolveClassToIntermediary(resolved.tsym.flatName().toString());
+ var sourceName = resolved.tsym.flatName().toString();
+ var mappedName = mappings.resolveClassToIntermediary(sourceName);
+ if (mappedName == null) {
+ plugin.utils.reportError(sourceFile, node, "Unknown class name " + sourceName);
+ return;
+ }
fieldAccess.name = plugin.names.fromString("id");
node.typeargs = List.nil();
node.args = List.of(plugin.treeMaker.Literal(mappedName));
diff --git a/javaplugin/src/main/java/moe/nea/firmament/javaplugin/MappingTree.java b/javaplugin/src/main/java/moe/nea/firmament/javaplugin/MappingTree.java
index 7a270b7..eef5f9a 100644
--- a/javaplugin/src/main/java/moe/nea/firmament/javaplugin/MappingTree.java
+++ b/javaplugin/src/main/java/moe/nea/firmament/javaplugin/MappingTree.java
@@ -9,40 +9,43 @@ import java.util.stream.Collectors;
public class MappingTree {
- private final Map<String, TinyClass> classLookup;
- private final int targetIndex;
- private final int sourceIndex;
+ private final Map<String, TinyClass> classLookup;
+ private final int targetIndex;
+ private final int sourceIndex;
- public MappingTree(TinyFile tinyV2File, String sourceNamespace, String targetNamespace) {
- sourceIndex = tinyV2File.getHeader().getNamespaces().indexOf(sourceNamespace);
- if (sourceIndex < 0)
- throw new RuntimeException("Could not find source namespace " + sourceNamespace + " in mappings file.");
- this.classLookup = tinyV2File
- .getClassEntries()
- .stream()
- .collect(Collectors.toMap(it -> it.getClassNames().get(sourceIndex), it -> it));
- targetIndex = tinyV2File.getHeader().getNamespaces().indexOf(targetNamespace);
- if (targetIndex < 0)
- throw new RuntimeException("Could not find target namespace " + targetNamespace + " in mappings file.");
- }
+ public MappingTree(TinyFile tinyV2File, String sourceNamespace, String targetNamespace) {
+ sourceIndex = tinyV2File.getHeader().getNamespaces().indexOf(sourceNamespace);
+ if (sourceIndex < 0)
+ throw new RuntimeException("Could not find source namespace " + sourceNamespace + " in mappings file.");
+ this.classLookup = tinyV2File
+ .getClassEntries()
+ .stream()
+ .collect(Collectors.toMap(it -> it.getClassNames().get(sourceIndex), it -> it));
+ targetIndex = tinyV2File.getHeader().getNamespaces().indexOf(targetNamespace);
+ if (targetIndex < 0)
+ throw new RuntimeException("Could not find target namespace " + targetNamespace + " in mappings file.");
+ }
- public String resolveMethodToIntermediary(String className, String methodName) {
- var classData = classLookup.get(className.replace(".", "/"));
- TinyMethod candidate = null;
- for (TinyMethod method : classData.getMethods()) {
- if (method.getMethodNames().get(sourceIndex).equals(methodName)) {
- if (candidate != null) {
- throw new RuntimeException("Found two candidates for method " + className + "." + methodName);
- }
- candidate = method;
- }
- }
- return candidate.getMethodNames().get(targetIndex);
- }
+ public String resolveMethodToIntermediary(String className, String methodName) {
+ var classData = classLookup.get(className.replace(".", "/"));
+ TinyMethod candidate = null;
+ for (TinyMethod method : classData.getMethods()) {
+ if (method.getMethodNames().get(sourceIndex).equals(methodName)) {
+ if (candidate != null) {
+ throw new RuntimeException("Found two candidates for method " + className + "." + methodName);
+ }
+ candidate = method;
+ }
+ }
+ return candidate.getMethodNames().get(targetIndex);
+ }
- public String resolveClassToIntermediary(String className) {
- return classLookup.get(className.replace(".", "/"))
- .getClassNames().get(targetIndex)
- .replace("/", ".");
- }
+ public String resolveClassToIntermediary(String className) {
+ var cls = classLookup.get(className.replace(".", "/"));
+ if (cls == null) {
+ return null;
+ }
+ return cls.getClassNames().get(targetIndex)
+ .replace("/", ".");
+ }
}
diff --git a/javaplugin/src/main/java/moe/nea/firmament/javaplugin/Utils.java b/javaplugin/src/main/java/moe/nea/firmament/javaplugin/Utils.java
index d9008bd..4c8806d 100644
--- a/javaplugin/src/main/java/moe/nea/firmament/javaplugin/Utils.java
+++ b/javaplugin/src/main/java/moe/nea/firmament/javaplugin/Utils.java
@@ -111,7 +111,7 @@ public class Utils {
var error = diagnostics.error(
JCDiagnostic.DiagnosticFlag.API,
log.currentSource(),
- ((JCTree) node).pos(),
+ node == null ? null : ((JCTree) node).pos(),
"firmament.generic",
message
);