EMMA Coverage Report (generated Thu Nov 26 15:54:18 CST 2009)
[all classes][org.eclipse.pde.api.tools.internal.problems]

COVERAGE SUMMARY FOR SOURCE FILE [ApiProblemFactory.java]

nameclass, %method, %block, %line, %
ApiProblemFactory.java100% (1/1)95%  (21/22)97%  (800/823)98%  (265.5/270)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ApiProblemFactory100% (1/1)95%  (21/22)97%  (800/823)98%  (265.5/270)
ApiProblemFactory (): void 0%   (0/1)0%   (0/3)0%   (0/1)
loadMessageTemplates (Locale): Hashtable 100% (1/1)71%  (50/70)75%  (12/16)
<static initializer> 100% (1/1)100% (3/3)100% (2/2)
createProblemId (int, int, int, int): int 100% (1/1)100% (20/20)100% (4/4)
getLocalizedMessage (IApiProblem): String 100% (1/1)100% (6/6)100% (1/1)
getLocalizedMessage (int, String []): String 100% (1/1)100% (133/133)100% (26/26)
getProblemCategory (int): int 100% (1/1)100% (4/4)100% (1/1)
getProblemElementKind (int): int 100% (1/1)100% (6/6)100% (1/1)
getProblemFlags (int): int 100% (1/1)100% (6/6)100% (1/1)
getProblemKind (int): int 100% (1/1)100% (6/6)100% (1/1)
getProblemKindFromPref (String): int 100% (1/1)100% (91/91)100% (30/30)
getProblemMessageId (int): int 100% (1/1)100% (10/10)100% (1/1)
getProblemMessageId (int, int, int, int): int 100% (1/1)100% (262/262)100% (139/139)
getProblemSeverityId (IApiProblem): String 100% (1/1)100% (73/73)100% (33/33)
newApiBaselineProblem (String, String [], Object [], int, int): IApiProblem 100% (1/1)100% (17/17)100% (2/2)
newApiComponentResolutionProblem (String, String [], String [], Object [], in... 100% (1/1)100% (17/17)100% (2/2)
newApiProblem (String, String, String [], String [], Object [], int, int, int... 100% (1/1)100% (13/13)100% (1/1)
newApiProblem (String, String, String [], String [], Object [], int, int, int... 100% (1/1)100% (15/15)100% (1/1)
newApiSinceTagProblem (String, String, String [], String [], Object [], int, ... 100% (1/1)100% (17/17)100% (2/2)
newApiUsageProblem (String, String, String [], String [], Object [], int, int... 100% (1/1)100% (17/17)100% (2/2)
newApiUsageProblem (String, String, String [], String [], Object [], int, int... 100% (1/1)100% (17/17)100% (2/2)
newApiVersionNumberProblem (String, String, String [], String [], Object [], ... 100% (1/1)100% (17/17)100% (2/2)

1/*******************************************************************************
2 * Copyright (c) 2008, 2009 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.pde.api.tools.internal.problems;
12 
13import java.text.ChoiceFormat;
14import java.util.Enumeration;
15import java.util.Hashtable;
16import java.util.Locale;
17import java.util.MissingResourceException;
18import java.util.ResourceBundle;
19 
20import org.eclipse.pde.api.tools.internal.builder.BuilderMessages;
21import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta;
22import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem;
23import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblemTypes;
24import org.eclipse.pde.api.tools.internal.util.Util;
25 
26import com.ibm.icu.text.MessageFormat;
27 
28/**
29 * Factory for creating {@link IApiProblem}s
30 * 
31 * @since 1.0.0
32 */
33public class ApiProblemFactory {
34        
35        public static final int TYPE_CONVERSION_ID = 76;
36 
37        /**
38         * The current mapping of problem id to message
39         */
40        private static Hashtable fMessages = null;
41        
42        /**
43         * Creates a new {@link IApiProblem}
44         * @param resourcepath the path to the resource this problem was found in
45         * @param typeName the type name this problem was found in
46         * @param messageargs listing of arguments to pass in to the localized message.
47         * The arguments are passed into the string in the order they appear in the array.
48         * @param argumentids the ids of arguments passed into the problem
49         * @param arguments the arguments that correspond to the listing of ids
50         * @param linenumber the number of the line the problem occurred on
51         * @param charstart the start of a char selection range
52         * @param charend the end of a char selection range
53         * @param category the category of the problem. See {@link IApiProblem} for categories
54         * @param element the id of the backing element for this problem See {@link IElementDescriptor}, {@link IDelta} and {@link IJavaElement} for kinds
55         * @param kind the kind of the problem
56         * @param flags any additional flags for the kind
57         * @return a new {@link IApiProblem}
58         */
59        public static IApiProblem newApiProblem(String resourcepath, String typeName, String[] messageargs, String[] argumentids, Object[] arguments, int linenumber, int charstart, int charend, int category, int element, int kind, int flags) {
60                return newApiProblem(resourcepath, typeName, messageargs, argumentids, arguments, linenumber, charstart, charend, createProblemId(category, element, kind, flags));
61        }
62        
63        /**
64         * Creates a new {@link IApiProblem}
65         * @param resourcepath the path to the resource this problem was found in
66         * @param typeName the type name this problem was found in
67         * @param messageargs listing of arguments to pass in to the localized message.
68         * The arguments are passed into the string in the order they appear in the array.
69         * @param argumentids the ids of arguments passed into the problem
70         * @param arguments the arguments that correspond to the listing of ids
71         * @param linenumber the number of the line the problem occurred on
72         * @param charstart the start of a char selection range
73         * @param charend the end of a char selection range
74         * @param id the composite id of the problem
75         * @return a new {@link IApiProblem}
76         */
77        public static IApiProblem newApiProblem(String resourcepath, String typeName, String[] messageargs, String[] argumentids, Object[] arguments, int linenumber, int charstart, int charend, int id) {
78                return new ApiProblem(resourcepath, typeName, messageargs, argumentids, arguments, linenumber, charstart, charend, id);
79        }
80        
81        /**
82         * Creates a new API usage {@link IApiProblem}
83         * @param resourcepath the path to the resource this problem was found in
84         * @param typeName the type name this problem was found in
85         * @param messageargs listing of arguments to pass in to the localized message.
86         * The arguments are passed into the string in the order they appear in the array.
87         * @param argumentids the ids of arguments passed into the problem
88         * @param arguments the arguments that correspond to the listing of ids
89         * @param linenumber the number of the line the problem occurred on
90         * @param charstart the start of a char selection range
91         * @param charend the end of a char selection range
92         * @param element the element kind
93         * @param kind the kind
94         * @return a new {@link IApiProblem} for API usage
95         */
96        public static IApiProblem newApiUsageProblem(String resourcepath, String typeName, String[] messageargs, String[] argumentids, Object[] arguments, int linenumber, int charstart, int charend, int element, int kind) {
97                int id = createProblemId(IApiProblem.CATEGORY_USAGE, element, kind, IApiProblem.NO_FLAGS);
98                return newApiProblem(resourcepath, typeName, messageargs, argumentids, arguments, linenumber, charstart, charend, id);
99        }
100 
101        /**
102         * Creates a new API usage {@link IApiProblem}
103         * @param resourcepath the path to the resource this problem was found in
104         * @param typeName the type name this problem was found in
105         * @param messageargs listing of arguments to pass in to the localized message.
106         * The arguments are passed into the string in the order they appear in the array.
107         * @param argumentids the ids of arguments passed into the problem
108         * @param arguments the arguments that correspond to the listing of ids
109         * @param linenumber the number of the line the problem occurred on
110         * @param charstart the start of a char selection range
111         * @param charend the end of a char selection range
112         * @param element the element kind
113         * @param kind the kind
114         * @param flags the flags
115         * @return a new {@link IApiProblem} for API usage
116         */
117        public static IApiProblem newApiUsageProblem(String resourcepath, String typeName, String[] messageargs, String[] argumentids, Object[] arguments, int linenumber, int charstart, int charend, int element, int kind, int flags) {
118                int id = createProblemId(IApiProblem.CATEGORY_USAGE, element, kind, flags);
119                return newApiProblem(resourcepath, typeName, messageargs, argumentids, arguments, linenumber, charstart, charend, id);
120        }
121        
122        /**
123         * Creates a new API baseline {@link IApiProblem}
124         * @param resourcepath the path to the resource this problem was found in
125         * The arguments are passed into the string in the order they appear in the array.
126         * @param argumentids the ids of arguments passed into the problem
127         * @param arguments the arguments that correspond to the listing of ids
128         * @param element the element kind
129         * @param kind the kind
130         * @return a new {@link IApiProblem} for API usage
131         */
132        public static IApiProblem newApiBaselineProblem(String resourcepath, String[] argumentids, Object[] arguments, int element, int kind) {
133                int id = createProblemId(IApiProblem.CATEGORY_API_BASELINE, element, kind, IApiProblem.NO_FLAGS);
134                return newApiProblem(resourcepath, null, null, argumentids, arguments, -1, -1, -1, id);
135        }
136        /**
137         * Creates a new API component resolution {@link IApiProblem}
138         * @param resourcepath the path to the resource this problem was found in
139         * @param messageargs listing of arguments to pass in to the localized message.
140         * The arguments are passed into the string in the order they appear in the array.
141         * @param argumentids the ids of arguments passed into the problem
142         * @param arguments the arguments that correspond to the listing of ids
143         * @param element the element kind
144         * @param kind the kind
145         * @return a new {@link IApiProblem} for API usage
146         */
147        public static IApiProblem newApiComponentResolutionProblem(String resourcepath, String[] messageargs, String[] argumentids, Object[] arguments, int element, int kind) {
148                int id = createProblemId(IApiProblem.CATEGORY_API_COMPONENT_RESOLUTION, element, kind, IApiProblem.NO_FLAGS);
149                return newApiProblem(resourcepath, null, messageargs, argumentids, arguments, -1, -1, -1, id);
150        }
151        /**
152         * Creates a new since tag {@link IApiProblem}
153         * @param resourcepath the path to the resource this problem was found in
154         * @param typeName the type name this problem was found in
155         * @param messageargs listing of arguments to pass in to the localized message.
156         * The arguments are passed into the string in the order they appear in the array.
157         * @param argumentids the ids of arguments passed into the problem
158         * @param arguments the arguments that correspond to the listing of ids
159         * @param linenumber the number of the line the problem occurred on
160         * @param charstart the start of a char selection range
161         * @param charend the end of a char selection range
162         * @param element the element kind
163         * @param kind the kind
164         * @return a new {@link IApiProblem} for since tags
165         */
166        public static IApiProblem newApiSinceTagProblem(String resourcepath, String typeName, String[] messageargs, String[] argumentids, Object[] arguments, int linenumber, int charstart, int charend, int element, int kind) {
167                int id = createProblemId(IApiProblem.CATEGORY_SINCETAGS, element, kind, IApiProblem.NO_FLAGS);
168                return newApiProblem(resourcepath, typeName, messageargs, argumentids, arguments, linenumber, charstart, charend, id);
169        }
170        
171        /**
172         * Creates a new version number {@link IApiProblem}
173         * @param resourcepath the path to the resource this problem was found in
174         * @param typeName the type name this problem was found in
175         * @param messageargs listing of arguments to pass in to the localized message.
176         * The arguments are passed into the string in the order they appear in the array.
177         * @param argumentids the ids of arguments passed into the problem
178         * @param arguments the arguments that correspond to the listing of ids
179         * @param linenumber the number of the line the problem occurred on
180         * @param charstart the start of a char selection range
181         * @param charend the end of a char selection range
182         * @param element the element kind
183         * @param kind the kind
184         * @return a new {@link IApiProblem} for version numbers
185         */
186        public static IApiProblem newApiVersionNumberProblem(String resourcepath, String typeName, String[] messageargs, String[] argumentids, Object[] arguments, int linenumber, int charstart, int charend, int element, int kind) {
187                int id = createProblemId(IApiProblem.CATEGORY_VERSION, element, kind, IApiProblem.NO_FLAGS);
188                return newApiProblem(resourcepath, typeName, messageargs, argumentids, arguments, linenumber, charstart, charend, id);
189        }
190        
191        /**
192         * Returns the localized message for the given {@link IApiProblem}. Returns
193         * <code>null</code> if no localized message cannot be created.
194         * @param problemid the id of the problem to create a message for
195         * @param arguments the arguments to pass into the localized string. The arguments are passed in to the string
196         * in the order they appear in the array.
197         * 
198         * @return a localized message for the given {@link IApiProblem} or <code>null</code>
199         */
200        public static String getLocalizedMessage(IApiProblem problem) {
201                return getLocalizedMessage(problem.getMessageid(), problem.getMessageArguments());
202        }
203        
204        /**
205         * Returns the localized message for the given problem id and message arguments. Returns
206         * a not found message if no localized message cannot be created.
207         * @param messageid
208         * @param messageargs
209         * @return a localized message for the given arguments or a 'not found' message
210         */
211        public static String getLocalizedMessage(int messageid, String[] messageargs){
212                if(fMessages == null) {
213                        fMessages = loadMessageTemplates(Locale.getDefault());
214                }
215                String pattern = (String) fMessages.get(new Integer(messageid));
216                if(pattern == null) {
217                        return MessageFormat.format(BuilderMessages.ApiProblemFactory_problem_message_not_found, new String[] {Integer.toString(messageid)});
218                }
219                if (messageid == TYPE_CONVERSION_ID) {
220                        MessageFormat messageFormat = new MessageFormat(pattern);
221                        double[] typeElementTypes = {
222                                IDelta.ANNOTATION_ELEMENT_TYPE,
223                                IDelta.CLASS_ELEMENT_TYPE,
224                                IDelta.ENUM_ELEMENT_TYPE,
225                                IDelta.INTERFACE_ELEMENT_TYPE,
226                        };
227                        String [] typeElementTypesStrings = {
228                                        (String) fMessages.get(Util.getDeltaElementType(IDelta.ANNOTATION_ELEMENT_TYPE)),
229                                        (String) fMessages.get(Util.getDeltaElementType(IDelta.CLASS_ELEMENT_TYPE)),
230                                        (String) fMessages.get(Util.getDeltaElementType(IDelta.ENUM_ELEMENT_TYPE)),
231                                        (String) fMessages.get(Util.getDeltaElementType(IDelta.INTERFACE_ELEMENT_TYPE)),
232                        };
233                        ChoiceFormat choiceFormat = new ChoiceFormat(typeElementTypes, typeElementTypesStrings);
234                        messageFormat.setFormatByArgumentIndex(1, choiceFormat);
235                        messageFormat.setFormatByArgumentIndex(2, choiceFormat);
236                        Object[] args = new Object[messageargs.length];
237                        args[0] = messageargs[0];
238                        args[1] = Integer.decode(messageargs[1]);
239                        args[2] = Integer.decode(messageargs[2]);
240                        return messageFormat.format(args);
241                }
242                return MessageFormat.format(pattern, messageargs);
243        }
244        
245        /**
246         * This method initializes the MessageTemplates class variable according
247         * to the current Locale.
248         * @param loc Locale
249         * @return HashtableOfInt
250         */
251        public static Hashtable loadMessageTemplates(Locale loc) {
252                ResourceBundle bundle = null;
253                String bundleName = "org.eclipse.pde.api.tools.internal.problems.problemmessages"; //$NON-NLS-1$
254                try {
255                        bundle = ResourceBundle.getBundle(bundleName, loc); 
256                } catch(MissingResourceException e) {
257                        System.out.println("Missing resource : " + bundleName.replace('.', '/') + ".properties for locale " + loc); //$NON-NLS-1$//$NON-NLS-2$
258                        throw e;
259                }
260                Hashtable templates = new Hashtable(700);
261                Enumeration keys = bundle.getKeys();
262                while (keys.hasMoreElements()) {
263                    String key = (String)keys.nextElement();
264                    try {
265                        int messageID = Integer.parseInt(key);
266                                templates.put(new Integer(messageID), bundle.getString(key));
267                    } catch(NumberFormatException e) {
268                        // key is not a number
269                            templates.put(key, bundle.getString(key));
270                        } catch (MissingResourceException e) {
271                                // available ID
272                    }
273                }
274                return templates;
275        }
276        
277        /**
278         * Creates a problem id from the composite members of a problem id.
279         * @param category
280         * @param element
281         * @param kind
282         * @param flags
283         * @return a new problem id
284         */
285        public static int createProblemId(int category, int element, int kind, int flags) {
286                return category | element << IApiProblem.OFFSET_ELEMENT | 
287                                                  kind << IApiProblem.OFFSET_KINDS | 
288                                                  flags << IApiProblem.OFFSET_FLAGS |
289                                                  getProblemMessageId(category, element, kind, flags);
290        }
291        
292        /**
293         * Returns the kind of the problem from the given problem id. The returned kind is not checked to see if it
294         * is correct or existing.
295         * 
296         * @see IApiProblem#getKind()
297         * @see IDelta#getKind()
298         * 
299         * @param problemid
300         * @return the kind from the given problem id
301         */
302        public static int getProblemKind(int problemid) {
303                return (problemid & ApiProblem.KIND_MASK) >> IApiProblem.OFFSET_KINDS;
304        }
305        
306        /**
307         * Returns the kind of element from the given problem id. The returned element kind is not checked to see if it
308         * is correct or existing.
309         * 
310         * @see IElementDescriptor#getElementType()
311         * @see IDelta#getElementType()
312         * 
313         * @param problemid
314         * @return the element kind from the given problem id
315         */
316        public static int getProblemElementKind(int problemid) {
317                return (problemid & ApiProblem.ELEMENT_KIND_MASK) >> IApiProblem.OFFSET_ELEMENT;
318        }
319        
320        /**
321         * Returns the flags from the given problem id. The returned flags are not checked to see if they
322         * are correct or existing.
323         * 
324         * @see IDelta#getFlags()
325         * 
326         * @param problemid
327         * @return the flags from the given problem id
328         */
329        public static int getProblemFlags(int problemid) {
330                return (problemid & ApiProblem.FLAGS_MASK) >> IApiProblem.OFFSET_FLAGS;
331        }
332        
333        /**
334         * Returns the category of the given problem id. The returned category is not checked to see if it
335         * is correct or existing.
336         * 
337         * @see IApiProblem#getCategory()
338         * 
339         * @param problemid
340         * @return the category of this problem id
341         */
342        public static int getProblemCategory(int problemid) {
343                return (problemid & ApiProblem.CATEGORY_MASK);
344        }
345        
346        /**
347         * Convenience method to get the message id from a problem id
348         * @param problemid
349         * @return the message id to use for the given problem id
350         */
351        public static int getProblemMessageId(int problemid) {
352                return getProblemMessageId(getProblemCategory(problemid), getProblemElementKind(problemid), getProblemKind(problemid), getProblemFlags(problemid));
353        }
354        
355        /**
356         * Returns the problem message id for the given problem parameters.
357         * @param category
358         * @param element
359         * @param kind
360         * @param flags
361         * @return the id of the message to use for the given problem parameters or <code>0</code>
362         */
363        public static int getProblemMessageId(int category, int element, int kind, int flags) {
364                switch(category) {
365                        case IApiProblem.CATEGORY_API_BASELINE: {
366                                switch(kind) {
367                                        case IApiProblem.API_BASELINE_MISSING: return 1;
368                                }
369                                break;
370                        }
371                        case IApiProblem.CATEGORY_SINCETAGS: {
372                                switch(kind) {
373                                        case IApiProblem.SINCE_TAG_INVALID: return 2;
374                                        case IApiProblem.SINCE_TAG_MALFORMED: return 3;
375                                        case IApiProblem.SINCE_TAG_MISSING: return 4;
376                                }
377                                break;
378                        }
379                        case IApiProblem.CATEGORY_VERSION: {
380                                switch(kind) {
381                                        case IApiProblem.MAJOR_VERSION_CHANGE: return 5;
382                                        case IApiProblem.MAJOR_VERSION_CHANGE_NO_BREAKAGE: return 6;
383                                        case IApiProblem.MINOR_VERSION_CHANGE: return 7;
384                                        case IApiProblem.MINOR_VERSION_CHANGE_NO_NEW_API: return 56;
385                                        case IApiProblem.REEXPORTED_MAJOR_VERSION_CHANGE : return 19;
386                                        case IApiProblem.REEXPORTED_MINOR_VERSION_CHANGE : return 20;
387                                }
388                                break;
389                        }
390                        case IApiProblem.CATEGORY_USAGE: {
391                                switch(kind) {
392                                        case IApiProblem.ILLEGAL_IMPLEMENT: {
393                                                switch(flags) {
394                                                        case IApiProblem.NO_FLAGS: return 8;
395                                                        case IApiProblem.INDIRECT_REFERENCE: return 24;
396                                                }
397                                                break;
398                                        }
399                                        case IApiProblem.ILLEGAL_EXTEND: {
400                                                switch(flags) {
401                                                        case IApiProblem.NO_FLAGS: return 9;
402                                                        case IApiProblem.LOCAL_TYPE : return 25;
403                                                        case IApiProblem.ANONYMOUS_TYPE: return 28;
404                                                }
405                                                break;
406                                        }
407                                        case IApiProblem.ILLEGAL_INSTANTIATE: return 10;
408                                        case IApiProblem.ILLEGAL_OVERRIDE: return 11;
409                                        case IApiProblem.ILLEGAL_REFERENCE: {
410                                                switch(flags) {
411                                                        case IApiProblem.FIELD: return 12;
412                                                        case IApiProblem.CONSTRUCTOR_METHOD: return 110;
413                                                        case IApiProblem.METHOD: return 111;
414                                                }
415                                                break;
416                                        }
417                                        case IApiProblem.API_LEAK: {
418                                                switch(flags) {
419                                                        case IApiProblem.LEAK_EXTENDS: return 13;
420                                                        case IApiProblem.LEAK_IMPLEMENTS: return 14;
421                                                        case IApiProblem.LEAK_FIELD: return 15;
422                                                        case IApiProblem.LEAK_RETURN_TYPE: return 16;
423                                                        case IApiProblem.LEAK_METHOD_PARAMETER: return 17;
424                                                        case IApiProblem.LEAK_CONSTRUCTOR_PARAMETER: return 109;
425                                                }
426                                                break;
427                                        }
428                                        case IApiProblem.UNSUPPORTED_TAG_USE: return 112;
429                                        case IApiProblem.DUPLICATE_TAG_USE: return 22;
430                                        case IApiProblem.INVALID_REFERENCE_IN_SYSTEM_LIBRARIES :
431                                                switch(flags) {
432                                                        case IApiProblem.METHOD : return 33;
433                                                        case IApiProblem.CONSTRUCTOR_METHOD : return 34;
434                                                        case IApiProblem.FIELD : return 35;
435                                                        default: return 36;
436                                                }
437                                        case IApiProblem.UNUSED_PROBLEM_FILTERS: return 30;
438                                }
439                                break;
440                        }
441                        case IApiProblem.CATEGORY_COMPATIBILITY: {
442                                switch(kind) {
443                                        case IDelta.ADDED: {
444                                                switch(element) {
445                                                        case IDelta.CLASS_ELEMENT_TYPE: {
446                                                                switch(flags) {
447                                                                        case IDelta.METHOD: return 41;
448                                                                        case IDelta.RESTRICTIONS: return 72;
449                                                                }
450                                                                break;
451                                                        }
452                                                        case IDelta.ANNOTATION_ELEMENT_TYPE: {
453                                                                switch(flags) {
454                                                                        case IDelta.FIELD: return 39;
455                                                                }
456                                                                break;
457                                                        }
458                                                        case IDelta.INTERFACE_ELEMENT_TYPE: {
459                                                                switch(flags) {
460                                                                        case IDelta.FIELD: return 40;
461                                                                        case IDelta.METHOD: return 44;
462                                                                        case IDelta.RESTRICTIONS: return 72;
463                                                                        case IDelta.SUPER_INTERFACE_WITH_METHODS : return 133;
464                                                                }
465                                                                break;
466                                                        }
467                                                        case IDelta.METHOD_ELEMENT_TYPE : {
468                                                                switch(flags) {
469                                                                        case IDelta.RESTRICTIONS: return 132;
470                                                                }
471                                                        }
472                                                }
473                                                switch(flags) {
474                                                        case IDelta.CLASS_BOUND: return 21;
475                                                        case IDelta.CONSTRUCTOR: return 23;
476                                                        case IDelta.INTERFACE_BOUND: return 26;
477                                                        case IDelta.METHOD_WITHOUT_DEFAULT_VALUE: return 29;
478                                                        case IDelta.TYPE_PARAMETER: return 32;
479                                                        case IDelta.TYPE_ARGUMENT: return 106;
480                                                }
481                                                break;
482                                        }
483                                        case IDelta.CHANGED: {
484                                                switch(element) {
485                                                        case IDelta.FIELD_ELEMENT_TYPE: {
486                                                                switch(flags) {
487                                                                        case IDelta.TYPE: return 81;
488                                                                        case IDelta.VALUE: return 84;
489                                                                        case IDelta.DECREASE_ACCESS: return 114;
490                                                                        case IDelta.NON_FINAL_TO_FINAL: return 118;
491                                                                        case IDelta.STATIC_TO_NON_STATIC: return 121;
492                                                                        case IDelta.NON_STATIC_TO_STATIC: return 69;
493                                                                }
494                                                                break;
495                                                        }
496                                                        case IDelta.METHOD_ELEMENT_TYPE : {
497                                                                switch(flags) {
498                                                                        case IDelta.DECREASE_ACCESS : return 115;
499                                                                        case IDelta.NON_ABSTRACT_TO_ABSTRACT : return 117;
500                                                                        case IDelta.NON_FINAL_TO_FINAL: return 119;
501                                                                        case IDelta.NON_STATIC_TO_STATIC: return 120;
502                                                                        case IDelta.STATIC_TO_NON_STATIC: return 122;
503                                                                }
504                                                                break;
505                                                        }
506                                                        case IDelta.CONSTRUCTOR_ELEMENT_TYPE : {
507                                                                switch(flags) {
508                                                                        case IDelta.DECREASE_ACCESS : return 116;
509                                                                }
510                                                        }
511                                                }
512                                                switch(flags) {
513                                                        case IDelta.CLASS_BOUND: return 52;
514                                                        case IDelta.CONTRACTED_SUPERINTERFACES_SET: return 54;
515                                                        case IDelta.DECREASE_ACCESS: return 55;
516                                                        case IDelta.FINAL_TO_NON_FINAL_STATIC_CONSTANT: return 61;
517                                                        case IDelta.INTERFACE_BOUND: return 64;
518                                                        case IDelta.NON_ABSTRACT_TO_ABSTRACT: return 66;
519                                                        case IDelta.NON_FINAL_TO_FINAL: return 67;
520                                                        case IDelta.NON_STATIC_TO_STATIC: return 123;
521                                                        case IDelta.STATIC_TO_NON_STATIC: return 73;
522                                                        case IDelta.TYPE_CONVERSION: return TYPE_CONVERSION_ID;
523                                                        case IDelta.VARARGS_TO_ARRAY: return 85;
524                                                        case IDelta.TYPE_ARGUMENT: return 124;
525                                                }
526                                                break;
527                                        }
528                                        case IDelta.REMOVED: {
529                                                switch(flags) {
530                                                        case IDelta.ANNOTATION_DEFAULT_VALUE: return 86;
531                                                        case IDelta.API_COMPONENT: return 87;
532                                                        case IDelta.CLASS_BOUND: return 89;
533                                                        case IDelta.CONSTRUCTOR: return 91;
534                                                        case IDelta.ENUM_CONSTANT: return 92;
535                                                        case IDelta.FIELD: return 94;
536                                                        case IDelta.INTERFACE_BOUND: return 96;
537                                                        case IDelta.METHOD: return 98;
538                                                        case IDelta.METHOD_WITH_DEFAULT_VALUE: return 100;
539                                                        case IDelta.METHOD_WITHOUT_DEFAULT_VALUE: return 101;
540                                                        case IDelta.TYPE: return 102;
541                                                        case IDelta.TYPE_ARGUMENTS: return 103;
542                                                        case IDelta.TYPE_MEMBER: return 104;
543                                                        case IDelta.TYPE_PARAMETER: return 105;
544                                                        case IDelta.VALUE : return 108;
545                                                        case IDelta.API_TYPE: return 113;
546                                                        case IDelta.API_FIELD: return 125;
547                                                        case IDelta.API_METHOD: return 126;
548                                                        case IDelta.API_CONSTRUCTOR: return 127;
549                                                        case IDelta.API_ENUM_CONSTANT: return 128;
550                                                        case IDelta.API_METHOD_WITH_DEFAULT_VALUE : return 129;
551                                                        case IDelta.API_METHOD_WITHOUT_DEFAULT_VALUE: return 130;
552                                                        case IDelta.TYPE_ARGUMENT: return 107;
553                                                        case IDelta.SUPERCLASS: return 131;
554                                                        case IDelta.REEXPORTED_API_TYPE: return 134;
555                                                        case IDelta.REEXPORTED_TYPE: return 135;
556                                                }
557                                        }
558                                }
559                                break;
560                        }
561                        case IApiProblem.CATEGORY_API_COMPONENT_RESOLUTION: {
562                                switch(kind) {
563                                        case IApiProblem.API_COMPONENT_RESOLUTION: {
564                                                return 99;
565                                        }
566                                }
567                        }
568                }
569                return 0;
570        }
571        
572        /**
573         * Returns the problem severity id for the given problem parameters.
574         * @param category
575         * @param element
576         * @param kind
577         * @param flags
578         * @return the id of the preference to use to lookup the user specified severity level for the given {@link IApiProblem}
579         */
580        public static String getProblemSeverityId(IApiProblem problem) {
581                switch(problem.getCategory()) {
582                        case IApiProblem.CATEGORY_API_COMPONENT_RESOLUTION : {
583                                switch(problem.getKind()) {
584                                        case IApiProblem.API_COMPONENT_RESOLUTION: return IApiProblemTypes.REPORT_RESOLUTION_ERRORS_API_COMPONENT;
585                                }
586                                break;
587                        }
588                        case IApiProblem.CATEGORY_API_BASELINE: {
589                                switch(problem.getKind()) {
590                                        case IApiProblem.API_BASELINE_MISSING: return IApiProblemTypes.MISSING_DEFAULT_API_BASELINE;
591                                }
592                                break;
593                        }
594                        case IApiProblem.CATEGORY_SINCETAGS: {
595                                switch(problem.getKind()) {
596                                        case IApiProblem.SINCE_TAG_INVALID: return IApiProblemTypes.INVALID_SINCE_TAG_VERSION;
597                                        case IApiProblem.SINCE_TAG_MALFORMED: return IApiProblemTypes.MALFORMED_SINCE_TAG;
598                                        case IApiProblem.SINCE_TAG_MISSING: return IApiProblemTypes.MISSING_SINCE_TAG;
599                                }
600                                break;
601                        }
602                        case IApiProblem.CATEGORY_VERSION: {
603                                return IApiProblemTypes.INCOMPATIBLE_API_COMPONENT_VERSION;
604                        }
605                        case IApiProblem.CATEGORY_USAGE: {
606                                switch(problem.getKind()) {
607                                        case IApiProblem.ILLEGAL_IMPLEMENT: return IApiProblemTypes.ILLEGAL_IMPLEMENT;
608                                        case IApiProblem.ILLEGAL_EXTEND: return IApiProblemTypes.ILLEGAL_EXTEND;
609                                        case IApiProblem.ILLEGAL_INSTANTIATE: return IApiProblemTypes.ILLEGAL_INSTANTIATE;
610                                        case IApiProblem.ILLEGAL_OVERRIDE: return IApiProblemTypes.ILLEGAL_OVERRIDE;
611                                        case IApiProblem.ILLEGAL_REFERENCE: return IApiProblemTypes.ILLEGAL_REFERENCE;
612                                        case IApiProblem.API_LEAK: {
613                                                switch(problem.getFlags()) {
614                                                        case IApiProblem.LEAK_EXTENDS : return IApiProblemTypes.LEAK_EXTEND;
615                                                        case IApiProblem.LEAK_FIELD : return IApiProblemTypes.LEAK_FIELD_DECL;
616                                                        case IApiProblem.LEAK_IMPLEMENTS : return IApiProblemTypes.LEAK_IMPLEMENT;
617                                                        case IApiProblem.LEAK_CONSTRUCTOR_PARAMETER: 
618                                                        case IApiProblem.LEAK_METHOD_PARAMETER : return IApiProblemTypes.LEAK_METHOD_PARAM;
619                                                        case IApiProblem.LEAK_RETURN_TYPE : return IApiProblemTypes.LEAK_METHOD_RETURN_TYPE;
620                                                }
621                                                break;
622                                        }
623                                        case IApiProblem.UNSUPPORTED_TAG_USE: return IApiProblemTypes.INVALID_JAVADOC_TAG;
624                                        case IApiProblem.DUPLICATE_TAG_USE: return IApiProblemTypes.INVALID_JAVADOC_TAG;
625                                        case IApiProblem.INVALID_REFERENCE_IN_SYSTEM_LIBRARIES: return IApiProblemTypes.INVALID_REFERENCE_IN_SYSTEM_LIBRARIES;
626                                        case IApiProblem.UNUSED_PROBLEM_FILTERS: return IApiProblemTypes.UNUSED_PROBLEM_FILTERS;
627                                }
628                                break;
629                        }
630                        case IApiProblem.CATEGORY_COMPATIBILITY: {
631                                return Util.getDeltaPrefererenceKey(problem.getElementKind(), problem.getKind(), problem.getFlags());
632                        }
633                }
634                return null;
635        }
636        
637        /**
638         * Returns the problem kind from the given preference key.
639         * 
640         * @see IApiProblemTypes for a listing of all preference keys
641         * @param prefkey
642         * @return the corresponding kind for the given preference key, or 0 if the pref key is unknown
643         */
644        public static int getProblemKindFromPref(String prefkey) {
645                if(IApiProblemTypes.ILLEGAL_EXTEND.equals(prefkey)) {
646                        return IApiProblem.ILLEGAL_EXTEND;
647                }
648                if(IApiProblemTypes.ILLEGAL_IMPLEMENT.equals(prefkey)) {
649                        return IApiProblem.ILLEGAL_IMPLEMENT;
650                }
651                if(IApiProblemTypes.ILLEGAL_INSTANTIATE.equals(prefkey)) {
652                        return IApiProblem.ILLEGAL_INSTANTIATE;
653                }
654                if(IApiProblemTypes.ILLEGAL_REFERENCE.equals(prefkey)) {
655                        return IApiProblem.ILLEGAL_REFERENCE;
656                }
657                if(IApiProblemTypes.ILLEGAL_OVERRIDE.equals(prefkey)) {
658                        return IApiProblem.ILLEGAL_OVERRIDE;
659                }
660                if(IApiProblemTypes.INVALID_REFERENCE_IN_SYSTEM_LIBRARIES.equals(prefkey)) {
661                        return IApiProblem.INVALID_REFERENCE_IN_SYSTEM_LIBRARIES;
662                }
663                if(IApiProblemTypes.UNUSED_PROBLEM_FILTERS.equals(prefkey)) {
664                        return IApiProblem.UNUSED_PROBLEM_FILTERS;
665                }
666                if(IApiProblemTypes.MISSING_SINCE_TAG.equals(prefkey)) {
667                        return IApiProblem.SINCE_TAG_MISSING;
668                }
669                if(IApiProblemTypes.MALFORMED_SINCE_TAG.equals(prefkey)) {
670                        return IApiProblem.SINCE_TAG_MALFORMED;
671                }
672                if(IApiProblemTypes.INVALID_SINCE_TAG_VERSION.equals(prefkey)) {
673                        return IApiProblem.SINCE_TAG_INVALID;
674                }
675                if(IApiProblemTypes.REPORT_RESOLUTION_ERRORS_API_COMPONENT.equals(prefkey)) {
676                        return IApiProblem.API_COMPONENT_RESOLUTION;
677                }
678                if(prefkey != null) {
679                        if(prefkey.indexOf("ADDED") > -1) { //$NON-NLS-1$
680                                return IDelta.ADDED;
681                        }
682                        if(prefkey.indexOf("CHANGED") > -1) { //$NON-NLS-1$
683                                return IDelta.CHANGED;
684                        }
685                        if(prefkey.indexOf("REMOVED") > -1) { //$NON-NLS-1$
686                                return IDelta.REMOVED;
687                        }
688                }
689                return 0;
690        }
691}

[all classes][org.eclipse.pde.api.tools.internal.problems]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov