blob: 010467e5dfe9cc4b803bf04b6e0777d3e6cd285a [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2005. 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-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="../book.css" charset="ISO-8859-1" type="text/css">
<title>Quick Fix</title>
</head>
<body>
<h1>Quick Fix</h1>
<p>The Java editor offers corrections to problems found while typing and after compiling. To show that
correction proposals are available for a problem or warning, a 'light bulb' is visible on the editor's annotation bar.<br><br>
Left click on the light bulb or invoking <b>Ctrl+1 (Edit &gt; Quick Fix)</b> brings up the proposals for the problem at the cursor position.<br>
Each quick fix show a preview when selected in the proposal window.<br>
<br>
Some selected quick fixes can also be assigned with direct shortcuts. You can configure these shortcuts on the keys preference page. <br></p>
<p><img src="../images/c-quickfix.png" border="0" alt="Quick fix selection dialog"></p>
<p>The following quick fixes are available:</p>
<table border="0" cellpadding="10" cellspacing="0" width="700">
<tbody>
<tr>
<td width="20%" valign="top" align="right"><b>Package Declaration</b></td>
<td width="80%" valign="top" align="left">
<ul>
<li>Add missing package declaration or correct package declaration</li>
<li>Move compilation unit to package that corresponds to the package declaration</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" align="right"><b>Imports</b></td>
<td valign="top" align="left">
<ul>
<li>Remove unused, unresolvable or non-visible import</li>
<li>Invoke 'Organize imports' on problems in imports</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" align="right"><b>Types</b></td>
<td valign="top" align="left">
<ul>
<li>Create new class, interface, enum, annotation or type variable for references to types that can not be resolved</li>
<li>Change visibility for types that are accessed but not visible</li>
<li>Rename to a similar type for references to types that can not be resolved</li>
<li>Add import statement for types that can not be resolved but exist in the project</li>
<li>Add explicit import statement for ambiguous type references (two import-on-demands for the same type)</li>
<li>If the type name is not matching with the compilation unit name either rename the type or rename the compilation unit</li>
<li>Remove unused private types</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" align="right"><b>Constructors</b></td>
<td valign="top" align="left">
<ul>
<li>Create new constructor for references to constructors that can not be resolved (this, super or new class creation)</li>
<li>Reorder, add or remove arguments for constructor references that mismatch parameters</li>
<li>Change method with constructor name to constructor (remove return type)</li>
<li>Change visibility for constructors that are accessed but not visible</li>
<li>Remove unused private constructor</li>
<li>Create constructor when super call of the implicit default constructor is undefined, not visible or throws an exception</li>
<li>If type contains unimplemented methods, change type modifier to 'abstract' or add the method to implement</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" align="right"><b>Methods</b></td>
<td valign="top" align="left">
<ul>
<li>Create new method for references to methods that can not be resolved</li>
<li>Rename to a similar method for references to methods that can not be resolved</li>
<li>Reorder or remove arguments for method references that mismatch parameters</li>
<li>Correct access (visibility, static) of referenced methods</li>
<li>Remove unused private methods</li>
<li>Correct return type for methods that have a missing return type or where the return type does not match the return statement</li>
<li>Add return statement if missing</li>
<li>For non-abstract methods with no body change to 'abstract' or add body</li>
<li>For an abstract method in a non-abstract type remove abstract modifier of the method or make type abstract</li>
<li>For an abstract/native method with body remove the abstract or native modifier or remove body</li>
<li>Change method access to 'static' if method is invoked inside a constructor invocation (super, this)</li>
<li>Change method access to default access to avoid emulated method access</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" align="right"><b>Fields and variables</b></td>
<td valign="top" align="left">
<ul>
<li>Correct access (visibility, static) of referenced fields</li>
<li>Create new fields, parameters, local variables or constants for references to variables that can not be resolved</li>
<li>Rename to a variable with similar name for references that can not be resolved</li>
<li>Remove unused private fields</li>
<li>Correct non-static access of static fields</li>
<li>Add 'final' modifier to local variables accessed in outer types</li>
<li>Change field access to default access to avoid emulated method access</li>
<li>Change local variable type to fix a type mismatch</li>
<li>Initialize a variable that has not been initialized</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" align="right"><b>Exception Handling</b></td>
<td valign="top" align="left">
<ul>
<li>Remove unneeded catch block</li>
<li>Handle uncaught exception by surrounding with try/catch or adding catch block to a surrounding try block</li>
<li>Handle uncaught exception by adding a throw declaration to the parent method or by generalize an existing throw declaration</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" align="right"><b>Build Path Problems</b></td>
<td valign="top" align="left">
<ul>
<li>Add a missing JAR or library for an unresolvable type</li>
<li>Open the build path dialog for access restriction problems or missing binary classes.</li>
<li>Change project compliance and JRE to 5.0</li>
<li>Change workspace compliance and JRE to 5.0</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" align="right"><b>Others</b></td>
<td valign="top" align="left">
<ul>
<li>Add cast or change cast to fix type mismatches</li>
<li>Let a type implement an interface to fix type mismatches</li>
<li>For non-NLS strings open the NLS wizard or mark as non-NLS</li>
<li>Add missing @Override, @Deprecated annotations</li>
<li>Suppress a warning using @SuppressWarning</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Quick Assists are proposals available even if there is no problem or warning. See the <a href='cquickassists.htm'>Quick Assist</a> page for more information.</p>
<p>
<img src="../images/ngrelc.png" alt="Related concepts" border="0"></p>
<p>
<a href="../concepts/concepts-7.htm">Java editor</a><br>
<a href="cquickassists.htm">Quick Assist</a></p>
<p><img src="../images/ngrelr.png" alt="Related reference" border="0"></p>
<p>
<a href="../reference/ref-2.htm">JDT actions</a>
</p>
</body>
</html>