Bug 23113 - Request to enrich messages provided by AST with errors defined in IProblem
Summary: Request to enrich messages provided by AST with errors defined in IProblem
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-09-03 10:38 EDT by Dirk Baeumer CLA
Modified: 2002-09-19 10:05 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Baeumer CLA 2002-09-03 10:38:39 EDT
2.x

The Message class provided by the AST to report errors doesn't contain a unique 
ID to identify the problem. Now that IProblem is API it would be very useful if 
we can enrich the message class with a unique ID based on the ones defined in 
IProblem. This would ease the code of presenting errors to the user in the case 
were we create a temporary CU in memory to see if a refactoring results in a 
error. Currently we present the compiler's error message which in most cases is 
hard to understand.
Comment 1 Olivier Thomann CLA 2002-09-04 14:35:01 EDT
Looks doable.
Jim - any comment?
Comment 2 Jim des Rivieres CLA 2002-09-04 17:29:23 EDT
I don't mean to be contrary, but it feels like adding this API will tend to 
make things more brittle in the long run.

IProblem constants do not specify what the problem is (although the name is 
mighty suggestive). More importantly, the compiler does not make any promises 
as to which problem ids are used in which circumstances. Under these 
conditions, it is difficult for a client to reliably do much beyond 
substituting one error message for the compiler's. Perhaps we could improve 
the compiler's error messages and achieve the same result directly. Or are 
there specific cases where we could exact a stronger guarantee from the 
underlying compiler?

Comment 3 Dirk Baeumer CLA 2002-09-05 04:25:35 EDT
You are right the the ids defiend by IProblem don't carry enough information to 
change error messages in general. But the refactoring we are executing adds 
enough information/context to decide which error messages to change. Consider 
the example that we rename a local variable and choose a name already in use. 
The compiler message is "Duplicate local variable `name`". This message is a 
little bit confusing for the user since he expects something like "A local 
variable `name` already exists in method". Since we know "what" we are 
changing, the errors that exists before our change and the position of our new 
code we have enough information to change the compiler's error message in this 
case.
Comment 4 Olivier Thomann CLA 2002-09-05 15:23:43 EDT
We should add a new API which would return a collection of IProblem. We can keep
the existing API that returns a collection of Message. This is ok if you don't
care about the details of the problems reported during the resolution.
Is this ok for you?
Comment 5 Jim des Rivieres CLA 2002-09-05 17:19:14 EDT
Proposed new API method CompilationUnit.getProblems()

	/**
	 * Returns the list of detailed problem reports noted by the compiler
	 * during the parsing or the type checking of this compilation unit. 
This
	 * list might be a subset of errors detected and reported by a Java
	 * compiler.
	 * <p>
	 * Simple clients that do little more than log the messages or display
	 * them to the user should probably call <code>getMessages</code> 
instead.
	 * </p>
	 * 
	 * @return the list of detailed problem objects, possibly empty
	 * @see #getMessages
	 * @see AST#parseCompilationUnit
	 * @since 2.1
	 */
	public IProblem[] getProblems() {

A note on getMessages should point more sophisticated clients at getProblems.
Comment 6 Olivier Thomann CLA 2002-09-06 13:36:29 EDT
Fixed and released in 2.1 stream.
Comment 7 David Audel CLA 2002-09-19 10:05:40 EDT
Verified.