Netbeans Rcp Antlr Format And Indent
I do not have the formatting and indenting fully working yet, but I did figure out the integration points. It took me almost a full day to figure out how to just get that working so I figure it was worth at least starting a tutorial.
It is actually quite simple! And, once you have things registered correctly, the next step (to be documented later) will be to use your ANTLR Lexer to do the formatting.
This is part of the ANTLR integration tutorials.
IndentTask
1.
The indent task will make a callback to the reindent() method when the enter key is pressed while editing. The Context object contains everything that you will need, including the editor document object. It should just be a matter of taking the text after the cursor and before the next line and indenting things properly.
public class SqlIndentTask implements IndentTask {
private Context context;
SqlIndentTask(Context context) {
this.context = context;
}
public void reindent() throws BadLocationException {
System.out.println("we will indent this now");
}
public ExtraLock indentLock() {
return null;
}
}
ReformatTask
1.
The reformat task will make a callback to the reformat() method when you invoke the built in Netbeans format command. In other words when you use the menu Source → Format action or press Alt+Shift+F. The Context object contains everything that you will need, including the editor document object. It should just be a matter of taking the text and running it through the ANTLR Lexer to format things properly.
public class SqlReformatTask implements ReformatTask {
private Context context;
public SqlReformatTask(Context context) {
this.context = context;
}
@Override
public void reformat()
throws BadLocationException {
System.out.println("we will format this now");
}
@Override
public ExtraLock reformatLock() {
return null;
}
}