Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d6673327472b433fb5be7ea1362fb52f520067ec (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
/*******************************************************************************
 * Copyright (c) 2006 Oracle Corporation.
 * 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:
 *    Cameron Bateman/Oracle - initial API and implementation
 *    
 ********************************************************************************/

package org.eclipse.jst.jsf.validation.internal;

import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jst.jsf.core.internal.IJSFPreferenceModel;
import org.eclipse.jst.jsf.core.internal.JSFCorePlugin;
import org.eclipse.jst.jsf.validation.internal.el.diagnostics.DiagnosticFactory;

/**
 * Model object for EL validation preferences
 * 
 * @author cbateman
 */
public class ELValidationPreferences implements IJSFPreferenceModel
{
    private final static String KEY_ENABLE_BUILD_VALIDATION = 
        "org.eclipse.jst.jsf.ui.ValidateJSFELBuild"; //$NON-NLS-1$
    private final static boolean DEFAULT_ENABLE_BUILD_VALIDATION = true;

    private final static String KEY_ENABLE_INCREMENTAL_VALIDATION = 
        "org.eclipse.jst.jsf.ui.ValidateJSFELIncremental"; //$NON-NLS-1$
    private final static boolean DEFAULT_ENABLE_INCREMENTAL_VALIDATION = false;
    

    private boolean         _enableBuildValidation;
    private boolean         _enableIncrementalValidation;
    private int[]           _severities;

    /**
     * Loads the object from the preference store provided
     * 
     * @param prefStore
     */
    public void load(IPreferenceStore  prefStore)
    {
        if (!prefStore.contains(KEY_ENABLE_BUILD_VALIDATION))
        {
            prefStore.setDefault(KEY_ENABLE_BUILD_VALIDATION, DEFAULT_ENABLE_BUILD_VALIDATION);
        }
        _enableBuildValidation = 
            prefStore.getBoolean(KEY_ENABLE_BUILD_VALIDATION);

        if (!prefStore.contains(KEY_ENABLE_INCREMENTAL_VALIDATION))
        {
            prefStore.setDefault(KEY_ENABLE_INCREMENTAL_VALIDATION, DEFAULT_ENABLE_INCREMENTAL_VALIDATION);
        }
        _enableIncrementalValidation = 
            prefStore.getBoolean(KEY_ENABLE_INCREMENTAL_VALIDATION);
        
        loadSeverities(prefStore);
    }

    private void loadSeverities(final IPreferenceStore  prefStore)
    {
        final int severities[] = getSeverities();
        
        for (int i = 0; i < DiagnosticFactory.NUM_IDS; i++)
        {
            final String key = getKeyById(i);
            
            if (!prefStore.contains(key))
            {
                final int diagSeverity = getDefaultSeverity(i); 
                final Severity severity  = mapDiagToSeverity(diagSeverity);
        
                prefStore.setDefault(key, severity.toString());
            }
            final String  storedSeverity = prefStore.getString(key);
            severities[i] = mapSeverityToDiag(storedSeverity);
        }
    }
    /**
     * Copies the object into the preference store but DOES NOT SAVE IT
     * 
     * @param prefStore
     */
    public void commit(IPreferenceStore prefStore)
    {
        prefStore.setValue(KEY_ENABLE_BUILD_VALIDATION, _enableBuildValidation);
        prefStore.setValue(KEY_ENABLE_INCREMENTAL_VALIDATION, 
                           _enableIncrementalValidation);
        commitSeverities(prefStore);
    }
    
    private void commitSeverities(final IPreferenceStore prefStore)
    {
        final int severities[] = getSeverities();
        
        for (int i = 0; i < severities.length; i++)
        {
            final String key = getKeyById(i);
            prefStore.setValue(key
                , mapDiagToSeverity(severities[i]).toString());
        }
    }
    
    /**
     * Reverts the model to it's defaults.  Does not commit to pref store. 
     */
    public void setDefaults()
    {
        setEnableBuildValidation(DEFAULT_ENABLE_BUILD_VALIDATION);
        setEnableIncrementalValidation(DEFAULT_ENABLE_INCREMENTAL_VALIDATION);
        setProblemSeverityDefaults();
    }
    
    private void setProblemSeverityDefaults()
    {
        final int[] severities = getSeverities();
        
        for (int i = 0; i < DiagnosticFactory.NUM_IDS; i++)
        {
            severities[i] = getDefaultSeverity(i); 
        }
    }
    
    public Object getValueByKey(IScopeContext context, String key) {
        // ignore context for now; will be used when we have project overrides
        if (KEY_ENABLE_BUILD_VALIDATION.equals(key))
        {
            return Boolean.valueOf(isEnableBuildValidation());
        }
        else if (KEY_ENABLE_INCREMENTAL_VALIDATION.equals(key))
        {
            return Boolean.valueOf(isEnableIncrementalValidation());
        }
        else
        {
            try
            {
                final Severity severity = getSeverity(key);
                return severity.toString();
            }
            catch (IllegalArgumentException e)
            {
                // getIdByKey will throw this exception if key is not a valid
                // severity key.  Ignore the exception here and fall-through
            }
        }
        
        return null; // not found
    }

    /* (non-Javadoc)
     * @see org.eclipse.jst.jsf.core.internal.IJSFPreferenceModel#getStoredValueByKey(org.eclipse.core.runtime.preferences.IScopeContext, java.lang.String)
     */
    public Object getStoredValueByKey(IScopeContext context, String key) {
        // ignore context for now; will be used when we have project overrides
        if (KEY_ENABLE_BUILD_VALIDATION.equals(key))
        {
            return Boolean.valueOf(context.getNode("org.eclipse.jst.jsf.ui").getBoolean(key, true)); //$NON-NLS-1$
        }
        else if (KEY_ENABLE_INCREMENTAL_VALIDATION.equals(key))
        {
            return Boolean.valueOf(context.getNode("org.eclipse.jst.jsf.ui").getBoolean(key, false)); //$NON-NLS-1$
        }
        else
        {
            try
            {
                return context.getNode("org.eclipse.jst.jsf.core").get(key, mapDiagToSeverity(getDefaultSeverity(getIdByKey(key))).toString()); //$NON-NLS-1$
            }
            catch (IllegalArgumentException e)
            {
                // getIdByKey will throw this exception if key is not a valid
                // severity key.  Ignore the exception here and fall-through
            }
        }
        
        return null; // not found
    }

    /* (non-Javadoc)
     * @see org.eclipse.jst.jsf.core.internal.IJSFPreferenceModel#setValueByKey(org.eclipse.core.runtime.preferences.IScopeContext, java.lang.String, java.lang.Object)
     */
    public Object setValueByKey(IScopeContext context, String key, Object value) 
    {
        // ignore context for now; will be used when we have project overrides
        if (KEY_ENABLE_BUILD_VALIDATION.equals(key))
        {
            boolean oldValue = isEnableBuildValidation();
            boolean newValue = ((Boolean)value).booleanValue();
            setEnableBuildValidation(newValue);
            return Boolean.valueOf(oldValue);
        }
        else if (KEY_ENABLE_INCREMENTAL_VALIDATION.equals(key))
        {
            boolean oldValue = isEnableIncrementalValidation();
            boolean newValue = ((Boolean)value).booleanValue();
            setEnableIncrementalValidation(newValue);
            return Boolean.valueOf(oldValue);
        }
        else
        {
            final Severity oldValue = getSeverity(key);
            setSeverity(key, (Severity)value);
            return oldValue;
        }
    }

    /**
     * @return the build validation enablement
     */
    public boolean isEnableBuildValidation() 
    {
        return _enableBuildValidation;
    }

    /**
     * @return the incremental validation enablement
     */
    public boolean isEnableIncrementalValidation() 
    {
        return _enableIncrementalValidation;
    }

    /**
     * @param enableBuildValidation
     */
    public void setEnableBuildValidation(boolean enableBuildValidation) {
        _enableBuildValidation = enableBuildValidation;
    }

    /**
     * @param enableIncrementalValidation
     */
    public void setEnableIncrementalValidation(boolean enableIncrementalValidation) {
        _enableIncrementalValidation = enableIncrementalValidation;
    }
    
    /**
     * @param key
     * @return the severity
     */
    public Severity getSeverity(final String key)
    {
        final int severityDiag = _severities[getIdByKey(key)];
        final Severity severity = mapDiagToSeverity(severityDiag);
        return severity;
    }

    /**
     * @param key
     * @param severity
     */
    public void setSeverity(final String key, final Severity severity)
    {
        final int newSeverityDiag = mapSeverityToDiag(severity.toString());
        final int diagId = getIdByKey(key);
        _severities[diagId] = newSeverityDiag;
    }
    
    /**
     * @param diagnosticId
     * @return the severity as configured for diagnosticId.  The value
     * is relative to the Diagnostic class severity scheme
     */
    public final int getDiagnosticSeverity(final int diagnosticId)
    {
        return getSeverities()[diagnosticId];
    }
    
    private int[] getSeverities()
    {
        if (_severities == null)
        {
            _severities = new int[DiagnosticFactory.NUM_IDS];
        }
        
        return _severities;
    }
    
    /**
     * @param diagSeverity
     * @return a Severity preference value for a diagnostic severity
     */
    public static Severity mapDiagToSeverity(int diagSeverity)
    {
        switch(diagSeverity)
        {
            case Diagnostic.ERROR:
                return Severity.ERROR;
            case Diagnostic.WARNING:
                return Severity.WARNING;
            default:
                return Severity.IGNORE;
        }
    }
    
    /**
     * @param severity
     * @return a Diagnostic severity level for a severity pref string
     */
    public static int mapSeverityToDiag(String severity)
    {
        if ("error".equals(severity)) //$NON-NLS-1$
        {
            return Diagnostic.ERROR;
        }
        else if ("warning".equals(severity)) //$NON-NLS-1$
        {
            return Diagnostic.WARNING;
        }
        else if ("ignore".equals(severity)) //$NON-NLS-1$
        {
            return Diagnostic.OK;
        }
        else
        {
            throw new IllegalArgumentException("Invalid enum name: "+severity); //$NON-NLS-1$
        }
    }
    
    /**
     * @param diagnosticId
     * @return the default severity of a diagnostic
     */
    public static int getDefaultSeverity(final int diagnosticId)
    {
        switch(diagnosticId)
        {
            case DiagnosticFactory.BINARY_OP_BOTH_OPERANDS_NULL_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.BINARY_OP_POSSIBLE_DIVISION_BY_ZERO_ID:
                return Diagnostic.ERROR;
            case DiagnosticFactory.BINARY_OP_COULD_NOT_MAKE_NUMERIC_COERCION_ID:
                return Diagnostic.ERROR;
            case DiagnosticFactory.BINARY_OP_CONSTANT_EXPRESSION_ALWAYS_EVAL_SAME_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.BINARY_OP_EQUALITY_COMP_WITH_NULL_ALWAYS_EVAL_SAME_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.BINARY_OP_CANNOT_COERCE_ARGUMENT_TO_BOOLEAN_ID:
                return Diagnostic.ERROR;
            case DiagnosticFactory.BINARY_OP_FIRST_ARGUMENT_SHORT_CIRCUITS_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.BINARY_OP_SECOND_ARGUMENT_ALWAYS_EVAL_SAME_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.BINARY_OP_NO_AVAILABLE_TYPE_COERCION_ID:
                return Diagnostic.ERROR;
            case DiagnosticFactory.BINARY_OP_COULD_NOT_COERCE_LITERALS_TO_NUMBERS_ID:
                return Diagnostic.ERROR;
            case DiagnosticFactory.UNARY_OP_CONSTANT_EXPRESSION_EVAL_SAME_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.UNARY_OP_EMPTY_ALWAYS_FALSE_ON_TYPE_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.UNARY_OP_MINUS_ON_NULL_ALWAYS_ZERO_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.UNARY_OP_COULD_NOT_MAKE_NUMERIC_COERCION_ID:
                return Diagnostic.ERROR;
            case DiagnosticFactory.UNARY_OP_CANNOT_COERCE_ARGUMENT_TO_BOOLEAN_ID:
                return Diagnostic.ERROR;
            case DiagnosticFactory.TERNARY_OP_CHOICE_IS_ALWAYS_SAME_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.TERNARY_OP_CANNOT_COERCE_CHOICE_TO_BOOLEAN_ID:
                return Diagnostic.ERROR;
            case DiagnosticFactory.UNARY_OP_STRING_CONVERSION_NOT_GUARANTEED_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.CANNOT_APPLY_OPERATOR_TO_METHOD_BINDING_ID:
                return Diagnostic.ERROR;
            case DiagnosticFactory.MEMBER_NOT_FOUND_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.VARIABLE_NOT_FOUND_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.MISSING_CLOSING_EXPR_BRACKET_ID:
                return Diagnostic.ERROR;
            case DiagnosticFactory.GENERAL_SYNTAX_ERROR_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.EMPTY_EL_EXPRESSION_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.BINARY_OP_DOT_WITH_VALUEB_NULL_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.BINARY_OP_DOT_WITH_DOTTED_KEY_SHOULD_USE_ARRAY_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.POSSIBLE_ARRAY_INDEX_OUT_OF_BOUNDS_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.BINARY_COMPARISON_WITH_ENUM_ALWAYS_SAME_ID:
                return Diagnostic.WARNING;
            case DiagnosticFactory.BINARY_OP_COMPARISON_OF_ENUMS_INCOMPATIBLE_ID:
                return Diagnostic.ERROR;
            case DiagnosticFactory.MEMBER_IS_INTERMEDIATE_ID:
                return Diagnostic.WARNING;
            default:
                throw new IllegalArgumentException("Diagnostic Id: "+ diagnosticId +" is out of range"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }

    /**
     * @param diagnosticId
     * @return the preference key for the corresponding diagnosticId in the el DiagnosticFactory
     */
    public static String getKeyById(final int diagnosticId)
    {
        switch(diagnosticId)
        {
            case DiagnosticFactory.BINARY_OP_BOTH_OPERANDS_NULL_ID:
                return BINARY_OP_BOTH_OPERANDS_NULL;
            case DiagnosticFactory.BINARY_OP_POSSIBLE_DIVISION_BY_ZERO_ID:
                return BINARY_OP_POSSIBLE_DIVISION_BY_ZERO;
            case DiagnosticFactory.BINARY_OP_COULD_NOT_MAKE_NUMERIC_COERCION_ID:
                return BINARY_OP_COULD_NOT_MAKE_NUMERIC_COERCION;
            case DiagnosticFactory.BINARY_OP_CONSTANT_EXPRESSION_ALWAYS_EVAL_SAME_ID:
                return BINARY_OP_CONSTANT_EXPRESSION_ALWAYS_EVAL_SAME;
            case DiagnosticFactory.BINARY_OP_EQUALITY_COMP_WITH_NULL_ALWAYS_EVAL_SAME_ID:
                return BINARY_OP_EQUALITY_COMP_WITH_NULL_ALWAYS_EVAL_SAME;
            case DiagnosticFactory.BINARY_OP_CANNOT_COERCE_ARGUMENT_TO_BOOLEAN_ID:
                return BINARY_OP_CANNOT_COERCE_ARGUMENT_TO_BOOLEAN;
            case DiagnosticFactory.BINARY_OP_FIRST_ARGUMENT_SHORT_CIRCUITS_ID:
                return BINARY_OP_FIRST_ARGUMENT_SHORT_CIRCUITS;
            case DiagnosticFactory.BINARY_OP_SECOND_ARGUMENT_ALWAYS_EVAL_SAME_ID:
                return BINARY_OP_SECOND_ARGUMENT_ALWAYS_EVAL_SAME;
            case DiagnosticFactory.BINARY_OP_NO_AVAILABLE_TYPE_COERCION_ID:
                return BINARY_OP_NO_AVAILABLE_TYPE_COERCION;
            case DiagnosticFactory.BINARY_OP_COULD_NOT_COERCE_LITERALS_TO_NUMBERS_ID:
                return BINARY_OP_COULD_NOT_COERCE_LITERALS_TO_NUMBERS;
            case DiagnosticFactory.UNARY_OP_CONSTANT_EXPRESSION_EVAL_SAME_ID:
                return UNARY_OP_CONSTANT_EXPRESSION_EVAL_SAME;
            case DiagnosticFactory.UNARY_OP_EMPTY_ALWAYS_FALSE_ON_TYPE_ID:
                return UNARY_OP_EMPTY_ALWAYS_FALSE_ON_TYPE;
            case DiagnosticFactory.UNARY_OP_MINUS_ON_NULL_ALWAYS_ZERO_ID:
                return UNARY_OP_MINUS_ON_NULL_ALWAYS_ZERO;
            case DiagnosticFactory.UNARY_OP_COULD_NOT_MAKE_NUMERIC_COERCION_ID:
                return UNARY_OP_COULD_NOT_MAKE_NUMERIC_COERCION;
            case DiagnosticFactory.UNARY_OP_CANNOT_COERCE_ARGUMENT_TO_BOOLEAN_ID:
                return UNARY_OP_CANNOT_COERCE_ARGUMENT_TO_BOOLEAN;
            case DiagnosticFactory.TERNARY_OP_CHOICE_IS_ALWAYS_SAME_ID:
                return TERNARY_OP_CHOICE_IS_ALWAYS_SAME;
            case DiagnosticFactory.TERNARY_OP_CANNOT_COERCE_CHOICE_TO_BOOLEAN_ID:
                return TERNARY_OP_CANNOT_COERCE_CHOICE_TO_BOOLEAN;
            case DiagnosticFactory.UNARY_OP_STRING_CONVERSION_NOT_GUARANTEED_ID:
                return UNARY_OP_STRING_CONVERSION_NOT_GUARANTEED;
            case DiagnosticFactory.CANNOT_APPLY_OPERATOR_TO_METHOD_BINDING_ID:
                return CANNOT_APPLY_OPERATOR_TO_METHOD_BINDING;
            case DiagnosticFactory.MEMBER_NOT_FOUND_ID:
                return MEMBER_NOT_FOUND;
            case DiagnosticFactory.VARIABLE_NOT_FOUND_ID:
                return VARIABLE_NOT_FOUND;
            case DiagnosticFactory.MISSING_CLOSING_EXPR_BRACKET_ID:
                return MISSING_CLOSING_EXPR_BRACKET;
            case DiagnosticFactory.GENERAL_SYNTAX_ERROR_ID:
                return GENERAL_SYNTAX_ERROR;
            case DiagnosticFactory.EMPTY_EL_EXPRESSION_ID:
                return EMPTY_EL_EXPRESSION;
            case DiagnosticFactory.BINARY_OP_DOT_WITH_VALUEB_NULL_ID:
                return BINARY_OP_DOT_WITH_VALUEB_NULL;
            case DiagnosticFactory.BINARY_OP_DOT_WITH_DOTTED_KEY_SHOULD_USE_ARRAY_ID:
                return BINARY_OP_DOT_WITH_DOTTED_KEY_SHOULD_USE_ARRAY;
            case DiagnosticFactory.POSSIBLE_ARRAY_INDEX_OUT_OF_BOUNDS_ID:
                return POSSIBLE_ARRAY_INDEX_OUT_OF_BOUNDS;
            case DiagnosticFactory.BINARY_COMPARISON_WITH_ENUM_ALWAYS_SAME_ID:
                return BINARY_COMPARISON_WITH_ENUM_ALWAYS_SAME;
            case DiagnosticFactory.BINARY_OP_COMPARISON_OF_ENUMS_INCOMPATIBLE_ID:
                return BINARY_OP_COMPARISON_OF_ENUMS_INCOMPATIBLE;
            case DiagnosticFactory.MEMBER_IS_INTERMEDIATE_ID:
                return MEMBER_IS_INTERMEDIATE;
            default:
                throw new IllegalArgumentException("Diagnostic Id: "+ diagnosticId +" is out of range"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
    
    /**
     * @param key
     * @return the preference key for the corresponding diagnosticId in the el DiagnosticFactory
     */
    public static int getIdByKey(final String key)
    {
        if (BINARY_OP_BOTH_OPERANDS_NULL.equals(key))
        {
            return DiagnosticFactory.BINARY_OP_BOTH_OPERANDS_NULL_ID;
        }
        else if (BINARY_OP_POSSIBLE_DIVISION_BY_ZERO.equals(key))
        {
            return DiagnosticFactory.BINARY_OP_POSSIBLE_DIVISION_BY_ZERO_ID;
        }
        else if (BINARY_OP_COULD_NOT_MAKE_NUMERIC_COERCION.equals(key))
        {
            return DiagnosticFactory.BINARY_OP_COULD_NOT_MAKE_NUMERIC_COERCION_ID;
        }
        else if (BINARY_OP_CONSTANT_EXPRESSION_ALWAYS_EVAL_SAME.equals(key))
        {
            return DiagnosticFactory.BINARY_OP_CONSTANT_EXPRESSION_ALWAYS_EVAL_SAME_ID;
        }
        else if (BINARY_OP_EQUALITY_COMP_WITH_NULL_ALWAYS_EVAL_SAME.equals(key))
        {
            return DiagnosticFactory.BINARY_OP_EQUALITY_COMP_WITH_NULL_ALWAYS_EVAL_SAME_ID;
        }
        else if (BINARY_OP_CANNOT_COERCE_ARGUMENT_TO_BOOLEAN.equals(key))
        {
            return DiagnosticFactory.BINARY_OP_CANNOT_COERCE_ARGUMENT_TO_BOOLEAN_ID;
        }
        else if (BINARY_OP_FIRST_ARGUMENT_SHORT_CIRCUITS.equals(key))
        {
            return DiagnosticFactory.BINARY_OP_FIRST_ARGUMENT_SHORT_CIRCUITS_ID;
        }
        else if (BINARY_OP_SECOND_ARGUMENT_ALWAYS_EVAL_SAME.equals(key))
        {
            return DiagnosticFactory.BINARY_OP_SECOND_ARGUMENT_ALWAYS_EVAL_SAME_ID;
        }
        else if (BINARY_OP_NO_AVAILABLE_TYPE_COERCION.equals(key))
        {
            return DiagnosticFactory.BINARY_OP_NO_AVAILABLE_TYPE_COERCION_ID;
        }
        else if (BINARY_OP_COULD_NOT_COERCE_LITERALS_TO_NUMBERS.equals(key))
        {
            return DiagnosticFactory.BINARY_OP_COULD_NOT_COERCE_LITERALS_TO_NUMBERS_ID;
        }
        else if (UNARY_OP_CONSTANT_EXPRESSION_EVAL_SAME.equals(key))
        {
            return DiagnosticFactory.UNARY_OP_CONSTANT_EXPRESSION_EVAL_SAME_ID;
        }
        else if (UNARY_OP_EMPTY_ALWAYS_FALSE_ON_TYPE.equals(key))
        {
            return DiagnosticFactory.UNARY_OP_EMPTY_ALWAYS_FALSE_ON_TYPE_ID;
        }
        else if (UNARY_OP_MINUS_ON_NULL_ALWAYS_ZERO.equals(key))
        {
            return DiagnosticFactory.UNARY_OP_MINUS_ON_NULL_ALWAYS_ZERO_ID;
        }
        else if (UNARY_OP_COULD_NOT_MAKE_NUMERIC_COERCION.equals(key))
        {
            return DiagnosticFactory.UNARY_OP_COULD_NOT_MAKE_NUMERIC_COERCION_ID;
        }
        else if (UNARY_OP_CANNOT_COERCE_ARGUMENT_TO_BOOLEAN.equals(key))
        {
            return DiagnosticFactory.UNARY_OP_CANNOT_COERCE_ARGUMENT_TO_BOOLEAN_ID;
        }
        else if (TERNARY_OP_CHOICE_IS_ALWAYS_SAME.equals(key))
        {
            return DiagnosticFactory.TERNARY_OP_CHOICE_IS_ALWAYS_SAME_ID;
        }
        else if (TERNARY_OP_CANNOT_COERCE_CHOICE_TO_BOOLEAN.equals(key))
        {
            return DiagnosticFactory.TERNARY_OP_CANNOT_COERCE_CHOICE_TO_BOOLEAN_ID;
        }
        else if (UNARY_OP_STRING_CONVERSION_NOT_GUARANTEED.equals(key))
        {
            return DiagnosticFactory.UNARY_OP_STRING_CONVERSION_NOT_GUARANTEED_ID;
        }
        else if (CANNOT_APPLY_OPERATOR_TO_METHOD_BINDING.equals(key))
        {
            return DiagnosticFactory.CANNOT_APPLY_OPERATOR_TO_METHOD_BINDING_ID;
        }
        else if (MEMBER_NOT_FOUND.equals(key))
        {
            return DiagnosticFactory.MEMBER_NOT_FOUND_ID;
        }
        else if (VARIABLE_NOT_FOUND.equals(key))
        {
            return DiagnosticFactory.VARIABLE_NOT_FOUND_ID;
        }
        else if (MISSING_CLOSING_EXPR_BRACKET.equals(key))
        {
            return DiagnosticFactory.MISSING_CLOSING_EXPR_BRACKET_ID;
        }
        else if (GENERAL_SYNTAX_ERROR.equals(key))
        {
            return DiagnosticFactory.GENERAL_SYNTAX_ERROR_ID;
        }
        else if (EMPTY_EL_EXPRESSION.equals(key))
        {
           return DiagnosticFactory.EMPTY_EL_EXPRESSION_ID;
        }
        else if (BINARY_OP_DOT_WITH_VALUEB_NULL.equals(key))
        {
            return DiagnosticFactory.BINARY_OP_DOT_WITH_VALUEB_NULL_ID;
        }
        else if (BINARY_OP_DOT_WITH_DOTTED_KEY_SHOULD_USE_ARRAY.equals(key))
        {
            return DiagnosticFactory.BINARY_OP_DOT_WITH_DOTTED_KEY_SHOULD_USE_ARRAY_ID;
        }
        else if (POSSIBLE_ARRAY_INDEX_OUT_OF_BOUNDS.equals(key))
        {
            return DiagnosticFactory.POSSIBLE_ARRAY_INDEX_OUT_OF_BOUNDS_ID;
        }
        else if (BINARY_COMPARISON_WITH_ENUM_ALWAYS_SAME.equals(key))
        {
            return DiagnosticFactory.BINARY_COMPARISON_WITH_ENUM_ALWAYS_SAME_ID;
        }
        else if (BINARY_OP_COMPARISON_OF_ENUMS_INCOMPATIBLE.equals(key))
        {
            return DiagnosticFactory.BINARY_OP_COMPARISON_OF_ENUMS_INCOMPATIBLE_ID;
        }
        else if (MEMBER_IS_INTERMEDIATE.equals(key))
        {
            return DiagnosticFactory.MEMBER_IS_INTERMEDIATE_ID;
        }
        else
        {
            throw new IllegalArgumentException("Severity Key: "+ key); //$NON-NLS-1$
        }
    }
    
    /**
     * e.g. createQualifiedKeyName("foo") -> org.eclipse.jst.jsf.core.foo
     * @param baseName
     * @return a plugin qualified key given the baseName
     * 
     */
    private static String createQualifiedKeyName(final String baseName)
    {
        return JSFCorePlugin.PLUGIN_ID + "." + baseName; //$NON-NLS-1$
    }
    
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String BINARY_OP_BOTH_OPERANDS_NULL = 
        createQualifiedKeyName("BINARY_OP_BOTH_OPERANDS_NULL"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String BINARY_OP_POSSIBLE_DIVISION_BY_ZERO = 
        createQualifiedKeyName("BINARY_OP_POSSIBLE_DIVISION_BY_ZERO"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String BINARY_OP_COULD_NOT_MAKE_NUMERIC_COERCION = 
        createQualifiedKeyName("BINARY_OP_COULD_NOT_MAKE_NUMERIC_COERCION"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String BINARY_OP_CONSTANT_EXPRESSION_ALWAYS_EVAL_SAME = 
        createQualifiedKeyName("BINARY_OP_CONSTANT_EXPRESSION_ALWAYS_EVAL_SAME"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String BINARY_OP_EQUALITY_COMP_WITH_NULL_ALWAYS_EVAL_SAME = 
        createQualifiedKeyName("BINARY_OP_EQUALITY_COMP_WITH_NULL_ALWAYS_EVAL_SAME"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String BINARY_OP_CANNOT_COERCE_ARGUMENT_TO_BOOLEAN = 
        createQualifiedKeyName("BINARY_OP_CANNOT_COERCE_ARGUMENT_TO_BOOLEAN"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String BINARY_OP_FIRST_ARGUMENT_SHORT_CIRCUITS = 
        createQualifiedKeyName("BINARY_OP_FIRST_ARGUMENT_SHORT_CIRCUITS"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String BINARY_OP_SECOND_ARGUMENT_ALWAYS_EVAL_SAME =
        createQualifiedKeyName("BINARY_OP_SECOND_ARGUMENT_ALWAYS_EVAL_SAME"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String BINARY_OP_NO_AVAILABLE_TYPE_COERCION = 
        createQualifiedKeyName("BINARY_OP_NO_AVAILABLE_TYPE_COERCION"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String BINARY_OP_COULD_NOT_COERCE_LITERALS_TO_NUMBERS = 
        createQualifiedKeyName("BINARY_OP_COULD_NOT_COERCE_LITERALS_TO_NUMBERS"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String UNARY_OP_CONSTANT_EXPRESSION_EVAL_SAME = 
        createQualifiedKeyName("UNARY_OP_CONSTANT_EXPRESSION_EVAL_SAME"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String UNARY_OP_EMPTY_ALWAYS_FALSE_ON_TYPE = 
        createQualifiedKeyName("UNARY_OP_EMPTY_ALWAYS_FALSE_ON_TYPE"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String UNARY_OP_MINUS_ON_NULL_ALWAYS_ZERO = 
        createQualifiedKeyName("UNARY_OP_MINUS_ON_NULL_ALWAYS_ZERO"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String UNARY_OP_COULD_NOT_MAKE_NUMERIC_COERCION = 
        createQualifiedKeyName("UNARY_OP_COULD_NOT_MAKE_NUMERIC_COERCION"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String UNARY_OP_CANNOT_COERCE_ARGUMENT_TO_BOOLEAN = 
        createQualifiedKeyName("UNARY_OP_CANNOT_COERCE_ARGUMENT_TO_BOOLEAN"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String TERNARY_OP_CHOICE_IS_ALWAYS_SAME = 
        createQualifiedKeyName("TERNARY_OP_CHOICE_IS_ALWAYS_SAME"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String TERNARY_OP_CANNOT_COERCE_CHOICE_TO_BOOLEAN = 
        createQualifiedKeyName("TERNARY_OP_CANNOT_COERCE_CHOICE_TO_BOOLEAN");  //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String UNARY_OP_STRING_CONVERSION_NOT_GUARANTEED = 
        createQualifiedKeyName("UNARY_OP_STRING_CONVERSION_NOT_GUARANTEED"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String CANNOT_APPLY_OPERATOR_TO_METHOD_BINDING = 
        createQualifiedKeyName("CANNOT_APPLY_OPERATOR_TO_METHOD_BINDING"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String MEMBER_NOT_FOUND = 
        createQualifiedKeyName("MEMBER_NOT_FOUND"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String VARIABLE_NOT_FOUND = 
        createQualifiedKeyName("VARIABLE_NOT_FOUND"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String MISSING_CLOSING_EXPR_BRACKET = 
        createQualifiedKeyName("MISSING_CLOSING_EXPR_BRACKET"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String GENERAL_SYNTAX_ERROR = 
        createQualifiedKeyName("GENERAL_SYNTAX_ERROR"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String EMPTY_EL_EXPRESSION = 
        createQualifiedKeyName("EMPTY_EL_EXPRESSION"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String BINARY_OP_DOT_WITH_VALUEB_NULL = 
        createQualifiedKeyName("BINARY_OP_DOT_WITH_VALUEB_NULL"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String BINARY_OP_DOT_WITH_DOTTED_KEY_SHOULD_USE_ARRAY = 
        createQualifiedKeyName("BINARY_OP_DOT_WITH_DOTTED_KEY_SHOULD_USE_ARRAY"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String POSSIBLE_ARRAY_INDEX_OUT_OF_BOUNDS = 
        createQualifiedKeyName("POSSIBLE_ARRAY_INDEX_OUT_OF_BOUNDS"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String BINARY_COMPARISON_WITH_ENUM_ALWAYS_SAME = 
        createQualifiedKeyName("BINARY_COMPARISON_WITH_ENUM_ALWAYS_SAME"); //$NON-NLS-1$
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String BINARY_OP_COMPARISON_OF_ENUMS_INCOMPATIBLE = 
        createQualifiedKeyName("BINARY_OP_COMPARISON_OF_ENUMS_INCOMPATIBLE"); //$NON-NLS-1$
    
    /**
     * preference key.  Match to DiagnosticFactory constants
     */
    public final static String MEMBER_IS_INTERMEDIATE =
        createQualifiedKeyName("MEMBER_IS_INTERMEDIATE"); //$NON-NLS-1$
}

Back to the top