nitc $ JavaExtraFilesPhase :: SELF
Type of this instance, automatically specialized in every classnitc $ JavaExtraFilesPhase :: process_annotated_node
Specific actions to execute on annotated nodesnitc :: Phase :: _in_hierarchy
The dependence relation of the phase with the other phasesnitc :: Phase :: _toolcontext
The toolcontext instance attached to the phasecore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: Phase :: defaultinit
core :: Object :: defaultinit
nitc :: Phase :: in_hierarchy
The dependence relation of the phase with the other phasesnitc :: Phase :: in_hierarchy=
The dependence relation of the phase with the other phasescore :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: Phase :: process_annotated_node
Specific actions to execute on annotated nodesnitc :: Phase :: process_mainmodule
Specific action to execute on the whole program.nitc :: Phase :: process_nclassdef
Specific actions to execute on the tree of a class definitionnitc :: Phase :: process_nmodule
Specific actions to execute on the whole tree of a modulenitc :: Phase :: process_nmodule_after
Specific actions to execute on the whole tree of a modulenitc :: Phase :: process_npropdef
Specific actions to execute on the tree of a propertynitc :: Phase :: toolcontext
The toolcontext instance attached to the phasenitc :: Phase :: toolcontext=
The toolcontext instance attached to the phase
private class JavaExtraFilesPhase
super Phase
redef fun process_annotated_node(nmoduledecl, nat)
do
# Skip if we are not interested
var annot_name = "extra_java_files"
if nat.name != annot_name then return
# Do some validity checks and print errors if the annotation is used incorrectly
var modelbuilder = toolcontext.modelbuilder
if not nmoduledecl isa AModuledecl then
modelbuilder.error(nat, "Syntax Error: only the declaration of modules may use `{annot_name}`.")
return
end
var args = nat.n_args
if args.is_empty then
modelbuilder.error(nat, "Syntax Error: `{annot_name}` expects at least one argument.")
return
end
# retrieve module
var nmodule = nmoduledecl.parent.as(AModule)
var mmodule = nmodule.mmodule.as(not null)
var java_files = mmodule.extra_java_files
if java_files == null then
java_files = new Array[ExtraJavaFile]
mmodule.extra_java_files = java_files
end
var format_error = "Syntax Error: `{annot_name}` expects its arguments to be paths to java files."
for arg in args do
var name = arg.as_string
if name == null or name.is_empty then
modelbuilder.error(arg, format_error)
return
end
var path = name.split(".").last + ".java"
# Append specified path to directory of the Nit source file
var source_file = nat.location.file
if source_file != null then path = "{source_file.filename.dirname}/{path}"
if not path.file_exists then
modelbuilder.error(nat, "FFI with Java Error: file `{path}` not found.")
continue
end
var file = new ExtraJavaFile(name, path)
mmodule.ffi_files.add file
java_files.add file
end
end
end
src/ffi/extra_java_files.nit:35,1--91,3