Bug 65250 - Problem selection does not choose first n errors
Summary: Problem selection does not choose first n errors
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 RC2   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-02 05:53 EDT by Philipe Mulet CLA
Modified: 2004-06-11 09:33 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 Philipe Mulet CLA 2004-06-02 05:53:28 EDT
Build 3.0RC1

Using following code to generate source for a massive class, observe that 
generated code is invalid, but the first occurrences of syntax errors are not 
notified.

public class X {
	public static void main(String[] args) {
		StringBuffer buffer = new StringBuffer();
		buffer.append("public class Zork {\n");
		for (int i = 0; i < 1000; i++) {
			buffer.append("\tint field_"+i+" = 0; \n");
		}
		for (int i = 0; i < 1000; i++) {
			if (i == 0)
				buffer.append("\tvoid method_"+i+"() { /* 
default */ } \n");
			else
				buffer.append("\tvoid method_"+i+"() { method_"+
(i-1)+"() \n");
		}
		buffer.append("}\n");
		System.out.println(buffer);
	}
}
Comment 1 David Audel CLA 2004-06-03 07:02:02 EDT
A problem is in CompletionResult#computePriority(IProblem problem). If the 
line number of problems is greater than 1000 then all priorities are the same.

private int computePriority(IProblem problem){
	
  final int P_STATIC = 1000;
  final int P_OUTSIDE_METHOD = 4000;
  final int P_FIRST_ERROR = 2000;
  final int P_ERROR = 10000;
		
  int priority = 1000 - problem.getSourceLineNumber(); // early problems first
  if (priority < 0) priority = 0;
  if (problem.isError()){
    priority += P_ERROR;
  }
  ...
}

Another problem is that the referenceContext for method with error in 
signature is the CompilationUnit and not the method. That's because the 
diagnose of these methods occurs during diet parse and not method parse.

private int computePriority(IProblem problem){
  ...
  ReferenceContext context = problemsMap == null ? null :
    (ReferenceContext) problemsMap.get(problem);
  if (context != null){
    if (context instanceof AbstractMethodDeclaration){
      AbstractMethodDeclaration method = (AbstractMethodDeclaration) context;
      if (method.isStatic()) {
        priority += P_STATIC;
      }
    } else {
      priority += P_OUTSIDE_METHOD;
    }
  } else {
    priority += P_OUTSIDE_METHOD;
  }
  ...
}
Comment 2 David Audel CLA 2004-06-08 04:41:11 EDT
I created another bug report for the reference context problem (bug 65978)
Comment 3 David Audel CLA 2004-06-08 07:03:06 EDT
Fixed and test added
  ParserTests#test021()
Comment 4 Olivier Thomann CLA 2004-06-11 09:33:52 EDT
Verified in 200406110010