Community
Participate
Working Groups
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 } } }
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.
Fixed in HEAD. Available in builds > N20060404-0010.
Verified in N20060426-0010 that getContentType() is no longer called by the JavaSpellingReconcileStrategy.