Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Ruiz2012-02-23 20:25:05 +0000
committerSergey Prigogin2012-02-23 20:25:05 +0000
commit3115bb4e228e7d1903aaba91178d7ec9742c190e (patch)
tree9a4c4a8c743dc5769b8b1408a6f3656873d29593 /codan/org.eclipse.cdt.codan.ui.cxx/src
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/src')
-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
2 files changed, 101 insertions, 0 deletions
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 00000000000..b9b3c9e902d
--- /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 00000000000..4667d3b9731
--- /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