mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 01:05:38 +02:00
Cleaned up problem preferences interfaces and fixed persistence
This commit is contained in:
parent
a0fe770fad
commit
3c2fd7ab95
39 changed files with 1617 additions and 627 deletions
|
@ -13,10 +13,9 @@ package org.eclipse.cdt.codan.internal.checkers;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
|
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
|
||||||
import org.eclipse.cdt.codan.core.model.ICheckerWithParameters;
|
import org.eclipse.cdt.codan.core.model.ICheckerWithPreferences;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
||||||
import org.eclipse.cdt.codan.core.param.SingleParameterInfo;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
|
@ -29,10 +28,9 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class NamingConventionFunctionChecker extends AbstractIndexAstChecker
|
public class NamingConventionFunctionChecker extends AbstractIndexAstChecker
|
||||||
implements ICheckerWithParameters {
|
implements ICheckerWithPreferences {
|
||||||
private static final String DEFAULT_PATTERN = "^[a-z]"; // default pattern name starts with english lowercase letter //$NON-NLS-1$
|
|
||||||
public static final String PARAM_KEY = "pattern"; //$NON-NLS-1$
|
|
||||||
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker"; //$NON-NLS-1$
|
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker"; //$NON-NLS-1$
|
||||||
|
public static final String PARAM_KEY = "pattern"; //$NON-NLS-1$
|
||||||
|
|
||||||
public void processAst(IASTTranslationUnit ast) {
|
public void processAst(IASTTranslationUnit ast) {
|
||||||
final IProblem pt = getProblemById(ER_ID, getFile());
|
final IProblem pt = getProblemById(ER_ID, getFile());
|
||||||
|
@ -44,7 +42,7 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker
|
||||||
|
|
||||||
public int visit(IASTDeclaration element) {
|
public int visit(IASTDeclaration element) {
|
||||||
if (element instanceof IASTFunctionDefinition) {
|
if (element instanceof IASTFunctionDefinition) {
|
||||||
String parameter = (String) pt.getParameter(PARAM_KEY);
|
String parameter = (String) getPreference(pt,PARAM_KEY);
|
||||||
Pattern pattern = Pattern.compile(parameter);
|
Pattern pattern = Pattern.compile(parameter);
|
||||||
IASTName astName = ((IASTFunctionDefinition) element)
|
IASTName astName = ((IASTFunctionDefinition) element)
|
||||||
.getDeclarator().getName();
|
.getDeclarator().getName();
|
||||||
|
@ -65,13 +63,15 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see
|
* @see
|
||||||
* org.eclipse.cdt.codan.core.model.ICheckerWithParameters#initParameters
|
* org.eclipse.cdt.codan.core.model.ICheckerWithPreferences#initParameters
|
||||||
* (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy)
|
* (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy)
|
||||||
*/
|
*/
|
||||||
public void initParameters(IProblemWorkingCopy problem) {
|
public void initPreferences(IProblemWorkingCopy problem) {
|
||||||
problem.setParameterInfo(new SingleParameterInfo(PARAM_KEY,
|
addPreference(
|
||||||
CheckersMessages.NamingConventionFunctionChecker_LabelNamePattern));
|
problem,
|
||||||
problem.setParameter(PARAM_KEY, DEFAULT_PATTERN);
|
PARAM_KEY,
|
||||||
|
CheckersMessages.NamingConventionFunctionChecker_LabelNamePattern,
|
||||||
|
"^[a-z]"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
|
||||||
*/
|
*/
|
||||||
protected boolean checkImplicitReturn(String id) {
|
protected boolean checkImplicitReturn(String id) {
|
||||||
final IProblem pt = getProblemById(id, getFile());
|
final IProblem pt = getProblemById(id, getFile());
|
||||||
return (Boolean) pt.getParameter(PARAM_IMPLICIT);
|
return (Boolean) getPreference(pt,PARAM_IMPLICIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,11 +158,11 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* checker must implement @link ICheckerWithParameters */
|
/* checker must implement @link ICheckerWithPreferences */
|
||||||
public void initParameters(IProblemWorkingCopy problem) {
|
public void initPreferences(IProblemWorkingCopy problem) {
|
||||||
if (problem.getId().equals(RET_NO_VALUE_ID)
|
if (problem.getId().equals(RET_NO_VALUE_ID)
|
||||||
|| problem.getId().equals(RET_NORET_ID)) {
|
|| problem.getId().equals(RET_NORET_ID)) {
|
||||||
addParam(problem, PARAM_IMPLICIT,
|
addPreference(problem, PARAM_IMPLICIT,
|
||||||
CheckersMessages.ReturnChecker_Param0, Boolean.FALSE);
|
CheckersMessages.ReturnChecker_Param0, Boolean.FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
package org.eclipse.cdt.codan.internal.checkers;
|
package org.eclipse.cdt.codan.internal.checkers;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
|
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
|
||||||
|
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||||
|
@ -27,15 +28,14 @@ import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||||
* Checker that detects statements without effect such as
|
* Checker that detects statements without effect such as
|
||||||
*
|
*
|
||||||
* a+b;
|
* a+b;
|
||||||
*
|
|
||||||
* or
|
* or
|
||||||
*
|
|
||||||
* +b;
|
* +b;
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class StatementHasNoEffectChecker extends AbstractIndexAstChecker {
|
public class StatementHasNoEffectChecker extends AbstractIndexAstChecker {
|
||||||
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem"; //$NON-NLS-1$
|
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem"; //$NON-NLS-1$
|
||||||
|
private static final String PARAM_MACRO_ID = "macro";
|
||||||
|
|
||||||
public void processAst(IASTTranslationUnit ast) {
|
public void processAst(IASTTranslationUnit ast) {
|
||||||
ast.accept(new CheckStmpVisitor());
|
ast.accept(new CheckStmpVisitor());
|
||||||
|
@ -111,4 +111,8 @@ public class StatementHasNoEffectChecker extends AbstractIndexAstChecker {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initPreferences(IProblemWorkingCopy problem) {
|
||||||
|
addPreference(problem, PARAM_MACRO_ID, "Check statements that belong to macro", Boolean.TRUE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.cxx.model;
|
package org.eclipse.cdt.codan.core.cxx.model;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.model.ICheckerWithParameters;
|
import org.eclipse.cdt.codan.core.model.ICheckerWithPreferences;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
|
@ -23,7 +23,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||||
* Abstract class for checkers that do all the work on function definition level
|
* Abstract class for checkers that do all the work on function definition level
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractAstFunctionChecker extends
|
public abstract class AbstractAstFunctionChecker extends
|
||||||
AbstractIndexAstChecker implements ICheckerWithParameters {
|
AbstractIndexAstChecker implements ICheckerWithPreferences {
|
||||||
public void processAst(IASTTranslationUnit ast) {
|
public void processAst(IASTTranslationUnit ast) {
|
||||||
// traverse the ast using the visitor pattern.
|
// traverse the ast using the visitor pattern.
|
||||||
ast.accept(new ASTVisitor() {
|
ast.accept(new ASTVisitor() {
|
||||||
|
|
|
@ -12,15 +12,9 @@ package org.eclipse.cdt.codan.core.cxx.model;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||||
import org.eclipse.cdt.codan.core.cxx.Activator;
|
import org.eclipse.cdt.codan.core.cxx.Activator;
|
||||||
import org.eclipse.cdt.codan.core.model.AbstractChecker;
|
import org.eclipse.cdt.codan.core.model.AbstractCheckerWithProblemPreferences;
|
||||||
import org.eclipse.cdt.codan.core.model.ICheckerWithParameters;
|
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemLocation;
|
import org.eclipse.cdt.codan.core.model.IProblemLocation;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
|
||||||
import org.eclipse.cdt.codan.core.model.IRunnableInEditorChecker;
|
import org.eclipse.cdt.codan.core.model.IRunnableInEditorChecker;
|
||||||
import org.eclipse.cdt.codan.core.param.IProblemParameterInfo;
|
|
||||||
import org.eclipse.cdt.codan.core.param.MapParameterInfo;
|
|
||||||
import org.eclipse.cdt.codan.core.param.SingleParameterInfo;
|
|
||||||
import org.eclipse.cdt.codan.core.param.IProblemParameterInfo.ParameterType;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
@ -39,8 +33,8 @@ import org.eclipse.core.runtime.Path;
|
||||||
*
|
*
|
||||||
* Clients may extend this class.
|
* Clients may extend this class.
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractIndexAstChecker extends AbstractChecker implements
|
public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblemPreferences implements
|
||||||
ICAstChecker, IRunnableInEditorChecker, ICheckerWithParameters {
|
ICAstChecker, IRunnableInEditorChecker {
|
||||||
private IFile file;
|
private IFile file;
|
||||||
|
|
||||||
protected IFile getFile() {
|
protected IFile getFile() {
|
||||||
|
@ -134,23 +128,4 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements
|
||||||
processAst(ast);
|
processAst(ast);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initParameters(IProblemWorkingCopy problem) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
public IProblemParameterInfo addParam(IProblemWorkingCopy problem,
|
|
||||||
String key, String label, Object defaultValue) {
|
|
||||||
MapParameterInfo map = (MapParameterInfo) problem.getParameterInfo();
|
|
||||||
if (map == null) {
|
|
||||||
map = new MapParameterInfo();
|
|
||||||
problem.setParameterInfo(map);
|
|
||||||
}
|
|
||||||
SingleParameterInfo info = new SingleParameterInfo(key,
|
|
||||||
label,
|
|
||||||
ParameterType.typeOf(defaultValue));
|
|
||||||
map.setElement(info);
|
|
||||||
problem.setParameter(key, defaultValue);
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
#Sat May 15 15:21:20 EDT 2010
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
|
||||||
|
sp_cleanup.add_default_serial_version_id=true
|
||||||
|
sp_cleanup.add_generated_serial_version_id=false
|
||||||
|
sp_cleanup.add_missing_annotations=true
|
||||||
|
sp_cleanup.add_missing_deprecated_annotations=true
|
||||||
|
sp_cleanup.add_missing_methods=false
|
||||||
|
sp_cleanup.add_missing_nls_tags=false
|
||||||
|
sp_cleanup.add_missing_override_annotations=true
|
||||||
|
sp_cleanup.add_missing_override_annotations_interface_methods=false
|
||||||
|
sp_cleanup.add_serial_version_id=false
|
||||||
|
sp_cleanup.always_use_blocks=true
|
||||||
|
sp_cleanup.always_use_parentheses_in_expressions=false
|
||||||
|
sp_cleanup.always_use_this_for_non_static_field_access=false
|
||||||
|
sp_cleanup.always_use_this_for_non_static_method_access=false
|
||||||
|
sp_cleanup.convert_to_enhanced_for_loop=false
|
||||||
|
sp_cleanup.correct_indentation=false
|
||||||
|
sp_cleanup.format_source_code=true
|
||||||
|
sp_cleanup.format_source_code_changes_only=false
|
||||||
|
sp_cleanup.make_local_variable_final=false
|
||||||
|
sp_cleanup.make_parameters_final=false
|
||||||
|
sp_cleanup.make_private_fields_final=true
|
||||||
|
sp_cleanup.make_type_abstract_if_missing_method=false
|
||||||
|
sp_cleanup.make_variable_declarations_final=false
|
||||||
|
sp_cleanup.never_use_blocks=false
|
||||||
|
sp_cleanup.never_use_parentheses_in_expressions=true
|
||||||
|
sp_cleanup.on_save_use_additional_actions=true
|
||||||
|
sp_cleanup.organize_imports=true
|
||||||
|
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
|
||||||
|
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
|
||||||
|
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
|
||||||
|
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
|
||||||
|
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
|
||||||
|
sp_cleanup.remove_private_constructors=true
|
||||||
|
sp_cleanup.remove_trailing_whitespaces=true
|
||||||
|
sp_cleanup.remove_trailing_whitespaces_all=true
|
||||||
|
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
|
||||||
|
sp_cleanup.remove_unnecessary_casts=true
|
||||||
|
sp_cleanup.remove_unnecessary_nls_tags=true
|
||||||
|
sp_cleanup.remove_unused_imports=true
|
||||||
|
sp_cleanup.remove_unused_local_variables=false
|
||||||
|
sp_cleanup.remove_unused_private_fields=true
|
||||||
|
sp_cleanup.remove_unused_private_members=false
|
||||||
|
sp_cleanup.remove_unused_private_methods=true
|
||||||
|
sp_cleanup.remove_unused_private_types=true
|
||||||
|
sp_cleanup.sort_members=false
|
||||||
|
sp_cleanup.sort_members_all=false
|
||||||
|
sp_cleanup.use_blocks=false
|
||||||
|
sp_cleanup.use_blocks_only_for_return_and_throw=false
|
||||||
|
sp_cleanup.use_parentheses_in_expressions=false
|
||||||
|
sp_cleanup.use_this_for_non_static_field_access=false
|
||||||
|
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
|
||||||
|
sp_cleanup.use_this_for_non_static_method_access=false
|
||||||
|
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
|
|
@ -0,0 +1,140 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2009,2010 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.core.param;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor.PreferenceType;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for BasicProblemPreference
|
||||||
|
*/
|
||||||
|
public class BasicProblemPreferenceTest extends TestCase {
|
||||||
|
private static final String TEST_STR = "aaa"; //$NON-NLS-1$
|
||||||
|
BasicProblemPreference pref;
|
||||||
|
String key = "xxx"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
pref = new BasicProblemPreference(key, "My Value"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIntegerExportValue() {
|
||||||
|
pref.setType(PreferenceType.TYPE_INTEGER);
|
||||||
|
pref.setValue(22);
|
||||||
|
String value = pref.exportValue();
|
||||||
|
assertEquals(String.valueOf(22), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIntegerImportValue() {
|
||||||
|
pref.setType(PreferenceType.TYPE_INTEGER);
|
||||||
|
pref.importValue("22"); //$NON-NLS-1$
|
||||||
|
assertEquals(22, pref.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStringExportValue() {
|
||||||
|
pref.setType(PreferenceType.TYPE_STRING);
|
||||||
|
pref.setValue(TEST_STR);
|
||||||
|
String value = pref.exportValue();
|
||||||
|
assertEquals(TEST_STR, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStringImportValue() {
|
||||||
|
pref.setType(PreferenceType.TYPE_STRING);
|
||||||
|
pref.importValue(TEST_STR);
|
||||||
|
assertEquals(TEST_STR, pref.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBooleanImportValue() {
|
||||||
|
pref.setType(PreferenceType.TYPE_BOOLEAN);
|
||||||
|
pref.setValue(Boolean.TRUE);
|
||||||
|
String value = pref.exportValue();
|
||||||
|
assertEquals("true", value); //$NON-NLS-1$
|
||||||
|
pref.importValue(TEST_STR);
|
||||||
|
assertEquals(Boolean.FALSE, pref.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFileImportValue() {
|
||||||
|
pref.setType(PreferenceType.TYPE_FILE);
|
||||||
|
File file = new File("file.c"); //$NON-NLS-1$
|
||||||
|
pref.setValue(file);
|
||||||
|
String value = pref.exportValue();
|
||||||
|
assertEquals(file.getName(), value);
|
||||||
|
pref.importValue(file.getName());
|
||||||
|
assertEquals(file, pref.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBadKey() {
|
||||||
|
try {
|
||||||
|
pref.setKey(null);
|
||||||
|
fail("Should be exception"); //$NON-NLS-1$
|
||||||
|
} catch (Exception e) {
|
||||||
|
assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBadType() {
|
||||||
|
try {
|
||||||
|
pref.setType(null);
|
||||||
|
fail("Should be exception"); //$NON-NLS-1$
|
||||||
|
} catch (Exception e) {
|
||||||
|
assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStringImportValueNum() {
|
||||||
|
pref.setType(PreferenceType.TYPE_STRING);
|
||||||
|
pref.importValue("42.5");
|
||||||
|
assertEquals("42.5", pref.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param str
|
||||||
|
*/
|
||||||
|
protected void checkImportExport(String str) {
|
||||||
|
pref.setType(PreferenceType.TYPE_STRING);
|
||||||
|
pref.setValue(str);
|
||||||
|
pref.importValue(pref.exportValue());
|
||||||
|
assertEquals(str, pref.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStringExportSpecial() {
|
||||||
|
checkImportExport("a=b");
|
||||||
|
checkImportExport("\"");
|
||||||
|
checkImportExport("33");
|
||||||
|
checkImportExport("22.4");
|
||||||
|
checkImportExport("a,b");
|
||||||
|
checkImportExport("{a+b}");
|
||||||
|
checkImportExport("\b");
|
||||||
|
}
|
||||||
|
// public void testEscape() {
|
||||||
|
// String str = "\"a\"";
|
||||||
|
// String res = pref.escape(str);
|
||||||
|
// assertEquals("\"\\\"a\\\"\"", res);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void testUnEscape() {
|
||||||
|
// String res = "\"a\"";
|
||||||
|
// String str = "\"\\\"a\\\"\"";
|
||||||
|
// assertEquals(res, pref.unescape(str));
|
||||||
|
// }
|
||||||
|
}
|
|
@ -0,0 +1,109 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2009,2010 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.core.param;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor.PreferenceType;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for BasicProblemPreference
|
||||||
|
*/
|
||||||
|
public class ListProblemPreferenceTest extends TestCase {
|
||||||
|
private static final String PAR1 = "0"; //$NON-NLS-1$
|
||||||
|
private static final String PAR2 = "1"; //$NON-NLS-1$
|
||||||
|
private ListProblemPreference list;
|
||||||
|
private String key = "list"; //$NON-NLS-1$
|
||||||
|
private ListProblemPreference list2;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
list = new ListProblemPreference(key, "My Value"); //$NON-NLS-1$
|
||||||
|
list2 = new ListProblemPreference(key, "My Value2"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parval
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected BasicProblemPreference addPar(String key, Object parval) {
|
||||||
|
BasicProblemPreference str = makePar(key, parval);
|
||||||
|
list.addChildDescriptor(str);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parval
|
||||||
|
* @param parval
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected BasicProblemPreference makePar(String key, Object parval) {
|
||||||
|
BasicProblemPreference str = new BasicProblemPreference(key, key);
|
||||||
|
if (parval != null) {
|
||||||
|
str.setValue(parval);
|
||||||
|
str.setType(PreferenceType.typeOf(parval));
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExportValueStr() {
|
||||||
|
BasicProblemPreference str = addPar(PAR1, "42.5"); //$NON-NLS-1$
|
||||||
|
String value = list.exportValue();
|
||||||
|
assertEquals("(42.5)", value); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportValue() {
|
||||||
|
addPar(PAR1, "xxx"); //$NON-NLS-1$
|
||||||
|
String value = list.exportValue();
|
||||||
|
BasicProblemPreference str2 = new BasicProblemPreference(PAR1, PAR1);
|
||||||
|
list2.addChildDescriptor(str2);
|
||||||
|
list2.importValue(value);
|
||||||
|
assertEquals("xxx", list2.getChildValue(PAR1)); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportValueSpec() {
|
||||||
|
BasicProblemPreference str = addPar(PAR1, "a=b"); //$NON-NLS-1$
|
||||||
|
String value = list.exportValue();
|
||||||
|
BasicProblemPreference str2 = new BasicProblemPreference(PAR1, PAR1);
|
||||||
|
list2.addChildDescriptor(str2);
|
||||||
|
list2.importValue(value);
|
||||||
|
assertEquals(str.getValue(), list2.getChildValue(PAR1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportValue2() {
|
||||||
|
addPar(PAR1, "a=b"); //$NON-NLS-1$
|
||||||
|
BasicProblemPreference p2 = addPar(PAR2, "2,\"2"); //$NON-NLS-1$
|
||||||
|
String value = list.exportValue();
|
||||||
|
list = new ListProblemPreference(key, "My Value"); //$NON-NLS-1$
|
||||||
|
addPar(PAR1, null);
|
||||||
|
addPar(PAR2, null);
|
||||||
|
list.importValue(value);
|
||||||
|
assertEquals("a=b", list.getChildValue(PAR1)); //$NON-NLS-1$
|
||||||
|
assertEquals(p2.getValue(), list.getChildValue(PAR2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportValue2_nosec() {
|
||||||
|
addPar(PAR1, "a=b"); //$NON-NLS-1$
|
||||||
|
BasicProblemPreference p2 = addPar(PAR2, "2' 2\""); //$NON-NLS-1$
|
||||||
|
String value = list.exportValue();
|
||||||
|
list = new ListProblemPreference(key, "My Value"); //$NON-NLS-1$
|
||||||
|
addPar(PAR1, null);
|
||||||
|
list.importValue(value);
|
||||||
|
assertEquals("a=b", list.getChildValue(PAR1)); //$NON-NLS-1$
|
||||||
|
assertEquals(p2.getValue(), list.getChildValue(PAR2));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2009,2010 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.core.param;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor.PreferenceType;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for BasicProblemPreference
|
||||||
|
*/
|
||||||
|
public class MapProblemPreferenceTest extends TestCase {
|
||||||
|
private static final String PAR1 = "aaa"; //$NON-NLS-1$
|
||||||
|
private static final String PAR2 = "bbb"; //$NON-NLS-1$
|
||||||
|
private MapProblemPreference map;
|
||||||
|
private String key = "map"; //$NON-NLS-1$
|
||||||
|
private MapProblemPreference map2;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
map = new MapProblemPreference(key, "My Value"); //$NON-NLS-1$
|
||||||
|
map2 = new MapProblemPreference(key, "My Value2"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parval
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected BasicProblemPreference addPar(String key, Object parval) {
|
||||||
|
BasicProblemPreference str = makePar(key, parval);
|
||||||
|
map.addChildDescriptor(str);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parval
|
||||||
|
* @param parval
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected BasicProblemPreference makePar(String key, Object parval) {
|
||||||
|
BasicProblemPreference str = new BasicProblemPreference(key, key);
|
||||||
|
if (parval != null) {
|
||||||
|
str.setValue(parval);
|
||||||
|
str.setType(PreferenceType.typeOf(parval));
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExportValueStr() {
|
||||||
|
BasicProblemPreference str = addPar(PAR1, "42.5"); //$NON-NLS-1$
|
||||||
|
String value = map.exportValue();
|
||||||
|
assertEquals("{" + str.getKey() + "=>42.5}", value); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportValue() {
|
||||||
|
addPar(PAR1, "xxx"); //$NON-NLS-1$
|
||||||
|
String value = map.exportValue();
|
||||||
|
BasicProblemPreference str2 = new BasicProblemPreference(PAR1, PAR1);
|
||||||
|
map2.addChildDescriptor(str2);
|
||||||
|
map2.importValue(value);
|
||||||
|
assertEquals("xxx", map2.getChildValue(PAR1)); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportValueSpec() {
|
||||||
|
BasicProblemPreference str = addPar(PAR1, "a=b"); //$NON-NLS-1$
|
||||||
|
String value = map.exportValue();
|
||||||
|
BasicProblemPreference str2 = new BasicProblemPreference(PAR1, PAR1);
|
||||||
|
map2.addChildDescriptor(str2);
|
||||||
|
map2.importValue(value);
|
||||||
|
assertEquals(str.getValue(), map2.getChildValue(PAR1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportValue2() {
|
||||||
|
addPar(PAR1, "a=b"); //$NON-NLS-1$
|
||||||
|
BasicProblemPreference p2 = addPar(PAR2, "2,\"2"); //$NON-NLS-1$
|
||||||
|
String value = map.exportValue();
|
||||||
|
map = new MapProblemPreference(key, "My Value"); //$NON-NLS-1$
|
||||||
|
addPar(PAR1, null);
|
||||||
|
addPar(PAR2, null);
|
||||||
|
map.importValue(value);
|
||||||
|
assertEquals("a=b", map.getChildValue(PAR1)); //$NON-NLS-1$
|
||||||
|
assertEquals(p2.getValue(), map.getChildValue(PAR2));
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,6 +41,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
|
||||||
suite.addTestSuite(SuggestedParenthesisCheckerTest.class);
|
suite.addTestSuite(SuggestedParenthesisCheckerTest.class);
|
||||||
suite.addTestSuite(ExpressionRequiredInReturnCheckerTest.class);
|
suite.addTestSuite(ExpressionRequiredInReturnCheckerTest.class);
|
||||||
suite.addTestSuite(CatchByReferenceTest.class);
|
suite.addTestSuite(CatchByReferenceTest.class);
|
||||||
|
suite.addTest(CodanFastTestSuite.suite());
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2004, 2007 QNX Software Systems and others.
|
||||||
|
* 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:
|
||||||
|
* QNX Software Systems - initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.codan.core.test;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.codan.core.param.BasicProblemPreferenceTest;
|
||||||
|
import org.eclipse.cdt.codan.core.param.ListProblemPreferenceTest;
|
||||||
|
import org.eclipse.cdt.codan.core.param.MapProblemPreferenceTest;
|
||||||
|
|
||||||
|
public class CodanFastTestSuite extends TestSuite {
|
||||||
|
public CodanFastTestSuite() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public CodanFastTestSuite(Class theClass, String name) {
|
||||||
|
super(theClass, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CodanFastTestSuite(Class theClass) {
|
||||||
|
super(theClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CodanFastTestSuite(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
final CodanFastTestSuite suite = new CodanFastTestSuite();
|
||||||
|
suite.addTestSuite(BasicProblemPreferenceTest.class);
|
||||||
|
suite.addTestSuite(ListProblemPreferenceTest.class);
|
||||||
|
suite.addTestSuite(MapProblemPreferenceTest.class);
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
#Fri Nov 20 13:57:56 EST 2009
|
#Sat May 15 15:20:42 EDT 2010
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
|
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
|
||||||
sp_cleanup.add_default_serial_version_id=true
|
sp_cleanup.add_default_serial_version_id=true
|
||||||
|
@ -8,6 +8,7 @@ sp_cleanup.add_missing_deprecated_annotations=true
|
||||||
sp_cleanup.add_missing_methods=false
|
sp_cleanup.add_missing_methods=false
|
||||||
sp_cleanup.add_missing_nls_tags=false
|
sp_cleanup.add_missing_nls_tags=false
|
||||||
sp_cleanup.add_missing_override_annotations=true
|
sp_cleanup.add_missing_override_annotations=true
|
||||||
|
sp_cleanup.add_missing_override_annotations_interface_methods=false
|
||||||
sp_cleanup.add_serial_version_id=false
|
sp_cleanup.add_serial_version_id=false
|
||||||
sp_cleanup.always_use_blocks=true
|
sp_cleanup.always_use_blocks=true
|
||||||
sp_cleanup.always_use_parentheses_in_expressions=false
|
sp_cleanup.always_use_parentheses_in_expressions=false
|
||||||
|
|
|
@ -16,7 +16,8 @@ Export-Package: org.eclipse.cdt.codan.core,
|
||||||
x-friends:="org.eclipse.cdt.codan.checkers,
|
x-friends:="org.eclipse.cdt.codan.checkers,
|
||||||
org.eclipse.cdt.codan.checkers.ui,
|
org.eclipse.cdt.codan.checkers.ui,
|
||||||
org.eclipse.cdt.codan.ui,
|
org.eclipse.cdt.codan.ui,
|
||||||
org.eclipse.cdt.codan.core.cxx",
|
org.eclipse.cdt.codan.core.cxx,
|
||||||
|
org.eclipse.cdt.codan.core.test",
|
||||||
org.eclipse.cdt.codan.internal.core;
|
org.eclipse.cdt.codan.internal.core;
|
||||||
x-friends:="org.eclipse.cdt.codan.core,
|
x-friends:="org.eclipse.cdt.codan.core,
|
||||||
org.eclipse.cdt.codan.core.cxx,
|
org.eclipse.cdt.codan.core.cxx,
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2009,2010 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.core.model;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.codan.core.param.BasicProblemPreference;
|
||||||
|
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||||
|
import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor.PreferenceType;
|
||||||
|
import org.eclipse.cdt.codan.core.param.MapProblemPreference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AbstarctChecker that has extra method to simplify adding parameters
|
||||||
|
*/
|
||||||
|
public abstract class AbstractCheckerWithProblemPreferences extends
|
||||||
|
AbstractChecker implements ICheckerWithPreferences {
|
||||||
|
/**
|
||||||
|
* Checker that actually has parameter must override this
|
||||||
|
*/
|
||||||
|
public void initPreferences(IProblemWorkingCopy problem) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a parameter
|
||||||
|
*
|
||||||
|
* @param problem
|
||||||
|
* - problem that has parameter
|
||||||
|
* @param key
|
||||||
|
* - parameter key
|
||||||
|
* @param label
|
||||||
|
* - parameter label - user visible
|
||||||
|
* @param defaultValue
|
||||||
|
* - parameter default value
|
||||||
|
* @return - parameter info object
|
||||||
|
*/
|
||||||
|
public IProblemPreference addPreference(IProblemWorkingCopy problem,
|
||||||
|
String key, String label, Object defaultValue) {
|
||||||
|
MapProblemPreference map = getTopLevelPreferenceMap(problem);
|
||||||
|
BasicProblemPreference info = new BasicProblemPreference(key, label,
|
||||||
|
PreferenceType.typeOf(defaultValue));
|
||||||
|
map.addChildDescriptor(info);
|
||||||
|
setDefaultPreferenceValue(problem, key, defaultValue);
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IProblemPreference addPreference(IProblemWorkingCopy problem,
|
||||||
|
IProblemPreference info, Object defaultValue) {
|
||||||
|
MapProblemPreference map = getTopLevelPreferenceMap(problem);
|
||||||
|
map.addChildDescriptor(info);
|
||||||
|
setDefaultPreferenceValue(problem, info.getKey(), defaultValue);
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param problem
|
||||||
|
* @param key
|
||||||
|
* @param defaultValue
|
||||||
|
*/
|
||||||
|
protected void setDefaultPreferenceValue(IProblemWorkingCopy problem,
|
||||||
|
String key, Object defaultValue) {
|
||||||
|
MapProblemPreference map = getTopLevelPreferenceMap(problem);
|
||||||
|
if (map.getChildValue(key) == null)
|
||||||
|
map.addChildValue(key, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param problem
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected MapProblemPreference getTopLevelPreferenceMap(
|
||||||
|
IProblemWorkingCopy problem) {
|
||||||
|
MapProblemPreference map = (MapProblemPreference) problem
|
||||||
|
.getPreference();
|
||||||
|
if (map == null) {
|
||||||
|
map = new MapProblemPreference("params", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
problem.setPreference(map);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return value for the key in the top level preference map
|
||||||
|
*
|
||||||
|
* @param problem
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Object getPreference(IProblem problem, String key) {
|
||||||
|
return ((MapProblemPreference) problem.getPreference())
|
||||||
|
.getChildValue(key);
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ package org.eclipse.cdt.codan.core.model;
|
||||||
*
|
*
|
||||||
* @noextend This interface is not intended to be extended by clients.
|
* @noextend This interface is not intended to be extended by clients.
|
||||||
*/
|
*/
|
||||||
public interface ICheckerWithParameters {
|
public interface ICheckerWithPreferences {
|
||||||
/**
|
/**
|
||||||
* Implement this method to set default parameters for checkers with
|
* Implement this method to set default parameters for checkers with
|
||||||
* parameters.
|
* parameters.
|
||||||
|
@ -30,5 +30,5 @@ public interface ICheckerWithParameters {
|
||||||
* @param problem
|
* @param problem
|
||||||
* - instance of problem working copy
|
* - instance of problem working copy
|
||||||
*/
|
*/
|
||||||
void initParameters(IProblemWorkingCopy problem);
|
void initPreferences(IProblemWorkingCopy problem);
|
||||||
}
|
}
|
|
@ -10,7 +10,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.model;
|
package org.eclipse.cdt.codan.core.model;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.param.IProblemParameterInfo;
|
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface representing code analysis problem type. For example
|
* Interface representing code analysis problem type. For example
|
||||||
|
@ -65,16 +65,14 @@ public interface IProblem extends IProblemElement {
|
||||||
*/
|
*/
|
||||||
String getMessagePattern();
|
String getMessagePattern();
|
||||||
|
|
||||||
public Object getParameter(Object key);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get parameter info root - contains description of types of all the
|
* Get root preference descriptor - contains description of types of all the
|
||||||
* parameters or null if not defined (used by ui to generate user controls
|
* parameters or null if not defined (used by ui to generate user controls
|
||||||
* for changing parameters)
|
* for changing parameters)
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public IProblemParameterInfo getParameterInfo();
|
public IProblemPreference getPreference();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get short description of a problem
|
* Get short description of a problem
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.model;
|
package org.eclipse.cdt.codan.core.model;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.param.IProblemParameterInfo;
|
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modifiable problem.
|
* Modifiable problem.
|
||||||
|
@ -52,22 +52,11 @@ public interface IProblemWorkingCopy extends IProblem {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set value for the checker parameter, checker may set value during
|
* Set value for the checker parameter, checker may set value during
|
||||||
* initialization only
|
* initialization only, which would the default. User control this values
|
||||||
|
* through ui later.
|
||||||
*
|
*
|
||||||
* @param key
|
|
||||||
* - key of the parameter
|
|
||||||
* @param value
|
|
||||||
* - parameter value
|
|
||||||
*/
|
*/
|
||||||
public void setParameter(Object key, Object value);
|
public void setPreference(IProblemPreference pref);
|
||||||
|
|
||||||
/**
|
|
||||||
* Set parameter info object for the given problem, see
|
|
||||||
* {@link IProblemParameterInfo}
|
|
||||||
*
|
|
||||||
* @param info
|
|
||||||
*/
|
|
||||||
public void setParameterInfo(IProblemParameterInfo info);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set problem description
|
* Set problem description
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* 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.core.param;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation for single parameter checker of type string.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public abstract class AbstractProblemParameterInfo implements
|
|
||||||
IProblemParameterInfo {
|
|
||||||
public static final String PARAM = "param"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getKey()
|
|
||||||
*/
|
|
||||||
public String getKey() {
|
|
||||||
return PARAM;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getType()
|
|
||||||
*/
|
|
||||||
public ParameterType getType() {
|
|
||||||
return ParameterType.TYPE_STRING;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getUiInfo()
|
|
||||||
*/
|
|
||||||
public String getUiInfo() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getLabel()
|
|
||||||
*/
|
|
||||||
public String getLabel() {
|
|
||||||
return getKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getElement(java
|
|
||||||
* .lang.String)
|
|
||||||
*/
|
|
||||||
public IProblemParameterInfo getElement(String key) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getToolTip()
|
|
||||||
*/
|
|
||||||
public String getToolTip() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getIterator()
|
|
||||||
*/
|
|
||||||
public Iterator<IProblemParameterInfo> getIterator() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,156 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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.core.param;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.StreamTokenizer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default implementation for single parameter checker of type string.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class AbstractProblemPreference implements IProblemPreference {
|
||||||
|
public static final String PARAM = "param"; //$NON-NLS-1$
|
||||||
|
protected String key;
|
||||||
|
protected String label;
|
||||||
|
protected String toolTip = null;
|
||||||
|
protected PreferenceType type;
|
||||||
|
protected String uiInfo;
|
||||||
|
private IProblemPreference parent;
|
||||||
|
|
||||||
|
public PreferenceType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getToolTip() {
|
||||||
|
return toolTip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUiInfo() {
|
||||||
|
return uiInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKey(String key) {
|
||||||
|
if (isValidIdentifier(key))
|
||||||
|
this.key = key;
|
||||||
|
else
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Key must have java identifier syntax or number, i.e no dots and other funky stuff"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isValidIdentifier(String id) {
|
||||||
|
int n = id.length();
|
||||||
|
if (n == 0)
|
||||||
|
return false;
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
if (!Character.isJavaIdentifierPart(id.charAt(i)))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(String label) {
|
||||||
|
if (label == null)
|
||||||
|
throw new NullPointerException("Label cannot be null"); //$NON-NLS-1$
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToolTip(String tooltip) {
|
||||||
|
this.toolTip = tooltip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(PreferenceType type) {
|
||||||
|
if (type == null)
|
||||||
|
throw new NullPointerException("Type cannot be null"); //$NON-NLS-1$
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUiInfo(String uiinfo) {
|
||||||
|
this.uiInfo = uiinfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getValue() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(Object value) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IProblemPreference getChildDescriptor(String key) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IProblemPreference[] getChildDescriptors() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addChildDescriptor(IProblemPreference info) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object clone() {
|
||||||
|
try {
|
||||||
|
return super.clone();
|
||||||
|
} catch (CloneNotSupportedException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param str
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected StreamTokenizer getImportTokenizer(String str) {
|
||||||
|
ByteArrayInputStream st = new ByteArrayInputStream(str.getBytes());
|
||||||
|
StreamTokenizer tokenizer = new StreamTokenizer(new InputStreamReader(
|
||||||
|
st));
|
||||||
|
tokenizer.resetSyntax();
|
||||||
|
tokenizer.quoteChar('"');
|
||||||
|
tokenizer.wordChars('_', '_');
|
||||||
|
tokenizer.wordChars('-', '-');
|
||||||
|
tokenizer.wordChars('.', '.');
|
||||||
|
tokenizer.wordChars('0', '9');
|
||||||
|
tokenizer.wordChars('a', 'z');
|
||||||
|
tokenizer.wordChars('A', 'Z');
|
||||||
|
tokenizer.wordChars(128 + 32, 255);
|
||||||
|
tokenizer.whitespaceChars(0, ' ');
|
||||||
|
tokenizer.commentChar('/');
|
||||||
|
return tokenizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IProblemPreference getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parent
|
||||||
|
* the parent to set
|
||||||
|
*/
|
||||||
|
public void setParent(IProblemPreference parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQualifiedKey() {
|
||||||
|
if (parent == null)
|
||||||
|
return getKey();
|
||||||
|
return parent.getQualifiedKey() + "." + getKey(); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,130 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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.core.param;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StreamTokenizer;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ParameterInfo representing a single checker parameter
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BasicProblemPreference extends AbstractProblemPreference {
|
||||||
|
Object value;
|
||||||
|
{
|
||||||
|
key = PARAM;
|
||||||
|
type = PreferenceType.TYPE_STRING;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate an info with given key and label
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* - property id (use in actual property hash of a checker)
|
||||||
|
* @param label
|
||||||
|
* - label to be shown to user
|
||||||
|
* @param type
|
||||||
|
* - parameter type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public BasicProblemPreference(String key, String label, PreferenceType type) {
|
||||||
|
if (key == null)
|
||||||
|
throw new NullPointerException("key"); //$NON-NLS-1$
|
||||||
|
if (type == null)
|
||||||
|
throw new NullPointerException("type"); //$NON-NLS-1$
|
||||||
|
setKey(key);
|
||||||
|
setLabel(label);
|
||||||
|
setType(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate an info with given key and label
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* - property id (use in actual property hash of a checker)
|
||||||
|
* @param label
|
||||||
|
* - label to be shown to user
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public BasicProblemPreference(String key, String label) {
|
||||||
|
setKey(key);
|
||||||
|
setLabel(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(Object value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String exportValue() {
|
||||||
|
Pattern pat = Pattern.compile("^[A-Za-z0-9._-]+$"); //$NON-NLS-1$
|
||||||
|
String x = String.valueOf(getValue());
|
||||||
|
if (pat.matcher(x).find() == false)
|
||||||
|
return escape(x);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String escape(String x) {
|
||||||
|
x = x.replaceAll("[\"\\\\]", "\\\\$0"); //$NON-NLS-1$//$NON-NLS-2$
|
||||||
|
return "\"" + x + "\""; //$NON-NLS-1$//$NON-NLS-2$
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* org.eclipse.cdt.codan.core.param.IProblemPreferenceValue#importValue(
|
||||||
|
* java.lang.String)
|
||||||
|
*/
|
||||||
|
public void importValue(String str) {
|
||||||
|
if (str.startsWith("\"")) //$NON-NLS-1$
|
||||||
|
str = unescape(str);
|
||||||
|
switch (getType()) {
|
||||||
|
case TYPE_STRING:
|
||||||
|
setValue(str);
|
||||||
|
break;
|
||||||
|
case TYPE_INTEGER:
|
||||||
|
setValue(Integer.parseInt(str));
|
||||||
|
break;
|
||||||
|
case TYPE_BOOLEAN:
|
||||||
|
setValue(Boolean.valueOf(str));
|
||||||
|
break;
|
||||||
|
case TYPE_FILE:
|
||||||
|
setValue(new File(str));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException(getType()
|
||||||
|
+ " is not supported for basic type"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param str
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String unescape(String str) {
|
||||||
|
StreamTokenizer tokenizer = getImportTokenizer(str);
|
||||||
|
try {
|
||||||
|
tokenizer.nextToken();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String sval = tokenizer.sval;
|
||||||
|
return sval;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2009,2010 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.core.param;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Value of the problem preference. If more than one it can be composite, i.e.
|
||||||
|
* map
|
||||||
|
*/
|
||||||
|
public interface IProblemPreference extends Cloneable, IProblemPreferenceValue,
|
||||||
|
IProblemPreferenceDescriptor {
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2009,2010 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.core.param;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for container type preferences
|
||||||
|
*/
|
||||||
|
public interface IProblemPreferenceContainer {
|
||||||
|
Object getChildValue(String key);
|
||||||
|
|
||||||
|
void addChildValue(String key, Object value);
|
||||||
|
|
||||||
|
void removeChildValue(String key);
|
||||||
|
}
|
|
@ -11,7 +11,6 @@
|
||||||
package org.eclipse.cdt.codan.core.param;
|
package org.eclipse.cdt.codan.core.param;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -29,8 +28,8 @@ import java.util.Map;
|
||||||
* @noextend This interface is not intended to be extended by clients.
|
* @noextend This interface is not intended to be extended by clients.
|
||||||
* @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 IProblemPreferenceDescriptor extends Cloneable {
|
||||||
public enum ParameterType {
|
public enum PreferenceType {
|
||||||
TYPE_STRING("string"), //$NON-NLS-1$
|
TYPE_STRING("string"), //$NON-NLS-1$
|
||||||
TYPE_INTEGER("integer"), //$NON-NLS-1$
|
TYPE_INTEGER("integer"), //$NON-NLS-1$
|
||||||
TYPE_BOOLEAN("boolean"), //$NON-NLS-1$
|
TYPE_BOOLEAN("boolean"), //$NON-NLS-1$
|
||||||
|
@ -39,14 +38,14 @@ public interface IProblemParameterInfo {
|
||||||
TYPE_MAP("map"); //$NON-NLS-1$
|
TYPE_MAP("map"); //$NON-NLS-1$
|
||||||
private String literal;
|
private String literal;
|
||||||
|
|
||||||
private ParameterType(String literal) {
|
private PreferenceType(String literal) {
|
||||||
this.literal = literal;
|
this.literal = literal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ParameterType valueOfLiteral(String name) {
|
public static PreferenceType valueOfLiteral(String name) {
|
||||||
ParameterType[] values = values();
|
PreferenceType[] values = values();
|
||||||
for (int i = 0; i < values.length; i++) {
|
for (int i = 0; i < values.length; i++) {
|
||||||
ParameterType e = values[i];
|
PreferenceType e = values[i];
|
||||||
if (e.literal.equals(name))
|
if (e.literal.equals(name))
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
@ -62,7 +61,7 @@ public interface IProblemParameterInfo {
|
||||||
* @param value
|
* @param value
|
||||||
* @return parameter type corresponding to the value java type
|
* @return parameter type corresponding to the value java type
|
||||||
*/
|
*/
|
||||||
public static ParameterType typeOf(Object value) {
|
public static PreferenceType typeOf(Object value) {
|
||||||
if (value instanceof Boolean)
|
if (value instanceof Boolean)
|
||||||
return TYPE_BOOLEAN;
|
return TYPE_BOOLEAN;
|
||||||
if (value instanceof String)
|
if (value instanceof String)
|
||||||
|
@ -90,7 +89,7 @@ public interface IProblemParameterInfo {
|
||||||
*
|
*
|
||||||
* @return string value of the type
|
* @return string value of the type
|
||||||
*/
|
*/
|
||||||
ParameterType getType();
|
PreferenceType 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
|
||||||
|
@ -115,20 +114,32 @@ public interface IProblemParameterInfo {
|
||||||
String getToolTip();
|
String getToolTip();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Available if type is list or hash. Returns value of subparamer with the
|
* Available if type is composite. Returns value of subdescriptor with the
|
||||||
* name of key. For the "list" type key is the number (index).
|
* name of key. For the "list" type key is the number (index).
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* - name of the subparameter.
|
* - name of the subdescriptor.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IProblemParameterInfo getElement(String key);
|
IProblemPreference getChildDescriptor(String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Available if type is list or hash. Returns iterator over parameter values
|
* Available if type is list or map. Returns array of children.
|
||||||
* for list and hash.
|
* Of size 0 for basic types, keys for map, and arrays of 0 element for
|
||||||
|
* array type
|
||||||
|
* (since all elements are the same).
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Iterator<IProblemParameterInfo> getIterator();
|
IProblemPreference[] getChildDescriptors();
|
||||||
|
|
||||||
|
void addChildDescriptor(IProblemPreference info);
|
||||||
|
|
||||||
|
Object clone();
|
||||||
|
|
||||||
|
IProblemPreference getParent();
|
||||||
|
|
||||||
|
public void setParent(IProblemPreference parent);
|
||||||
|
|
||||||
|
String getQualifiedKey();
|
||||||
}
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2009,2010 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.core.param;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Value of the problem preference. If more than one it can be composite, i.e.
|
||||||
|
* map
|
||||||
|
*/
|
||||||
|
public interface IProblemPreferenceValue extends Cloneable {
|
||||||
|
/**
|
||||||
|
* Get value of parameter if it is basic type.
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Object getValue();
|
||||||
|
|
||||||
|
void setValue(Object value);
|
||||||
|
|
||||||
|
String exportValue();
|
||||||
|
|
||||||
|
void importValue(String str);
|
||||||
|
}
|
|
@ -1,87 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* 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.core.param;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Alena
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ListParameterInfo extends SingleParameterInfo {
|
|
||||||
protected ArrayList<IProblemParameterInfo> list = new ArrayList<IProblemParameterInfo>(
|
|
||||||
1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param key
|
|
||||||
* @param label
|
|
||||||
*/
|
|
||||||
public ListParameterInfo(String key, String label) {
|
|
||||||
super(key, label);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ParameterType getType() {
|
|
||||||
return ParameterType.TYPE_LIST;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setType(ParameterType type) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get parameter into for element equal to key's int value,
|
|
||||||
*
|
|
||||||
* @throws NumberFormatException
|
|
||||||
* if key is not number
|
|
||||||
* @throws ArrayIndexOutOfBoundsException
|
|
||||||
* is index is out of bound
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public IProblemParameterInfo getElement(String key)
|
|
||||||
throws NumberFormatException, ArrayIndexOutOfBoundsException {
|
|
||||||
if (key == null) {
|
|
||||||
// special case if all element are the same return first, if key is
|
|
||||||
// null
|
|
||||||
return list.get(0);
|
|
||||||
}
|
|
||||||
Integer iv = Integer.valueOf(key);
|
|
||||||
if (iv.intValue() >= list.size() && list.size() == 1) {
|
|
||||||
// special case if all element are the same return first
|
|
||||||
return list.get(0);
|
|
||||||
}
|
|
||||||
return list.get(iv.intValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set i'th element of parameter info, if all are the same i is 0
|
|
||||||
*
|
|
||||||
* @param i
|
|
||||||
* @param info
|
|
||||||
*/
|
|
||||||
public void setElement(int i, IProblemParameterInfo info) {
|
|
||||||
while (i >= list.size()) {
|
|
||||||
list.add(null);
|
|
||||||
}
|
|
||||||
list.set(i, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IProblemParameterInfo getElement(int i) {
|
|
||||||
return list.get(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<IProblemParameterInfo> getIterator() {
|
|
||||||
return list.iterator();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,177 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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.core.param;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StreamTokenizer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Alena
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ListProblemPreference extends AbstractProblemPreference implements
|
||||||
|
IProblemPreferenceContainer {
|
||||||
|
protected ArrayList<IProblemPreference> list = new ArrayList<IProblemPreference>(
|
||||||
|
1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key
|
||||||
|
* @param label
|
||||||
|
*/
|
||||||
|
public ListProblemPreference(String key, String label) {
|
||||||
|
setKey(key);
|
||||||
|
setLabel(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreferenceType getType() {
|
||||||
|
return PreferenceType.TYPE_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setType(PreferenceType type) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get parameter into for element equal to key's int value,
|
||||||
|
*
|
||||||
|
* @throws NumberFormatException
|
||||||
|
* if key is not number
|
||||||
|
* @throws ArrayIndexOutOfBoundsException
|
||||||
|
* is index is out of bound
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public IProblemPreference getChildDescriptor(String key)
|
||||||
|
throws NumberFormatException {
|
||||||
|
if (key == null) {
|
||||||
|
// special case if all element are the same return first, if key is
|
||||||
|
// null
|
||||||
|
return (IProblemPreference) getChildPreference(0).clone();
|
||||||
|
}
|
||||||
|
Integer iv = Integer.valueOf(key);
|
||||||
|
if (iv.intValue() >= list.size()) {
|
||||||
|
// special case if all element are the same return first clone
|
||||||
|
IProblemPreference childInfo = (IProblemPreference) getChildPreference(
|
||||||
|
0).clone();
|
||||||
|
return childInfo;
|
||||||
|
}
|
||||||
|
return getChildPreference(iv.intValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set i'th element of parameter info, if all are the same i is 0
|
||||||
|
*
|
||||||
|
* @param i
|
||||||
|
* @param info
|
||||||
|
*/
|
||||||
|
public void setChildPreference(int i, IProblemPreference info) {
|
||||||
|
if (info != null) {
|
||||||
|
while (i >= list.size()) {
|
||||||
|
list.add(null);
|
||||||
|
}
|
||||||
|
list.set(i, info);
|
||||||
|
} else {
|
||||||
|
while (i == list.size() - 1) {
|
||||||
|
list.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If all list elements have same info it is enough to set only first one
|
||||||
|
* (index 0)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addChildDescriptor(IProblemPreference info) {
|
||||||
|
Integer iv = Integer.valueOf(info.getKey());
|
||||||
|
IProblemPreference desc = (IProblemPreference) info.clone();
|
||||||
|
desc.setParent(this);
|
||||||
|
setChildPreference(iv, desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IProblemPreference getChildPreference(int i) {
|
||||||
|
return list.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IProblemPreference[] getChildDescriptors() {
|
||||||
|
return list.toArray(new IProblemPreference[list.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getChildValue(String key) {
|
||||||
|
IProblemPreference childInfo = getChildDescriptor(key);
|
||||||
|
return childInfo.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addChildValue(String key, Object value) {
|
||||||
|
IProblemPreference pref = getChildDescriptor(key);
|
||||||
|
pref.setValue(value);
|
||||||
|
// because descriptor can be phantom we have to set preference phisically
|
||||||
|
setChildPreference(Integer.parseInt(key), pref);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeChildValue(String key) {
|
||||||
|
int index = Integer.parseInt(key);
|
||||||
|
list.remove(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public Object clone() {
|
||||||
|
ListProblemPreference list1 = (ListProblemPreference) super.clone();
|
||||||
|
list1.list = (ArrayList<IProblemPreference>) list.clone();
|
||||||
|
return list1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String exportValue() {
|
||||||
|
StringBuffer buf = new StringBuffer("("); //$NON-NLS-1$
|
||||||
|
for (Iterator<IProblemPreference> iterator = list.iterator(); iterator
|
||||||
|
.hasNext();) {
|
||||||
|
IProblemPreference d = iterator.next();
|
||||||
|
buf.append(d.exportValue());
|
||||||
|
if (iterator.hasNext())
|
||||||
|
buf.append(","); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
return buf.toString() + ")"; //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
public void importValue(String str) {
|
||||||
|
StreamTokenizer tokenizer = getImportTokenizer(str);
|
||||||
|
int token;
|
||||||
|
int index = 0;
|
||||||
|
try {
|
||||||
|
token = tokenizer.nextToken();
|
||||||
|
if (token != '(')
|
||||||
|
throw new IllegalArgumentException(str);
|
||||||
|
while (true) {
|
||||||
|
token = tokenizer.nextToken();
|
||||||
|
String val = tokenizer.sval;
|
||||||
|
String ik = String.valueOf(index);
|
||||||
|
IProblemPreference desc = getChildDescriptor(ik);
|
||||||
|
if (desc != null) {
|
||||||
|
desc.importValue(val);
|
||||||
|
addChildValue(ik, desc.getValue());
|
||||||
|
}
|
||||||
|
token = tokenizer.nextToken();
|
||||||
|
if (token == ')')
|
||||||
|
break;
|
||||||
|
if (token != ',')
|
||||||
|
throw new IllegalArgumentException(str);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalArgumentException(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,83 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* 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.core.param;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HashParamterInfo - for checker that needs more than one parameter and they
|
|
||||||
* all different "named".
|
|
||||||
* For example checker has 2 optional boolean parameters. For example checker
|
|
||||||
* for parameter names
|
|
||||||
* shadowing would have two boolean options: "check contructors" and
|
|
||||||
* "check setters". In this case you use this type.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class MapParameterInfo extends SingleParameterInfo {
|
|
||||||
protected HashMap<String, IProblemParameterInfo> hash = new HashMap<String, IProblemParameterInfo>();
|
|
||||||
|
|
||||||
public MapParameterInfo() {
|
|
||||||
super(""); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param label
|
|
||||||
* - label for this group of parameters
|
|
||||||
*/
|
|
||||||
public MapParameterInfo(String label) {
|
|
||||||
super(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param key
|
|
||||||
* - key for itself
|
|
||||||
* @param label
|
|
||||||
* - label for this group of parameters
|
|
||||||
*/
|
|
||||||
public MapParameterInfo(String key, String label) {
|
|
||||||
super(key, label);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ParameterType getType() {
|
|
||||||
return ParameterType.TYPE_MAP;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setType(ParameterType type) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get parameter into for element by key
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public IProblemParameterInfo getElement(String key) {
|
|
||||||
return hash.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set parameter info for element with the key equals to info.getKey()
|
|
||||||
*
|
|
||||||
* @param i
|
|
||||||
* @param info
|
|
||||||
*/
|
|
||||||
public void setElement(IProblemParameterInfo info) {
|
|
||||||
hash.put(info.getKey(), info);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<IProblemParameterInfo> getIterator() {
|
|
||||||
return hash.values().iterator();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,153 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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.core.param;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StreamTokenizer;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HashParamterInfo - for checker that needs more than one parameter and they
|
||||||
|
* all different "named".
|
||||||
|
* For example checker has 2 optional boolean parameters. For example checker
|
||||||
|
* for parameter names
|
||||||
|
* shadowing would have two boolean options: "check contructors" and
|
||||||
|
* "check setters". In this case you use this type.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MapProblemPreference extends AbstractProblemPreference implements
|
||||||
|
IProblemPreferenceContainer {
|
||||||
|
protected LinkedHashMap<String, IProblemPreference> hash = new LinkedHashMap<String, IProblemPreference>();
|
||||||
|
|
||||||
|
public MapProblemPreference() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key
|
||||||
|
* - key for itself
|
||||||
|
* @param label
|
||||||
|
* - label for this group of parameters
|
||||||
|
*/
|
||||||
|
public MapProblemPreference(String key, String label) {
|
||||||
|
setKey(key);
|
||||||
|
setLabel(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreferenceType getType() {
|
||||||
|
return PreferenceType.TYPE_MAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setType(PreferenceType type) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get parameter into for element by key
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public IProblemPreference getChildDescriptor(String key) {
|
||||||
|
return hash.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put parameter info into the map for element with the key equals to
|
||||||
|
* info.getKey()
|
||||||
|
*
|
||||||
|
* @param i
|
||||||
|
* @param info
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addChildDescriptor(IProblemPreference info) {
|
||||||
|
IProblemPreference desc = (IProblemPreference) info.clone();
|
||||||
|
desc.setParent(this);
|
||||||
|
hash.put(info.getKey(), desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IProblemPreference[] getChildDescriptors() {
|
||||||
|
return hash.values().toArray(
|
||||||
|
new IProblemPreference[hash.values().size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getChildValue(String key) {
|
||||||
|
IProblemPreference childInfo = getChildDescriptor(key);
|
||||||
|
return childInfo.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addChildValue(String key, Object value) {
|
||||||
|
getChildDescriptor(key).setValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeChildValue(String key) {
|
||||||
|
hash.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public Object clone() {
|
||||||
|
MapProblemPreference map = (MapProblemPreference) super.clone();
|
||||||
|
map.hash = (LinkedHashMap<String, IProblemPreference>) hash.clone();
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String exportValue() {
|
||||||
|
StringBuffer buf = new StringBuffer("{"); //$NON-NLS-1$
|
||||||
|
for (Iterator<String> iterator = hash.keySet().iterator(); iterator
|
||||||
|
.hasNext();) {
|
||||||
|
String key = iterator.next();
|
||||||
|
IProblemPreference d = hash.get(key);
|
||||||
|
buf.append(key + "=>" + d.exportValue()); //$NON-NLS-1$
|
||||||
|
if (iterator.hasNext())
|
||||||
|
buf.append(","); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
return buf.toString() + "}"; //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
public void importValue(String str) {
|
||||||
|
StreamTokenizer tokenizer = getImportTokenizer(str);
|
||||||
|
int token;
|
||||||
|
try {
|
||||||
|
token = tokenizer.nextToken();
|
||||||
|
if (token != '{')
|
||||||
|
throw new IllegalArgumentException(str);
|
||||||
|
while (true) {
|
||||||
|
token = tokenizer.nextToken();
|
||||||
|
String key = tokenizer.sval;
|
||||||
|
token = tokenizer.nextToken();
|
||||||
|
if (token != '=')
|
||||||
|
throw new IllegalArgumentException(str);
|
||||||
|
token = tokenizer.nextToken();
|
||||||
|
if (token != '>')
|
||||||
|
throw new IllegalArgumentException(str);
|
||||||
|
token = tokenizer.nextToken();
|
||||||
|
String val = tokenizer.sval;
|
||||||
|
IProblemPreference desc = getChildDescriptor(key);
|
||||||
|
if (desc != null) {
|
||||||
|
desc.importValue(val);
|
||||||
|
} else {
|
||||||
|
//putChildValue(key, val);
|
||||||
|
}
|
||||||
|
token = tokenizer.nextToken();
|
||||||
|
if (token == '}')
|
||||||
|
break;
|
||||||
|
if (token != ',')
|
||||||
|
throw new IllegalArgumentException(str);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalArgumentException(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,114 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* 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.core.param;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ParameterInfo representing a single checker parameter
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class SingleParameterInfo extends AbstractProblemParameterInfo {
|
|
||||||
protected String key = PARAM;
|
|
||||||
protected String label;
|
|
||||||
protected String toolTip = null;
|
|
||||||
protected ParameterType type = ParameterType.TYPE_STRING;
|
|
||||||
protected String uiInfo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate an info with given key and label
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* - property id (use in actual property hash of a checker)
|
|
||||||
* @param label
|
|
||||||
* - label to be shown to user
|
|
||||||
* @param type
|
|
||||||
* - parameter type
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public SingleParameterInfo(String key, String label, ParameterType type) {
|
|
||||||
if (key == null)
|
|
||||||
throw new NullPointerException("key"); //$NON-NLS-1$
|
|
||||||
if (type == null)
|
|
||||||
throw new NullPointerException("type"); //$NON-NLS-1$
|
|
||||||
setKey(key);
|
|
||||||
setLabel(label);
|
|
||||||
setType(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate an info with given key and label
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* - property id (use in actual property hash of a checker)
|
|
||||||
* @param label
|
|
||||||
* - label to be shown to user
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public SingleParameterInfo(String key, String label) {
|
|
||||||
setKey(key);
|
|
||||||
setLabel(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate an info with given label, default key PARAM would be as a key
|
|
||||||
*
|
|
||||||
* @param label
|
|
||||||
* - label to be shown to user
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public SingleParameterInfo(String label) {
|
|
||||||
setLabel(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ParameterType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLabel() {
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getToolTip() {
|
|
||||||
return toolTip;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKey() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUiInfo() {
|
|
||||||
return uiInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKey(String key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLabel(String label) {
|
|
||||||
this.label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setToolTip(String tooltip) {
|
|
||||||
this.toolTip = tooltip;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(ParameterType type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUiInfo(String uiinfo) {
|
|
||||||
this.uiInfo = uiinfo;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -19,7 +19,7 @@ import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||||
import org.eclipse.cdt.codan.core.PreferenceConstants;
|
import org.eclipse.cdt.codan.core.PreferenceConstants;
|
||||||
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
||||||
import org.eclipse.cdt.codan.core.model.IChecker;
|
import org.eclipse.cdt.codan.core.model.IChecker;
|
||||||
import org.eclipse.cdt.codan.core.model.ICheckerWithParameters;
|
import org.eclipse.cdt.codan.core.model.ICheckerWithPreferences;
|
||||||
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.IProblemCategory;
|
import org.eclipse.cdt.codan.core.model.IProblemCategory;
|
||||||
|
@ -81,14 +81,19 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
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 ICheckerWithParameters) {
|
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) {
|
||||||
((ICheckerWithParameters) c)
|
try {
|
||||||
.initParameters((IProblemWorkingCopy) p);
|
((ICheckerWithPreferences) c)
|
||||||
|
.initPreferences((IProblemWorkingCopy) p);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
CodanCorePlugin.log(t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +166,7 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
addRefProblem(checkerObj, p);
|
addRefProblem(checkerObj, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Throwable e) {
|
||||||
CodanCorePlugin.log(e);
|
CodanCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||||
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
||||||
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.cdt.codan.core.param.IProblemPreference;
|
||||||
import org.eclipse.cdt.codan.internal.core.model.CodanProblem;
|
import org.eclipse.cdt.codan.internal.core.model.CodanProblem;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.ProjectScope;
|
import org.eclipse.core.resources.ProjectScope;
|
||||||
|
@ -21,7 +23,7 @@ import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||||
import org.osgi.service.prefs.Preferences;
|
import org.osgi.service.prefs.Preferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Alena
|
* Helper class to load/save problem profile settings in persistent storage
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class CodanPreferencesLoader {
|
public class CodanPreferencesLoader {
|
||||||
|
@ -58,7 +60,7 @@ public class CodanPreferencesLoader {
|
||||||
*/
|
*/
|
||||||
public void setProperty(String id, String s) {
|
public void setProperty(String id, String s) {
|
||||||
IProblem prob = baseModel.findProblem(id);
|
IProblem prob = baseModel.findProblem(id);
|
||||||
if (!(prob instanceof CodanProblem))
|
if (!(prob instanceof IProblemWorkingCopy))
|
||||||
return;
|
return;
|
||||||
String sevs = s;
|
String sevs = s;
|
||||||
boolean enabled = true;
|
boolean enabled = true;
|
||||||
|
@ -66,14 +68,14 @@ public class CodanPreferencesLoader {
|
||||||
sevs = sevs.substring(1);
|
sevs = sevs.substring(1);
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
((CodanProblem) prob).setEnabled(enabled);
|
((IProblemWorkingCopy) prob).setEnabled(enabled);
|
||||||
CodanSeverity sev;
|
CodanSeverity sev;
|
||||||
try {
|
try {
|
||||||
sev = CodanSeverity.valueOf(sevs);
|
sev = CodanSeverity.valueOf(sevs);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
sev = CodanSeverity.Warning;
|
sev = CodanSeverity.Warning;
|
||||||
}
|
}
|
||||||
((CodanProblem) prob).setSeverity(sev);
|
((IProblemWorkingCopy) prob).setSeverity(sev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -117,10 +119,28 @@ public class CodanPreferencesLoader {
|
||||||
String s = storePreferences.get(id, null);
|
String s = storePreferences.get(id, null);
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
setProperty(id, s);
|
setProperty(id, s);
|
||||||
|
setParameterValues(id, storePreferences);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param problemId
|
||||||
|
* @param storePreferences
|
||||||
|
*/
|
||||||
|
private void setParameterValues(String problemId,
|
||||||
|
Preferences storePreferences) {
|
||||||
|
IProblem prob = baseModel.findProblem(problemId);
|
||||||
|
String prefKey = getPreferencesKey(problemId);
|
||||||
|
if (prefKey == null)
|
||||||
|
return;
|
||||||
|
String exported = storePreferences.get(prefKey, null);
|
||||||
|
if (exported != null) {
|
||||||
|
System.err.println(prefKey + " import " + exported);
|
||||||
|
prob.getPreference().importValue(exported);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Preferences getProjectNode(IProject project) {
|
public static Preferences getProjectNode(IProject project) {
|
||||||
if (!project.exists())
|
if (!project.exists())
|
||||||
return null;
|
return null;
|
||||||
|
@ -138,4 +158,30 @@ public class CodanPreferencesLoader {
|
||||||
return null;
|
return null;
|
||||||
return prefNode;
|
return prefNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getPreferencesKey(String id) {
|
||||||
|
IProblem prob = baseModel.findProblem(id);
|
||||||
|
IProblemPreference pref = prob.getPreference();
|
||||||
|
if (pref == null)
|
||||||
|
return null;
|
||||||
|
return id + "." + pref.getKey(); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getPreferencesString(String id) {
|
||||||
|
IProblem prob = baseModel.findProblem(id);
|
||||||
|
IProblemPreference pref = prob.getPreference();
|
||||||
|
if (pref == null)
|
||||||
|
return null;
|
||||||
|
String str = pref.exportValue();
|
||||||
|
//System.err.println(id + " set " + str);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,10 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.core.model;
|
package org.eclipse.cdt.codan.internal.core.model;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemReporter;
|
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.IProblemParameterInfo;
|
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||||
|
|
||||||
public class CodanProblem implements IProblemWorkingCopy {
|
public class CodanProblem implements IProblemWorkingCopy {
|
||||||
private String id;
|
private String id;
|
||||||
|
@ -23,8 +21,7 @@ public class CodanProblem implements IProblemWorkingCopy {
|
||||||
private String message;
|
private String message;
|
||||||
private CodanSeverity severity = CodanSeverity.Warning;
|
private CodanSeverity severity = CodanSeverity.Warning;
|
||||||
private boolean enabled = true;
|
private boolean enabled = true;
|
||||||
private HashMap<Object, Object> parameters = new HashMap<Object, Object>(0);
|
private IProblemPreference preference;
|
||||||
private IProblemParameterInfo parameterInfo;
|
|
||||||
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;
|
||||||
|
@ -76,20 +73,12 @@ public class CodanProblem implements IProblemWorkingCopy {
|
||||||
return super.clone();
|
return super.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParameter(Object key, Object value) {
|
public void setPreference(IProblemPreference value) {
|
||||||
parameters.put(key, value);
|
preference = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParameterInfo(IProblemParameterInfo info) {
|
public IProblemPreference getPreference() {
|
||||||
parameterInfo = info;
|
return preference;
|
||||||
}
|
|
||||||
|
|
||||||
public Object getParameter(Object key) {
|
|
||||||
return parameters.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IProblemParameterInfo getParameterInfo() {
|
|
||||||
return parameterInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -11,12 +11,13 @@
|
||||||
package org.eclipse.cdt.codan.examples.checkers;
|
package org.eclipse.cdt.codan.examples.checkers;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.cxx.model.AbstractCIndexChecker;
|
import org.eclipse.cdt.codan.core.cxx.model.AbstractCIndexChecker;
|
||||||
import org.eclipse.cdt.codan.core.model.ICheckerWithParameters;
|
import org.eclipse.cdt.codan.core.model.ICheckerWithPreferences;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
||||||
import org.eclipse.cdt.codan.core.param.AbstractProblemParameterInfo;
|
import org.eclipse.cdt.codan.core.param.BasicProblemPreference;
|
||||||
import org.eclipse.cdt.codan.core.param.IProblemParameterInfo;
|
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICElementVisitor;
|
import org.eclipse.cdt.core.model.ICElementVisitor;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
@ -27,7 +28,7 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class NamingConventionFunctionIIndexChecker extends
|
public class NamingConventionFunctionIIndexChecker extends
|
||||||
AbstractCIndexChecker implements ICheckerWithParameters {
|
AbstractCIndexChecker implements ICheckerWithPreferences {
|
||||||
private static final String DEFAULT_PATTERN = "^[a-z]"; // name starts with english lowercase letter //$NON-NLS-1$
|
private static final String DEFAULT_PATTERN = "^[a-z]"; // name starts with english lowercase letter //$NON-NLS-1$
|
||||||
public static final String PARAM_KEY = "pattern"; //$NON-NLS-1$
|
public static final String PARAM_KEY = "pattern"; //$NON-NLS-1$
|
||||||
private static final String ER_ID = "org.eclipse.cdt.codan.examples.checkers.NamingConventionFunctionProblem"; //$NON-NLS-1$
|
private static final String ER_ID = "org.eclipse.cdt.codan.examples.checkers.NamingConventionFunctionProblem"; //$NON-NLS-1$
|
||||||
|
@ -45,7 +46,8 @@ public class NamingConventionFunctionIIndexChecker extends
|
||||||
unit.accept(new ICElementVisitor() {
|
unit.accept(new ICElementVisitor() {
|
||||||
public boolean visit(ICElement element) throws CoreException {
|
public boolean visit(ICElement element) throws CoreException {
|
||||||
if (element.getElementType() == ICElement.C_FUNCTION) {
|
if (element.getElementType() == ICElement.C_FUNCTION) {
|
||||||
String parameter = (String) pt.getParameter(PARAM_KEY);
|
String parameter = (String) pt.getPreference()
|
||||||
|
.getValue();
|
||||||
Pattern pattern = Pattern.compile(parameter);
|
Pattern pattern = Pattern.compile(parameter);
|
||||||
String name = element.getElementName();
|
String name = element.getElementName();
|
||||||
if (!pattern.matcher(name).find()) {
|
if (!pattern.matcher(name).find()) {
|
||||||
|
@ -67,21 +69,14 @@ public class NamingConventionFunctionIIndexChecker extends
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see
|
* @see
|
||||||
* org.eclipse.cdt.codan.core.model.ICheckerWithParameters#initParameters
|
* org.eclipse.cdt.codan.core.model.ICheckerWithPreferences#initParameters
|
||||||
* (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy)
|
* (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy)
|
||||||
*/
|
*/
|
||||||
public void initParameters(IProblemWorkingCopy problem) {
|
public void initPreferences(IProblemWorkingCopy problem) {
|
||||||
IProblemParameterInfo info = new AbstractProblemParameterInfo() {
|
IProblemPreference info = new BasicProblemPreference(PARAM_KEY,
|
||||||
public String getLabel() {
|
"Name Pattern");
|
||||||
return "Name Pattern";
|
info.setValue(DEFAULT_PATTERN);
|
||||||
}
|
problem.setPreference(info);
|
||||||
|
|
||||||
public String getKey() {
|
|
||||||
return PARAM_KEY;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
problem.setParameterInfo(info);
|
|
||||||
problem.setParameter(PARAM_KEY, DEFAULT_PATTERN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
#Sat May 15 20:01:30 EDT 2010
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
|
||||||
|
sp_cleanup.add_default_serial_version_id=true
|
||||||
|
sp_cleanup.add_generated_serial_version_id=false
|
||||||
|
sp_cleanup.add_missing_annotations=true
|
||||||
|
sp_cleanup.add_missing_deprecated_annotations=true
|
||||||
|
sp_cleanup.add_missing_methods=false
|
||||||
|
sp_cleanup.add_missing_nls_tags=false
|
||||||
|
sp_cleanup.add_missing_override_annotations=true
|
||||||
|
sp_cleanup.add_missing_override_annotations_interface_methods=false
|
||||||
|
sp_cleanup.add_serial_version_id=false
|
||||||
|
sp_cleanup.always_use_blocks=true
|
||||||
|
sp_cleanup.always_use_parentheses_in_expressions=false
|
||||||
|
sp_cleanup.always_use_this_for_non_static_field_access=false
|
||||||
|
sp_cleanup.always_use_this_for_non_static_method_access=false
|
||||||
|
sp_cleanup.convert_to_enhanced_for_loop=false
|
||||||
|
sp_cleanup.correct_indentation=false
|
||||||
|
sp_cleanup.format_source_code=true
|
||||||
|
sp_cleanup.format_source_code_changes_only=false
|
||||||
|
sp_cleanup.make_local_variable_final=false
|
||||||
|
sp_cleanup.make_parameters_final=false
|
||||||
|
sp_cleanup.make_private_fields_final=true
|
||||||
|
sp_cleanup.make_type_abstract_if_missing_method=false
|
||||||
|
sp_cleanup.make_variable_declarations_final=false
|
||||||
|
sp_cleanup.never_use_blocks=false
|
||||||
|
sp_cleanup.never_use_parentheses_in_expressions=true
|
||||||
|
sp_cleanup.on_save_use_additional_actions=true
|
||||||
|
sp_cleanup.organize_imports=true
|
||||||
|
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
|
||||||
|
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
|
||||||
|
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
|
||||||
|
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
|
||||||
|
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
|
||||||
|
sp_cleanup.remove_private_constructors=true
|
||||||
|
sp_cleanup.remove_trailing_whitespaces=false
|
||||||
|
sp_cleanup.remove_trailing_whitespaces_all=true
|
||||||
|
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
|
||||||
|
sp_cleanup.remove_unnecessary_casts=true
|
||||||
|
sp_cleanup.remove_unnecessary_nls_tags=true
|
||||||
|
sp_cleanup.remove_unused_imports=true
|
||||||
|
sp_cleanup.remove_unused_local_variables=false
|
||||||
|
sp_cleanup.remove_unused_private_fields=true
|
||||||
|
sp_cleanup.remove_unused_private_members=false
|
||||||
|
sp_cleanup.remove_unused_private_methods=true
|
||||||
|
sp_cleanup.remove_unused_private_types=true
|
||||||
|
sp_cleanup.sort_members=false
|
||||||
|
sp_cleanup.sort_members_all=false
|
||||||
|
sp_cleanup.use_blocks=false
|
||||||
|
sp_cleanup.use_blocks_only_for_return_and_throw=false
|
||||||
|
sp_cleanup.use_parentheses_in_expressions=false
|
||||||
|
sp_cleanup.use_this_for_non_static_field_access=false
|
||||||
|
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
|
||||||
|
sp_cleanup.use_this_for_non_static_method_access=false
|
||||||
|
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
|
|
@ -22,7 +22,7 @@ public class CodanUIMessages extends NLS {
|
||||||
public static String CheckedTreeEditor_SelectionCannotBeEmpty;
|
public static String CheckedTreeEditor_SelectionCannotBeEmpty;
|
||||||
public static String CodanPreferencePage_Customize;
|
public static String CodanPreferencePage_Customize;
|
||||||
public static String CodanPreferencePage_Description;
|
public static String CodanPreferencePage_Description;
|
||||||
public static String CodanPreferencePage_HasParameters;
|
public static String CodanPreferencePage_HasPreferences;
|
||||||
public static String CodanPreferencePage_Info;
|
public static String CodanPreferencePage_Info;
|
||||||
public static String CodanPreferencePage_MessageLabel;
|
public static String CodanPreferencePage_MessageLabel;
|
||||||
public static String CodanPreferencePage_NoInfo;
|
public static String CodanPreferencePage_NoInfo;
|
||||||
|
|
|
@ -10,12 +10,11 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.ui.dialogs;
|
package org.eclipse.cdt.codan.internal.ui.dialogs;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.io.File;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
||||||
import org.eclipse.cdt.codan.core.param.IProblemParameterInfo;
|
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||||
import org.eclipse.cdt.codan.core.param.IProblemParameterInfo.ParameterType;
|
|
||||||
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
|
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
|
||||||
import org.eclipse.jface.preference.BooleanFieldEditor;
|
import org.eclipse.jface.preference.BooleanFieldEditor;
|
||||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||||
|
@ -28,13 +27,13 @@ import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Label;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Alena
|
* Composite to show problem preferences
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ParametersComposite extends Composite {
|
public class ParametersComposite extends Composite {
|
||||||
private FieldEditorPreferencePage page;
|
private FieldEditorPreferencePage page;
|
||||||
private IProblem problem;
|
private IProblem problem;
|
||||||
private PreferenceStore pref;
|
private PreferenceStore prefStore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param parent
|
* @param parent
|
||||||
|
@ -47,44 +46,42 @@ public class ParametersComposite extends Composite {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
this.setLayout(new GridLayout(2, false));
|
this.setLayout(new GridLayout(2, false));
|
||||||
this.problem = problem;
|
this.problem = problem;
|
||||||
this.pref = new PreferenceStore();
|
this.prefStore = new PreferenceStore();
|
||||||
page = new FieldEditorPreferencePage() {
|
page = new FieldEditorPreferencePage() {
|
||||||
@Override
|
@Override
|
||||||
protected void createFieldEditors() {
|
protected void createFieldEditors() {
|
||||||
noDefaultAndApplyButton();
|
noDefaultAndApplyButton();
|
||||||
IProblemParameterInfo parameterInfo = problem
|
IProblemPreference pref = problem.getPreference();
|
||||||
.getParameterInfo();
|
createFieldEditorsForParameters(pref);
|
||||||
createFieldEditorsForParameters(parameterInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param info
|
* @param info
|
||||||
*/
|
*/
|
||||||
private void createFieldEditorsForParameters(
|
private void createFieldEditorsForParameters(IProblemPreference info) {
|
||||||
IProblemParameterInfo info) {
|
|
||||||
if (info == null)
|
if (info == null)
|
||||||
return;
|
return;
|
||||||
switch (info.getType()) {
|
switch (info.getType()) {
|
||||||
case TYPE_STRING: {
|
case TYPE_STRING: {
|
||||||
StringFieldEditor fe = new StringFieldEditor(
|
StringFieldEditor fe = new StringFieldEditor(
|
||||||
info.getKey(), info.getLabel(),
|
info.getQualifiedKey(), info.getLabel(),
|
||||||
getFieldEditorParent());
|
getFieldEditorParent());
|
||||||
addField(fe);
|
addField(fe);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TYPE_BOOLEAN: {
|
case TYPE_BOOLEAN: {
|
||||||
BooleanFieldEditor fe = new BooleanFieldEditor(
|
BooleanFieldEditor fe = new BooleanFieldEditor(
|
||||||
info.getKey(), info.getLabel(),
|
info.getQualifiedKey(), info.getLabel(),
|
||||||
getFieldEditorParent());
|
getFieldEditorParent());
|
||||||
addField(fe);
|
addField(fe);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TYPE_MAP: {
|
case TYPE_MAP: {
|
||||||
Iterator<IProblemParameterInfo> iterator = info
|
IProblemPreference[] childrenDescriptor = info
|
||||||
.getIterator();
|
.getChildDescriptors();
|
||||||
while (iterator.hasNext()) {
|
for (int i = 0; i < childrenDescriptor.length; i++) {
|
||||||
IProblemParameterInfo info1 = iterator.next();
|
IProblemPreference desc = childrenDescriptor[i];
|
||||||
createFieldEditorsForParameters(info1);
|
createFieldEditorsForParameters(desc);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -94,70 +91,92 @@ public class ParametersComposite extends Composite {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
IProblemParameterInfo info = problem.getParameterInfo();
|
IProblemPreference info = problem.getPreference();
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
Label label = new Label(this, 0);
|
Label label = new Label(this, 0);
|
||||||
label.setText(CodanUIMessages.ParametersComposite_None);
|
label.setText(CodanUIMessages.ParametersComposite_None);
|
||||||
|
} else {
|
||||||
|
initPrefStore(info);
|
||||||
}
|
}
|
||||||
initPrefStore(info);
|
page.setPreferenceStore(prefStore);
|
||||||
page.setPreferenceStore(pref);
|
|
||||||
page.createControl(parent);
|
page.createControl(parent);
|
||||||
page.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
|
page.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(IProblemWorkingCopy problemwc) {
|
public void save(IProblemWorkingCopy problem) {
|
||||||
page.performOk();
|
page.performOk();
|
||||||
IProblemParameterInfo info = problemwc.getParameterInfo();
|
savePrefStore(problem.getPreference());
|
||||||
savePrefStore(info, problemwc);
|
}
|
||||||
|
|
||||||
|
private void savePrefStore(IProblemPreference desc) {
|
||||||
|
if (desc == null)
|
||||||
|
return;
|
||||||
|
String key = desc.getQualifiedKey();
|
||||||
|
switch (desc.getType()) {
|
||||||
|
case TYPE_STRING:
|
||||||
|
desc.setValue(prefStore.getString(key));
|
||||||
|
break;
|
||||||
|
case TYPE_BOOLEAN:
|
||||||
|
desc.setValue(prefStore.getBoolean(key));
|
||||||
|
break;
|
||||||
|
case TYPE_INTEGER:
|
||||||
|
desc.setValue(prefStore.getInt(key));
|
||||||
|
break;
|
||||||
|
case TYPE_FILE:
|
||||||
|
desc.setValue(new File(prefStore.getString(key)));
|
||||||
|
break;
|
||||||
|
case TYPE_MAP:
|
||||||
|
case TYPE_LIST:
|
||||||
|
IProblemPreference[] childrenDescriptor = desc
|
||||||
|
.getChildDescriptors();
|
||||||
|
for (int i = 0; i < childrenDescriptor.length; i++) {
|
||||||
|
IProblemPreference chi = childrenDescriptor[i];
|
||||||
|
savePrefStore(chi);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new UnsupportedOperationException(desc.getType()
|
||||||
|
.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initPrefStore(IProblemPreference desc) {
|
||||||
|
if (desc == null)
|
||||||
|
return;
|
||||||
|
String key = desc.getQualifiedKey();
|
||||||
|
switch (desc.getType()) {
|
||||||
|
case TYPE_STRING:
|
||||||
|
prefStore.setValue(key, (String) desc.getValue());
|
||||||
|
break;
|
||||||
|
case TYPE_BOOLEAN:
|
||||||
|
prefStore.setValue(key, (Boolean) desc.getValue());
|
||||||
|
break;
|
||||||
|
case TYPE_INTEGER:
|
||||||
|
prefStore.setValue(key, (Integer) desc.getValue());
|
||||||
|
break;
|
||||||
|
case TYPE_FILE:
|
||||||
|
prefStore.setValue(key, ((File) desc.getValue()).getPath());
|
||||||
|
break;
|
||||||
|
case TYPE_MAP:
|
||||||
|
case TYPE_LIST: {
|
||||||
|
IProblemPreference[] childrenDescriptor = desc
|
||||||
|
.getChildDescriptors();
|
||||||
|
for (int i = 0; i < childrenDescriptor.length; i++) {
|
||||||
|
IProblemPreference chi = childrenDescriptor[i];
|
||||||
|
initPrefStore(chi);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new UnsupportedOperationException(desc.getType()
|
||||||
|
.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param info
|
* @return the problem
|
||||||
* @param problemwc
|
|
||||||
*/
|
*/
|
||||||
private void savePrefStore(IProblemParameterInfo info,
|
public IProblem getProblem() {
|
||||||
IProblemWorkingCopy problemwc) {
|
return problem;
|
||||||
if (info == null)
|
|
||||||
return;
|
|
||||||
String key = info.getKey();
|
|
||||||
Object parameter = problem.getParameter(key);
|
|
||||||
if (info.getType() == ParameterType.TYPE_MAP && parameter == null) {
|
|
||||||
Iterator<IProblemParameterInfo> iterator = info.getIterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
IProblemParameterInfo info1 = iterator.next();
|
|
||||||
savePrefStore(info1, problemwc);
|
|
||||||
}
|
|
||||||
} else if (parameter instanceof String) {
|
|
||||||
String newValue = pref.getString(key);
|
|
||||||
problemwc.setParameter(key, newValue);
|
|
||||||
} else if (parameter instanceof Boolean) {
|
|
||||||
boolean newValue = pref.getBoolean(key);
|
|
||||||
problemwc.setParameter(key, newValue);
|
|
||||||
} else
|
|
||||||
throw new UnsupportedOperationException(info.getType().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param info
|
|
||||||
*/
|
|
||||||
private void initPrefStore(IProblemParameterInfo info) {
|
|
||||||
if (info == null)
|
|
||||||
return;
|
|
||||||
String key = info.getKey();
|
|
||||||
Object parameter = problem.getParameter(key);
|
|
||||||
if (info.getType() == ParameterType.TYPE_MAP && parameter == null) {
|
|
||||||
Iterator<IProblemParameterInfo> iterator = info.getIterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
IProblemParameterInfo info1 = iterator.next();
|
|
||||||
initPrefStore(info1);
|
|
||||||
}
|
|
||||||
} else if (parameter instanceof String) {
|
|
||||||
pref.setDefault(key, (String) parameter);
|
|
||||||
pref.setValue(key, (String) parameter);
|
|
||||||
} else if (parameter instanceof Boolean) {
|
|
||||||
pref.setDefault(key, (Boolean) parameter);
|
|
||||||
pref.setValue(key, (Boolean) parameter);
|
|
||||||
} else
|
|
||||||
throw new UnsupportedOperationException(info.getType().toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,17 +3,17 @@ BuildPropertyPage_RunWithBuild=&Run with build
|
||||||
CheckedTreeEditor_SelectionCannotBeEmpty=Selection cannot be empty
|
CheckedTreeEditor_SelectionCannotBeEmpty=Selection cannot be empty
|
||||||
CodanPreferencePage_Customize=Customize...
|
CodanPreferencePage_Customize=Customize...
|
||||||
CodanPreferencePage_Description=Description:
|
CodanPreferencePage_Description=Description:
|
||||||
CodanPreferencePage_HasParameters=This problem has parameters
|
CodanPreferencePage_HasPreferences=This problem has extra preferences
|
||||||
CodanPreferencePage_Info=Info
|
CodanPreferencePage_Info=Info
|
||||||
CodanPreferencePage_MessageLabel=Message:
|
CodanPreferencePage_MessageLabel=Message:
|
||||||
CodanPreferencePage_NoInfo=Not defined
|
CodanPreferencePage_NoInfo=Not defined
|
||||||
CodanPreferencePage_Parameters=Parameters:
|
CodanPreferencePage_Parameters=Parameters:
|
||||||
CustomizeProblemComposite_TabParameters=Parameters
|
CustomizeProblemComposite_TabParameters=Preferences
|
||||||
CustomizeProblemComposite_TabScope=Scope
|
CustomizeProblemComposite_TabScope=Scope
|
||||||
CustomizeProblemDialog_Message=Edit problem parameters, scope and launch options
|
CustomizeProblemDialog_Message=Edit problem preferences, scope and launch options
|
||||||
CustomizeProblemDialog_Title=Customize Problem...
|
CustomizeProblemDialog_Title=Customize Problem...
|
||||||
Job_TitleRunningAnalysis=Running Code Analysis
|
Job_TitleRunningAnalysis=Running Code Analysis
|
||||||
ParametersComposite_None=No Parameters
|
ParametersComposite_None=No extra preferences
|
||||||
ProblemsTreeEditor_NameColumn=Name
|
ProblemsTreeEditor_NameColumn=Name
|
||||||
ProblemsTreeEditor_Problems=Problems
|
ProblemsTreeEditor_Problems=Problems
|
||||||
ProblemsTreeEditor_SeverityColumn=Severity
|
ProblemsTreeEditor_SeverityColumn=Severity
|
||||||
|
|
|
@ -17,7 +17,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.param.IProblemParameterInfo;
|
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;
|
||||||
|
@ -88,6 +88,7 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
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$
|
||||||
}
|
}
|
||||||
|
@ -97,12 +98,13 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
* GUI blocks needed to manipulate various types of preferences. Each field
|
* GUI blocks needed to manipulate various types of preferences. Each field
|
||||||
* editor knows how to save and restore itself.
|
* editor knows how to save and restore itself.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void createFieldEditors() {
|
public void createFieldEditors() {
|
||||||
profile = isPropertyPage() ? getRegistry()
|
profile = isPropertyPage() ? getRegistry()
|
||||||
.getResourceProfileWorkingCopy((IResource) getElement())
|
.getResourceProfileWorkingCopy((IResource) getElement())
|
||||||
: getRegistry().getWorkspaceProfile();
|
: getRegistry().getWorkspaceProfile();
|
||||||
checkedTreeEditor = new ProblemsTreeEditor(
|
checkedTreeEditor = new ProblemsTreeEditor(getFieldEditorParent(),
|
||||||
getFieldEditorParent(), profile);
|
profile);
|
||||||
addField(checkedTreeEditor);
|
addField(checkedTreeEditor);
|
||||||
checkedTreeEditor.getTreeViewer().addSelectionChangedListener(
|
checkedTreeEditor.getTreeViewer().addSelectionChangedListener(
|
||||||
problemSelectionListener);
|
problemSelectionListener);
|
||||||
|
@ -136,10 +138,10 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
info.setLayoutData(new GridData(GridData.FILL_BOTH));
|
info.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||||
info.setLayout(new GridLayout(3, false));
|
info.setLayout(new GridLayout(3, false));
|
||||||
info.setText(CodanUIMessages.CodanPreferencePage_Info);
|
info.setText(CodanUIMessages.CodanPreferencePage_Info);
|
||||||
GridDataFactory gdLab = GridDataFactory.swtDefaults().align(
|
GridDataFactory gdLab = GridDataFactory.swtDefaults()
|
||||||
SWT.BEGINNING, SWT.BEGINNING).grab(false, false);
|
.align(SWT.BEGINNING, SWT.BEGINNING).grab(false, false);
|
||||||
GridDataFactory gdFact = GridDataFactory.swtDefaults().align(
|
GridDataFactory gdFact = GridDataFactory.swtDefaults()
|
||||||
SWT.BEGINNING, SWT.BEGINNING).grab(true, true);
|
.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);
|
||||||
|
@ -152,8 +154,12 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
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.copy().span(2, 1).hint(pixelConverter.convertWidthInCharsToPixels(60),
|
infoDesc.setLayoutData(gdFact
|
||||||
pixelConverter.convertHeightInCharsToPixels(3)).create());
|
.copy()
|
||||||
|
.span(2, 1)
|
||||||
|
.hint(pixelConverter.convertWidthInCharsToPixels(60),
|
||||||
|
pixelConverter.convertHeightInCharsToPixels(3))
|
||||||
|
.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);
|
||||||
|
@ -161,8 +167,8 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
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().align(SWT.END,
|
infoButton.setLayoutData(GridDataFactory.swtDefaults()
|
||||||
SWT.BEGINNING).create());
|
.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
|
||||||
|
@ -170,7 +176,7 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
openCustomizeDialog();
|
openCustomizeDialog();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
restoreWidgetValues();
|
restoreWidgetValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -205,15 +211,19 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private void saveWidgetValues() {
|
private void saveWidgetValues() {
|
||||||
CodanUIActivator.getDefault().getDialogSettings().put(getWidgetId(),
|
CodanUIActivator
|
||||||
selectedProblem == null ? "" : selectedProblem.getId()); //$NON-NLS-1$
|
.getDefault()
|
||||||
|
.getDialogSettings()
|
||||||
|
.put(getWidgetId(),
|
||||||
|
selectedProblem == null ? "" : selectedProblem.getId()); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreWidgetValues() {
|
private void restoreWidgetValues() {
|
||||||
String id = CodanUIActivator.getDefault().getDialogSettings().get(
|
String id = CodanUIActivator.getDefault().getDialogSettings()
|
||||||
getWidgetId());
|
.get(getWidgetId());
|
||||||
if (id != null && id.length() > 0) {
|
if (id != null && id.length() > 0) {
|
||||||
checkedTreeEditor.getTreeViewer().setSelection(new StructuredSelection(profile.findProblem(id)), true);
|
checkedTreeEditor.getTreeViewer().setSelection(
|
||||||
|
new StructuredSelection(profile.findProblem(id)), true);
|
||||||
} else {
|
} else {
|
||||||
setSelectedProblem(null);
|
setSelectedProblem(null);
|
||||||
}
|
}
|
||||||
|
@ -236,21 +246,20 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
||||||
infoParams.setText(""); //$NON-NLS-1$
|
infoParams.setText(""); //$NON-NLS-1$
|
||||||
infoButton.setEnabled(false);
|
infoButton.setEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
IProblemParameterInfo parameterInfo = selectedProblem
|
IProblemPreference pref = selectedProblem.getPreference();
|
||||||
.getParameterInfo();
|
String description = selectedProblem.getDescription();
|
||||||
String desc = selectedProblem.getDescription();
|
if (description == null)
|
||||||
if (desc == null)
|
description = CodanUIMessages.CodanPreferencePage_NoInfo;
|
||||||
desc = CodanUIMessages.CodanPreferencePage_NoInfo;
|
|
||||||
String messagePattern = selectedProblem.getMessagePattern();
|
String messagePattern = selectedProblem.getMessagePattern();
|
||||||
String message = CodanUIMessages.CodanPreferencePage_NoInfo;
|
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$ //$NON-NLS-4$
|
message = MessageFormat.format(messagePattern, "X", "Y", "Z"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
}
|
}
|
||||||
infoMessage.setText(message);
|
infoMessage.setText(message);
|
||||||
infoDesc.setText(desc);
|
infoDesc.setText(description);
|
||||||
infoParams
|
infoParams
|
||||||
.setText(parameterInfo == null ? CodanUIMessages.CodanPreferencePage_NoInfo
|
.setText(pref == null ? CodanUIMessages.CodanPreferencePage_NoInfo
|
||||||
: CodanUIMessages.CodanPreferencePage_HasParameters);
|
: CodanUIMessages.CodanPreferencePage_HasPreferences);
|
||||||
infoButton.setEnabled(true);
|
infoButton.setEnabled(true);
|
||||||
}
|
}
|
||||||
info.layout(true);
|
info.layout(true);
|
||||||
|
|
|
@ -62,7 +62,9 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
||||||
Object[] children = p.getChildren();
|
Object[] children = p.getChildren();
|
||||||
for (int i = 0; i < children.length; i++) {
|
for (int i = 0; i < children.length; i++) {
|
||||||
Object object = children[i];
|
Object object = children[i];
|
||||||
if (isChecked(object)) { return true; }
|
if (isChecked(object)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -76,7 +78,9 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
||||||
* Object)
|
* Object)
|
||||||
*/
|
*/
|
||||||
public boolean isGrayed(Object element) {
|
public boolean isGrayed(Object element) {
|
||||||
if (element instanceof IProblem) { return false; }
|
if (element instanceof IProblem) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (element instanceof IProblemCategory) {
|
if (element instanceof IProblemCategory) {
|
||||||
// checked if at least one is checked (buy grayed)
|
// checked if at least one is checked (buy grayed)
|
||||||
IProblemCategory p = (IProblemCategory) element;
|
IProblemCategory p = (IProblemCategory) element;
|
||||||
|
@ -91,14 +95,16 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
||||||
all_checked = false;
|
all_checked = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (all_checked || all_unchecked) return false;
|
if (all_checked || all_unchecked)
|
||||||
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProblemsContentProvider implements IContentProvider, ITreeContentProvider {
|
class ProblemsContentProvider implements IContentProvider,
|
||||||
|
ITreeContentProvider {
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
}
|
}
|
||||||
|
@ -108,10 +114,15 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] getChildren(Object parentElement) {
|
public Object[] getChildren(Object parentElement) {
|
||||||
if (parentElement instanceof Object[]) return (Object[]) parentElement;
|
if (parentElement instanceof Object[])
|
||||||
if (parentElement instanceof IProblemCategory) { return ((IProblemCategory) parentElement).getChildren(); }
|
return (Object[]) parentElement;
|
||||||
if (parentElement instanceof IProblemProfile) { return ((IProblemProfile) parentElement).getRoot()
|
if (parentElement instanceof IProblemCategory) {
|
||||||
.getChildren(); }
|
return ((IProblemCategory) parentElement).getChildren();
|
||||||
|
}
|
||||||
|
if (parentElement instanceof IProblemProfile) {
|
||||||
|
return ((IProblemProfile) parentElement).getRoot()
|
||||||
|
.getChildren();
|
||||||
|
}
|
||||||
return new Object[0];
|
return new Object[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,35 +139,39 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void checkStateChanged(CheckStateChangedEvent event) {
|
public void checkStateChanged(CheckStateChangedEvent event) {
|
||||||
Object element = event.getElement();
|
Object element = event.getElement();
|
||||||
if (element instanceof IProblemWorkingCopy) {
|
if (element instanceof IProblemWorkingCopy) {
|
||||||
((IProblemWorkingCopy) element).setEnabled(event.getChecked());
|
((IProblemWorkingCopy) element).setEnabled(event.getChecked());
|
||||||
} else if (element instanceof IProblemCategory) {
|
} else if (element instanceof IProblemCategory) {
|
||||||
IProblemCategory cat = (IProblemCategory)element;
|
IProblemCategory cat = (IProblemCategory) element;
|
||||||
IProblemElement[] children = cat.getChildren();
|
IProblemElement[] children = cat.getChildren();
|
||||||
for (int i = 0; i < children.length; i++) {
|
for (int i = 0; i < children.length; i++) {
|
||||||
IProblemElement pe = children[i];
|
IProblemElement pe = children[i];
|
||||||
checkStateChanged(new CheckStateChangedEvent(getTreeViewer(), pe, event.getChecked()));
|
checkStateChanged(new CheckStateChangedEvent(getTreeViewer(),
|
||||||
|
pe, event.getChecked()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getTreeViewer().refresh();
|
getTreeViewer().refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ProblemsTreeEditor(Composite parent, IProblemProfile profile) {
|
public ProblemsTreeEditor(Composite parent, IProblemProfile profile) {
|
||||||
super(PreferenceConstants.P_PROBLEMS, CodanUIMessages.ProblemsTreeEditor_Problems, parent);
|
super(PreferenceConstants.P_PROBLEMS,
|
||||||
|
CodanUIMessages.ProblemsTreeEditor_Problems, parent);
|
||||||
setEmptySelectionAllowed(true);
|
setEmptySelectionAllowed(true);
|
||||||
getTreeViewer().getTree().setHeaderVisible(true);
|
getTreeViewer().getTree().setHeaderVisible(true);
|
||||||
// getTreeViewer().getTree().
|
// getTreeViewer().getTree().
|
||||||
getTreeViewer().setContentProvider(new ProblemsContentProvider());
|
getTreeViewer().setContentProvider(new ProblemsContentProvider());
|
||||||
getTreeViewer().setCheckStateProvider(new ProblemsCheckStateProvider());
|
getTreeViewer().setCheckStateProvider(new ProblemsCheckStateProvider());
|
||||||
// column Name
|
// column Name
|
||||||
TreeViewerColumn column1 = new TreeViewerColumn(getTreeViewer(), SWT.NONE);
|
TreeViewerColumn column1 = new TreeViewerColumn(getTreeViewer(),
|
||||||
|
SWT.NONE);
|
||||||
column1.getColumn().setWidth(300);
|
column1.getColumn().setWidth(300);
|
||||||
column1.getColumn().setText(CodanUIMessages.ProblemsTreeEditor_NameColumn);
|
column1.getColumn().setText(
|
||||||
|
CodanUIMessages.ProblemsTreeEditor_NameColumn);
|
||||||
column1.setLabelProvider(new ColumnLabelProvider() {
|
column1.setLabelProvider(new ColumnLabelProvider() {
|
||||||
|
@Override
|
||||||
public String getText(Object element) {
|
public String getText(Object element) {
|
||||||
if (element instanceof IProblem) {
|
if (element instanceof IProblem) {
|
||||||
IProblem p = (IProblem) element;
|
IProblem p = (IProblem) element;
|
||||||
|
@ -170,27 +185,34 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// column Severity
|
// column Severity
|
||||||
TreeViewerColumn column2 = new TreeViewerColumn(getTreeViewer(), SWT.NONE);
|
TreeViewerColumn column2 = new TreeViewerColumn(getTreeViewer(),
|
||||||
|
SWT.NONE);
|
||||||
column2.getColumn().setWidth(100);
|
column2.getColumn().setWidth(100);
|
||||||
column2.getColumn().setText(CodanUIMessages.ProblemsTreeEditor_SeverityColumn);
|
column2.getColumn().setText(
|
||||||
|
CodanUIMessages.ProblemsTreeEditor_SeverityColumn);
|
||||||
column2.setLabelProvider(new ColumnLabelProvider() {
|
column2.setLabelProvider(new ColumnLabelProvider() {
|
||||||
@Override
|
@Override
|
||||||
public Image getImage(Object element) {
|
public Image getImage(Object element) {
|
||||||
final ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
|
final ISharedImages images = PlatformUI.getWorkbench()
|
||||||
|
.getSharedImages();
|
||||||
if (element instanceof IProblem) {
|
if (element instanceof IProblem) {
|
||||||
IProblem p = (IProblem) element;
|
IProblem p = (IProblem) element;
|
||||||
switch (p.getSeverity().intValue()) {
|
switch (p.getSeverity().intValue()) {
|
||||||
case IMarker.SEVERITY_INFO:
|
case IMarker.SEVERITY_INFO:
|
||||||
return images.getImage(ISharedImages.IMG_OBJS_INFO_TSK);
|
return images
|
||||||
case IMarker.SEVERITY_WARNING:
|
.getImage(ISharedImages.IMG_OBJS_INFO_TSK);
|
||||||
return images.getImage(ISharedImages.IMG_OBJS_WARN_TSK);
|
case IMarker.SEVERITY_WARNING:
|
||||||
case IMarker.SEVERITY_ERROR:
|
return images
|
||||||
return images.getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
|
.getImage(ISharedImages.IMG_OBJS_WARN_TSK);
|
||||||
|
case IMarker.SEVERITY_ERROR:
|
||||||
|
return images
|
||||||
|
.getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getText(Object element) {
|
public String getText(Object element) {
|
||||||
if (element instanceof IProblem) {
|
if (element instanceof IProblem) {
|
||||||
IProblem p = (IProblem) element;
|
IProblem p = (IProblem) element;
|
||||||
|
@ -200,18 +222,23 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
column2.setEditingSupport(new EditingSupport(getTreeViewer()) {
|
column2.setEditingSupport(new EditingSupport(getTreeViewer()) {
|
||||||
|
@Override
|
||||||
protected boolean canEdit(Object element) {
|
protected boolean canEdit(Object element) {
|
||||||
return element instanceof IProblem;
|
return element instanceof IProblem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected CellEditor getCellEditor(Object element) {
|
protected CellEditor getCellEditor(Object element) {
|
||||||
return new ComboBoxCellEditor(getTreeViewer().getTree(), CodanSeverity.stringValues());
|
return new ComboBoxCellEditor(getTreeViewer().getTree(),
|
||||||
|
CodanSeverity.stringValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected Object getValue(Object element) {
|
protected Object getValue(Object element) {
|
||||||
return ((IProblem) element).getSeverity().intValue();
|
return ((IProblem) element).getSeverity().intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setValue(Object element, Object value) {
|
protected void setValue(Object element, Object value) {
|
||||||
int index = ((Integer) value).intValue();
|
int index = ((Integer) value).intValue();
|
||||||
CodanSeverity val = CodanSeverity.values()[index];
|
CodanSeverity val = CodanSeverity.values()[index];
|
||||||
|
@ -276,6 +303,10 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
||||||
String id = probs[i].getId();
|
String id = probs[i].getId();
|
||||||
String s = codanPreferencesLoader.getProperty(id);
|
String s = codanPreferencesLoader.getProperty(id);
|
||||||
getPreferenceStore().setValue(id, s);
|
getPreferenceStore().setValue(id, s);
|
||||||
|
String params = codanPreferencesLoader.getPreferencesString(id);
|
||||||
|
if (params != null)
|
||||||
|
getPreferenceStore().setValue(
|
||||||
|
codanPreferencesLoader.getPreferencesKey(id), params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue