mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 01:36:01 +02:00
Bug 338683 - Codan confuses fields with methods
This commit is contained in:
parent
ef5c018b27
commit
d9f24fae67
4 changed files with 102 additions and 6 deletions
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* 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)
|
private void handleMemberProblem(IASTName name, IASTNode parentNode, IProblemBinding problemBinding, String contextFlagsString)
|
||||||
throws DOMException {
|
throws DOMException {
|
||||||
IASTNode parentParentNode = parentNode.getParent();
|
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) {
|
if (problemBinding.getCandidateBindings().length == 0) {
|
||||||
reportProblem(ERR_ID_MethodResolutionProblem, name.getLastName(), name.getRawSignature(), contextFlagsString);
|
reportProblem(ERR_ID_MethodResolutionProblem, name.getLastName(), name.getRawSignature(), contextFlagsString);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.CaseBreakCheckerTest;
|
||||||
import org.eclipse.cdt.codan.core.internal.checkers.CatchByReferenceTest;
|
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.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.ReturnCheckerTest;
|
||||||
import org.eclipse.cdt.codan.core.internal.checkers.ReturnStyleCheckerTest;
|
import org.eclipse.cdt.codan.core.internal.checkers.ReturnStyleCheckerTest;
|
||||||
import org.eclipse.cdt.codan.core.internal.checkers.StatementHasNoEffectCheckerTest;
|
import org.eclipse.cdt.codan.core.internal.checkers.StatementHasNoEffectCheckerTest;
|
||||||
|
@ -56,6 +57,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
|
||||||
suite.addTestSuite(SuspiciousSemicolonCheckerTest.class);
|
suite.addTestSuite(SuspiciousSemicolonCheckerTest.class);
|
||||||
suite.addTestSuite(CaseBreakCheckerTest.class);
|
suite.addTestSuite(CaseBreakCheckerTest.class);
|
||||||
suite.addTestSuite(FormatStringCheckerTest.class);
|
suite.addTestSuite(FormatStringCheckerTest.class);
|
||||||
|
suite.addTestSuite(ProblemBindingCheckerTest.class);
|
||||||
// framework
|
// framework
|
||||||
suite.addTest(CodanFastTestSuite.suite());
|
suite.addTest(CodanFastTestSuite.suite());
|
||||||
// quick fixes
|
// quick fixes
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -14,11 +14,13 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.CodanRuntime;
|
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.IProblem;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemProfile;
|
import org.eclipse.cdt.codan.core.model.IProblemProfile;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemReporter;
|
import org.eclipse.cdt.codan.core.model.IProblemReporter;
|
||||||
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||||
import org.eclipse.cdt.codan.core.param.MapProblemPreference;
|
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.CodanProblem;
|
||||||
import org.eclipse.cdt.codan.internal.core.model.CodanProblemMarker;
|
import org.eclipse.cdt.codan.internal.core.model.CodanProblemMarker;
|
||||||
import org.eclipse.core.resources.IMarker;
|
import org.eclipse.core.resources.IMarker;
|
||||||
|
@ -187,14 +189,22 @@ public class CheckerTestCase extends CodanTestCase {
|
||||||
IProblem[] problems = profile.getProblems();
|
IProblem[] problems = profile.getProblems();
|
||||||
for (int i = 0; i < problems.length; i++) {
|
for (int i = 0; i < problems.length; i++) {
|
||||||
IProblem p = problems[i];
|
IProblem p = problems[i];
|
||||||
|
boolean enabled = false;
|
||||||
for (int j = 0; j < ids.length; j++) {
|
for (int j = 0; j < ids.length; j++) {
|
||||||
String pid = ids[j];
|
String pid = ids[j];
|
||||||
if (p.getId().equals(pid)) {
|
if (p.getId().equals(pid)) {
|
||||||
((CodanProblem) p).setEnabled(true);
|
enabled = true;
|
||||||
} else {
|
// Force the launch mode to FULL_BUILD to make sure we can test the problem even if by default it
|
||||||
((CodanProblem) p).setEnabled(false);
|
// 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);
|
CodanRuntime.getInstance().getCheckersRegistry().updateProfile(cproject.getProject(), profile);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue