--- /dev/null
+
+
+using Valadoc.Html;
+using Valadoc;
+using Gee;
+
+public class Valadoc.Html.Api.Vala {
+ private Attribute csskeyword = new Attribute ("class", "apikeyword");
+ private Attribute cssformalparam = new Attribute ("class", "apiformalparameter");
+ private Attribute cssparamlist = new Attribute ("class", "apiparameterlist");
+ private Attribute cssexclist = new Attribute ("class", "apiexceptionlist");
+ private Attribute cssapi = new Attribute ("class", "api");
+ private Attribute csstype = new Attribute ("class", "apitype");
+ private Attribute cssbasictype = new Attribute ("class", "apibasictype");
+ private Attribute csslink = new Attribute ("class", "apilink");
+ private Attribute cssoptparamlist = new Attribute ("class", "apioptparameterlist");
+
+
+ private Entry keyword (string str) {
+ Span span = new Span ();
+ span.add_attribute (this.csskeyword);
+ span.add_child (new String(str));
+ return span;
+ }
+
+ private Entry type (Basic? type, out bool documentedelement) {
+ ArrayList<Entry> elements = new ArrayList<Entry> ();
+ weak Attribute css = this.csstype;
+ documentedelement = false;
+
+ while (true) {
+ if (type == null) {
+ elements.insert (0, this.keyword("void"));
+ break;
+ }
+ else if (type is Pointer) {
+ elements.add (new String("*"));
+ type = ((Pointer)type).data_type;
+ }
+ else if (type is Array) {
+ //TODO: multidim. arrays
+ elements.add (new String("[]"));
+ type = ((Array)type).data_type;
+ }
+ else if (type is TypeParameter) {
+ elements.insert (0, new String (((TypeParameter)type).name));
+ break;
+ }
+ else if (type is DocumentedElement) {
+ weak DocumentedElement dtype = (DocumentedElement)type;
+ if (dtype.package.name == "glib-2.0" && dtype.nspace.name == null && (dtype is Struct || dtype is Class)) {
+ css = this.cssbasictype;
+ }
+
+ Link link = new Link ("/%s/%s.html".printf (dtype.package.name, dtype.full_name ()), new String (dtype.name));
+ link.add_attribute (csslink);
+ elements.insert (0, link);
+ documentedelement = true;
+ break;
+ }
+ else { // typereference
+ // prepend:
+ ArrayList<Entry> lst = this.type_reference (((TypeReference)type));
+ foreach (Entry e in elements) {
+ lst.add (e);
+ }
+ elements = lst;
+ break;
+ }
+ }
+
+ Span span = new Span.from_list (elements);
+ span.add_attribute (css);
+ return span;
+ }
+
+ private ArrayList<Entry>? type_parameter_list (TemplateParameterListHandler tplh) {
+ Collection<TypeParameter> tpllist = tplh.get_template_param_list ();
+ if (tpllist.size == 0) {
+ return null;
+ }
+
+ ArrayList<Entry> cnt = new ArrayList<Entry> ();
+ int i = 0;
+
+ cnt.add (new String ("<"));
+
+ foreach (TypeParameter tpl in tpllist ) {
+ Span span = new Span ();
+ span.add_child (new String (tpl.name));
+ span.add_attribute (this.csstype);
+ cnt.add (span);
+
+ if (++i != tpllist.size) {
+ cnt.add (new String (", "));
+ }
+ }
+
+ cnt.add (new String (">"));
+ return cnt;
+ }
+
+ private ArrayList<Entry> type_reference (TypeReference typeref) {
+ ArrayList<Entry> list = new ArrayList<Entry> ();
+ bool documentedelement;
+
+ StringBuilder str = new StringBuilder ();
+ //if(typeref.pass_ownership) {
+ //}
+
+ if(typeref.is_dynamic) {
+ str.append ("dynamic ");
+ }
+
+ if(typeref.is_owned) {
+ str.append ("owned ");
+ }
+
+ if(typeref.is_unowned) {
+ str.append ("unowned ");
+ }
+
+ if(typeref.is_weak) {
+ str.append ("weak ");
+ }
+
+ if (str.len > 0) {
+ list.add (this.keyword (str.str));
+ }
+
+ list.add (this.type (typeref.data_type, out documentedelement));
+
+ Collection<TypeReference> typeargs = typeref.get_type_arguments ();
+ if (typeargs.size != 0) {
+ list.add (new String ("<"));
+ int i = 0;
+
+ foreach (TypeReference tref in typeargs) {
+ foreach (Entry e in this.type_reference (tref)) {
+ list.add (e);
+ }
+
+ if (++i != typeargs.size) {
+ list.add (new String (", "));
+ }
+ }
+
+ list.add (new String (">"));
+ }
+
+ if(typeref.is_nullable && documentedelement) {
+ list.add(new String("?"));
+ }
+
+ return list;
+ }
+
+ private Entry formal_parameter (FormalParameter param) {
+ Span span = new Span ();
+ span.add_attribute (this.cssformalparam);
+
+ if (param.ellipsis) {
+ span.add_child (new String ("..."));
+ return span;
+ }
+ else {
+ if (param.is_out) {
+ span.add_child (this.keyword("out "));
+ }
+ else if (param.is_ref) {
+ span.add_child (this.keyword("ref "));
+ }
+
+ span.add_childs (this.type_reference(param.type_reference));
+ span.add_child (new String(" "+param.name));
+ return span;
+ }
+ }
+
+ private Entry parameter_list (ParameterListHandler paramh) {
+ Span rspan = new Span ();
+ Span span = rspan;
+
+ span.add_attribute (cssparamlist);
+
+ span.add_child (new String("("));
+ bool default_value = false;
+ int i = 0;
+
+ foreach (FormalParameter param in paramh.param_list) {
+ if (param.has_default_value) {
+ default_value = true;
+
+ span = new Span ();
+ span.add_attribute (this.cssoptparamlist);
+ span.add_child (new String("["));
+ rspan.add_child (span);
+ }
+
+ span.add_child (this.formal_parameter(param));
+ if (++i != paramh.param_list.size) {
+ span.add_child (new String (", "));
+ }
+ }
+
+ if (default_value) {
+ span.add_child (new String("]"));
+ span = rspan;
+ }
+
+ span.add_child (new String(")"));
+ return rspan;
+ }
+
+ private string symbol_accessibility (SymbolAccessibility symbol) {
+ if (symbol.is_public) {
+ return "public";
+ }
+ else if (symbol.is_protected) {
+ return "protected ";
+ }
+ else {
+ return "private ";
+ }
+ }
+
+ private Entry exception (DocumentedElement element) {
+ Span span = new Span();
+ span.add_child (new String (element.full_name()));
+ return span;
+ }
+
+ private Entry? exceptions (ExceptionHandler exh) {
+ Collection<DocumentedElement> errs = exh.get_error_domains ();
+ if (errs.size == 0) {
+ return null;
+ }
+
+ Span span = new Span ();
+ span.add_attribute (cssexclist);
+
+ span.add_child (this.keyword(" throws "));
+
+ foreach (DocumentedElement type in errs) {
+ span.add_child (this.exception(type));
+ }
+
+ return span;
+ }
+
+ public Div from_method (Method m) {
+ Div api = new Div ();
+ api.add_attribute (cssapi);
+
+ StringBuilder str = new StringBuilder (this.symbol_accessibility (m));
+ str.append_c (' ');
+
+ if ( m.is_abstract ) {
+ str.append ("abstract ");
+ }
+ else if ( m.is_virtual ) {
+ str.append ("virtual ");
+ }
+ else if ( m.is_override ) {
+ str.append ("override ");
+ }
+
+ if ( m.is_static ) {
+ str.append ("static ");
+ }
+
+ if ( m.is_inline ) {
+ str.append ("inline ");
+ }
+
+ api.add_child (this.keyword(str.str));
+ str = null;
+
+
+ // return type:
+ if (m.is_constructor == false) {
+ Collection<Entry> lst = this.type_reference (m.type_reference);
+ api.add_childs (lst);
+ }
+
+ api.add_child (new String (" "+m.name));
+
+
+ Collection<Entry> lst = this.type_parameter_list ((m.is_constructor)? (TemplateParameterListHandler)m.parent: m);
+ if (lst != null) {
+ api.add_childs (lst);
+ }
+
+ api.add_child (new String (" "));
+
+ // type parameters
+ api.add_child (this.parameter_list (m));
+ Entry? exceptions = this.exceptions (m);
+ if (exceptions != null) {
+ api.add_child (exceptions);
+ }
+
+ if (m.is_yields) {
+ api.add_child (this.keyword(" yields"));
+ }
+
+ api.add_child (new String(";"));
+ return api;
+ }
+
+ public Div from_delegate (Delegate del) {
+ Div api = new Div ();
+ api.add_attribute (cssapi);
+
+
+ api.add_child (this.keyword(this.symbol_accessibility (del) + " delegate "));
+
+
+ // return type:
+ Collection<Entry> lst = this.type_reference (del.type_reference);
+ foreach (Entry e in lst) {
+ api.add_child (e);
+ }
+
+ api.add_child (new String (" "+del.name));
+
+ lst = this.type_parameter_list (del);
+ if (lst != null) {
+ api.add_childs (lst);
+ }
+
+ api.add_child (new String (" "));
+
+
+ // type parameters
+ api.add_child (this.parameter_list (del));
+ Entry? exceptions = this.exceptions (del);
+ if (exceptions != null) {
+ api.add_child (exceptions);
+ }
+
+ api.add_child (new String(";"));
+ return api;
+ }
+
+ public Div from_signal (Signal sig) {
+ Div api = new Div ();
+ api.add_attribute (cssapi);
+
+
+ api.add_child (this.keyword(this.symbol_accessibility (sig) + " signal "));
+
+ // return type:
+ Collection<Entry> lst = this.type_reference (sig.type_reference);
+ foreach (Entry e in lst) {
+ api.add_child (e);
+ }
+
+ api.add_child (new String (" "+sig.name+" "));
+ // type parameters
+ api.add_child (this.parameter_list (sig));
+ api.add_child (new String(";"));
+ return api;
+ }
+
+ public Div from_field (Field field) {
+ Div api = new Div ();
+ api.add_attribute (cssapi);
+
+ StringBuilder str = new StringBuilder (this.symbol_accessibility (field));
+ str.append_c (' ');
+
+ if (field.is_volatile) {
+ str.append ("volatile ");
+ }
+
+ if (field.is_static) {
+ str.append ("static ");
+ }
+
+ api.add_child (this.keyword (str.str));
+
+ foreach (Entry e in this.type_reference (field.type_reference)) {
+ api.add_child (e);
+ }
+
+ api.add_child (new String(" "+field.name+";"));
+ return api;
+ }
+
+ public Div from_constant (Constant c) {
+ Div api = new Div ();
+ api.add_attribute (cssapi);
+
+ api.add_child (this.keyword (this.symbol_accessibility (c)+" const "));
+
+ foreach (Entry e in this.type_reference (c.type_reference)) {
+ api.add_child (e);
+ }
+
+ api.add_child (new String(" "+c.name+";"));
+ return api;
+ }
+
+ public Div from_namespace (Namespace ns) {
+ Div api = new Div ();
+ api.add_attribute (cssapi);
+
+ api.add_child (this.keyword ("namespace "));
+ api.add_child (new String (ns.name+";"));
+ return api;
+ }
+
+ public Div from_enum (Enum en) {
+ Div api = new Div ();
+ api.add_attribute (cssapi);
+
+ api.add_child (this.keyword (this.symbol_accessibility (en) + " enum "));
+ api.add_child (new String (en.name+";"));
+ return api;
+ }
+
+ public Div from_errordomain (ErrorDomain err) {
+ Div api = new Div ();
+ api.add_attribute (cssapi);
+
+ api.add_child (this.keyword (this.symbol_accessibility (err) + " errordomain "));
+ api.add_child (new String (err.name+";"));
+ return api;
+ }
+
+ public Div from_enumvalue (EnumValue env) {
+ Div api = new Div ();
+ api.add_attribute (cssapi);
+ api.add_child (new String (env.name));
+ return api;
+ }
+
+ public Div from_errorcode (ErrorCode errc) {
+ Div api = new Div ();
+ api.add_attribute (cssapi);
+ api.add_child (new String (errc.name));
+ return api;
+ }
+
+ public Div from_struct (Struct stru) {
+ Div api = new Div ();
+ api.add_attribute (cssapi);
+
+ api.add_child (this.keyword (this.symbol_accessibility (stru) + " struct "));
+ api.add_child (new String (stru.name));
+
+ Collection<Entry> lst = this.type_parameter_list (stru);
+ if (lst != null) {
+ api.add_childs (lst);
+ }
+
+ api.add_child (new String (";"));
+ return api;
+ }
+
+ public Div from_class (Class cl) {
+ Div api = new Div ();
+ api.add_attribute (cssapi);
+
+ StringBuilder str = new StringBuilder (this.symbol_accessibility (cl));
+ if (cl.is_abstract) {
+ str.append (" abstract");
+ }
+
+ str.append (" class ");
+
+ api.add_child (this.keyword(str.str));
+ str = null;
+
+ api.add_child (new String (cl.name));
+
+ Collection<Entry> lst = this.type_parameter_list (cl);
+ if (lst != null) {
+ api.add_childs (lst);
+ }
+
+ api.add_child (new String (";"));
+ return api;
+ }
+
+ public Div from_interface (Interface iface) {
+ Div api = new Div ();
+ api.add_attribute (cssapi);
+
+
+ api.add_child (this.keyword (this.symbol_accessibility (iface)+" interface "));
+ api.add_child (new String (iface.name));
+
+ Collection<Entry> lst = this.type_parameter_list (iface);
+ if (lst != null) {
+ api.add_childs (lst);
+ }
+
+ api.add_child (new String (";"));
+ return api;
+ }
+
+ private Entry from_property_accessor (PropertyAccessor propac) {
+ StringBuilder str = new StringBuilder ();
+
+ if (propac.is_private) {
+ str.append ("private ");
+ }
+ else if (propac.is_public) {
+ str.append ("public ");
+ }
+ else {
+ str.append ("protected ");
+ }
+
+ if (propac.is_owned) {
+ str.append ("owned ");
+ }
+
+ if (propac.is_get ) {
+ str.append ("get ");
+ }
+ else {
+ str.append ("set ");
+ }
+
+ Span span = new Span ();
+ span.add_child (this.keyword (str.str));
+ span.add_child (new String ("; "));
+ return span;
+ }
+
+ public Div from_property (Property prop) {
+ Div api = new Div ();
+ api.add_attribute (cssapi);
+
+
+ StringBuilder str = new StringBuilder (this.symbol_accessibility (prop));
+ if (prop.is_virtual) {
+ str.append ( " virtual " );
+ }
+ else if (prop.is_abstract) {
+ str.append ( " abstract " );
+ }
+ else {
+ str.append ( " override " );
+ }
+
+ api.add_child (this.keyword (str.str));
+
+ foreach (Entry e in this.type_reference (prop.type_reference)) {
+ api.add_child (e);
+ }
+
+ api.add_child (new String(" "+prop.name+" { "));
+ if (prop.setter != null) {
+ api.add_child(from_property_accessor (prop.setter));
+ }
+
+ if (prop.getter != null) {
+ api.add_child(from_property_accessor (prop.getter));
+ }
+
+ api.add_child (new String("}"));
+ return api;
+ }
+
+ public Div from_documented_element (DocumentedElement el) {
+ if (el is Method) {
+ return this.from_method ((Method)el);
+ }
+ else if (el is Delegate) {
+ return this.from_delegate ((Delegate)el);
+ }
+ else if (el is Signal) {
+ return this.from_signal ((Signal)el);
+ }
+ else if (el is Field) {
+ return this.from_field ((Field)el);
+ }
+ else if (el is Constant) {
+ return this.from_constant ((Constant)el);
+ }
+ else if (el is Namespace) {
+ return this.from_namespace ((Namespace)el);
+ }
+ else if (el is Enum) {
+ return this.from_enum ((Enum)el);
+ }
+ else if (el is ErrorDomain) {
+ return this.from_errordomain ((ErrorDomain)el);
+ }
+ else if (el is EnumValue) {
+ return this.from_enumvalue ((EnumValue)el);
+ }
+ else if (el is ErrorCode) {
+ return this.from_errorcode ((ErrorCode)el);
+ }
+ else if (el is Struct) {
+ return this.from_struct ((Struct)el);
+ }
+ else if (el is Class) {
+ return this.from_class ((Class)el);
+ }
+ else if (el is Interface) {
+ return this.from_interface ((Interface)el);
+ }
+ else {
+ return this.from_property ((Property)el);
+ }
+ }
+}
+
+
return ns.get_namespace_helper ( node, vnspaces, pos+1 );
}
- // TODO: Rename vars
protected Namespace get_namespace ( Vala.Symbol node ) {
Vala.Symbol vnd = ((Vala.Symbol)node).parent_symbol;
if ( vnd is Vala.Namespace == false )
return this.is_weak_helper ( ((Vala.FormalParameter)parent).parameter_type );
}
- // return type
- if ( parent is Vala.Method == true )
- return this.is_weak_helper ( ((Vala.Method)parent).return_type );
- else if ( parent is Vala.Signal == true )
- return this.is_weak_helper ( ((Vala.Signal)parent).return_type );
- else if ( parent is Vala.Delegate == true )
- return this.is_weak_helper ( ((Vala.Delegate)parent).return_type );
-
return false;
}
}
public bool is_weak {
get {
+ Vala.CodeNode parent = this.vtyperef.parent_node;
+
+ if (parent is Vala.FormalParameter) {
+ return false;
+ }
+
+ if (parent is Vala.Method == true) {
+ return this.is_weak_helper ( ((Vala.Method)parent).return_type );
+ }
+ else if (parent is Vala.Signal == true) {
+ return this.is_weak_helper ( ((Vala.Signal)parent).return_type );
+ }
+ else if (parent is Vala.Delegate == true) {
+ return this.is_weak_helper ( ((Vala.Delegate)parent).return_type );
+ }
+
return ( this.vtyperef.parent_node is Field )? this.is_weak_helper( this.vtyperef ) : false;
}
}
var vparamlst = this.vmethod.get_parameters ();
this.add_parameter_list ( vparamlst );
-// var vtparams = this.vmethod.get_type_parameters ();
-// this.set_template_parameter_list ( vtparams );
-
- //var vexceptionlst = this.vmethod.get_error_types ();
- //this.add_error_domains ( vexceptionlst );
+ var vtparams = this.vmethod.get_type_parameters ();
+ this.set_template_parameter_list ( vtparams );
}
// intern
private Valadoc.Settings settings;
private CodeContext context;
private ErrorReporter reporter;
+ private Package sourcefiles = null;
public WikiPageTree? wikitree {
private set;
return ;
Vala.SourceFile vfile = vcl.source_reference.file;
- Package file = this.find_file( vfile );
- Namespace ns = file.get_namespace ( vcl );
+ Package file = this.find_file(vfile);
+ Namespace ns = file.get_namespace (vcl);
ns.add_class ( vcl );
}
var rpath = realpath (source);
if (source.has_suffix (".vala") || source.has_suffix (".gs")) {
var source_file = new SourceFile (context, rpath);
- Package vdpkg = new Package (this.settings, source_file, this, false);
- this.packages.add (vdpkg);
+
+
+ if (this.sourcefiles == null) {
+ this.sourcefiles = new Package (this.settings, source_file, this, false);
+ this.packages.add (this.sourcefiles);
+ }
+ else {
+ this.sourcefiles.add_file (source_file);
+ }
if (context.profile == Profile.POSIX) {
// import the Posix namespace by default (namespace of backend-specific standard library)