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 Summary
Modifier and TypeMethodDescriptionAdd an import for the givenClasstype.Add an import by qualified class name.Add an import for the givenImporttype.Ensures the type passed as argument is included in the list of imports for this java source.addImport(T type) Add an import for the givenJavaTypetype.Get theImportfor the given fully-qualified class name, if it exists; otherwise, return null;getImport(T type) booleanbooleanReturn whether or not thisImporterhas an import for the given fully-qualified class name.boolean<T extends JavaType<T>>
booleanhasImport(T type) removeImport(Class<?> type) removeImport(String name) Remove anyImportfor the given fully-qualified class name, if it exists; otherwise, do nothing;removeImport(Import imprt) removeImport(T type) booleanrequiresImport(Class<?> type) booleanrequiresImport(String type) Return whether or not thisImporterwould require an import to reference the given fully-qualified class name.resolveType(String type) Given a simple or qualified type, resolve that type against the available imports and return the referenced type.
-
Method Details
-
hasImport
-
hasImport
Return whether or not thisImporterhas an import for the given fully-qualified class name. -
requiresImport
-
requiresImport
Return whether or not thisImporterwould 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
-
hasImport
-
getImport
Get theImportfor the given fully-qualified class name, if it exists; otherwise, return null; -
getImport
-
getImport
-
getImport
-
getImports
-
resolveType
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:- If the type is primitive or full qualified, the type is returned as it
- Find the type in the imports with the simple name
- If only one wildcard import is used, use this import for resolving
- Use the available
WildcardImportResolver. The first qualified name is used - The current package if defined is used for resolving
- The type is returned as it
- Parameters:
type- the type to resolve- Returns:
- the (resolved) type
-
addImport
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
Add an import for the givenClasstype. -
addImport
Add an import for the givenImporttype. -
addImport
Add an import for the givenJavaTypetype. -
addImport
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 anImportobject 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- TheTypeto 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
Remove anyImportfor the given fully-qualified class name, if it exists; otherwise, do nothing; -
removeImport
-
removeImport
-
removeImport
-