Dresden OCL Toolkit

tudresden.ocl.injection
Class Injector

java.lang.Object
  extended bytudresden.ocl.injection.Injector

public final class Injector
extends Object

Implements a modifying java parser. This means, the input stream is continuesly written into an output stream, and may be modified before writing. The parser recognizes java meta information only, which is anything outside method bodies and attribute inizializers. To use the parser, provide an implemention of the InjectionConsumer interface to the constructor.

See Also:
InjectionConsumer

Nested Class Summary
private  class Injector.EndException
           
private  class Injector.ParseException
           
 
Field Summary
private  StringBuffer buf
           
private  boolean collect_when_blocking
           
private  StringBuffer collector
           
private  String comment
           
private  String commentBuf
           
private  InjectionConsumer consumer
           
private  boolean do_block
           
private  String doccomment
           
private  Reader input
           
private  JavaFile javafile
           
private  int linenumber
          The line number in the current file.
private  int lineposition
          The character in the current line.
private  char outbuf
           
private  boolean outbufvalid
           
private  Writer output
           
private  boolean start_block
           
private  char tokenBuf
           
 
Constructor Summary
Injector(Reader input, Writer output, InjectionConsumer consumer)
          Constructs a new java parser.
 
Method Summary
static Map extractDocParagraphs(String doccomment)
           
static String findDocTag(String doccomment, String tagname)
           
private  void flushOutbuf()
           
private  String getCollector()
           
private static Map makeResult(Map result, String tagname, StringBuffer buf)
           
private  JavaAttribute[] parseAttribute(JavaAttribute ja, char c)
           
private  void parseBehaviour(JavaBehaviour jb)
           
private  char parseBody(boolean attribute)
          Parses a method body or an attribute initializer, depending on the parameter.
private  JavaClass parseClass(JavaClass parent, int modifiers)
           
private  JavaFeature[] parseFeature(JavaClass parent)
          Parses a class feature.
private  JavaFeature[] parseFeature(JavaClass parent, String bufs)
          The same as parseFeature(JavaClass) but the first token has already been fetched from the input stream.
 void parseFile()
           
 char read()
           
private  int readComment()
          Reads a comment.
private  char readToken()
          Splits the character stream into tokens.
private  void scheduleBlock(boolean collect_when_blocking)
           
private  void write(String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

input

private Reader input

output

private Writer output

consumer

private InjectionConsumer consumer

buf

private StringBuffer buf

do_block

private boolean do_block

start_block

private boolean start_block

collect_when_blocking

private boolean collect_when_blocking

collector

private StringBuffer collector

doccomment

private String doccomment

javafile

private JavaFile javafile

outbuf

private char outbuf

outbufvalid

private boolean outbufvalid

linenumber

private int linenumber
The line number in the current file.


lineposition

private int lineposition
The character in the current line.


tokenBuf

private char tokenBuf

commentBuf

private String commentBuf

comment

private String comment
Constructor Detail

Injector

public Injector(Reader input,
                Writer output,
                InjectionConsumer consumer)
Constructs a new java parser.

See Also:
InjectionConsumer
Method Detail

read

public final char read()
                throws IOException,
                       Injector.EndException
Throws:
IOException
Injector.EndException

scheduleBlock

private void scheduleBlock(boolean collect_when_blocking)

getCollector

private String getCollector()

flushOutbuf

private void flushOutbuf()
                  throws IOException
Throws:
IOException

write

private void write(String s)
            throws IOException
Throws:
IOException

readComment

private int readComment()
                 throws IOException,
                        Injector.EndException
Reads a comment. Is started after the initial '/' character. If the next character is either '/' or '*', the rest of the comment is read, and a value of -1 is returned. If not, there is no comment, and this next character is returned, casted to int.

Throws:
IOException
Injector.EndException

readToken

private char readToken()
                throws IOException,
                       Injector.EndException
Splits the character stream into tokens. This tokenizer works only outside of method bodys.

Returns:
'\0' for multiple character token in buf, 'c' for comment token in comment, else for single character token.
Throws:
IOException
Injector.EndException

parseBody

private char parseBody(boolean attribute)
                throws IOException,
                       Injector.EndException,
                       Injector.ParseException
Parses a method body or an attribute initializer, depending on the parameter. For method bodys, the input stream must be directly behind the first opening curly bracket of the body. For attribute initializers, the input stream must be directly behind the '='.

Returns:
the delimiter, which terminated the attribute initializer (';' or ',') or '}' for methods.
Throws:
IOException
Injector.EndException
Injector.ParseException

parseFeature

private JavaFeature[] parseFeature(JavaClass parent)
                            throws IOException,
                                   Injector.EndException,
                                   InjectorParseException
Parses a class feature. May be an attribute, a method or a inner class. May even be a normal class, in this case parent==null.

Throws:
IOException
Injector.EndException
InjectorParseException

parseFeature

private JavaFeature[] parseFeature(JavaClass parent,
                                   String bufs)
                            throws IOException,
                                   Injector.EndException,
                                   InjectorParseException
The same as parseFeature(JavaClass) but the first token has already been fetched from the input stream.

Throws:
IOException
Injector.EndException
InjectorParseException
See Also:
parseFeature(JavaClass)

parseBehaviour

private void parseBehaviour(JavaBehaviour jb)
                     throws IOException,
                            Injector.EndException,
                            Injector.ParseException
Throws:
IOException
Injector.EndException
Injector.ParseException

parseAttribute

private JavaAttribute[] parseAttribute(JavaAttribute ja,
                                       char c)
                                throws IOException,
                                       Injector.EndException,
                                       InjectorParseException
Throws:
IOException
Injector.EndException
InjectorParseException

parseClass

private JavaClass parseClass(JavaClass parent,
                             int modifiers)
                      throws IOException,
                             Injector.EndException,
                             InjectorParseException
Throws:
IOException
Injector.EndException
InjectorParseException

parseFile

public void parseFile()
               throws IOException,
                      InjectorParseException
Throws:
IOException
InjectorParseException

findDocTag

public static final String findDocTag(String doccomment,
                                      String tagname)
Returns:
the first word following the tag

makeResult

private static final Map makeResult(Map result,
                                    String tagname,
                                    StringBuffer buf)

extractDocParagraphs

public static final Map extractDocParagraphs(String doccomment)

Dresden OCL Toolkit

Submit a bug
Developed at the Dresden University of Technology.
This software is published under the GNU Lesser General Public License.