diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanRenciler.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanReconciler.java similarity index 54% rename from codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanRenciler.java rename to codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanReconciler.java index aad4ddbac60..06be5d60bf2 100644 --- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanRenciler.java +++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanReconciler.java @@ -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); - } + builder.runInEditor(ast, resource, monitor); } } diff --git a/codan/org.eclipse.cdt.codan.core/plugin.xml b/codan/org.eclipse.cdt.codan.core/plugin.xml index af41945061e..c6127da064a 100644 --- a/codan/org.eclipse.cdt.codan.core/plugin.xml +++ b/codan/org.eclipse.cdt.codan.core/plugin.xml @@ -16,7 +16,7 @@ - * EXPERIMENTAL. 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. + * EXPERIMENTAL. 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. *

*/ 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$ } diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegisry.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegisry.java index d0030e42a9a..3f37a82432c 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegisry.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegisry.java @@ -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, ICheckersRegistry { private static final String NAME_ATTR = "name"; //$NON-NLS-1$ @@ -324,7 +323,7 @@ public class CheckersRegisry implements Iterable, 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, 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) { diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanPreferencesLoader.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanPreferencesLoader.java index 718311f005e..3f0d24d3478 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanPreferencesLoader.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanPreferencesLoader.java @@ -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; + } } diff --git a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanCReconciler.java b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanCReconciler.java index a94143c2734..ac9cd9ff1c1 100644 --- a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanCReconciler.java +++ b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanCReconciler.java @@ -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); + } + } } } diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIActivator.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIActivator.java index e59880165b9..6adfef50b48 100644 --- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIActivator.java +++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIActivator.java @@ -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; + } } diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/BuildPropertyPage.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/BuildPropertyPage.java index 31e90295204..8e4b9dc3c9d 100644 --- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/BuildPropertyPage.java +++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/BuildPropertyPage.java @@ -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,13 +82,11 @@ 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() }); - setPreferenceStore(scoped); + if (getElement() != null) { + IPreferenceStore scoped = CodanUIActivator.getDefault() + .getPreferenceStore(((IProject) getElement())); + setPreferenceStore(scoped); + } } protected String getPageId() { diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceInitializer.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceInitializer.java index 8994b27b264..50ae4a1805f 100644 --- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceInitializer.java +++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/PreferenceInitializer.java @@ -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); } - }