1
/*******************************************************************************
2
* Copyright (c) 2009, 2010 Alena Laskavaia
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Alena Laskavaia - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.codan.core.cxx.model;
13
import org.eclipse.cdt.codan.core.CodanCorePlugin;
14
import org.eclipse.cdt.codan.core.model.AbstractCheckerWithProblemPreferences;
15
import org.eclipse.cdt.core.CCorePlugin;
16
import org.eclipse.cdt.core.index.IIndex;
17
import org.eclipse.cdt.core.model.CoreModel;
18
import org.eclipse.cdt.core.model.ICElement;
19
import org.eclipse.cdt.core.model.ITranslationUnit;
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.runtime.CoreException;
25
* Implementation of IChecker that works with C-Index of a file (but not AST)
27
* Clients may extend this class.
29
public abstract class AbstractCIndexChecker extends AbstractCheckerWithProblemPreferences implements ICIndexChecker {
31
protected IIndex index;
33
protected IFile getFile() {
37
void processFile(IFile file) throws CoreException, InterruptedException {
38
// create translation unit and access index
39
ICElement model = CoreModel.getDefault().create(file);
40
if (!(model instanceof ITranslationUnit))
41
return; // not a C/C++ file
42
ITranslationUnit tu = (ITranslationUnit) model;
43
index = CCorePlugin.getIndexManager().getIndex(tu.getCProject());
44
// lock the index for read access
45
index.acquireReadLock();
47
// traverse the translation unit using the visitor pattern.
52
index.releaseReadLock();
56
public synchronized boolean processResource(IResource resource) {
57
if (resource instanceof IFile) {
58
IFile file = (IFile) resource;
61
} catch (CoreException e) {
62
CodanCorePlugin.log(e);
63
} catch (InterruptedException e) {
72
public boolean runInEditor() {