summaryrefslogtreecommitdiffstats
path: root/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/IProblemPreferenceDescriptor.java
blob: f6f97e0e038d1eb305c5e6c24ce360e652995554 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*******************************************************************************
 * 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 java.util.List;
import java.util.Map;

/**
 * Problem parameter usually key=value settings that allows to alter checker
 * behaviour for given problem. For example if checker finds violation of naming
 * conventions for function, parameter would be the pattern of allowed names.
 * 
 * IProblemPreferenceDescriptor represent preference's meta-info for the ui. If
 * more than one parameter is required it can be map or list of sub-preferences.
 * This is only needed for auto-generated ui for parameter
 * editing. For more complex cases custom ui control should be used. Extend
 * {@link AbstractProblemPreference} class
 * to implement this interface.
 * 
 * @noextend This interface is not intended to be extended by clients.
 * @noimplement This interface is not intended to be implemented by clients.
 */
public interface IProblemPreferenceDescriptor extends Cloneable {
	/**
	 * Type of the user preference
	 */
	public enum PreferenceType {
		/**
		 * String type, represented by string input field by default
		 */
		TYPE_STRING("string"), //$NON-NLS-1$
		/**
		 * Integer type, represented by integer input field by default
		 */
		TYPE_INTEGER("integer"), //$NON-NLS-1$
		/**
		 * Boolean type, represented by checkbox (boolean input field)
		 */
		TYPE_BOOLEAN("boolean"), //$NON-NLS-1$
		/**
		 * File type, represented by file picker input field
		 */
		TYPE_FILE("file"), //$NON-NLS-1$
		/**
		 * List type, represented by list (table) control
		 */
		TYPE_LIST("list"), //$NON-NLS-1$
		/**
		 * Map type, represented by composite of children fields
		 */
		TYPE_MAP("map"), //$NON-NLS-1$
		/**
		 * Custom type, represented by string input field by default
		 */
		TYPE_CUSTOM("custom"); //$NON-NLS-1$
		private String literal;

		private PreferenceType(String literal) {
			this.literal = literal;
		}

		/**
		 * @param name - name of the type literal (i.e. comes from name() or
		 *        toString())
		 * @return type represented by this name
		 */
		public static PreferenceType valueOfLiteral(String name) {
			PreferenceType[] values = values();
			for (int i = 0; i < values.length; i++) {
				PreferenceType e = values[i];
				if (e.literal.equals(name))
					return e;
			}
			return null;
		}

		@Override
		public String toString() {
			return literal;
		}

		/**
		 * @param value
		 * @return parameter type corresponding to the value java type
		 */
		public static PreferenceType typeOf(Object value) {
			if (value instanceof Boolean)
				return TYPE_BOOLEAN;
			if (value instanceof String)
				return TYPE_STRING;
			if (value instanceof Integer)
				return TYPE_INTEGER;
			if (value instanceof File)
				return TYPE_FILE;
			if (value instanceof List)
				return TYPE_LIST;
			if (value instanceof Map)
				return TYPE_MAP;
			return TYPE_CUSTOM;
		}
	}

	/**
	 * Key of the preference. Key must be java-like identified or number. Cannot
	 * contain dots. Cannot be null.
	 * 
	 * @return key
	 */
	String getKey();

	/**
	 * type of the parameter, supports boolean, integer, string, file, list and
	 * map. For list type child preference can be
	 * accessed by number (index), if map is the type child preference can be
	 * accessed by a key (string)
	 * 
	 * @return type of the preference
	 */
	PreferenceType getType();

	/**
	 * Additional info on how it is represented in the ui, for example boolean
	 * can be represented as checkbox, drop-down and so on, Values TBD.
	 * Not supported at the moment.
	 * 
	 * @return ui info or null if not set
	 */
	String getUiInfo();

	/**
	 * User visible label for the parameter control in UI
	 * 
	 * @return the label
	 */
	String getLabel();

	/**
	 * Detailed explanation of parameter. Not supported at the moment.
	 * 
	 * @return the toolTip text
	 */
	String getToolTip();

	/**
	 * default clone implementation
	 * 
	 * @return clone of the object
	 */
	Object clone();

	/**
	 * @return parent preference
	 */
	IProblemPreference getParent();

	/**
	 * Combined key of values from parents plus itself separated by dot
	 * 
	 * @return qualified key
	 */
	String getQualifiedKey();
}