diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanBuilder.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanBuilder.java index e901b60cc5c..683c7b02dda 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanBuilder.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanBuilder.java @@ -10,18 +10,26 @@ *******************************************************************************/ package org.eclipse.cdt.codan.core.builder; +import java.io.File; +import java.net.URI; import java.util.Map; import org.eclipse.cdt.codan.core.CodanCorePlugin; import org.eclipse.cdt.codan.core.model.CheckersRegisry; import org.eclipse.cdt.codan.core.model.CodanRuntime; +import org.eclipse.cdt.codan.core.model.ICAstChecker; import org.eclipse.cdt.codan.core.model.IChecker; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.IResourceDeltaVisitor; import org.eclipse.core.resources.IResourceVisitor; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -104,6 +112,31 @@ public class CodanBuilder extends IncrementalProjectBuilder { } } + public void reconcileAst(IASTTranslationUnit ast, IProgressMonitor monitor) { + String filePath = ast.getFilePath(); + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IWorkspaceRoot root = workspace.getRoot(); + IFile[] resources; + URI uri = new File(filePath).toURI(); + resources = root.findFilesForLocationURI(uri); + if (resources != null && resources.length > 0) { + IFile resource = resources[0]; + CodanRuntime.getInstance().getProblemReporter().deleteMarkers( + resource); + for (IChecker checker : CheckersRegisry.getInstance()) { + try { + boolean run = false; + if (checker.enabledInContext(resource)) + run = true; + if (run && checker instanceof ICAstChecker) + ((ICAstChecker) checker).processAst(ast); + } catch (Throwable e) { + CodanCorePlugin.log(e); + } + } + } + } + protected void fullBuild(final IProgressMonitor monitor) throws CoreException { try { diff --git a/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF index 876a5db02d7..9d5357d0a0f 100644 --- a/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF +++ b/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF @@ -9,7 +9,10 @@ Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.core.resources, org.eclipse.cdt.core;bundle-version="5.1.0", - org.eclipse.cdt.codan.core;bundle-version="1.0.0" + org.eclipse.cdt.codan.core;bundle-version="1.0.0", + org.eclipse.cdt.ui;bundle-version="5.1.0", + org.eclipse.ui.workbench.texteditor;bundle-version="3.5.0", + org.eclipse.ui.editors;bundle-version="3.5.0" Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy diff --git a/codan/org.eclipse.cdt.codan.ui/plugin.xml b/codan/org.eclipse.cdt.codan.ui/plugin.xml index c4c7b989aea..eff5ea69576 100644 --- a/codan/org.eclipse.cdt.codan.ui/plugin.xml +++ b/codan/org.eclipse.cdt.codan.ui/plugin.xml @@ -62,4 +62,9 @@ class="org.eclipse.cdt.codan.internal.ui.preferences.PreferenceInitializer"> + + + diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Activator.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Activator.java index 4a44a4b4b23..849993afa61 100644 --- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Activator.java +++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Activator.java @@ -10,13 +10,11 @@ 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 */ @@ -25,7 +23,10 @@ public class Activator extends AbstractUIPlugin { /* * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext + * ) */ public void start(BundleContext context) throws Exception { super.start(context); @@ -34,7 +35,10 @@ public class Activator extends AbstractUIPlugin { /* * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext + * ) */ public void stop(BundleContext context) throws Exception { plugin = null; @@ -43,7 +47,7 @@ public class Activator extends AbstractUIPlugin { /** * Returns the shared instance - * + * * @return the shared instance */ public static Activator getDefault() { @@ -51,10 +55,11 @@ public class Activator extends AbstractUIPlugin { } /** - * Returns an image descriptor for the image file at the given - * plug-in relative path - * - * @param path the path + * 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) { diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanCReconciler.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanCReconciler.java new file mode 100644 index 00000000000..23394d4d821 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CodanCReconciler.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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.builder.CodanBuilder; +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) { + new CodanBuilder().reconcileAst(ast, progressMonitor); + System.err.println("ast reconsiled"); + } +} diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Startup.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Startup.java new file mode 100644 index 00000000000..41fbf89fdc6 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/Startup.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * 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); + } + } + }); + } +}