Interface Importer<O extends JavaSource<O>>
-
- All Known Subinterfaces:
EnumConstantSource.Body,JavaAnnotationSource,JavaClassSource,JavaEnumSource,JavaInterfaceSource,JavaPackageInfoSource,JavaSource<T>
public interface Importer<O extends JavaSource<O>>Defines the aspect ofJavaSourcethat handles type imports.- Author:
- Lincoln Baxter, III
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ImportaddImport(java.lang.Class<?> type)Add an import for the givenClasstype.ImportaddImport(java.lang.String className)Add an import by qualified class name.ImportaddImport(Import imprt)Add an import for the givenImporttype.ImportaddImport(Type<?> type)Ensures the type passed as argument is included in the list of imports for this java source.<T extends JavaType<?>>
ImportaddImport(T type)Add an import for the givenJavaTypetype.ImportgetImport(java.lang.Class<?> type)Get theImportfor the givenClasstype, if it exists; otherwise, return null;ImportgetImport(java.lang.String literalValue)Get theImportfor the given fully-qualified class name, if it exists; otherwise, return null;ImportgetImport(Import imprt)<T extends JavaType<?>>
ImportgetImport(T type)java.util.List<Import>getImports()booleanhasImport(java.lang.Class<?> type)Return whether or not thisImporterhas an import for the givenClasstype.booleanhasImport(java.lang.String type)Return whether or not thisImporterhas an import for the given fully-qualified class name.booleanhasImport(Import imprt)<T extends JavaType<T>>
booleanhasImport(T type)OremoveImport(java.lang.Class<?> type)Remove anyImportfor the givenClasstype, if it exists; otherwise, do nothing;OremoveImport(java.lang.String name)Remove anyImportfor the given fully-qualified class name, if it exists; otherwise, do nothing;OremoveImport(Import imprt)<T extends JavaType<?>>
OremoveImport(T type)booleanrequiresImport(java.lang.Class<?> type)Return whether or not thisImporterwould require an import to reference the givenClasstype.booleanrequiresImport(java.lang.String type)Return whether or not thisImporterwould require an import to reference the given fully-qualified class name.java.lang.StringresolveType(java.lang.String type)Given a simple or qualified type, resolve that type against the available imports and return the referenced type.
-
-
-
Method Detail
-
hasImport
boolean hasImport(java.lang.Class<?> type)
Return whether or not thisImporterhas an import for the givenClasstype.
-
hasImport
boolean hasImport(java.lang.String type)
Return whether or not thisImporterhas an import for the given fully-qualified class name.
-
requiresImport
boolean requiresImport(java.lang.Class<?> type)
Return whether or not thisImporterwould require an import to reference the givenClasstype.
-
requiresImport
boolean requiresImport(java.lang.String type)
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
<T extends JavaType<T>> boolean hasImport(T type)
-
hasImport
boolean hasImport(Import imprt)
-
getImport
Import getImport(java.lang.String literalValue)
Get theImportfor the given fully-qualified class name, if it exists; otherwise, return null;
-
getImport
Import getImport(java.lang.Class<?> type)
Get theImportfor the givenClasstype, if it exists; otherwise, return null;
-
getImports
java.util.List<Import> getImports()
-
resolveType
java.lang.String resolveType(java.lang.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:- 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
Import addImport(java.lang.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(java.lang.Class<?> type)
Add an import for the givenClasstype.
-
addImport
<T extends JavaType<?>> Import addImport(T type)
Add an import for the givenJavaTypetype.
-
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 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
O removeImport(java.lang.String name)
Remove anyImportfor the given fully-qualified class name, if it exists; otherwise, do nothing;
-
removeImport
O removeImport(java.lang.Class<?> type)
Remove anyImportfor the givenClasstype, if it exists; otherwise, do nothing;
-
-