Skip to main content
summaryrefslogtreecommitdiffstats
path: root/qt
diff options
context:
space:
mode:
authorAndrew Eidsness2014-01-08 15:25:45 -0500
committerDoug Schaefer2014-01-10 10:40:14 -0500
commitf531f2f4d80565c9966df42b8e400ca5a970265b (patch)
tree0611848e43a3f29d4f9d0f1be63fff9655b4d35d /qt
parent030bfc50fb028aeba7b329787955b8e17a51d2da (diff)
downloadorg.eclipse.cdt-f531f2f4d80565c9966df42b8e400ca5a970265b.tar.gz
org.eclipse.cdt-f531f2f4d80565c9966df42b8e400ca5a970265b.tar.xz
org.eclipse.cdt-f531f2f4d80565c9966df42b8e400ca5a970265b.zip
Bug 425102 New check for Qt Codan checker
The Qt Codan checker for QObject::connect function calls was not confirming that the SIGNAL and SLOT expansion parameter were Qt signals and slots. The checker would allow the function call as long as the expansion parameter resolved to a C++ method. This patch changes the behaviour to required signals inside SIGNAL and slots inside SLOT. Change-Id: Ieec2f3a7ef4968d45ac3f6323b20c2f195fe3400 Signed-off-by: Andrew Eidsness <eclipse@jfront.com> Reviewed-on: https://git.eclipse.org/r/20401 Tested-by: Hudson CI Reviewed-by: Doug Schaefer <dschaefer@qnx.com> IP-Clean: Doug Schaefer <dschaefer@qnx.com>
Diffstat (limited to 'qt')
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/QtMethodReference.java37
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/codan/QtSyntaxChecker.java6
2 files changed, 40 insertions, 3 deletions
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/QtMethodReference.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/QtMethodReference.java
index 42afecd5ae..5501383f5f 100644
--- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/QtMethodReference.java
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/QtMethodReference.java
@@ -9,6 +9,7 @@ package org.eclipse.cdt.internal.qt.core;
import java.util.regex.Matcher;
+import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
@@ -23,6 +24,11 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.qt.core.pdom.ASTNameReference;
import org.eclipse.cdt.internal.qt.core.pdom.QtASTImageLocation;
import org.eclipse.cdt.qt.core.QtKeywords;
+import org.eclipse.cdt.qt.core.QtPlugin;
+import org.eclipse.cdt.qt.core.index.IQMethod;
+import org.eclipse.cdt.qt.core.index.IQObject;
+import org.eclipse.cdt.qt.core.index.QtIndex;
+import org.eclipse.core.resources.IProject;
/**
* Qt signals and slots are referenced using the SIGNAL and SLOT macros. The expansion
@@ -164,6 +170,37 @@ public class QtMethodReference extends ASTNameReference {
return expansionParam.toCharArray();
}
+ private IQObject findQObject() {
+ String[] qualName = null;
+ try {
+ qualName = cls.getQualifiedName();
+ } catch(DOMException e) {
+ QtPlugin.log(e);
+ }
+
+ IProject project = ASTUtil.getProject(delegate);
+ if (project == null)
+ return null;
+
+ QtIndex qtIndex = QtIndex.getIndex(project);
+ if (qtIndex == null)
+ return null;
+
+ return qtIndex.findQObject(qualName);
+ }
+
+ public IQMethod getMethod() {
+ IQObject qobj = findQObject();
+ if (qobj == null)
+ return null;
+
+ // Return the first matching method.
+ for(IQMethod method : ASTUtil.findMethods(qobj, this))
+ return method;
+
+ return null;
+ }
+
@Override
public IBinding resolveBinding() {
if (binding != null)
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/codan/QtSyntaxChecker.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/codan/QtSyntaxChecker.java
index 88002c9277..b582aeb804 100644
--- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/codan/QtSyntaxChecker.java
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/codan/QtSyntaxChecker.java
@@ -18,12 +18,12 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
-import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.qt.core.ASTUtil;
import org.eclipse.cdt.internal.qt.core.QtFunctionCall;
import org.eclipse.cdt.internal.qt.core.QtMethodReference;
import org.eclipse.cdt.qt.core.QtNature;
import org.eclipse.cdt.qt.core.QtPlugin;
+import org.eclipse.cdt.qt.core.index.IQMethod;
import org.eclipse.osgi.util.NLS;
/**
@@ -69,8 +69,8 @@ public class QtSyntaxChecker extends AbstractIndexAstChecker implements IChecker
Collection<QtMethodReference> refs = QtFunctionCall.getReferences(fncall);
if (refs != null)
for(QtMethodReference ref : refs) {
- IBinding binding = ref.resolveBinding();
- if (binding != null)
+ IQMethod method = ref.getMethod();
+ if (method != null)
continue;
// Either the macro expansion didn't have an argument, or the argument was not a valid method.

Back to the top