summaryrefslogtreecommitdiffstats
path: root/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui')
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstarctCodanCMarkerResolution.java91
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstractCodanProblemDetailsProvider.java114
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Activator.java98
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Entries8
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Tag1
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Template0
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanCReconciler.java71
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanEditorUtility.java111
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Startup.java93
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Entries2
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Template0
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/RunCodeAnalysis.java69
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/ToggleNatureAction.java130
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Entries1
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Repository (renamed from org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Repository)2
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Root (renamed from org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Root)0
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Tag1
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/RunCodanCommand.java37
18 files changed, 362 insertions, 467 deletions
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstarctCodanCMarkerResolution.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstarctCodanCMarkerResolution.java
new file mode 100644
index 0000000..6a36763
--- /dev/null
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstarctCodanCMarkerResolution.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 Alena Laskavaia
+ * 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.ui;
+
+import org.eclipse.cdt.codan.internal.ui.CodanUIActivator;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IMarkerResolution2;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * Generic class for codan marker resolution (for quick fix). Use as a base
+ * class for codanMarkerResolution extension. To add specific icon and
+ * description client class should additionally implement
+ * {@link IMarkerResolution2}
+ */
+public abstract class AbstarctCodanCMarkerResolution implements IMarkerResolution {
+ /**
+ * Get position offset from marker. If CHAR_START attribute is not set for
+ * marker, line and document would be used.
+ *
+ * @param marker
+ * @param doc
+ * @return
+ */
+ public int getOffset(IMarker marker, IDocument doc) {
+ int charStart = marker.getAttribute(IMarker.CHAR_START, -1);
+ int position;
+ if (charStart > 0) {
+ position = charStart;
+ } else {
+ int line = marker.getAttribute(IMarker.LINE_NUMBER, -1) - 1;
+ try {
+ position = doc.getLineOffset(line);
+ } catch (BadLocationException e) {
+ return -1;
+ }
+ }
+ return position;
+ }
+
+ /**
+ * Runs this resolution.
+ *
+ * @param marker
+ * the marker to resolve
+ */
+ public void run(IMarker marker) {
+ IEditorPart editorPart;
+ try {
+ editorPart = CodanEditorUtility.openInEditor(marker);
+ } catch (PartInitException e) {
+ CodanUIActivator.log(e);
+ return;
+ }
+ if (editorPart instanceof ITextEditor) {
+ ITextEditor editor = (ITextEditor) editorPart;
+ IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
+ apply(marker, doc);
+ }
+ }
+
+ /**
+ * Apply marker resolution for given marker in given open document.
+ *
+ * @param marker
+ * @param document
+ */
+ public abstract void apply(IMarker marker, IDocument document);
+
+ /**
+ * Override is extra checks is required to determine appicablity of marker resolution
+ * @param marker
+ * @return
+ */
+ public boolean isApplicable(IMarker marker) {
+ return true;
+ }
+}
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstractCodanProblemDetailsProvider.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstractCodanProblemDetailsProvider.java
new file mode 100644
index 0000000..4fff924
--- /dev/null
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstractCodanProblemDetailsProvider.java
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Alena Laskavaia
+ * 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.ui;
+
+import org.eclipse.cdt.codan.core.CodanRuntime;
+import org.eclipse.cdt.codan.core.model.IProblem;
+import org.eclipse.core.resources.IMarker;
+
+/**
+ * Abstract class that provides stubs for problems details.
+ * This class intended to be extended by the users of codanProblemDetails extension point.
+ * One instance of this class would exists at runtime. To query for results, framework
+ * would synchronize on this class object, set setMarker then call other getStyled* methods
+ * to obtain data.
+ */
+public abstract class AbstractCodanProblemDetailsProvider {
+ protected IMarker marker;
+
+ public AbstractCodanProblemDetailsProvider() {
+ }
+
+ /**
+ * sets the marker, called from framework to initialize provider
+ */
+ public void setMarker(IMarker marker) {
+ this.marker = marker;
+ }
+
+ /**
+ * Get marker associated with this provider
+ * @return
+ */
+ public IMarker getMarker() {
+ return marker;
+ }
+
+ /**
+ * Convenience method to return marker message
+ * @return
+ */
+ protected String getProblemMessage() {
+ String message = marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$
+ return message;
+ }
+
+ /**
+ * Convenience method to return codan problem id
+ * @return
+ */
+ protected String getProblemId() {
+ String id = marker.getAttribute(IMarker.PROBLEM, (String) null);
+ return id;
+ }
+
+ /**
+ * return true if provider can provide details for given marker (previously set by setMarker)
+ * @param id - id of the problem
+ * @return true if details are available for given marker
+ */
+ public abstract boolean isApplicable(String id);
+
+ /**
+ * Return styled problem message. This text would be used in Link widget.
+ * String can include <a> tags to which would be
+ * visible as hyperlinks and newline characters (\n). Default message if
+ * marker message plus location. Ampersand (&) should be escape because
+ * it is interpreted as mnemonic for control navigation (can use espaceForLink method). <br>
+ * This method intended to be overriden by the client.
+ */
+ public String getStyledProblemMessage() {
+ String message = escapeForLink(getProblemMessage());
+ String href = getLocationHRef();
+ String link = href.replaceFirst("^file:", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ link = link.replaceFirst("#(\\d+)$", ":$1"); //$NON-NLS-1$//$NON-NLS-2$
+ return "<a href=\"" + href + "\">" + link + "</a> \n" + message; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
+ protected String getLocationHRef() {
+ return CodanEditorUtility.getLocationHRef(marker);
+ }
+ /**
+ * Return styled problem description. This text would be used in Link widget.
+ * String can include <a> tags to which would be
+ * visible as hyperlinks and newline characters (\n).
+ * Ampersand (&) should be escape because
+ * it is interpreted as mnemonic for control navigation (can use espaceForLink method).
+ *
+ * Default implementation return desciption of codan problem. <br>
+ * This method intended to be overriden by the client.
+ *
+ */
+ public String getStyledProblemDescription() {
+ String id = getProblemId();
+ if (id == null)
+ return ""; //$NON-NLS-1$
+ IProblem problem = CodanRuntime.getInstance().getChechersRegistry().getDefaultProfile().findProblem(id);
+ return escapeForLink(problem.getDescription());
+ }
+
+ /**
+ * Method to escape characters which are interpreted by Link swt control,
+ * such as & (mnemonic)
+ */
+ protected String escapeForLink(String text) {
+ return text.replaceAll("&", "&&"); //$NON-NLS-1$//$NON-NLS-2$
+ }
+}
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Activator.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Activator.java
deleted file mode 100644
index 849993a..0000000
--- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Activator.java
+++ /dev/null
@@ -1,98 +0,0 @@
-package org.eclipse.cdt.codan.ui;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class Activator extends AbstractUIPlugin {
- // The plug-in ID
- public static final String PLUGIN_ID = "org.eclipse.cdt.codan.ui";
- // The shared instance
- private static Activator plugin;
-
- /**
- * The constructor
- */
- public Activator() {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
- * )
- */
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
- * )
- */
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static Activator getDefault() {
- return plugin;
- }
-
- /**
- * Returns an image descriptor for the image file at the given plug-in
- * relative path
- *
- * @param path
- * the path
- * @return the image descriptor
- */
- public static ImageDescriptor getImageDescriptor(String path) {
- return imageDescriptorFromPlugin(PLUGIN_ID, path);
- }
-
- /**
- * Logs the specified status with this plug-in's log.
- *
- * @param status
- * status to log
- */
- public static void log(IStatus status) {
- getDefault().getLog().log(status);
- }
-
- /**
- * Logs an internal error with the specified throwable
- *
- * @param e
- * the exception to be logged
- */
- public static void log(Throwable e) {
- log(new Status(IStatus.ERROR, PLUGIN_ID, 1, "Internal Error", e)); //$NON-NLS-1$
- }
-
- /**
- * Logs an internal error with the specified message.
- *
- * @param message
- * the error message to log
- */
- public static void log(String message) {
- log(new Status(IStatus.ERROR, PLUGIN_ID, 1, message, null));
- }
-}
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Entries b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Entries
index 4387fb2..e02c292 100644
--- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Entries
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Entries
@@ -1,4 +1,6 @@
-/Activator.java/1.2/Fri Apr 24 12:49:44 2009//
-/CodanCReconciler.java/1.3/Sat Aug 22 21:16:50 2009//
-/Startup.java/1.1/Fri Apr 24 12:49:44 2009//
+/AbstarctCodanCMarkerResolution.java/1.4/Thu Jun 3 17:01:40 2010//TCDT_7_0_0
+/AbstractCodanProblemDetailsProvider.java/1.7/Sat May 8 01:19:46 2010//TCDT_7_0_0
+/CodanEditorUtility.java/1.1/Wed May 5 19:59:17 2010//TCDT_7_0_0
D/actions////
+D/handlers////
+D/views////
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Tag
new file mode 100644
index 0000000..49a449a
--- /dev/null
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Tag
@@ -0,0 +1 @@
+NCDT_7_0_0
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Template
deleted file mode 100644
index e69de29..0000000
--- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Template
+++ /dev/null
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanCReconciler.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanCReconciler.java
deleted file mode 100644
index 5bec1c1..0000000
--- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanCReconciler.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Alena Laskavaia
- * 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.ui;
-
-import org.eclipse.cdt.codan.core.CodanRuntime;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
-import org.eclipse.cdt.internal.ui.editor.CEditor;
-import org.eclipse.cdt.internal.ui.text.ICReconcilingListener;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.ui.texteditor.ITextEditor;
-
-/**
- * @author Alena
- *
- */
-public class CodanCReconciler implements ICReconcilingListener {
- void install(ITextEditor editor) {
- if (editor instanceof CEditor) {
- initialize();
- ((CEditor) editor).addReconcileListener(this);
- }
- }
-
- void uninstall(ITextEditor editor) {
- if (editor instanceof CEditor) {
- initialize();
- ((CEditor) editor).removeReconcileListener(this);
- }
- }
-
- /**
- *
- */
- private void initialize() {
- // TODO Auto-generated method stub
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.cdt.internal.ui.text.ICReconcilingListener#aboutToBeReconciled
- * ()
- */
- public void aboutToBeReconciled() {
- // TODO Auto-generated method stub
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.cdt.internal.ui.text.ICReconcilingListener#reconciled(org
- * .eclipse.cdt.core.dom.ast.IASTTranslationUnit, boolean,
- * org.eclipse.core.runtime.IProgressMonitor)
- */
- public void reconciled(IASTTranslationUnit ast, boolean force,
- IProgressMonitor progressMonitor) {
- CodanRuntime.getInstance().getAstQuickBuilder().reconcileAst(ast,
- progressMonitor);
- // System.err.println("ast reconsiled");
- }
-}
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanEditorUtility.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanEditorUtility.java
new file mode 100644
index 0000000..1cdc5ef
--- /dev/null
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanEditorUtility.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * $QNXLicenseC:
+ * Copyright 2008, QNX Software Systems. All Rights Reserved.
+ *
+ * You must obtain a written license from and pay applicable license fees to QNX
+ * Software Systems before you may reproduce, modify or distribute this software,
+ * or any work that includes all or part of this software. Free development
+ * licenses are available for evaluation and non-commercial purposes. For more
+ * information visit http://licensing.qnx.com or email licensing@qnx.com.
+ *
+ * This file may contain contributions from others. Please review this entire
+ * file for other proprietary rights or license notices, as well as the QNX
+ * Development Suite License Guide at http://licensing.qnx.com/license-guide/
+ * for other information.
+ * $
+ *******************************************************************************/
+/*
+ * Created by: Elena Laskavaia
+ * Created on: 2010-05-05
+ * Last modified by: $Author: elaskavaia $
+ */
+package org.eclipse.cdt.codan.ui;
+
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.internal.ui.util.EditorUtility;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * Utility tools to open editor and highlight the line
+ */
+public class CodanEditorUtility {
+ /**
+ * @param fileUrl - file "url", like file:/tmp/a.c#22
+ * @throws PartInitException
+ * @throws BadLocationException
+ */
+ public static void openFileURL(String fileUrl, IResource markerResource) throws PartInitException, BadLocationException {
+ String file = getFileFromURL(fileUrl);
+
+ IEditorPart part = openInEditor(file, markerResource);
+ int line = getLineFromURL(fileUrl);
+ revealLine(part, line);
+ }
+
+ /**
+ * Line is the part the follows # in this URL
+ * @return -1 if not line found in URL, and line number if there is
+ */
+ public static int getLineFromURL(String fileUrl) {
+ String sline = fileUrl.replaceAll(".*#(\\d+)$", "$1"); //$NON-NLS-1$ //$NON-NLS-2$
+ int line = -1;
+ try {
+ line = Integer.parseInt(sline);
+ } catch (NumberFormatException e2) {
+ // no line
+ }
+ return line;
+ }
+
+ public static String getFileFromURL(String link) {
+ String file = link.replaceFirst("^file:", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ file = file.replaceAll("#\\d+$", ""); //$NON-NLS-1$//$NON-NLS-2$
+ return file;
+ }
+
+ public static void revealLine(IEditorPart part, int line) throws BadLocationException {
+ if (line > 0) {
+ if (part instanceof ITextEditor) {
+ ITextEditor textEditor = (ITextEditor) part;
+ IDocument document = textEditor.getDocumentProvider().getDocument(part.getEditorInput());
+ textEditor.selectAndReveal(document.getLineOffset(line - 1), 0);
+ }
+ }
+ }
+
+ @SuppressWarnings("restriction")
+ public static IEditorPart openInEditor(String file, IResource markerResource) throws PartInitException {
+ IPath pfile = new Path(file);
+ ICElement element = null;
+ if (markerResource != null)
+ CoreModel.getDefault().create(markerResource);
+ IEditorPart part = EditorUtility.openInEditor(pfile, element);
+ return part;
+ }
+
+ public static IEditorPart openInEditor(IMarker marker) throws PartInitException {
+ String href = getLocationHRef(marker);
+ String file = getFileFromURL(href);
+ return openInEditor(file, marker.getResource());
+ }
+
+ public static String getLocationHRef(IMarker marker) {
+ String loc = marker.getResource().getLocationURI().toString();
+ String loc2 = marker.getAttribute(IMarker.LOCATION, ""); //$NON-NLS-1$
+ int line = marker.getAttribute(IMarker.LINE_NUMBER, 0);
+ if (loc2.length() > 0) {
+ loc = "file:" + loc2.replaceAll("[^:]*: ", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ String href = loc + "#" + line; //$NON-NLS-1$
+ return href;
+ }
+}
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Startup.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Startup.java
deleted file mode 100644
index 41fbf89..0000000
--- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Startup.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Alena Laskavaia
- * 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.ui;
-
-import org.eclipse.ui.IEditorReference;
-import org.eclipse.ui.IPartListener2;
-import org.eclipse.ui.IStartup;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchPartReference;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.texteditor.ITextEditor;
-
-/**
- * @author Alena
- *
- */
-public class Startup implements IStartup {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IStartup#earlyStartup()
- */
- public void earlyStartup() {
- registerListeners();
- }
-
- /**
- * Register part listener for editor to install c ast reconcile listener
- */
- private void registerListeners() {
- final IWorkbench workbench = PlatformUI.getWorkbench();
- workbench.getDisplay().asyncExec(new Runnable() {
- public void run() {
- IWorkbenchWindow active = workbench.getActiveWorkbenchWindow();
- final IWorkbenchPage page = active.getActivePage();
- IPartListener2 partListener = new IPartListener2() {
- CodanCReconciler reconsiler = new CodanCReconciler();
-
- public void partActivated(IWorkbenchPartReference partRef) {
- }
-
- public void partDeactivated(IWorkbenchPartReference partRef) {
- }
-
- public void partOpened(IWorkbenchPartReference partRef) {
- IWorkbenchPart editor = partRef.getPart(false);
- if (editor instanceof ITextEditor) {
- reconsiler.install((ITextEditor) editor);
- }
- }
-
- public void partHidden(IWorkbenchPartReference partRef) {
- }
-
- public void partVisible(IWorkbenchPartReference partRef) {
- }
-
- public void partClosed(IWorkbenchPartReference partRef) {
- IWorkbenchPart part = partRef.getPart(false);
- if (part instanceof ITextEditor) {
- reconsiler.uninstall((ITextEditor) part);
- }
- }
-
- public void partBroughtToTop(IWorkbenchPartReference partRef) {
- }
-
- public void partInputChanged(IWorkbenchPartReference partRef) {
- }
- };
- page.addPartListener(partListener);
- // check current open editors
- IEditorReference[] editorReferences = page
- .getEditorReferences();
- for (int i = 0; i < editorReferences.length; i++) {
- IEditorReference ref = editorReferences[i];
- partListener.partOpened(ref);
- }
- }
- });
- }
-}
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Entries b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Entries
deleted file mode 100644
index 30cf7ec..0000000
--- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Entries
+++ /dev/null
@@ -1,2 +0,0 @@
-/RunCodeAnalysis.java/1.3/Sat Aug 22 21:16:50 2009//
-/ToggleNatureAction.java/1.2/Sat Aug 22 21:16:50 2009//
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Template
deleted file mode 100644
index e69de29..0000000
--- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Template
+++ /dev/null
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/RunCodeAnalysis.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/RunCodeAnalysis.java
deleted file mode 100644
index 01d7c25..0000000
--- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/RunCodeAnalysis.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Alena Laskavaia
- * 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.ui.actions;
-
-import java.util.Iterator;
-
-import org.eclipse.cdt.codan.core.CodanRuntime;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
-
-public class RunCodeAnalysis implements IObjectActionDelegate {
- private ISelection sel;
-
- public void setActivePart(IAction action, IWorkbenchPart targetPart) {
- // nothing
- }
-
- public void run(IAction action) {
- Job job = new Job("Running Code Analysis") {
- @SuppressWarnings("unchecked")
- @Override
- protected IStatus run(final IProgressMonitor monitor) {
- IStructuredSelection ss = (IStructuredSelection) sel;
- int count = ss.size();
- monitor.beginTask(getName(), count * 100);
- if (monitor.isCanceled())
- return Status.CANCEL_STATUS;
- for (Iterator iterator = ss.iterator(); iterator.hasNext();) {
- Object o = iterator.next();
- if (o instanceof IResource) {
- IResource res = (IResource) o;
- SubProgressMonitor subMon = new SubProgressMonitor(
- monitor, 100);
- CodanRuntime.getInstance().getBuilder()
- .processResource(res, subMon);
- if (subMon.isCanceled())
- return Status.CANCEL_STATUS;
- }
- if (monitor.isCanceled())
- return Status.CANCEL_STATUS;
- }
- return Status.OK_STATUS;
- }
- };
- job.setUser(true);
- job.schedule();
- }
-
- public void selectionChanged(IAction action, ISelection selection) {
- this.sel = selection;
- }
-}
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/ToggleNatureAction.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/ToggleNatureAction.java
deleted file mode 100644
index 3993621..0000000
--- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/ToggleNatureAction.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Alena Laskavaia
- * 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.ui.actions;
-
-import java.util.Iterator;
-
-import org.eclipse.cdt.codan.core.CodanCorePlugin;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
-
-public class ToggleNatureAction implements IObjectActionDelegate {
- private ISelection selection;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
- */
- public void run(IAction action) {
- if (selection instanceof IStructuredSelection) {
- for (Iterator it = ((IStructuredSelection) selection).iterator(); it
- .hasNext();) {
- Object element = it.next();
- IProject project = null;
- if (element instanceof IProject) {
- project = (IProject) element;
- } else if (element instanceof IAdaptable) {
- project = (IProject) ((IAdaptable) element)
- .getAdapter(IProject.class);
- }
- if (project != null) {
- toggleNature(project, !hasCodanNature(project));
- }
- }
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action
- * .IAction, org.eclipse.jface.viewers.ISelection)
- */
- public void selectionChanged(IAction action, ISelection selection) {
- this.selection = selection;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.
- * action.IAction, org.eclipse.ui.IWorkbenchPart)
- */
- public void setActivePart(IAction action, IWorkbenchPart targetPart) {
- }
-
- public boolean hasCodanNature(IProject project) {
- IProjectDescription description;
- try {
- description = project.getDescription();
- String[] natures = description.getNatureIds();
- for (int i = 0; i < natures.length; ++i) {
- if (CodanCorePlugin.NATURE_ID.equals(natures[i])) {
- return true;
- }
- }
- } catch (CoreException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return false;
- }
-
- /**
- * Toggles sample nature on a project
- *
- * @param project
- * to have sample nature added or removed
- */
- public void toggleNature(IProject project, boolean add) {
- try {
- IProjectDescription description = project.getDescription();
- String[] natures = description.getNatureIds();
- for (int i = 0; i < natures.length; ++i) {
- if (CodanCorePlugin.NATURE_ID.equals(natures[i])) {
- if (add == false) {
- // Remove the nature
- String[] newNatures = new String[natures.length - 1];
- System.arraycopy(natures, 0, newNatures, 0, i);
- System.arraycopy(natures, i + 1, newNatures, i,
- natures.length - i - 1);
- description.setNatureIds(newNatures);
- project.setDescription(description, null);
- return;
- } else {
- // already there no need to add
- add = false;
- break;
- }
- }
- }
- if (add) {
- // Add the nature
- String[] newNatures = new String[natures.length + 1];
- System.arraycopy(natures, 0, newNatures, 0, natures.length);
- newNatures[natures.length] = CodanCorePlugin.NATURE_ID;
- description.setNatureIds(newNatures);
- project.setDescription(description, null);
- }
- } catch (CoreException e) {
- }
- }
-}
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Entries b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Entries
new file mode 100644
index 0000000..8a29f40
--- /dev/null
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Entries
@@ -0,0 +1 @@
+/RunCodanCommand.java/1.3/Thu Jun 3 17:01:40 2010//TCDT_7_0_0
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Repository b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Repository
index 09c1aeb..c8ef8af 100644
--- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Repository
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Repository
@@ -1 +1 @@
-org.eclipse.cdt/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions
+org.eclipse.cdt/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Root b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Root
index 04efa23..04efa23 100644
--- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Root
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Root
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Tag
new file mode 100644
index 0000000..49a449a
--- /dev/null
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/CVS/Tag
@@ -0,0 +1 @@
+NCDT_7_0_0
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/RunCodanCommand.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/RunCodanCommand.java
new file mode 100644
index 0000000..d0999a8
--- /dev/null
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/handlers/RunCodanCommand.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Alena Laskavaia and others.
+ * 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.ui.handlers;
+
+import org.eclipse.cdt.codan.internal.ui.actions.RunCodeAnalysis;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Command to run code analysis on selected resources
+ * @see org.eclipse.core.commands.IHandler
+ * @see org.eclipse.core.commands.AbstractHandler
+ */
+public class RunCodanCommand extends AbstractHandler {
+
+ public RunCodanCommand() {
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+ RunCodeAnalysis action = new RunCodeAnalysis();
+ action.selectionChanged(null, currentSelection);
+ action.run(null);
+ return null;
+ }
+}