~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractCIndexChecker.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 *    Alena Laskavaia  - initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.codan.core.cxx.model;
 
12
 
 
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;
 
23
 
 
24
/**
 
25
 * Implementation of IChecker that works with C-Index of a file (but not AST)
 
26
 * 
 
27
 * Clients may extend this class.
 
28
 */
 
29
public abstract class AbstractCIndexChecker extends AbstractCheckerWithProblemPreferences implements ICIndexChecker {
 
30
        private IFile file;
 
31
        protected IIndex index;
 
32
 
 
33
        protected IFile getFile() {
 
34
                return file;
 
35
        }
 
36
 
 
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();
 
46
                try {
 
47
                        // traverse the translation unit using the visitor pattern.
 
48
                        this.file = file;
 
49
                        processUnit(tu);
 
50
                } finally {
 
51
                        this.file = null;
 
52
                        index.releaseReadLock();
 
53
                }
 
54
        }
 
55
 
 
56
        public synchronized boolean processResource(IResource resource) {
 
57
                if (resource instanceof IFile) {
 
58
                        IFile file = (IFile) resource;
 
59
                        try {
 
60
                                processFile(file);
 
61
                        } catch (CoreException e) {
 
62
                                CodanCorePlugin.log(e);
 
63
                        } catch (InterruptedException e) {
 
64
                                // ignore
 
65
                        }
 
66
                        return false;
 
67
                }
 
68
                return true;
 
69
        }
 
70
 
 
71
        @Override
 
72
        public boolean runInEditor() {
 
73
                return false;
 
74
        }
 
75
}