Class AbstractBaseContextWithCache

All Implemented Interfaces:
io.github.mmm.code.api.CodeContext, io.github.mmm.code.api.CodeLoader, io.github.mmm.code.api.CodeProvider, io.github.mmm.code.api.CodeWithContext, io.github.mmm.code.api.node.CodeNode, BaseContext, BaseProvider, BaseLoader, AutoCloseable

public abstract class AbstractBaseContextWithCache extends AbstractBaseContext
Extends AbstractBaseContext with caching to speed up lookups.
Since:
1.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
  • Constructor Details

  • Method Details

    • createCache

      protected <K,V> Map<K,V> createCache()
      Type Parameters:
      K - key type.
      V - value type.
      Returns:
      a new empty Map instance to use as cache. May be a regular HashMap but can also be a full blown cache implementation that will automatically evict old items if a specific size is reached.
    • getLoader

      protected abstract BaseLoader getLoader()
      Returns:
      the BaseLoader to load BaseTypes.
    • getOrCreateType

      public BaseType getOrCreateType(String qualifiedName, boolean add)
    • getType

      public BaseType getType(String qualifiedName)
      Specified by:
      getType in interface BaseLoader
      Specified by:
      getType in interface io.github.mmm.code.api.CodeLoader
      Overrides:
      getType in class AbstractBaseProvider
    • getType

      public BaseType getType(io.github.mmm.code.api.CodeName qName)
    • getType

      public BaseGenericType getType(Class<?> clazz)
      Parameters:
      clazz - the Class to get as CodeGenericType.
      Returns:
      the existing or otherwise newly created CodeGenericType. Typically a CodeType but may also be a array type in case an array was given.
    • getTypeFromCache

      protected BaseType getTypeFromCache(String qualifiedName)
      Overrides:
      getTypeFromCache in class AbstractBaseContext
      Parameters:
      qualifiedName - the qualified name of the requested CodeType.
      Returns:
      the requested CodeType from the cache or null if not in cache.
    • getOrCreateSource

      public BaseSource getOrCreateSource(File byteCodeLocation, File sourceCodeLocation)
      This is an internal method that should only be used from implementations of BaseSourceProvider.
      Parameters:
      byteCodeLocation - the byte code location.
      sourceCodeLocation - the source code location.
      Returns:
      the existing or otherwise created BaseSource.
    • getOrCreateSource

      protected BaseSource getOrCreateSource(CodeSource codeSource)
      Parameters:
      codeSource - the CodeSource.
      Returns:
      the existing or otherwise created BaseSource.
    • getOrCreateSource

      public BaseSource getOrCreateSource(String id, Supplier<BaseSource> sourceSupplier)
      Attention: This is an internal method that shall not be used from outside. Use getSource(String) instead.
      Parameters:
      id - the ID of the requested source.
      sourceSupplier - the Supplier used as factory to create the source if it does not already exist.
      Returns:
      the existing BaseSource for the given ID.
    • isPreventRegisterSource

      protected boolean isPreventRegisterSource()
      Returns:
      true if getOrCreateSource(String, Supplier) may not be called to register a new source, false otherwise.
    • getSource

      public BaseSource getSource(String id)
      Specified by:
      getSource in interface BaseContext
      Overrides:
      getSource in class AbstractBaseContext
      Parameters:
      id - the ID of the requested source.
      Returns:
      the existing BaseSource for the given ID or null if not found.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface io.github.mmm.code.api.CodeProvider
      Overrides:
      close in class AbstractBaseContext