-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
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
- Loading branch information
1 parent
12dfc4d
commit 9333443
Showing
18 changed files
with
225 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/net/fabricmc/mappingio/format/ErrorAcceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ErrorAcceptor { | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/net/fabricmc/mappingio/format/ParsingError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
src/main/java/net/fabricmc/mappingio/format/ThrowingErrorAcceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ThrowingErrorAcceptor implements ErrorAcceptor { | ||
public ThrowingErrorAcceptor(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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.