protected AptControlInterface initControlInterface ( ) { TypeMirror controlType = _fieldDecl . getType ( ) ; if ( ! ( controlType instanceof DeclaredType ) ) { _ap . printError ( _fieldDecl , "control.field.bad.type" ) ; return null ; } // // The field can either be declared as the bean type or the public interface type. // If it is the bean type, then we need to reflect to find the public interface // type it implements. // TypeDeclaration typeDecl = ( ( DeclaredType ) controlType ) . getDeclaration ( ) ; InterfaceDeclaration controlIntf = null ; // // It is possible that the declared type is associated with a to-be-generated // bean type. In this case, look for the associated control interface on the // processor input list. // if ( typeDecl == null ) { String className = controlType . toString ( ) ; String intfName = className . substring ( 0 , className . length ( ) - 4 ) ; String interfaceHint = getControlInterfaceHint ( ) ; controlIntf = ( InterfaceDeclaration ) _ap . getAnnotationProcessorEnvironment ( ) . getTypeDeclaration ( intfName ) ; if ( controlIntf == null ) { // The specified class name may not be fully qualified. In this case, the // best we can do is look for a best fit match against the input types for ( TypeDeclaration td : _ap . getAnnotationProcessorEnvironment ( ) . getSpecifiedTypeDeclarations ( ) ) { // if an interface hint was provided, use it to find the control interface, // if not provided try to find the control interface by matching simple names. if ( interfaceHint != null ) { if ( td instanceof InterfaceDeclaration && td . getQualifiedName ( ) . equals ( interfaceHint ) ) { controlIntf = ( InterfaceDeclaration ) td ; break ; } } else { if ( td instanceof InterfaceDeclaration && td . getSimpleName ( ) . equals ( intfName ) ) { controlIntf = ( InterfaceDeclaration ) td ; break ; } } } } } else if ( typeDecl instanceof ClassDeclaration ) { Collection < InterfaceType > implIntfs = ( ( ClassDeclaration ) typeDecl ) . getSuperinterfaces ( ) ; for ( InterfaceType intfType : implIntfs ) { InterfaceDeclaration intfDecl = intfType . getDeclaration ( ) ; if ( intfDecl == null ) return null ; if ( intfDecl . getAnnotation ( ControlInterface . class ) != null || intfDecl . getAnnotation ( ControlExtension . class ) != null ) { controlIntf = intfDecl ; break ; } } } else if ( typeDecl instanceof InterfaceDeclaration ) { controlIntf = ( InterfaceDeclaration ) typeDecl ; } if ( controlIntf == null ) { _ap . printError ( _fieldDecl , "control.field.bad.type.2" ) ; return null ; } return new AptControlInterface ( controlIntf , _ap ) ; }
Initializes the ControlInterface associated with this ControlField