From f531f2f4d80565c9966df42b8e400ca5a970265b Mon Sep 17 00:00:00 2001 From: Andrew Eidsness Date: Wed, 8 Jan 2014 15:25:45 -0500 Subject: [PATCH] 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 Reviewed-on: https://git.eclipse.org/r/20401 Tested-by: Hudson CI Reviewed-by: Doug Schaefer IP-Clean: Doug Schaefer --- .../internal/qt/core/QtMethodReference.java | 37 +++++++++++++++++++ .../qt/core/codan/QtSyntaxChecker.java | 6 +-- 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 42afecd5ae0..5501383f5fe 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 88002c9277d..b582aeb8047 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 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.