-
Notifications
You must be signed in to change notification settings - Fork 82
/
ProblemSeveritiesConfigurationBlock.java
1655 lines (1340 loc) · 91.6 KB
/
ProblemSeveritiesConfigurationBlock.java
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
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
* Benjamin Muskalla <b.muskalla@gmx.net> - [preferences] Add preference for new compiler warning: MissingSynchronizedModifierInInheritedMethod - https://bugs.eclipse.org/bugs/show_bug.cgi?id=245240
* Stephan Herrmann <stephan@cs.tu-berlin.de> - [compiler][null] inheritance of null annotations as an option - https://bugs.eclipse.org/388281
*******************************************************************************/
package org.eclipse.jdt.internal.ui.preferences;
import java.util.Arrays;
import java.util.List;
import org.eclipse.equinox.bidi.StructuredTextTypeHandlerFactory;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.contentassist.SubjectControlContentAssistant;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.StatusDialog;
import org.eclipse.jface.layout.PixelConverter;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.util.BidiUtils;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.contentassist.ContentAssistHandler;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.manipulation.util.BasicElementLabels;
import org.eclipse.jdt.internal.corext.refactoring.StubTypeContext;
import org.eclipse.jdt.internal.corext.refactoring.TypeContextChecker;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
import org.eclipse.jdt.internal.ui.dialogs.TableTextCellEditor;
import org.eclipse.jdt.internal.ui.dialogs.TextFieldNavigationHandler;
import org.eclipse.jdt.internal.ui.preferences.FilteredPreferenceTree.PreferenceTreeNode;
import org.eclipse.jdt.internal.ui.refactoring.contentassist.CompletionContextRequestor;
import org.eclipse.jdt.internal.ui.refactoring.contentassist.ControlContentAssistHelper;
import org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaTypeCompletionProcessor;
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
public class ProblemSeveritiesConfigurationBlock extends OptionsConfigurationBlock {
private interface IAnnotationDialogField {
String getErrorMessage();
void setStatus(NullAnnotationsConfigurationDialog.AnnotationWrapper element, IStatus newStatus);
}
abstract class AbstractAnnotationsConfigurationDialog extends StatusDialog {
protected static final int RESTORE_DEFAULTS_BUTTON_ID= IDialogConstants.CLIENT_ID + 1;
protected static final String COLUMN_ANNOTATION= "annotation"; //$NON-NLS-1$
protected static final String EMPTY_STRING= ""; //$NON-NLS-1$
public AbstractAnnotationsConfigurationDialog(Shell parent) {
super(parent);
}
protected class AnnotationDialogField extends StringDialogField implements IAnnotationDialogField {
final String fErrorMessage;
IStatus fStatus;
public AnnotationDialogField(String errorMessage) {
fErrorMessage= errorMessage;
fStatus= new StatusInfo();
}
@Override
public String getText() {
return super.getText().trim();
}
@Override
public String getErrorMessage() {
return fErrorMessage;
}
public IStatus getStatus() {
return fStatus;
}
@Override
public void setStatus(AnnotationWrapper element, IStatus newStatus) {
fStatus= newStatus;
}
IStatus doValidation() {
return AbstractAnnotationsConfigurationDialog.this.doValidation(this, null, getText(), true);
}
}
protected class AnnotationWrapper { // mimic a mutable string
public String annotationName;
public IStatus status; // null means: no status computed, yet.
public AnnotationWrapper(String annotationName) {
this.annotationName= annotationName;
}
}
protected class FieldListener implements ModifyListener {
AnnotationDialogField fField;
FieldListener(AnnotationDialogField field) {
fField= field;
}
@Override
public void modifyText(ModifyEvent e) {
fField.doValidation();
}
}
protected class AnnotationCompletionContextRequestor extends CompletionContextRequestor {
@Override
public StubTypeContext getStubTypeContext() {
return TypeContextChecker.createAnnotationStubTypeContext(fProject);
}
}
protected abstract IStatus doValidation(IAnnotationDialogField dialogField, AnnotationWrapper element, String newValue, boolean isTypeMandatory);
protected Group createAnnotationGroup(AnnotationDialogField primaryField, Composite parent, String[] texts, int fieldWidthHint) {
Group group= new Group(parent, SWT.NONE);
GridLayout layout= new GridLayout(3, false);
layout.marginLeft= convertWidthInCharsToPixels(2);
GridData groupData= new GridData(SWT.FILL, SWT.FILL, true, true);
// compensate different height of intro texts when suggesting height of the group:
GC gc= new GC(parent);
gc.setFont(JFaceResources.getDialogFont());
Point size= gc.stringExtent(texts[1]);
int lines= (size.x / fieldWidthHint) + 1;
gc.dispose();
groupData.heightHint= convertHeightInCharsToPixels(8+lines);
group.setLayoutData(groupData);
group.setLayout(layout);
group.setText(texts[0]);
Label intro= new Label(group, SWT.WRAP);
intro.setText(texts[1]);
intro.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, layout.numColumns, 1));
LayoutUtil.setWidthHint(intro, 1); // force text wrapping
primaryField.doFillIntoGrid(group, 2);
addSpacer(group); // button column is empty for the primary field
Text text= primaryField.getTextControl(null);
((GridData)text.getLayoutData()).grabExcessHorizontalSpace= true;
text.addModifyListener(new FieldListener(primaryField));
TextFieldNavigationHandler.install(text);
BidiUtils.applyBidiProcessing(text, StructuredTextTypeHandlerFactory.JAVA);
if (fProject != null) {
JavaTypeCompletionProcessor annotationCompletionProcessor= new JavaTypeCompletionProcessor(false, false, true);
annotationCompletionProcessor.setCompletionContextRequestor(new AnnotationCompletionContextRequestor());
ControlContentAssistHelper.createTextContentAssistant(text, annotationCompletionProcessor);
}
return group;
}
Label addSpacer(Group group) {
return new Label(group, SWT.NONE);
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, RESTORE_DEFAULTS_BUTTON_ID, PreferencesMessages.NullAnnotationsConfigurationDialog_restore_defaults, false);
super.createButtonsForButtonBar(parent);
}
@Override
protected boolean isResizable() {
return true;
}
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.PROBLEM_SEVERITIES_PROPERTY_PAGE);
}
@Override
public void create() {
super.create(); // cannot show error status before this super call
StringDialogField firstErrorField= null;
IStatus firstError= null;
AnnotationDialogField[] primaryFields= getPrimaryFields();
for (AnnotationDialogField field : primaryFields) {
IStatus status= field.doValidation();
if (status.getSeverity() == IStatus.ERROR && firstError == null) {
firstErrorField= field;
firstError= status;
}
}
if (firstErrorField != null && firstError != null) {
updateStatus(firstError);
firstErrorField.postSetFocusOnDialogField(dialogArea.getDisplay());
}
}
protected abstract AnnotationDialogField[] getPrimaryFields();
}
class NullAnnotationsConfigurationDialog extends AbstractAnnotationsConfigurationDialog {
private class AnnotationListDialogField extends ListDialogField<AnnotationWrapper> implements IAnnotationDialogField {
final String fErrorMessage;
public AnnotationListDialogField(IListAdapter<AnnotationWrapper> adapter, String[] buttonLabels, ILabelProvider lprovider, String errorMessage) {
super(adapter, buttonLabels, lprovider);
fErrorMessage= errorMessage;
}
public void addElementsFromCommaSeparatedList(String value) {
value= value.trim();
if (value.isEmpty())
return;
for (String string : value.split(",")) { //$NON-NLS-1$
addElement(new AnnotationWrapper(string.trim()));
}
}
public String getCommaSeparatedElements() {
List<AnnotationWrapper> elements= getElements();
if (elements.isEmpty()) return EMPTY_STRING;
StringBuilder buf= new StringBuilder();
for (int i= 0; i < elements.size(); i++) {
String annotationName= elements.get(i).annotationName;
if (annotationName.isEmpty())
continue;
if (i > 0) buf.append(',');
buf.append(annotationName);
}
return buf.toString();
}
@Override
public void elementChanged(AnnotationWrapper element) throws IllegalArgumentException {
super.elementChanged(element);
NullAnnotationsConfigurationDialog.this.doValidation(this, element, element.annotationName, false);
}
@Override
public String getErrorMessage() {
return fErrorMessage;
}
public IStatus getMostSevereStatus() {
List<AnnotationWrapper> elements= getElements();
if (elements.isEmpty())
return new StatusInfo();
IStatus[] all= new IStatus[elements.size()];
for (int i= 0; i < elements.size(); i++) {
all[i]= elements.get(i).status;
if (all[i] == null)
all[i]= new StatusInfo();
}
return StatusUtil.getMostSevere(all);
}
@Override
public void setStatus(AnnotationWrapper element, IStatus newStatus) {
element.status= newStatus;
}
}
private class AnnotationListAdapter implements IListAdapter<AnnotationWrapper> {
@Override
public void customButtonPressed(ListDialogField<AnnotationWrapper> field, int index) {
if (index == 0) { // "Add"
AnnotationWrapper newElement= new AnnotationWrapper(EMPTY_STRING);
field.addElement(newElement);
field.editElement(newElement);
}
}
@Override
public void selectionChanged(ListDialogField<AnnotationWrapper> field) {
// nothing
}
@Override
public void doubleClicked(ListDialogField<AnnotationWrapper> field) {
// nothing
}
}
private class AnnotationListLabelProvider extends LabelProvider {
AnnotationListDialogField fField;
void setDialogField(AnnotationListDialogField field) {
fField= field;
}
@Override
public String getText(Object element) {
return BasicElementLabels.getJavaElementName(((AnnotationWrapper) element).annotationName);
}
@Override
public Image getImage(Object element) {
if (element instanceof AnnotationWrapper) {
AnnotationWrapper annotationWrapper= (AnnotationWrapper) element;
IStatus status= annotationWrapper.status;
if (status == null) {
status= validateAnnotation(annotationWrapper.annotationName, fField.getErrorMessage(), false);
annotationWrapper.status= status;
}
switch (status.getSeverity()) {
case IStatus.INFO:
return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_REFACTORING_INFO);
case IStatus.ERROR:
return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_REFACTORING_ERROR);
default:
// fall through
}
}
return JavaPluginImages.get(JavaPluginImages.IMG_BLANK);
}
}
private AnnotationDialogField fNullableAnnotationDialogField;
private AnnotationDialogField fNonNullAnnotationDialogField;
private AnnotationDialogField fNonNullByDefaultAnnotationDialogField;
private AnnotationListDialogField fOtherNullableAnnotationsDialogField;
private AnnotationListDialogField fOtherNonNullAnnotationsDialogField;
private AnnotationListDialogField fOtherNonNullByDefaultAnnotationsDialogField;
private NullAnnotationsConfigurationDialog() {
super(ProblemSeveritiesConfigurationBlock.this.getShell());
setTitle(PreferencesMessages.NullAnnotationsConfigurationDialog_title);
String errorMessage= PreferencesMessages.NullAnnotationsConfigurationDialog_nullable_annotation_error;
fNullableAnnotationDialogField= createAnnotationDialogField(PREF_NULLABLE_ANNOTATION_NAME, errorMessage);
fOtherNullableAnnotationsDialogField= createAnnotationListDialogField(PREF_NULLABLE_ANNOTATION_SECONDARY_NAMES, errorMessage);
errorMessage= PreferencesMessages.NullAnnotationsConfigurationDialog_nonnull_annotation_error;
fNonNullAnnotationDialogField= createAnnotationDialogField(PREF_NONNULL_ANNOTATION_NAME, errorMessage);
fOtherNonNullAnnotationsDialogField= createAnnotationListDialogField(PREF_NONNULL_ANNOTATION_SECONDARY_NAMES, errorMessage);
errorMessage= PreferencesMessages.NullAnnotationsConfigurationDialog_nonnullbydefault_annotation_error;
fNonNullByDefaultAnnotationDialogField= createAnnotationDialogField(PREF_NONNULL_BY_DEFAULT_ANNOTATION_NAME, errorMessage);
fOtherNonNullByDefaultAnnotationsDialogField= createAnnotationListDialogField(PREF_NONNULL_BY_DEFAULT_ANNOTATION_SECONDARY_NAMES, errorMessage);
}
private AnnotationDialogField createAnnotationDialogField(Key key, String errorMessage) {
AnnotationDialogField field= new AnnotationDialogField(errorMessage);
field.setLabelText(PreferencesMessages.NullAnnotationsConfigurationDialog_primary_label);
field.setText(getValue(key));
return field;
}
private AnnotationListDialogField createAnnotationListDialogField(Key key, String errorMessage) {
String[] buttons= new String[] { PreferencesMessages.NullAnnotationsConfigurationDialog_add_button };
AnnotationListLabelProvider annotationLabelProvider= new AnnotationListLabelProvider();
AnnotationListDialogField field= new AnnotationListDialogField(new AnnotationListAdapter(), buttons, annotationLabelProvider, errorMessage);
field.setLabelText(PreferencesMessages.NullAnnotationsConfigurationDialog_secondary_label);
field.setTableColumns(new ListDialogField.ColumnsDescription(1, false));
field.addElementsFromCommaSeparatedList(getValue(key));
annotationLabelProvider.setDialogField(field);
return field;
}
@Override
protected Control createDialogArea(Composite parent) {
Composite composite= (Composite) super.createDialogArea(parent);
initializeDialogUnits(parent);
GridLayout layout= (GridLayout) composite.getLayout();
layout.numColumns= 1;
int fieldWidthHint= convertWidthInCharsToPixels(90); // heuristic to match the default size of the dialog
Label intro= new Label(composite, SWT.WRAP);
intro.setText(PreferencesMessages.NullAnnotationsConfigurationDialog_null_annotations_description);
intro.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, layout.numColumns, 1));
LayoutUtil.setWidthHint(intro, fieldWidthHint);
String[] texts= { PreferencesMessages.NullAnnotationsConfigurationDialog_nullable_annotations_label,
PreferencesMessages.NullAnnotationsConfigurationDialog_nullable_annotations_description };
createNullAnnotationGroup(fNullableAnnotationDialogField, fOtherNullableAnnotationsDialogField, composite, texts, fieldWidthHint);
texts= new String[] { PreferencesMessages.NullAnnotationsConfigurationDialog_nonnull_annotations_label,
PreferencesMessages.NullAnnotationsConfigurationDialog_nonnull_annotations_description };
createNullAnnotationGroup(fNonNullAnnotationDialogField, fOtherNonNullAnnotationsDialogField, composite, texts, fieldWidthHint);
texts= new String[] { PreferencesMessages.NullAnnotationsConfigurationDialog_nonnullbydefault_annotations_label,
PreferencesMessages.NullAnnotationsConfigurationDialog_nonnullbydefault_annotations_description };
createNullAnnotationGroup(fNonNullByDefaultAnnotationDialogField, fOtherNonNullByDefaultAnnotationsDialogField, composite, texts, fieldWidthHint);
fNullableAnnotationDialogField.postSetFocusOnDialogField(parent.getDisplay());
applyDialogFont(composite);
return composite;
}
private void createNullAnnotationGroup(AnnotationDialogField primaryField, final AnnotationListDialogField secondaryList, Composite parent, String[] texts, int fieldWidthHint) {
Group group= createAnnotationGroup(primaryField, parent, texts, fieldWidthHint);
secondaryList.doFillIntoGrid(group, 3);
final TableViewer tableViewer= secondaryList.getTableViewer();
tableViewer.setColumnProperties(new String[] {COLUMN_ANNOTATION});
TableTextCellEditor cellEditor= new TableTextCellEditor(tableViewer, 0) {
@Override
protected Control createControl(Composite parent2) {
Control control= super.createControl(parent2);
BidiUtils.applyBidiProcessing(text, StructuredTextTypeHandlerFactory.JAVA);
return control;
}
@Override
protected void keyReleaseOccured(KeyEvent event) {
if (event.keyCode == SWT.F2 && event.stateMask == 0) {
tableViewer.refresh(); // ensure icon is updated on F2
}
super.keyReleaseOccured(event);
}
};
Text cellEditorText= cellEditor.getText();
TextFieldNavigationHandler.install(cellEditorText);
if (fProject != null) {
JavaTypeCompletionProcessor annotationCompletionProcessor= new JavaTypeCompletionProcessor(false, false, true);
annotationCompletionProcessor.setCompletionContextRequestor(new AnnotationCompletionContextRequestor());
SubjectControlContentAssistant contentAssistant= ControlContentAssistHelper.createJavaContentAssistant(annotationCompletionProcessor);
ContentAssistHandler.createHandlerForText(cellEditorText, contentAssistant);
cellEditor.setContentAssistant(contentAssistant);
}
tableViewer.setCellEditors(new CellEditor[] { cellEditor });
tableViewer.setCellModifier(new ICellModifier() {
@Override
public void modify(Object element, String property, Object value) {
if (element instanceof Item)
element= ((Item) element).getData();
AnnotationWrapper annotationWrapper= (AnnotationWrapper) element;
annotationWrapper.annotationName= ((String) value).trim();
secondaryList.elementChanged(annotationWrapper);
}
@Override
public Object getValue(Object element, String property) {
return ((AnnotationWrapper) element).annotationName;
}
@Override
public boolean canModify(Object element, String property) {
return true;
}
});
tableViewer.getTable().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.F2 && event.stateMask == 0) {
ISelection selection= tableViewer.getSelection();
if (! (selection instanceof IStructuredSelection))
return;
IStructuredSelection structuredSelection= (IStructuredSelection) selection;
if (!structuredSelection.isEmpty())
tableViewer.editElement(structuredSelection.getFirstElement(), 0);
}
}
});
}
@Override
protected AnnotationDialogField[] getPrimaryFields() {
return new AnnotationDialogField[] { fNullableAnnotationDialogField, fNonNullAnnotationDialogField, fNonNullByDefaultAnnotationDialogField };
}
@Override
protected IStatus doValidation(IAnnotationDialogField dialogField, AnnotationWrapper element, String newValue, boolean isTypeMandatory) {
IStatus fieldStatus= validateAnnotation(newValue, dialogField.getErrorMessage(), isTypeMandatory);
if (fieldStatus != null) {
dialogField.setStatus(element, fieldStatus);
// compute most severe among all known statuses, preferring fieldStatus then first-found if equal severities:
IStatus mostSevereStatus= StatusUtil.getMoreSevere(fNullableAnnotationDialogField.getStatus(), fieldStatus);
mostSevereStatus= StatusUtil.getMoreSevere(fNonNullAnnotationDialogField.getStatus(), mostSevereStatus);
mostSevereStatus= StatusUtil.getMoreSevere(fNonNullByDefaultAnnotationDialogField.getStatus(), mostSevereStatus);
mostSevereStatus= StatusUtil.getMoreSevere(fOtherNullableAnnotationsDialogField.getMostSevereStatus(), mostSevereStatus);
mostSevereStatus= StatusUtil.getMoreSevere(fOtherNonNullAnnotationsDialogField.getMostSevereStatus(), mostSevereStatus);
mostSevereStatus= StatusUtil.getMoreSevere(fOtherNonNullByDefaultAnnotationsDialogField.getMostSevereStatus(), mostSevereStatus);
updateStatus(mostSevereStatus);
return fieldStatus;
}
return new StatusInfo();
}
@Override
protected void buttonPressed(int buttonId) {
if (buttonId == RESTORE_DEFAULTS_BUTTON_ID) {
fNullableAnnotationDialogField.setText(NULL_ANNOTATIONS_DEFAULTS[0]);
fNonNullAnnotationDialogField.setText(NULL_ANNOTATIONS_DEFAULTS[1]);
fNonNullByDefaultAnnotationDialogField.setText(NULL_ANNOTATIONS_DEFAULTS[2]);
fOtherNullableAnnotationsDialogField.removeAllElements();
fOtherNonNullAnnotationsDialogField.removeAllElements();
fOtherNonNullByDefaultAnnotationsDialogField.removeAllElements();
} else {
super.buttonPressed(buttonId);
}
}
public String[] getResult() {
return new String[] {
fNullableAnnotationDialogField.getText(),
fNonNullAnnotationDialogField.getText(),
fNonNullByDefaultAnnotationDialogField.getText(),
fOtherNullableAnnotationsDialogField.getCommaSeparatedElements(),
fOtherNonNullAnnotationsDialogField.getCommaSeparatedElements(),
fOtherNonNullByDefaultAnnotationsDialogField.getCommaSeparatedElements()
};
}
}
class OwningAnnotationsConfigurationDialog extends AbstractAnnotationsConfigurationDialog {
private AnnotationDialogField fOwningAnnotationDialogField;
private AnnotationDialogField fNotOwningAnnotationDialogField;
private OwningAnnotationsConfigurationDialog() {
super(ProblemSeveritiesConfigurationBlock.this.getShell());
setTitle(PreferencesMessages.OwningAnnotationsConfigurationDialog_title);
String errorMessage= PreferencesMessages.OwningAnnotationsConfigurationDialog_owning_annotation_error;
fOwningAnnotationDialogField= createAnnotationDialogField(PREF_OWNING_ANNOTATION_NAME, errorMessage);
errorMessage= PreferencesMessages.OwningAnnotationsConfigurationDialog_notowning_annotation_error;
fNotOwningAnnotationDialogField= createAnnotationDialogField(PREF_NOTOWNING_ANNOTATION_NAME, errorMessage);
}
private AnnotationDialogField createAnnotationDialogField(Key key, String errorMessage) {
AnnotationDialogField field= new AnnotationDialogField(errorMessage);
field.setLabelText(PreferencesMessages.OwningAnnotationsConfigurationDialog_annotation_label);
field.setText(getValue(key));
return field;
}
@Override
protected Control createDialogArea(Composite parent) {
Composite composite= (Composite) super.createDialogArea(parent);
initializeDialogUnits(parent);
GridLayout layout= (GridLayout) composite.getLayout();
layout.numColumns= 1;
int fieldWidthHint= convertWidthInCharsToPixels(90); // heuristic to match the default size of the dialog
Label intro= new Label(composite, SWT.WRAP);
intro.setText(PreferencesMessages.OwningAnnotationsConfigurationDialog_owning_annotations_description);
intro.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, layout.numColumns, 1));
LayoutUtil.setWidthHint(intro, fieldWidthHint);
String[] texts= { PreferencesMessages.OwningAnnotationsConfigurationDialog_owning_annotation_label,
PreferencesMessages.OwningAnnotationsConfigurationDialog_owning_annotation_description };
createAnnotationGroup(fOwningAnnotationDialogField, composite, texts, fieldWidthHint);
texts= new String[] { PreferencesMessages.OwningAnnotationsConfigurationDialog_notowning_annotation_label,
PreferencesMessages.OwningAnnotationsConfigurationDialog_notowning_annotation_description };
createAnnotationGroup(fNotOwningAnnotationDialogField, composite, texts, fieldWidthHint);
fOwningAnnotationDialogField.postSetFocusOnDialogField(parent.getDisplay());
applyDialogFont(composite);
return composite;
}
@Override
protected AnnotationDialogField[] getPrimaryFields() {
return new AnnotationDialogField[] { fOwningAnnotationDialogField, fNotOwningAnnotationDialogField };
}
@Override
protected IStatus doValidation(IAnnotationDialogField dialogField, AnnotationWrapper element, String newValue, boolean isTypeMandatory) {
IStatus fieldStatus= validateAnnotation(newValue, dialogField.getErrorMessage(), isTypeMandatory);
if (fieldStatus != null) {
dialogField.setStatus(element, fieldStatus);
// compute most severe among all known statuses, preferring fieldStatus then first-found if equal severities:
IStatus mostSevereStatus= StatusUtil.getMoreSevere(fOwningAnnotationDialogField.getStatus(), fieldStatus);
mostSevereStatus= StatusUtil.getMoreSevere(fNotOwningAnnotationDialogField.getStatus(), mostSevereStatus);
updateStatus(mostSevereStatus);
return fieldStatus;
}
return new StatusInfo();
}
@Override
protected void buttonPressed(int buttonId) {
if (buttonId == RESTORE_DEFAULTS_BUTTON_ID) {
fOwningAnnotationDialogField.setText(OWNING_ANNOTATIONS_DEFAULTS[0]);
fNotOwningAnnotationDialogField.setText(OWNING_ANNOTATIONS_DEFAULTS[1]);
} else {
super.buttonPressed(buttonId);
}
}
public String[] getResult() {
return new String[] {
fOwningAnnotationDialogField.getText(),
fNotOwningAnnotationDialogField.getText(),
};
}
}
private static final String SETTINGS_SECTION_NAME= "ProblemSeveritiesConfigurationBlock"; //$NON-NLS-1$
// Preference store keys, see JavaCore.getOptions
private static final Key PREF_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD= getJDTCoreKey(JavaCore.COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD);
private static final Key PREF_PB_METHOD_WITH_CONSTRUCTOR_NAME= getJDTCoreKey(JavaCore.COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME);
private static final Key PREF_PB_DEPRECATION= getJDTCoreKey(JavaCore.COMPILER_PB_DEPRECATION);
private static final Key PREF_PB_DEPRECATION_IN_DEPRECATED_CODE=getJDTCoreKey(JavaCore.COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE);
private static final Key PREF_PB_DEPRECATION_WHEN_OVERRIDING= getJDTCoreKey(JavaCore.COMPILER_PB_DEPRECATION_WHEN_OVERRIDING_DEPRECATED_METHOD);
private static final Key PREF_PB_TERMINAL_DEPRECATION= getJDTCoreKey(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION);
private static final Key PREF_PB_API_LEAKS= getJDTCoreKey(JavaCore.COMPILER_PB_API_LEAKS);
private static final Key PREF_PB_UNSTABLE_AUTO_MODULE_NAME= getJDTCoreKey(JavaCore.COMPILER_PB_UNSTABLE_AUTO_MODULE_NAME);
private static final Key PREF_PB_HIDDEN_CATCH_BLOCK= getJDTCoreKey(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK);
private static final Key PREF_PB_UNUSED_LOCAL= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_LOCAL);
private static final Key PREF_PB_UNUSED_PARAMETER= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_PARAMETER);
private static final Key PREF_PB_UNUSED_EXCEPTION_PARAMETER= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_EXCEPTION_PARAMETER);
private static final Key PREF_PB_SIGNAL_PARAMETER_IN_OVERRIDING= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_PARAMETER_WHEN_OVERRIDING_CONCRETE);
private static final Key PREF_PB_UNUSED_PARAMETER_INCLUDE_DOC_COMMENT_REFERENCE= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_PARAMETER_INCLUDE_DOC_COMMENT_REFERENCE);
private static final Key PREF_PB_SIGNAL_PARAMETER_IN_ABSTRACT= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_PARAMETER_WHEN_IMPLEMENTING_ABSTRACT);
private static final Key PREF_PB_SYNTHETIC_ACCESS_EMULATION= getJDTCoreKey(JavaCore.COMPILER_PB_SYNTHETIC_ACCESS_EMULATION);
private static final Key PREF_PB_NON_EXTERNALIZED_STRINGS= getJDTCoreKey(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL);
private static final Key PREF_PB_UNUSED_IMPORT= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_IMPORT);
private static final Key PREF_PB_UNUSED_PRIVATE= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER);
private static final Key PREF_PB_UNUSED_TYPE_PARAMETER= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_TYPE_PARAMETER);
private static final Key PREF_PB_STATIC_ACCESS_RECEIVER= getJDTCoreKey(JavaCore.COMPILER_PB_STATIC_ACCESS_RECEIVER);
private static final Key PREF_PB_NO_EFFECT_ASSIGNMENT= getJDTCoreKey(JavaCore.COMPILER_PB_NO_EFFECT_ASSIGNMENT);
private static final Key PREF_PB_CHAR_ARRAY_IN_CONCAT= getJDTCoreKey(JavaCore.COMPILER_PB_CHAR_ARRAY_IN_STRING_CONCATENATION);
private static final Key PREF_PB_POSSIBLE_ACCIDENTAL_BOOLEAN_ASSIGNMENT= getJDTCoreKey(JavaCore.COMPILER_PB_POSSIBLE_ACCIDENTAL_BOOLEAN_ASSIGNMENT);
private static final Key PREF_PB_LOCAL_VARIABLE_HIDING= getJDTCoreKey(JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING);
private static final Key PREF_PB_FIELD_HIDING= getJDTCoreKey(JavaCore.COMPILER_PB_FIELD_HIDING);
private static final Key PREF_PB_SPECIAL_PARAMETER_HIDING_FIELD= getJDTCoreKey(JavaCore.COMPILER_PB_SPECIAL_PARAMETER_HIDING_FIELD);
private static final Key PREF_PB_INDIRECT_STATIC_ACCESS= getJDTCoreKey(JavaCore.COMPILER_PB_INDIRECT_STATIC_ACCESS);
private static final Key PREF_PB_EMPTY_STATEMENT= getJDTCoreKey(JavaCore.COMPILER_PB_EMPTY_STATEMENT);
private static final Key PREF_PB_UNNECESSARY_ELSE= getJDTCoreKey(JavaCore.COMPILER_PB_UNNECESSARY_ELSE);
private static final Key PREF_PB_UNNECESSARY_TYPE_CHECK= getJDTCoreKey(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK);
private static final Key PREF_PB_INCOMPATIBLE_INTERFACE_METHOD= getJDTCoreKey(JavaCore.COMPILER_PB_INCOMPATIBLE_NON_INHERITED_INTERFACE_METHOD);
private static final Key PREF_PB_UNUSED_DECLARED_THROWN_EXCEPTION= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION);
private static final Key PREF_PB_UNUSED_DECLARED_THROWN_EXCEPTION_WHEN_OVERRIDING= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_WHEN_OVERRIDING);
private static final Key PREF_PB_UNUSED_DECLARED_THROWN_EXCEPTION_INCLUDE_DOC_COMMENT_REFERENCE= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_INCLUDE_DOC_COMMENT_REFERENCE);
private static final Key PREF_PB_UNUSED_DECLARED_THROWN_EXCEPTION_EXEMPT_EXCEPTION_AND_THROWABLE= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_EXEMPT_EXCEPTION_AND_THROWABLE);
private static final Key PREF_PB_MISSING_SERIAL_VERSION= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_SERIAL_VERSION);
private static final Key PREF_PB_UNDOCUMENTED_EMPTY_BLOCK= getJDTCoreKey(JavaCore.COMPILER_PB_UNDOCUMENTED_EMPTY_BLOCK);
private static final Key PREF_PB_FINALLY_BLOCK_NOT_COMPLETING= getJDTCoreKey(JavaCore.COMPILER_PB_FINALLY_BLOCK_NOT_COMPLETING);
private static final Key PREF_PB_UNQUALIFIED_FIELD_ACCESS= getJDTCoreKey(JavaCore.COMPILER_PB_UNQUALIFIED_FIELD_ACCESS);
private static final Key PREF_PB_MISSING_DEPRECATED_ANNOTATION= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_DEPRECATED_ANNOTATION);
private static final Key PREF_PB_FORBIDDEN_REFERENCE= getJDTCoreKey(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE);
private static final Key PREF_PB_DISCOURRAGED_REFERENCE= getJDTCoreKey(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE);
private static final Key PREF_PB_UNUSED_LABEL= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_LABEL);
private static final Key PREF_PB_PARAMETER_ASSIGNMENT= getJDTCoreKey(JavaCore.COMPILER_PB_PARAMETER_ASSIGNMENT);
private static final Key PREF_PB_FALLTHROUGH_CASE= getJDTCoreKey(JavaCore.COMPILER_PB_FALLTHROUGH_CASE);
private static final Key PREF_PB_COMPARING_IDENTICAL= getJDTCoreKey(JavaCore.COMPILER_PB_COMPARING_IDENTICAL);
private static final Key PREF_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD);
private static final Key PREF_PB_NULL_REFERENCE= getJDTCoreKey(JavaCore.COMPILER_PB_NULL_REFERENCE);
private static final Key PREF_PB_POTENTIAL_NULL_REFERENCE= getJDTCoreKey(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE);
private static final Key PREF_ANNOTATION_NULL_ANALYSIS= getJDTCoreKey(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS);
private static final Key PREF_PB_SYNTACTIC_NULL_ANLYSIS_FOR_FIELDS= getJDTCoreKey(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS);
private static final Key PREF_INHERIT_NULL_ANNOTATIONS= getJDTCoreKey(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS);
private static final Key PREF_EXTERNAL_ANNOTATIONS_FROM_ALL_LOCATIONS= getJDTCoreKey(JavaCore.CORE_JAVA_BUILD_EXTERNAL_ANNOTATIONS_FROM_ALL_LOCATIONS);
/**
* Key for the "Use default annotations for null " setting.
* <p>Values are { {@link #ENABLED}, {@link #DISABLED} }.
*/
private static final Key INTR_DEFAULT_NULL_ANNOTATIONS= getLocalKey("internal.default.null.annotations"); //$NON-NLS-1$
private static final Key PREF_NULLABLE_ANNOTATION_NAME= getJDTCoreKey(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME);
private static final Key PREF_NONNULL_ANNOTATION_NAME= getJDTCoreKey(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME);
private static final Key PREF_NONNULL_BY_DEFAULT_ANNOTATION_NAME= getJDTCoreKey(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME);
private static final Key PREF_NULLABLE_ANNOTATION_SECONDARY_NAMES= getJDTCoreKey(JavaCore.COMPILER_NULLABLE_ANNOTATION_SECONDARY_NAMES);
private static final Key PREF_NONNULL_ANNOTATION_SECONDARY_NAMES= getJDTCoreKey(JavaCore.COMPILER_NONNULL_ANNOTATION_SECONDARY_NAMES);
private static final Key PREF_NONNULL_BY_DEFAULT_ANNOTATION_SECONDARY_NAMES= getJDTCoreKey(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_SECONDARY_NAMES);
private static final String[] NULL_ANNOTATIONS_DEFAULTS= {
PREF_NULLABLE_ANNOTATION_NAME.getStoredValue(DefaultScope.INSTANCE, null),
PREF_NONNULL_ANNOTATION_NAME.getStoredValue(DefaultScope.INSTANCE, null),
PREF_NONNULL_BY_DEFAULT_ANNOTATION_NAME.getStoredValue(DefaultScope.INSTANCE, null),
};
private static final Key PREF_MISSING_NONNULL_BY_DEFAULT_ANNOTATION= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION);
private static final Key PREF_PB_NULL_SPECIFICATION_VIOLATION= getJDTCoreKey(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION);
private static final Key PREF_PB_POTENTIAL_NULL_ANNOTATION_INFERENCE_CONFLICT= getJDTCoreKey(JavaCore.COMPILER_PB_NULL_ANNOTATION_INFERENCE_CONFLICT);
private static final Key PREF_PB_NULL_UNCHECKED_CONVERSION= getJDTCoreKey(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION);
private static final Key PREF_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED= getJDTCoreKey(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED);
private static final Key PREF_PB_PESSIMISTIC_NULL_ANALYSIS_FOR_FREE_TYPE_VARIABLES= getJDTCoreKey(JavaCore.COMPILER_PB_PESSIMISTIC_NULL_ANALYSIS_FOR_FREE_TYPE_VARIABLES);
private static final Key PREF_PB_NONNULL_TYPEVAR_FROM_LEGACY_INVOCATION= getJDTCoreKey(JavaCore.COMPILER_PB_NONNULL_TYPEVAR_FROM_LEGACY_INVOCATION);
private static final Key PREF_PB_REDUNDANT_NULL_ANNOTATION= getJDTCoreKey(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION);
private static final Key PREF_PB_NONNULL_PARAMETER_ANNOTATION_DROPPED= getJDTCoreKey(JavaCore.COMPILER_PB_NONNULL_PARAMETER_ANNOTATION_DROPPED);
private static final Key PREF_PB_REDUNDANT_NULL_CHECK= getJDTCoreKey(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK);
private static final Key PREF_PB_UNCLOSED_CLOSEABLE= getJDTCoreKey(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE);
private static final Key PREF_PB_POTENTIALLY_UNCLOSED_CLOSEABLE= getJDTCoreKey(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE);
private static final Key PREF_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE= getJDTCoreKey(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE);
private static final Key PREF_ANNOTATION_RESOURCE_ANALYSIS = getJDTCoreKey(JavaCore.COMPILER_ANNOTATION_RESOURCE_ANALYSIS);
private static final Key PREF_PB_INCOMPATIBLE_OWNING_CONTRACT = getJDTCoreKey(JavaCore.COMPILER_PB_INCOMPATIBLE_OWNING_CONTRACT);
private static final Key PREF_PB_RECOMMENDED_RESOURCE_MANAGEMENT = getJDTCoreKey(JavaCore.COMPILER_PB_RECOMMENDED_RESOURCE_MANAGEMENT);
/**
* Key for the "Use default annotations for ownership " setting.
* <p>Values are { {@link #ENABLED}, {@link #DISABLED} }.
*/
private static final Key INTR_DEFAULT_OWNING_ANNOTATIONS= getLocalKey("internal.default.owning.annotations"); //$NON-NLS-1$
private static final Key PREF_OWNING_ANNOTATION_NAME= getJDTCoreKey(JavaCore.COMPILER_OWNING_ANNOTATION_NAME);
private static final Key PREF_NOTOWNING_ANNOTATION_NAME= getJDTCoreKey(JavaCore.COMPILER_NOTOWNING_ANNOTATION_NAME);
private static final String[] OWNING_ANNOTATIONS_DEFAULTS= {
PREF_OWNING_ANNOTATION_NAME.getStoredValue(DefaultScope.INSTANCE, null),
PREF_NOTOWNING_ANNOTATION_NAME.getStoredValue(DefaultScope.INSTANCE, null),
};
private static final Key PREF_PB_INCLUDE_ASSERTS_IN_NULL_ANALYSIS= getJDTCoreKey(JavaCore.COMPILER_PB_INCLUDE_ASSERTS_IN_NULL_ANALYSIS);
private static final Key PREF_PB_REDUNDANT_SUPERINTERFACE= getJDTCoreKey(JavaCore.COMPILER_PB_REDUNDANT_SUPERINTERFACE);
private static final Key PREF_PB_UNUSED_WARNING_TOKEN= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_WARNING_TOKEN);
private static final Key PREF_PB_SUPPRESS_WARNINGS_NOT_FULLY_ANALYSED= getJDTCoreKey(JavaCore.COMPILER_PB_SUPPRESS_WARNINGS_NOT_FULLY_ANALYSED);
private static final Key PREF_15_PB_UNCHECKED_TYPE_OPERATION= getJDTCoreKey(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION);
private static final Key PREF_15_PB_FINAL_PARAM_BOUND= getJDTCoreKey(JavaCore.COMPILER_PB_FINAL_PARAMETER_BOUND);
private static final Key PREF_15_PB_VARARGS_ARGUMENT_NEED_CAST= getJDTCoreKey(JavaCore.COMPILER_PB_VARARGS_ARGUMENT_NEED_CAST);
private static final Key PREF_15_PB_UNLIKELY_COLLECTION_METHOD_ARGUMENT_TYPE= getJDTCoreKey(JavaCore.COMPILER_PB_UNLIKELY_COLLECTION_METHOD_ARGUMENT_TYPE);
private static final Key PREF_15_PB_UNLIKELY_COLLECTION_METHOD_ARGUMENT_TYPE_STRICT= getJDTCoreKey(JavaCore.COMPILER_PB_UNLIKELY_COLLECTION_METHOD_ARGUMENT_TYPE_STRICT);
private static final Key PREF_15_PB_UNLIKELY_EQUALS_ARGUMENT_TYPE= getJDTCoreKey(JavaCore.COMPILER_PB_UNLIKELY_EQUALS_ARGUMENT_TYPE);
private static final Key PREF_15_PB_AUTOBOXING_PROBLEM= getJDTCoreKey(JavaCore.COMPILER_PB_AUTOBOXING);
private static final Key PREF_15_PB_MISSING_OVERRIDE_ANNOTATION= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION);
private static final Key PREF_16_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION);
private static final Key PREF_15_PB_ANNOTATION_SUPER_INTERFACE= getJDTCoreKey(JavaCore.COMPILER_PB_ANNOTATION_SUPER_INTERFACE);
private static final Key PREF_15_PB_TYPE_PARAMETER_HIDING= getJDTCoreKey(JavaCore.COMPILER_PB_TYPE_PARAMETER_HIDING);
private static final Key PREF_15_PB_INCOMPLETE_ENUM_SWITCH= getJDTCoreKey(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH);
private static final Key PREF_15_PB_MISSING_ENUM_CASE_DESPITE_DEFAULT= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_ENUM_CASE_DESPITE_DEFAULT);
private static final Key PREF_15_PB_SWITCH_MISSING_DEFAULT_CASE= getJDTCoreKey(JavaCore.COMPILER_PB_SWITCH_MISSING_DEFAULT_CASE);
private static final Key PREF_15_PB_RAW_TYPE_REFERENCE= getJDTCoreKey(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE);
private static final Key PREF_17_PB_REDUNDANT_TYPE_ARGUMENTS= getJDTCoreKey(JavaCore.COMPILER_PB_REDUNDANT_TYPE_ARGUMENTS);
private static final Key PREF_15_PB_UNAVOIDABLE_GENERIC_TYPE_PROBLEMS= getJDTCoreKey(JavaCore.COMPILER_PB_UNAVOIDABLE_GENERIC_TYPE_PROBLEMS);
private static final Key PREF_PB_SUPPRESS_WARNINGS= getJDTCoreKey(JavaCore.COMPILER_PB_SUPPRESS_WARNINGS);
private static final Key PREF_PB_SUPPRESS_OPTIONAL_ERRORS= getJDTCoreKey(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS);
private static final Key PREF_PB_UNHANDLED_WARNING_TOKEN= getJDTCoreKey(JavaCore.COMPILER_PB_UNHANDLED_WARNING_TOKEN);
private static final Key PREF_PB_FATAL_OPTIONAL_ERROR= getJDTCoreKey(JavaCore.COMPILER_PB_FATAL_OPTIONAL_ERROR);
private static final Key PREF_PB_MISSING_HASHCODE_METHOD= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_HASHCODE_METHOD);
private static final Key PREF_PB_DEAD_CODE= getJDTCoreKey(JavaCore.COMPILER_PB_DEAD_CODE);
private static final Key PREF_PB_UNUSED_OBJECT_ALLOCATION= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_OBJECT_ALLOCATION);
private static final Key PREF_PB_MISSING_STATIC_ON_METHOD= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_STATIC_ON_METHOD);
private static final Key PREF_PB_POTENTIALLY_MISSING_STATIC_ON_METHOD= getJDTCoreKey(JavaCore.COMPILER_PB_POTENTIALLY_MISSING_STATIC_ON_METHOD);
// values
private static final String ERROR= JavaCore.ERROR;
private static final String WARNING= JavaCore.WARNING;
private static final String INFO= JavaCore.INFO;
private static final String IGNORE= JavaCore.IGNORE;
private static final String ENABLED= JavaCore.ENABLED;
private static final String DISABLED= JavaCore.DISABLED;
private PixelConverter fPixelConverter;
private PreferenceTree fFilteredPrefTree;
public ProblemSeveritiesConfigurationBlock(IStatusChangeListener context, IProject project, IWorkbenchPreferenceContainer container) {
super(context, project, getKeys(), container);
// Compatibility code for the merge of the two option PB_SIGNAL_PARAMETER:
if (ENABLED.equals(getValue(PREF_PB_SIGNAL_PARAMETER_IN_ABSTRACT))) {
setValue(PREF_PB_SIGNAL_PARAMETER_IN_OVERRIDING, ENABLED);
}
}
public static Key[] getKeys() {
return new Key[] {
PREF_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD,
PREF_PB_METHOD_WITH_CONSTRUCTOR_NAME, PREF_PB_DEPRECATION, PREF_PB_TERMINAL_DEPRECATION, PREF_PB_HIDDEN_CATCH_BLOCK, PREF_PB_UNUSED_LOCAL,
PREF_PB_API_LEAKS,
PREF_PB_UNSTABLE_AUTO_MODULE_NAME,
PREF_PB_UNUSED_PARAMETER, PREF_PB_UNUSED_EXCEPTION_PARAMETER, PREF_PB_UNUSED_PARAMETER_INCLUDE_DOC_COMMENT_REFERENCE,
PREF_PB_SYNTHETIC_ACCESS_EMULATION, PREF_PB_NON_EXTERNALIZED_STRINGS,
PREF_PB_UNUSED_IMPORT, PREF_PB_UNUSED_LABEL,
PREF_PB_STATIC_ACCESS_RECEIVER, PREF_PB_DEPRECATION_IN_DEPRECATED_CODE,
PREF_PB_NO_EFFECT_ASSIGNMENT, PREF_PB_INCOMPATIBLE_INTERFACE_METHOD,
PREF_PB_UNUSED_PRIVATE, PREF_PB_UNUSED_TYPE_PARAMETER, PREF_PB_CHAR_ARRAY_IN_CONCAT, PREF_PB_UNNECESSARY_ELSE,
PREF_PB_POSSIBLE_ACCIDENTAL_BOOLEAN_ASSIGNMENT, PREF_PB_LOCAL_VARIABLE_HIDING, PREF_PB_FIELD_HIDING,
PREF_PB_SPECIAL_PARAMETER_HIDING_FIELD, PREF_PB_INDIRECT_STATIC_ACCESS,
PREF_PB_EMPTY_STATEMENT, PREF_PB_SIGNAL_PARAMETER_IN_OVERRIDING, PREF_PB_SIGNAL_PARAMETER_IN_ABSTRACT,
PREF_PB_UNNECESSARY_TYPE_CHECK, PREF_PB_UNUSED_DECLARED_THROWN_EXCEPTION, PREF_PB_UNQUALIFIED_FIELD_ACCESS,
PREF_PB_UNDOCUMENTED_EMPTY_BLOCK, PREF_PB_FINALLY_BLOCK_NOT_COMPLETING, PREF_PB_DEPRECATION_WHEN_OVERRIDING,
PREF_PB_UNUSED_DECLARED_THROWN_EXCEPTION_WHEN_OVERRIDING, PREF_PB_UNUSED_DECLARED_THROWN_EXCEPTION_INCLUDE_DOC_COMMENT_REFERENCE,
PREF_PB_UNUSED_DECLARED_THROWN_EXCEPTION_EXEMPT_EXCEPTION_AND_THROWABLE,
PREF_PB_MISSING_SERIAL_VERSION, PREF_PB_PARAMETER_ASSIGNMENT,
PREF_PB_NULL_REFERENCE, PREF_PB_POTENTIAL_NULL_REFERENCE,
PREF_ANNOTATION_NULL_ANALYSIS,
INTR_DEFAULT_NULL_ANNOTATIONS,
PREF_NULLABLE_ANNOTATION_NAME,
PREF_NULLABLE_ANNOTATION_SECONDARY_NAMES,
PREF_NONNULL_ANNOTATION_NAME,
PREF_NONNULL_ANNOTATION_SECONDARY_NAMES,
PREF_NONNULL_BY_DEFAULT_ANNOTATION_NAME,
PREF_NONNULL_BY_DEFAULT_ANNOTATION_SECONDARY_NAMES,
PREF_MISSING_NONNULL_BY_DEFAULT_ANNOTATION,
PREF_PB_NULL_SPECIFICATION_VIOLATION,
PREF_PB_POTENTIAL_NULL_ANNOTATION_INFERENCE_CONFLICT,
PREF_PB_NULL_UNCHECKED_CONVERSION,
PREF_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED,
PREF_PB_PESSIMISTIC_NULL_ANALYSIS_FOR_FREE_TYPE_VARIABLES,
PREF_PB_NONNULL_TYPEVAR_FROM_LEGACY_INVOCATION,
PREF_PB_REDUNDANT_NULL_ANNOTATION,
PREF_PB_NONNULL_PARAMETER_ANNOTATION_DROPPED,
PREF_PB_REDUNDANT_NULL_CHECK, PREF_PB_INCLUDE_ASSERTS_IN_NULL_ANALYSIS,
PREF_PB_SYNTACTIC_NULL_ANLYSIS_FOR_FIELDS,
PREF_INHERIT_NULL_ANNOTATIONS,
PREF_EXTERNAL_ANNOTATIONS_FROM_ALL_LOCATIONS,
PREF_PB_UNCLOSED_CLOSEABLE, PREF_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, PREF_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE,
PREF_ANNOTATION_RESOURCE_ANALYSIS, PREF_PB_INCOMPATIBLE_OWNING_CONTRACT, PREF_PB_RECOMMENDED_RESOURCE_MANAGEMENT,
INTR_DEFAULT_OWNING_ANNOTATIONS, PREF_OWNING_ANNOTATION_NAME, PREF_NOTOWNING_ANNOTATION_NAME,
PREF_PB_FALLTHROUGH_CASE, PREF_PB_REDUNDANT_SUPERINTERFACE, PREF_PB_UNUSED_WARNING_TOKEN, PREF_PB_SUPPRESS_WARNINGS_NOT_FULLY_ANALYSED,
PREF_15_PB_UNCHECKED_TYPE_OPERATION, PREF_15_PB_FINAL_PARAM_BOUND, PREF_15_PB_VARARGS_ARGUMENT_NEED_CAST,
PREF_15_PB_AUTOBOXING_PROBLEM, PREF_15_PB_MISSING_OVERRIDE_ANNOTATION, PREF_16_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION,
PREF_15_PB_ANNOTATION_SUPER_INTERFACE,
PREF_15_PB_TYPE_PARAMETER_HIDING,
PREF_15_PB_INCOMPLETE_ENUM_SWITCH, PREF_15_PB_MISSING_ENUM_CASE_DESPITE_DEFAULT, PREF_15_PB_SWITCH_MISSING_DEFAULT_CASE,
PREF_PB_MISSING_DEPRECATED_ANNOTATION,
PREF_15_PB_RAW_TYPE_REFERENCE, PREF_15_PB_UNAVOIDABLE_GENERIC_TYPE_PROBLEMS, PREF_17_PB_REDUNDANT_TYPE_ARGUMENTS,
PREF_PB_FATAL_OPTIONAL_ERROR,
PREF_PB_FORBIDDEN_REFERENCE, PREF_PB_DISCOURRAGED_REFERENCE,
PREF_PB_SUPPRESS_WARNINGS, PREF_PB_SUPPRESS_OPTIONAL_ERRORS,
PREF_PB_UNHANDLED_WARNING_TOKEN,
PREF_PB_COMPARING_IDENTICAL, PREF_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD, PREF_PB_MISSING_HASHCODE_METHOD,
PREF_PB_DEAD_CODE, PREF_PB_UNUSED_OBJECT_ALLOCATION,
PREF_PB_MISSING_STATIC_ON_METHOD, PREF_PB_POTENTIALLY_MISSING_STATIC_ON_METHOD,
PREF_15_PB_UNLIKELY_COLLECTION_METHOD_ARGUMENT_TYPE,
PREF_15_PB_UNLIKELY_COLLECTION_METHOD_ARGUMENT_TYPE_STRICT,
PREF_15_PB_UNLIKELY_EQUALS_ARGUMENT_TYPE
};
}
/*
* @see org.eclipse.jface.preference.PreferencePage#createContents(Composite)
*/
@Override
protected Control createContents(Composite parent) {
fPixelConverter= new PixelConverter(parent);
setShell(parent.getShell());
Composite mainComp= new Composite(parent, SWT.NONE);
mainComp.setFont(parent.getFont());
GridLayout layout= new GridLayout();
layout.marginHeight= 0;
layout.marginWidth= 0;
mainComp.setLayout(layout);
createIgnoreOptionalProblemsLink(mainComp);
Composite spacer= new Composite(mainComp, SWT.NONE);
spacer.setLayoutData(new GridData(0, 0));
Composite commonComposite= createStyleTabContent(mainComp);
GridData gridData= new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.heightHint= fPixelConverter.convertHeightInCharsToPixels(30);
commonComposite.setLayoutData(gridData);
validateSettings(null, null, null);
return mainComp;
}
private Composite createStyleTabContent(Composite folder) {
String[] errorWarningInfoIgnore= new String[] { ERROR, WARNING, INFO, IGNORE };
String[] errorWarningInfoIgnoreLabels= new String[] {
PreferencesMessages.ProblemSeveritiesConfigurationBlock_error,
PreferencesMessages.ProblemSeveritiesConfigurationBlock_warning,
PreferencesMessages.ProblemSeveritiesConfigurationBlock_info,
PreferencesMessages.ProblemSeveritiesConfigurationBlock_ignore
};
String[] errorWarning= new String[] { ERROR, WARNING };
String[] errorWarningLabels= new String[] {
PreferencesMessages.ProblemSeveritiesConfigurationBlock_error,
PreferencesMessages.ProblemSeveritiesConfigurationBlock_warning
};
String[] enabledDisabled= new String[] { ENABLED, DISABLED };
String[] disabledEnabled= new String[] { DISABLED, ENABLED };
fFilteredPrefTree= new PreferenceTree(this, folder, PreferencesMessages.ProblemSeveritiesConfigurationBlock_common_description);
final ScrolledPageContent sc1= fFilteredPrefTree.getScrolledPageContent();
int nColumns= 3;
Composite composite= sc1.getBody();
GridLayout layout= new GridLayout(nColumns, false);
layout.marginHeight= 0;
layout.marginWidth= 0;
composite.setLayout(layout);
final int defaultIndent= 0;
final int extraIndent= LayoutUtil.getIndent();
String label;
ExpandableComposite excomposite;
Composite inner;
PreferenceTreeNode<?> section;
PreferenceTreeNode<?> node;
Key twistieKey;
// --- style
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_section_code_style;
twistieKey= OptionsConfigurationBlock.getLocalKey("ProblemSeveritiesConfigurationBlock_section_code_style"); //$NON-NLS-1$
section= fFilteredPrefTree.addExpandableComposite(composite, label, nColumns, twistieKey, null, false);
excomposite= getExpandableComposite(twistieKey);
inner= createInnerComposite(excomposite, nColumns, composite.getFont());
// - expression level
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_static_access_receiver_label;
fFilteredPrefTree.addComboBox(inner, label, PREF_PB_STATIC_ACCESS_RECEIVER, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_indirect_access_to_static_label;
fFilteredPrefTree.addComboBox(inner, label, PREF_PB_INDIRECT_STATIC_ACCESS, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unqualified_field_access_label;
fFilteredPrefTree.addComboBox(inner, label, PREF_PB_UNQUALIFIED_FIELD_ACCESS, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_synth_access_emul_label;
fFilteredPrefTree.addComboBox(inner, label, PREF_PB_SYNTHETIC_ACCESS_EMULATION, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);
label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_parameter_assignment;
fFilteredPrefTree.addComboBox(inner, label, PREF_PB_PARAMETER_ASSIGNMENT, errorWarningInfoIgnore, errorWarningInfoIgnoreLabels, defaultIndent, section);