JML

org.multijava.mjc
Class TestMjcParser

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.multijava.util.testing.TestCase
              extended byorg.multijava.mjc.TestMjcParser
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
TestJmlParser.Helper

public class TestMjcParser
extends TestCase

Unit tests for MjcParser


Nested Class Summary
protected static class TestMjcParser.TestCompiler
           
 
Field Summary
protected  Main compiler
           
private static JavadocLexer docLexer
           
static StringBuffer errorOut
           
private static MjcLexer mjLexer
           
private static MjcParser parser
           
private static ParsingController parsingController
          Used to switch lexers.
private static String SAMPLE_AUG_METHOD
           
private static String SAMPLE_CLASS
           
private static String SAMPLE_DOC
           
private static String SAMPLE_DOC_CLASS
           
private static String SAMPLE_DOC_CONTENT
           
private static String SAMPLE_FIELD
           
private static String SAMPLE_INIT
           
private static String SAMPLE_INIT2
           
private static String SAMPLE_INNER_CLASS
           
private static String SAMPLE_INTERFACE
           
private static String SAMPLE_METHOD
           
 
Fields inherited from class org.multijava.util.testing.TestCase
NEWLINE
 
Fields inherited from class junit.framework.TestCase
 
Constructor Summary
TestMjcParser(String name)
           
TestMjcParser(String name, ModifierUtility modUtil)
           
 
Method Summary
protected  void establishTest(String sourceCode)
          Establish lexers and parsers for the given source code, including parsing of javadoc comments.
protected  void establishTest(String sourceCode, boolean parseJavadocs)
          Establish lexers and parsers for the given source code, parsing javadoc comments according to the given boolean.
protected  JCompilationUnitType getAST(String sourceCode)
          Returns an AST for the source code represented by the given string.
protected  JCompilationUnitType getAST(String sourceCode, boolean parseJavadocs)
          Returns an AST for the source code represented by the given string.
 void test_comment_parsing_1()
           
 void test_comment_parsing_2()
           
 void test_ignore_misplaced_javadoc_parsing1()
          Should ignore javadoc comment preceding the package declaration.
 void test_ignore_misplaced_javadoc_parsing10()
          Should ignore javadoc comments inside a method declaration.
 void test_ignore_misplaced_javadoc_parsing11()
          Should ignore javadoc comments inside a field declaration.
 void test_ignore_misplaced_javadoc_parsing12()
          Should ignore javadoc comments inside an initializer declaration.
 void test_ignore_misplaced_javadoc_parsing13()
          Should ignore javadoc comments inside an if-else statement.
 void test_ignore_misplaced_javadoc_parsing2()
          Should ignore javadoc comment between "public" and "class".
 void test_ignore_misplaced_javadoc_parsing3()
          Should ignore javadoc comment between "class" and "Sample".
 void test_ignore_misplaced_javadoc_parsing4()
          Should ignore javadoc comment between "Sample" and "{".
 void test_ignore_misplaced_javadoc_parsing5()
          Should ignore javadoc comment inside empty class body.
 void test_ignore_misplaced_javadoc_parsing6()
          Should ignore evil javadoc comment inside empty class body while successfully parsing the class.
 void test_ignore_misplaced_javadoc_parsing7()
          Should ignore javadoc comments inside an interface declaration.
 void test_ignore_misplaced_javadoc_parsing8()
          Should ignore javadoc comments inside an augmenting method declaration.
 void test_ignore_misplaced_javadoc_parsing9()
          Should ignore javadoc comments inside an empty inner class declaration.
 void test_initMods_1()
           
 void test_initMods_2()
           
 void test_initMods_3()
           
 void test_initMods_4()
           
 void testAugmentingMethodDeclJavadocParsing1()
          Should handle javadoc comments for an augmenting method declaration.
 void testClassDeclJavadocParsing1()
          Should handle a class declaration preceded by a javadoc comment.
 void testClassDeclJavadocParsing2()
          Should handle javadoc comment for a class declaration.
 void testClassDeclJavadocParsing3()
          Should handle empty javadoc comment.
 void testClassDeclJavadocParsing4()
          Should handle two javadoc comments for a single class declaration.
 void testClassDeclJavadocParsing5()
          Should get a null javadoc comment for a class declaration when javadoc parsing is disabled.
 void testClassDeclParsing()
          Should handle a class declaration without a javadoc comment.
 void testFieldJavadocParsing1()
          Should handle javadoc comments for a field declaration.
 void testInitializerJavadocParsing1()
          Should handle javadoc comments for an initializer declaration.
 void testInnerClassJavadocParsing1()
          Should handle javadoc comments for an inner class declaration.
 void testInterfaceDeclJavadocParsing1()
          Should handle javadoc comments for an interface declaration.
 void testMethodJavadocParsing1()
          Should handle javadoc comments for a method declaration.
 
Methods inherited from class org.multijava.util.testing.TestCase
assertDiff, assertEquals
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mjLexer

private static MjcLexer mjLexer

docLexer

private static JavadocLexer docLexer

parser

private static MjcParser parser

parsingController

private static ParsingController parsingController
Used to switch lexers. Aliases are created within lexer instances.


errorOut

public static final StringBuffer errorOut

compiler

protected Main compiler

SAMPLE_DOC_CONTENT

private static final String SAMPLE_DOC_CONTENT

SAMPLE_DOC

private static final String SAMPLE_DOC

SAMPLE_CLASS

private static final String SAMPLE_CLASS

SAMPLE_INTERFACE

private static final String SAMPLE_INTERFACE

SAMPLE_AUG_METHOD

private static final String SAMPLE_AUG_METHOD

SAMPLE_DOC_CLASS

private static final String SAMPLE_DOC_CLASS

SAMPLE_INNER_CLASS

private static final String SAMPLE_INNER_CLASS

SAMPLE_METHOD

private static final String SAMPLE_METHOD

SAMPLE_FIELD

private static final String SAMPLE_FIELD

SAMPLE_INIT

private static final String SAMPLE_INIT

SAMPLE_INIT2

private static final String SAMPLE_INIT2
Constructor Detail

TestMjcParser

public TestMjcParser(String name)

TestMjcParser

public TestMjcParser(String name,
                     ModifierUtility modUtil)
Method Detail

testClassDeclParsing

public void testClassDeclParsing()
                          throws antlr.RecognitionException,
                                 antlr.TokenStreamException
Should handle a class declaration without a javadoc comment.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

testClassDeclJavadocParsing1

public void testClassDeclJavadocParsing1()
                                  throws antlr.RecognitionException,
                                         antlr.TokenStreamException
Should handle a class declaration preceded by a javadoc comment.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

testClassDeclJavadocParsing2

public void testClassDeclJavadocParsing2()
                                  throws antlr.RecognitionException,
                                         antlr.TokenStreamException
Should handle javadoc comment for a class declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

testClassDeclJavadocParsing3

public void testClassDeclJavadocParsing3()
                                  throws antlr.RecognitionException,
                                         antlr.TokenStreamException
Should handle empty javadoc comment.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

testClassDeclJavadocParsing4

public void testClassDeclJavadocParsing4()
                                  throws antlr.RecognitionException,
                                         antlr.TokenStreamException
Should handle two javadoc comments for a single class declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

testClassDeclJavadocParsing5

public void testClassDeclJavadocParsing5()
                                  throws antlr.RecognitionException,
                                         antlr.TokenStreamException
Should get a null javadoc comment for a class declaration when javadoc parsing is disabled.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

testInterfaceDeclJavadocParsing1

public void testInterfaceDeclJavadocParsing1()
                                      throws antlr.RecognitionException,
                                             antlr.TokenStreamException
Should handle javadoc comments for an interface declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

testAugmentingMethodDeclJavadocParsing1

public void testAugmentingMethodDeclJavadocParsing1()
                                             throws antlr.RecognitionException,
                                                    antlr.TokenStreamException
Should handle javadoc comments for an augmenting method declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

testInnerClassJavadocParsing1

public void testInnerClassJavadocParsing1()
                                   throws antlr.RecognitionException,
                                          antlr.TokenStreamException
Should handle javadoc comments for an inner class declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

testMethodJavadocParsing1

public void testMethodJavadocParsing1()
                               throws antlr.RecognitionException,
                                      antlr.TokenStreamException
Should handle javadoc comments for a method declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

testFieldJavadocParsing1

public void testFieldJavadocParsing1()
                              throws antlr.RecognitionException,
                                     antlr.TokenStreamException
Should handle javadoc comments for a field declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

testInitializerJavadocParsing1

public void testInitializerJavadocParsing1()
                                    throws antlr.RecognitionException,
                                           antlr.TokenStreamException
Should handle javadoc comments for an initializer declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_ignore_misplaced_javadoc_parsing1

public void test_ignore_misplaced_javadoc_parsing1()
                                            throws antlr.RecognitionException,
                                                   antlr.TokenStreamException
Should ignore javadoc comment preceding the package declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_ignore_misplaced_javadoc_parsing2

public void test_ignore_misplaced_javadoc_parsing2()
                                            throws antlr.RecognitionException,
                                                   antlr.TokenStreamException
Should ignore javadoc comment between "public" and "class".

Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_ignore_misplaced_javadoc_parsing3

public void test_ignore_misplaced_javadoc_parsing3()
                                            throws antlr.RecognitionException,
                                                   antlr.TokenStreamException
Should ignore javadoc comment between "class" and "Sample".

Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_ignore_misplaced_javadoc_parsing4

public void test_ignore_misplaced_javadoc_parsing4()
                                            throws antlr.RecognitionException,
                                                   antlr.TokenStreamException
Should ignore javadoc comment between "Sample" and "{".

Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_ignore_misplaced_javadoc_parsing5

public void test_ignore_misplaced_javadoc_parsing5()
                                            throws antlr.RecognitionException,
                                                   antlr.TokenStreamException
Should ignore javadoc comment inside empty class body.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_ignore_misplaced_javadoc_parsing6

public void test_ignore_misplaced_javadoc_parsing6()
                                            throws antlr.RecognitionException,
                                                   antlr.TokenStreamException
Should ignore evil javadoc comment inside empty class body while successfully parsing the class.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_ignore_misplaced_javadoc_parsing7

public void test_ignore_misplaced_javadoc_parsing7()
                                            throws antlr.RecognitionException,
                                                   antlr.TokenStreamException
Should ignore javadoc comments inside an interface declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_ignore_misplaced_javadoc_parsing8

public void test_ignore_misplaced_javadoc_parsing8()
                                            throws antlr.RecognitionException,
                                                   antlr.TokenStreamException
Should ignore javadoc comments inside an augmenting method declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_ignore_misplaced_javadoc_parsing9

public void test_ignore_misplaced_javadoc_parsing9()
                                            throws antlr.RecognitionException,
                                                   antlr.TokenStreamException
Should ignore javadoc comments inside an empty inner class declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_ignore_misplaced_javadoc_parsing10

public void test_ignore_misplaced_javadoc_parsing10()
                                             throws antlr.RecognitionException,
                                                    antlr.TokenStreamException
Should ignore javadoc comments inside a method declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_ignore_misplaced_javadoc_parsing11

public void test_ignore_misplaced_javadoc_parsing11()
                                             throws antlr.RecognitionException,
                                                    antlr.TokenStreamException
Should ignore javadoc comments inside a field declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_ignore_misplaced_javadoc_parsing12

public void test_ignore_misplaced_javadoc_parsing12()
                                             throws antlr.RecognitionException,
                                                    antlr.TokenStreamException
Should ignore javadoc comments inside an initializer declaration.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_ignore_misplaced_javadoc_parsing13

public void test_ignore_misplaced_javadoc_parsing13()
                                             throws antlr.RecognitionException,
                                                    antlr.TokenStreamException
Should ignore javadoc comments inside an if-else statement.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_initMods_1

public void test_initMods_1()
                     throws antlr.RecognitionException,
                            antlr.TokenStreamException
Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_initMods_2

public void test_initMods_2()
                     throws antlr.RecognitionException,
                            antlr.TokenStreamException
Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_initMods_3

public void test_initMods_3()
                     throws antlr.TokenStreamException
Throws:
antlr.TokenStreamException

test_initMods_4

public void test_initMods_4()
                     throws antlr.RecognitionException,
                            antlr.TokenStreamException
Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_comment_parsing_1

public void test_comment_parsing_1()
                            throws antlr.RecognitionException,
                                   antlr.TokenStreamException
Throws:
antlr.RecognitionException
antlr.TokenStreamException

test_comment_parsing_2

public void test_comment_parsing_2()
                            throws antlr.RecognitionException,
                                   antlr.TokenStreamException
Throws:
antlr.RecognitionException
antlr.TokenStreamException

establishTest

protected void establishTest(String sourceCode)
Establish lexers and parsers for the given source code, including parsing of javadoc comments.


establishTest

protected void establishTest(String sourceCode,
                             boolean parseJavadocs)
Establish lexers and parsers for the given source code, parsing javadoc comments according to the given boolean.


getAST

protected JCompilationUnitType getAST(String sourceCode)
                               throws antlr.RecognitionException,
                                      antlr.TokenStreamException
Returns an AST for the source code represented by the given string. The AST is annotated with any javadocs annotations that appear in the string.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

getAST

protected JCompilationUnitType getAST(String sourceCode,
                                      boolean parseJavadocs)
                               throws antlr.RecognitionException,
                                      antlr.TokenStreamException
Returns an AST for the source code represented by the given string. If the parseJavadocs flag is true, then the AST is annotated with any javadocs that appear in the string.

Throws:
antlr.RecognitionException
antlr.TokenStreamException

JML

JML is Copyright (C) 1998-2002 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This release depends on code from the MultiJava project and is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.