Skip to content

Commit

Permalink
Add @Nullable annotation where applicable (#66)
Browse files Browse the repository at this point in the history
* Annotate all nullable parameters with `@Nullable`

Also fix some inconsistent names

* Annotate all nullable method return types with `@Nullable`

* Annotate all nullable public fields with `@Nullable`
  • Loading branch information
NebelNidas authored Nov 2, 2023
1 parent a301899 commit 387c2f4
Show file tree
Hide file tree
Showing 26 changed files with 441 additions and 279 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ repositories {

dependencies {
implementation "org.ow2.asm:asm:${project.asm_version}"
compileOnly "org.jetbrains:annotations:${project.jetbrains_annotations_version}"
implementation "net.fabricmc:tiny-remapper:${tiny_remapper_version}"
compileOnly "org.jetbrains:annotations:${project.jetbrains_annotations_version}"

testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_jupiter_version}"
testCompileOnly "org.jetbrains:annotations:${project.jetbrains_annotations_version}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit_jupiter_version}"
}

Expand Down
184 changes: 98 additions & 86 deletions src/main/java/net/fabricmc/mappingio/FlatMappingVisitor.java

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/main/java/net/fabricmc/mappingio/MappingReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.Arrays;
import java.util.List;

import org.jetbrains.annotations.Nullable;

import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.enigma.EnigmaDirReader;
import net.fabricmc.mappingio.format.enigma.EnigmaFileReader;
Expand All @@ -39,6 +41,7 @@ public final class MappingReader {
private MappingReader() {
}

@Nullable
public static MappingFormat detectFormat(Path file) throws IOException {
if (Files.isDirectory(file)) {
return MappingFormat.ENIGMA_DIR;
Expand All @@ -49,6 +52,7 @@ public static MappingFormat detectFormat(Path file) throws IOException {
}
}

@Nullable
public static MappingFormat detectFormat(Reader reader) throws IOException {
char[] buffer = new char[DETECT_HEADER_LEN];
int pos = 0;
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/net/fabricmc/mappingio/MappingVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.List;
import java.util.Set;

import org.jetbrains.annotations.Nullable;

/**
* Visitor with order implied context and consecutive dst name visits.
*
Expand Down Expand Up @@ -69,7 +71,7 @@ default boolean visitHeader() throws IOException {

void visitNamespaces(String srcNamespace, List<String> dstNamespaces) throws IOException;

default void visitMetadata(String key, String value) throws IOException { }
default void visitMetadata(String key, @Nullable String value) throws IOException { }

/**
* Determine whether the mapping content (classes and anything below, metadata if not part of the header) should be visited.
Expand All @@ -81,10 +83,10 @@ default boolean visitContent() throws IOException {
}

boolean visitClass(String srcName) throws IOException;
boolean visitField(String srcName, String srcDesc) throws IOException;
boolean visitMethod(String srcName, String srcDesc) throws IOException;
boolean visitMethodArg(int argPosition, int lvIndex, String srcName) throws IOException;
boolean visitMethodVar(int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, String srcName) throws IOException;
boolean visitField(String srcName, @Nullable String srcDesc) throws IOException;
boolean visitMethod(String srcName, @Nullable String srcDesc) throws IOException;
boolean visitMethodArg(int argPosition, int lvIndex, @Nullable String srcName) throws IOException;
boolean visitMethodVar(int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, @Nullable String srcName) throws IOException;

/**
* Finish the visitation pass.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.List;
import java.util.Set;

import org.jetbrains.annotations.Nullable;

import net.fabricmc.mappingio.FlatMappingVisitor;
import net.fabricmc.mappingio.MappedElementKind;
import net.fabricmc.mappingio.MappingFlag;
Expand Down Expand Up @@ -65,7 +67,7 @@ public void visitNamespaces(String srcNamespace, List<String> dstNamespaces) thr
}

@Override
public void visitMetadata(String key, String value) throws IOException {
public void visitMetadata(String key, @Nullable String value) throws IOException {
next.visitMetadata(key, value);
}

Expand All @@ -85,7 +87,7 @@ public boolean visitClass(String srcName) {
}

@Override
public boolean visitField(String srcName, String srcDesc) {
public boolean visitField(String srcName, @Nullable String srcDesc) {
this.srcMemberName = srcName;
this.srcMemberDesc = srcDesc;

Expand All @@ -97,7 +99,7 @@ public boolean visitField(String srcName, String srcDesc) {
}

@Override
public boolean visitMethod(String srcName, String srcDesc) {
public boolean visitMethod(String srcName, @Nullable String srcDesc) {
this.srcMemberName = srcName;
this.srcMemberDesc = srcDesc;

Expand All @@ -109,7 +111,7 @@ public boolean visitMethod(String srcName, String srcDesc) {
}

@Override
public boolean visitMethodArg(int argPosition, int lvIndex, String srcName) {
public boolean visitMethodArg(int argPosition, int lvIndex, @Nullable String srcName) {
this.srcMemberSubName = srcName;
this.argIdx = argPosition;
this.lvIndex = lvIndex;
Expand All @@ -120,7 +122,7 @@ public boolean visitMethodArg(int argPosition, int lvIndex, String srcName) {
}

@Override
public boolean visitMethodVar(int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, String srcName) {
public boolean visitMethodVar(int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, @Nullable String srcName) {
this.srcMemberSubName = srcName;
this.argIdx = lvtRowIndex;
this.lvIndex = lvIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.Objects;
import java.util.Set;

import org.jetbrains.annotations.Nullable;

import net.fabricmc.mappingio.MappedElementKind;
import net.fabricmc.mappingio.MappingFlag;
import net.fabricmc.mappingio.MappingVisitor;
Expand Down Expand Up @@ -53,7 +55,7 @@ public void visitNamespaces(String srcNamespace, List<String> dstNamespaces) thr
}

@Override
public void visitMetadata(String key, String value) throws IOException {
public void visitMetadata(String key, @Nullable String value) throws IOException {
next.visitMetadata(key, value);
}

Expand All @@ -68,22 +70,22 @@ public boolean visitClass(String srcName) throws IOException {
}

@Override
public boolean visitField(String srcName, String srcDesc) throws IOException {
public boolean visitField(String srcName, @Nullable String srcDesc) throws IOException {
return next.visitField(srcName, srcDesc);
}

@Override
public boolean visitMethod(String srcName, String srcDesc) throws IOException {
public boolean visitMethod(String srcName, @Nullable String srcDesc) throws IOException {
return next.visitMethod(srcName, srcDesc);
}

@Override
public boolean visitMethodArg(int argPosition, int lvIndex, String srcName) throws IOException {
public boolean visitMethodArg(int argPosition, int lvIndex, @Nullable String srcName) throws IOException {
return next.visitMethodArg(argPosition, lvIndex, srcName);
}

@Override
public boolean visitMethodVar(int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, String srcName) throws IOException {
public boolean visitMethodVar(int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, @Nullable String srcName) throws IOException {
return next.visitMethodVar(lvtRowIndex, lvIndex, startOpIdx, endOpIdx, srcName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.List;
import java.util.Map;

import org.jetbrains.annotations.Nullable;

import net.fabricmc.mappingio.MappedElementKind;
import net.fabricmc.mappingio.MappingVisitor;

Expand Down Expand Up @@ -87,7 +89,7 @@ public void visitNamespaces(String srcNamespace, List<String> dstNamespaces) thr
}

@Override
public void visitMetadata(String key, String value) throws IOException {
public void visitMetadata(String key, @Nullable String value) throws IOException {
if (relayHeaderOrMetadata) next.visitMetadata(key, value);
}

Expand All @@ -106,28 +108,28 @@ public boolean visitClass(String srcName) throws IOException {
}

@Override
public boolean visitField(String srcName, String srcDesc) throws IOException {
public boolean visitField(String srcName, @Nullable String srcDesc) throws IOException {
this.srcName = srcName;

return next.visitField(srcName, srcDesc);
}

@Override
public boolean visitMethod(String srcName, String srcDesc) throws IOException {
public boolean visitMethod(String srcName, @Nullable String srcDesc) throws IOException {
this.srcName = srcName;

return next.visitMethod(srcName, srcDesc);
}

@Override
public boolean visitMethodArg(int argPosition, int lvIndex, String srcName) throws IOException {
public boolean visitMethodArg(int argPosition, int lvIndex, @Nullable String srcName) throws IOException {
this.srcName = srcName;

return next.visitMethodArg(argPosition, lvIndex, srcName);
}

@Override
public boolean visitMethodVar(int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, String srcName) throws IOException {
public boolean visitMethodVar(int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, @Nullable String srcName) throws IOException {
this.srcName = srcName;

return next.visitMethodVar(lvtRowIndex, lvIndex, startOpIdx, endOpIdx, srcName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.Map;
import java.util.Set;

import org.jetbrains.annotations.Nullable;

import net.fabricmc.mappingio.MappedElementKind;
import net.fabricmc.mappingio.MappingFlag;
import net.fabricmc.mappingio.MappingUtil;
Expand Down Expand Up @@ -127,7 +129,7 @@ public void visitNamespaces(String srcNamespace, List<String> dstNamespaces) thr
}

@Override
public void visitMetadata(String key, String value) throws IOException {
public void visitMetadata(String key, @Nullable String value) throws IOException {
if (classMapReady && relayHeaderOrMetadata) next.visitMetadata(key, value);
}

Expand All @@ -150,7 +152,7 @@ public boolean visitClass(String srcName) throws IOException {
}

@Override
public boolean visitField(String srcName, String srcDesc) throws IOException {
public boolean visitField(String srcName, @Nullable String srcDesc) throws IOException {
assert classMapReady;
if (passThrough) return next.visitField(srcName, srcDesc);

Expand All @@ -161,7 +163,7 @@ public boolean visitField(String srcName, String srcDesc) throws IOException {
}

@Override
public boolean visitMethod(String srcName, String srcDesc) throws IOException {
public boolean visitMethod(String srcName, @Nullable String srcDesc) throws IOException {
assert classMapReady;
if (passThrough) return next.visitMethod(srcName, srcDesc);

Expand All @@ -172,7 +174,7 @@ public boolean visitMethod(String srcName, String srcDesc) throws IOException {
}

@Override
public boolean visitMethodArg(int argPosition, int lvIndex, String srcName) throws IOException {
public boolean visitMethodArg(int argPosition, int lvIndex, @Nullable String srcName) throws IOException {
assert classMapReady;
if (passThrough) return next.visitMethodArg(argPosition, lvIndex, srcName);

Expand All @@ -184,7 +186,7 @@ public boolean visitMethodArg(int argPosition, int lvIndex, String srcName) thro
}

@Override
public boolean visitMethodVar(int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, String srcName) throws IOException {
public boolean visitMethodVar(int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, @Nullable String srcName) throws IOException {
assert classMapReady;
if (passThrough) return next.visitMethodVar(lvtRowIndex, lvIndex, startOpIdx, endOpIdx, srcName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.io.IOException;

import org.jetbrains.annotations.Nullable;

import net.fabricmc.mappingio.MappingVisitor;

public final class MissingDescFilter extends ForwardingMappingVisitor {
Expand All @@ -26,14 +28,14 @@ public MissingDescFilter(MappingVisitor next) {
}

@Override
public boolean visitField(String srcName, String srcDesc) throws IOException {
public boolean visitField(String srcName, @Nullable String srcDesc) throws IOException {
if (srcDesc == null) return false;

return super.visitField(srcName, srcDesc);
}

@Override
public boolean visitMethod(String srcName, String srcDesc) throws IOException {
public boolean visitMethod(String srcName, @Nullable String srcDesc) throws IOException {
if (srcDesc == null) return false;

return super.visitMethod(srcName, srcDesc);
Expand Down
Loading

0 comments on commit 387c2f4

Please sign in to comment.