| Summary: | Exception in AbstractEditStrategy | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Samantha Chan <chanskw> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED WORKSFORME | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | mkomor |
| Version: | 1.0.1 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| Whiteboard: | |||
The brackets woudn't have any effect. Closing this, since it seems to be rather outdated. Please reopen if it's still an issue. |
XText 1.0.2 1) I have customized content assist to provide a function template when the user invokes content assist. So, when the user invokes the template, we will insert code like this: foo(a) where a is the variable for the user to fill in. 2) When the user is inside foo(<here, trying to enter the variable), if the user enter double quote, this will invoke the auto code insertion for quotes. 3) This eventually invoke code in AbstractAutoEditStrategy: protected String getDocumentContent(IDocument document, DocumentCommand command) { if (command.length == 0) return document.get(); try { StringBuilder result = new StringBuilder(document.getLength() + command.length); if (command.offset > 0) result.append(document.get(0, command.offset)); if (command.offset + command.length < document.getLength()) result.append(document.get(command.offset + command.length, document.getLength() - command.offset + command.length)); return result.toString(); } catch(BadLocationException ex) { log.error("Exception in AutoEditStrategy", ex); return document.get(); } } and results in an error like this in the log: !ENTRY org.apache.log4j 4 0 2011-02-17 14:46:19.946 !MESSAGE org.eclipse.xtext.ui.editor.autoedit.AbstractEditStrategy - Exception in AutoEditStrategy This is due to a BadLocationException caught in the above function. I think this function is written incorrectly in the following lines: if (command.offset + command.length < document.getLength()) result.append(document.get(command.offset + command.length, document.getLength() - command.offset + command.length)); return result.toString(); in here document.get(offset, length) is called with length = document.getLength - commandoffset + command.length I think we are missing brackets and this code should be written like this: f (command.offset + command.length < document.getLength()) result.append(document.get(command.offset + command.length, document.getLength() - (command.offset + command.length))); // extra bracket surrounding command.offset + command.length return result.toString();