Allow extension option list enums to not have fromUnderlyingValue method
@@ -78,6 +78,7 @@ import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
+import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.ArrayType;
@@ -2026,7 +2027,7 @@ public abstract class ComponentProcessor extends AbstractProcessor {
/**
* Returns the OptionList HelperKey associated with the given element.
- * @param element the Element describing a class which implements the OptionList interface.
+ * @param optionList the Element describing a class which implements the OptionList interface.
* @return the HelperKey associated with the given element.
*/
private HelperKey optionListToHelperKey(Element optionList) {
@@ -2071,7 +2072,11 @@ public abstract class ComponentProcessor extends AbstractProcessor {
+ "method.");
}
- // Get the fromUnderlyingValue method. This is not used, we just need to require it.
+ // Get the "fromUnderlyingValue" static method if this class falls under the "com.google.appinventor.components"
+ // package. We don't use this method here, but we require the built-in helpers to have it for providing backward
+ // compatibility.
+ final PackageElement packageElem = processingEnv.getElementUtils().getPackageOf(optionElem);
+ if (packageElem.getQualifiedName().toString().startsWith("com.google.appinventor.components.")) {
java.lang.reflect.Method fromValueMethod;
Type genericType = null;
try {
@@ -2087,6 +2092,7 @@ public abstract class ComponentProcessor extends AbstractProcessor {
throw new IllegalArgumentException("Class: " + className + " must have a static "
+ "fromUnderlyingValue(" + genericType.getTypeName() + ") method.");
}
+ }
// Create a map of enum const names -> values. This is used to filter the below elements
// returned by getEnclosedElements().
