diff --git a/codan/org.eclipse.cdt.codan.core/schema/checkers.exsd b/codan/org.eclipse.cdt.codan.core/schema/checkers.exsd index 6634a51baf2..bd88d43bc8a 100644 --- a/codan/org.eclipse.cdt.codan.core/schema/checkers.exsd +++ b/codan/org.eclipse.cdt.codan.core/schema/checkers.exsd @@ -168,6 +168,56 @@ where xxx what checker would post as an argument for the problem. + + + + Example parameter for 'messagePattern' (with position 0.) This value is used only in the "Code Analysis" Preference UI to provide some context to the message shown for a particular problem. + + + + + + + + + + Example parameter for 'messagePattern' (with position 1.) This value is used only in the "Code Analysis" Preference UI to provide some context to the message shown for a particular problem. + + + + + + + + + + Example parameter for 'messagePattern' (with position 2.) This value is used only in the "Code Analysis" Preference UI to provide some context to the message shown for a particular problem. + + + + + + + + + + Example parameter for 'messagePattern' (with position 3.) This value is used only in the "Code Analysis" Preference UI to provide some context to the message shown for a particular problem. + + + + + + + + + + Example parameter for 'messagePattern' (with position 4.) This value is used only in the "Code Analysis" Preference UI to provide some context to the message shown for a particular problem. + + + + + + diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java index d12806da4ce..5d6ac5968af 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Alena Laskavaia + * Copyright (c) 2009, 2011 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 + * Alena Laskavaia - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.core.model; @@ -20,20 +20,20 @@ import org.eclipse.cdt.codan.core.param.IProblemPreference; * determined by runtime. If it is the case - two Problems should be created * (i.e. one for error and one for warning). All of problem attributes are * defined in a checker extension point. - * + * *

* 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. *

- * + * * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ public interface IProblem extends IProblemElement { /** * Name of the problem - user visible "title", not the message - * + * * @return title of the problem */ String getName(); @@ -41,50 +41,60 @@ public interface IProblem extends IProblemElement { /** * Unique problem id. Should be qualified by plugin name to maintain * uniqueness. - * + * * @return unique problem id */ String getId(); /** - * Is enabled in current context (usually within profile) - * + * Returns true if the problem is enabled in current context + * (usually within profile) + * * @return true if enabled */ boolean isEnabled(); /** - * Get current severity - * + * Returns current severity + * * @return severity */ CodanSeverity getSeverity(); /** * Message pattern, java patter like 'Variable {0} is never used here' - * + * * @return pattern */ String getMessagePattern(); /** - * Get root preference descriptor or null if not defined (used by ui to + * Returns the example parameters to use with {@link #getMessagePattern()}. + * These parameters are used only in the "Code Analysis" Preference UI. + * + * @return example parameters + * @since 2.0 + */ + public String[] getExampleMessageParameters(); + + /** + * Returns root preference descriptor or null if not defined (used by UI to * generate user controls for changing parameters) - * + * * @return root preference or null */ public IProblemPreference getPreference(); /** - * Get short description of a problem - * + * Returns short description of a problem + * * @return description */ public String getDescription(); /** - * Return marker id for the problem - * + * Returns marker id for the problem + * * @return marker id */ public String getMarkerType(); diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegistry.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegistry.java index a8e23546252..b213202e964 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegistry.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegistry.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Alena Laskavaia + * Copyright (c) 2009, 2011 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 + * Alena Laskavaia - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.internal.core; @@ -86,18 +86,15 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { processChecker(configurationElement); } // init parameters for checkers with parameters - for (Iterator iterator = problemList.keySet().iterator(); iterator - .hasNext();) { + for (Iterator iterator = problemList.keySet().iterator(); iterator.hasNext();) { IChecker c = iterator.next(); if (c instanceof ICheckerWithPreferences) { Collection list = problemList.get(c); - for (Iterator iterator2 = list.iterator(); iterator2 - .hasNext();) { + for (Iterator iterator2 = list.iterator(); iterator2.hasNext();) { IProblem p = iterator2.next(); if (p instanceof IProblemWorkingCopy) { try { - ((ICheckerWithPreferences) c) - .initPreferences((IProblemWorkingCopy) p); + ((ICheckerWithPreferences) c).initPreferences((IProblemWorkingCopy) p); } catch (Throwable t) { t.printStackTrace(); CodanCorePlugin.log(t); @@ -140,19 +137,16 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { name = id; IChecker checkerObj = null; try { - Object checker = configurationElement - .createExecutableExtension("class"); //$NON-NLS-1$ + Object checker = configurationElement.createExecutableExtension("class"); //$NON-NLS-1$ checkerObj = (IChecker) checker; addChecker(checkerObj); } catch (CoreException e) { CodanCorePlugin.log(e); return; } - IConfigurationElement[] children1 = configurationElement - .getChildren("problemRef"); //$NON-NLS-1$ boolean hasRef = false; - IConfigurationElement[] children2 = configurationElement - .getChildren(PROBLEM_ELEMENT); + IConfigurationElement[] children2 = + configurationElement.getChildren(PROBLEM_ELEMENT); if (children2 != null) { for (IConfigurationElement ref : children2) { IProblem p = processProblem(ref); @@ -160,11 +154,12 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { hasRef = true; } } + IConfigurationElement[] children1 = + configurationElement.getChildren("problemRef"); //$NON-NLS-1$ if (children1 != null) { for (IConfigurationElement ref : children1) { hasRef = true; - IProblem p = getDefaultProfile().findProblem( - ref.getAttribute("refId")); //$NON-NLS-1$ + IProblem p = getDefaultProfile().findProblem(ref.getAttribute("refId")); //$NON-NLS-1$ addRefProblem(checkerObj, p); } } @@ -183,8 +178,7 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { * @param configurationElement * @return */ - private CodanProblem processProblem( - IConfigurationElement configurationElement) { + private CodanProblem processProblem(IConfigurationElement configurationElement) { if (configurationElement.getName().equals(PROBLEM_ELEMENT)) { String id = getAtt(configurationElement, ID_ATTR); if (id == null) @@ -199,9 +193,15 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { String enab = getAtt(configurationElement, "defaultEnabled", false); //$NON-NLS-1$ String sev = getAtt(configurationElement, "defaultSeverity", false); //$NON-NLS-1$ String patt = getAtt(configurationElement, "messagePattern", false); //$NON-NLS-1$ + ArrayList exampleParams = new ArrayList(); + for (int i = 0; ; i++) { + String param = configurationElement.getAttribute("exampleParam" + i); //$NON-NLS-1$ + if (param == null) + break; + exampleParams.add(param); + } String desc = getAtt(configurationElement, "description", false); //$NON-NLS-1$ - String markerType = getAtt(configurationElement, - "markerType", false); //$NON-NLS-1$ + String markerType = getAtt(configurationElement, "markerType", false); //$NON-NLS-1$ if (enab != null) { p.setEnabled(Boolean.valueOf(enab)); } @@ -213,6 +213,9 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { if (patt != null) { p.setMessagePattern(patt); } + if (!exampleParams.isEmpty()) { + p.setExampleMessageParameters(exampleParams.toArray(new String[exampleParams.size()])); + } if (markerType != null) { p.setMarkerType(markerType); } @@ -232,21 +235,25 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { String name, boolean req) { String elementValue = configurationElement.getAttribute(name); if (elementValue == null && req) - CodanCorePlugin - .log("Extension " + configurationElement.getDeclaringExtension().getUniqueIdentifier() //$NON-NLS-1$ - + " missing required attribute: " + configurationElement.getName() + "." + name); //$NON-NLS-1$ //$NON-NLS-2$ + CodanCorePlugin.log("Extension " //$NON-NLS-1$ + + configurationElement.getDeclaringExtension().getUniqueIdentifier() + + " missing required attribute: " + configurationElement.getName() //$NON-NLS-1$ + + "." + name); //$NON-NLS-1$ return elementValue; } /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#iterator() */ public Iterator iterator() { return checkers.iterator(); } + /** + * @return the singleton checkers registry + */ public static CheckersRegistry getInstance() { if (instance == null) return new CheckersRegistry(); @@ -255,7 +262,7 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { /* * (non-Javadoc) - * + * * @see * org.eclipse.cdt.codan.core.model.ICheckersRegistry#addChecker(org.eclipse * .cdt.codan.core.model.IChecker) @@ -266,7 +273,7 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { /* * (non-Javadoc) - * + * * @see * org.eclipse.cdt.codan.core.model.ICheckersRegistry#addProblem(org.eclipse * .cdt.codan.core.model.IProblem, java.lang.String) @@ -280,7 +287,7 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { /* * (non-Javadoc) - * + * * @see * org.eclipse.cdt.codan.core.model.ICheckersRegistry#addCategory(org.eclipse * .cdt.codan.core.model.IProblemCategory, java.lang.String) @@ -294,7 +301,7 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { /* * (non-Javadoc) - * + * * @see * org.eclipse.cdt.codan.core.model.ICheckersRegistry#addRefProblem(org. * eclipse.cdt.codan.core.model.IChecker, @@ -311,7 +318,7 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { /** * Returns list of problems registered for given checker - * + * * @return collection of problems or null */ public Collection getRefProblems(IChecker checker) { @@ -320,7 +327,7 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { /* * (non-Javadoc) - * + * * @see * org.eclipse.cdt.codan.core.model.ICheckersRegistry#getDefaultProfile() */ @@ -330,7 +337,7 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { /* * (non-Javadoc) - * + * * @see * org.eclipse.cdt.codan.core.model.ICheckersRegistry#getWorkspaceProfile() */ @@ -361,7 +368,7 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { /* * (non-Javadoc) - * + * * @see * org.eclipse.cdt.codan.core.model.ICheckersRegistry#getResourceProfile * (org.eclipse.core.resources.IResource) @@ -373,18 +380,17 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { try { prof = (IProblemProfile) getWorkspaceProfile().clone(); // load default values - CodanPreferencesLoader loader = new CodanPreferencesLoader( - prof); - Preferences projectNode = CodanPreferencesLoader - .getProjectNode((IProject) element); - boolean useWorkspace = projectNode.getBoolean( - PreferenceConstants.P_USE_PARENT, false); + CodanPreferencesLoader loader = new CodanPreferencesLoader(prof); + Preferences projectNode = + CodanPreferencesLoader.getProjectNode((IProject) element); + boolean useWorkspace = projectNode.getBoolean(PreferenceConstants.P_USE_PARENT, + false); if (!useWorkspace) { loader.load(projectNode); } profiles.put(element, prof); } catch (CloneNotSupportedException e) { - // cant + // can't } } else if (element.getParent() != null) { prof = getResourceProfile(element.getParent()); @@ -398,34 +404,32 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { /* * (non-Javadoc) - * + * * @seeorg.eclipse.cdt.codan.core.model.ICheckersRegistry# * getResourceProfileWorkingCopy(org.eclipse.core.resources.IResource) */ public IProblemProfile getResourceProfileWorkingCopy(IResource element) { try { - IProblemProfile prof = (IProblemProfile) getResourceProfile(element) - .clone(); + IProblemProfile prof = (IProblemProfile) getResourceProfile(element).clone(); return prof; } catch (CloneNotSupportedException e) { - // cant + // can't return null; } } /** - * Test if checker is enabled (needs to be run) or not. Checker is enabled - * if at least one problem it prints is enabled. - * + * Tests if a checker is enabled (needs to be run) or not. Checker is enabled + * if at least one problem it reports is enabled. + * * @param checker * @param resource - * @return + * @return true if the checker is enabled */ public boolean isCheckerEnabled(IChecker checker, IResource resource) { IProblemProfile resourceProfile = getResourceProfile(resource); Collection refProblems = getRefProblems(checker); - for (Iterator iterator = refProblems.iterator(); iterator - .hasNext();) { + for (Iterator iterator = refProblems.iterator(); iterator.hasNext();) { IProblem p = iterator.next(); // we need to check problem enablement in particular profile IProblem problem = resourceProfile.findProblem(p.getId()); @@ -439,15 +443,15 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { } /** - * Test if checker need to run in specific launch mode - * + * Tests if a checker needs to run in a specific launch mode. + * * @param checker * @param resource * @param mode - * @return + * @return true if the checker should run. */ - public boolean isCheckerEnabledForLaunchMode(IChecker checker, - IResource resource, CheckerLaunchMode mode) { + public boolean isCheckerEnabledForLaunchMode(IChecker checker, IResource resource, + CheckerLaunchMode mode) { IProblemProfile resourceProfile = getResourceProfile(resource); Collection refProblems = getRefProblems(checker); boolean enabled = false; @@ -459,13 +463,10 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { if (problem == null) throw new IllegalArgumentException("Id is not registered"); //$NON-NLS-1$ if (checker instanceof AbstractCheckerWithProblemPreferences) { - MapProblemPreference map = (MapProblemPreference) problem - .getPreference(); - IProblemPreference pref1 = map - .getChildDescriptor(LaunchTypeProblemPreference.KEY); + MapProblemPreference map = (MapProblemPreference) problem.getPreference(); + IProblemPreference pref1 = map.getChildDescriptor(LaunchTypeProblemPreference.KEY); LaunchTypeProblemPreference pref = (LaunchTypeProblemPreference) pref1; - if (pref == null - || pref.isRunningInMode(CheckerLaunchMode.USE_PARENT)) { + if (pref == null || pref.isRunningInMode(CheckerLaunchMode.USE_PARENT)) { enabled = true; break; } @@ -479,7 +480,7 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { } /** - * @return + * @return the number of checkers */ public int getCheckersSize() { return checkers.size(); diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanProblem.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanProblem.java index 98738bc3646..6dcbc3361dd 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanProblem.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanProblem.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Alena Laskavaia + * Copyright (c) 2009, 2011 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 + * Alena Laskavaia - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.internal.core.model; @@ -15,21 +15,30 @@ import org.eclipse.cdt.codan.core.model.IProblemReporter; import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy; import org.eclipse.cdt.codan.core.param.IProblemPreference; +/** + * A type of problems reported by Codan. + */ public class CodanProblem implements IProblemWorkingCopy, Cloneable { + private String id; private String name; - private String message; + private String messagePattern; private CodanSeverity severity = CodanSeverity.Warning; private boolean enabled = true; private IProblemPreference preference; private boolean frozen; private String description; private String markerType = IProblemReporter.GENERIC_CODE_ANALYSIS_MARKER_TYPE; + private String[] exampleParams = { "X", "Y", "Z", "U", "V" }; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$ public CodanSeverity getSeverity() { return severity; } + /** + * @param problemId - the ID of the problem + * @param name - the name of the problem + */ public CodanProblem(String problemId, String name) { this.id = problemId; this.name = name; @@ -65,7 +74,7 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable { /* * (non-Javadoc) - * + * * @see java.lang.Object#clone() */ @Override @@ -92,11 +101,11 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable { /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.codan.core.model.IProblem#getMessagePattern() */ public String getMessagePattern() { - return message; + return messagePattern; } protected void freeze() { @@ -104,12 +113,12 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable { } /** - * @param message - * the message to set + * @param messagePattern + * the message to set */ - public void setMessagePattern(String message) { + public void setMessagePattern(String messagePattern) { checkSet(); - this.message = message; + this.messagePattern = messagePattern; } protected void checkSet() { @@ -119,7 +128,7 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable { /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.codan.core.model.IProblem#getDescription() */ public String getDescription() { @@ -128,7 +137,7 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable { /* * (non-Javadoc) - * + * * @see * org.eclipse.cdt.codan.core.model.IProblemWorkingCopy#setDescription(java * .lang.String) @@ -139,14 +148,40 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable { /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.codan.core.model.IProblem#getMarkerType() */ public String getMarkerType() { return markerType; } - public void setMarkerType(String type) { - markerType = type; + /** + * Sets the marker id for the problem. + + * @param markerType + */ + public void setMarkerType(String markerType) { + this.markerType = markerType; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.codan.core.model.IProblem#getExampleParameters() + */ + public String[] getExampleMessageParameters() { + return exampleParams.clone(); + } + + /** + * Sets an example message parameter to use with {@link #getMessagePattern()}. + * + * @param exampleParameters - the example message parameters to set, + * e.g. { "<variable_name>" }. + * @see #getExampleMessageParameters() + */ + public void setExampleMessageParameters(String[] exampleParameters) { + checkSet(); + this.exampleParams = exampleParameters; } } diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java index d5cc67dd97f..de78de9c748 100644 --- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java +++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Alena Laskavaia + * Copyright (c) 2009, 2011 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 + * Alena Laskavaia - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.internal.ui.preferences; @@ -17,7 +17,6 @@ import org.eclipse.cdt.codan.core.CodanRuntime; import org.eclipse.cdt.codan.core.model.ICheckersRegistry; import org.eclipse.cdt.codan.core.model.IProblem; import org.eclipse.cdt.codan.core.model.IProblemProfile; -import org.eclipse.cdt.codan.core.param.IProblemPreference; import org.eclipse.cdt.codan.internal.ui.CodanUIActivator; import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; import org.eclipse.cdt.codan.internal.ui.dialogs.CustomizeProblemDialog; @@ -55,29 +54,27 @@ import org.eclipse.ui.preferences.ScopedPreferenceStore; * preference store that belongs to the main plug-in class. That way, * preferences can be accessed directly via the preference store. */ -public class CodanPreferencePage extends FieldEditorOverlayPage implements - IWorkbenchPreferencePage { +public class CodanPreferencePage extends FieldEditorOverlayPage implements IWorkbenchPreferencePage { private IProblemProfile profile; private ISelectionChangedListener problemSelectionListener; private IProblem selectedProblem; private Group info; private Label infoDesc; private Label infoMessage; - //private Label infoParams; + // private Label infoParams; private Button infoButton; private ProblemsTreeEditor checkedTreeEditor; public CodanPreferencePage() { super(GRID); - setPreferenceStore(new ScopedPreferenceStore(new InstanceScope(), + setPreferenceStore(new ScopedPreferenceStore(InstanceScope.INSTANCE, CodanCorePlugin.PLUGIN_ID)); // setDescription("Code Analysis Preference Page"); problemSelectionListener = new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (info != null) { if (event.getSelection() instanceof ITreeSelection) { - ITreeSelection s = (ITreeSelection) event - .getSelection(); + ITreeSelection s = (ITreeSelection) event.getSelection(); if (s.getFirstElement() instanceof IProblem) setSelectedProblem((IProblem) s.getFirstElement()); else @@ -100,8 +97,7 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements */ @Override public void createFieldEditors() { - checkedTreeEditor = new ProblemsTreeEditor(getFieldEditorParent(), - profile); + checkedTreeEditor = new ProblemsTreeEditor(getFieldEditorParent(), profile); addField(checkedTreeEditor); checkedTreeEditor.getTreeViewer().addSelectionChangedListener( problemSelectionListener); @@ -111,11 +107,9 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements openCustomizeDialog(); } }); - GridData layoutData = new GridData(GridData.FILL, GridData.FILL, true, - true); + GridData layoutData = new GridData(GridData.FILL, GridData.FILL, true, true); layoutData.heightHint = 400; - checkedTreeEditor.getTreeViewer().getControl() - .setLayoutData(layoutData); + checkedTreeEditor.getTreeViewer().getControl().setLayoutData(layoutData); } /* @@ -127,9 +121,9 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements */ @Override protected Control createContents(Composite parent) { - profile = isPropertyPage() ? getRegistry() - .getResourceProfileWorkingCopy((IResource) getElement()) - : getRegistry().getWorkspaceProfile(); + profile = isPropertyPage() ? + getRegistry().getResourceProfileWorkingCopy((IResource) getElement()) : + getRegistry().getWorkspaceProfile(); Composite comp = (Composite) super.createContents(parent); createInfoControl(comp); return comp; @@ -143,10 +137,10 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements info.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); info.setLayout(new GridLayout(2, false)); info.setText(CodanUIMessages.CodanPreferencePage_Info); - GridDataFactory gdLab = GridDataFactory.swtDefaults() - .align(SWT.BEGINNING, SWT.BEGINNING).grab(false, false); - GridDataFactory gdFact = GridDataFactory.swtDefaults() - .align(SWT.BEGINNING, SWT.BEGINNING).grab(true, true); + GridDataFactory gdLab = + GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.BEGINNING).grab(false, false); + GridDataFactory gdFact = + GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.BEGINNING).grab(true, true); // message Label labelMessage = new Label(info, SWT.NONE); labelMessage.setText(CodanUIMessages.CodanPreferencePage_MessageLabel); @@ -154,9 +148,9 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements infoMessage = new Label(info, SWT.WRAP); infoMessage.setLayoutData(gdFact.copy().create()); // description - // Label labelDesc = new Label(info, SWT.NONE); - // labelDesc.setText(CodanUIMessages.CodanPreferencePage_Description); - // labelDesc.setLayoutData(gdLab.create()); +// Label labelDesc = new Label(info, SWT.NONE); +// labelDesc.setText(CodanUIMessages.CodanPreferencePage_Description); +// labelDesc.setLayoutData(gdLab.create()); infoDesc = new Label(info, SWT.WRAP); PixelConverter pixelConverter = new PixelConverter(comp); infoDesc.setLayoutData(gdFact @@ -166,14 +160,14 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements pixelConverter.convertHeightInCharsToPixels(3)) .create()); // params - // Label labelParams = new Label(info, SWT.NONE); - // labelParams.setText(CodanUIMessages.CodanPreferencePage_Parameters); - // labelParams.setLayoutData(gdLab.create()); - // infoParams = new Label(info, SWT.NONE); - // infoParams.setLayoutData(gdFact.create()); +// Label labelParams = new Label(info, SWT.NONE); +// labelParams.setText(CodanUIMessages.CodanPreferencePage_Parameters); +// labelParams.setLayoutData(gdLab.create()); +// infoParams = new Label(info, SWT.NONE); +// infoParams.setLayoutData(gdFact.create()); infoButton = new Button(info, SWT.PUSH); - infoButton.setLayoutData(GridDataFactory.swtDefaults().span(2, 1) - .align(SWT.END, SWT.BEGINNING).create()); + infoButton.setLayoutData( + GridDataFactory.swtDefaults().span(2, 1).align(SWT.END, SWT.BEGINNING).create()); infoButton.setText(CodanUIMessages.CodanPreferencePage_Customize); infoButton.addSelectionListener(new SelectionAdapter() { @Override @@ -212,20 +206,13 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements return super.performOk(); } - /** - * - */ private void saveWidgetValues() { - CodanUIActivator - .getDefault() - .getDialogSettings() - .put(getWidgetId(), - selectedProblem == null ? "" : selectedProblem.getId()); //$NON-NLS-1$ + CodanUIActivator.getDefault().getDialogSettings().put(getWidgetId(), + selectedProblem == null ? "" : selectedProblem.getId()); //$NON-NLS-1$ } private void restoreWidgetValues() { - String id = CodanUIActivator.getDefault().getDialogSettings() - .get(getWidgetId()); + String id = CodanUIActivator.getDefault().getDialogSettings().get(getWidgetId()); if (id != null && id.length() > 0 && checkedTreeEditor != null) { checkedTreeEditor.getTreeViewer().setSelection( new StructuredSelection(profile.findProblem(id)), true); @@ -241,30 +228,28 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements return getPageId() + ".selection"; //$NON-NLS-1$ } - /** - * - */ private void updateProblemInfo() { if (selectedProblem == null) { infoMessage.setText(""); //$NON-NLS-1$ infoDesc.setText(""); //$NON-NLS-1$ - //infoParams.setText(""); //$NON-NLS-1$ +// infoParams.setText(""); //$NON-NLS-1$ infoButton.setEnabled(false); } else { - IProblemPreference pref = selectedProblem.getPreference(); String description = selectedProblem.getDescription(); if (description == null) description = CodanUIMessages.CodanPreferencePage_NoInfo; + String messageToShow = CodanUIMessages.CodanPreferencePage_NoInfo; String messagePattern = selectedProblem.getMessagePattern(); - String message = CodanUIMessages.CodanPreferencePage_NoInfo; if (messagePattern != null) { - message = MessageFormat.format(messagePattern, "X", "Y", "Z"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Object[] exampleParams = selectedProblem.getExampleMessageParameters(); + messageToShow = MessageFormat.format(messagePattern, exampleParams); } - infoMessage.setText(message); + infoMessage.setText(messageToShow); infoDesc.setText(description); - // infoParams - // .setText(pref == null ? CodanUIMessages.CodanPreferencePage_NoInfo - // : CodanUIMessages.CodanPreferencePage_HasPreferences); +// IProblemPreference pref = selectedProblem.getPreference(); +// infoParams.setText(pref == null ? +// CodanUIMessages.CodanPreferencePage_NoInfo : +// CodanUIMessages.CodanPreferencePage_HasPreferences); infoButton.setEnabled(true); } info.layout(true); @@ -273,20 +258,16 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements /* * (non-Javadoc) * - * @see - * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) */ public void init(IWorkbench workbench) { } - /** - * - */ protected void openCustomizeDialog() { if (selectedProblem == null) return; - CustomizeProblemDialog d = new CustomizeProblemDialog(getShell(), - selectedProblem, (IResource) getElement()); - d.open(); + CustomizeProblemDialog dialog = new CustomizeProblemDialog(getShell(), selectedProblem, + (IResource) getElement()); + dialog.open(); } } \ No newline at end of file