public static boolean isGetterMethod ( ClassContext classContext , Method method ) { MethodGen methodGen = classContext . getMethodGen ( method ) ; if ( methodGen == null ) { return false ; } InstructionList il = methodGen . getInstructionList ( ) ; // System.out.println("Checking getter method: " + method.getName()); if ( il . getLength ( ) > 60 ) { return false ; } int count = 0 ; Iterator < InstructionHandle > it = il . iterator ( ) ; while ( it . hasNext ( ) ) { InstructionHandle ih = it . next ( ) ; switch ( ih . getInstruction ( ) . getOpcode ( ) ) { case Const . GETFIELD : count ++ ; if ( count > 1 ) { return false ; } break ; case Const . PUTFIELD : case Const . BALOAD : case Const . CALOAD : case Const . DALOAD : case Const . FALOAD : case Const . IALOAD : case Const . LALOAD : case Const . SALOAD : case Const . AALOAD : case Const . BASTORE : case Const . CASTORE : case Const . DASTORE : case Const . FASTORE : case Const . IASTORE : case Const . LASTORE : case Const . SASTORE : case Const . AASTORE : case Const . PUTSTATIC : return false ; case Const . INVOKESTATIC : case Const . INVOKEVIRTUAL : case Const . INVOKEINTERFACE : case Const . INVOKESPECIAL : case Const . GETSTATIC : // no-op } } // System.out.println("Found getter method: " + method.getName()); return true ; }
Determine whether or not the the given method is a getter method . I . e . if it just returns the value of an instance field .