Interface Importer<O extends JavaSource<O>>

All Known Subinterfaces:
EnumConstantSource.Body, JavaAnnotationSource, JavaClassSource, JavaEnumSource, JavaInterfaceSource, JavaPackageInfoSource, JavaRecordSource, JavaSource<T>

public interface Importer<O extends JavaSource<O>>
Defines the aspect of JavaSource that handles type imports.
Author:
Lincoln Baxter, III
  • Method Details

    • hasImport

      boolean hasImport(Class<?> type)
      Return whether or not this Importer has an import for the given Class type.
    • hasImport

      boolean hasImport(String type)
      Return whether or not this Importer has an import for the given fully-qualified class name.
    • requiresImport

      boolean requiresImport(Class<?> type)
      Return whether or not this Importer would require an import to reference the given Class type.
    • requiresImport

      boolean requiresImport(String type)
      Return whether or not this Importer would require an import to reference the given fully-qualified class name. If the type is generic, the generic parts are also checked in a recursive way.
    • hasImport

      <T extends JavaType<T>> boolean hasImport(T type)
      Return whether or not this Importer has an import for the given Importer type.
    • hasImport

      boolean hasImport(Import imprt)
      Return whether or not this Importer has the given Import type.
    • getImport

      Import getImport(String literalValue)
      Get the Import for the given fully-qualified class name, if it exists; otherwise, return null;
    • getImport

      Import getImport(Class<?> type)
      Get the Import for the given Class type, if it exists; otherwise, return null;
    • getImport

      <T extends JavaType<?>> Import getImport(T type)
      Get the Import for the given Importer type, if it exists; otherwise, return null;
    • getImport

      Import getImport(Import imprt)
      Get the Import of the given Import type, if it exists; otherwise, return null;
    • getImports

      List<Import> getImports()
      Get an immutable list of all Imports currently imported by this Importer
    • resolveType

      String resolveType(String type)
      Given a simple or qualified type, resolve that type against the available imports and return the referenced type. The resolving processing order is as followed:
      1. If the type is primitive or full qualified, the type is returned as it
      2. Find the type in the imports with the simple name
      3. If only one wildcard import is used, use this import for resolving
      4. Use the available WildcardImportResolver. The first qualified name is used
      5. The current package if defined is used for resolving
      6. The type is returned as it
      If the type is returned as it, maybe parts which can hinder we matching process like generic's are stripped of.
      Parameters:
      type - the type to resolve
      Returns:
      the (resolved) type
    • addImport

      Import addImport(String className)
      Add an import by qualified class name. (E.g: "com.example.Imported") unless it is in the provided 'java.lang.*' package. In the case of a generic type, the classes used are recursively also imported.
    • addImport

      Import addImport(Class<?> type)
      Add an import for the given Class type.
    • addImport

      Import addImport(Import imprt)
      Add an import for the given Import type.
    • addImport

      <T extends JavaType<?>> Import addImport(T type)
      Add an import for the given JavaType type.
    • addImport

      Import addImport(Type<?> type)
      Ensures the type passed as argument is included in the list of imports for this java source. The method will also recursively import parameter types. This method is idempotent: if a type has already been imported, no further action will be required. The method returns an Import object which should be used to reference the imported type in the code if the import operation is valid or null if one of the following conditions is met: - This type is the same type as the Class name - This type cannot be added to the import statement because it references a type with the same name but from a different package - This type belongs to the java.lang package
      Parameters:
      type - The Type to be imported.
      Returns:
      The name (simple or fully qualified) that should be used to reference the imported type in the code or null if the import could not be performed due to one of the following conditions is met: - This type is the same type as the Class name - This type cannot be added to the import statement because it references a type with the same name but from a different package - This type belongs to the java.lang package
    • removeImport

      O removeImport(String name)
      Remove any Import for the given fully-qualified class name, if it exists; otherwise, do nothing;
    • removeImport

      O removeImport(Class<?> type)
      Remove any Import for the given Class type, if it exists; otherwise, do nothing;
    • removeImport

      <T extends JavaType<?>> O removeImport(T type)
      Remove any Import for the given Importer type, if it exists; otherwise, do nothing;
    • removeImport

      O removeImport(Import imprt)
      Remove the given Import from this Importer instance, if it exists; otherwise, do nothing;