Class MemoryMappingTree

java.lang.Object
net.fabricmc.mappingio.tree.MemoryMappingTree
All Implemented Interfaces:
MappingVisitor, MappingTree, MappingTreeView, VisitableMappingTree

public final class MemoryMappingTree extends Object implements VisitableMappingTree
VisitableMappingTree implementation that stores all data in memory.

Switching the source namespace with an existing destination namespace via setSrcNamespace(String) or setDstNamespaces(List) is not supported yet.

  • Constructor Details

    • MemoryMappingTree

      public MemoryMappingTree()
    • MemoryMappingTree

      public MemoryMappingTree(boolean indexByDstNames)
    • MemoryMappingTree

      public MemoryMappingTree(MappingTree src)
  • Method Details

    • setIndexByDstNames

      public void setIndexByDstNames(boolean indexByDstNames)
      Whether to index classes by their destination names, in addition to their source names.

      Trades higher memory consumption for faster lookups by destination name.

    • setHierarchyInfoProvider

      @Experimental public void setHierarchyInfoProvider(@Nullable @Nullable HierarchyInfoProvider<?> provider)
      Experimental feature, may be removed or changed without further notice.
    • getSrcNamespace

      @Nullable public @Nullable String getSrcNamespace()
      Specified by:
      getSrcNamespace in interface MappingTreeView
      Returns:
      The source namespace, or null if the tree is uninitialized.
    • setSrcNamespace

      @Nullable public @Nullable String setSrcNamespace(String namespace)
      Sets the tree's and all of its contained elements' source namespace name.

      If the passed namespace name equals an existing destination namespace's name, implementors may choose to switch the two namespaces around, analogous to MappingSourceNsSwitch. This has to be made clear in the implementation's documentation.

      Specified by:
      setSrcNamespace in interface MappingTree
      Returns:
      The previous source namespace name, if present.
      Throws:
      UnsupportedOperationException - If the passed namespace name is already in use by one of the destination namespaces. This may change in a future release.
    • getDstNamespaces

      public List<String> getDstNamespaces()
      Specified by:
      getDstNamespaces in interface MappingTreeView
      Returns:
      A list containing the destination namespaces, in order of their IDs. Can only be empty if the tree is uninitialized.
    • setDstNamespaces

      public List<String> setDstNamespaces(List<String> namespaces)
      Sets the tree's and all of its contained elements' destination namespace names.

      Can be used to reorder and/or drop destination namespaces, analogous to MappingDstNsReorder.

      Implementors may allow switching with the source namespace as well, analogous to MappingSourceNsSwitch. This has to be made clear in the implementation's documentation.

      Specified by:
      setDstNamespaces in interface MappingTree
      Returns:
      The previous destination namespaces.
      Throws:
      IllegalArgumentException - If the passed namespace names contain duplicates.
      UnsupportedOperationException - If the passed namespace names contain the source namespace's name. This may change in a future release.
    • getMetadata

      public List<? extends MappingTree.MetadataEntry> getMetadata()
      Specified by:
      getMetadata in interface MappingTree
      Specified by:
      getMetadata in interface MappingTreeView
      Returns:
      A modifiable list of all metadata entries currently present in the tree. The list's order is equal to the order in which the entries have been originally added.
    • getMetadata

      public List<? extends MappingTree.MetadataEntry> getMetadata(String key)
      Specified by:
      getMetadata in interface MappingTree
      Specified by:
      getMetadata in interface MappingTreeView
      Returns:
      An unmodifiable list of all currently present metadata entries whose key is equal to the passed one. The list's order is equal to the order in which the entries have been originally added.
    • addMetadata

      public void addMetadata(MappingTree.MetadataEntry entry)
      Specified by:
      addMetadata in interface MappingTree
    • removeMetadata

      public boolean removeMetadata(String key)
      Description copied from interface: MappingTree
      Removes all metadata entries whose key is equal to the passed one.
      Specified by:
      removeMetadata in interface MappingTree
      Returns:
      Whether any entries have been removed.
    • getClasses

      public Collection<? extends MappingTree.ClassMapping> getClasses()
      Specified by:
      getClasses in interface MappingTree
      Specified by:
      getClasses in interface MappingTreeView
    • getClass

      @Nullable public @Nullable MappingTree.ClassMapping getClass(String srcName)
      Specified by:
      getClass in interface MappingTree
      Specified by:
      getClass in interface MappingTreeView
    • getClass

      @Nullable public @Nullable MappingTree.ClassMapping getClass(String name, int namespace)
      Specified by:
      getClass in interface MappingTree
      Specified by:
      getClass in interface MappingTreeView
    • addClass

      Description copied from interface: MappingTree
      Merges a class mapping into the tree.
      Specified by:
      addClass in interface MappingTree
      Returns:
      The MappingTree.ClassMapping instance present in the tree after the merge has occurred. May or may not be the passed instance.
    • removeClass

      @Nullable public @Nullable MappingTree.ClassMapping removeClass(String srcName)
      Description copied from interface: MappingTree
      Removes a class mapping from the tree.
      Specified by:
      removeClass in interface MappingTree
      Returns:
      The removed class mapping, if any.
    • accept

      public void accept(MappingVisitor visitor, VisitOrder order) throws IOException
      Specified by:
      accept in interface MappingTreeView
      Throws:
      IOException
    • reset

      public void reset()
      Description copied from interface: MappingVisitor
      Reset the visitor, including any chained visitors, to allow for another independent visit (excluding visitEnd=false).
      Specified by:
      reset in interface MappingVisitor
    • visitNamespaces

      public void visitNamespaces(String srcNamespace, List<String> dstNamespaces)
      Specified by:
      visitNamespaces in interface MappingVisitor
    • visitMetadata

      public void visitMetadata(String key, @Nullable @Nullable String value)
      Specified by:
      visitMetadata in interface MappingVisitor
    • visitClass

      public boolean visitClass(String srcName)
      Description copied from interface: MappingVisitor
      Visit a class.
      Specified by:
      visitClass in interface MappingVisitor
      Parameters:
      srcName - The fully qualified source name of the class, in internal form (slashes instead of dots, dollar signs for delimiting inner classes).
      Returns:
      Whether the class's content should be visited too.
    • visitField

      public boolean visitField(String srcName, @Nullable @Nullable String srcDesc)
      Specified by:
      visitField in interface MappingVisitor
    • visitMethod

      public boolean visitMethod(String srcName, @Nullable @Nullable String srcDesc)
      Specified by:
      visitMethod in interface MappingVisitor
    • visitMethodArg

      public boolean visitMethodArg(int argPosition, int lvIndex, @Nullable @Nullable String srcName)
      Description copied from interface: MappingVisitor
      Visit a parameter.
      Specified by:
      visitMethodArg in interface MappingVisitor
      Parameters:
      argPosition - Always starts at 0 and gets incremented by 1 for each additional parameter.
      lvIndex - The parameter's local variable index in the current method, also known as slot. Starts at 0 for static methods, 1 otherwise. For each additional parameter, it gets incremented by 1, or by 2 if it's a double-wide primitive (long or double).
      srcName - The optional source name of the parameter.
      Returns:
      Whether the arg's content should be visited too.
    • visitMethodVar

      public boolean visitMethodVar(int lvtRowIndex, int lvIndex, int startOpIdx, int endOpIdx, @Nullable @Nullable String srcName)
      Description copied from interface: MappingVisitor
      Visit a variable.
      Specified by:
      visitMethodVar in interface MappingVisitor
      Parameters:
      lvtRowIndex - The variable's index in the method's LVT (local variable table). It is optional, so -1 can be passed instead. This is the case since LVTs themselves are optional debug information, see JVMS 4.7.13.
      lvIndex - The var's local variable index in the current method, also known as slot. For each additional variable, it gets incremented by 1, or by 2 if it's a double-wide primitive (long or double). The first variable starts at the last parameter's slot plus wideness.
      startOpIdx - Required for cases when the lvIndex alone doesn't uniquely identify a local variable. This is the case when variables get re-defined later on, in which case most decompilers opt to not re-define the existing var, but instead generate a new one (with both sharing the same lvIndex).
      endOpIdx - Counterpart to startOpIdx. Exclusive.
      srcName - The optional source name of the variable.
      Returns:
      Whether the var's content should be visited too.
    • visitEnd

      public boolean visitEnd()
      Description copied from interface: MappingVisitor
      Finish the visitation pass.

      Implementors may throw an exception if a second pass is requested without the NEEDS_MULTIPLE_PASSES flag having been passed beforehand, but only if that behavior is documented.

      Specified by:
      visitEnd in interface MappingVisitor
      Returns:
      true if the visitation pass is final, false if it should be started over.
    • visitDstName

      public void visitDstName(MappedElementKind targetKind, int namespace, String name)
      Description copied from interface: MappingVisitor
      Destination name for the current element.
      Specified by:
      visitDstName in interface MappingVisitor
      Parameters:
      namespace - Namespace index (index into the dstNamespaces list in MappingVisitor.visitNamespaces(String, List)).
      name - Destination name.
    • visitComment

      public void visitComment(MappedElementKind targetKind, String comment)
      Description copied from interface: MappingVisitor
      Comment for the specified element (last content-visited or any parent).
      Specified by:
      visitComment in interface MappingVisitor
      Parameters:
      comment - Comment as a potentially multi-line string.