Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
authorAlena Laskavaia2010-03-22 03:23:46 +0000
committerAlena Laskavaia2010-03-22 03:23:46 +0000
commit53e15f64c29406af10b1e64a966cbdaf68b6f66f (patch)
tree6ce724e0fb442db8fb19e454127b4ec0f085aa8e /codan
parent92923566ce752894fc6ce7abd238dd85071e8d66 (diff)
downloadorg.eclipse.cdt-53e15f64c29406af10b1e64a966cbdaf68b6f66f.tar.gz
org.eclipse.cdt-53e15f64c29406af10b1e64a966cbdaf68b6f66f.tar.xz
org.eclipse.cdt-53e15f64c29406af10b1e64a966cbdaf68b6f66f.zip
- added limited support for string parameters
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractListParameterInfo.java13
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractProblemParameterInfo.java15
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemParameterInfo.java46
-rw-r--r--codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java70
-rw-r--r--codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ParametersComposite.java109
5 files changed, 214 insertions, 39 deletions
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractListParameterInfo.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractListParameterInfo.java
index a558268c8aa..73eab896a08 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractListParameterInfo.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractListParameterInfo.java
@@ -11,12 +11,14 @@
package org.eclipse.cdt.codan.core.model;
import java.util.ArrayList;
+import java.util.Iterator;
/**
* @author Alena
*
*/
-public class AbstractListParameterInfo extends AbstractProblemParameterInfo {
+public abstract class AbstractListParameterInfo extends
+ AbstractProblemParameterInfo {
protected ArrayList<IProblemParameterInfo> list = new ArrayList<IProblemParameterInfo>(
1);
@@ -27,8 +29,8 @@ public class AbstractListParameterInfo extends AbstractProblemParameterInfo {
* org.eclipse.cdt.codan.core.model.AbstractProblemParameterInfo#getType()
*/
@Override
- public String getType() {
- return TYPE_LIST;
+ public ParameterTypes getType() {
+ return ParameterTypes.TYPE_LIST;
}
/**
@@ -71,4 +73,9 @@ public class AbstractListParameterInfo extends AbstractProblemParameterInfo {
protected IProblemParameterInfo getElement(int i) {
return list.get(i);
}
+
+ @Override
+ public Iterator<IProblemParameterInfo> getIterator() {
+ return list.iterator();
+ }
}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractProblemParameterInfo.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractProblemParameterInfo.java
index 18954539e84..3f5e7b72b1d 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractProblemParameterInfo.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractProblemParameterInfo.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.cdt.codan.core.model;
+import java.util.Iterator;
+
/**
* Default implementation for single parameter checker of type string.
*
@@ -32,8 +34,8 @@ public abstract class AbstractProblemParameterInfo implements
*
* @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getType()
*/
- public String getType() {
- return TYPE_STRING;
+ public ParameterTypes getType() {
+ return ParameterTypes.TYPE_STRING;
}
/*
@@ -73,4 +75,13 @@ public abstract class AbstractProblemParameterInfo implements
public String getToolTip() {
return null;
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getIterator()
+ */
+ public Iterator<IProblemParameterInfo> getIterator() {
+ return null;
+ }
}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemParameterInfo.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemParameterInfo.java
index 2c918f605f3..2d01d791b43 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemParameterInfo.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemParameterInfo.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.cdt.codan.core.model;
+import java.util.Iterator;
+
/**
* Problem parameter usually key=value settings that allows to alter checker
* behaviour for given problem. For example if checker finds violation of naming
@@ -23,12 +25,34 @@ package org.eclipse.cdt.codan.core.model;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IProblemParameterInfo {
- final static String TYPE_STRING = "string"; //$NON-NLS-1$
- final static String TYPE_INTEGER = "integer"; //$NON-NLS-1$
- final static String TYPE_BOOLEAN = "boolean"; //$NON-NLS-1$
- final static String TYPE_FILE = "file"; //$NON-NLS-1$
- final static String TYPE_LIST = "list"; //$NON-NLS-1$
- final static String TYPE_HASH = "hash"; //$NON-NLS-1$
+ enum ParameterTypes {
+ TYPE_STRING("string"), //$NON-NLS-1$
+ TYPE_INTEGER("integer"), //$NON-NLS-1$
+ TYPE_BOOLEAN("boolean"), //$NON-NLS-1$
+ TYPE_FILE("file"), //$NON-NLS-1$
+ TYPE_LIST("list"), //$NON-NLS-1$
+ TYPE_HASH("hash"); //$NON-NLS-1$
+ private String literal;
+
+ private ParameterTypes(String literal) {
+ this.literal = literal;
+ }
+
+ public static ParameterTypes valueOfLiteral(String name) {
+ ParameterTypes[] values = values();
+ for (int i = 0; i < values.length; i++) {
+ ParameterTypes e = values[i];
+ if (e.literal.equals(name))
+ return e;
+ }
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return literal;
+ }
+ }
String getKey();
@@ -40,7 +64,7 @@ public interface IProblemParameterInfo {
*
* @return string value of the type
*/
- String getType();
+ ParameterTypes getType();
/**
* Additional info on how it is represented in the ui, for example boolean
@@ -73,4 +97,12 @@ public interface IProblemParameterInfo {
* @return
*/
IProblemParameterInfo getElement(String key);
+
+ /**
+ * Available if type is list or hash. Returns iterator over parameter values
+ * for list and hash.
+ *
+ * @return
+ */
+ Iterator<IProblemParameterInfo> getIterator();
}
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 5f6d2b23a8b..cc899afee5f 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
@@ -15,6 +15,7 @@ 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.model.IProblemWorkingCopy;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -45,31 +46,29 @@ import org.eclipse.ui.preferences.ScopedPreferenceStore;
public class CodanPreferencePage extends FieldEditorOverlayPage implements
IWorkbenchPreferencePage {
private IProblemProfile profile;
- private Composite parametersComposite;
+ private Composite parametersTab;
private ISelectionChangedListener problemSelectionListener;
+ private IProblem selectedProblem;
public CodanPreferencePage() {
super(GRID);
setPreferenceStore(new ScopedPreferenceStore(new InstanceScope(),
CodanCorePlugin.PLUGIN_ID));
setDescription("Code Analyzers Preference Page");
- problemSelectionListener = new ISelectionChangedListener(){
-
+ problemSelectionListener = new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
- if (parametersComposite!=null ) {
+ if (parametersTab != null) {
if (event.getSelection() instanceof ITreeSelection) {
- ITreeSelection s = (ITreeSelection) event.getSelection();
- if (s.getFirstElement() instanceof IProblem)
+ ITreeSelection s = (ITreeSelection) event
+ .getSelection();
+ if (s.getFirstElement() instanceof IProblem)
setSelectedProblem((IProblem) s.getFirstElement());
}
}
-
}
};
}
-
-
protected String getPageId() {
return "org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage"; //$NON-NLS-1$
}
@@ -92,39 +91,41 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
// createMainTab(tabFolder);
createParamtersTab(tabFolder);
createScopeTab(tabFolder);
- checkedTreeEditor.getTreeViewer().addSelectionChangedListener(problemSelectionListener);
-
+ checkedTreeEditor.getTreeViewer().addSelectionChangedListener(
+ problemSelectionListener);
}
/**
* @param selection
*/
protected void setSelectedProblem(IProblem problem) {
- Control[] children = parametersComposite.getChildren();
- parametersComposite.setLayout(new GridLayout());
+ if (this.selectedProblem != problem) {
+ saveProblemEdits();
+ }
+ this.selectedProblem = problem;
+ Control[] children = parametersTab.getChildren();
for (int i = 0; i < children.length; i++) {
Control control = children[i];
control.dispose();
}
- if (problem.getParameterInfo()==null) {
- Label label = new Label(parametersComposite, SWT.NULL);
- label.setText("No Parameters");
- } else {
- Label label = new Label(parametersComposite, SWT.NULL);
- label.setText("Parameters: TODO");
- }
- parametersComposite.pack(true);
- parametersComposite.layout(true);
+ ParametersComposite comp = new ParametersComposite(parametersTab,
+ problem);
+ comp.setLayoutData(new GridData(GridData.FILL_BOTH));
+ parametersTab.pack(true);
+ parametersTab.layout(true);
}
+
/**
* @param tabFolder
*/
private void createParamtersTab(TabFolder tabFolder) {
TabItem tabItem1 = new TabItem(tabFolder, SWT.NULL);
tabItem1.setText("Parameters");
- parametersComposite = new Composite(tabFolder, SWT.NONE);
- tabItem1.setControl(parametersComposite);
+ parametersTab = new Composite(tabFolder, SWT.NONE);
+ tabItem1.setControl(parametersTab);
+ parametersTab.setLayout(new GridLayout());
}
+
/**
* @param tabFolder
*/
@@ -137,8 +138,8 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
Label label = new Label(comp, SWT.NONE);
label.setText("Scope: TODO");
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
}
+
/**
* @return
*/
@@ -153,11 +154,26 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
*/
@Override
public boolean performOk() {
- //if (isPropertyPage())
- getRegistry().updateProfile((IResource) getElement(), null);
+ // if (isPropertyPage())
+ getRegistry().updateProfile((IResource) getElement(), null);
+ saveProblemEdits();
return super.performOk();
}
+ /**
+ *
+ */
+ private void saveProblemEdits() {
+ if (selectedProblem==null) return;
+ Control[] children = parametersTab.getChildren();
+ for (int i = 0; i < children.length; i++) {
+ Control control = children[i];
+ if (control instanceof ParametersComposite) {
+ ((ParametersComposite) control).save((IProblemWorkingCopy) selectedProblem); // XXX
+ }
+ }
+ }
+
/*
* (non-Javadoc)
*
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ParametersComposite.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ParametersComposite.java
new file mode 100644
index 00000000000..f0b4e60914e
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ParametersComposite.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * 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.internal.ui.preferences;
+
+import org.eclipse.cdt.codan.core.model.IProblem;
+import org.eclipse.cdt.codan.core.model.IProblemParameterInfo;
+import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.PreferenceStore;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * @author Alena
+ *
+ */
+public class ParametersComposite extends Composite {
+ private FieldEditorPreferencePage page;
+ private IProblem problem;
+ private PreferenceStore pref;
+
+ /**
+ * @param parent
+ * @param problem
+ * @param style
+ */
+ public ParametersComposite(Composite parent, final IProblem problem) {
+ super(parent, SWT.NONE);
+ this.setLayout(new GridLayout(2, false));
+ this.problem = problem;
+ this.pref = new PreferenceStore();
+ page = new FieldEditorPreferencePage() {
+ @Override
+ protected void createFieldEditors() {
+ noDefaultAndApplyButton();
+ IProblemParameterInfo parameterInfo = problem
+ .getParameterInfo();
+ createFieldEditorsForParameters(parameterInfo);
+ }
+
+ /**
+ * @param info
+ */
+ private void createFieldEditorsForParameters(
+ IProblemParameterInfo info) {
+ switch (info.getType()) {
+ case TYPE_STRING:
+ StringFieldEditor fe = new StringFieldEditor(info.getKey(),
+ info.getLabel(), getFieldEditorParent());
+ addField(fe);
+ break;
+ default:
+ throw new UnsupportedOperationException(info.getType()
+ .toString());
+ }
+ }
+ };
+ IProblemParameterInfo info = problem.getParameterInfo();
+ initPrefStore(info);
+ page.setPreferenceStore(pref);
+ page.createControl(parent);
+ page.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
+ }
+
+ public void save(IProblemWorkingCopy problemwc) {
+ page.performOk();
+ IProblemParameterInfo info = problemwc.getParameterInfo();
+ savePrefStore(info, problemwc);
+ }
+
+ /**
+ * @param info
+ * @param problemwc
+ */
+ private void savePrefStore(IProblemParameterInfo info,
+ IProblemWorkingCopy problemwc) {
+ String key = info.getKey();
+ Object parameter = problem.getParameter(key);
+ if (parameter instanceof String) {
+ String newValue = pref.getString(key);
+ problemwc.setParameter(key, newValue);
+ } else
+ throw new UnsupportedOperationException(info.getType().toString());
+ }
+
+ /**
+ * @param info
+ */
+ private void initPrefStore(IProblemParameterInfo info) {
+ String key = info.getKey();
+ Object parameter = problem.getParameter(key);
+ if (parameter instanceof String) {
+ pref.setDefault(key, (String) parameter);
+ pref.setValue(key, (String) parameter);
+ } else
+ throw new UnsupportedOperationException(info.getType().toString());
+ }
+}

Back to the top