Add "required_parameters" to Annotation params
Some annotations must have a set of parameters. To model this
requirements, the schema for annotations has "required_parameters" now.
For example, @Backing for enum types should have "type" parameter even
though the annotation itself is optional.
AidlAnnotation::CheckValid() checks if there's no missing required
parameters.
Bug: none
Test: aidl_unittests
Change-Id: I50d82a1576f62bfdc2f220b66b7475cf74198e53
diff --git a/aidl_language.cpp b/aidl_language.cpp
index ea6f5c2..256af2c 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -125,16 +125,19 @@
false},
{AidlAnnotation::Type::JAVA_STABLE_PARCELABLE, "JavaOnlyStableParcelable", {}, false},
{AidlAnnotation::Type::HIDE, "Hide", {}, false},
- {AidlAnnotation::Type::BACKING, "Backing", {{"type", "String"}}, false},
- {AidlAnnotation::Type::JAVA_PASSTHROUGH, "JavaPassthrough", {{"annotation", "String"}}, true},
+ {AidlAnnotation::Type::BACKING, "Backing", {{"type", "String"}}, false, {"type"}},
+ {AidlAnnotation::Type::JAVA_PASSTHROUGH,
+ "JavaPassthrough",
+ {{"annotation", "String"}},
+ true,
+ {"annotation"}},
{AidlAnnotation::Type::JAVA_DERIVE,
- "JavaDerive",
- {{"toString", "boolean"},
- {"equals", "boolean"}},
- false},
+ "JavaDerive",
+ {{"toString", "boolean"}, {"equals", "boolean"}},
+ false},
{AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE, "JavaOnlyImmutable", {}, false},
{AidlAnnotation::Type::FIXED_SIZE, "FixedSize", {}, false},
- {AidlAnnotation::Type::DESCRIPTOR, "Descriptor", {{"value", "String"}}, false},
+ {AidlAnnotation::Type::DESCRIPTOR, "Descriptor", {{"value", "String"}}, false, {"value"}},
{AidlAnnotation::Type::RUST_DERIVE,
"RustDerive",
{{"Copy", "boolean"},
@@ -241,7 +244,14 @@
return false;
}
}
- return true;
+ bool success = true;
+ for (const auto& param : schema_.required_parameters) {
+ if (parameters_.count(param) == 0) {
+ AIDL_ERROR(this) << "Missing '" << param << "' on @" << GetName() << ".";
+ success = false;
+ }
+ }
+ return success;
}
std::map<std::string, std::string> AidlAnnotation::AnnotationParams(