Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split error acceptors (sinks) and collectors
Browse files Browse the repository at this point in the history
NebelNidas committed Apr 15, 2024
1 parent 12dfc4d commit 4363dc9
Showing 18 changed files with 225 additions and 163 deletions.
18 changes: 9 additions & 9 deletions src/main/java/net/fabricmc/mappingio/MappingReader.java
Original file line number Diff line number Diff line change
@@ -28,10 +28,10 @@

import org.jetbrains.annotations.Nullable;

import net.fabricmc.mappingio.format.ErrorCollector;
import net.fabricmc.mappingio.format.ErrorCollector.Severity;
import net.fabricmc.mappingio.format.ErrorCollector.ThrowingErrorCollector;
import net.fabricmc.mappingio.format.ErrorSink;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.ThrowingErrorSink;
import net.fabricmc.mappingio.format.ParsingError.Severity;
import net.fabricmc.mappingio.format.enigma.EnigmaDirReader;
import net.fabricmc.mappingio.format.enigma.EnigmaFileReader;
import net.fabricmc.mappingio.format.jobf.JobfFileReader;
@@ -224,7 +224,7 @@ public static void read(Path path, MappingVisitor visitor) throws IOException {
* @param errorCollector The error collector instance to log errors to.
* @throws IOException If the format can't be detected or reading fails.
*/
public static void read(Path path, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Path path, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
read(path, null, visitor, errorCollector);
}

@@ -238,7 +238,7 @@ public static void read(Path path, MappingVisitor visitor, ErrorCollector errorC
*/
@Deprecated
public static void read(Path path, MappingFormat format, MappingVisitor visitor) throws IOException {
read(path, format, visitor, new ThrowingErrorCollector(Severity.ERROR));
read(path, format, visitor, new ThrowingErrorSink(Severity.ERROR));
}

/**
@@ -249,7 +249,7 @@ public static void read(Path path, MappingFormat format, MappingVisitor visitor)
* @param visitor The receiving visitor.
* @throws IOException If reading fails.
*/
public static void read(Path path, MappingFormat format, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Path path, MappingFormat format, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
if (format == null) {
format = detectFormat(path);
if (format == null) throw new IOException("invalid/unsupported mapping format");
@@ -290,7 +290,7 @@ public static void read(Reader reader, MappingVisitor visitor) throws IOExceptio
* @param errorCollector The error collector instance to log errors to.
* @throws IOException If the format can't be detected or reading fails.
*/
public static void read(Reader reader, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Reader reader, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
read(reader, null, visitor, errorCollector);
}

@@ -304,7 +304,7 @@ public static void read(Reader reader, MappingVisitor visitor, ErrorCollector er
*/
@Deprecated
public static void read(Reader reader, MappingFormat format, MappingVisitor visitor) throws IOException {
read(reader, format, visitor, new ThrowingErrorCollector(Severity.ERROR));
read(reader, format, visitor, new ThrowingErrorSink(Severity.ERROR));
}

/**
@@ -316,7 +316,7 @@ public static void read(Reader reader, MappingFormat format, MappingVisitor visi
* @param errorCollector The error collector instance to log errors to.
* @throws IOException If reading fails.
*/
public static void read(Reader reader, MappingFormat format, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Reader reader, MappingFormat format, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
if (format == null) {
if (!reader.markSupported()) reader = new BufferedReader(reader);
reader.mark(DETECT_HEADER_LEN);
81 changes: 4 additions & 77 deletions src/main/java/net/fabricmc/mappingio/format/ErrorCollector.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 FabricMC
* Copyright (c) 2024 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,17 +18,16 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.jetbrains.annotations.ApiStatus;
import net.fabricmc.mappingio.format.ParsingError.Severity;

public interface ErrorCollector {
public interface ErrorCollector extends ErrorSink {
static ErrorCollector create() {
return new ErrorCollector() {
@Override
public void add(Severity severity, String message) throws IOException {
errors.add(new ParsingError(severity, message));
errors.add(ParsingError.create(severity, message));
}

@Override
@@ -40,77 +39,5 @@ public List<ParsingError> getErrors() {
};
}

default void addInfo(String message) throws IOException {
add(Severity.INFO, message);
}

default void addWarning(String message) throws IOException {
add(Severity.WARNING, message);
}

default void addError(String message) throws IOException {
add(Severity.ERROR, message);
}

void add(Severity severity, String message) throws IOException;

List<ParsingError> getErrors();

enum Severity {
/**
* When something's technically wrong but doesn't affect
* parsing or the mapping data in any way.
*/
INFO,
/**
* When element data is partially missing, but the rest of the element
* could still be deciphered and it didn't have to be skipped entirely.
* Or when an unknown top-level element is encountered.
*/
WARNING,
/**
* An issue so severe that parsing of entire elements had to be skipped.
* E.g. a class's/member's source name being absent.
*/
ERROR
}

class ParsingError {
ParsingError(Severity severity, String message) {
this.severity = severity;
this.message = message;
}

public Severity getSeverity() {
return severity;
}

public String getMessage() {
return message;
}

private final Severity severity;
private final String message;
}

@ApiStatus.Internal
class ThrowingErrorCollector implements ErrorCollector {
public ThrowingErrorCollector(Severity severityToThrowAt) {
this.severityToThrowAt = severityToThrowAt;
}

@Override
public void add(Severity severity, String message) throws IOException {
if (severity.compareTo(severityToThrowAt) >= 0) {
throw new IOException(message);
}
}

@Override
public List<ParsingError> getErrors() {
return Collections.emptyList();
}

private Severity severityToThrowAt;
}
}
37 changes: 37 additions & 0 deletions src/main/java/net/fabricmc/mappingio/format/ErrorSink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2023 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.mappingio.format;

import java.io.IOException;

import net.fabricmc.mappingio.format.ParsingError.Severity;

public interface ErrorSink {
default void addInfo(String message) throws IOException {
add(Severity.INFO, message);
}

default void addWarning(String message) throws IOException {
add(Severity.WARNING, message);
}

default void addError(String message) throws IOException {
add(Severity.ERROR, message);
}

void add(Severity severity, String message) throws IOException;
}
59 changes: 59 additions & 0 deletions src/main/java/net/fabricmc/mappingio/format/ParsingError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2024 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.mappingio.format;

import org.jetbrains.annotations.ApiStatus;

@ApiStatus.NonExtendable
public interface ParsingError {
static ParsingError create(Severity severity, String message) {
return new ParsingError() {
@Override
public Severity getSeverity() {
return severity;
}

@Override
public String getMessage() {
return message;
}
};
}

Severity getSeverity();

String getMessage();

enum Severity {
/**
* When something's technically wrong but doesn't affect
* parsing or the mapping data in any way.
*/
INFO,
/**
* When element data is partially missing, but the rest of the element
* could still be deciphered and it didn't have to be skipped entirely.
* Or when an unknown top-level element is encountered.
*/
WARNING,
/**
* An issue so severe that parsing of entire elements had to be skipped.
* E.g. a class's/member's source name being absent.
*/
ERROR
}
}
39 changes: 39 additions & 0 deletions src/main/java/net/fabricmc/mappingio/format/ThrowingErrorSink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2024 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.mappingio.format;

import java.io.IOException;

import org.jetbrains.annotations.ApiStatus;

import net.fabricmc.mappingio.format.ParsingError.Severity;

@ApiStatus.Internal
public final class ThrowingErrorSink implements ErrorSink {
public ThrowingErrorSink(Severity severityToThrowAt) {
this.severityToThrowAt = severityToThrowAt;
}

@Override
public void add(Severity severity, String message) throws IOException {
if (severity.compareTo(severityToThrowAt) >= 0) {
throw new IOException(message);
}
}

private Severity severityToThrowAt;
}
Original file line number Diff line number Diff line change
@@ -29,10 +29,10 @@
import net.fabricmc.mappingio.MappingUtil;
import net.fabricmc.mappingio.MappingVisitor;
import net.fabricmc.mappingio.adapter.ForwardingMappingVisitor;
import net.fabricmc.mappingio.format.ErrorCollector;
import net.fabricmc.mappingio.format.ErrorCollector.Severity;
import net.fabricmc.mappingio.format.ErrorCollector.ThrowingErrorCollector;
import net.fabricmc.mappingio.format.ErrorSink;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.ThrowingErrorSink;
import net.fabricmc.mappingio.format.ParsingError.Severity;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;

@@ -51,16 +51,16 @@ public static void read(Path dir, MappingVisitor visitor) throws IOException {
read(dir, MappingUtil.NS_SOURCE_FALLBACK, MappingUtil.NS_TARGET_FALLBACK, visitor);
}

public static void read(Path dir, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Path dir, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
read(dir, MappingUtil.NS_SOURCE_FALLBACK, MappingUtil.NS_TARGET_FALLBACK, visitor, errorCollector);
}

@Deprecated
public static void read(Path dir, String sourceNs, String targetNs, MappingVisitor visitor) throws IOException {
read(dir, sourceNs, targetNs, visitor, new ThrowingErrorCollector(Severity.ERROR));
read(dir, sourceNs, targetNs, visitor, new ThrowingErrorSink(Severity.ERROR));
}

public static void read(Path dir, String sourceNs, String targetNs, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Path dir, String sourceNs, String targetNs, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
Set<MappingFlag> flags = visitor.getFlags();
MappingVisitor parentVisitor = null;

Original file line number Diff line number Diff line change
@@ -26,10 +26,10 @@
import net.fabricmc.mappingio.MappingUtil;
import net.fabricmc.mappingio.MappingVisitor;
import net.fabricmc.mappingio.format.ColumnFileReader;
import net.fabricmc.mappingio.format.ErrorCollector;
import net.fabricmc.mappingio.format.ErrorCollector.Severity;
import net.fabricmc.mappingio.format.ErrorCollector.ThrowingErrorCollector;
import net.fabricmc.mappingio.format.ErrorSink;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.ThrowingErrorSink;
import net.fabricmc.mappingio.format.ParsingError.Severity;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;

@@ -48,20 +48,20 @@ public static void read(Reader reader, MappingVisitor visitor) throws IOExceptio
read(reader, MappingUtil.NS_SOURCE_FALLBACK, MappingUtil.NS_TARGET_FALLBACK, visitor);
}

public static void read(Reader reader, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Reader reader, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
read(reader, MappingUtil.NS_SOURCE_FALLBACK, MappingUtil.NS_TARGET_FALLBACK, visitor, errorCollector);
}

@Deprecated
public static void read(Reader reader, String sourceNs, String targetNs, MappingVisitor visitor) throws IOException {
read(reader, sourceNs, targetNs, visitor, new ThrowingErrorCollector(Severity.ERROR));
read(reader, sourceNs, targetNs, visitor, new ThrowingErrorSink(Severity.ERROR));
}

public static void read(Reader reader, String sourceNs, String targetNs, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Reader reader, String sourceNs, String targetNs, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
read(new ColumnFileReader(reader, '\t', ' '), sourceNs, targetNs, visitor, errorCollector);
}

public static void read(ColumnFileReader reader, String sourceNs, String targetNs, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(ColumnFileReader reader, String sourceNs, String targetNs, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
Set<MappingFlag> flags = visitor.getFlags();
MappingVisitor parentVisitor = null;

@@ -96,7 +96,7 @@ public static void read(ColumnFileReader reader, String sourceNs, String targetN
}
}

private static void readClass(ColumnFileReader reader, int indent, String outerSrcClass, String outerDstClass, StringBuilder commentSb, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void readClass(ColumnFileReader reader, int indent, String outerSrcClass, String outerDstClass, StringBuilder commentSb, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
String srcInnerName = reader.nextCol();

if (srcInnerName == null || srcInnerName.isEmpty()) {
@@ -125,7 +125,7 @@ private static void readClass(ColumnFileReader reader, int indent, String outerS
readClassBody(reader, indent, srcName, dstName, commentSb, visitor, errorCollector);
}

private static void readClassBody(ColumnFileReader reader, int indent, String srcClass, String dstClass, StringBuilder commentSb, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void readClassBody(ColumnFileReader reader, int indent, String srcClass, String dstClass, StringBuilder commentSb, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
boolean visited = false;
int state = 0; // 0=invalid 1=visit -1=skip

@@ -213,7 +213,7 @@ private static int visitClass(String srcClass, String dstClass, int state, Strin
return state;
}

private static void readMethod(ColumnFileReader reader, int indent, StringBuilder commentSb, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void readMethod(ColumnFileReader reader, int indent, StringBuilder commentSb, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
if (!visitor.visitElementContent(MappedElementKind.METHOD)) return;

while (reader.nextLine(indent + 2)) {
Original file line number Diff line number Diff line change
@@ -27,10 +27,10 @@
import net.fabricmc.mappingio.MappingFlag;
import net.fabricmc.mappingio.MappingUtil;
import net.fabricmc.mappingio.MappingVisitor;
import net.fabricmc.mappingio.format.ErrorCollector;
import net.fabricmc.mappingio.format.ErrorCollector.Severity;
import net.fabricmc.mappingio.format.ErrorCollector.ThrowingErrorCollector;
import net.fabricmc.mappingio.format.ErrorSink;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.ThrowingErrorSink;
import net.fabricmc.mappingio.format.ParsingError.Severity;

/**
* {@linkplain MappingFormat#PROGUARD_FILE ProGuard file} reader.
@@ -47,22 +47,22 @@ public static void read(Reader reader, MappingVisitor visitor) throws IOExceptio
read(reader, MappingUtil.NS_SOURCE_FALLBACK, MappingUtil.NS_TARGET_FALLBACK, visitor);
}

public static void read(Reader reader, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Reader reader, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
read(reader, MappingUtil.NS_SOURCE_FALLBACK, MappingUtil.NS_TARGET_FALLBACK, visitor, errorCollector);
}

@Deprecated
public static void read(Reader reader, String sourceNs, String targetNs, MappingVisitor visitor) throws IOException {
read(reader, sourceNs, targetNs, visitor, new ThrowingErrorCollector(Severity.ERROR));
read(reader, sourceNs, targetNs, visitor, new ThrowingErrorSink(Severity.ERROR));
}

public static void read(Reader reader, String sourceNs, String targetNs, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Reader reader, String sourceNs, String targetNs, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
BufferedReader br = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);

read(br, sourceNs, targetNs, visitor, errorCollector);
}

private static void read(BufferedReader reader, String sourceNs, String targetNs, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void read(BufferedReader reader, String sourceNs, String targetNs, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
CharArrayReader parentReader = null;

if (visitor.getFlags().contains(MappingFlag.NEEDS_MULTIPLE_PASSES)) {
Original file line number Diff line number Diff line change
@@ -26,10 +26,10 @@
import net.fabricmc.mappingio.MappingUtil;
import net.fabricmc.mappingio.MappingVisitor;
import net.fabricmc.mappingio.format.ColumnFileReader;
import net.fabricmc.mappingio.format.ErrorCollector;
import net.fabricmc.mappingio.format.ErrorCollector.Severity;
import net.fabricmc.mappingio.format.ErrorCollector.ThrowingErrorCollector;
import net.fabricmc.mappingio.format.ErrorSink;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.ThrowingErrorSink;
import net.fabricmc.mappingio.format.ParsingError.Severity;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;

@@ -49,20 +49,20 @@ public static void read(Reader reader, MappingVisitor visitor) throws IOExceptio
read(reader, MappingUtil.NS_SOURCE_FALLBACK, MappingUtil.NS_TARGET_FALLBACK, visitor);
}

public static void read(Reader reader, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Reader reader, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
read(reader, MappingUtil.NS_SOURCE_FALLBACK, MappingUtil.NS_TARGET_FALLBACK, visitor, errorCollector);
}

@Deprecated
public static void read(Reader reader, String sourceNs, String targetNs, MappingVisitor visitor) throws IOException {
read(reader, sourceNs, targetNs, visitor, new ThrowingErrorCollector(Severity.ERROR));
read(reader, sourceNs, targetNs, visitor, new ThrowingErrorSink(Severity.ERROR));
}

public static void read(Reader reader, String sourceNs, String targetNs, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Reader reader, String sourceNs, String targetNs, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
read(new ColumnFileReader(reader, '\t', ' '), sourceNs, targetNs, visitor, errorCollector);
}

private static void read(ColumnFileReader reader, String sourceNs, String targetNs, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void read(ColumnFileReader reader, String sourceNs, String targetNs, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
Set<MappingFlag> flags = visitor.getFlags();
MappingVisitor parentVisitor = null;
MappingFormat format = MappingFormat.SRG_FILE;
20 changes: 10 additions & 10 deletions src/main/java/net/fabricmc/mappingio/format/srg/TsrgFileReader.java
Original file line number Diff line number Diff line change
@@ -28,10 +28,10 @@
import net.fabricmc.mappingio.MappingUtil;
import net.fabricmc.mappingio.MappingVisitor;
import net.fabricmc.mappingio.format.ColumnFileReader;
import net.fabricmc.mappingio.format.ErrorCollector;
import net.fabricmc.mappingio.format.ErrorCollector.Severity;
import net.fabricmc.mappingio.format.ErrorCollector.ThrowingErrorCollector;
import net.fabricmc.mappingio.format.ErrorSink;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.ThrowingErrorSink;
import net.fabricmc.mappingio.format.ParsingError.Severity;

/**
* {@linkplain MappingFormat#CSRG_FILE CSRG file},
@@ -69,16 +69,16 @@ public static void read(Reader reader, MappingVisitor visitor) throws IOExceptio
read(reader, MappingUtil.NS_SOURCE_FALLBACK, MappingUtil.NS_TARGET_FALLBACK, visitor);
}

public static void read(Reader reader, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Reader reader, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
read(new ColumnFileReader(reader, '\t', ' '), MappingUtil.NS_SOURCE_FALLBACK, MappingUtil.NS_TARGET_FALLBACK, visitor, errorCollector);
}

@Deprecated
public static void read(Reader reader, String sourceNs, String targetNs, MappingVisitor visitor) throws IOException {
read(new ColumnFileReader(reader, '\t', ' '), sourceNs, targetNs, visitor, new ThrowingErrorCollector(Severity.ERROR));
read(new ColumnFileReader(reader, '\t', ' '), sourceNs, targetNs, visitor, new ThrowingErrorSink(Severity.ERROR));
}

public static void read(ColumnFileReader reader, String sourceNs, String targetNs, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(ColumnFileReader reader, String sourceNs, String targetNs, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
MappingFormat format = reader.nextCol("tsrg2") ? format = MappingFormat.TSRG_2_FILE : MappingFormat.TSRG_FILE;
String srcNamespace;
List<String> dstNamespaces;
@@ -206,7 +206,7 @@ public static void read(ColumnFileReader reader, String sourceNs, String targetN
}
}

private static boolean readClass(ColumnFileReader reader, boolean isTsrg2, int dstNsCount, List<String> nameTmp, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static boolean readClass(ColumnFileReader reader, boolean isTsrg2, int dstNsCount, List<String> nameTmp, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
readDstNames(reader, MappedElementKind.CLASS, 0, dstNsCount, visitor, errorCollector);
if (!visitor.visitElementContent(MappedElementKind.CLASS)) return false;

@@ -295,7 +295,7 @@ private static boolean readClass(ColumnFileReader reader, boolean isTsrg2, int d
return true;
}

private static void readMethod(ColumnFileReader reader, int dstNsCount, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void readMethod(ColumnFileReader reader, int dstNsCount, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
readDstNames(reader, MappedElementKind.METHOD, 0, dstNsCount, visitor, errorCollector);
if (!visitor.visitElementContent(MappedElementKind.METHOD)) return;

@@ -333,12 +333,12 @@ private static void readMethod(ColumnFileReader reader, int dstNsCount, MappingV
}
}

private static void readElement(ColumnFileReader reader, MappedElementKind kind, int dstNsOffset, int dstNsCount, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void readElement(ColumnFileReader reader, MappedElementKind kind, int dstNsOffset, int dstNsCount, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
readDstNames(reader, kind, dstNsOffset, dstNsCount, visitor, errorCollector);
visitor.visitElementContent(kind);
}

private static void readDstNames(ColumnFileReader reader, MappedElementKind subjectKind, int dstNsOffset, int dstNsCount, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void readDstNames(ColumnFileReader reader, MappedElementKind subjectKind, int dstNsOffset, int dstNsCount, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
for (int dstNs = dstNsOffset; dstNs < dstNsCount; dstNs++) {
String name = reader.nextCol();

Original file line number Diff line number Diff line change
@@ -26,10 +26,10 @@
import net.fabricmc.mappingio.MappingFlag;
import net.fabricmc.mappingio.MappingVisitor;
import net.fabricmc.mappingio.format.ColumnFileReader;
import net.fabricmc.mappingio.format.ErrorCollector;
import net.fabricmc.mappingio.format.ErrorCollector.Severity;
import net.fabricmc.mappingio.format.ErrorCollector.ThrowingErrorCollector;
import net.fabricmc.mappingio.format.ErrorSink;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.ThrowingErrorSink;
import net.fabricmc.mappingio.format.ParsingError.Severity;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;

@@ -64,14 +64,14 @@ private static List<String> getNamespaces(ColumnFileReader reader) throws IOExce

@Deprecated
public static void read(Reader reader, MappingVisitor visitor) throws IOException {
read(reader, visitor, new ThrowingErrorCollector(Severity.ERROR));
read(reader, visitor, new ThrowingErrorSink(Severity.ERROR));
}

public static void read(Reader reader, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Reader reader, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
read(new ColumnFileReader(reader, '\t', '\t'), visitor, errorCollector);
}

private static void read(ColumnFileReader reader, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void read(ColumnFileReader reader, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
if (!reader.nextCol("v1")) { // magic/version
throw new IOException("invalid/unsupported tiny file: no tiny 1 header");
}
@@ -203,7 +203,7 @@ private static void read(ColumnFileReader reader, MappingVisitor visitor, ErrorC
}
}

private static void readDstNames(ColumnFileReader reader, MappedElementKind subjectKind, int dstNsCount, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void readDstNames(ColumnFileReader reader, MappedElementKind subjectKind, int dstNsCount, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
for (int dstNs = 0; dstNs < dstNsCount; dstNs++) {
String name = reader.nextCol();

Original file line number Diff line number Diff line change
@@ -25,10 +25,10 @@
import net.fabricmc.mappingio.MappingFlag;
import net.fabricmc.mappingio.MappingVisitor;
import net.fabricmc.mappingio.format.ColumnFileReader;
import net.fabricmc.mappingio.format.ErrorCollector;
import net.fabricmc.mappingio.format.ErrorCollector.Severity;
import net.fabricmc.mappingio.format.ErrorCollector.ThrowingErrorCollector;
import net.fabricmc.mappingio.format.ErrorSink;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.ThrowingErrorSink;
import net.fabricmc.mappingio.format.ParsingError.Severity;

/**
* {@linkplain MappingFormat#TINY_2 Tiny v2 file} reader.
@@ -63,14 +63,14 @@ private static List<String> getNamespaces(ColumnFileReader reader) throws IOExce

@Deprecated
public static void read(Reader reader, MappingVisitor visitor) throws IOException {
read(new ColumnFileReader(reader, '\t', '\t'), visitor, new ThrowingErrorCollector(Severity.ERROR));
read(new ColumnFileReader(reader, '\t', '\t'), visitor, new ThrowingErrorSink(Severity.ERROR));
}

public static void read(Reader reader, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
public static void read(Reader reader, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
read(new ColumnFileReader(reader, '\t', '\t'), visitor, errorCollector);
}

private static void read(ColumnFileReader reader, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void read(ColumnFileReader reader, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
if (!reader.nextCol("tiny") // magic
|| reader.nextIntCol(true) != 2 // major version
|| reader.nextIntCol(true) < 0) { // minor version
@@ -150,7 +150,7 @@ private static void read(ColumnFileReader reader, MappingVisitor visitor, ErrorC
}
}

private static void readClass(ColumnFileReader reader, int dstNsCount, boolean escapeNames, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void readClass(ColumnFileReader reader, int dstNsCount, boolean escapeNames, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
readDstNames(reader, MappedElementKind.CLASS, dstNsCount, escapeNames, visitor, errorCollector);
if (!visitor.visitElementContent(MappedElementKind.CLASS)) return;

@@ -197,7 +197,7 @@ private static void readClass(ColumnFileReader reader, int dstNsCount, boolean e
}
}

private static void readMethod(ColumnFileReader reader, int dstNsCount, boolean escapeNames, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void readMethod(ColumnFileReader reader, int dstNsCount, boolean escapeNames, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
readDstNames(reader, MappedElementKind.METHOD, dstNsCount, escapeNames, visitor, errorCollector);
if (!visitor.visitElementContent(MappedElementKind.METHOD)) return;

@@ -292,7 +292,7 @@ private static void readMethod(ColumnFileReader reader, int dstNsCount, boolean
}
}

private static void readElement(ColumnFileReader reader, MappedElementKind kind, int dstNsCount, boolean escapeNames, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void readElement(ColumnFileReader reader, MappedElementKind kind, int dstNsCount, boolean escapeNames, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
readDstNames(reader, kind, dstNsCount, escapeNames, visitor, errorCollector);
if (!visitor.visitElementContent(kind)) return;

@@ -303,7 +303,7 @@ private static void readElement(ColumnFileReader reader, MappedElementKind kind,
}
}

private static void readComment(ColumnFileReader reader, MappedElementKind subjectKind, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void readComment(ColumnFileReader reader, MappedElementKind subjectKind, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
String comment = reader.nextCol(true);

if (comment == null) {
@@ -314,7 +314,7 @@ private static void readComment(ColumnFileReader reader, MappedElementKind subje
visitor.visitComment(subjectKind, comment);
}

private static void readDstNames(ColumnFileReader reader, MappedElementKind subjectKind, int dstNsCount, boolean escapeNames, MappingVisitor visitor, ErrorCollector errorCollector) throws IOException {
private static void readDstNames(ColumnFileReader reader, MappedElementKind subjectKind, int dstNsCount, boolean escapeNames, MappingVisitor visitor, ErrorSink errorCollector) throws IOException {
for (int dstNs = 0; dstNs < dstNsCount; dstNs++) {
String name = reader.nextCol(escapeNames);

6 changes: 3 additions & 3 deletions src/test/java/net/fabricmc/mappingio/read/DetectionTest.java
Original file line number Diff line number Diff line change
@@ -31,9 +31,9 @@
import net.fabricmc.mappingio.MappingReader;
import net.fabricmc.mappingio.NopMappingVisitor;
import net.fabricmc.mappingio.TestHelper;
import net.fabricmc.mappingio.format.ErrorCollector.Severity;
import net.fabricmc.mappingio.format.ErrorCollector.ThrowingErrorCollector;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.ThrowingErrorSink;
import net.fabricmc.mappingio.format.ParsingError.Severity;

public class DetectionTest {
private static final Path dir = TestHelper.MappingDirs.DETECTION;
@@ -129,7 +129,7 @@ private void check(MappingFormat format) throws Exception {

// Make sure that the passed reader still works after implicit format detection (see https://github.com/FabricMC/mapping-io/pull/71).
try (Reader reader = new InputStreamReader(Files.newInputStream(path), StandardCharsets.UTF_8)) {
MappingReader.read(reader, new NopMappingVisitor(true), new ThrowingErrorCollector(Severity.INFO));
MappingReader.read(reader, new NopMappingVisitor(true), new ThrowingErrorSink(Severity.INFO));
}
}
}
Original file line number Diff line number Diff line change
@@ -23,9 +23,9 @@

import org.junit.jupiter.api.Test;

import net.fabricmc.mappingio.format.ErrorCollector;
import net.fabricmc.mappingio.format.ErrorCollector.Severity;
import net.fabricmc.mappingio.format.ErrorCollector.ThrowingErrorCollector;
import net.fabricmc.mappingio.format.ErrorSink;
import net.fabricmc.mappingio.format.ThrowingErrorSink;
import net.fabricmc.mappingio.format.ParsingError.Severity;
import net.fabricmc.mappingio.format.enigma.EnigmaFileReader;
import net.fabricmc.mappingio.format.jobf.JobfFileReader;
import net.fabricmc.mappingio.format.proguard.ProGuardFileReader;
@@ -40,7 +40,7 @@

public class EmptyContentReadTest {
private static final VisitableMappingTree tree = new MemoryMappingTree();
private static final ErrorCollector errorCollector = new ThrowingErrorCollector(Severity.INFO);
private static final ErrorSink errorCollector = new ThrowingErrorSink(Severity.INFO);

@Test
public void emptyEnigmaFile() throws Exception {
Original file line number Diff line number Diff line change
@@ -31,9 +31,9 @@
import net.fabricmc.mappingio.MappingReader;
import net.fabricmc.mappingio.NopMappingVisitor;
import net.fabricmc.mappingio.format.ErrorCollector;
import net.fabricmc.mappingio.format.ErrorCollector.ParsingError;
import net.fabricmc.mappingio.format.ErrorCollector.Severity;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.ParsingError;
import net.fabricmc.mappingio.format.ParsingError.Severity;

public class InvalidContentReadTest {
private static final String tinyHeader = "v1 source target\n";
Original file line number Diff line number Diff line change
@@ -24,16 +24,16 @@
import net.fabricmc.mappingio.SubsetAssertingVisitor;
import net.fabricmc.mappingio.TestHelper;
import net.fabricmc.mappingio.adapter.FlatAsRegularMappingVisitor;
import net.fabricmc.mappingio.format.ErrorCollector;
import net.fabricmc.mappingio.format.ErrorCollector.Severity;
import net.fabricmc.mappingio.format.ErrorCollector.ThrowingErrorCollector;
import net.fabricmc.mappingio.format.ErrorSink;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.ThrowingErrorSink;
import net.fabricmc.mappingio.format.ParsingError.Severity;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;
import net.fabricmc.mappingio.tree.VisitableMappingTree;

public class ValidContentReadTest {
private static final ErrorCollector errorCollector = new ThrowingErrorCollector(Severity.INFO);
private static final ErrorSink errorCollector = new ThrowingErrorSink(Severity.INFO);
private static MappingTree testTree;
private static MappingTree testTreeWithHoles;

Original file line number Diff line number Diff line change
@@ -34,9 +34,9 @@
import net.fabricmc.mappingio.SubsetAssertingVisitor;
import net.fabricmc.mappingio.TestHelper;
import net.fabricmc.mappingio.adapter.FlatAsRegularMappingVisitor;
import net.fabricmc.mappingio.format.ErrorCollector.Severity;
import net.fabricmc.mappingio.format.ErrorCollector.ThrowingErrorCollector;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.ThrowingErrorSink;
import net.fabricmc.mappingio.format.ParsingError.Severity;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MappingTreeView;
import net.fabricmc.mappingio.tree.MemoryMappingTree;
@@ -144,7 +144,7 @@ private void checkDir(Path dir, MappingFormat format) throws Exception {

private VisitEndTestVisitor checkCompliance(MappingFormat format, Path path, int visitPassCountToFinish, boolean setFlag, MappingTreeView supTree) throws Exception {
VisitEndTestVisitor visitor = new VisitEndTestVisitor(visitPassCountToFinish, setFlag, supTree, format);
MappingReader.read(path, format, visitor, new ThrowingErrorCollector(Severity.INFO));
MappingReader.read(path, format, visitor, new ThrowingErrorSink(Severity.INFO));
assertTrue(visitor.finishedVisitPassCount == visitPassCountToFinish);
return visitor;
}
6 changes: 3 additions & 3 deletions src/test/java/net/fabricmc/mappingio/write/WriteTest.java
Original file line number Diff line number Diff line change
@@ -26,9 +26,9 @@
import net.fabricmc.mappingio.SubsetAssertingVisitor;
import net.fabricmc.mappingio.TestHelper;
import net.fabricmc.mappingio.adapter.FlatAsRegularMappingVisitor;
import net.fabricmc.mappingio.format.ErrorCollector.Severity;
import net.fabricmc.mappingio.format.ErrorCollector.ThrowingErrorCollector;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.ThrowingErrorSink;
import net.fabricmc.mappingio.format.ParsingError.Severity;
import net.fabricmc.mappingio.tree.MappingTreeView;
import net.fabricmc.mappingio.tree.MemoryMappingTree;
import net.fabricmc.mappingio.tree.VisitableMappingTree;
@@ -119,7 +119,7 @@ private void dogfood(MappingTreeView origTree, Path outputPath, MappingFormat ou
outputPath = TestHelper.writeToDir(origTree, dir, outputFormat);
VisitableMappingTree writtenTree = new MemoryMappingTree();

MappingReader.read(outputPath, outputFormat, writtenTree, new ThrowingErrorCollector(Severity.INFO));
MappingReader.read(outputPath, outputFormat, writtenTree, new ThrowingErrorSink(Severity.INFO));

writtenTree.accept(new FlatAsRegularMappingVisitor(new SubsetAssertingVisitor(origTree, null, outputFormat)));
origTree.accept(new FlatAsRegularMappingVisitor(new SubsetAssertingVisitor(writtenTree, outputFormat, null)));

0 comments on commit 4363dc9

Please sign in to comment.