mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
- added running checkers on AST reconcile (while typing)
This commit is contained in:
parent
eaeddf5e8b
commit
19caf501e5
6 changed files with 220 additions and 11 deletions
|
@ -10,18 +10,26 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.builder;
|
package org.eclipse.cdt.codan.core.builder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||||
import org.eclipse.cdt.codan.core.model.CheckersRegisry;
|
import org.eclipse.cdt.codan.core.model.CheckersRegisry;
|
||||||
import org.eclipse.cdt.codan.core.model.CodanRuntime;
|
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.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.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.IResourceDelta;
|
import org.eclipse.core.resources.IResourceDelta;
|
||||||
import org.eclipse.core.resources.IResourceDeltaVisitor;
|
import org.eclipse.core.resources.IResourceDeltaVisitor;
|
||||||
import org.eclipse.core.resources.IResourceVisitor;
|
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.IncrementalProjectBuilder;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
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)
|
protected void fullBuild(final IProgressMonitor monitor)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -9,7 +9,10 @@ Require-Bundle: org.eclipse.ui,
|
||||||
org.eclipse.core.runtime,
|
org.eclipse.core.runtime,
|
||||||
org.eclipse.core.resources,
|
org.eclipse.core.resources,
|
||||||
org.eclipse.cdt.core;bundle-version="5.1.0",
|
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-RequiredExecutionEnvironment: J2SE-1.5
|
||||||
Bundle-ActivationPolicy: lazy
|
Bundle-ActivationPolicy: lazy
|
||||||
|
|
||||||
|
|
|
@ -62,4 +62,9 @@
|
||||||
class="org.eclipse.cdt.codan.internal.ui.preferences.PreferenceInitializer">
|
class="org.eclipse.cdt.codan.internal.ui.preferences.PreferenceInitializer">
|
||||||
</initializer>
|
</initializer>
|
||||||
</extension>
|
</extension>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.ui.startup">
|
||||||
|
<startup
|
||||||
|
class="org.eclipse.cdt.codan.ui.Startup"></startup>
|
||||||
|
</extension>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
@ -10,13 +10,11 @@ import org.osgi.framework.BundleContext;
|
||||||
* The activator class controls the plug-in life cycle
|
* The activator class controls the plug-in life cycle
|
||||||
*/
|
*/
|
||||||
public class Activator extends AbstractUIPlugin {
|
public class Activator extends AbstractUIPlugin {
|
||||||
|
|
||||||
// The plug-in ID
|
// The plug-in ID
|
||||||
public static final String PLUGIN_ID = "org.eclipse.cdt.codan.ui";
|
public static final String PLUGIN_ID = "org.eclipse.cdt.codan.ui";
|
||||||
|
|
||||||
// The shared instance
|
// The shared instance
|
||||||
private static Activator plugin;
|
private static Activator plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor
|
* The constructor
|
||||||
*/
|
*/
|
||||||
|
@ -25,7 +23,10 @@ public class Activator extends AbstractUIPlugin {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (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 {
|
public void start(BundleContext context) throws Exception {
|
||||||
super.start(context);
|
super.start(context);
|
||||||
|
@ -34,7 +35,10 @@ public class Activator extends AbstractUIPlugin {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (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 {
|
public void stop(BundleContext context) throws Exception {
|
||||||
plugin = null;
|
plugin = null;
|
||||||
|
@ -43,7 +47,7 @@ public class Activator extends AbstractUIPlugin {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the shared instance
|
* Returns the shared instance
|
||||||
*
|
*
|
||||||
* @return the shared instance
|
* @return the shared instance
|
||||||
*/
|
*/
|
||||||
public static Activator getDefault() {
|
public static Activator getDefault() {
|
||||||
|
@ -51,10 +55,11 @@ public class Activator extends AbstractUIPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an image descriptor for the image file at the given
|
* Returns an image descriptor for the image file at the given plug-in
|
||||||
* plug-in relative path
|
* relative path
|
||||||
*
|
*
|
||||||
* @param path the path
|
* @param path
|
||||||
|
* the path
|
||||||
* @return the image descriptor
|
* @return the image descriptor
|
||||||
*/
|
*/
|
||||||
public static ImageDescriptor getImageDescriptor(String path) {
|
public static ImageDescriptor getImageDescriptor(String path) {
|
||||||
|
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue