Community
Participate
Working Groups
I've added the following word pattern rule to the JavaPartitionScanner class of the java editor example: rules.add(new WordPatternRule(new JavaWordDetector(), "ice", "cube", comment)); The JavaWordDetector is imported from the org.eclipse.ui.examples.javaeditor.util package (incidentally there is another JavaWordDetector in the org.eclipse.ui.examples.javaeditor.java package which seems never to be used in the example). I then run the modified example, create a new *.jav file and start typing the text 'icecube'. The editor freezes after I've typed 'ic'. Similarly when I open a *.jav file that contains this text, it is colored correctly like a comment, but when I try to edit it the editor freezes again. The console of the development environment shows the following error message: Unhandled exception caught in event loop. Reason: java.lang.ArrayIndexOutOfBoundsException I've tried this both with j2sdk versions 1.4.0 and 1.4.1beta.
I've looked at the sources of the WordPatternRule and the PatternRule in the org.eclipse.jface.text.rules package and found the problem. The PatternRule's doEvaluate method reads a character from the scanner and determines whether it is part of the start sequence. If it is part of the start sequence it tries to detect the rest of that sequence and, if that is found, it looks for the end sequence using the endSequenceDetected method. If either of these sequences is not found it unreads the character from the scanner returns a Token.UNDEFINED. The WordPatternRule overrides the endSequenceDetected method. If the end sequence is not detected this method unreads the entire buffer including the startsequence in the unreadBuffer method. But on return in the PatternRule.doEvaluate method another scanner.unread() call is made, therefor unreading past the beginning of the start sequence. To fix this the for loop in the WordPattern.unreadBuffer method should be changed from: for (int i= fBuffer.length() - 1; i >= 0; i--) to: for (int i= fBuffer.length() - 1; i > 0; i--) so that it leaves the last character in the buffer alone for the PatternRule to unread.
Nick, I had originally entered this call on the wrong component. I've corrected this and I've taken the liberty of reassigning it to you as the owner of this component. Frans
I've removed the unused JavaWordDetector in org.eclipse.ui.examples.javaeditor.java. Reassigning to Kai to look at the hang problem.
Proposed change released into the 2.0.1 and the 2.1 stream.