Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5539d5ee76f20d78d5c776a5af09c83fef47fb43 (plain) (blame)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
/*******************************************************************************
 * Copyright (c) 2008, 2013 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.pde.api.tools.internal.problems;

import java.text.ChoiceFormat;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.eclipse.core.resources.IMarker;
import org.eclipse.pde.api.tools.internal.builder.BuilderMessages;
import org.eclipse.pde.api.tools.internal.provisional.IApiMarkerConstants;
import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem;
import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblemFilter;
import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblemTypes;
import org.eclipse.pde.api.tools.internal.util.Util;

import com.ibm.icu.text.MessageFormat;

/**
 * Factory for creating {@link IApiProblem}s
 * 
 * @since 1.0.0
 */
public class ApiProblemFactory {
	
	public static final int TYPE_CONVERSION_ID = 76;

	/**
	 * The current mapping of problem id to message
	 */
	private static Hashtable fMessages = null;
	
	/**
	 * Creates a new {@link IApiProblemFilter}
	 * @param componentid
	 * @param problem
	 * @param comment
	 * @return the new {@link IApiProblemFilter}
	 * @since 1.1
	 */
	public static IApiProblemFilter newProblemFilter(String componentid, IApiProblem problem, String comment) {
		return new ApiProblemFilter(componentid, problem, comment);
	}
	
	/**
	 * Computes an {@link IApiProblem} hashcode from the given filter handle. If the handle is <code>null</code>
	 * this method returns <code>-1</code>.
	 * 
	 * @param filterhandle the problem handle
	 * @return a new hashcode for the {@link IApiProblem} described in the filter or <code>-1</code>
	 * @see ApiProblem#hashCode()
	 * @see ApiProblemFilter#getHandle()
	 * @since 1.0.500
	 */
	public static int getProblemHashcode(String filterhandle) {
		if(filterhandle != null) {
			String[] args = filterhandle.split(ApiProblemFilter.HANDLE_DELIMITER);
			int hashcode = 0;
			try {
				//the problem id
				hashcode += Integer.parseInt(args[0]);
				//the resource path
				hashcode += args[1].hashCode();
				//the type name, do not add to the hashcode if the type name is null
				//https://bugs.eclipse.org/bugs/show_bug.cgi?id=404173
				if(args[2] != null && !args[2].equalsIgnoreCase("null")) { //$NON-NLS-1$
					hashcode += args[2].hashCode();
				}
				//the message arguments
				String[] margs = splitHandle(args[3], ApiProblemFilter.HANDLE_ARGUMENTS_DELIMITER);
				hashcode += argumentsHashcode(margs);
			}
			catch(Exception e) {} finally {
			}
			return hashcode;
		}
		return -1;
	}
	
	/**
	 * Returns the deep hash code of the complete listing of message arguments
	 * @param arguments
	 * @return the hash code of the message arguments
	 */
	private static int argumentsHashcode(String[] arguments) {
		if(arguments == null) {
			return 0;
		}
		int hashcode = 0;
		for(int i = 0; i < arguments.length; i++) {
			hashcode += arguments[i].hashCode();
		}
		return hashcode;
	}
	
	private static String[] splitHandle(String messageArguments, String delimiter) {
		List matches = null;
		char[] argumentsChars = messageArguments.toCharArray();
		char[] delimiterChars = delimiter.toCharArray();
		int delimiterLength = delimiterChars.length;
		int start = 0;
		int argumentsCharsLength = argumentsChars.length;
		int balance = 0;
		for (int i = 0; i < argumentsCharsLength;) {
			char c = argumentsChars[i];
			switch(c) {
				case '(' : {
					balance++;
					break;
				}
				case ')' : {
					balance--;
					break;
				}
				default: break;
			}
			if (c == delimiterChars[0] && balance == 0) {
				// see if this is a matching delimiter start only if not within parenthesis (balance == 0)
				if (i + delimiterLength < argumentsCharsLength) {
					boolean match = true;
					loop: for (int j = 1; j < delimiterLength; j++) {
						if (argumentsChars[i + j] != delimiterChars[j]) {
							match = false;
							break loop;
						}
					}
					if (match) {
						// record the matching substring and proceed
						if (matches == null) {
							matches = new ArrayList();
						}
						matches.add(messageArguments.substring(start, i));
						start = i + delimiterLength;
						i += delimiterLength;
					} else {
						i++;
					}
				} else {
					i++;
				}
			} else {
				i++;
			}
		}
		if (matches == null) {
			return new String[] { messageArguments };
		} else {
			matches.add(messageArguments.substring(start, argumentsCharsLength));
		}
		return (String[]) matches.toArray(new String[matches.size()]);
	}
	
	/**
	 * Creates a new {@link IApiProblem}
	 * @param resourcepath the path to the resource this problem was found in
	 * @param typeName the type name this problem was found in
	 * @param messageargs listing of arguments to pass in to the localized message.
	 * The arguments are passed into the string in the order they appear in the array.
	 * @param argumentids the ids of arguments passed into the problem
	 * @param arguments the arguments that correspond to the listing of ids
	 * @param linenumber the number of the line the problem occurred on
	 * @param charstart the start of a char selection range
	 * @param charend the end of a char selection range
	 * @param category the category of the problem. See {@link IApiProblem} for categories
	 * @param element the id of the backing element for this problem See {@link IElementDescriptor}, {@link IDelta} and {@link IJavaElement} for kinds
	 * @param kind the kind of the problem
	 * @param flags any additional flags for the kind
	 * @return a new {@link IApiProblem}
	 */
	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) {
		return newApiProblem(resourcepath, typeName, messageargs, argumentids, arguments, linenumber, charstart, charend, createProblemId(category, element, kind, flags));
	}
	
	/**
	 * Creates a new {@link IApiProblem}
	 * @param resourcepath the path to the resource this problem was found in
	 * @param typeName the type name this problem was found in
	 * @param messageargs listing of arguments to pass in to the localized message.
	 * The arguments are passed into the string in the order they appear in the array.
	 * @param argumentids the ids of arguments passed into the problem
	 * @param arguments the arguments that correspond to the listing of ids
	 * @param linenumber the number of the line the problem occurred on
	 * @param charstart the start of a char selection range
	 * @param charend the end of a char selection range
	 * @param id the composite id of the problem
	 * @return a new {@link IApiProblem}
	 */
	public static IApiProblem newApiProblem(String resourcepath, String typeName, String[] messageargs, String[] argumentids, Object[] arguments, int linenumber, int charstart, int charend, int id) {
		return new ApiProblem(resourcepath, typeName, messageargs, argumentids, arguments, linenumber, charstart, charend, id);
	}
	
	/**
	 * Creates a new API usage {@link IApiProblem}
	 * @param resourcepath the path to the resource this problem was found in
	 * @param typeName the type name this problem was found in
	 * @param messageargs listing of arguments to pass in to the localized message.
	 * The arguments are passed into the string in the order they appear in the array.
	 * @param argumentids the ids of arguments passed into the problem
	 * @param arguments the arguments that correspond to the listing of ids
	 * @param linenumber the number of the line the problem occurred on
	 * @param charstart the start of a char selection range
	 * @param charend the end of a char selection range
	 * @param element the element kind
	 * @param kind the kind
	 * @return a new {@link IApiProblem} for API usage
	 */
	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 id = createProblemId(IApiProblem.CATEGORY_USAGE, element, kind, IApiProblem.NO_FLAGS);
		return newApiProblem(resourcepath, typeName, messageargs, argumentids, arguments, linenumber, charstart, charend, id);
	}

	/**
	 * Creates a new API usage {@link IApiProblem}
	 * @param resourcepath the path to the resource this problem was found in
	 * @param typeName the type name this problem was found in
	 * @param messageargs listing of arguments to pass in to the localized message.
	 * The arguments are passed into the string in the order they appear in the array.
	 * @param argumentids the ids of arguments passed into the problem
	 * @param arguments the arguments that correspond to the listing of ids
	 * @param linenumber the number of the line the problem occurred on
	 * @param charstart the start of a char selection range
	 * @param charend the end of a char selection range
	 * @param element the element kind
	 * @param kind the kind
	 * @param flags the flags
	 * @return a new {@link IApiProblem} for API usage
	 */
	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) {
		int id = createProblemId(IApiProblem.CATEGORY_USAGE, element, kind, flags);
		return newApiProblem(resourcepath, typeName, messageargs, argumentids, arguments, linenumber, charstart, charend, id);
	}
	
	/**
	 * Creates a new API baseline {@link IApiProblem}
	 * @param resourcepath the path to the resource this problem was found in
	 * The arguments are passed into the string in the order they appear in the array.
	 * @param argumentids the ids of arguments passed into the problem
	 * @param arguments the arguments that correspond to the listing of ids
	 * @param element the element kind
	 * @param kind the kind
	 * @return a new {@link IApiProblem} for API usage
	 */
	public static IApiProblem newApiBaselineProblem(String resourcepath, String[] argumentids, Object[] arguments, int element, int kind) {
		int id = createProblemId(IApiProblem.CATEGORY_API_BASELINE, element, kind, IApiProblem.NO_FLAGS);
		return newApiProblem(resourcepath, null, null, argumentids, arguments, -1, -1, -1, id);
	}
	/**
	 * Creates a new API component resolution {@link IApiProblem}
	 * @param resourcepath the path to the resource this problem was found in
	 * @param messageargs listing of arguments to pass in to the localized message.
	 * The arguments are passed into the string in the order they appear in the array.
	 * @param argumentids the ids of arguments passed into the problem
	 * @param arguments the arguments that correspond to the listing of ids
	 * @param element the element kind
	 * @param kind the kind
	 * @return a new {@link IApiProblem} for API usage
	 */
	public static IApiProblem newApiComponentResolutionProblem(String resourcepath, String[] messageargs, String[] argumentids, Object[] arguments, int element, int kind) {
		int id = createProblemId(IApiProblem.CATEGORY_API_COMPONENT_RESOLUTION, element, kind, IApiProblem.NO_FLAGS);
		return newApiProblem(resourcepath, null, messageargs, argumentids, arguments, -1, -1, -1, id);
	}
	/**
	 * Creates a new fatal {@link IApiProblem}
	 * @param resourcepath the path to the resource this problem was found in
	 * @param messageargs listing of arguments to pass in to the localized message.
	 * The arguments are passed into the string in the order they appear in the array.
	 * @param kind the kind
	 * @return a new {@link IApiProblem} for API usage
	 */
	public static IApiProblem newFatalProblem(String resourcepath, String[] messageargs, int kind) {
		int id = createProblemId(IApiProblem.CATEGORY_FATAL_PROBLEM, IElementDescriptor.RESOURCE, kind, IApiProblem.NO_FLAGS);
		return newApiProblem(resourcepath, null, messageargs, null, null, -1, -1, -1, id);
	}
	/**
	 * Creates a new since tag {@link IApiProblem}
	 * @param resourcepath the path to the resource this problem was found in
	 * @param typeName the type name this problem was found in
	 * @param messageargs listing of arguments to pass in to the localized message.
	 * The arguments are passed into the string in the order they appear in the array.
	 * @param argumentids the ids of arguments passed into the problem
	 * @param arguments the arguments that correspond to the listing of ids
	 * @param linenumber the number of the line the problem occurred on
	 * @param charstart the start of a char selection range
	 * @param charend the end of a char selection range
	 * @param element the element kind
	 * @param kind the kind
	 * @return a new {@link IApiProblem} for since tags
	 */
	public static IApiProblem newApiSinceTagProblem(String resourcepath, String typeName, String[] messageargs, String[] argumentids, Object[] arguments, int linenumber, int charstart, int charend, int element, int kind) {
		int id = createProblemId(IApiProblem.CATEGORY_SINCETAGS, element, kind, IApiProblem.NO_FLAGS);
		return newApiProblem(resourcepath, typeName, messageargs, argumentids, arguments, linenumber, charstart, charend, id);
	}
	
	/**
	 * Creates a new version number {@link IApiProblem}
	 * @param resourcepath the path to the resource this problem was found in
	 * @param typeName the type name this problem was found in
	 * @param messageargs listing of arguments to pass in to the localized message.
	 * The arguments are passed into the string in the order they appear in the array.
	 * @param argumentids the ids of arguments passed into the problem
	 * @param arguments the arguments that correspond to the listing of ids
	 * @param linenumber the number of the line the problem occurred on
	 * @param charstart the start of a char selection range
	 * @param charend the end of a char selection range
	 * @param element the element kind
	 * @param kind the kind
	 * @return a new {@link IApiProblem} for version numbers
	 */
	public static IApiProblem newApiVersionNumberProblem(String resourcepath, String typeName, String[] messageargs, String[] argumentids, Object[] arguments, int linenumber, int charstart, int charend, int element, int kind) {
		int id = createProblemId(IApiProblem.CATEGORY_VERSION, element, kind, IApiProblem.NO_FLAGS);
		return newApiProblem(resourcepath, typeName, messageargs, argumentids, arguments, linenumber, charstart, charend, id);
	}
	
	/**
	 * Creates a new API Use Scan breakage {@link IApiProblem}
	 * 
	 * @param resourcePath path of the resource associated with the problem
	 * @param typeName the type name this problem was found in
	 * @param messageargs listing of arguments to pass in to the localized message.
	 * The arguments are passed into the string in the order they appear in the array.
	 * @param argumentids the ids of arguments passed into the problem
	 * @param arguments the arguments that correspond to the listing of ids
	 * @param linenumber the number of the line the problem occurred on
	 * @param charstart the start of a char selection range
	 * @param charend the end of a char selection range
	 * @param element the element kind
	 * @param kind the kind
	 * @param flags flags the reason for problem. <code>0</code> if the type could not be resolved. 
	 * <code>1</code> if member could not be located in the type.
	 * @return a new {@link IApiProblem} for API Use Scan breakage
	 */
	public static IApiProblem newApiUseScanProblem( String resourcePath, String typeName, String[] messageargs, String[] argumentids, Object[] arguments, int linenumber, int charstart, int charend, int element, int kind, int flags) {
		int id = createProblemId(IApiProblem.CATEGORY_API_USE_SCAN_PROBLEM, element, kind, flags);
		return newApiProblem(resourcePath, typeName, messageargs, argumentids, arguments, linenumber, charstart, charend, id);
	}
	
	/**
	 * Returns the localized message for the given {@link IApiProblem}. Returns
	 * <code>null</code> if no localized message cannot be created.
	 * @param problemid the id of the problem to create a message for
	 * @param arguments the arguments to pass into the localized string. The arguments are passed in to the string
	 * in the order they appear in the array.
	 * 
	 * @return a localized message for the given {@link IApiProblem} or <code>null</code>
	 */
	public static String getLocalizedMessage(IApiProblem problem) {
		return getLocalizedMessage(problem.getMessageid(), problem.getMessageArguments());
	}
	
	/**
	 * Returns the localized message for the given problem id and message arguments. Returns
	 * a not found message if no localized message cannot be created.
	 * @param messageid
	 * @param messageargs
	 * @return a localized message for the given arguments or a 'not found' message
	 */
	public static String getLocalizedMessage(int messageid, String[] messageargs){
		if(fMessages == null) {
			fMessages = loadMessageTemplates(Locale.getDefault());
		}
		String pattern = (String) fMessages.get(new Integer(messageid));
		if(pattern == null) {
			return MessageFormat.format(BuilderMessages.ApiProblemFactory_problem_message_not_found, new String[] {Integer.toString(messageid)});
		}
		if (messageid == TYPE_CONVERSION_ID) {
			MessageFormat messageFormat = new MessageFormat(pattern);
			double[] typeElementTypes = {
				IDelta.ANNOTATION_ELEMENT_TYPE,
				IDelta.CLASS_ELEMENT_TYPE,
				IDelta.ENUM_ELEMENT_TYPE,
				IDelta.INTERFACE_ELEMENT_TYPE,
			};
			String [] typeElementTypesStrings = {
					(String) fMessages.get(Util.getDeltaElementType(IDelta.ANNOTATION_ELEMENT_TYPE)),
					(String) fMessages.get(Util.getDeltaElementType(IDelta.CLASS_ELEMENT_TYPE)),
					(String) fMessages.get(Util.getDeltaElementType(IDelta.ENUM_ELEMENT_TYPE)),
					(String) fMessages.get(Util.getDeltaElementType(IDelta.INTERFACE_ELEMENT_TYPE)),
			};
			ChoiceFormat choiceFormat = new ChoiceFormat(typeElementTypes, typeElementTypesStrings);
			messageFormat.setFormatByArgumentIndex(1, choiceFormat);
			messageFormat.setFormatByArgumentIndex(2, choiceFormat);
			Object[] args = new Object[messageargs.length];
			args[0] = messageargs[0];
			args[1] = Integer.decode(messageargs[1]);
			args[2] = Integer.decode(messageargs[2]);
			return messageFormat.format(args);
		}
		return MessageFormat.format(pattern, messageargs);
	}
	
	/**
	 * This method initializes the MessageTemplates class variable according
	 * to the current Locale.
	 * @param loc Locale
	 * @return HashtableOfInt
	 */
	public static Hashtable loadMessageTemplates(Locale loc) {
		ResourceBundle bundle = null;
		String bundleName = "org.eclipse.pde.api.tools.internal.problems.problemmessages"; //$NON-NLS-1$
		try {
			bundle = ResourceBundle.getBundle(bundleName, loc); 
		} catch(MissingResourceException e) {
			System.out.println("Missing resource : " + bundleName.replace('.', '/') + ".properties for locale " + loc); //$NON-NLS-1$//$NON-NLS-2$
			throw e;
		}
		Hashtable templates = new Hashtable(700);
		Enumeration keys = bundle.getKeys();
		while (keys.hasMoreElements()) {
		    String key = (String)keys.nextElement();
		    try {
		        int messageID = Integer.parseInt(key);
				templates.put(new Integer(messageID), bundle.getString(key));
		    } catch(NumberFormatException e) {
		        // key is not a number
		    	templates.put(key, bundle.getString(key));
			} catch (MissingResourceException e) {
				// available ID
		    }
		}
		return templates;
	}
	
	/**
	 * Creates a problem id from the composite members of a problem id.
	 * @param category
	 * @param element
	 * @param kind
	 * @param flags
	 * @return a new problem id
	 */
	public static int createProblemId(int category, int element, int kind, int flags) {
		return category | element << IApiProblem.OFFSET_ELEMENT | 
						  kind << IApiProblem.OFFSET_KINDS | 
						  flags << IApiProblem.OFFSET_FLAGS |
						  getProblemMessageId(category, element, kind, flags);
	}
	
	/**
	 * Returns the {@link IApiProblem} id from the given marker or <code>-1</code> if the marker is <code>null</code> or the marker 
	 * does not contain the {@link IApiMarkerConstants#MARKER_ATTR_PROBLEM_ID} attribute
	 * 
	 * @param marker
	 * @return the {@link IApiProblem} id or <code>-1</code>
	 * @since 1.0.400
	 */
	public static int getProblemId(IMarker marker) {
		if(marker != null) {
			return marker.getAttribute(IApiMarkerConstants.MARKER_ATTR_PROBLEM_ID, -1);
		}
		return -1;
	}
	
	/**
	 * Returns the kind of the problem from the given problem id. The returned kind is not checked to see if it
	 * is correct or existing.
	 * 
	 * @see IApiProblem#getKind()
	 * @see IDelta#getKind()
	 * 
	 * @param problemid
	 * @return the kind from the given problem id
	 */
	public static int getProblemKind(int problemid) {
		return (problemid & ApiProblem.KIND_MASK) >> IApiProblem.OFFSET_KINDS;
	}
	
	/**
	 * Returns the kind of element from the given problem id. The returned element kind is not checked to see if it
	 * is correct or existing.
	 * 
	 * @see IElementDescriptor#getElementType()
	 * @see IDelta#getElementType()
	 * 
	 * @param problemid
	 * @return the element kind from the given problem id
	 */
	public static int getProblemElementKind(int problemid) {
		return (problemid & ApiProblem.ELEMENT_KIND_MASK) >> IApiProblem.OFFSET_ELEMENT;
	}
	
	/**
	 * Returns the flags from the given problem id. The returned flags are not checked to see if they
	 * are correct or existing.
	 * 
	 * @see IDelta#getFlags()
	 * 
	 * @param problemid
	 * @return the flags from the given problem id
	 */
	public static int getProblemFlags(int problemid) {
		return (problemid & ApiProblem.FLAGS_MASK) >> IApiProblem.OFFSET_FLAGS;
	}
	
	/**
	 * Returns the category of the given problem id. The returned category is not checked to see if it
	 * is correct or existing.
	 * 
	 * @see IApiProblem#getCategory()
	 * 
	 * @param problemid
	 * @return the category of this problem id
	 */
	public static int getProblemCategory(int problemid) {
		return (problemid & ApiProblem.CATEGORY_MASK);
	}
	
	/**
	 * Convenience method to get the message id from a problem id
	 * @param problemid
	 * @return the message id to use for the given problem id
	 */
	public static int getProblemMessageId(int problemid) {
		return getProblemMessageId(getProblemCategory(problemid), getProblemElementKind(problemid), getProblemKind(problemid), getProblemFlags(problemid));
	}
	
	/**
	 * Returns the problem message id for the given problem parameters.
	 * @param category
	 * @param element
	 * @param kind
	 * @param flags
	 * @return the id of the message to use for the given problem parameters or <code>0</code>
	 */
	public static int getProblemMessageId(int category, int element, int kind, int flags) {
		switch(category) {
			case IApiProblem.CATEGORY_API_BASELINE: {
				switch(kind) {
					case IApiProblem.API_BASELINE_MISSING: return 1;
					default: break;
				}
				break;
			}
			case IApiProblem.CATEGORY_SINCETAGS: {
				switch(kind) {
					case IApiProblem.SINCE_TAG_INVALID: return 2;
					case IApiProblem.SINCE_TAG_MALFORMED: return 3;
					case IApiProblem.SINCE_TAG_MISSING: return 4;
					default: break;
				}
				break;
			}
			case IApiProblem.CATEGORY_VERSION: {
				switch(kind) {
					case IApiProblem.MAJOR_VERSION_CHANGE: return 5;
					case IApiProblem.MAJOR_VERSION_CHANGE_NO_BREAKAGE: return 6;
					case IApiProblem.MINOR_VERSION_CHANGE: return 7;
					case IApiProblem.MINOR_VERSION_CHANGE_NO_NEW_API: return 56;
					case IApiProblem.REEXPORTED_MAJOR_VERSION_CHANGE : return 19;
					case IApiProblem.REEXPORTED_MINOR_VERSION_CHANGE : return 20;
					default: break;
				}
				break;
			}
			case IApiProblem.CATEGORY_USAGE: {
				switch(kind) {
					case IApiProblem.ILLEGAL_IMPLEMENT: {
						switch(flags) {
							case IApiProblem.NO_FLAGS: return 8;
							case IApiProblem.INDIRECT_REFERENCE: return 24;
							case IApiProblem.LOCAL_TYPE: return 18;
							case IApiProblem.INDIRECT_LOCAL_REFERENCE: return 37;
							case IApiProblem.ANONYMOUS_TYPE: return 27;
							default: break;
						}
						break;
					}
					case IApiProblem.ILLEGAL_EXTEND: {
						switch(flags) {
							case IApiProblem.NO_FLAGS: return 9;
							case IApiProblem.LOCAL_TYPE : return 25;
							case IApiProblem.ANONYMOUS_TYPE: return 28;
							default: break;
						}
						break;
					}
					case IApiProblem.ILLEGAL_INSTANTIATE: return 10;
					case IApiProblem.ILLEGAL_OVERRIDE: return 11;
					case IApiProblem.ILLEGAL_REFERENCE: {
						switch(flags) {
							case IApiProblem.FIELD: return 12;
							case IApiProblem.CONSTRUCTOR_METHOD: return 110;
							case IApiProblem.METHOD: return 111;
							case IApiProblem.ANNOTATION: return 42;
							default: break;
						}
						break;
					}
					case IApiProblem.API_LEAK: {
						switch(flags) {
							case IApiProblem.LEAK_EXTENDS: return 13;
							case IApiProblem.LEAK_IMPLEMENTS: return 14;
							case IApiProblem.LEAK_FIELD: return 15;
							case IApiProblem.LEAK_RETURN_TYPE: return 16;
							case IApiProblem.LEAK_METHOD_PARAMETER: return 17;
							case IApiProblem.LEAK_CONSTRUCTOR_PARAMETER: return 109;
							default: break;
						}
						break;
					}
					case IApiProblem.UNSUPPORTED_TAG_USE: return 112;
					case IApiProblem.DUPLICATE_TAG_USE: return 22;
					case IApiProblem.INVALID_REFERENCE_IN_SYSTEM_LIBRARIES :
						switch(flags) {
							case IApiProblem.METHOD : return 33;
							case IApiProblem.CONSTRUCTOR_METHOD : return 34;
							case IApiProblem.FIELD : return 35;
							default: return 36;
						}
					case IApiProblem.UNUSED_PROBLEM_FILTERS: return 30;
					case IApiProblem.MISSING_EE_DESCRIPTIONS: return 38;
					default: break;
				}
				break;
			}
			case IApiProblem.CATEGORY_COMPATIBILITY: {
				switch(kind) {
					case IDelta.ADDED: {
						switch(element) {
							case IDelta.CLASS_ELEMENT_TYPE: {
								switch(flags) {
									case IDelta.METHOD: return 41;
									case IDelta.RESTRICTIONS: return 72;
									default: break;
								}
								break;
							}
							case IDelta.ANNOTATION_ELEMENT_TYPE: {
								switch(flags) {
									case IDelta.FIELD: return 39;
									default: break;
								}
								break;
							}
							case IDelta.INTERFACE_ELEMENT_TYPE: {
								switch(flags) {
									case IDelta.FIELD: return 40;
									case IDelta.METHOD: return 44;
									case IDelta.RESTRICTIONS: return 72;
									case IDelta.SUPER_INTERFACE_WITH_METHODS : return 133;
									default: break;
								}
								break;
							}
							case IDelta.METHOD_ELEMENT_TYPE : {
								switch(flags) {
									case IDelta.RESTRICTIONS: return 132;
									default: break;
								}
								break;
							}
							default: break;
						}
						switch(flags) {
							case IDelta.CLASS_BOUND: return 21;
							case IDelta.CONSTRUCTOR: return 23;
							case IDelta.INTERFACE_BOUND: return 26;
							case IDelta.METHOD_WITHOUT_DEFAULT_VALUE: return 29;
							case IDelta.TYPE_PARAMETER: return 32;
							case IDelta.TYPE_ARGUMENT: return 106;
							default: break;
						}
						break;
					}
					case IDelta.CHANGED: {
						switch(element) {
							case IDelta.FIELD_ELEMENT_TYPE: {
								switch(flags) {
									case IDelta.TYPE: return 81;
									case IDelta.VALUE: return 84;
									case IDelta.DECREASE_ACCESS: return 114;
									case IDelta.NON_FINAL_TO_FINAL: return 118;
									case IDelta.STATIC_TO_NON_STATIC: return 121;
									case IDelta.NON_STATIC_TO_STATIC: return 69;
									default: break;
								}
								break;
							}
							case IDelta.METHOD_ELEMENT_TYPE : {
								switch(flags) {
									case IDelta.DECREASE_ACCESS : return 115;
									case IDelta.NON_ABSTRACT_TO_ABSTRACT : return 117;
									case IDelta.NON_FINAL_TO_FINAL: return 119;
									case IDelta.NON_STATIC_TO_STATIC: return 120;
									case IDelta.STATIC_TO_NON_STATIC: return 122;
									default: break;
								}
								break;
							}
							case IDelta.CONSTRUCTOR_ELEMENT_TYPE : {
								switch(flags) {
									case IDelta.DECREASE_ACCESS : return 116;
									default: break;
								}
								break;
							}
							default: break;
						}
						switch(flags) {
							case IDelta.CLASS_BOUND: return 52;
							case IDelta.CONTRACTED_SUPERINTERFACES_SET: return 54;
							case IDelta.DECREASE_ACCESS: return 55;
							case IDelta.FINAL_TO_NON_FINAL_STATIC_CONSTANT: return 61;
							case IDelta.INTERFACE_BOUND: return 64;
							case IDelta.NON_ABSTRACT_TO_ABSTRACT: return 66;
							case IDelta.NON_FINAL_TO_FINAL: return 67;
							case IDelta.NON_STATIC_TO_STATIC: return 123;
							case IDelta.STATIC_TO_NON_STATIC: return 73;
							case IDelta.TYPE_CONVERSION: return TYPE_CONVERSION_ID;
							case IDelta.VARARGS_TO_ARRAY: return 85;
							case IDelta.TYPE_ARGUMENT: return 124;
							default: break;
						}
						break;
					}
					case IDelta.REMOVED: {
						switch(flags) {
							case IDelta.ANNOTATION_DEFAULT_VALUE: return 86;
							case IDelta.API_COMPONENT: return 87;
							case IDelta.CLASS_BOUND: return 89;
							case IDelta.CONSTRUCTOR: return 91;
							case IDelta.ENUM_CONSTANT: return 92;
							case IDelta.FIELD: return 94;
							case IDelta.INTERFACE_BOUND: return 96;
							case IDelta.METHOD: return 98;
							case IDelta.METHOD_WITH_DEFAULT_VALUE: return 100;
							case IDelta.METHOD_WITHOUT_DEFAULT_VALUE: return 101;
							case IDelta.TYPE: return 102;
							case IDelta.TYPE_ARGUMENTS: return 103;
							case IDelta.TYPE_MEMBER: return 104;
							case IDelta.TYPE_PARAMETER: return 105;
							case IDelta.VALUE : return 108;
							case IDelta.API_TYPE: return 113;
							case IDelta.API_FIELD: return 125;
							case IDelta.API_METHOD: return 126;
							case IDelta.API_CONSTRUCTOR: return 127;
							case IDelta.API_ENUM_CONSTANT: return 128;
							case IDelta.API_METHOD_WITH_DEFAULT_VALUE : return 129;
							case IDelta.API_METHOD_WITHOUT_DEFAULT_VALUE: return 130;
							case IDelta.TYPE_ARGUMENT: return 107;
							case IDelta.SUPERCLASS: return 131;
							case IDelta.REEXPORTED_API_TYPE: return 134;
							case IDelta.REEXPORTED_TYPE: return 135;
							default: break;
						}
						break;
					}
					default: break;
				}
				break;
			}
			case IApiProblem.CATEGORY_API_COMPONENT_RESOLUTION: {
				switch(kind) {
					case IApiProblem.API_COMPONENT_RESOLUTION: return 99;
					default: break;
				}
				break;
			}
			case IApiProblem.CATEGORY_FATAL_PROBLEM: {
				switch(kind) {
					case IApiProblem.FATAL_JDT_BUILDPATH_PROBLEM: return 31;
					default: break;
				}
				break;
			}
			case IApiProblem.CATEGORY_API_USE_SCAN_PROBLEM : {
				switch(kind) {
					case IApiProblem.API_USE_SCAN_TYPE_PROBLEM: return 136 + flags;
					case IApiProblem.API_USE_SCAN_METHOD_PROBLEM: return 138 + flags;
					case IApiProblem.API_USE_SCAN_FIELD_PROBLEM: return 140 + flags;
					default: break;
				}
				break;
			}
			default: break;
		}
		return 0;
	}
	
	/**
	 * Returns the problem severity id for the given problem parameters.
	 * @param category
	 * @param element
	 * @param kind
	 * @param flags
	 * @return the id of the preference to use to lookup the user specified severity level for the given {@link IApiProblem}
	 */
	public static String getProblemSeverityId(IApiProblem problem) {
		switch(problem.getCategory()) {
			case IApiProblem.CATEGORY_FATAL_PROBLEM: {
				switch(problem.getKind()) {
					case IApiProblem.FATAL_JDT_BUILDPATH_PROBLEM: return IApiProblemTypes.FATAL_PROBLEMS;
					default: break;
				}
				break;	
			}
			case IApiProblem.CATEGORY_API_COMPONENT_RESOLUTION : {
				switch(problem.getKind()) {
					case IApiProblem.API_COMPONENT_RESOLUTION: return IApiProblemTypes.REPORT_RESOLUTION_ERRORS_API_COMPONENT;
					default: break;
				}
				break;
			}
			case IApiProblem.CATEGORY_API_BASELINE: {
				switch(problem.getKind()) {
					case IApiProblem.API_BASELINE_MISSING: return IApiProblemTypes.MISSING_DEFAULT_API_BASELINE;
					default: break;
				}
				break;
			}
			case IApiProblem.CATEGORY_SINCETAGS: {
				switch(problem.getKind()) {
					case IApiProblem.SINCE_TAG_INVALID: return IApiProblemTypes.INVALID_SINCE_TAG_VERSION;
					case IApiProblem.SINCE_TAG_MALFORMED: return IApiProblemTypes.MALFORMED_SINCE_TAG;
					case IApiProblem.SINCE_TAG_MISSING: return IApiProblemTypes.MISSING_SINCE_TAG;
					default: break;
				}
				break;
			}
			case IApiProblem.CATEGORY_VERSION: {
				return IApiProblemTypes.INCOMPATIBLE_API_COMPONENT_VERSION;
			}
			case IApiProblem.CATEGORY_USAGE: {
				switch(problem.getKind()) {
					case IApiProblem.ILLEGAL_IMPLEMENT: return IApiProblemTypes.ILLEGAL_IMPLEMENT;
					case IApiProblem.ILLEGAL_EXTEND: return IApiProblemTypes.ILLEGAL_EXTEND;
					case IApiProblem.ILLEGAL_INSTANTIATE: return IApiProblemTypes.ILLEGAL_INSTANTIATE;
					case IApiProblem.ILLEGAL_OVERRIDE: return IApiProblemTypes.ILLEGAL_OVERRIDE;
					case IApiProblem.ILLEGAL_REFERENCE: return IApiProblemTypes.ILLEGAL_REFERENCE;
					case IApiProblem.API_LEAK: {
						switch(problem.getFlags()) {
							case IApiProblem.LEAK_EXTENDS : return IApiProblemTypes.LEAK_EXTEND;
							case IApiProblem.LEAK_FIELD : return IApiProblemTypes.LEAK_FIELD_DECL;
							case IApiProblem.LEAK_IMPLEMENTS : return IApiProblemTypes.LEAK_IMPLEMENT;
							case IApiProblem.LEAK_CONSTRUCTOR_PARAMETER: 
							case IApiProblem.LEAK_METHOD_PARAMETER : return IApiProblemTypes.LEAK_METHOD_PARAM;
							case IApiProblem.LEAK_RETURN_TYPE : return IApiProblemTypes.LEAK_METHOD_RETURN_TYPE;
							default: break;
						}
						break;
					}
					case IApiProblem.UNSUPPORTED_TAG_USE: return IApiProblemTypes.INVALID_JAVADOC_TAG;
					case IApiProblem.DUPLICATE_TAG_USE: return IApiProblemTypes.INVALID_JAVADOC_TAG;
					case IApiProblem.INVALID_REFERENCE_IN_SYSTEM_LIBRARIES: return IApiProblemTypes.INVALID_REFERENCE_IN_SYSTEM_LIBRARIES;
					case IApiProblem.UNUSED_PROBLEM_FILTERS: return IApiProblemTypes.UNUSED_PROBLEM_FILTERS;
					case IApiProblem.MISSING_EE_DESCRIPTIONS: return IApiProblemTypes.MISSING_EE_DESCRIPTIONS;
					default: break;
				}
				break;
			}
			case IApiProblem.CATEGORY_COMPATIBILITY: {
				return Util.getDeltaPrefererenceKey(problem.getElementKind(), problem.getKind(), problem.getFlags());
			}
			case IApiProblem.CATEGORY_API_USE_SCAN_PROBLEM: {
				switch(problem.getKind()) {
					case IApiProblem.API_USE_SCAN_TYPE_PROBLEM : return IApiProblemTypes.API_USE_SCAN_TYPE_SEVERITY;
					case IApiProblem.API_USE_SCAN_METHOD_PROBLEM : return IApiProblemTypes.API_USE_SCAN_METHOD_SEVERITY;
					case IApiProblem.API_USE_SCAN_FIELD_PROBLEM : return IApiProblemTypes.API_USE_SCAN_FIELD_SEVERITY;
					default: break;
				}
				break;
			}
			default: break;
		}
		return null;
	}
}

Back to the top