private VariableElement getVariableElement ( Element holder , Configuration config , DocTree tag ) { Utils utils = config . utils ; CommentHelper ch = utils . getCommentHelper ( holder ) ; String signature = ch . getReferencedSignature ( tag ) ; if ( signature == null ) { // no reference //Base case: no label. if ( utils . isVariableElement ( holder ) ) { return ( VariableElement ) ( holder ) ; } else { // If the value tag does not specify a parameter which is a valid field and // it is not used within the comments of a valid field, return null. return null ; } } String [ ] sigValues = signature . split ( "#" ) ; String memberName = null ; TypeElement te = null ; if ( sigValues . length == 1 ) { //Case 2: @value in same class. if ( utils . isExecutableElement ( holder ) || utils . isVariableElement ( holder ) ) { te = utils . getEnclosingTypeElement ( holder ) ; } else if ( utils . isTypeElement ( holder ) ) { te = utils . getTopMostContainingTypeElement ( holder ) ; } memberName = sigValues [ 0 ] ; } else { //Case 3: @value in different class. Elements elements = config . docEnv . getElementUtils ( ) ; te = elements . getTypeElement ( sigValues [ 0 ] ) ; memberName = sigValues [ 1 ] ; } if ( te == null ) { return null ; } for ( Element field : utils . getFields ( te ) ) { if ( utils . getSimpleName ( field ) . equals ( memberName ) ) { return ( VariableElement ) field ; } } return null ; }
Given the name of the field return the corresponding VariableElement . Return null due to invalid use of value tag if the name is null or empty string and if the value tag is not used on a field .