-
Notifications
You must be signed in to change notification settings - Fork 66
/
jdt_tips.html
2724 lines (2603 loc) · 145 KB
/
jdt_tips.html
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2020. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="STYLESHEET" href="../book.css" charset="ISO-8859-1" type="text/css">
<style type="text/css">
ul {padding-left: 1.2em; margin-left: 1.2em;}
</style>
<title>Tips and Tricks (JDT)</title>
<script language="JavaScript" type="text/javascript" src="PLUGINS_ROOT/org.eclipse.help/livehelp.js"> </script>
</head>
<body>
<h2>Tips and Tricks (JDT)</h2>
<p>
The following tips and tricks give some helpful ideas for increasing your productivity.
See also <a href="../../org.eclipse.platform.doc.user/tips/platform_tips.html">Platform Tips and Tricks</a>
for general Eclipse tips and <a href="../../org.eclipse.jdt.doc.user/whatsNew/jdt_whatsnew.html">What's New (JDT)</a> for
features in this release.
</p>
<br>
<p>
<a href="#editing_section">Editing</a> |
<a href="#refactor_section">Refactoring</a> |
<a href="#searching_section">Searching</a> |
<a href="#navigation_section">Navigation</a> |
<a href="#views_section">Views</a> |
<a href="#misc_section">Miscellaneous</a> |
<a href="#debugging_section">Debugging</a>
</p>
<br>
<h3><a name="editing_section"></a>Editing source</h3>
<table border="1" cellpadding="10" cellspacing="0" summary="Editing source tips and tricks">
<tbody>
<tr>
<td width="20%" valign="top" align="left"><b>Content assist</b></td>
<td valign="top" align="left" width="80%">Content assist provides you
with a list of suggested completions for partially entered strings.
In the Java editor press <b>Ctrl+Space</b> or use <b>Edit >
Content Assist</b>.
<p><img src="images/code-assist.png" border="0" alt="Content assist selection dialog">
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Content assist in
Javadoc comments</b></td>
<td valign="top" align="left" width="80%">Content assist is also
available in Javadoc comments.
<p><img src="images/code-assist-javadoc2.png" border="0" alt="Content assist for Javadoc comments"></p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Content assist for static imports</b></td>
<td valign="top" align="left" width="80%">To get content assist proposals for static members
configure your list of favorite static members on the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeAssistPreferenceFavorites)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the Favorites preference page">
<b>Java > Editor > Content Assist > Favorites</b></a> preference page.
<p>For example, if you have added <code>java.util.Arrays.*</code> to
this list, then all static methods of this type matching the completion
prefix will be added to the proposals list:</p>
<p><img src="images/content-assist-proposals.png" alt="Content Assist proposals"></p></td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Suppress types in content
assist</b></td>
<td valign="top" align="left" width="80%">
To exclude certain types from appearing in content assist, use the type
filter feature configured on the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.TypeFilterPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the type filter preference page">
<b>Java > Appearance > Type Filters</b></a>
preference page. Types matching one of these filter patterns
will not appear in the Open Type dialog and will not be available to
content assist, quick fix and organize imports. These filter patterns
do not affect the Package Explorer and Type Hierarchy views.
<p><img border="0" src="images/type-filter.png" alt="Type filter preference page"></p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Content assist for
variable, method parameter and field name completions</b></td>
<td valign="top" align="left" width="80%">
You can use content assist to speed up the creation of fields, method
parameters and local variables. With the cursor positioned after the
type name of the declaration, press <b>Ctrl+Space</b> or use <b>Edit > Content Assist</b>.
<p><img src="images/code-assist-fieldname.png" alt="Suggestions for field names"></p>
<p>If you use a name prefix or suffix for fields, local variables or
method parameters, be sure to specify this in the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeStylePreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the code style preference page">
<b>Java > Code Style</b></a>
preference page.</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Content assist for variable with unresolved type</b>
</td>
<td valign="top" align="left" width="80%">Code assist also works on accesses to
types that are not imported yet. Depending on the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeAssistPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the Content Assist preference page">
<b>Java > Editor > Content Assist </b></a>
<b>> Add import instead of qualified name</b> preference the editor
will either automatically add imports or fully qualify the types for such
proposals.
<p>Pressing <b>;</b> in the following scenario:</p>
<p>
<img title="Content Assist For Variables With Unresolved Types" alt="Screenshot showing Content Assist for variables with unresolved types" src="images/code-assist-with-import.png">
</p>
<p>results in:</p>
<p>
<img title="Content Assist Result When Pressing ';'" alt="Screenshot showing the content assist result when pressing ';'" src="images/code-assist-with-import-result.png">
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Content assist after instanceof condition</b></td>
<td valign="top" align="left" width="80%">Content assist can propose members
available on types used in instanceof conditions.
<p>
<img title="Content Assist After instanceof Condition" alt="Screenshot showing Content Assist after instanceof condition" src="images/instanceof-compl-proposals.png">
</p>
<p>
Eclipse will add the required cast for you when you select such a proposal.
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Parameter hints</b></td>
<td valign="top" align="left" width="80%">With the cursor in a method
argument, you can see a list of parameter hints. In the Java Editor
press <b>Ctrl+Shift+Space</b> or invoke <b>Edit > Content Assist > Parameter Hints</b>.
<p><img src="images/parameter-hints.png" border="0" alt="Parameter hint hover"></p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Content assist on
anonymous classes</b></td>
<td valign="top" align="left" width="80%">Content assist also
provides help when creating an anonymous class. With the cursor
positioned after "new " and the beginning of an abstract class or interface name
press <b>Ctrl+Space</b> or invoke <b>Edit > Content Assist > Default</b>.
<p><img src="images/code-assist-anonym1.png" border="0" alt="Content assist for an anonymous class"></p>
This will create the body of the anonymous inner class including all
methods that need to be implemented.
<p>This also works if you place the caret after the opening parentheses of a class instance creation:</p>
<p><img src="images/code-assist-anonym2.png" border="0" alt="Content assist for an anonymous class"></p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Toggle between
inserting and replacing content assist</b></td>
<td valign="top" align="left" width="80%">When content assist is invoked
on an existing identifier, it can either replace the
identifier with the chosen completion or do an insert. The
default behavior (overwrite or insert) is defined in the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeAssistPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the content assist preference page">
<b>Java > Editor > Content Assist</b></a> preference page.<br>
You can temporarily toggle the behavior while inside the content
assist selection dialog by pressing and holding the <b>Ctrl</b> key while
selecting the completion.</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Incremental content assist</b></td>
<td valign="top" align="left" width="80%">Content assist can also <b>Insert common prefixes automatically</b>, similar to
Unix shell expansion. To enable that behavior, select the check box on the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeAssistPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the content assist preference page">
<b>Java > Editor > Content Assist</b></a> preference page.
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Camel case support in code completion</b>
</td>
<td valign="top" align="left" width="80%">Code completion supports camel case patterns.
For example, completing on <tt>NPE</tt> or <tt>NuPoiE</tt> will propose <tt>NullPointerException</tt>.
This support can be disabled using the <b>Show camel case matches</b>
preference on the <a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeAssistPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the Content Assist preference page">
<b>Java > Editor > Content Assist</b></a> preference page.
<p><img alt="Java editor completing on NPE" src="images/completiononcamelcase.png">
</p></td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><img src="images/new.png" alt=""><b>Subword code completion</b>
</td>
<td valign="top" align="left" width="80%">
Content assist supports substring patterns by default. Enter any part of the desired proposal's text, and Content Assist will find it!
For example, completing on <code>selection</code> proposes all results containing <code>selection</code> as a substring.
<p>
<img src="images/substring-code-completion.png" alt="Popup with proposals like addSelectionListener(..), getSelection(), etc.">
</p>
<p>This feature can be disabled using the <b>VM property: -Djdt.codeCompleteSubstringMatch=false</b>.</p>
<p>
Subword patterns are also supported. For example, completing on <code>addmouselistener</code> proposes results like
<code><b>addMouse</b>Move<b>Listener</b></code> and <code><b>addMouse</b>Wheel<b>Listener</b></code>:
</p>
<p>
<img src="images/subword-code-completion.png" alt="Popup with subword content assist proposals">
</p>
<p>
This feature can be disabled using the <b>Show subword matches</b> option on the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeAssistPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the Content Assist preference page">
<b>Java > Editor > Content Assist</b></a> preference page.
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Use ';' key to insert method invocation</b>
</td>
<td valign="top" align="left" width="80%">
You can use the semicolon (<b>;</b>) key to select any method invocation proposal from the content assist popup.
The '<code>;</code>' will be appended at the end of the method invocation.
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Customize content assist categories</b>
</td>
<td valign="top" align="left" width="80%">
Repeatedly invoking content assist <b>(Ctrl+Space)</b> cycles through different proposal
categories.
<p>
<img src="images/content_assist_participant.png" border="0" alt="Content assist with new method template proposals">
</p>
To configure which categories to show use the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeAssistPreferenceAdvanced)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the content assist preference page">
<b>Java > Editor > Content Assist > Advanced</b></a> preference page.
<p>
You can also assign separate key shortcuts to your favorite proposal categories.
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Create getters and
setters</b></td>
<td valign="top" align="left" width="80%">To create getter and setter
methods for a field, select the field's declaration and invoke <b>Source
> Generate Getter and Setter</b>.
<p><img src="images/create-getter-setter.png" border="0" alt="Generate Getter and Setter dialog">
</p>
If you use a name prefix or suffix be sure to specify this in the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeStylePreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the code style preference page">
<b>Java > Code Style</b></a>
preference page.</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Create getters and setters quick assist</b></td>
<td valign="top" align="left" width="80%">A quick assist <b>(Ctrl+1)</b> is available on fields to
create getters and setters.
<p>
<img title="Create Getters and Setters Quick Assist" alt="Screen shot showing the create getters and setters quick assist" src="images/gettersetter-quickassist.png">
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Use content assist to
create getter and setters</b></td>
<td valign="top" align="left" width="80%">Another way to create
getters and setters is using content assist. Set the cursor in the
type body between members and press <b>Ctrl+Space</b> to get the proposals
that create a getter or setter method stub. <br>
<img border="0" src="images/codeassist-getter.png" alt="Content assist for creating a setter"></td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Delete getters and
setters together with a field</b></td>
<td valign="top" align="left" width="80%">When you delete a field
from within a view,
Eclipse can propose deleting its Getter and Setter methods.
If you use a name prefix or suffix for fields, be sure to specify this in the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeStylePreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the code style preference page">
<b>Java > Code Style</b></a>
preference page.</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Create delegate methods</b></td>
<td valign="top" align="left" width="80%">To create a delegate method
for a field select the field's declaration and invoke <b>Source >
Generate Delegate Methods</b>. This adds the selected methods
to the type that contains a forward call to delegated methods. This
is an example of a delegate method: <br>
<img src="images/delegate-method.png" border="0" alt="Delegate method example">
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Create <code>hashCode()</code> and <code>equals()</code></b>
</td>
<td valign="top" align="left" width="80%">To create the methods <code>hashCode()</code> and <code>equals()</code>
invoke <b>Source > Generate hashCode() and equals()</b>.
<p>
<img src="images/create-hashcode-equals.png" border="0" alt="Generate hashCode() and equals() dialog">
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Use templates to create
a method</b></td>
<td valign="top" align="left" width="80%">Templates are shown together with the <b>Content
Assist (Ctrl+Space)</b> proposals.<br>
There are existing templates, such as 'private_method',
'public_method', 'protected_method' and more, but you can also
define new templates for method stubs.<br>
<p>After applying a template, use the <b>Tab</b> key to navigate among the values to enter
(return type, name and arguments).<br>
<img src="images/templates-create-method.png" border="0" alt="Content assist with new method template proposals">
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Use templates to create
SWT widgets</b></td>
<td valign="top" align="left" width="80%">On projects which have the SWT library on the classpath,
you can create SWT widgets with <b>Content Assist (Ctrl+Space)</b>
<p>To add, for example, an SWT button, type <i>Button</i> and press <strong>Ctrl+Space</strong>,
select the <i>Button</i> SWT template, and press <strong>Enter</strong>.</p>
<p> <img src="images/swt-templates.png" alt="Create a button with the Button template"> </p>
<p>To see all available templates go to the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.JavaTemplatePreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the Templates preference page">
<b>Java > Editor > Templates</b></a> preference page or open the Templates view through <b>Window > Show View > Other...</b>.
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Java Postfix Templates</b></td>
<td valign="top" align="left" width="80%">
Postfix completion allows certain kinds of language constructs to be applied to the previously entered text. For example,
entering <code>"input text".var</code> and selecting the <strong>var - Creates a new variable</strong> postfix template
will result in <code>String name = "input text"</code>.
<p> <img src="images/postfix-templates.png" alt="Java Postfix Templates"> </p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Create your own
templates</b></td>
<td width="80%" valign="top">
To create your own templates, go to the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.JavaTemplatePreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the editor templates preference page">
<b>Java > Editor > Templates</b></a> preference page and press the <b>New</b> button to
create a template. For example, a template to iterate backwards in an
array would look like this:
<p>
<img src="images/template-for-iter.png" alt="Template for an iterator"></p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Use Quick Fix to create
a new method</b></td>
<td valign="top" align="left" width="80%">Start with the method
invocation and use <b>Quick Fix (Ctrl+1)</b> to create the method.
<p><img src="images/quick-fix-create-method.png" border="0" alt="'Create method' quick fix">
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Use Quick Fix to change
a method signature</b></td>
<td valign="top" align="left" width="80%">Add an argument to a method
invocation at a call site. Then use <b>Quick Fix (Ctrl+1)</b> to add the
required parameter in the method declaration.
<p><img src="images/quickfix-change-signature.png" border="0" alt="'Change signature' quick fix">
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Use content assist to
create a constructor stub</b></td>
<td valign="top" align="left" width="80%">At the location where you
want to add the new constructor, use content assist after typing the
first letters of the constructor name.<br>
<img border="0" src="images/code-assist-add-constructor.png" alt="Create constructor with content assist"></td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Create new fields from
parameters</b></td>
<td valign="top" align="left" width="80%">Do you need to create new
fields to store the arguments passed in the constructor or method? Use <b>Quick
Assist</b> (<b>Ctrl+1</b>) on a parameter to create the assignment and the
field declaration and let Eclipse propose a name according to your Code
Style preferences.<br>
<img border="0" src="images/quick-assist-create-field.png" alt="'Assign parameter to new field' quick assist"></td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Use content assist to
override a method</b></td>
<td valign="top" align="left" width="80%">Invoke <b>Content Assist
(Ctrl+Space)</b> in the type body at the location where the method
should be added. Content assist will offer all methods that can be
overridden. A method body for the chosen method will be created.
<p><img src="images/code-assist-newmethod.png" border="0" alt="'Override method' content assist">
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Use Quick Fix to add
unimplemented methods</b></td>
<td valign="top" align="left" width="80%">To implement a new
interface, add the 'implements' declaration first to the type.
Even without saving or building, the Java editor will underline the
type to signal that methods are missing and will show the Quick Fix
light bulb. Click on the light bulb or press <b>Ctrl+1 (Edit >
Quick Fix)</b> to choose between adding the unimplemented methods or
making your class abstract.
<p><img src="images/quick-fix-unimplemented-methods.png" border="0" alt="Quick Fix offering 'Add unimplemented methods' proposal">
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Use Clean Up to add
unimplemented methods</b></td>
<td valign="top" align="left" width="80%">When you add a new method to
an interface or an abstract method to an abstract class, Eclipse can generate
method stubs in all concrete subclasses at once. Invoke <b>Source > Clean Up...</b>
on a set of Java elements, use a custom profile, and select on the <b>Configure...</b>
dialog to <b>Add unimplemented methods</b> on the <b>Missing Code</b> tab.
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Override a method
from a base class</b></td>
<td valign="top" align="left" width="80%">To create a method that
overrides a method from a base class: <br>
Select the type where the methods should be added and invoke <b>Source >
Override/Implement Methods</b>. This opens a dialog that lets you
choose which methods to override.
<p><img src="images/override-method.png" border="0" alt="'Override/Implement method' dialog">
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Quick fix to convert to static import</b></td>
<td valign="top" align="left" width="80%">A new quick fix has been implemented that allows the user to convert static field accesses and static methods to use a static import.
It's also possible to replace all occurrences at the same time.
<p>
<img src="images/quickfix_convert_to_static_import.png" alt="">
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Rename in file</b></td><td valign="top" align="left" width="80%">To quickly do a rename that
doesn't require full analysis of dependencies in other files, use the
'Rename in file' Quick Assist. In the Java Editor, position the
cursor in an identifier of a variable, method or type and press <b>Ctrl+1
(Edit > Quick Fix)</b><br>
The editor is switched to the linked edit mode (like templates) and
changing the identifier simultaneously changes all other references
to that variable, method or type.
<p><img src="images/quick-fix-localrename.png" border="0" alt="Changing multiple identifiers using 'Local Rename' quick fix">
</p>
You can also use the direct shortcut <b>Ctrl+2 R</b>. Use the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Keys)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens keys preference page">
<b>General > Keys</b></a> preference page
to configure shortcuts (in the 'Source' category).
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Rename in workspace</b></td><td valign="top" align="left" width="80%">
The <b>Refactor > Rename</b> (<b>Alt+Shift+R</b>) popup has an <b>Options...</b> link which opens the full <b>Rename dialog</b> that
provides more options like renaming a field's getter and setter methods.
<p>
<img src="images/rename-options.png" alt="">
</p>
The dialog can also be opened via the menu button in the popup or by pressing <b>Alt+Shift+R</b> again.
The in-place mode can be disabled entirely via the <b>Rename in editor without dialog</b> option on the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.JavaBasePreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the Java preference page">
<b>Java</b></a> preference page.
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Use Quick Fix to handle
exceptions</b></td>
<td width="80%" valign="top">Dealing with thrown exceptions is
easy. Unhandled exceptions are detected while typing and marked with
a red line in the editor.
<ul>
<li>Click on the light bulb or press <b>Ctrl+1</b> to surround the
call with a try catch block. If you want to include more statements
in the try block, select the statements and use <b>Source >
Surround With > Try/catch Block</b>. You can also select individual
statements by using <b>Edit > Expand Selection To</b> and
selecting <b>Enclosing</b>, <b>Next</b> or <b>Previous</b>.</li>
<li>If the call is already surrounded with a try block, Quick Fix
will suggest adding the catch block to the existing block.</li>
<li>If you don't want to handle the exception, let Quick Fix add a
new thrown exception to the enclosing method declaration</li>
</ul>
<p><img src="images/quick-fix-uncaught-exception.png" border="0" alt="'Uncaught exception' quick fix proposals">
</p>
At any time, you can convert a catch block to a thrown exception. Use
<b>Ctrl+1 (Edit > Quick Fix)</b> on a catch block.<br>
<p><img src="images/quick-assist-catch-to-throws.png" border="0" alt="'Replace catch clause with throws' quick assist">
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Less typing for
assignments</b></td>
<td width="80%" valign="top">Instead of typing an assignment, start
with the expression that will be assigned.
<p><img src="images/quick-assist-assign-statement.png" border="0" alt="'Assign statement to local variable' quick assist">
</p>
Now use <b>Ctrl+1 (Edit > Quick Fix)</b> and choose '<b>Assign
statement to new local variable</b>' and Quick Assist will guess a
variable name for you. <br>
<img src="images/quick-assist-assign-statement2.png" alt="Quick Assist Assignment" border="0"></td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Less work with cast
expressions</b></td>
<td width="80%" valign="top">Don't spend too much time with typing casts. Ignore them first and use quick assist to add them after
finishing the statement.
<p>
For example on assignments:<br>
<img border="0" src="images/quickfix-addcast1.png" alt="Add cast in assignment"> <br>
Or for method arguments:<br>
<img border="0" src="images/quickfix-addcast2.png" alt="Add cast for method arguments"> <br>
Or for method call targets:<br>
<img border="0" src="images/quickfix-addcast3.png" alt="Add cast in method call targets"></p></td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Assign a cast expression</b><br>
</td>
<td width="80%" valign="top">After an 'instanceof' check, it is very common to cast the expression and assign it to a new local variable. Invoke <b>Quick
Assist (Ctrl+1)</b> on the 'instanceof' keyword or at the beginning of the block body to save yourself some typing:<br>
<img border="0" src="images/assign-to-casted-quickfix.png"
alt="'Introduce new local with casted type' quick fix">
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Surround lines</b></td>
<td width="80%" valign="top">To surround statements with an if /
while / for statement or a block, select the lines to surround and
invoke <b>Source > Surround With</b> or press <b>Alt+Shift+Z</b>.
<p><img src="images/surroundwith.png" border="0" alt="'Surround with templates' quick assist">
</p>
<p>The entries in the menu are derived from the normal editor templates: All
templates that contain the variable ${line_selection} will show up in the menu.</p>
Templates can be configured on the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.JavaTemplatePreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the editor templates preference page">
<b>Java > Editor > Templates</b></a> preference page. Edit the corresponding templates to customize the resulting code or
define your own surround-with templates.<br>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Create 'for' loops</b></td>
<td width="80%" valign="top">A set of <b>Quick Assists (Ctrl+1)</b> can create <code>for</code> loops that iterate over a given expression.
<p>
For arrays:
</p>
<ul>
<li>Create an enhanced <code>for</code> loop</li>
<li>Create a <code>for</code> loop using an index</li>
</ul>
<p><a href="images/quickfix-create-for-loop-array.txt"><img src="images/quickfix-create-for-loop-array.png" alt=""></a></p>
For <code>Collection</code>s:
<ul>
<li>Create an enhanced <code>for</code> loop</li>
<li>Create a <code>for</code> loop using an <code>Iterator</code></li>
</ul>
For <code>List</code>s:
<ul>
<li>Create a <code>for</code> loop using an index and <code>get(i)</code></li>
</ul>
<p><a href="images/quickfix-create-for-loop-collection.txt"><img src="images/quickfix-create-for-loop-collection.png" alt=""></a></p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Migrate anonymous class creations to lambda expressions and back</b></td>
<td width="80%" valign="top">You can convert anonymous class creations to lambda expressions (and back) by invoking the <b>Quick Assists (Ctrl+1)</b>:
<ul>
<li>Convert to lambda expression</li>
<li>Convert to anonymous class creation</li>
</ul>
<p>Before:</p>
<p><img src="images/convert-to-lambda-1.png" alt="anonymous class with a 1-line method body"></p>
<p>After the Quick Assist (<b>Ctrl+1</b>), the 6 lines are condensed into 1:</p>
<p><img src="images/convert-to-lambda-2.png" alt="lambda expression -- everything on 1 line"></p>
Or invoke <b>Source > Clean Up...</b>, use a custom profile, and on the <b>Configure...</b> dialog select <b>Convert functional interface instances</b>
and <b>Use lambda where possible</b> on the <b>Code Style</b> tab.
<p>The Clean Up will not convert a functional anonymous class to lambda if the method has declaration annotations (other than <code>@Override</code> and <code>
@Deprecated</code>). You can still use the quick assist to do the conversion in such cases.</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Migrate lambda expressions to method references and back</b></td>
<td width="80%" valign="top">You can convert lambda expressions to method references (and back) by invoking the <b>Quick Assists (Ctrl+1)</b>:
<ul>
<li>Convert to method reference
<p><img src="images/convert-to-method-reference.png" alt="t -> Integer.toHexString(t)"></p></li>
<li>Convert to lambda expression
<p><img src="images/convert-to-lambda.png" alt="Integer::toHexString"></p></li>
</ul>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Create module-info.java file</b></td>
<td width="80%" valign="top">An existing non-modular Java project can be quickly converted to a module by creating a module-info.java file for that project.
This feature can be availed once the project has been moved to compliance 9 or above:
<p><img src="images/java9-create-module.png" alt="Configure > Create module-info.java"></p>
<p>You can also paste a snippet of code representing module-info.java directly into a source folder to create the module-info.java file.</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><img src="images/new.png" alt=""><b>Enable preview features</b></td>
<td width="80%" valign="top">You can quickly enable the preview features on an applicable Java project by right-clicking on it
and selecting <b>Configure > Enable preview features</b>:
<p><img src="images/enable-preview.png" alt="Configure > Enable preview features"></p>
<p>You can also change the default severity (warning) of the preview features compile problem in the opened <b>Project properties</b> dialog.</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>More Quick Assists and Fixes</b><br>
</td>
<td width="80%" valign="top">Check out the <a
href="../reference/ref-java-editor-quickassist.htm">Quick Assist</a> page for a complete list of available code transformations. A list of quick fixes can be found <a
href="../reference/ref-java-editor-quickfix.htm">here</a>.
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Shortcuts for Quick Fixes and Assists<br>
</b></td>
<td valign="top" align="left" width="80%">Some of the popular quick assists like
<b>Rename in file</b> and <b>Assign to local variable</b> can be invoked
directly with <b>Ctrl+2 R</b> and <b>Ctrl+2 L</b>. Check
the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Keys)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens keys preference page">
<b>General > Keys</b></a> preference page for more quick fixes and quick assists that support direct
invocation.
<p>Type "Quick Assist" or "Quick Fix" in the filter field:</p>
<p><img src="images/quick-assist-shortcuts.png" alt="Keys preference page with quick assist shortcuts"></p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Annotate command</b></td>
<td width="80%" valign="top">You can invoke <b>Annotate</b> command - either by using the context menu, or by pressing <b>Ctrl+1</b> - when browsing attached source code of a library
using the class file editor to annotate any type in the signature of a library method or field. Proposals will be offered for marking the selected type as <code>@NonNull</code> or <code>@Nullable</code>.
After selecting a proposal, the compiler will immediately leverage the new annotation for its null analysis.
<p><img src="images/annotate-map-return.png" alt=""></p>
<p>Two pre-requisites must be met for using this command:</p>
<ul>
<li>The project is configured to use annotation-based null analysis.</li>
<li>An existing workspace folder has been specified as the external annotation location for a given library.</li>
</ul>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Content assist can insert
argument names automatically</b></td>
<td width="80%" valign="top">
You can have content assist insert argument names automatically on
method completion. This behavior can be customized on the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeAssistPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the content assist preference page">
<b>Java > Editor > Content Assist</b></a> preference page (see the
<b>Fill method arguments and show guessed arguments</b> checkbox.) For example, when
you select the second entry here,
<p><img src="images/code-assist-argument-proposal.png" alt="content assist window">
</p>
<p>content assist will automatically insert argument names:</p>
<p><img src="images/code-assist-argument-proposal-inserted.png" alt="content assist inserted argument names">
</p>
<p>You can then use the <b>Tab</b> key to navigate between the
inserted names.</p>
<p>If you choose <b>Insert best guessed arguments</b>, the best guess will be filled in by default. The alternative
proposals are still available.
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Automatically insert
type arguments</b><br>
</td>
<td width="80%" valign="top">Enabling <b>Fill method arguments and show guessed arguments</b> on the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeAssistPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the content assist preference page">
<b>Java > Editor > Content Assist</b></a> preference page
is also useful when working with parameterized types in J2SE 5.0.<br>
<img border="0" src="images/code-assist-type-arg-guessing.png"
alt="Content assist on a parameterized type">
<br>results in:<br>
<img border="0" src="images/code-assist-type-arg-guessing2.png"
alt="Content assist guessed and inserted type argument">
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Remove type arguments after content assist</b><br>
</td>
<td width="80%" valign="top">
If content assist added type arguments for a generic type, but you do not want them
because you need the <code>.class</code> literal or you want to invoke a static method,
rather than deleting all the arguments manually,
you can just delete the '<code><</code>' and that will remove the entire text up to '<code>></code>'.
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Remove surrounding
statement</b></td>
<td width="80%" valign="top">To remove a surrounding statement or
block, position the cursor at the opening or closing bracket and press <b>Ctrl+1
(Edit > Quick Fix)</b>.
<p><img src="images/quick-assist-remove-surrounding.png" border="0" alt="'Remove surrounding statement' quick assist">
</p>
</td>
</tr>
<tr>
<td valign="top" align="left"><b>How was that word spelled again?</b></td>
<td>You can enable spell-checking support in the Java editor on the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.editors.preferencePages.Spelling)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the spelling preference page">
<b>General > Editors > Text Editors > Spelling</b></a>
preference page. Spelling errors
are displayed in the Java editor and corresponding Quick Fixes are available:
<p><img alt="An example of a spelling correction proposal." title="Spelling Correction Proposal" src="images/spelling-correction-proposal.png" align="middle"></p>
<p>You can make the
dictionary also available to the content assist. A Quick Fix allows you to
add new words to the user dictionary on the fly.</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Structured selections</b></td>
<td width="80%" valign="top">The Structured Selection actions can be used to
enlarge the current selection to the next enclosing element:
<p>Highlight some text and press <b>Alt+Shift+Arrow Up</b> or select <b>Edit
> Expand Selection To > Enclosing Element</b> from the menu
bar - the selection will be expanded to the smallest Java-syntax
element that contains the selection. You can then further expand the
selection by invoking the action again (or other actions from the Expand Selection To menu).</p>
<p>This is for example helpful to select the enclosing identifier for renames,
or to select adjacent statements for a subsequent Extract Method refactoring.</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Find the matching
bracket</b></td>
<td width="80%" valign="top">To find a matching bracket select an
opening or closing bracket and press <b>Ctrl+Shift+P</b> or select <b>Navigate >
Go To > Matching Bracket</b>. You can also <b>double click</b>
next to a bracket - this selects the text between the two brackets.
<p><img src="images/matching-brackets.png" border="0" alt="Using 'double click' to select text between two brackets"></p>
<p>The Java editor also supports highlighting of enclosing brackets.</p>
<p><img src="images/enclosing-brackets.png" alt="Enclosing brackets"></p>
<p>This can be configured on the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.JavaEditorPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the Java editor preference page">
<b>Java > Editor</b></a> preference page.
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Smart Javadoc</b></td>
<td width="80%" valign="top">Type '/**' and press <b>Enter</b>. This
automatically adds a Javadoc comment stub containing the standard
@param, @return and @exception tags.
<p><img src="images/smart-javadoc.png" border="0" alt="Result of 'Smart Javadoc'">
</p>
The templates for the new comment can be configured in the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeTemplatePreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the code templates preference page">
<b>Java > Code Style > Code Templates</b></a> preference page.
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Use the local history
to revert back to a previous edition of a method</b></td>
<td valign="top" align="left" width="80%">Whenever you edit a file,
its previous contents are kept in the local history. Java tooling
makes the local history available for Java elements, so you can
revert back to a previous edition of a single method instead of the
full file.
<p>Select an element (e.g. in the Outline view) and use <b>Replace With > Local History</b>
to revert back to a previous edition of the element.</p>
<p><img src="images/localhistory-replace.png" border="0" alt="Replace form local history dialog">
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Use the local history
to restore removed methods</b></td>
<td valign="top" align="left" width="80%">Whenever you edit a file,
its previous contents are kept in the local history. Java tooling
makes the local history available for Java elements, so you can
restore deleted methods selectively.
<p>Select a container (e.g. in the Outline view) and use <b>Restore from Local History</b> to
restore any removed members.</p>
<p><img src="images/localhistory-restore.png" border="0" alt="Restore from local history dialog">
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Customizable code
generation</b></td>
<td width="80%" valign="top" align="left">The
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeTemplatePreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the code templates preference page">
<b>Java > Code Style > Code Templates</b></a> preference page
allows you to customize
generated code and comments in a similar way to normal templates.
These code templates are used whenever code is generated.<br>
<p><img
src="images/code-templates.png" border="0"
alt="Code templates preference page">
</p>
Since 3.1, it is possible to use project specific Code templates, that will also be shared in the team if your project is shared. Open the <b>Properties</b> on a project to enable project specific settings.
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Create comments in your
code</b></td>
<td width="80%" valign="top" align="left">Comments can be added explicitly with <b>Source > Generate Element Comment (Alt+Shift+J)</b> or automatically by various wizards, refactorings or quick fixes.<br>
Configure the comment templates on the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeTemplatePreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the code templates preference page">
<b>Java > Code Style > Code Templates</b></a> preference page.<br>
Enable or disable the automatic generation of comments either directly on the wizard (e.g. using <b>'Generate
Comment'</b> checkbox on the new Java type wizards) or by the <b>'Automatically
add new comments for new methods and types'</b> checkbox of the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeTemplatePreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the code templates preference page">
<b>Java > Code Style > Code Templates</b></a> preference page.<br>
All these settings can also be configured on a per project basis. Open the <b>Properties</b> on a project to enable project specific settings.</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Sort members</b></td>
<td width="80%" valign="top" align="left">You can <b>Sort Members</b>
of a Java compilation unit or a set of compilation units according to a category order defined in the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.MembersOrderPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the member sort order preference page">
<b>Java > Appearance > Members Sort Order</b></a> preference page.<br>
You'll find the action under <b>Source > Sort Members</b>.</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Sort library entries alphabetically in Package Explorer</b></td>
<td width="80%" valign="top" align="left">
The library entries can be sorted alphabetically when setting the preference <b>Sort library entries alphabetically in Package Explorer</b>
on the <b>Java > Appearance</b> preference page:
<p><img src="images/jdt_sort_library_pref.png" alt=""></p>
<table>
<tr><th>OFF</th><th>ON</th></tr>
<tr>
<td><img src="images/jdt_library_entries_unsorted.png" alt="before" style="width:240px"></td>
<td><img src="images/jdt_library_entries_sorted.png" alt="before" style="width:240px"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Wrap strings</b></td>
<td width="80%" valign="top" align="left">
You can have String literals wrapped when you edit them. For
example, if you have code like this:
<pre>String message= "This is a very long message.";</pre>
<p>position your caret after the word "very" and press <b>Enter</b>.
The code will be automatically changed to:</p>
<pre>String message= "This is a very" +
" long message.";</pre>
<p>This behavior can be customized in the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.SmartTypingPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the typing preference page">
<b>Java > Editor > Typing</b></a> preference page.</p>
</td>
</tr>
<tr>
<td valign="top" align="left"><b>Smart Typing and how to control it</b></td>
<td>
The Java editor's Smart Typing features ease your daily work. You can configure
them on the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.SmartTypingPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the typing preference page">
<b>Java > Editor > Typing</b></a> preference page.
<p>
<img src="images/typing-preferences.png" border="0" alt="Java editor typing preference page" title="Typing Preference Page" align="middle">
</p>
<p>
When you enable <b>Automatically insert Semicolons at correct
position</b>, typing a semicolon automatically positions the cursor at the end of the statement before inserting the semicolon. This saves you some additional cursor navigation.<br>
You can
undo this automatic positioning by pressing backspace right afterwards.
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Fix your code
indentation with one key stroke</b></td>
<td width="80%" valign="top" align="left">A useful feature is <b>Source
> Correct Indentation</b> or <b>Ctrl+I</b>.<br>
Select the code where the indents are incorrect and invoke the action.
<p>If nothing is selected, the action indents the current line.</p></td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Fix your code
indentation on save</b></td>
<td width="80%" valign="top" align="left">Eclipse can correct the indentation
of your code when you save the editor. Go to the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.SaveParticipantPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the Save Actions preference page">
<b>Java > Editor > Save Actions</b></a> preference page and
<b>Configure...</b> <b>Additional actions</b>, and select to <b>Correct indentation</b> on
the <b>Code Organizing</b> tab.
</td>
</tr>
<tr>
<td valign="top" align="left"><b>Quick menus for source and
refactoring actions</b></td>
<td align="left" valign="top">
The refactoring and source actions can be accessed via a quick
menu. Select the element to be manipulated in the Java editor or in a
Java view and press <b>Alt+Shift+S</b> for the quick source menu,
<b>Alt+Shift+T</b> for the quick refactoring menu and <b>Alt+Shift+Z</b> for the surround with menu.
<p><img border="0" src="images/quick-refactoring-menu.png" alt="Quick refactoring menu"></p></td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Extract local variable as 'var'</b></td>
<td width="80%" valign="top" align="left">
While extracting a local variable in a project having compliance of Java 10 or above, you can choose to declare the local variable type as 'var':
<img src="images/extract_local_to_var.png" alt="">
</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Find unused code</b></td>
<td width="80%" valign="top" align="left">The Java compiler detects
unreachable code, unused variables, parameters, imports and unused
private types, methods and fields.
Change the settings for the detection on the
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.ProblemSeveritiesPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the error/warning preference page">
<b>Java > Compiler > Error/Warnings</b></a>
preference page. These settings can also be specified per project, use: <b>Project > Properties > Java Compiler >
Error/Warnings</b>.<p><img src="images/warn-privates.png" border="0" alt="Compiler preference page">
</p>
These problems are detected as you type, and a quick fix is
offered to remove the unneeded code.
You can also use <b>Source > Clean Up...</b> to remove unused code.</td>
</tr>
<tr>
<td width="20%" valign="top" align="left"><b>Find problems with null</b>
</td>
<td width="80%" valign="top" align="left">The compiler can help you find problems with <code>null</code> in your code.
The
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.ProblemSeveritiesPreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the Errors/Warnings preference page">
<b>Java > Compiler > Errors/Warnings</b></a>
preference page has three options to detect problems:
<ul>
<li><b>Null pointer access</b> (in 'Null analysis')<br>
When this option is enabled, the compiler will issue an error or warning
whenever a variable that is statically known to hold a null value
is used to access a field or method, as shown in the example below:
<p><img src="images/null-reference.png" alt="Null pointer access example"></p><br>
</li>
<li><b>Potential null pointer access</b> (in 'Null analysis')<br>
When this option is enabled, the compiler will issue an error or a
warning whenever a variable is statically known to potentially hold
a null value, as shown in the example below:
<p><img src="images/potential-null-ref.png" alt="Potential null pointer access example"></p><br>
</li>
<li><b>Redundant null check</b> (in 'Null analysis')<br>
When enabled, the compiler will issue an error or a warning whenever
a variable that is statically known to hold a null or a non-null