Class MappingContext

java.lang.Object
software.coley.sourcesolver.mapping.MappingContext

public class MappingContext extends Object
Centralized mapping control.
Author:
Matt Coley
  • Constructor Details

    • MappingContext

      public MappingContext(@Nonnull com.sun.tools.javac.tree.EndPosTable table, @Nonnull String source)
      Parameters:
      table - Table to lookup tree positions within.
      source - Original source code being parsed.
  • Method Details

    • getSource

      @Nonnull public String getSource()
      Returns:
      Original source code being parsed.
    • getTable

      @Nonnull public com.sun.tools.javac.tree.EndPosTable getTable()
      Returns:
      Table to lookup tree positions within.
    • setMapper

      public <T extends Mapper<?, ?>> void setMapper(@Nonnull Class<T> mapperType, @Nonnull T mapperImplementation)
      Type Parameters:
      T - Mapper type.
      Parameters:
      mapperType - Mapper class.
      mapperImplementation - Implementation of the class.
    • setMapperSupplier

      public <T extends Mapper<?, ?>> void setMapperSupplier(@Nonnull Class<T> mapperType, @Nonnull Supplier<T> mapperSupplier)
      Type Parameters:
      T - Mapper type.
      Parameters:
      mapperType - Mapper class.
      mapperSupplier - Supplier to provide an implementation of the class.
    • getMapper

      @Nonnull public <T> T getMapper(Class<T> mapperType)
      Type Parameters:
      T - Mapper type.
      Parameters:
      mapperType - Mapper class.
      Returns:
      Implementation of the mapper class.
      Throws:
      IllegalStateException - When no such implementation exists for the given mapper type.
    • map

      @Nonnull public <M extends Model, T extends Tree, X extends Mapper<M, T>> M map(@Nonnull Class<X> mapperType, @Nonnull T tree)
      Type Parameters:
      M - Model type to output.
      T - Tree type to convert.
      X - Mapper type to handle conversion.
      Parameters:
      mapperType - Mapper class.
      tree - Tree to map.
      Returns:
      Model representation of the tree.
    • mapOr

      @Nonnull public <M extends Model, T extends Tree, X extends Mapper<M, T>> M mapOr(@Nonnull Class<X> mapperType, @Nullable T tree, @Nonnull Supplier<M> defaultValueSupplier)
      Type Parameters:
      M - Model type to output.
      T - Tree type to convert.
      X - Mapper type to handle conversion.
      Parameters:
      mapperType - Mapper class.
      tree - Tree to map.
      defaultValueSupplier - Supplier to provide a fallback model.
      Returns:
      Model representation of the tree.