Class ImportManager
java.lang.Object
org.inferred.freebuilder.processor.source.ImportManager
Adds imports and applies scope visibility rules to a compilation unit.
To ensure we never import common names like 'Builder', nested classes must have at least one non-lowercase letter (apart from the first) in their name.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final QualifiedNameImpossible typename, to use instead of null (which toMap goes odd over).private final com.google.common.collect.Multimap<QualifiedName, TypeUsage> Types to import, and for which usages.private final Map<String, QualifiedName> Simple name → type, orCONFLICTif multiple types conflicted for that name.private final Stringprivate final Map<TypeUsage, QualifiedName> Which type, imported or in scope, to use to shorten each type usage.private final ScopeHandlerType usages to process. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateImportManager(List<TypeUsage> usages, ScopeHandler scopeHandler, String pkg) -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanaddImport(QualifiedName name, TypeUsage usage) private voidappendImports(StringBuilder result) private voidappendUsage(StringBuilder result, TypeUsage usage) private static booleanprivate voidrejectName(QualifiedName name) private booleanreserveName(QualifiedName name) private voidresolveUsage(TypeUsage usage) private void(package private) static StringshortenReferences(CharSequence codeWithQualifiedNames, String pkg, int importsIndex, List<TypeUsage> typeUsages, ScopeHandler scopeHandler) private Function<QualifiedName, ScopeHandler.ScopeState> visibilityIn(ScopeHandler scopeHandler, TypeUsage usage)
-
Field Details
-
CONFLICT
Impossible typename, to use instead of null (which toMap goes odd over). -
todo
-
namespace
Simple name → type, orCONFLICTif multiple types conflicted for that name. -
imports
Types to import, and for which usages. -
resolutions
Which type, imported or in scope, to use to shorten each type usage. -
scopeHandler
-
pkg
-
-
Constructor Details
-
ImportManager
-
-
Method Details
-
shortenReferences
static String shortenReferences(CharSequence codeWithQualifiedNames, String pkg, int importsIndex, List<TypeUsage> typeUsages, ScopeHandler scopeHandler) -
selectImports
private void selectImports() -
appendImports
-
appendUsage
-
reserveName
-
rejectName
-
addImport
-
resolveUsage
-
visibilityIn
private Function<QualifiedName, ScopeHandler.ScopeState> visibilityIn(ScopeHandler scopeHandler, TypeUsage usage) -
isSensibleImport
-