system
Class CommentConverter

java.lang.Object
  extended bysystem.CommentConverter

public class CommentConverter
extends Object

This class opens up the given file and converts the comments when you call the various methods. It can also add comments where there are not comments yet. After you made all your changes, call save() to write them to the file.

Since:
1.00
Version:
1.02
Author:
Berend "Kirk" Wouda

Field Summary
protected  kirk.io.FileLineList file
          The FileLineList that is used for editing the file.
protected  boolean starinsets
          Whether or not this CommentConverter uses the star insets style of javadoc commenting.
 
Constructor Summary
CommentConverter(String filename, boolean starinsets)
          Constructs a new CommentConverter over filename, and sets the appropriate javadoc style.
 
Method Summary
 void addAttributeComments(String[] tags, int whitelines)
          Adds all the javadoc attribute comments to all attributes without comment in this file using the set style.
 void addClassComments(String[] tags, int whitelines)
          Adds all the javadoc class comments to all classes without comment in this file using the set style.
protected  void addComment(int index, String[] tags, int whitelines)
          Adds comment above index with the set javadoc style comment.
 void addMethodComments(String[] tags, int whitelines)
          Adds all the javadoc method comments to all methods without comment in this file using the set style.
 void convertAttributeComments(String[] tags)
          Converts all the non-javadoc attribute comments in this file to javadoc comments using the set style.
 void convertClassComments(String[] tags)
          Converts all the non-javadoc class comments in this file to javadoc comments using the set style.
 void convertMethodComments(String[] tags)
          Converts all the non-javadoc method comments in this file to javadoc comments using the set style.
protected  String[] convertMethodTags(int index, String[] tags)
          Goes through tags and convert any special javadoc tags that have to with the method signature at index.
protected  String getIndentation(int index)
          Returns the indentation of the line at index as a String.
protected  boolean isAttribute(int index)
          Returns whether the line indicated by index is an attribute line.
protected  boolean isClass(int index)
          Returns whether the line indicated by index is a class line.
protected  boolean isMethod(int index)
          Returns whether the line indicated by index is a method line.
protected  boolean isToken(int fileindex, int tokenindex, String string, boolean precise)
          Returns whether the token on tokenindex in the String at index in file, is equal to the passed string, when tokenized on whitespace.
protected  void replaceComment(int index, String[] tags)
          Replaces the comment above index with the set javadoc style comment.
 void save(String filename)
          Saves the changes this class made to the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

protected kirk.io.FileLineList file
The FileLineList that is used for editing the file.


starinsets

protected boolean starinsets
Whether or not this CommentConverter uses the star insets style of javadoc commenting.

Constructor Detail

CommentConverter

public CommentConverter(String filename,
                        boolean starinsets)
                 throws IOException
Constructs a new CommentConverter over filename, and sets the appropriate javadoc style.

Parameters:
filename - The name of the file to be opened.
starinsets - The javadoc style. true when the star insets should be used, false for no star insets.
Throws:
IOException - When an IO error is encountered.
Method Detail

save

public void save(String filename)
          throws IOException
Saves the changes this class made to the file.

Parameters:
filename - The name of the file to save to.
Throws:
IOException

convertClassComments

public void convertClassComments(String[] tags)
Converts all the non-javadoc class comments in this file to javadoc comments using the set style. Also it puts in any class tags that are requested.

Parameters:
tags - An array of Strings. Each String is a javadoc tag or something that the user wanted in all class comments.

addClassComments

public void addClassComments(String[] tags,
                             int whitelines)
Adds all the javadoc class comments to all classes without comment in this file using the set style. Also it puts in any class tags that are requested, as well as the requested amount of white lines.

Parameters:
tags - An array of Strings. Each String is a javadoc tag or something that the user wanted in all class comments.
whitelines - The number of white lines that has to be in each class comment.

convertMethodComments

public void convertMethodComments(String[] tags)
                           throws Exception
Converts all the non-javadoc method comments in this file to javadoc comments using the set style. Also it puts in any method tags that are requested.

Parameters:
tags - An array of Strings. Each String is a javadoc tag or something that the user wanted in all method comments.
Throws:
Exception - When a file format error is encountered.

addMethodComments

public void addMethodComments(String[] tags,
                              int whitelines)
                       throws Exception
Adds all the javadoc method comments to all methods without comment in this file using the set style. Also it puts in any method tags that are requested, as well as the requested amount of white lines.

Parameters:
tags - An array of Strings. Each String is a javadoc tag or something that the user wanted in all method comments.
whitelines - The number of white lines that has to be in each method comment.
Throws:
Exception - When a file format error is encountered.

convertAttributeComments

public void convertAttributeComments(String[] tags)
Converts all the non-javadoc attribute comments in this file to javadoc comments using the set style. Also it puts in any attribute tags that are requested.

Parameters:
tags - An array of Strings. Each String is a javadoc tag or something that the user wanted in all attribute comments.

addAttributeComments

public void addAttributeComments(String[] tags,
                                 int whitelines)
Adds all the javadoc attribute comments to all attributes without comment in this file using the set style. Also it puts in any attribute tags that are requested, as well as the requested amount of white lines.

Parameters:
tags - An array of Strings. Each String is a javadoc tag or something that the user wanted in all attribute comments.
whitelines - The number of white lines that has to be in each attribute comment.

convertMethodTags

protected String[] convertMethodTags(int index,
                                     String[] tags)
                              throws Exception
Goes through tags and convert any special javadoc tags that have to with the method signature at index. When this method is called, it is assumed that there is a method there.

Parameters:
index - The index of the method signature where the info comes from.
tags - The tags to be converted.
Returns:
The converted tags.
Throws:
Exception - When a file format error is encountered.

isClass

protected boolean isClass(int index)

Returns whether the line indicated by index is a class line. Examples of class lines:

etc.

Parameters:
index - The line that needs to be checked.
Returns:
Whether the line indicated by index is a class line.

isMethod

protected boolean isMethod(int index)

Returns whether the line indicated by index is a method line. Examples of method lines:

etc.

Parameters:
index - The line that needs to be checked.
Returns:
Whether the line indicated by index is a method line.

isAttribute

protected boolean isAttribute(int index)

Returns whether the line indicated by index is an attribute line. Examples of attribute lines:


isToken

protected boolean isToken(int fileindex,
                          int tokenindex,
                          String string,
                          boolean precise)

Returns whether the token on tokenindex in the String at index in file, is equal to the passed string, when tokenized on whitespace.

A bit cheating, but if you specify a negative number as an index then any token is allowed to match.

Parameters:
fileindex - The index of the String to check.
tokenindex - The index of the token to check.
string - The string to be checked for.
precise - Whether the matching has to be precise, or it has to starts with string.
Returns:
Whether the token is equal to string. false in any case if tokenindex is larger than the amount of tokens in the String, or when fileindex is out of bounds.

replaceComment

protected void replaceComment(int index,
                              String[] tags)
Replaces the comment above index with the set javadoc style comment. Note that white lines in comment that isn't multiline comment will break off the comment converting. This is because it's too much trouble to distinguish them from class/method/attribute seperating whitelines, which we like to keep. They probably won't happen much anyways.

Parameters:
index - The index of the method/class/attribute that needs comment converted.
tags - The tags to be inserted.

addComment

protected void addComment(int index,
                          String[] tags,
                          int whitelines)
Adds comment above index with the set javadoc style comment. Note that anything that is above index will move "upwards" so to speak, but the line directly above index (the line on index - 1) may not contain comment, cause comment should be converted then.

Parameters:
index - The index of the method/class/attribute that needs comment converted.
tags - The tags to be inserted.
whitelines - The amount of white lines to be inserted.

getIndentation

protected String getIndentation(int index)
Returns the indentation of the line at index as a String.

Parameters:
index - The index of the line of which the indentation is to be returned.
Returns:
The indentation of the line at index.