Class ResourceFileTypeManifold<M extends IModel>

java.lang.Object
manifold.api.service.BaseService
manifold.api.type.ResourceFileTypeManifold<M>
Type Parameters:
M - The model you derive backing contributions of source code.
All Implemented Interfaces:
IPluginHost, IService, IFileConnected, ISelfCompiled, ITypeManifold
Direct Known Subclasses:
JavaTypeManifold

public abstract class ResourceFileTypeManifold<M extends IModel> extends BaseService implements ITypeManifold
A base class for a type manifold that is based on a resource file type, typically discernible by the file extension.
  • Constructor Details

    • ResourceFileTypeManifold

      public ResourceFileTypeManifold()
  • Method Details

    • init

      public void init(IModule module)
      Description copied from interface: ITypeManifold
      Initialize this type manifold. Avoid defining types in the scope of this method.
      Specified by:
      init in interface ITypeManifold
      Parameters:
      module - The module to which this type manifold exclusively belongs
    • init

      protected void init(IModule module, BiFunction<String, Set<IFile>, M> modelMapper)
      Parameters:
      module - The module passed into the invalid input: '{@code ITypeManifold) implementation constructor @param modelMapper A function to provide a model given a qualified name and resource file'
    • isFileBacked

      public boolean isFileBacked()
      Description copied from interface: IFileConnected
      Are the types produced from this type manifold backed by project files such as resource files?
      Specified by:
      isFileBacked in interface IFileConnected
    • createCacheClearer

      protected ResourceFileTypeManifold<M>.CacheClearer createCacheClearer()
    • isDuplicate

      protected boolean isDuplicate(IFile file, Set<IFile> files)
    • getPeripheralTypes

      protected Map<String, manifold.util.concurrent.LocklessLazyVar<M>> getPeripheralTypes()
      A map of name-to-model peripheral to the main map of name-to-model, possibly including types that are not file-based. Optional.
    • getTypeNameForFile

      public String getTypeNameForFile(String defaultFqn, IFile file)
      Provide the type name that corresponds with the resource file, if different from defaultFqn.
      Parameters:
      defaultFqn - The default name derived from the resource file name.
      file - The resource file corresponding with the type name.
      Returns:
      A valid type name corresponding with the type or null if there is no primary type for file but there may be additional types via getAdditionalTypes(String, IFile)
    • getAdditionalTypes

      protected Set<String> getAdditionalTypes(String fqnForFile, IFile file)
      Additional types derived from file. These can be supporting classes, interfaces, extension classes, what have you. In the case of extension classes, this type manifold must implement IExtensionClassProducer.
      Parameters:
      fqnForFile - The primary type this type manifold assigned to file
      file - The resource file from which types may be derived
    • isInnerType

      public abstract boolean isInnerType(String topLevelFqn, String relativeInner)
      Parameters:
      topLevelFqn - Qualified name of top-level type
      relativeInner - Top-level relative name of inner class
      Returns:
      true if relativeInner is an inner class of topLevel
    • contribute

      protected abstract String contribute(JavaFileManager.Location location, String topLevelFqn, boolean genStubs, String existing, M model, DiagnosticListener<JavaFileObject> errorHandler)
      Contribute source code for the specified type and model.
      Parameters:
      location - (Experimental) The location of the use-site in the Java compiler. Provides javac module context. Optional and only relevant at compile-time when executed within a Javac compiler.
      topLevelFqn - The qualified name of the top-level type to contribute.
      genStubs -
      existing - The source produced from other manifolds so far; if not empty, this manifold must not be a ContributorKind.Primary contributor.
      model - The model your manifold uses to generate the source.
      Returns:
      The combined source code for the specified top-level type.
    • getModel

      protected M getModel(String topLevel)
    • handlesFile

      public boolean handlesFile(IFile file)
      Specified by:
      handlesFile in interface IFileConnected
      Returns:
      True if the type manifold handles the given file
    • getTypesForFile

      public String[] getTypesForFile(IFile file)
      Description copied from interface: IFileConnected
      Returns ALL type names associated with the given file whether or not the types have been loaded yet. Type loading should NOT be used in the implementation of this method.
      Specified by:
      getTypesForFile in interface IFileConnected
      Parameters:
      file - The file in question
      Returns:
      All known types derived from that file
    • getModule

      public IModule getModule()
      Description copied from interface: ITypeManifold
      The module to which this producer is scoped
      Specified by:
      getModule in interface ITypeManifold
    • refreshedFile

      public RefreshKind refreshedFile(IFile file, String[] types, RefreshKind kind)
      Description copied from interface: IFileConnected
      Notifies that a file has been refreshed. The implementor should return all types that it knows need to be refreshed based on the given file.
      Specified by:
      refreshedFile in interface IFileConnected
      Parameters:
      file - The file that was refreshed
      kind - @return All known types affected by the file change
    • isType

      public boolean isType(String fqn)
      Description copied from interface: ITypeManifold
      Does this producer supply source for the specified fqn?
      Specified by:
      isType in interface ITypeManifold
    • isPackage

      public boolean isPackage(String pkg)
      Description copied from interface: ITypeManifold
      Verifies whether or not the specified package may be provided by this source producer
      Specified by:
      isPackage in interface ITypeManifold
    • findTopLevelFqn

      public String findTopLevelFqn(String fqn)
      This method avoids initializing all the files
    • isTopLevelType

      public boolean isTopLevelType(String fqn)
      Specified by:
      isTopLevelType in interface ITypeManifold
    • getPackage

      public String getPackage(String fqn)
      Description copied from interface: ITypeManifold
      What is the package name for the specified fqn?
      Specified by:
      getPackage in interface ITypeManifold
    • contribute

      public String contribute(JavaFileManager.Location location, String fqn, boolean genStubs, String existing, DiagnosticListener<JavaFileObject> errorHandler)
      Description copied from interface: ITypeManifold
      Contribute source corresponding with the fqn.
      Specified by:
      contribute in interface ITypeManifold
    • getAllTypeNames

      public Collection<String> getAllTypeNames()
      Specified by:
      getAllTypeNames in interface ITypeManifold
    • getTypeNames

      public Collection<TypeName> getTypeNames(String namespace)
      Specified by:
      getTypeNames in interface ITypeManifold
    • findFilesForType

      public List<IFile> findFilesForType(String fqn)
      Specified by:
      findFilesForType in interface ITypeManifold
    • clear

      public void clear()
      Description copied from interface: ITypeManifold
      Clear all cached data
      Specified by:
      clear in interface ITypeManifold
    • getContent

      public static String getContent(IFile file)