1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

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>
This commit is contained in:
Andrew Eidsness 2014-01-08 15:25:45 -05:00 committed by Doug Schaefer
parent 030bfc50fb
commit f531f2f4d8
2 changed files with 40 additions and 3 deletions

View file

@ -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)

View file

@ -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.