do
var project = new AndroidProject
- var annot = priority_annotation_on_modules("app_name", mmodule)
+ var annot = lookup_annotation_on_modules("app_name", mmodule)
if annot != null then project.name = annot.arg_as_string(self)
- annot = priority_annotation_on_modules("app_version", mmodule)
+ annot = lookup_annotation_on_modules("app_version", mmodule)
if annot != null then project.version = annot.as_version(self)
- annot = priority_annotation_on_modules("java_package", mmodule)
+ annot = lookup_annotation_on_modules("java_package", mmodule)
if annot != null then project.java_package = annot.arg_as_string(self)
var annots = collect_annotations_on_modules("min_api_version", mmodule)
- for an in annots do project.min_api = an.arg_as_int(self)
+ if not annots.is_empty then
+ var i = annots.pop.arg_as_int(self)
+ if i == null then i = 0
+ project.min_api = i
+ for an in annots do
+ i = an.arg_as_int(self)
+ if i == null then continue
+ project.min_api = project.min_api.max(i)
+ end
+ end
annots = collect_annotations_on_modules("max_api_version", mmodule)
- for an in annots do project.max_api = an.arg_as_int(self)
+ if not annots.is_empty then
+ var i = annots.pop.arg_as_int(self)
+ if i == null then i = 0
+ project.max_api = i
+ for an in annots do
+ i = an.arg_as_int(self)
+ if i == null then continue
+ project.max_api = project.max_api.min(i)
+ end
+ end
- annots = collect_annotations_on_modules("target_api_version", mmodule)
- for an in annots do project.target_api = an.arg_as_int(self)
+ annot = lookup_annotation_on_modules("target_api_version", mmodule)
+ if annot != null then project.target_api = annot.arg_as_int(self) or else 0
annots = collect_annotations_on_modules("android_manifest", mmodule)
for an in annots do project.manifest_lines.add an.arg_as_string(self) or else ""
return project
end
-
- # Recursively collect all annotations by name in `mmodule` and its importations (direct and indirect)
- private fun collect_annotations_on_modules(name: String, mmodule: MModule): Array[AAnnotation]
- do
- var annotations = new Array[AAnnotation]
- for mmod in mmodule.in_importation.greaters do
- if not mmodule2nmodule.keys.has(mmod) then continue
- var amod = mmodule2nmodule[mmod]
- var module_decl = amod.n_moduledecl
- if module_decl == null then continue
- var aas = module_decl.collect_annotations_by_name(name)
- annotations.add_all aas
- end
- return annotations
- end
-
- # Get an annotation by name from `mmodule` and its super modules. Will recursively search
- # in imported module to find the "latest" declaration and detects priority conflicts.
- private fun priority_annotation_on_modules(name: String, mmodule: MModule): nullable AAnnotation
- do
- if mmodule2nmodule.keys.has(mmodule) then
- var amod = mmodule2nmodule[mmodule]
- var module_decl = amod.n_moduledecl
- if module_decl != null then
- var annotations = module_decl.collect_annotations_by_name(name)
- if annotations.length == 1 then
- return annotations.first
- else if annotations.length > 1 then
- toolcontext.error(mmodule.location,
- "Multiple declaration of annotation {name}, it must be defined only once.")
- end
- end
- end
-
- var sources = new Array[MModule]
- var annotations = null
- for mmod in mmodule.in_importation.direct_greaters do
- var res = priority_annotation_on_modules(name, mmod)
- if res != null then
- sources.add mmod
- annotations = res
- end
- end
- if sources.length > 1 then
- toolcontext.error(mmodule.location,
- "Priority conflict on annotation {name}, it has been defined in: {sources.join(", ")}")
- return null
- end
- return annotations
- end
end
redef class AAnnotation