mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
- added preference to disable check as you type
This commit is contained in:
parent
25406f96bc
commit
7fa181c4b6
9 changed files with 121 additions and 62 deletions
|
@ -10,37 +10,22 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.cxx.internal.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.cdt.codan.internal.core.CodanBuilder;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author Alena
|
||||
*
|
||||
*/
|
||||
|
||||
public class CxxCodanRenciler {
|
||||
public class CxxCodanReconciler {
|
||||
private CodanBuilder builder = new CodanBuilder();
|
||||
|
||||
public void reconciledAst(IASTTranslationUnit ast, IProgressMonitor monitor) {
|
||||
public void reconciledAst(IASTTranslationUnit ast, IResource resource,
|
||||
IProgressMonitor monitor) {
|
||||
if (ast == null)
|
||||
return;
|
||||
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];
|
||||
builder.runInEditor(ast, resource, monitor);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
</extension>
|
||||
<extension
|
||||
id="codanNature"
|
||||
name="CDT Code Analysis Nature"
|
||||
name="Code Analysis Nature"
|
||||
point="org.eclipse.core.resources.natures">
|
||||
<runtime>
|
||||
<run
|
||||
|
|
|
@ -13,13 +13,14 @@ package org.eclipse.cdt.codan.core;
|
|||
/**
|
||||
* Constant definitions for plug-in preferences
|
||||
* <p>
|
||||
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
|
||||
* part of a work in progress. There is no guarantee that this API will
|
||||
* work or that it will remain the same.
|
||||
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as part
|
||||
* of a work in progress. There is no guarantee that this API will work or that
|
||||
* it will remain the same.
|
||||
* </p>
|
||||
*/
|
||||
public class PreferenceConstants {
|
||||
public static final String P_RUN_ON_BUILD = "booleanPreference"; //$NON-NLS-1$
|
||||
public static final String P_RUN_ON_BUILD = "onBuild"; //$NON-NLS-1$
|
||||
public static final String P_RUN_IN_EDITOR = "inEditor"; //$NON-NLS-1$
|
||||
public static final String P_PROBLEMS = "problems"; //$NON-NLS-1$
|
||||
public static final String P_USE_PARENT = "useParentScope"; //$NON-NLS-1$
|
||||
}
|
||||
|
|
|
@ -30,13 +30,12 @@ import org.eclipse.cdt.codan.internal.core.model.CodanProblemCategory;
|
|||
import org.eclipse.cdt.codan.internal.core.model.ProblemProfile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.osgi.service.prefs.Preferences;
|
||||
|
||||
public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
|
||||
private static final String NAME_ATTR = "name"; //$NON-NLS-1$
|
||||
|
@ -324,7 +323,7 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
|
|||
wp = (IProblemProfile) getDefaultProfile().clone();
|
||||
// load default values
|
||||
CodanPreferencesLoader loader = new CodanPreferencesLoader(wp);
|
||||
loader.load(CodanCorePlugin.getDefault().getStorePreferences());
|
||||
loader.load(loader.getWorkspaceNode());
|
||||
} catch (CloneNotSupportedException e) {
|
||||
wp = getDefaultProfile();
|
||||
}
|
||||
|
@ -358,13 +357,12 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
|
|||
// load default values
|
||||
CodanPreferencesLoader loader = new CodanPreferencesLoader(
|
||||
prof);
|
||||
IEclipsePreferences node = new ProjectScope(
|
||||
(IProject) element)
|
||||
.getNode(CodanCorePlugin.PLUGIN_ID);
|
||||
boolean useWorkspace = node.getBoolean(
|
||||
Preferences projectNode = loader
|
||||
.getProjectNode((IProject) element);
|
||||
boolean useWorkspace = projectNode.getBoolean(
|
||||
PreferenceConstants.P_USE_PARENT, false);
|
||||
if (!useWorkspace) {
|
||||
loader.load(node);
|
||||
loader.load(projectNode);
|
||||
}
|
||||
profiles.put(element, prof);
|
||||
} catch (CloneNotSupportedException e) {
|
||||
|
|
|
@ -10,11 +10,15 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.internal.core;
|
||||
|
||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemProfile;
|
||||
import org.eclipse.cdt.codan.internal.core.model.CodanProblem;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.osgi.service.prefs.Preferences;
|
||||
|
||||
/**
|
||||
* @author Alena
|
||||
|
@ -54,7 +58,8 @@ public class CodanPreferencesLoader {
|
|||
*/
|
||||
public void setProperty(String id, String s) {
|
||||
IProblem prob = baseModel.findProblem(id);
|
||||
if (!(prob instanceof CodanProblem)) return;
|
||||
if (!(prob instanceof CodanProblem))
|
||||
return;
|
||||
String sevs = s;
|
||||
boolean enabled = true;
|
||||
if (sevs.startsWith("-")) { //$NON-NLS-1$
|
||||
|
@ -94,7 +99,8 @@ public class CodanPreferencesLoader {
|
|||
*/
|
||||
public String getProperty(String id) {
|
||||
IProblem prob = baseModel.findProblem(id);
|
||||
if (!(prob instanceof CodanProblem)) return null;
|
||||
if (!(prob instanceof CodanProblem))
|
||||
return null;
|
||||
String enabled = prob.isEnabled() ? "" : "-"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
String severity = prob.getSeverity().toString();
|
||||
String res = enabled + severity;
|
||||
|
@ -104,7 +110,7 @@ public class CodanPreferencesLoader {
|
|||
/**
|
||||
* @param storePreferences
|
||||
*/
|
||||
public void load(IEclipsePreferences storePreferences) {
|
||||
public void load(Preferences storePreferences) {
|
||||
IProblem[] probs = getProblems();
|
||||
for (int i = 0; i < probs.length; i++) {
|
||||
String id = probs[i].getId();
|
||||
|
@ -114,4 +120,22 @@ public class CodanPreferencesLoader {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Preferences getProjectNode(IProject project) {
|
||||
if (!project.exists())
|
||||
return null;
|
||||
Preferences prefNode = new ProjectScope(project)
|
||||
.getNode(CodanCorePlugin.PLUGIN_ID);
|
||||
if (prefNode == null)
|
||||
return null;
|
||||
return prefNode;
|
||||
}
|
||||
|
||||
public static Preferences getWorkspaceNode() {
|
||||
Preferences prefNode = new InstanceScope()
|
||||
.getNode(CodanCorePlugin.PLUGIN_ID);
|
||||
if (prefNode == null)
|
||||
return null;
|
||||
return prefNode;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,11 +10,22 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.internal.ui.cxx;
|
||||
|
||||
import org.eclipse.cdt.codan.core.cxx.internal.model.CxxCodanRenciler;
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.cdt.codan.core.PreferenceConstants;
|
||||
import org.eclipse.cdt.codan.core.cxx.internal.model.CxxCodanReconciler;
|
||||
import org.eclipse.cdt.codan.internal.ui.CodanUIActivator;
|
||||
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.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
|
||||
/**
|
||||
|
@ -22,7 +33,7 @@ import org.eclipse.ui.texteditor.ITextEditor;
|
|||
*
|
||||
*/
|
||||
public class CodanCReconciler implements ICReconcilingListener {
|
||||
private CxxCodanRenciler reconsiler = new CxxCodanRenciler();
|
||||
private CxxCodanReconciler reconsiler = new CxxCodanReconciler();
|
||||
|
||||
void install(ITextEditor editor) {
|
||||
if (editor instanceof CEditor) {
|
||||
|
@ -66,7 +77,22 @@ public class CodanCReconciler implements ICReconcilingListener {
|
|||
*/
|
||||
public void reconciled(IASTTranslationUnit ast, boolean force,
|
||||
IProgressMonitor progressMonitor) {
|
||||
reconsiler.reconciledAst(ast, progressMonitor);
|
||||
// System.err.println("ast reconsiled");
|
||||
if (ast == null)
|
||||
return;
|
||||
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];
|
||||
IProject project = resource.getProject();
|
||||
IPreferenceStore store = CodanUIActivator.getDefault()
|
||||
.getPreferenceStore(project);
|
||||
if (store.getBoolean(PreferenceConstants.P_RUN_IN_EDITOR)) {
|
||||
reconsiler.reconciledAst(ast, resource, progressMonitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
package org.eclipse.cdt.codan.internal.ui;
|
||||
|
||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.preferences.IScopeContext;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
|
@ -14,6 +21,7 @@ public class CodanUIActivator extends AbstractUIPlugin {
|
|||
public static final String PLUGIN_ID = "org.eclipse.cdt.codan.ui";
|
||||
// The shared instance
|
||||
private static CodanUIActivator plugin;
|
||||
private IPreferenceStore preferenceCoreStore;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
|
@ -95,4 +103,22 @@ public class CodanUIActivator extends AbstractUIPlugin {
|
|||
public static void log(String message) {
|
||||
log(new Status(IStatus.ERROR, PLUGIN_ID, 1, message, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public IPreferenceStore getCorePreferenceStore() {
|
||||
if (preferenceCoreStore == null) {
|
||||
preferenceCoreStore = new ScopedPreferenceStore(
|
||||
new InstanceScope(), CodanCorePlugin.PLUGIN_ID);
|
||||
}
|
||||
return preferenceCoreStore;
|
||||
}
|
||||
|
||||
public IPreferenceStore getPreferenceStore(IProject project) {
|
||||
ProjectScope ps = new ProjectScope(project);
|
||||
ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, PLUGIN_ID);
|
||||
scoped.setSearchContexts(new IScopeContext[] { ps, new InstanceScope() });
|
||||
return scoped;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||
import org.eclipse.cdt.codan.core.PreferenceConstants;
|
||||
import org.eclipse.cdt.codan.internal.ui.CodanUIActivator;
|
||||
import org.eclipse.cdt.codan.internal.ui.actions.ToggleNatureAction;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.preferences.IScopeContext;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.jface.preference.BooleanFieldEditor;
|
||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.ui.IWorkbenchPropertyPage;
|
||||
import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
||||
|
||||
public class BuildPropertyPage extends FieldEditorPreferencePage implements
|
||||
IWorkbenchPropertyPage {
|
||||
|
@ -21,8 +18,7 @@ public class BuildPropertyPage extends FieldEditorPreferencePage implements
|
|||
*
|
||||
*/
|
||||
public BuildPropertyPage() {
|
||||
setPreferenceStore(org.eclipse.cdt.codan.internal.ui.CodanUIActivator.getDefault()
|
||||
.getPreferenceStore());
|
||||
setPreferenceStore(CodanUIActivator.getDefault().getPreferenceStore());
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -35,7 +31,9 @@ public class BuildPropertyPage extends FieldEditorPreferencePage implements
|
|||
@Override
|
||||
protected void createFieldEditors() {
|
||||
addField(new BooleanFieldEditor(PreferenceConstants.P_RUN_ON_BUILD,
|
||||
"&Run with Build", getFieldEditorParent()));
|
||||
"&Run with build", getFieldEditorParent()));
|
||||
addField(new BooleanFieldEditor(PreferenceConstants.P_RUN_IN_EDITOR,
|
||||
"Run as you &type (selected checkers)", getFieldEditorParent()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -70,7 +68,9 @@ public class BuildPropertyPage extends FieldEditorPreferencePage implements
|
|||
* @see org.eclipse.ui.IWorkbenchPropertyPage#getElement()
|
||||
*/
|
||||
public IAdaptable getElement() {
|
||||
return element;
|
||||
if (element.getAdapter(IProject.class) != null)
|
||||
return (IProject) element.getAdapter(IProject.class);
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -82,14 +82,12 @@ public class BuildPropertyPage extends FieldEditorPreferencePage implements
|
|||
*/
|
||||
public void setElement(IAdaptable element) {
|
||||
this.element = element;
|
||||
ProjectScope ps = new ProjectScope((IProject) getElement());
|
||||
ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps,
|
||||
CodanCorePlugin.PLUGIN_ID);
|
||||
scoped
|
||||
.setSearchContexts(new IScopeContext[] { ps,
|
||||
new InstanceScope() });
|
||||
if (getElement() != null) {
|
||||
IPreferenceStore scoped = CodanUIActivator.getDefault()
|
||||
.getPreferenceStore(((IProject) getElement()));
|
||||
setPreferenceStore(scoped);
|
||||
}
|
||||
}
|
||||
|
||||
protected String getPageId() {
|
||||
return "org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage";
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.codan.core.PreferenceConstants;
|
||||
import org.eclipse.cdt.codan.internal.ui.CodanUIActivator;
|
||||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
|
||||
|
@ -18,16 +19,16 @@ import org.eclipse.jface.preference.IPreferenceStore;
|
|||
* Class used to initialize default preference values.
|
||||
*/
|
||||
public class PreferenceInitializer extends AbstractPreferenceInitializer {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
|
||||
* @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#
|
||||
* initializeDefaultPreferences()
|
||||
*/
|
||||
public void initializeDefaultPreferences() {
|
||||
IPreferenceStore store = org.eclipse.cdt.codan.internal.ui.CodanUIActivator
|
||||
.getDefault().getPreferenceStore();
|
||||
IPreferenceStore store = CodanUIActivator.getDefault()
|
||||
.getPreferenceStore();
|
||||
store.setDefault(PreferenceConstants.P_RUN_ON_BUILD, false);
|
||||
store.setDefault(PreferenceConstants.P_RUN_IN_EDITOR, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue