@param context is METHOD or FIELD
( int context, String name )
| 43 | @param context is METHOD or FIELD |
| 44 | */ |
| 45 | public void addModifier( int context, String name ) |
| 46 | { |
| 47 | if ( modifiers == null ) |
| 48 | modifiers = new Hashtable(); |
| 49 | |
| 50 | Object existing = modifiers.put( name, Void.TYPE/*arbitrary flag*/ ); |
| 51 | if ( existing != null ) |
| 52 | throw new IllegalStateException("Duplicate modifier: "+ name ); |
| 53 | |
| 54 | int count = 0; |
| 55 | if ( hasModifier("private") ) ++count; |
| 56 | if ( hasModifier("protected") ) ++count; |
| 57 | if ( hasModifier("public") ) ++count; |
| 58 | if ( count > 1 ) |
| 59 | throw new IllegalStateException( |
| 60 | "public/private/protected cannot be used in combination." ); |
| 61 | |
| 62 | switch( context ) |
| 63 | { |
| 64 | case CLASS: |
| 65 | validateForClass(); |
| 66 | break; |
| 67 | case METHOD: |
| 68 | validateForMethod(); |
| 69 | break; |
| 70 | case FIELD: |
| 71 | validateForField(); |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | public boolean hasModifier( String name ) |
| 77 | { |
no test coverage detected