Skip to content

Commit

Permalink
Add getParameterValues(boolean includeDefaultValues) (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehutch committed Jul 6, 2021
1 parent 8745bea commit fad9f4b
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/main/java/io/github/classgraph/AnnotationInfo.java
Expand Up @@ -114,24 +114,28 @@ public AnnotationParameterValueList getDefaultParameterValues() {
/**
* Get the parameter values.
*
* @param includeDefaultValues
* if true, include default values for any annotation parameter value that is missing.
* @return The parameter values of this annotation, including any default parameter values inherited from the
* annotation class definition, or the empty list if none.
* annotation class definition (if requested), or the empty list if none.
*/
public AnnotationParameterValueList getParameterValues() {
public AnnotationParameterValueList getParameterValues(boolean includeDefaultValues) {
final ClassInfo classInfo = getClassInfo();
if (classInfo == null) {
// ClassInfo has not yet been set, just return values without defaults
// (happens when trying to log AnnotationInfo during scanning, before ScanResult is available)
return annotationParamValues == null ? AnnotationParameterValueList.EMPTY_LIST : annotationParamValues;
}
// Lazily convert any Object[] arrays of boxed types to primitive arrays
if (annotationParamValues != null && !annotationParamValuesHasBeenConvertedToPrimitive) {
annotationParamValues.convertWrapperArraysToPrimitiveArrays(classInfo);
annotationParamValuesHasBeenConvertedToPrimitive = true;
}
if (!includeDefaultValues) {
// Don't include defaults
return annotationParamValues == null ? AnnotationParameterValueList.EMPTY_LIST : annotationParamValues;
}
if (annotationParamValuesWithDefaults == null) {
final ClassInfo classInfo = getClassInfo();
if (classInfo == null) {
// ClassInfo has not yet been set, just return values without defaults
// (happens when trying to log AnnotationInfo during scanning, before ScanResult is available)
return annotationParamValues == null ? AnnotationParameterValueList.EMPTY_LIST
: annotationParamValues;
}

// Lazily convert any Object[] arrays of boxed types to primitive arrays
if (annotationParamValues != null && !annotationParamValuesHasBeenConvertedToPrimitive) {
annotationParamValues.convertWrapperArraysToPrimitiveArrays(classInfo);
annotationParamValuesHasBeenConvertedToPrimitive = true;
}
if (classInfo.annotationDefaultParamValues != null
&& !classInfo.annotationDefaultParamValuesHasBeenConvertedToPrimitive) {
classInfo.annotationDefaultParamValues.convertWrapperArraysToPrimitiveArrays(classInfo);
Expand Down Expand Up @@ -193,6 +197,16 @@ public AnnotationParameterValueList getParameterValues() {
return annotationParamValuesWithDefaults;
}

/**
* Get the parameter values.
*
* @return The parameter values of this annotation, including any default parameter values inherited from the
* annotation class definition, or the empty list if none.
*/
public AnnotationParameterValueList getParameterValues() {
return getParameterValues(true);
}

// -------------------------------------------------------------------------------------------------------------

/**
Expand Down

0 comments on commit fad9f4b

Please sign in to comment.