void checkForSetter ( Map < Integer , Instruction > pcMap ) throws ClassParseException { final String methodName = getMethod ( ) . getName ( ) ; if ( methodName . startsWith ( "set" ) ) { final String rawVarNameCandidate = methodName . substring ( 3 ) ; final String firstLetter = rawVarNameCandidate . substring ( 0 , 1 ) . toLowerCase ( ) ; final String varNameCandidateCamelCased = rawVarNameCandidate . replaceFirst ( rawVarNameCandidate . substring ( 0 , 1 ) , firstLetter ) ; String accessedFieldName = null ; final Instruction instruction = expressionList . getHead ( ) ; // setters should be aload_0, ?load_1, putfield, return if ( ( instruction instanceof AssignToInstanceField ) && ( expressionList . getTail ( ) instanceof Return ) && ( pcMap . size ( ) == 4 ) ) { final Instruction prev = instruction . getPrevPC ( ) ; if ( prev instanceof AccessLocalVariable ) { final FieldEntry field = ( ( AssignToInstanceField ) instruction ) . getConstantPoolFieldEntry ( ) ; accessedFieldName = field . getNameAndTypeEntry ( ) . getNameUTF8Entry ( ) . getUTF8 ( ) ; if ( accessedFieldName . equals ( varNameCandidateCamelCased ) ) { // Verify field type matches setter arg type final String fieldType = field . getNameAndTypeEntry ( ) . getDescriptorUTF8Entry ( ) . getUTF8 ( ) ; final String setterArgType = getMethod ( ) . getDescriptor ( ) . substring ( 1 , 2 ) ; //System.out.println( "### field type = " + fieldType ); //System.out.println( "### setter type = " + setterArgType ); assert fieldType . length ( ) == 1 : " can only use basic type getters" ; if ( fieldType . equals ( setterArgType ) ) { if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "Found " + methodName + " as a setter for " + varNameCandidateCamelCased . toLowerCase ( ) + " of type " + fieldType ) ; } methodIsSetter = true ; setAccessorVariableFieldEntry ( field ) ; // Setters use putfield which will miss the normal store check if ( fieldType . equals ( "B" ) || fieldType . equals ( "Z" ) ) { usesByteWrites = true ; } assert methodIsGetter == false : " cannot be both" ; } else { throw new ClassParseException ( ClassParseException . TYPE . BADSETTERTYPEMISMATCH , methodName ) ; } } else { throw new ClassParseException ( ClassParseException . TYPE . BADSETTERTYPEMISMATCH , methodName ) ; } } } } }
Determine if this method is a setter and record the accessed field if so