Skip to main content
summaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
authorAlena Laskavaia2015-03-04 15:16:47 -0500
committerGerrit Code Review @ Eclipse.org2015-03-06 15:38:44 -0500
commitdd528c19b6c4ec9245c076e46ae4ea23c0914abb (patch)
tree1604b20fd647fbed9fc0e5da743b3c92101e92df /codan
parent6bd7355e47e40bf8f8030b4533a0f2da0b1e2b58 (diff)
downloadorg.eclipse.cdt-dd528c19b6c4ec9245c076e46ae4ea23c0914abb.tar.gz
org.eclipse.cdt-dd528c19b6c4ec9245c076e46ae4ea23c0914abb.tar.xz
org.eclipse.cdt-dd528c19b6c4ec9245c076e46ae4ea23c0914abb.zip
codan: added AbstractCElementChecker class
this allows to run on translation unit but without index locking useful for externl tools Change-Id: If0788eee7d322aa4cafb7985e0c8f742c31369ae Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com>
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractCElementChecker.java58
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractCIndexChecker.java55
2 files changed, 74 insertions, 39 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractCElementChecker.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractCElementChecker.java
new file mode 100644
index 0000000000..b4bfbeb994
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractCElementChecker.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2015 QNX Software Systems
+ * 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:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.core.cxx.model;
+
+import org.eclipse.cdt.codan.core.model.AbstractCheckerWithProblemPreferences;
+import org.eclipse.cdt.codan.core.model.CheckerLaunchMode;
+import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.core.resources.IResource;
+
+/**
+ * Implementation of IChecker that works with translation unit without locking
+ * the index
+ *
+ * Clients may extend this class.
+ * @since 3.3
+ */
+public abstract class AbstractCElementChecker extends AbstractCheckerWithProblemPreferences implements ICIndexChecker {
+ @Override
+ public synchronized boolean processResource(IResource resource) {
+ ICElement model = CoreModel.getDefault().create(resource);
+ if (!(model instanceof ITranslationUnit))
+ return true; // not a C/C++ file
+ ITranslationUnit tu = (ITranslationUnit) model;
+ processTranslationUnitUnlocked(tu);
+ return false;
+ }
+
+ protected void processTranslationUnitUnlocked(ITranslationUnit tu) {
+ processUnit(tu);
+ }
+
+ @Override
+ public void initPreferences(IProblemWorkingCopy problem) {
+ getTopLevelPreference(problem); // initialize
+ getLaunchModePreference(problem).enableInLaunchModes(
+ CheckerLaunchMode.RUN_ON_FILE_OPEN,
+ CheckerLaunchMode.RUN_ON_FILE_SAVE,
+ CheckerLaunchMode.RUN_ON_DEMAND,
+ CheckerLaunchMode.RUN_ON_FULL_BUILD,
+ CheckerLaunchMode.RUN_ON_INC_BUILD);
+ }
+
+ @Override
+ public boolean runInEditor() {
+ return false;
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractCIndexChecker.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractCIndexChecker.java
index f5f2ab3094..2aa8016e94 100644
--- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractCIndexChecker.java
+++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractCIndexChecker.java
@@ -11,14 +11,10 @@
package org.eclipse.cdt.codan.core.cxx.model;
import org.eclipse.cdt.codan.core.CodanCorePlugin;
-import org.eclipse.cdt.codan.core.model.AbstractCheckerWithProblemPreferences;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.index.IIndex;
-import org.eclipse.cdt.core.model.CoreModel;
-import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
/**
@@ -26,7 +22,7 @@ import org.eclipse.core.runtime.CoreException;
*
* Clients may extend this class.
*/
-public abstract class AbstractCIndexChecker extends AbstractCheckerWithProblemPreferences implements ICIndexChecker {
+public abstract class AbstractCIndexChecker extends AbstractCElementChecker implements ICIndexChecker {
private IFile file;
protected IIndex index;
@@ -34,43 +30,24 @@ public abstract class AbstractCIndexChecker extends AbstractCheckerWithProblemPr
return file;
}
- void processFile(IFile file) throws CoreException, InterruptedException {
- // create translation unit and access index
- ICElement model = CoreModel.getDefault().create(file);
- if (!(model instanceof ITranslationUnit))
- return; // not a C/C++ file
- ITranslationUnit tu = (ITranslationUnit) model;
- index = CCorePlugin.getIndexManager().getIndex(tu.getCProject());
- // lock the index for read access
- index.acquireReadLock();
- try {
- // traverse the translation unit using the visitor pattern.
- this.file = file;
- processUnit(tu);
- } finally {
- this.file = null;
- index.releaseReadLock();
- }
- }
-
@Override
- public synchronized boolean processResource(IResource resource) {
- if (resource instanceof IFile) {
- IFile file = (IFile) resource;
+ protected void processTranslationUnitUnlocked(ITranslationUnit tu) {
+ try {
+ index = CCorePlugin.getIndexManager().getIndex(tu.getCProject());
+ // lock the index for read access
+ index.acquireReadLock();
try {
- processFile(file);
- } catch (CoreException e) {
- CodanCorePlugin.log(e);
- } catch (InterruptedException e) {
- // ignore
+ // traverse the translation unit using the visitor pattern.
+ this.file = tu.getFile();
+ processUnit(tu);
+ } finally {
+ this.file = null;
+ index.releaseReadLock();
}
- return false;
+ } catch (CoreException e) {
+ CodanCorePlugin.log(e);
+ } catch (InterruptedException e) {
+ // ignore
}
- return true;
- }
-
- @Override
- public boolean runInEditor() {
- return false;
}
}

Back to the top