Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-Andre Laperle2011-03-13 01:03:56 -0500
committerMarc-Andre Laperle2011-03-13 01:03:56 -0500
commitd9f24fae675d3362e5c74ac77828f46774e056bc (patch)
treeba60329476d01b8d36c28a34e3622fca9f53e90f
parentef5c018b2752bfe5f6b060652cf2ba8c05756f3a (diff)
downloadorg.eclipse.cdt-d9f24fae675d3362e5c74ac77828f46774e056bc.tar.gz
org.eclipse.cdt-d9f24fae675d3362e5c74ac77828f46774e056bc.tar.xz
org.eclipse.cdt-d9f24fae675d3362e5c74ac77828f46774e056bc.zip
Bug 338683 - Codan confuses fields with methods
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ProblemBindingChecker.java10
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ProblemBindingCheckerTest.java78
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java2
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CheckerTestCase.java18
4 files changed, 102 insertions, 6 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ProblemBindingChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ProblemBindingChecker.java
index 71629d975b..01c1041c03 100644
--- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ProblemBindingChecker.java
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ProblemBindingChecker.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Marc-Andre Laperle and others.
+ * Copyright (c) 2010, 2011 Marc-Andre Laperle and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -210,7 +210,13 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
private void handleMemberProblem(IASTName name, IASTNode parentNode, IProblemBinding problemBinding, String contextFlagsString)
throws DOMException {
IASTNode parentParentNode = parentNode.getParent();
- if (parentParentNode instanceof IASTFunctionCallExpression) {
+
+ // An IASTFieldReference corresponds to a method if it's the first child in the parent function call expression
+ // For example,
+ // func(x.y()); the field reference is first in the x.y() function call expression -> y is a method
+ // func(x.y); the field reference is second in the func(x.y) function call expression, func is first as a Id Expression -> y is a field
+ boolean isMethod = parentParentNode instanceof IASTFunctionCallExpression && parentParentNode.getChildren()[0] == parentNode;
+ if (isMethod) {
if (problemBinding.getCandidateBindings().length == 0) {
reportProblem(ERR_ID_MethodResolutionProblem, name.getLastName(), name.getRawSignature(), contextFlagsString);
} else {
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ProblemBindingCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ProblemBindingCheckerTest.java
new file mode 100644
index 0000000000..173c85c664
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ProblemBindingCheckerTest.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Marc-Andre Laperle and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marc-Andre Laperle - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.core.internal.checkers;
+
+import org.eclipse.cdt.codan.core.test.CheckerTestCase;
+import org.eclipse.cdt.codan.internal.checkers.ProblemBindingChecker;
+
+public class ProblemBindingCheckerTest extends CheckerTestCase {
+ // @Override
+ @Override
+ public boolean isCpp() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.test.CodanTestCase#setUp()
+ */
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ enableProblems(ProblemBindingChecker.ERR_ID_AmbiguousProblem, ProblemBindingChecker.ERR_ID_Candidates,
+ ProblemBindingChecker.ERR_ID_CircularReferenceProblem, ProblemBindingChecker.ERR_ID_FieldResolutionProblem,
+ ProblemBindingChecker.ERR_ID_FunctionResolutionProblem, ProblemBindingChecker.ERR_ID_InvalidArguments,
+ ProblemBindingChecker.ERR_ID_InvalidTemplateArgumentsProblem, ProblemBindingChecker.ERR_ID_LabelStatementNotFoundProblem,
+ ProblemBindingChecker.ERR_ID_MemberDeclarationNotFoundProblem, ProblemBindingChecker.ERR_ID_MethodResolutionProblem,
+ ProblemBindingChecker.ERR_ID_OverloadProblem, ProblemBindingChecker.ERR_ID_RedeclarationProblem,
+ ProblemBindingChecker.ERR_ID_RedefinitionProblem, ProblemBindingChecker.ERR_ID_TypeResolutionProblem,
+ ProblemBindingChecker.ERR_ID_VariableResolutionProblem);
+ }
+
+ // int main () {
+ // struct X {} x;
+ // fun(x.y);
+ // }
+ public void testBug338683FieldInFunctionCall() {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(3, ProblemBindingChecker.ERR_ID_FieldResolutionProblem);
+ }
+
+ // int main () {
+ // struct X {} x;
+ // x.b(
+ // x.y(),
+ // x.y(
+ // x.y),
+ // x.y(
+ // x.y(
+ // a,
+ // fun(
+ // x.b(),
+ // x.y,
+ // a.b()))));
+ // }
+ public void testBug338683VariousFieldMethodCombinations() {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(3, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
+ checkErrorLine(4, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
+ checkErrorLine(5, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
+ checkErrorLine(6, ProblemBindingChecker.ERR_ID_FieldResolutionProblem);
+ checkErrorLine(7, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
+ checkErrorLine(8, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
+ checkErrorLine(9, ProblemBindingChecker.ERR_ID_VariableResolutionProblem);
+ checkErrorLine(10, ProblemBindingChecker.ERR_ID_FunctionResolutionProblem);
+ checkErrorLine(11, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
+ checkErrorLine(12, ProblemBindingChecker.ERR_ID_FieldResolutionProblem);
+ checkErrorLine(13, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java
index e9d9e12c1b..1070b82d7c 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java
@@ -20,6 +20,7 @@ import org.eclipse.cdt.codan.core.internal.checkers.AssignmentToItselfCheckerTes
import org.eclipse.cdt.codan.core.internal.checkers.CaseBreakCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.CatchByReferenceTest;
import org.eclipse.cdt.codan.core.internal.checkers.FormatStringCheckerTest;
+import org.eclipse.cdt.codan.core.internal.checkers.ProblemBindingCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.ReturnCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.ReturnStyleCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.StatementHasNoEffectCheckerTest;
@@ -56,6 +57,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
suite.addTestSuite(SuspiciousSemicolonCheckerTest.class);
suite.addTestSuite(CaseBreakCheckerTest.class);
suite.addTestSuite(FormatStringCheckerTest.class);
+ suite.addTestSuite(ProblemBindingCheckerTest.class);
// framework
suite.addTest(CodanFastTestSuite.suite());
// quick fixes
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CheckerTestCase.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CheckerTestCase.java
index beb283f339..0ce02c3d22 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CheckerTestCase.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CheckerTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Alena Laskavaia
+ * Copyright (c) 2009, 2011 Alena Laskavaia
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,11 +14,13 @@ import java.io.File;
import java.io.IOException;
import org.eclipse.cdt.codan.core.CodanRuntime;
+import org.eclipse.cdt.codan.core.model.CheckerLaunchMode;
import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemProfile;
import org.eclipse.cdt.codan.core.model.IProblemReporter;
import org.eclipse.cdt.codan.core.param.IProblemPreference;
import org.eclipse.cdt.codan.core.param.MapProblemPreference;
+import org.eclipse.cdt.codan.core.param.RootProblemPreference;
import org.eclipse.cdt.codan.internal.core.model.CodanProblem;
import org.eclipse.cdt.codan.internal.core.model.CodanProblemMarker;
import org.eclipse.core.resources.IMarker;
@@ -187,14 +189,22 @@ public class CheckerTestCase extends CodanTestCase {
IProblem[] problems = profile.getProblems();
for (int i = 0; i < problems.length; i++) {
IProblem p = problems[i];
+ boolean enabled = false;
for (int j = 0; j < ids.length; j++) {
String pid = ids[j];
if (p.getId().equals(pid)) {
- ((CodanProblem) p).setEnabled(true);
- } else {
- ((CodanProblem) p).setEnabled(false);
+ enabled = true;
+ // Force the launch mode to FULL_BUILD to make sure we can test the problem even if by default it
+ // is not set to run on FULL_BUILD
+ IProblemPreference preference = p.getPreference();
+ if (preference instanceof RootProblemPreference) {
+ RootProblemPreference rootProblemPreference = (RootProblemPreference) preference;
+ rootProblemPreference.getLaunchModePreference().enableInLaunchModes(CheckerLaunchMode.RUN_ON_FULL_BUILD);
+ }
+ break;
}
}
+ ((CodanProblem) p).setEnabled(enabled);
}
CodanRuntime.getInstance().getCheckersRegistry().updateProfile(cproject.getProject(), profile);
return;

Back to the top