Commit 7541b793 authored by Evan W. Patton's avatar Evan W. Patton Committed by Susan Rati Lane

Raise error when using boxed primitive types in component APIs (#1846)

* Raise error when using boxed primitive types in component APIs
* Make ComponentProcessor error messages private
parent c2a2ac18
......@@ -111,8 +111,10 @@ import javax.tools.StandardLocation;
public abstract class ComponentProcessor extends AbstractProcessor {
private static final String OUTPUT_PACKAGE = "";
public static final String MISSING_SIMPLE_PROPERTY_ANNOTATION =
private static final String MISSING_SIMPLE_PROPERTY_ANNOTATION =
"Designer property %s does not have a corresponding @SimpleProperty annotation.";
private static final String BOXED_TYPE_ERROR =
"Found use of boxed type %s. Please use the primitive type %s instead";
// Returned by getSupportedAnnotationTypes()
private static final Set<String> SUPPORTED_ANNOTATION_TYPES = ImmutableSet.of(
......@@ -148,6 +150,19 @@ public abstract class ComponentProcessor extends AbstractProcessor {
private static final String TYPE_PLACEHOLDER = "%type%";
private static final Map<String, String> BOXED_TYPES = new HashMap<>();
static {
BOXED_TYPES.put("java.lang.Boolean", "boolean");
BOXED_TYPES.put("java.lang.Byte", "byte");
BOXED_TYPES.put("java.lang.Char", "char");
BOXED_TYPES.put("java.lang.Short", "short");
BOXED_TYPES.put("java.lang.Integer", "int");
BOXED_TYPES.put("java.lang.Long", "long");
BOXED_TYPES.put("java.lang.Float", "float");
BOXED_TYPES.put("java.lang.Double", "double");
}
// The next two fields are set in init().
/**
* A handle allowing access to facilities provided by the annotation
......@@ -1603,6 +1618,10 @@ public abstract class ComponentProcessor extends AbstractProcessor {
* legal return values
*/
protected final String javaTypeToYailType(String type) {
if (BOXED_TYPES.containsKey(type)) {
throw new IllegalArgumentException(String.format(BOXED_TYPE_ERROR, type,
BOXED_TYPES.get(type)));
}
// boolean -> boolean
if (type.equals("boolean")) {
return type;
......@@ -1643,8 +1662,7 @@ public abstract class ComponentProcessor extends AbstractProcessor {
return "component";
}
throw new RuntimeException("Cannot convert Java type '" + type +
"' to Yail type");
throw new IllegalArgumentException("Cannot convert Java type '" + type + "' to Yail type");
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment