Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-ui-dev] Submitting a JavaDOC word-wrapping AutoIndentStategy


I have written my own version of JavaDocAutoIndentStrategy.  This saves me *tons* of time when editing an existing JavaDoc comment, and I want to have the comment wrapped at the right PrintMargin.  It is amazing that all of Eclipse was JavaDOCed without such a feature.

On each character insert, the strategy will wrap the paragraph when necessary.  Paragraph is defined as the current line in the comment, and subsequent lines which:
1) Do not begin with "<" (HTML <tags> such as <TABLE> <OL>, etc.  Special cases to ignore <B>, <I>, and other tags which are part of a paragraph
2) Do not begin with @ (i.e. @param, @return
3) are not empty lines

The strategy also handles DELETE key when:
/**
 * the comment<<CARET>>
 *
 */
such that the next line's javaDoc prefix (" * ") is not brought up to the caret's location, but is removed.  Similar for BACKSPACE when:
/**
 * the comment
 * <<CARET>>
 */
such that 4 BACKSPACES are not necessary to return to the previous line.

The strategy also reflows the current paragraph whenever you delete characters on the current line, and the first word on the next line can fit at the end of the current line.
The strategy respects indentation such as when writing nested HTML:
/**
 * <OL>
 *     <LI>item 1<<CARET>>
 *     <LI>item 3
 *     <LI>item 4 is really long, and when it wraps at
 *      the margin, it respects current indentation.
 * </OL>
..such that typing ENTER at the caret will inserts a new line with the same amount of intendation

It took me 1 and half days to implement, and I've been using it for the last 2 days.  I don't claim it to be bug free or that its behavior is perfect, but it is extremely useful when writing DOC.  It only wraps during common editing functions like typing a single character.  I did handle PASTE yet.  I'm not sure if you can use any of the code as is, but once you have tried it out, it will be clear to you that feature should be added.  Some behavior is limited by the Text architecture, such as undo not being "atomic".

I am using this "patch" with 2.0.1, but I believe it will work with 2.1 builds.  To try it out on 2.0.X, you need to add textpatch.jar to the org.eclipse.ui plugin, and hack the plugin.xml to include that JAR first.  This jar contains backported methods from 2.1's TextViewer and DocumentCommand class that allow me to place the Caret properly and consume the VerifyEvent.

The actual strategy is in jdtpatch.jar, and can be tested by hacking the org.eclipse.jdt.ui plugin.xml to include that JAR first.  Place both jars in their respective plugin's folders.

-Randy


Attachment: jdtpatch.jar
Description: Binary data

Attachment: textpatch.jar
Description: Binary data


Back to the top