Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Ruiz2012-02-23 15:25:05 -0500
committerSergey Prigogin2012-02-23 15:25:05 -0500
commit3115bb4e228e7d1903aaba91178d7ec9742c190e (patch)
tree9a4c4a8c743dc5769b8b1408a6f3656873d29593 /codan/org.eclipse.cdt.codan.ui.cxx
parentac7ee03d2515bbfb234d5022db341dc07bd3627c (diff)
downloadorg.eclipse.cdt-3115bb4e228e7d1903aaba91178d7ec9742c190e.tar.gz
org.eclipse.cdt-3115bb4e228e7d1903aaba91178d7ec9742c190e.tar.xz
org.eclipse.cdt-3115bb4e228e7d1903aaba91178d7ec9742c190e.zip
Initial take on external-tool-based checkers.
Diffstat (limited to 'codan/org.eclipse.cdt.codan.ui.cxx')
-rw-r--r--codan/org.eclipse.cdt.codan.ui.cxx/META-INF/MANIFEST.MF3
-rw-r--r--codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/ui/cxx/externaltool/CEditors.java42
-rw-r--r--codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/ui/cxx/externaltool/CxxSupportedResourceVerifier.java59
3 files changed, 103 insertions, 1 deletions
diff --git a/codan/org.eclipse.cdt.codan.ui.cxx/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.ui.cxx/META-INF/MANIFEST.MF
index abedd163a0..80bc1e757d 100644
--- a/codan/org.eclipse.cdt.codan.ui.cxx/META-INF/MANIFEST.MF
+++ b/codan/org.eclipse.cdt.codan.ui.cxx/META-INF/MANIFEST.MF
@@ -19,4 +19,5 @@ Require-Bundle: org.eclipse.ui,
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.cdt.codan.internal.ui.cxx;x-internal:=true,
- org.eclipse.cdt.codan.ui
+ org.eclipse.cdt.codan.ui,
+ org.eclipse.cdt.codan.ui.cxx.externaltool
diff --git a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/ui/cxx/externaltool/CEditors.java b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/ui/cxx/externaltool/CEditors.java
new file mode 100644
index 0000000000..b9b3c9e902
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/ui/cxx/externaltool/CEditors.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Google, Inc.
+ * 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:
+ * Alex Ruiz - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.ui.cxx.externaltool;
+
+import org.eclipse.cdt.internal.ui.editor.CEditor;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.editors.text.TextEditor;
+
+/**
+ * Utility methods related to <code>{@link CEditor}</code>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+@SuppressWarnings("restriction") // CEditor is internal API
+final class CEditors {
+
+ static TextEditor activeCEditor() {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ for (IWorkbenchWindow w : workbench.getWorkbenchWindows()) {
+ IWorkbenchPage activePage = w.getActivePage();
+ IEditorPart editor = activePage.getActiveEditor();
+ if (editor instanceof CEditor) {
+ return (CEditor) editor;
+ }
+ }
+ return null;
+ }
+
+ private CEditors() {}
+}
diff --git a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/ui/cxx/externaltool/CxxSupportedResourceVerifier.java b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/ui/cxx/externaltool/CxxSupportedResourceVerifier.java
new file mode 100644
index 0000000000..4667d3b973
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/ui/cxx/externaltool/CxxSupportedResourceVerifier.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Google, Inc.
+ * 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:
+ * Alex Ruiz - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.ui.cxx.externaltool;
+
+import static org.eclipse.cdt.codan.core.cxx.util.FileTypes.isCppFile;
+import static org.eclipse.cdt.codan.core.cxx.util.FileTypes.isHeaderFile;
+import static org.eclipse.cdt.codan.ui.CodanEditorUtility.isResourceOpenInEditor;
+import static org.eclipse.cdt.codan.ui.cxx.externaltool.CEditors.activeCEditor;
+
+import org.eclipse.cdt.codan.core.externaltool.ISupportedResourceVerifier;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.ui.editors.text.TextEditor;
+
+/**
+ * Implemenation of <code>{@link ISupportedResourceVerifier}</code> for C/C++ files.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class CxxSupportedResourceVerifier implements ISupportedResourceVerifier {
+ /**
+ * Indicates whether the external tool is capable of processing the given
+ * <code>{@link IResource}</code>.
+ * <p>
+ * The minimum requirements that the given {@code IResource} should satisfy are:
+ * <ul>
+ * <li>should be C/C++ file</li>
+ * <li>should be displayed in the current active {@code CEditor}</li>
+ * <li>should not have any unsaved changes</li>
+ * </ul>
+ * </p>
+ * @param resource the given {@code IResource}.
+ * @return {@code true} if the external tool is capable of processing the given file,
+ * {@code false} otherwise.
+ */
+ @Override
+ public boolean isSupported(IResource resource) {
+ return isFileOfSupportedType(resource) && isOpenInActiveCEditor(resource);
+ }
+
+ private boolean isFileOfSupportedType(IResource resource) {
+ return isCppFile(resource) || isHeaderFile(resource);
+ }
+
+ private boolean isOpenInActiveCEditor(IResource resource) {
+ TextEditor activeCEditor = activeCEditor();
+ if (activeCEditor == null) {
+ return false;
+ }
+ return !activeCEditor.isDirty() && isResourceOpenInEditor(resource, activeCEditor);
+ }
+}

Back to the top