@@ -553,6 +553,45 @@ public static EnumSet<ElementKind> getElementKindsForElementType(ElementType ele
553553 // Annotation values: inefficient extractors that take an element name
554554 // **********************************************************************
555555
556+ /**
557+ * Get the element with the name {@code elementName} of the annotation {@code anno}. The result
558+ * has type {@code expectedType}. If there is no value for {@code elementName}, {@code
559+ * defaultValue} is returned
560+ *
561+ * <p>This method is intended only for use when the class of the annotation is not on the user's
562+ * classpath. This is for users of the Dataflow Framework that do not use the rest of the Checker
563+ * Framework. Type-checkers can assume that checker-qual.jar is on the classpath and should use
564+ * {@link #getElementValue(AnnotationMirror, ExecutableElement, Class)} or {@link
565+ * #getElementValue(AnnotationMirror, ExecutableElement, Class, Object)}.
566+ *
567+ * @param anno the annotation whose element to access
568+ * @param elementName the name of the element to access
569+ * @param expectedType the type of the element and the return value
570+ * @param defaultValue the value to return if the element is not present
571+ * @param <T> the class of the type
572+ * @return the value of the element with the given name
573+ */
574+ public static <T > T getElementValueNotOnClasspath (
575+ AnnotationMirror anno , CharSequence elementName , Class <T > expectedType , T defaultValue ) {
576+ Map <? extends ExecutableElement , ? extends AnnotationValue > valmap = anno .getElementValues ();
577+
578+ for (Map .Entry <? extends ExecutableElement , ? extends AnnotationValue > entry :
579+ valmap .entrySet ()) {
580+ ExecutableElement elem = entry .getKey ();
581+ if (elem .getSimpleName ().contentEquals (elementName )) {
582+ AnnotationValue val = entry .getValue ();
583+ try {
584+ return expectedType .cast (val .getValue ());
585+ } catch (ClassCastException e ) {
586+ throw new BugInCF (
587+ "getElementValueNotOnClasspath(%s, %s, %s): val=%s, val.getValue()=%s [%s]" ,
588+ anno , elementName , expectedType , val , val .getValue (), val .getValue ().getClass ());
589+ }
590+ }
591+ }
592+ return defaultValue ;
593+ }
594+
556595 /**
557596 * Returns the values of an annotation's elements, including defaults. The method with the same
558597 * name in JavacElements cannot be used directly, because it includes a cast to
@@ -604,7 +643,7 @@ public static EnumSet<ElementKind> getElementKindsForElementType(ElementType ele
604643 * @deprecated use {@link #getElementValue(AnnotationMirror, ExecutableElement, Class)} or {@link
605644 * #getElementValue(AnnotationMirror, ExecutableElement, Class, Object)}
606645 */
607- @ Deprecated // for use only by the framework
646+ @ Deprecated // for use only by the framework, not by clients
608647 public static <T > T getElementValue (
609648 AnnotationMirror anno , CharSequence elementName , Class <T > expectedType , boolean useDefaults ) {
610649 Map <? extends ExecutableElement , ? extends AnnotationValue > valmap ;
0 commit comments