mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 12:03:16 +02:00
Bug 337625 - Support for example parameters for message pattern to be used in codan preference UI.
This commit is contained in:
parent
f1d8668d9a
commit
7a7f4df061
5 changed files with 231 additions and 154 deletions
|
@ -168,6 +168,56 @@ where xxx what checker would post as an argument for the problem.
|
||||||
</appinfo>
|
</appinfo>
|
||||||
</annotation>
|
</annotation>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<attribute name="exampleParam0" type="string">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
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.
|
||||||
|
</documentation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.attribute translatable="true"/>
|
||||||
|
</appinfo>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="exampleParam1" type="string">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
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.
|
||||||
|
</documentation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.attribute translatable="true"/>
|
||||||
|
</appinfo>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="exampleParam2" type="string">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
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.
|
||||||
|
</documentation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.attribute translatable="true"/>
|
||||||
|
</appinfo>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="exampleParam3" type="string">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
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.
|
||||||
|
</documentation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.attribute translatable="true"/>
|
||||||
|
</appinfo>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="exampleParam4" type="string">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
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.
|
||||||
|
</documentation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.attribute translatable="true"/>
|
||||||
|
</appinfo>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
<attribute name="description" type="string">
|
<attribute name="description" type="string">
|
||||||
<annotation>
|
<annotation>
|
||||||
<documentation>
|
<documentation>
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Alena Laskavaia - initial API and implementation
|
* Alena Laskavaia - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.model;
|
package org.eclipse.cdt.codan.core.model;
|
||||||
|
|
||||||
|
@ -47,14 +47,15 @@ public interface IProblem extends IProblemElement {
|
||||||
String getId();
|
String getId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is enabled in current context (usually within profile)
|
* Returns <code>true</code> if the problem is enabled in current context
|
||||||
|
* (usually within profile)
|
||||||
*
|
*
|
||||||
* @return true if enabled
|
* @return true if enabled
|
||||||
*/
|
*/
|
||||||
boolean isEnabled();
|
boolean isEnabled();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current severity
|
* Returns current severity
|
||||||
*
|
*
|
||||||
* @return severity
|
* @return severity
|
||||||
*/
|
*/
|
||||||
|
@ -68,7 +69,16 @@ public interface IProblem extends IProblemElement {
|
||||||
String getMessagePattern();
|
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)
|
* generate user controls for changing parameters)
|
||||||
*
|
*
|
||||||
* @return root preference or null
|
* @return root preference or null
|
||||||
|
@ -76,14 +86,14 @@ public interface IProblem extends IProblemElement {
|
||||||
public IProblemPreference getPreference();
|
public IProblemPreference getPreference();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get short description of a problem
|
* Returns short description of a problem
|
||||||
*
|
*
|
||||||
* @return description
|
* @return description
|
||||||
*/
|
*/
|
||||||
public String getDescription();
|
public String getDescription();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return marker id for the problem
|
* Returns marker id for the problem
|
||||||
*
|
*
|
||||||
* @return marker id
|
* @return marker id
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Alena Laskavaia - initial API and implementation
|
* Alena Laskavaia - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.core;
|
package org.eclipse.cdt.codan.internal.core;
|
||||||
|
|
||||||
|
@ -86,18 +86,15 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
processChecker(configurationElement);
|
processChecker(configurationElement);
|
||||||
}
|
}
|
||||||
// init parameters for checkers with parameters
|
// init parameters for checkers with parameters
|
||||||
for (Iterator<IChecker> iterator = problemList.keySet().iterator(); iterator
|
for (Iterator<IChecker> iterator = problemList.keySet().iterator(); iterator.hasNext();) {
|
||||||
.hasNext();) {
|
|
||||||
IChecker c = iterator.next();
|
IChecker c = iterator.next();
|
||||||
if (c instanceof ICheckerWithPreferences) {
|
if (c instanceof ICheckerWithPreferences) {
|
||||||
Collection<IProblem> list = problemList.get(c);
|
Collection<IProblem> list = problemList.get(c);
|
||||||
for (Iterator<IProblem> iterator2 = list.iterator(); iterator2
|
for (Iterator<IProblem> iterator2 = list.iterator(); iterator2.hasNext();) {
|
||||||
.hasNext();) {
|
|
||||||
IProblem p = iterator2.next();
|
IProblem p = iterator2.next();
|
||||||
if (p instanceof IProblemWorkingCopy) {
|
if (p instanceof IProblemWorkingCopy) {
|
||||||
try {
|
try {
|
||||||
((ICheckerWithPreferences) c)
|
((ICheckerWithPreferences) c).initPreferences((IProblemWorkingCopy) p);
|
||||||
.initPreferences((IProblemWorkingCopy) p);
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
CodanCorePlugin.log(t);
|
CodanCorePlugin.log(t);
|
||||||
|
@ -140,19 +137,16 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
name = id;
|
name = id;
|
||||||
IChecker checkerObj = null;
|
IChecker checkerObj = null;
|
||||||
try {
|
try {
|
||||||
Object checker = configurationElement
|
Object checker = configurationElement.createExecutableExtension("class"); //$NON-NLS-1$
|
||||||
.createExecutableExtension("class"); //$NON-NLS-1$
|
|
||||||
checkerObj = (IChecker) checker;
|
checkerObj = (IChecker) checker;
|
||||||
addChecker(checkerObj);
|
addChecker(checkerObj);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CodanCorePlugin.log(e);
|
CodanCorePlugin.log(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IConfigurationElement[] children1 = configurationElement
|
|
||||||
.getChildren("problemRef"); //$NON-NLS-1$
|
|
||||||
boolean hasRef = false;
|
boolean hasRef = false;
|
||||||
IConfigurationElement[] children2 = configurationElement
|
IConfigurationElement[] children2 =
|
||||||
.getChildren(PROBLEM_ELEMENT);
|
configurationElement.getChildren(PROBLEM_ELEMENT);
|
||||||
if (children2 != null) {
|
if (children2 != null) {
|
||||||
for (IConfigurationElement ref : children2) {
|
for (IConfigurationElement ref : children2) {
|
||||||
IProblem p = processProblem(ref);
|
IProblem p = processProblem(ref);
|
||||||
|
@ -160,11 +154,12 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
hasRef = true;
|
hasRef = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
IConfigurationElement[] children1 =
|
||||||
|
configurationElement.getChildren("problemRef"); //$NON-NLS-1$
|
||||||
if (children1 != null) {
|
if (children1 != null) {
|
||||||
for (IConfigurationElement ref : children1) {
|
for (IConfigurationElement ref : children1) {
|
||||||
hasRef = true;
|
hasRef = true;
|
||||||
IProblem p = getDefaultProfile().findProblem(
|
IProblem p = getDefaultProfile().findProblem(ref.getAttribute("refId")); //$NON-NLS-1$
|
||||||
ref.getAttribute("refId")); //$NON-NLS-1$
|
|
||||||
addRefProblem(checkerObj, p);
|
addRefProblem(checkerObj, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,8 +178,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
* @param configurationElement
|
* @param configurationElement
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private CodanProblem processProblem(
|
private CodanProblem processProblem(IConfigurationElement configurationElement) {
|
||||||
IConfigurationElement configurationElement) {
|
|
||||||
if (configurationElement.getName().equals(PROBLEM_ELEMENT)) {
|
if (configurationElement.getName().equals(PROBLEM_ELEMENT)) {
|
||||||
String id = getAtt(configurationElement, ID_ATTR);
|
String id = getAtt(configurationElement, ID_ATTR);
|
||||||
if (id == null)
|
if (id == null)
|
||||||
|
@ -199,9 +193,15 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
String enab = getAtt(configurationElement, "defaultEnabled", false); //$NON-NLS-1$
|
String enab = getAtt(configurationElement, "defaultEnabled", false); //$NON-NLS-1$
|
||||||
String sev = getAtt(configurationElement, "defaultSeverity", false); //$NON-NLS-1$
|
String sev = getAtt(configurationElement, "defaultSeverity", false); //$NON-NLS-1$
|
||||||
String patt = getAtt(configurationElement, "messagePattern", false); //$NON-NLS-1$
|
String patt = getAtt(configurationElement, "messagePattern", false); //$NON-NLS-1$
|
||||||
|
ArrayList<String> exampleParams = new ArrayList<String>();
|
||||||
|
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 desc = getAtt(configurationElement, "description", false); //$NON-NLS-1$
|
||||||
String markerType = getAtt(configurationElement,
|
String markerType = getAtt(configurationElement, "markerType", false); //$NON-NLS-1$
|
||||||
"markerType", false); //$NON-NLS-1$
|
|
||||||
if (enab != null) {
|
if (enab != null) {
|
||||||
p.setEnabled(Boolean.valueOf(enab));
|
p.setEnabled(Boolean.valueOf(enab));
|
||||||
}
|
}
|
||||||
|
@ -213,6 +213,9 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
if (patt != null) {
|
if (patt != null) {
|
||||||
p.setMessagePattern(patt);
|
p.setMessagePattern(patt);
|
||||||
}
|
}
|
||||||
|
if (!exampleParams.isEmpty()) {
|
||||||
|
p.setExampleMessageParameters(exampleParams.toArray(new String[exampleParams.size()]));
|
||||||
|
}
|
||||||
if (markerType != null) {
|
if (markerType != null) {
|
||||||
p.setMarkerType(markerType);
|
p.setMarkerType(markerType);
|
||||||
}
|
}
|
||||||
|
@ -232,9 +235,10 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
String name, boolean req) {
|
String name, boolean req) {
|
||||||
String elementValue = configurationElement.getAttribute(name);
|
String elementValue = configurationElement.getAttribute(name);
|
||||||
if (elementValue == null && req)
|
if (elementValue == null && req)
|
||||||
CodanCorePlugin
|
CodanCorePlugin.log("Extension " //$NON-NLS-1$
|
||||||
.log("Extension " + configurationElement.getDeclaringExtension().getUniqueIdentifier() //$NON-NLS-1$
|
+ configurationElement.getDeclaringExtension().getUniqueIdentifier()
|
||||||
+ " missing required attribute: " + configurationElement.getName() + "." + name); //$NON-NLS-1$ //$NON-NLS-2$
|
+ " missing required attribute: " + configurationElement.getName() //$NON-NLS-1$
|
||||||
|
+ "." + name); //$NON-NLS-1$
|
||||||
return elementValue;
|
return elementValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,6 +251,9 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
return checkers.iterator();
|
return checkers.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the singleton checkers registry
|
||||||
|
*/
|
||||||
public static CheckersRegistry getInstance() {
|
public static CheckersRegistry getInstance() {
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
return new CheckersRegistry();
|
return new CheckersRegistry();
|
||||||
|
@ -373,18 +380,17 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
try {
|
try {
|
||||||
prof = (IProblemProfile) getWorkspaceProfile().clone();
|
prof = (IProblemProfile) getWorkspaceProfile().clone();
|
||||||
// load default values
|
// load default values
|
||||||
CodanPreferencesLoader loader = new CodanPreferencesLoader(
|
CodanPreferencesLoader loader = new CodanPreferencesLoader(prof);
|
||||||
prof);
|
Preferences projectNode =
|
||||||
Preferences projectNode = CodanPreferencesLoader
|
CodanPreferencesLoader.getProjectNode((IProject) element);
|
||||||
.getProjectNode((IProject) element);
|
boolean useWorkspace = projectNode.getBoolean(PreferenceConstants.P_USE_PARENT,
|
||||||
boolean useWorkspace = projectNode.getBoolean(
|
false);
|
||||||
PreferenceConstants.P_USE_PARENT, false);
|
|
||||||
if (!useWorkspace) {
|
if (!useWorkspace) {
|
||||||
loader.load(projectNode);
|
loader.load(projectNode);
|
||||||
}
|
}
|
||||||
profiles.put(element, prof);
|
profiles.put(element, prof);
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
// cant
|
// can't
|
||||||
}
|
}
|
||||||
} else if (element.getParent() != null) {
|
} else if (element.getParent() != null) {
|
||||||
prof = getResourceProfile(element.getParent());
|
prof = getResourceProfile(element.getParent());
|
||||||
|
@ -404,28 +410,26 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
*/
|
*/
|
||||||
public IProblemProfile getResourceProfileWorkingCopy(IResource element) {
|
public IProblemProfile getResourceProfileWorkingCopy(IResource element) {
|
||||||
try {
|
try {
|
||||||
IProblemProfile prof = (IProblemProfile) getResourceProfile(element)
|
IProblemProfile prof = (IProblemProfile) getResourceProfile(element).clone();
|
||||||
.clone();
|
|
||||||
return prof;
|
return prof;
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
// cant
|
// can't
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if checker is enabled (needs to be run) or not. Checker is enabled
|
* Tests if a checker is enabled (needs to be run) or not. Checker is enabled
|
||||||
* if at least one problem it prints is enabled.
|
* if at least one problem it reports is enabled.
|
||||||
*
|
*
|
||||||
* @param checker
|
* @param checker
|
||||||
* @param resource
|
* @param resource
|
||||||
* @return
|
* @return <code>true</code> if the checker is enabled
|
||||||
*/
|
*/
|
||||||
public boolean isCheckerEnabled(IChecker checker, IResource resource) {
|
public boolean isCheckerEnabled(IChecker checker, IResource resource) {
|
||||||
IProblemProfile resourceProfile = getResourceProfile(resource);
|
IProblemProfile resourceProfile = getResourceProfile(resource);
|
||||||
Collection<IProblem> refProblems = getRefProblems(checker);
|
Collection<IProblem> refProblems = getRefProblems(checker);
|
||||||
for (Iterator<IProblem> iterator = refProblems.iterator(); iterator
|
for (Iterator<IProblem> iterator = refProblems.iterator(); iterator.hasNext();) {
|
||||||
.hasNext();) {
|
|
||||||
IProblem p = iterator.next();
|
IProblem p = iterator.next();
|
||||||
// we need to check problem enablement in particular profile
|
// we need to check problem enablement in particular profile
|
||||||
IProblem problem = resourceProfile.findProblem(p.getId());
|
IProblem problem = resourceProfile.findProblem(p.getId());
|
||||||
|
@ -439,15 +443,15 @@ public class CheckersRegistry implements Iterable<IChecker>, 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 checker
|
||||||
* @param resource
|
* @param resource
|
||||||
* @param mode
|
* @param mode
|
||||||
* @return
|
* @return <code>true</code> if the checker should run.
|
||||||
*/
|
*/
|
||||||
public boolean isCheckerEnabledForLaunchMode(IChecker checker,
|
public boolean isCheckerEnabledForLaunchMode(IChecker checker, IResource resource,
|
||||||
IResource resource, CheckerLaunchMode mode) {
|
CheckerLaunchMode mode) {
|
||||||
IProblemProfile resourceProfile = getResourceProfile(resource);
|
IProblemProfile resourceProfile = getResourceProfile(resource);
|
||||||
Collection<IProblem> refProblems = getRefProblems(checker);
|
Collection<IProblem> refProblems = getRefProblems(checker);
|
||||||
boolean enabled = false;
|
boolean enabled = false;
|
||||||
|
@ -459,13 +463,10 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
if (problem == null)
|
if (problem == null)
|
||||||
throw new IllegalArgumentException("Id is not registered"); //$NON-NLS-1$
|
throw new IllegalArgumentException("Id is not registered"); //$NON-NLS-1$
|
||||||
if (checker instanceof AbstractCheckerWithProblemPreferences) {
|
if (checker instanceof AbstractCheckerWithProblemPreferences) {
|
||||||
MapProblemPreference map = (MapProblemPreference) problem
|
MapProblemPreference map = (MapProblemPreference) problem.getPreference();
|
||||||
.getPreference();
|
IProblemPreference pref1 = map.getChildDescriptor(LaunchTypeProblemPreference.KEY);
|
||||||
IProblemPreference pref1 = map
|
|
||||||
.getChildDescriptor(LaunchTypeProblemPreference.KEY);
|
|
||||||
LaunchTypeProblemPreference pref = (LaunchTypeProblemPreference) pref1;
|
LaunchTypeProblemPreference pref = (LaunchTypeProblemPreference) pref1;
|
||||||
if (pref == null
|
if (pref == null || pref.isRunningInMode(CheckerLaunchMode.USE_PARENT)) {
|
||||||
|| pref.isRunningInMode(CheckerLaunchMode.USE_PARENT)) {
|
|
||||||
enabled = true;
|
enabled = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -479,7 +480,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return the number of checkers
|
||||||
*/
|
*/
|
||||||
public int getCheckersSize() {
|
public int getCheckersSize() {
|
||||||
return checkers.size();
|
return checkers.size();
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Alena Laskavaia - initial API and implementation
|
* Alena Laskavaia - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.core.model;
|
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.model.IProblemWorkingCopy;
|
||||||
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type of problems reported by Codan.
|
||||||
|
*/
|
||||||
public class CodanProblem implements IProblemWorkingCopy, Cloneable {
|
public class CodanProblem implements IProblemWorkingCopy, Cloneable {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
private String message;
|
private String messagePattern;
|
||||||
private CodanSeverity severity = CodanSeverity.Warning;
|
private CodanSeverity severity = CodanSeverity.Warning;
|
||||||
private boolean enabled = true;
|
private boolean enabled = true;
|
||||||
private IProblemPreference preference;
|
private IProblemPreference preference;
|
||||||
private boolean frozen;
|
private boolean frozen;
|
||||||
private String description;
|
private String description;
|
||||||
private String markerType = IProblemReporter.GENERIC_CODE_ANALYSIS_MARKER_TYPE;
|
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() {
|
public CodanSeverity getSeverity() {
|
||||||
return severity;
|
return severity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param problemId - the ID of the problem
|
||||||
|
* @param name - the name of the problem
|
||||||
|
*/
|
||||||
public CodanProblem(String problemId, String name) {
|
public CodanProblem(String problemId, String name) {
|
||||||
this.id = problemId;
|
this.id = problemId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -96,7 +105,7 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable {
|
||||||
* @see org.eclipse.cdt.codan.core.model.IProblem#getMessagePattern()
|
* @see org.eclipse.cdt.codan.core.model.IProblem#getMessagePattern()
|
||||||
*/
|
*/
|
||||||
public String getMessagePattern() {
|
public String getMessagePattern() {
|
||||||
return message;
|
return messagePattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void freeze() {
|
protected void freeze() {
|
||||||
|
@ -104,12 +113,12 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param message
|
* @param messagePattern
|
||||||
* the message to set
|
* the message to set
|
||||||
*/
|
*/
|
||||||
public void setMessagePattern(String message) {
|
public void setMessagePattern(String messagePattern) {
|
||||||
checkSet();
|
checkSet();
|
||||||
this.message = message;
|
this.messagePattern = messagePattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkSet() {
|
protected void checkSet() {
|
||||||
|
@ -146,7 +155,33 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable {
|
||||||
return markerType;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Alena Laskavaia - initial API and implementation
|
* Alena Laskavaia - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
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.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.param.IProblemPreference;
|
|
||||||
import org.eclipse.cdt.codan.internal.ui.CodanUIActivator;
|
import org.eclipse.cdt.codan.internal.ui.CodanUIActivator;
|
||||||
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
|
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
|
||||||
import org.eclipse.cdt.codan.internal.ui.dialogs.CustomizeProblemDialog;
|
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,
|
* preference store that belongs to the main plug-in class. That way,
|
||||||
* preferences can be accessed directly via the preference store.
|
* preferences can be accessed directly via the preference store.
|
||||||
*/
|
*/
|
||||||
public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
public class CodanPreferencePage extends FieldEditorOverlayPage implements IWorkbenchPreferencePage {
|
||||||
IWorkbenchPreferencePage {
|
|
||||||
private IProblemProfile profile;
|
private IProblemProfile profile;
|
||||||
private ISelectionChangedListener problemSelectionListener;
|
private ISelectionChangedListener problemSelectionListener;
|
||||||
private IProblem selectedProblem;
|
private IProblem selectedProblem;
|
||||||
private Group info;
|
private Group info;
|
||||||
private Label infoDesc;
|
private Label infoDesc;
|
||||||
private Label infoMessage;
|
private Label infoMessage;
|
||||||
//private Label infoParams;
|
// private Label infoParams;
|
||||||
private Button infoButton;
|
private Button infoButton;
|
||||||
private ProblemsTreeEditor checkedTreeEditor;
|
private ProblemsTreeEditor checkedTreeEditor;
|
||||||
|
|
||||||
public CodanPreferencePage() {
|
public CodanPreferencePage() {
|
||||||
super(GRID);
|
super(GRID);
|
||||||
setPreferenceStore(new ScopedPreferenceStore(new InstanceScope(),
|
setPreferenceStore(new ScopedPreferenceStore(InstanceScope.INSTANCE,
|
||||||
CodanCorePlugin.PLUGIN_ID));
|
CodanCorePlugin.PLUGIN_ID));
|
||||||
// setDescription("Code Analysis Preference Page");
|
// setDescription("Code Analysis Preference Page");
|
||||||
problemSelectionListener = new ISelectionChangedListener() {
|
problemSelectionListener = new ISelectionChangedListener() {
|
||||||
public void selectionChanged(SelectionChangedEvent event) {
|
public void selectionChanged(SelectionChangedEvent event) {
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
if (event.getSelection() instanceof ITreeSelection) {
|
if (event.getSelection() instanceof ITreeSelection) {
|
||||||
ITreeSelection s = (ITreeSelection) event
|
ITreeSelection s = (ITreeSelection) event.getSelection();
|
||||||
.getSelection();
|
|
||||||
if (s.getFirstElement() instanceof IProblem)
|
if (s.getFirstElement() instanceof IProblem)
|
||||||
setSelectedProblem((IProblem) s.getFirstElement());
|
setSelectedProblem((IProblem) s.getFirstElement());
|
||||||
else
|
else
|
||||||
|
@ -100,8 +97,7 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void createFieldEditors() {
|
public void createFieldEditors() {
|
||||||
checkedTreeEditor = new ProblemsTreeEditor(getFieldEditorParent(),
|
checkedTreeEditor = new ProblemsTreeEditor(getFieldEditorParent(), profile);
|
||||||
profile);
|
|
||||||
addField(checkedTreeEditor);
|
addField(checkedTreeEditor);
|
||||||
checkedTreeEditor.getTreeViewer().addSelectionChangedListener(
|
checkedTreeEditor.getTreeViewer().addSelectionChangedListener(
|
||||||
problemSelectionListener);
|
problemSelectionListener);
|
||||||
|
@ -111,11 +107,9 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
openCustomizeDialog();
|
openCustomizeDialog();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
GridData layoutData = new GridData(GridData.FILL, GridData.FILL, true,
|
GridData layoutData = new GridData(GridData.FILL, GridData.FILL, true, true);
|
||||||
true);
|
|
||||||
layoutData.heightHint = 400;
|
layoutData.heightHint = 400;
|
||||||
checkedTreeEditor.getTreeViewer().getControl()
|
checkedTreeEditor.getTreeViewer().getControl().setLayoutData(layoutData);
|
||||||
.setLayoutData(layoutData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -127,9 +121,9 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Control createContents(Composite parent) {
|
protected Control createContents(Composite parent) {
|
||||||
profile = isPropertyPage() ? getRegistry()
|
profile = isPropertyPage() ?
|
||||||
.getResourceProfileWorkingCopy((IResource) getElement())
|
getRegistry().getResourceProfileWorkingCopy((IResource) getElement()) :
|
||||||
: getRegistry().getWorkspaceProfile();
|
getRegistry().getWorkspaceProfile();
|
||||||
Composite comp = (Composite) super.createContents(parent);
|
Composite comp = (Composite) super.createContents(parent);
|
||||||
createInfoControl(comp);
|
createInfoControl(comp);
|
||||||
return comp;
|
return comp;
|
||||||
|
@ -143,10 +137,10 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
info.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
info.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||||
info.setLayout(new GridLayout(2, false));
|
info.setLayout(new GridLayout(2, false));
|
||||||
info.setText(CodanUIMessages.CodanPreferencePage_Info);
|
info.setText(CodanUIMessages.CodanPreferencePage_Info);
|
||||||
GridDataFactory gdLab = GridDataFactory.swtDefaults()
|
GridDataFactory gdLab =
|
||||||
.align(SWT.BEGINNING, SWT.BEGINNING).grab(false, false);
|
GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.BEGINNING).grab(false, false);
|
||||||
GridDataFactory gdFact = GridDataFactory.swtDefaults()
|
GridDataFactory gdFact =
|
||||||
.align(SWT.BEGINNING, SWT.BEGINNING).grab(true, true);
|
GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.BEGINNING).grab(true, true);
|
||||||
// message
|
// message
|
||||||
Label labelMessage = new Label(info, SWT.NONE);
|
Label labelMessage = new Label(info, SWT.NONE);
|
||||||
labelMessage.setText(CodanUIMessages.CodanPreferencePage_MessageLabel);
|
labelMessage.setText(CodanUIMessages.CodanPreferencePage_MessageLabel);
|
||||||
|
@ -154,9 +148,9 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
infoMessage = new Label(info, SWT.WRAP);
|
infoMessage = new Label(info, SWT.WRAP);
|
||||||
infoMessage.setLayoutData(gdFact.copy().create());
|
infoMessage.setLayoutData(gdFact.copy().create());
|
||||||
// description
|
// description
|
||||||
// Label labelDesc = new Label(info, SWT.NONE);
|
// Label labelDesc = new Label(info, SWT.NONE);
|
||||||
// labelDesc.setText(CodanUIMessages.CodanPreferencePage_Description);
|
// labelDesc.setText(CodanUIMessages.CodanPreferencePage_Description);
|
||||||
// labelDesc.setLayoutData(gdLab.create());
|
// labelDesc.setLayoutData(gdLab.create());
|
||||||
infoDesc = new Label(info, SWT.WRAP);
|
infoDesc = new Label(info, SWT.WRAP);
|
||||||
PixelConverter pixelConverter = new PixelConverter(comp);
|
PixelConverter pixelConverter = new PixelConverter(comp);
|
||||||
infoDesc.setLayoutData(gdFact
|
infoDesc.setLayoutData(gdFact
|
||||||
|
@ -166,14 +160,14 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
pixelConverter.convertHeightInCharsToPixels(3))
|
pixelConverter.convertHeightInCharsToPixels(3))
|
||||||
.create());
|
.create());
|
||||||
// params
|
// params
|
||||||
// Label labelParams = new Label(info, SWT.NONE);
|
// Label labelParams = new Label(info, SWT.NONE);
|
||||||
// labelParams.setText(CodanUIMessages.CodanPreferencePage_Parameters);
|
// labelParams.setText(CodanUIMessages.CodanPreferencePage_Parameters);
|
||||||
// labelParams.setLayoutData(gdLab.create());
|
// labelParams.setLayoutData(gdLab.create());
|
||||||
// infoParams = new Label(info, SWT.NONE);
|
// infoParams = new Label(info, SWT.NONE);
|
||||||
// infoParams.setLayoutData(gdFact.create());
|
// infoParams.setLayoutData(gdFact.create());
|
||||||
infoButton = new Button(info, SWT.PUSH);
|
infoButton = new Button(info, SWT.PUSH);
|
||||||
infoButton.setLayoutData(GridDataFactory.swtDefaults().span(2, 1)
|
infoButton.setLayoutData(
|
||||||
.align(SWT.END, SWT.BEGINNING).create());
|
GridDataFactory.swtDefaults().span(2, 1).align(SWT.END, SWT.BEGINNING).create());
|
||||||
infoButton.setText(CodanUIMessages.CodanPreferencePage_Customize);
|
infoButton.setText(CodanUIMessages.CodanPreferencePage_Customize);
|
||||||
infoButton.addSelectionListener(new SelectionAdapter() {
|
infoButton.addSelectionListener(new SelectionAdapter() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -212,20 +206,13 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
return super.performOk();
|
return super.performOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void saveWidgetValues() {
|
private void saveWidgetValues() {
|
||||||
CodanUIActivator
|
CodanUIActivator.getDefault().getDialogSettings().put(getWidgetId(),
|
||||||
.getDefault()
|
selectedProblem == null ? "" : selectedProblem.getId()); //$NON-NLS-1$
|
||||||
.getDialogSettings()
|
|
||||||
.put(getWidgetId(),
|
|
||||||
selectedProblem == null ? "" : selectedProblem.getId()); //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreWidgetValues() {
|
private void restoreWidgetValues() {
|
||||||
String id = CodanUIActivator.getDefault().getDialogSettings()
|
String id = CodanUIActivator.getDefault().getDialogSettings().get(getWidgetId());
|
||||||
.get(getWidgetId());
|
|
||||||
if (id != null && id.length() > 0 && checkedTreeEditor != null) {
|
if (id != null && id.length() > 0 && checkedTreeEditor != null) {
|
||||||
checkedTreeEditor.getTreeViewer().setSelection(
|
checkedTreeEditor.getTreeViewer().setSelection(
|
||||||
new StructuredSelection(profile.findProblem(id)), true);
|
new StructuredSelection(profile.findProblem(id)), true);
|
||||||
|
@ -241,30 +228,28 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
return getPageId() + ".selection"; //$NON-NLS-1$
|
return getPageId() + ".selection"; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void updateProblemInfo() {
|
private void updateProblemInfo() {
|
||||||
if (selectedProblem == null) {
|
if (selectedProblem == null) {
|
||||||
infoMessage.setText(""); //$NON-NLS-1$
|
infoMessage.setText(""); //$NON-NLS-1$
|
||||||
infoDesc.setText(""); //$NON-NLS-1$
|
infoDesc.setText(""); //$NON-NLS-1$
|
||||||
//infoParams.setText(""); //$NON-NLS-1$
|
// infoParams.setText(""); //$NON-NLS-1$
|
||||||
infoButton.setEnabled(false);
|
infoButton.setEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
IProblemPreference pref = selectedProblem.getPreference();
|
|
||||||
String description = selectedProblem.getDescription();
|
String description = selectedProblem.getDescription();
|
||||||
if (description == null)
|
if (description == null)
|
||||||
description = CodanUIMessages.CodanPreferencePage_NoInfo;
|
description = CodanUIMessages.CodanPreferencePage_NoInfo;
|
||||||
|
String messageToShow = CodanUIMessages.CodanPreferencePage_NoInfo;
|
||||||
String messagePattern = selectedProblem.getMessagePattern();
|
String messagePattern = selectedProblem.getMessagePattern();
|
||||||
String message = CodanUIMessages.CodanPreferencePage_NoInfo;
|
|
||||||
if (messagePattern != null) {
|
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);
|
infoDesc.setText(description);
|
||||||
// infoParams
|
// IProblemPreference pref = selectedProblem.getPreference();
|
||||||
// .setText(pref == null ? CodanUIMessages.CodanPreferencePage_NoInfo
|
// infoParams.setText(pref == null ?
|
||||||
// : CodanUIMessages.CodanPreferencePage_HasPreferences);
|
// CodanUIMessages.CodanPreferencePage_NoInfo :
|
||||||
|
// CodanUIMessages.CodanPreferencePage_HasPreferences);
|
||||||
infoButton.setEnabled(true);
|
infoButton.setEnabled(true);
|
||||||
}
|
}
|
||||||
info.layout(true);
|
info.layout(true);
|
||||||
|
@ -273,20 +258,16 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see
|
* @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
|
||||||
* org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
|
|
||||||
*/
|
*/
|
||||||
public void init(IWorkbench workbench) {
|
public void init(IWorkbench workbench) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
protected void openCustomizeDialog() {
|
protected void openCustomizeDialog() {
|
||||||
if (selectedProblem == null)
|
if (selectedProblem == null)
|
||||||
return;
|
return;
|
||||||
CustomizeProblemDialog d = new CustomizeProblemDialog(getShell(),
|
CustomizeProblemDialog dialog = new CustomizeProblemDialog(getShell(), selectedProblem,
|
||||||
selectedProblem, (IResource) getElement());
|
(IResource) getElement());
|
||||||
d.open();
|
dialog.open();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue