private void enforceVersionRequired ( FieldDeclaration f , InterfaceDeclaration controlIntf ) { VersionRequired versionRequired = f . getAnnotation ( VersionRequired . class ) ; Version versionPresent = controlIntf . getAnnotation ( Version . class ) ; if ( versionRequired != null ) { int majorRequired = - 1 ; try { majorRequired = versionRequired . major ( ) ; } catch ( NullPointerException ignore ) { /* the major version annotation is required and if unspecified, will throw an NPE when it is quereid but not provided. this error will be caught during syntactic validation perfoemed by javac, so ignore it if an NPE is caught here */ return ; } int minorRequired = versionRequired . minor ( ) ; /* no version requirement, so return */ if ( majorRequired < 0 ) return ; int majorPresent = - 1 ; int minorPresent = - 1 ; if ( versionPresent != null ) { try { majorPresent = versionPresent . major ( ) ; } catch ( NullPointerException ignore ) { /* the major version annotation is required and if unspecified, will throw an NPE when it is quereid but not provided. this error will be caught during syntactic validation perfoemed by javac, so ignore it if an NPE is caught here */ } minorPresent = versionPresent . minor ( ) ; if ( majorRequired <= majorPresent && ( minorRequired < 0 || minorRequired <= minorPresent ) ) { // Version requirement is satisfied return ; } } // // Version requirement failed // printError ( f , "control.field.bad.version" , f . getSimpleName ( ) , majorRequired , minorRequired , majorPresent , minorPresent ) ; } }
Enforces the VersionRequired annotation for control fields .