From e912eb6f3291d431164efac553036c6ccc93d1f6 Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Mon, 5 Mar 2012 01:31:48 -0500 Subject: [PATCH] Bug 372009 - Wrong class name in NonVirtualDestructor warning --- .../checkers/NonVirtualDestructor.java | 3 ++- .../NonVirtualDestructorCheckerTest.java | 8 +++++++ .../cdt/codan/core/test/CheckerTestCase.java | 21 +++++++++++++++---- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java index 84c697677a7..db7235a7307 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java @@ -9,6 +9,7 @@ * Alena Laskavaia - initial API and implementation * Patrick Hofer [bug 315528] * Sergey Prigogin (Google) + * Marc-Andre Laperle *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers; @@ -117,7 +118,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { node = decls[0]; } } - reportProblem(PROBLEM_ID, node, className.getSimpleID().toString(), + reportProblem(PROBLEM_ID, node, new String(className.getSimpleID()), virtualMethod.getName()); return PROCESS_SKIP; } diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java index edecd93c067..0f3bf57f068 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java @@ -195,4 +195,12 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase { loadCodeAndRun(getAboveComment()); checkNoErrors(); } + + // class Foo { + // virtual void bar(); + // }; + public void testBug372009_wrongClassNameInMessage() throws Exception { + loadCodeAndRun(getAboveComment()); + assertMessageContains("Foo", markers[0]); + } } 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 391cc8c6591..75b3f6a2667 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, 2011 Alena Laskavaia + * Copyright (c) 2009, 2012 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 @@ -7,6 +7,7 @@ * * Contributors: * Alena Laskavaia - initial API and implementation + * Marc-Andre Laperle *******************************************************************************/ package org.eclipse.cdt.codan.core.test; @@ -186,9 +187,21 @@ public class CheckerTestCase extends CodanTestCase { */ public void assertMessageMatch(String pattern, IMarker m) { try { - String attribute = (String) m.getAttribute(IMarker.MESSAGE); - if (attribute.matches(pattern)) { - fail("Expected " + attribute + " to match with /" + pattern //$NON-NLS-1$ //$NON-NLS-2$ + String message = (String) m.getAttribute(IMarker.MESSAGE); + if (message.matches(pattern)) { + fail("Expected " + message + " to match with /" + pattern //$NON-NLS-1$ //$NON-NLS-2$ + + "/"); //$NON-NLS-1$ + } + } catch (CoreException e) { + fail(e.getMessage()); + } + } + + public void assertMessageContains(CharSequence charSequence, IMarker m) { + try { + String message = (String) m.getAttribute(IMarker.MESSAGE); + if (!message.contains(charSequence)) { + fail("Expected " + message + " to contain /" + charSequence //$NON-NLS-1$ //$NON-NLS-2$ + "/"); //$NON-NLS-1$ } } catch (CoreException e) {