1 package org.springframework.roo.model; 2 3 import java.util.Set; 4 5 /** 6 * Represents the known imports for a particular compilation unit, and resolves whether a particular type 7 * name can be expressed as a simple type name or requires a fully-qualified type name. 8 * 9 * @author Ben Alex 10 * @since 1.0 11 * 12 */ 13 public interface ImportRegistrationResolver { 14 15 /** 16 * @return the package this compilation unit belongs to (never null) 17 */ 18 JavaPackage getCompilationUnitPackage(); 19 20 /** 21 * Determines whether the presented {@link JavaType} must be used in a fully-qualified form or not. 22 * It may only be used in simple form if: 23 * 24 * <ul> 25 * <li>it is of {@link DataType#VARIABLE}; or</li> 26 * <li>it is of {@link DataType#PRIMITIVE}; or</li> 27 * <li>it is already registered as an import; or</li> 28 * <li>it is in the same package as the compilation unit; or</li> 29 * <li>it is part of java.lang</li> 30 * </ul> 31 * 32 * <p> 33 * Note that advanced implementations may be able to determine all types available in a particular package, 34 * but this is not required. 35 * 36 * @param javaType to lookup (required) 37 * @return true if a fully-qualified form must be used, or false if a simple form can be used 38 */ 39 boolean isFullyQualifiedFormRequired(JavaType javaType); 40 41 /** 42 * Automatically invokes {@link #isAdditionLegal(JavaType)}, then {@link #addImport(JavaType)}, and 43 * finally {@link #isFullyQualifiedFormRequired(JavaType)}, returning the result of the final method. 44 * This method is the main method that should be used by callers, as it will automatically attempt to 45 * cause a {@link JavaType} to be used in its simple form if at all possible. 46 * 47 * @param javaType to automatically register (if possible) and lookup whether simplified used is available (required) 48 * @return true if a fully-qualified form must be used, or false if a simple form can be used 49 */ 50 boolean isFullyQualifiedFormRequiredAfterAutoImport(JavaType javaType); 51 52 /** 53 * Indicates whether the presented {@link JavaType} can be legally presented to {@link #addImport(JavaType)}. 54 * It is considered legal only if the presented {@link JavaType} is of type {@link DataType#TYPE}, 55 * there is not an existing conflicting registered import, and the proposed type is not within the default 56 * package. Note it is legal to add types from the same package as the compilation unit, and indeed may be 57 * required by implementations that are otherwise unaware of all the types available in a particular package. 58 * 59 * @param javaType 60 * @return 61 */ 62 boolean isAdditionLegal(JavaType javaType); 63 64 /** 65 * Explicitly registers an import. Note that no verification will be performed to ensure an import is legal or 66 * does not conflict with an existing import (use {@link #isAdditionLegal(JavaType)} for verification). 67 * 68 * @param javaType to register (required) 69 */ 70 void addImport(JavaType javaType); 71 72 /** 73 * Provides access to the registered imports. 74 * 75 * @return an unmodifiable representation of all registered imports (never null, but may be empty) 76 */ 77 Set<JavaType> getRegisteredImports(); 78 79 }