summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu.vizoso@collabora.co.uk>2011-02-04 11:33:26 +0100
committerTomeu Vizoso <tomeu.vizoso@collabora.co.uk>2011-02-22 17:10:08 +0100
commita988cd414ce6aa40f1d77fcfa2d5721d169b5927 (patch)
treed025f82a9c9cc2613c2ce9f5120e66b48711e387
parentf49f46f0c2b4ab2c7e33598596e6df72bd960c19 (diff)
downloadgobject-introspection-a988cd414ce6aa40f1d77fcfa2d5721d169b5927.tar.gz
Add warnings for the (method) annotation
https://bugzilla.gnome.org/show_bug.cgi?id=641347
-rw-r--r--giscanner/maintransformer.py20
-rw-r--r--tests/warn/Makefile.am1
-rw-r--r--tests/warn/invalid-method.h26
3 files changed, 43 insertions, 4 deletions
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index ea1b170d..38642081 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -900,7 +900,7 @@ method or constructor of some type."""
if func.is_constructor or self._is_constructor(func, subsymbol):
self._set_up_constructor(func, subsymbol)
return
- elif func.is_method or self._is_method(func, subsymbol):
+ elif self._is_method(func, subsymbol):
self._setup_method(func, subsymbol)
return
elif self._pair_static_method(func, subsymbol):
@@ -913,14 +913,25 @@ method or constructor of some type."""
def _is_method(self, func, subsymbol):
if not func.parameters:
+ if func.is_method:
+ message.warn_node(func,
+ '%s: Methods must have parameters' % (func.symbol, ))
return False
first = func.parameters[0]
target = self._transformer.lookup_typenode(first.type)
if not isinstance(target, (ast.Class, ast.Interface,
ast.Record, ast.Union,
ast.Boxed)):
+ if func.is_method:
+ message.warn_node(func,
+ '%s: Methods must have a pointer as their first '
+ 'parameter' % (func.symbol, ))
return False
if target.namespace != self._namespace:
+ if func.is_method:
+ message.warn_node(func,
+ '%s: Methods must belong to the same namespace as the '
+ 'class they belong to' % (func.symbol, ))
return False
# A quick hack here...in the future we should catch C signature/GI signature
@@ -928,9 +939,10 @@ method or constructor of some type."""
if first.type.ctype is not None and first.type.ctype.count('*') != 1:
return False
- uscored_prefix = self._get_uscored_prefix(func, subsymbol)
- if not subsymbol.startswith(uscored_prefix):
- return False
+ if not func.is_method:
+ uscored_prefix = self._get_uscored_prefix(func, subsymbol)
+ if not subsymbol.startswith(uscored_prefix):
+ return False
return True
diff --git a/tests/warn/Makefile.am b/tests/warn/Makefile.am
index 8b44cfcb..571ca4a3 100644
--- a/tests/warn/Makefile.am
+++ b/tests/warn/Makefile.am
@@ -7,6 +7,7 @@ TESTS = \
invalid-array.h \
invalid-closure.h \
invalid-element-type.h \
+ invalid-method.h \
invalid-option.h \
invalid-out.h \
invalid-transfer.h \
diff --git a/tests/warn/invalid-method.h b/tests/warn/invalid-method.h
new file mode 100644
index 00000000..26d528ac
--- /dev/null
+++ b/tests/warn/invalid-method.h
@@ -0,0 +1,26 @@
+#include "common.h"
+
+/**
+ * test_method_no_parameters: (method)
+ *
+ */
+void test_method_no_parameters();
+
+// EXPECT:7: Warning: Test: test_method_no_parameters: Methods must have parameters
+
+/**
+ * test_method_invalid_first_parameter: (method):
+ *
+ */
+void test_method_invalid_first_parameter(int param);
+
+// EXPECT:15: Warning: Test: test_method_invalid_first_parameter: Methods must have a pointer as their first parameter
+
+/**
+ * test_method_invalid_namespace: (method):
+ *
+ */
+void test_method_invalid_namespace(GClosure *param);
+
+// EXPECT:23: Warning: Test: test_method_invalid_namespace: Methods must belong to the same namespace as the class they are into
+