Bug 149752 - [javadoc] Organize imports adds import statements for exceptions mentioned in java docs comments
Summary: [javadoc] Organize imports adds import statements for exceptions mentioned in...
Status: RESOLVED DUPLICATE of bug 92821
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.1   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-05 17:44 EDT by Dejan Petronijevic CLA
Modified: 2006-07-07 05:49 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dejan Petronijevic CLA 2006-07-05 17:44:18 EDT
If there is a stale java doc comment preceding a method which no longer throws an exception, but the exception is declared with the @throws declaration, selecting "Organize Imports" from the Source menu will add import statement for the declared exception.
Enter the following code into eclipse:
//////////////////////////
public class ImportExample
{
	/**
	 * @throws NoSuchElementException
	 */
	public void op() {
		System.out.print( "" );
	}
}
///////////////////////////
and select Source->Organize Imports. import java.util.NoSuchElementException; will be added in front of the class declaration.
Comment 1 Frederic Fusier CLA 2006-07-06 05:52:54 EDT
What are your javadoc compiler settings ?
Comment 2 Frederic Fusier CLA 2006-07-06 06:10:04 EDT
Javadoc tool allow user to specify in @throws tag any subclass of RuntimeException even if it's not thrown by the method. So, syntax is correct and if your javadoc compiler settings "Process Javadoc comments" is on (this is the default), compiler needs to bind this reference and so Organize Import correctly add the import to do it...

In this case this is a duplicate of bug 92821 and there are several possibility here to workaround your problem:
1) you don't mind to parse javadoc, so unset "Process Javadoc comments" on
   your project
2) you want to parse javadoc comments but do not want to have an import for
   this specific reference, then write a fully qualified reference instead:
      * @throws java.util.NoSuchElementException
   Note that you can configure code assist to add fully qualified name and 
   complete after * @throws NoSuchEle<|>
Comment 3 Dejan Petronijevic CLA 2006-07-06 14:28:48 EDT
(In reply to comment #2)
> Javadoc tool allow user to specify in @throws tag any subclass of
> RuntimeException even if it's not thrown by the method. So, syntax is correct
> and if your javadoc compiler settings "Process Javadoc comments" is on (this is
> the default), compiler needs to bind this reference and so Organize Import
> correctly add the import to do it...

I didn't know this, sorry.

I used NoSuchElementException just as an example, I really had an exception derived straight from Exception. Here is a better example:
////////////////// ImportExample.java //////////////////
package main;
public class ImportExample
{
	/**
	 * @throws FakeException
	 */
	public void op()
	{
		System.out.print( "" );
	}
}
/////////////////////// FakeException.java //////////////////////
package main.exception;
public class FakeException extends Exception
{
}
/////////////////////////////////////////////////////////////////

Still the same behaviour. And yes, "Process Javadoc comments" is on. If this is the desired behaviour, it is OK with me, I'll just have to learn how to use it properly.
Thanks for the prompt response and all the excellent work you are doing for Eclipse.
Comment 4 Frederic Fusier CLA 2006-07-07 05:49:44 EDT
(In reply to comment #3)
> Still the same behaviour. And yes, "Process Javadoc comments" is on. If this is
> the desired behaviour, it is OK with me, I'll just have to learn how to use it
> properly.
Yes, as explained in comment 2 and in bug 92821, this is the expected behavior.

> Thanks for the prompt response and all the excellent work you are doing for
> Eclipse.
> 
You're welcome and thank you :-)


*** This bug has been marked as a duplicate of 92821 ***