ErrorCollector.java

net.minecraft.util.parsing.packrat.ErrorCollector

信息

  • 全限定名:net.minecraft.util.parsing.packrat.ErrorCollector
  • 类型:public interface
  • 包:net.minecraft.util.parsing.packrat
  • 源码路径:src/main/java/net/minecraft/util/parsing/packrat/ErrorCollector.java
  • 起始行号:L8
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

  • net.minecraft.util.parsing.packrat.ErrorCollector.LongestOnly

    • 类型: class
    • 修饰符: public static
    • 源码定位: L17
    • 说明:

      TODO

  • net.minecraft.util.parsing.packrat.ErrorCollector.LongestOnly.MutableErrorEntry

    • 类型: class
    • 修饰符: private static
    • 源码定位: L82
    • 说明:

      TODO

  • net.minecraft.util.parsing.packrat.ErrorCollector.Nop

    • 类型: class
    • 修饰符: public static
    • 源码定位: L88
    • 说明:

      TODO

构造器

方法

下面的方法块按源码顺序生成。

void store(int cursor, SuggestionSupplier<S> suggestions, Object reason) @ L9

  • 方法名:store
  • 源码定位:L9
  • 返回类型:void
  • 修饰符:package-private

参数:

  • cursor: int
  • suggestions: SuggestionSupplier
  • reason: Object

说明:

TODO

default void store(int cursor, Object reason) @ L11

  • 方法名:store
  • 源码定位:L11
  • 返回类型:void
  • 修饰符:default

参数:

  • cursor: int
  • reason: Object

说明:

TODO

void finish(int finalCursor) @ L15

  • 方法名:finish
  • 源码定位:L15
  • 返回类型:void
  • 修饰符:package-private

参数:

  • finalCursor: int

说明:

TODO

代码

public interface ErrorCollector<S> {
    void store(int cursor, SuggestionSupplier<S> suggestions, Object reason);
 
    default void store(int cursor, Object reason) {
        this.store(cursor, SuggestionSupplier.empty(), reason);
    }
 
    void finish(int finalCursor);
 
    public static class LongestOnly<S> implements ErrorCollector<S> {
        private ErrorCollector.LongestOnly.@Nullable MutableErrorEntry<S>[] entries = new ErrorCollector.LongestOnly.MutableErrorEntry[16];
        private int nextErrorEntry;
        private int lastCursor = -1;
 
        private void discardErrorsFromShorterParse(int cursor) {
            if (cursor > this.lastCursor) {
                this.lastCursor = cursor;
                this.nextErrorEntry = 0;
            }
        }
 
        @Override
        public void finish(int finalCursor) {
            this.discardErrorsFromShorterParse(finalCursor);
        }
 
        @Override
        public void store(int cursor, SuggestionSupplier<S> suggestions, Object reason) {
            this.discardErrorsFromShorterParse(cursor);
            if (cursor == this.lastCursor) {
                this.addErrorEntry(suggestions, reason);
            }
        }
 
        private void addErrorEntry(SuggestionSupplier<S> suggestions, Object reason) {
            int currentSize = this.entries.length;
            if (this.nextErrorEntry >= currentSize) {
                int newSize = Util.growByHalf(currentSize, this.nextErrorEntry + 1);
                ErrorCollector.LongestOnly.MutableErrorEntry<S>[] newEntries = new ErrorCollector.LongestOnly.MutableErrorEntry[newSize];
                System.arraycopy(this.entries, 0, newEntries, 0, currentSize);
                this.entries = newEntries;
            }
 
            int entryIndex = this.nextErrorEntry++;
            ErrorCollector.LongestOnly.MutableErrorEntry<S> entry = this.entries[entryIndex];
            if (entry == null) {
                entry = new ErrorCollector.LongestOnly.MutableErrorEntry<>();
                this.entries[entryIndex] = entry;
            }
 
            entry.suggestions = suggestions;
            entry.reason = reason;
        }
 
        public List<ErrorEntry<S>> entries() {
            int errorCount = this.nextErrorEntry;
            if (errorCount == 0) {
                return List.of();
            } else {
                List<ErrorEntry<S>> result = new ArrayList<>(errorCount);
 
                for (int i = 0; i < errorCount; i++) {
                    ErrorCollector.LongestOnly.MutableErrorEntry<S> entry = this.entries[i];
                    result.add(new ErrorEntry<>(this.lastCursor, entry.suggestions, entry.reason));
                }
 
                return result;
            }
        }
 
        public int cursor() {
            return this.lastCursor;
        }
 
        private static class MutableErrorEntry<S> {
            private SuggestionSupplier<S> suggestions = SuggestionSupplier.empty();
            private Object reason = "empty";
        }
    }
 
    public static class Nop<S> implements ErrorCollector<S> {
        @Override
        public void store(int cursor, SuggestionSupplier<S> suggestions, Object reason) {
        }
 
        @Override
        public void finish(int finalCursor) {
        }
    }
}

引用的其他类

  • LoggedChatMessage

    • 引用位置: 方法调用
    • 关联成员: System.arraycopy()
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.growByHalf()
  • SuggestionSupplier

    • 引用位置: 参数/方法调用
    • 关联成员: SuggestionSupplier.empty()