Bug 107621 - [implementation] JavaSpellingReconcileStrategy calls getContentType() and it is not used
Summary: [implementation] JavaSpellingReconcileStrategy calls getContentType() and it...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 3.2 RC1   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2005-08-22 11:20 EDT by Richard Kulp CLA
Modified: 2006-04-26 13:02 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 Richard Kulp CLA 2005-08-22 11:20:12 EDT
I wanted to create a content type that was a subtype of JavaSource so that we
can have our own default editor for special java classes. To determine if it was
our type we created a content describer that looks through the code to see if it
is our type. 

The problem is that the JavaSpellingReconcileStrategy class is calling the
getContentType() twice for every keystroke (reconcile) so that it can put it
into the SpellingContext. Then the spelling context never even uses this content
type. 

This is very inefficient, causes the class to parsed twice like that and never
even use the result. If this is absolutely necessary, then SpellingContext
should be changed to lazily request the content type instead of having it put it
 into it right away.

From JavaSpellingReconcileStrategy:
	public void reconcile(IRegion region) {
		if (fRequestor != null) {
			try {
				SpellingContext context= new SpellingContext();
				context.setContentType(getContentType());
				EditorsUI.getSpellingService().check(fDocument, context, fCollector,
fProgressMonitor);
			} catch (CoreException x) {
				// swallow exception
			}
		}
	}
Comment 1 Dani Megert CLA 2006-04-04 07:10:22 EDT
Note that the following comments are based on 3.2 M6 and I did not verify whether they were true at the time this bug got filed.

>The problem is that the JavaSpellingReconcileStrategy class is calling the
>getContentType() twice for every keystroke (reconcile) 
Using 3.2 M6, the method is invoked only once per keystroke.

>This is very inefficient, causes the class to parsed twice like that and never
>even use the result.
The class is not parsed at all normally: Platform Core will only need to consult the reader if the content type descriptor needs to look into the file. This is normally no the case if the extension ends with ".java".

>This is very inefficient, causes the class to parsed twice like that and never
>even use the result. 
This is not true: the content type is used to retrieve the correct spelling engine, see DefaultSpellingEngine.check(...)

Having said all that, the code is just plain wrong: the reconciler is a Java reconciler working on Java source files and hence we can simply always use the Java Source content type.

Same applies to the Java properties file editor.
Comment 2 Dani Megert CLA 2006-04-04 07:19:33 EDT
Fixed in HEAD.
Available in builds > N20060404-0010.
Comment 3 Dani Megert CLA 2006-04-26 13:02:58 EDT
Verified in N20060426-0010 that getContentType() is no longer called by the JavaSpellingReconcileStrategy.