epubjs
Version:
Render ePub documents in the browser, across many devices
74 lines (73 loc) • 9.04 kB
HTML
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Eclipse Features</title><link rel="stylesheet" href="core.css" type="text/css"/><meta name="generator" content="DocBook XSL Stylesheets V1.74.0"/></head><body><div class="sect1" title="Eclipse Features"><div class="titlepage"><div><div><h1 class="title"><a id="learnjava3-APP-A-SECT-4"/>Eclipse Features</h1></div></div></div><p>Eclipse has too many interesting features to really do them justice
here, but we’ll mention a few to show you why people love this IDE.</p><div class="sect2" title="Coding Shortcuts"><div class="titlepage"><div><div><h2 class="title"><a id="learnjava3-APP-A-SECT-4.1"/>Coding Shortcuts</h2></div></div></div><p><a id="idx11240" class="indexterm"/>Of course, you’ve noticed all the color coding and
meta-information present when viewing Java source code in Eclipse. You
can customize all of this behavior to suit your taste through the
Eclipse <span class="unicode">→</span> Preferences <span class="unicode">→</span> Java <span class="unicode">→</span> Editor
<span class="unicode">→</span> Syntax Coloring panel. Many other
options can be set through the Eclipse <span class="unicode">→</span>
Preferences <span class="unicode">→</span> Java <span class="unicode">→</span> Code Style and Editor panes.</p><p><a id="I_indexterm_id838411" class="indexterm"/> <a id="I_indexterm_id838418" class="indexterm"/>What may not be immediately obvious is that editing is
also enhanced. When typing, try pressing Ctrl-Space to attempt
autocompletion or have Eclipse present you with relevant options. For
example, instead of typing <code class="literal">JButton</code>,
try typing <code class="literal">JBu</code> plus Ctrl-Space.
Eclipse completes the name for you. If the portion of the name you type
is ambiguous, a drop-down list appears, similar to that shown in <a class="xref" href="apas04.html#learnjava3-APP-A-FIG-5" title="Figure A-5. Using completion in Eclipse">Figure A-5</a>.</p><p>Eclipse also provides abbreviations for common items. Try typing
<code class="literal">sysout</code> and pressing Crtl-Space.
Eclipse expands this to <code class="literal">System.out.println()</code> and places the cursor in
the parentheses automatically. If you type a quotation mark, Eclipse
closes the quotation for you. Note the green bar that it places after
the closing quote. Pressing Tab takes you to that point so that you
don’t have to use the arrow keys. Pressing Tab again takes you to the
next green bar spot, which is the end of the line.</p><div class="figure-float"><div class="figure"><a id="learnjava3-APP-A-FIG-5"/><div class="figure-contents"><div class="mediaobject"><a id="I__tt1363"/><img src="httpatomoreillycomsourceoreillyimages1707722.png" alt="Using completion in Eclipse"/></div></div><p class="title">Figure A-5. Using completion in Eclipse</p></div></div></div><div class="sect2" title="Autocorrection"><div class="titlepage"><div><div><h2 class="title"><a id="learnjava3-APP-A-SECT-4.2"/>Autocorrection</h2></div></div></div><p><a id="I_indexterm_id838490" class="indexterm"/>Eclipse can offer fixes for simple problems in your code
when it detects them. To see suggested fixes, click on the red X next to
a problem line. Eclipse presents a drop-down menu of possible fixes for
the problem. Selecting an option shows you the code changes that Eclipse
will make before you choose it.</p><p>For example, try changing the name of one of the <code class="literal">JButton</code>s in our Calculator to <code class="literal">JBButton</code>. Now, click the red X and a screen
similar to <a class="xref" href="apas04.html#learnjava3-APP-A-FIG-6" title="Figure A-6. Autocorrection in Eclipse">Figure A-6</a> appears. Eclipse
offers several possible corrections; the best one is to fix the
misspelling and change it back to <code class="literal">JButton</code>. Of course, if we’d really meant to
refer to a new kind of button, we could choose the option to create the
new class right there and Eclipse would help us do that by creating a
skeleton for us.</p><div class="figure"><a id="learnjava3-APP-A-FIG-6"/><div class="figure-contents"><div class="mediaobject"><a id="I__tt1364"/><img src="httpatomoreillycomsourceoreillyimages1707723.png" alt="Autocorrection in Eclipse"/></div></div><p class="title">Figure A-6. Autocorrection in Eclipse</p></div></div><div class="sect2" title="Refactoring"><div class="titlepage"><div><div><h2 class="title"><a id="learnjava3-APP-A-SECT-4.3"/>Refactoring</h2></div></div></div><p><a id="I_indexterm_id838558" class="indexterm"/>Eclipse offers a number of tools under the collective
title <span class="emphasis"><em>refactoring</em></span>. These include the ability to
rename and move members, automatically tracking down references to them
and changing them throughout the project. More advanced options allow
you to do things like create an interface for your class by copying all
of its public methods or add a factory pattern to your code to
encapsulate all object creation for a type. You can even encapsulate
access to a variable, changing the code to use an accessor method
instead. These tools can save you a lot of typing (or retyping, as the
case may be).</p><p>As an example, let’s look at our Calculator again. Click on the
<code class="literal">addGB()</code> method in the outline or
select the method definition yourself. We use this method a lot, so
let’s give it a better name. Select Refactor <span class="unicode">→</span> Rename and change the name to <code class="literal">addToGridBag</code>. If you want to see what it’s
going to do in advance, press the preview button to get a diff view of
the code. By selecting OK, Eclipse changes the name and all references
to the method in your project (in this case that would include all of
the source directories for all chapters). You can also refactor methods
in order to change the method signature and add or remove
arguments.</p></div><div class="sect2" title="Diffing Files"><div class="titlepage"><div><div><h2 class="title"><a id="learnjava3-APP-A-SECT-4.4"/>Diffing Files</h2></div></div></div><p><a id="I_indexterm_id838612" class="indexterm"/>Eclipse provides the ability to quickly diff two files.
Select two files simultaneously in the Package Explorer. Right-click one
of the files to display a context menu and select Compare With <span class="unicode">→</span> Each Other. Eclipse opens a dual-source view
editor pane that shows the differences between the files graphically.
You can even resolve conflicts by copying differences from one file to
the other with the arrows at the top of the pane. For example, open
<span class="emphasis"><em>ch15/webapp-xml/all-web.xml</em></span> and
<span class="emphasis"><em>ch15/webapp-xml/filters-web.xml</em></span> and view the
differences. You can also review changes made to a file using the
Compare With <span class="unicode">→</span> Local History option that
lets you compare the current state of the file with previous saves in
the project. These are very useful tools.</p></div><div class="sect2" title="Organizing Imports"><div class="titlepage"><div><div><h2 class="title"><a id="learnjava3-APP-A-SECT-4.5"/>Organizing Imports</h2></div></div></div><p><a id="I_indexterm_id838653" class="indexterm"/>Eclipse can tidy up the <code class="literal">import</code> statements in your source code.
Selecting Source <span class="unicode">→</span> Organize Imports
causes Eclipse to turn package imports into single class imports.
Eclipse automatically determines exactly which classes from each package
are used and breaks the package imports into individual imports. This
makes the code a little more explicit, but some people prefer package
imports when too many classes are used.</p></div><div class="sect2" title="Formatting Source Code"><div class="titlepage"><div><div><h2 class="title"><a id="learnjava3-APP-A-SECT-4.6"/>Formatting Source Code</h2></div></div></div><p><a id="I_indexterm_id838686" class="indexterm"/>Eclipse can autoformat your source code using the Source
<span class="unicode">→</span> Format option. This applies standard
Java conventions and indentation. The style is highly customizable;
choose Window <span class="unicode">→</span> Preferences <span class="unicode">→</span> Java <span class="unicode">→</span> Code
Style <span class="unicode">→</span> Formatter to see the available
options.</p></div></div></body></html>