1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 309760 name resolution checker, contributed patch

This commit is contained in:
Alena Laskavaia 2010-06-24 01:26:28 +00:00
parent ce2679ff3a
commit 38b1009303
2 changed files with 65 additions and 3 deletions

View file

@ -119,8 +119,19 @@
name="%problem.name.NoReturn">
</problem>
</checker>
<checker
class="org.eclipse.cdt.codan.internal.checkers.NameResolutionChecker"
id="org.eclipse.cdt.codan.checkers.NameResolutionChecker"
name="Name Resolution Checker">
<problem
category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems"
defaultEnabled="true"
defaultSeverity="Error"
description="Name resolution problem found by the indexer"
id="org.eclipse.cdt.codan.internal.checkers.NameResolutionChecker"
messagePattern="Symbol &apos;&apos;{0}&apos;&apos; could not be resolved"
name="Name Resolution Problem">
</problem>
</checker>
</extension>
</plugin>

View file

@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2010 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.internal.checkers;
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
public class NameResolutionChecker extends AbstractIndexAstChecker {
static final String ERR_ID = "org.eclipse.cdt.codan.internal.checkers.NameResolutionChecker"; //$NON-NLS-1$
public void processAst(IASTTranslationUnit ast) {
try {
ast.accept(new ASTVisitor() {
{
shouldVisitNames = true;
}
@Override
public int visit(IASTName name) {
IBinding binding = name.resolveBinding();
if (binding instanceof IProblemBinding) {
reportProblem(ERR_ID, name, name.getRawSignature());
}
return PROCESS_CONTINUE;
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean runInEditor() {
return true;
}
}