summaryrefslogtreecommitdiff
path: root/valadate
diff options
context:
space:
mode:
authorChris Daley <chebizarro@gmail.com>2017-04-30 21:46:34 -0700
committerRico Tzschichholz <ricotz@ubuntu.com>2017-11-19 12:35:04 +0100
commitc2025bbf8e3e0ded722f03da4a24ae7aaedb6fbf (patch)
treefcd27a521c8d0423207086d654df284dff067080 /valadate
parent7a53e2189dba7d8621029b096c9317a1bdc4b882 (diff)
downloadvala-c2025bbf8e3e0ded722f03da4a24ae7aaedb6fbf.tar.gz
removed all references to CCodeAttribute
Diffstat (limited to 'valadate')
-rw-r--r--valadate/testgatherer.vala57
-rw-r--r--valadate/testplan.vala116
2 files changed, 163 insertions, 10 deletions
diff --git a/valadate/testgatherer.vala b/valadate/testgatherer.vala
index 63dca58e3..4606ff66c 100644
--- a/valadate/testgatherer.vala
+++ b/valadate/testgatherer.vala
@@ -47,9 +47,62 @@ public class Valadate.TestGatherer : Vala.CodeVisitor {
}
private Type find_type (Vala.Class cls) throws Error {
- var attr = new Vala.CCodeAttribute (cls);
- unowned TestPlan.GetType node_get_type = (TestPlan.GetType)assembly.get_method ("%sget_type".printf (attr.lower_case_prefix));
+ unowned TestPlan.GetType node_get_type = (TestPlan.GetType)assembly.get_method ("%sget_type".printf (get_ccode_lower_case_prefix(cls)));
var ctype = node_get_type ();
return ctype;
}
+
+ private string get_ccode_lower_case_prefix (Vala.Symbol sym) {
+ var ccode = sym.get_attribute ("CCode");
+ string _lower_case_prefix = null;
+
+ if (ccode != null) {
+ _lower_case_prefix = ccode.get_string ("lower_case_cprefix");
+ if (_lower_case_prefix == null && (sym is Vala.ObjectTypeSymbol)) {
+ _lower_case_prefix = ccode.get_string ("cprefix");
+ }
+ }
+ if (_lower_case_prefix == null) {
+ if (sym is Vala.Namespace) {
+ if (sym.name == null) {
+ _lower_case_prefix = "";
+ } else {
+ _lower_case_prefix = "%s%s_".printf (get_ccode_lower_case_prefix (sym.parent_symbol), Vala.Symbol.camel_case_to_lower_case (sym.name));
+ }
+ } else if (sym is Vala.Method) {
+ // for lambda expressions
+ _lower_case_prefix = "";
+ } else {
+ _lower_case_prefix = "%s%s_".printf (get_ccode_lower_case_prefix (sym.parent_symbol), get_ccode_lower_case_suffix (sym));
+ }
+ }
+ return _lower_case_prefix;
+ }
+
+ private string get_ccode_lower_case_suffix (Vala.Symbol sym) {
+ var ccode = sym.get_attribute ("CCode");
+ string _lower_case_suffix = null;
+
+ if (ccode != null) {
+ _lower_case_suffix = ccode.get_string ("lower_case_csuffix");
+ }
+ if (_lower_case_suffix == null) {
+ if (sym is Vala.ObjectTypeSymbol) {
+ var csuffix = Vala.Symbol.camel_case_to_lower_case (sym.name);
+ // remove underscores in some cases to avoid conflicts of type macros
+ if (csuffix.has_prefix ("type_")) {
+ csuffix = "type" + csuffix.substring ("type_".length);
+ } else if (csuffix.has_prefix ("is_")) {
+ csuffix = "is" + csuffix.substring ("is_".length);
+ }
+ if (csuffix.has_suffix ("_class")) {
+ csuffix = csuffix.substring (0, csuffix.length - "_class".length) + "class";
+ }
+ _lower_case_suffix = csuffix;
+ } else if (sym.name != null) {
+ _lower_case_suffix = Vala.Symbol.camel_case_to_lower_case (sym.name);
+ }
+ }
+ return _lower_case_suffix;
+ }
}
diff --git a/valadate/testplan.vala b/valadate/testplan.vala
index 099c7d480..dd286570c 100644
--- a/valadate/testplan.vala
+++ b/valadate/testplan.vala
@@ -163,8 +163,7 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
}
private unowned Constructor get_constructor (Vala.Class cls) throws Error {
- var attr = new Vala.CCodeAttribute (cls.default_construction_method);
- return (Constructor)assembly.get_method (attr.name);
+ return (Constructor)assembly.get_method (get_symbol_name (cls.default_construction_method));
}
public void visit_testcase (Vala.Class cls) {
@@ -200,12 +199,10 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
annotate (adapter, method);
if (config.in_subprocess && adapter.status != TestStatus.SKIPPED) {
- var attr = new Vala.CCodeAttribute (method);
-
if (method.coroutine) {
try {
- unowned TestPlan.AsyncTestMethod beginmethod = (TestPlan.AsyncTestMethod)assembly.get_method (attr.name);
- unowned TestPlan.AsyncTestMethodResult testmethod = (TestPlan.AsyncTestMethodResult)assembly.get_method (attr.finish_real_name);
+ unowned TestPlan.AsyncTestMethod beginmethod = (TestPlan.AsyncTestMethod)assembly.get_method (get_symbol_name (method));
+ unowned TestPlan.AsyncTestMethodResult testmethod = (TestPlan.AsyncTestMethodResult)assembly.get_method (get_finish_name (method));
adapter.add_async_test (beginmethod, testmethod);
} catch (Error e) {
var message = e.message;
@@ -213,7 +210,7 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
}
} else {
try {
- TestPlan.TestMethod testmethod = (TestPlan.TestMethod)assembly.get_method (attr.name);
+ TestPlan.TestMethod testmethod = (TestPlan.TestMethod)assembly.get_method (get_symbol_name (method));
adapter.add_test ((owned)testmethod);
} catch (Error e) {
var message = e.message;
@@ -224,7 +221,6 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
adapter.label = "%s/%s".printf (testcase.label,adapter.label);
testcase.add_test (adapter);
}
-
}
private void annotate_label (Test test) {
@@ -295,4 +291,108 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
testsuite.add_test (tsuite);
testsuite = tsuite;
}
+
+ private string get_finish_name (Vala.Symbol sym) {
+ var ccode = sym.get_attribute ("CCode");
+ string finish_name = null;
+
+ if (ccode != null) {
+ finish_name = ccode.get_string ("cnfinish_nameame");
+ if (finish_name == null) {
+ finish_name = ccode.get_string ("finish_function");
+ }
+ }
+ return finish_name ?? get_finish_name_for_basename (get_default_name (sym));
+ }
+
+ private string get_finish_name_for_basename (string basename) {
+ string result = basename;
+ if (result.has_suffix ("_async")) {
+ result = result.substring (0, result.length - "_async".length);
+ }
+ return "%s_finish".printf (result);
+ }
+
+ private string get_symbol_name (Vala.Symbol sym) {
+ var ccode = sym.get_attribute ("CCode");
+ string name = null;
+
+ if (ccode != null)
+ name = ccode.get_string ("cname");
+ return name ?? get_default_name (sym);
+ }
+
+ private string get_default_name (Vala.Symbol sym) {
+ if (sym is Vala.CreationMethod) {
+ var m = (Vala.CreationMethod) sym;
+ string infix = "new";
+ if (m.name == ".new") {
+ return "%s%s".printf (get_ccode_lower_case_prefix (m.parent_symbol), infix);
+ } else {
+ return "%s%s_%s".printf (get_ccode_lower_case_prefix (m.parent_symbol), infix, m.name);
+ }
+ } else if (sym is Vala.Method) {
+ var m = (Vala.Method) sym;
+ if (sym.name.has_prefix ("_")) {
+ return "_%s%s".printf (get_ccode_lower_case_prefix (sym.parent_symbol), sym.name.substring (1));
+ } else {
+ return "%s%s".printf (get_ccode_lower_case_prefix (sym.parent_symbol), sym.name);
+ }
+ }
+ return sym.name;
+ }
+
+ private string get_ccode_lower_case_prefix (Vala.Symbol sym) {
+ var ccode = sym.get_attribute ("CCode");
+ string _lower_case_prefix = null;
+
+ if (ccode != null) {
+ _lower_case_prefix = ccode.get_string ("lower_case_cprefix");
+ if (_lower_case_prefix == null && (sym is Vala.ObjectTypeSymbol)) {
+ _lower_case_prefix = ccode.get_string ("cprefix");
+ }
+ }
+ if (_lower_case_prefix == null) {
+ if (sym is Vala.Namespace) {
+ if (sym.name == null) {
+ _lower_case_prefix = "";
+ } else {
+ _lower_case_prefix = "%s%s_".printf (get_ccode_lower_case_prefix (sym.parent_symbol), Vala.Symbol.camel_case_to_lower_case (sym.name));
+ }
+ } else if (sym is Vala.Method) {
+ // for lambda expressions
+ _lower_case_prefix = "";
+ } else {
+ _lower_case_prefix = "%s%s_".printf (get_ccode_lower_case_prefix (sym.parent_symbol), get_ccode_lower_case_suffix (sym));
+ }
+ }
+ return _lower_case_prefix;
+ }
+
+ private string get_ccode_lower_case_suffix (Vala.Symbol sym) {
+ var ccode = sym.get_attribute ("CCode");
+ string _lower_case_suffix = null;
+
+ if (ccode != null) {
+ _lower_case_suffix = ccode.get_string ("lower_case_csuffix");
+ }
+ if (_lower_case_suffix == null) {
+ if (sym is Vala.ObjectTypeSymbol) {
+ var csuffix = Vala.Symbol.camel_case_to_lower_case (sym.name);
+ // remove underscores in some cases to avoid conflicts of type macros
+ if (csuffix.has_prefix ("type_")) {
+ csuffix = "type" + csuffix.substring ("type_".length);
+ } else if (csuffix.has_prefix ("is_")) {
+ csuffix = "is" + csuffix.substring ("is_".length);
+ }
+ if (csuffix.has_suffix ("_class")) {
+ csuffix = csuffix.substring (0, csuffix.length - "_class".length) + "class";
+ }
+ _lower_case_suffix = csuffix;
+ } else if (sym.name != null) {
+ _lower_case_suffix = Vala.Symbol.camel_case_to_lower_case (sym.name);
+ }
+ }
+ return _lower_case_suffix;
+ }
}