mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
- added limited support for string parameters
This commit is contained in:
parent
92923566ce
commit
53e15f64c2
5 changed files with 214 additions and 39 deletions
|
@ -11,12 +11,14 @@
|
||||||
package org.eclipse.cdt.codan.core.model;
|
package org.eclipse.cdt.codan.core.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Alena
|
* @author Alena
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AbstractListParameterInfo extends AbstractProblemParameterInfo {
|
public abstract class AbstractListParameterInfo extends
|
||||||
|
AbstractProblemParameterInfo {
|
||||||
protected ArrayList<IProblemParameterInfo> list = new ArrayList<IProblemParameterInfo>(
|
protected ArrayList<IProblemParameterInfo> list = new ArrayList<IProblemParameterInfo>(
|
||||||
1);
|
1);
|
||||||
|
|
||||||
|
@ -27,8 +29,8 @@ public class AbstractListParameterInfo extends AbstractProblemParameterInfo {
|
||||||
* org.eclipse.cdt.codan.core.model.AbstractProblemParameterInfo#getType()
|
* org.eclipse.cdt.codan.core.model.AbstractProblemParameterInfo#getType()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public ParameterTypes getType() {
|
||||||
return TYPE_LIST;
|
return ParameterTypes.TYPE_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,4 +73,9 @@ public class AbstractListParameterInfo extends AbstractProblemParameterInfo {
|
||||||
protected IProblemParameterInfo getElement(int i) {
|
protected IProblemParameterInfo getElement(int i) {
|
||||||
return list.get(i);
|
return list.get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<IProblemParameterInfo> getIterator() {
|
||||||
|
return list.iterator();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.model;
|
package org.eclipse.cdt.codan.core.model;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation for single parameter checker of type string.
|
* 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()
|
* @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getType()
|
||||||
*/
|
*/
|
||||||
public String getType() {
|
public ParameterTypes getType() {
|
||||||
return TYPE_STRING;
|
return ParameterTypes.TYPE_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -73,4 +75,13 @@ public abstract class AbstractProblemParameterInfo implements
|
||||||
public String getToolTip() {
|
public String getToolTip() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getIterator()
|
||||||
|
*/
|
||||||
|
public Iterator<IProblemParameterInfo> getIterator() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.model;
|
package org.eclipse.cdt.codan.core.model;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Problem parameter usually key=value settings that allows to alter checker
|
* Problem parameter usually key=value settings that allows to alter checker
|
||||||
* behaviour for given problem. For example if checker finds violation of naming
|
* 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.
|
* @noimplement This interface is not intended to be implemented by clients.
|
||||||
*/
|
*/
|
||||||
public interface IProblemParameterInfo {
|
public interface IProblemParameterInfo {
|
||||||
final static String TYPE_STRING = "string"; //$NON-NLS-1$
|
enum ParameterTypes {
|
||||||
final static String TYPE_INTEGER = "integer"; //$NON-NLS-1$
|
TYPE_STRING("string"), //$NON-NLS-1$
|
||||||
final static String TYPE_BOOLEAN = "boolean"; //$NON-NLS-1$
|
TYPE_INTEGER("integer"), //$NON-NLS-1$
|
||||||
final static String TYPE_FILE = "file"; //$NON-NLS-1$
|
TYPE_BOOLEAN("boolean"), //$NON-NLS-1$
|
||||||
final static String TYPE_LIST = "list"; //$NON-NLS-1$
|
TYPE_FILE("file"), //$NON-NLS-1$
|
||||||
final static String TYPE_HASH = "hash"; //$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();
|
String getKey();
|
||||||
|
|
||||||
|
@ -40,7 +64,7 @@ public interface IProblemParameterInfo {
|
||||||
*
|
*
|
||||||
* @return string value of the type
|
* @return string value of the type
|
||||||
*/
|
*/
|
||||||
String getType();
|
ParameterTypes getType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Additional info on how it is represented in the ui, for example boolean
|
* Additional info on how it is represented in the ui, for example boolean
|
||||||
|
@ -73,4 +97,12 @@ public interface IProblemParameterInfo {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IProblemParameterInfo getElement(String key);
|
IProblemParameterInfo getElement(String key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available if type is list or hash. Returns iterator over parameter values
|
||||||
|
* for list and hash.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Iterator<IProblemParameterInfo> getIterator();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.ICheckersRegistry;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemProfile;
|
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.resources.IResource;
|
||||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||||
|
@ -45,8 +46,9 @@ import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
||||||
public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
IWorkbenchPreferencePage {
|
IWorkbenchPreferencePage {
|
||||||
private IProblemProfile profile;
|
private IProblemProfile profile;
|
||||||
private Composite parametersComposite;
|
private Composite parametersTab;
|
||||||
private ISelectionChangedListener problemSelectionListener;
|
private ISelectionChangedListener problemSelectionListener;
|
||||||
|
private IProblem selectedProblem;
|
||||||
|
|
||||||
public CodanPreferencePage() {
|
public CodanPreferencePage() {
|
||||||
super(GRID);
|
super(GRID);
|
||||||
|
@ -54,22 +56,19 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
CodanCorePlugin.PLUGIN_ID));
|
CodanCorePlugin.PLUGIN_ID));
|
||||||
setDescription("Code Analyzers Preference Page");
|
setDescription("Code Analyzers Preference Page");
|
||||||
problemSelectionListener = new ISelectionChangedListener() {
|
problemSelectionListener = new ISelectionChangedListener() {
|
||||||
|
|
||||||
public void selectionChanged(SelectionChangedEvent event) {
|
public void selectionChanged(SelectionChangedEvent event) {
|
||||||
if (parametersComposite!=null ) {
|
if (parametersTab != null) {
|
||||||
if (event.getSelection() instanceof ITreeSelection) {
|
if (event.getSelection() instanceof ITreeSelection) {
|
||||||
ITreeSelection s = (ITreeSelection) event.getSelection();
|
ITreeSelection s = (ITreeSelection) event
|
||||||
|
.getSelection();
|
||||||
if (s.getFirstElement() instanceof IProblem)
|
if (s.getFirstElement() instanceof IProblem)
|
||||||
setSelectedProblem((IProblem) s.getFirstElement());
|
setSelectedProblem((IProblem) s.getFirstElement());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected String getPageId() {
|
protected String getPageId() {
|
||||||
return "org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage"; //$NON-NLS-1$
|
return "org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage"; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
@ -92,39 +91,41 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
// createMainTab(tabFolder);
|
// createMainTab(tabFolder);
|
||||||
createParamtersTab(tabFolder);
|
createParamtersTab(tabFolder);
|
||||||
createScopeTab(tabFolder);
|
createScopeTab(tabFolder);
|
||||||
checkedTreeEditor.getTreeViewer().addSelectionChangedListener(problemSelectionListener);
|
checkedTreeEditor.getTreeViewer().addSelectionChangedListener(
|
||||||
|
problemSelectionListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param selection
|
* @param selection
|
||||||
*/
|
*/
|
||||||
protected void setSelectedProblem(IProblem problem) {
|
protected void setSelectedProblem(IProblem problem) {
|
||||||
Control[] children = parametersComposite.getChildren();
|
if (this.selectedProblem != problem) {
|
||||||
parametersComposite.setLayout(new GridLayout());
|
saveProblemEdits();
|
||||||
|
}
|
||||||
|
this.selectedProblem = problem;
|
||||||
|
Control[] children = parametersTab.getChildren();
|
||||||
for (int i = 0; i < children.length; i++) {
|
for (int i = 0; i < children.length; i++) {
|
||||||
Control control = children[i];
|
Control control = children[i];
|
||||||
control.dispose();
|
control.dispose();
|
||||||
}
|
}
|
||||||
if (problem.getParameterInfo()==null) {
|
ParametersComposite comp = new ParametersComposite(parametersTab,
|
||||||
Label label = new Label(parametersComposite, SWT.NULL);
|
problem);
|
||||||
label.setText("No Parameters");
|
comp.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||||
} else {
|
parametersTab.pack(true);
|
||||||
Label label = new Label(parametersComposite, SWT.NULL);
|
parametersTab.layout(true);
|
||||||
label.setText("Parameters: TODO");
|
|
||||||
}
|
|
||||||
parametersComposite.pack(true);
|
|
||||||
parametersComposite.layout(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tabFolder
|
* @param tabFolder
|
||||||
*/
|
*/
|
||||||
private void createParamtersTab(TabFolder tabFolder) {
|
private void createParamtersTab(TabFolder tabFolder) {
|
||||||
TabItem tabItem1 = new TabItem(tabFolder, SWT.NULL);
|
TabItem tabItem1 = new TabItem(tabFolder, SWT.NULL);
|
||||||
tabItem1.setText("Parameters");
|
tabItem1.setText("Parameters");
|
||||||
parametersComposite = new Composite(tabFolder, SWT.NONE);
|
parametersTab = new Composite(tabFolder, SWT.NONE);
|
||||||
tabItem1.setControl(parametersComposite);
|
tabItem1.setControl(parametersTab);
|
||||||
|
parametersTab.setLayout(new GridLayout());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tabFolder
|
* @param tabFolder
|
||||||
*/
|
*/
|
||||||
|
@ -137,8 +138,8 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
Label label = new Label(comp, SWT.NONE);
|
Label label = new Label(comp, SWT.NONE);
|
||||||
label.setText("Scope: TODO");
|
label.setText("Scope: TODO");
|
||||||
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -155,9 +156,24 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
public boolean performOk() {
|
public boolean performOk() {
|
||||||
// if (isPropertyPage())
|
// if (isPropertyPage())
|
||||||
getRegistry().updateProfile((IResource) getElement(), null);
|
getRegistry().updateProfile((IResource) getElement(), null);
|
||||||
|
saveProblemEdits();
|
||||||
return super.performOk();
|
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)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue