Skip to content

Commit

Permalink
Add FeatureSet class holding information about mapping format capab…
Browse files Browse the repository at this point in the history
…ilities (#92)
  • Loading branch information
NebelNidas authored Aug 25, 2024
1 parent 1e27c3e commit 368598c
Show file tree
Hide file tree
Showing 9 changed files with 1,252 additions and 134 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Added `MappingFormat#features()` to allow for more fine-grained programmatic querying of format capabilities
- Overhauled the internal `ColumnFileReader` to behave more consistently
- Made handling of the `NEEDS_MULTIPLE_PASSES` flag more consistent, reducing memory usage in a few cases
- Made some internal methods in Enigma and TSRG readers actually private
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/fabricmc/mappingio/MappingReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static List<String> getNamespaces(Path file, MappingFormat format) throws
if (format == null) throw new IOException("invalid/unsupported mapping format");
}

if (format.hasNamespaces) {
if (format.features().hasNamespaces()) {
try (Reader reader = Files.newBufferedReader(file)) {
return getNamespaces(reader, format);
}
Expand All @@ -183,7 +183,7 @@ public static List<String> getNamespaces(Reader reader, MappingFormat format) th
if (format == null) throw new IOException("invalid/unsupported mapping format");
}

if (format.hasNamespaces) {
if (format.features().hasNamespaces()) {
checkReaderCompatible(format);

switch (format) {
Expand Down
101 changes: 101 additions & 0 deletions src/main/java/net/fabricmc/mappingio/format/FeatureSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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;

public interface FeatureSet {
boolean hasNamespaces();
MetadataSupport fileMetadata();
MetadataSupport elementMetadata();
NameSupport packages();
NameSupport classes();
MemberSupport fields();
MemberSupport methods();
LocalSupport args();
LocalSupport vars();
ElementCommentSupport elementComments();
boolean hasFileComments();

default boolean supportsPackages() {
return packages().srcNames() != FeaturePresence.ABSENT
|| packages().dstNames() != FeaturePresence.ABSENT;
}

default boolean supportsClasses() {
return classes().srcNames() != FeaturePresence.ABSENT
|| classes().dstNames() != FeaturePresence.ABSENT;
}

default boolean supportsFields() {
return FeatureSetHelper.isSupported(fields());
}

default boolean supportsMethods() {
return FeatureSetHelper.isSupported(methods());
}

default boolean supportsArgs() {
return FeatureSetHelper.isSupported(args());
}

default boolean supportsVars() {
return FeatureSetHelper.isSupported(vars());
}

enum MetadataSupport {
/** No metadata at all. */
NONE,

/** Only some select properties. */
FIXED,

/** Arbitrary metadata may be attached. */
ARBITRARY
}

enum FeaturePresence {
REQUIRED,
OPTIONAL,
ABSENT
}

interface NameSupport {
FeaturePresence srcNames();
FeaturePresence dstNames();
}

interface DescSupport {
FeaturePresence srcDescs();
FeaturePresence dstDescs();
}

interface MemberSupport extends NameSupport, DescSupport {
}

interface LocalSupport extends NameSupport, DescSupport {
FeaturePresence positions();
FeaturePresence lvIndices();
FeaturePresence lvtRowIndices();
FeaturePresence startOpIndices();
FeaturePresence endOpIndices();
}

enum ElementCommentSupport {
NAMESPACED,
SHARED,
NONE
}
}
Loading

0 comments on commit 368598c

Please sign in to comment.