qdox-1.12/ 0000755 0001750 0001750 00000000000 11552640354 012311 5 ustar drazzib drazzib qdox-1.12/pom.xml 0000644 0001750 0001750 00000043115 11404460503 013622 0 ustar drazzib drazzib
4.0.0
QDox
com.thoughtworks.qdox
qdox
1.12
jar
http://qdox.codehaus.org
QDox is a high speed, small footprint parser for extracting class/interface/method definitions from source files
complete with JavaDoc @tags. It is designed to be used by active code generators or documentation tools.
2002
The Apache Software License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0.txt
repo
announce at QDox
announce@qdox.codehaus.org
announce-subscribe@qdox.codehaus.org
announce-unsubscribe@qdox.codehaus.org
http://archive.codehaus.org/lists/org.codehaus.qdox.announce
dev at QDox
dev@qdox.codehaus.org
dev-subscribe@qdox.codehaus.org
dev-unsubscribe@qdox.codehaus.org
http://archive.codehaus.org/lists/org.codehaus.qdox.dev
scm at QDox
scm-subscribe@qdox.codehaus.org
scm-unsubscribe@qdox.codehaus.org
http://archive.codehaus.org/lists/org.codehaus.qdox.scm
user at QDox
user@qdox.codehaus.org
user-subscribe@qdox.codehaus.org
user-unsubscribe@qdox.codehaus.org
http://archive.codehaus.org/lists/org.codehaus.qdox.user
jira
http://jira.codehaus.org/browse/QDOX
scm:svn:https://svn.codehaus.org/qdox/tags/qdox-1.12
scm:svn:https://svn.codehaus.org/qdox/tags/qdox-1.12
http://svn.qdox.codehaus.org/browse/qdox/tags/qdox-1.12
rfscholte
Robert Scholte
+1
project lead
joe
Joe Walnes
project founder
Aslak Hellesoy
rinkrank
developer
Paul Hammant
paul
developer
Mike Williams
mdub
developer
mauro
Mauro Talevi
developer
Mike Royle
Peter Donald
James Strachan
Nick Pomfret
Chris Stevenson
Ben Hogan
Laurent Etiemble
Shawn Chain
Brian Slesinsky
James Lee
Eric Redmond
org.apache.maven.wagon
wagon-webdav
1.0-beta-2
${basedir}/src/java
${basedir}/src/test
${basedir}/src/test-resources
maven-clean-plugin
2.2
maven-surefire-plugin
2.4.2
maven-jar-plugin
2.2
maven-install-plugin
2.2
maven-deploy-plugin
2.3
de.jflex
maven-jflex-plugin
1.4.3
generate
${project.build.directory}/generated-sources/parser
${basedir}/src/grammar/lexer.flex
${basedir}/src/grammar/skeleton.inner
maven-antrun-plugin
1.3
OS Arch = ${os.arch}
${project.build.directory}/generated-sources/parser
generate-sources
generate-sources
run
org.apache.maven.plugins
maven-compiler-plugin
2.0.2
1.4
1.4
UTF-8
org.apache.maven.plugins
maven-javadoc-plugin
2.4
attach-javadoc
package
jar
http://java.sun.com/j2se/1.5/docs/api
org.apache.maven.plugins
maven-assembly-plugin
2.2-beta-5
project
make-assembly
package
single
maven-site-plugin
2.0
${basedir}/src/site/templates/site-template.vm
org.codehaus.xsite
xsite-maven-plugin
1.0
content/website.xml
templates/skin.html
${xsite.sourceDirectoryPath}
${project.build.directory}/site
resources
site
run
maven-resources-plugin
2.3
pre-copy-resources
pre-site
copy-resources
${xsite.sourceDirectoryPath}
src/site
**/download.html
**/skin.html
src/site
**/download.html
**/skin.html
true
post-copy-resources
site
copy-resources
${project.build.directory}/site
${xsite.sourceDirectoryPath}/content
images/*.*
apidocs/**/*.*
org.apache.maven.plugins
maven-release-plugin
2.0
true
clean install
deploy
https://svn.codehaus.org/qdox/tags
-P!release-site -Dproject.rel.org.thoughtworks.qdox:qdox=${project.rel.org.thoughtworks.qdox:qdox} -Dproject.dev.org.thoughtworks.qdox:qdox=${project.dev.org.thoughtworks.qdox:qdox}
ant
ant
1.5.1
compile
true
junit
junit
3.8.1
compile
true
jmock
jmock
1.0.0
test
codehaus.org
QDox Central Repository
dav:https://dav.codehaus.org/repository/qdox/
codehaus.org
QDox Central Development Repository
dav:https://dav.codehaus.org/snapshots.repository/qdox/
codehaus.org
QDox Site
dav:https://dav.codehaus.org/qdox/
linux
Linux
i386
${basedir}/bootstrap/yacc.linux
linux64
Linux
amd64
${basedir}/bootstrap/yacc.linux.x86_64
solaris
SunOS
${basedir}/bootstrap/yacc.solaris
macosx
Mac
${basedir}/bootstrap/yacc.macosx
windows
Windows
${basedir}/bootstrap/yacc.exe
${xsite.sourceDirectoryPath}/content
org.apache.maven.plugins
maven-project-info-reports-plugin
2.1
dependencies
project-team
mailing-list
issue-tracking
license
scm
summary
org.codehaus.mojo
cobertura-maven-plugin
2.2
org.apache.maven.plugins
maven-javadoc-plugin
2.4
com.thoughtworks.qdox.*
true
${project.name} ${project.version} API
UTF-8
org.apache.maven.plugins
maven-changes-plugin
2.1
%URL%/%ISSUE%
changes-report
yyyy-MM-dd
${maven.build.timestamp}
${project.build.directory}/generated-site
qdox-1.12/LICENSE.txt 0000644 0001750 0001750 00000001101 11141545040 014113 0 ustar drazzib drazzib Copyright 2002-2009 Joe Walnes and QDox Project Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
qdox-1.12/README.txt 0000644 0001750 0001750 00000002305 11150023612 013771 0 ustar drazzib drazzib To build QDox there are two prerequisites:
* Maven 2 (2.0.9 or later)
http://maven.apache.org
* BYacc/J (1.8 or later)
http://byaccj.sourceforge.net/
Paarser generator used to create an effective parser for JavaDoc.
If using Windows, Linux, Solaris or Mac OS X, no additional installation is
needed as yacc binaries are supplied in the bootstrap directory.
If using any other platform, download BYacc/J from the site or build it yourself, in which case
we would be grateful to receive a copy of your binary, so we can upgrade the bootstrap support.
Build goals:
mvn install - Create qdox jar
mvn generate-sources - Generate the Java parser code (allowing you to develop in an IDE).
mvn site - Build the QDox website
mvn release:prepare - Prepare release (confirm or change release version interactively)
mvn release:perform - Perform release (perform release from tag of prepare phase)
If you are releasing, remember to
1) Update src/site/content/download.html
2) Go to JIRA and release the applicable version for QDOX : http://jira.codehaus.org/secure/project/ManageVersions.jspa?pid=10103
3) Copy the contents of target/site/ to the DAV folder for QDox's website : https://dav.codehaus.org/qdox/ qdox-1.12/src/ 0000755 0001750 0001750 00000000000 11552640352 013076 5 ustar drazzib drazzib qdox-1.12/src/test-resources/ 0000755 0001750 0001750 00000000000 11552640352 016065 5 ustar drazzib drazzib qdox-1.12/src/test-resources/readme.txt 0000644 0001750 0001750 00000000076 11147774447 020103 0 ustar drazzib drazzib this folder is introduces to have a solid way to test qdox-148 qdox-1.12/src/test-resources/qdox-140/ 0000755 0001750 0001750 00000000000 11552640352 017342 5 ustar drazzib drazzib qdox-1.12/src/test-resources/qdox-140/X.jav 0000644 0001750 0001750 00000000110 11150056440 020234 0 ustar drazzib drazzib interface X {
void paramWithNonAsciis\u00E4\u00F6\u00FC\u00DF();
} qdox-1.12/src/changes/ 0000755 0001750 0001750 00000000000 11552640352 014506 5 ustar drazzib drazzib qdox-1.12/src/changes/changes.xml 0000644 0001750 0001750 00000047132 11250554061 016643 0 ustar drazzib drazzib
Changes
Joe Walnes
AbstractJavaEntity#getCodeBlock() skips Javadoc separator
Unwanted DocletTag.getParameters()[0]=< in generic case
Multilined tag attribute values not working anymore
Parsing JavadocComment improvement
Add method to safely and easily get the package name for a JavaClass
Retaining whitespace in comments
QDox Site overhaul
Introduce toString() according to the Java Language Specification
JavaClass.getFullyQualifiedName() does not work on version 1.9 (version 1.6.3 works without problem). Manual resolve scanning imports are required
Annotation parsing fails on enum constant when javadoc present
Annotation with comment can't be parsed
Better handler of generics in Type
JavaField#getInitializationExpression() is wrong for char
ParseException when using annotations in methods
Parser fails to translate Unicode escapes
Qdox fails to parse enums inside class
QDOX-156 Remove single comment in JavaField#getInitializationExpression()
Wrong whitespace in JavaField#getInitializationExpression()
error parsing clauses with indexOf
most simple annotation, like @Override, results in a parseexception
make use of maven-jflex-plugin instead of an antrun
getInitializationExpression() includes comment text
More package information, not just package name.
Parser fails on package with annotations
QDox fails to parse correct code
Annotation with value in method signature does not parse
Annotations With Parameters do not work
Field modifiers of binary classes ignored
Multiple annotations on one field and generics
Name resolution of imported nested types does not work correctly
ParseException for private static String[] allConstants = {C1,C2,C3};
Parser fails depending on the position of an internal enum
Performance Improvement of JavaDocBuilder.getClassByName()
Static block source code gets associated with source code of subsequent method
Support for retrieval of generic type information (JSR 14)
add parser support for enumerated types
annotation value poluted with class instance block
inner classes not resolved correctly when appears as method param
packaging with java5+ fails due to incorrect javadocs
Improved annotation support including types, fields and expressions.
Fix to lexer bug.
Inconsistency between getMethods(), getFields() in binary and source JavaClass fixed.
Project version control web page shows CVS instead of SVN.
Migrate site to use XSite.
Improved generic parsing support.
Also fixes QDOX-108.
Improved annotation parsing support.
Improved anon inner class parsing support.
Maven2 support.
Original body of method can be obtained using JavaMethod.getSourceCode().
Original field initialization expression can be obtained by JavaField.getInitializationExpression().
Improved Enum parsing support.
Switched license from 'Ironsmith' Apache license clone to genuine Apache 2 license.
Provide line numbers for all java entities.
Ensure that things (e.g. named tag-parameters,
bean-properties) are consistently returned in declared
order.
Support for wildcard generic-type arguments.
Convenience methods - Type.isPrimitive() and Type.isVoid().
Parser can now handle Java 5 annotations.
Support for generic-type parameters on methods.
Support for Java 5 varargs syntax: "printf(Object... stuff)". New method, JavaParameter.isVarArgs().
JavaDoc comments now preserve end of line characters.
Support legal Unicode characters in identifiers.
Inner/nested classes are now resolved correctly between packages.
Correct terminology re "inner" vs "nested" classes.
Reinstate public constructors on concrete model classes.
Support for methods that specify array dimensions at end: String doStuff()[]
Static blocks do not add static modifier to next method.
Support for trailing semicolon after class definition.
Bugfix: Support for empty /**/ comments.
Patch from Mario Siegenthaler and Daniel Müller to improve
tolerance of Java 5 syntax, including: annotations with
classes as parameters, generic field initialization, static
imports and enums with enumeration ending with a semicolon.
Added QDoxTester to test that QDox can successfully parse a load of Java source.
Refactor DocletTag handling so that all context information
is provided via the DocletTagFactory.
Add support for parsing of JSR-14 generic types.
Also fixes QDOX-50.
Improve parsing of tag parameters, particularly where
whitespace is involved.
Fixed generation of Eclipse ".classpath".
Problems compiling against jmock-1.0.0.
Handle extra stars in Javadoc start/end tokens.
Handle unclosed quotes in tag values.
Support for strictfp modifier (and volatile and native).
JavaClass.getTagsByName() is buggy.
recursive retrieval of tags from superclasses got a bug.
Also fixes QDOX-37:
Handle inner-classes in type-resolution.
Support multiple fields in a single field-declaration.
Throw a ParseException, including location info, if a
syntax error is encountered.
Fix handling of MAC line-endings.
Allow "$" in identifiers.
Added DocletTag.getNamedParameterMap().
Added JavaField.getDeclarationSignature().
Support for binary classes.
Support for bean properties.
New isA(String fullyQualifiedName) method in JavaClass.
Pluggable DocletTag implementations via DocletTagFactory.
This opens up for tag validation, ${property} substitution
and other goodies that shouldn't go directly into QDox'
core, but rather into pluggable extensions.
Line numbers in the lexer.
resolveTypeInternal doesn't work for nested types.
JavaMethod.equals() failed for constructors.
BeanProperty : support for type retrieval.
Also fixes QDOX-19.
More robust handling of "*" and "@" in Javadoc body.
Encoding support for internationalization.
Type now has a getJavaClass() method making
it easier to find the JavaClass of a Type from e.g. Velocity.
Example: $method.returns.javaClass
Implemented tag inheritance on classes and methods. (It makes no sense
to have it on fields or constructors). Accessed with clazz|method.getTag[s]ByName(String name, boolean superclasses).
DocletTag is an interface.
Added a getClasses() method to JavaDocBuilder that will
return all JavaClasses.
Added a getDerivedClasses() method to JavaClass that will
return all derived classes, i.e. subclasses or subinterfaces.
Added getDeclarationSignature() and getCallSignature() methods
to JavaMethod.
Added a getNamedParameter(String tagName, String parameterName)
convenience method to AbstractJavaEntity for easier retrieval
of tag parameters without having to null-check the tag.
Added APITestCase. This is a JUnit extension that can be used
to compare the equality of two Java sources on the API level.
Added int getLineNumber() to DocletTag.
Added JavaSource getJavaSource() to DocletTag.
Added boolean isInner() to JavaClass.
Added JavaMethod[] getMethods(boolean superclasses) to JavaClass.
Quoted tokens allowed in doclet tags.
Asterix symbol allowed in doclet tags.
Added support for inner classes.
Moved build system over to Maven.
Initial release.
qdox-1.12/src/grammar/ 0000755 0001750 0001750 00000000000 11552640352 014524 5 ustar drazzib drazzib qdox-1.12/src/grammar/parser.y 0000644 0001750 0001750 00000056346 11345477502 016235 0 ustar drazzib drazzib %{
import com.thoughtworks.qdox.parser.*;
import com.thoughtworks.qdox.parser.structs.*;
import com.thoughtworks.qdox.model.*;
import com.thoughtworks.qdox.model.annotation.*;
import java.io.IOException;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
%}
%token SEMI DOT DOTDOTDOT COMMA STAR PERCENT EQUALS ANNOSTRING ANNOCHAR SLASH PLUS MINUS
%token PACKAGE IMPORT PUBLIC PROTECTED PRIVATE STATIC FINAL ABSTRACT NATIVE STRICTFP SYNCHRONIZED TRANSIENT VOLATILE
%token CLASS INTERFACE ENUM ANNOINTERFACE THROWS EXTENDS IMPLEMENTS SUPER DEFAULT
%token BRACEOPEN BRACECLOSE SQUAREOPEN SQUARECLOSE PARENOPEN PARENCLOSE
%token LESSTHAN GREATERTHAN LESSEQUALS GREATEREQUALS
%token LESSTHAN2 GREATERTHAN2 GREATERTHAN3
%token EXCLAMATION AMPERSAND2 VERTLINE2 EQUALS2 NOTEQUALS
%token TILDE AMPERSAND VERTLINE CIRCUMFLEX
%token VOID
%token QUERY COLON AT
%token JAVADOCSTART JAVADOCEND JAVADOCEOL
%token CODEBLOCK PARENBLOCK
%token BYTE SHORT INT LONG CHAR FLOAT DOUBLE BOOLEAN
// strongly typed tokens/types
%token IDENTIFIER JAVADOCTAG JAVADOCLINE
%token BOOLEAN_LITERAL
%token INTEGER_LITERAL
%token LONG_LITERAL
%token FLOAT_LITERAL
%token DOUBLE_LITERAL
%token CHAR_LITERAL
%token STRING_LITERAL
%token VERTLINE2 AMPERSAND2 VERTLINE CIRCUMFLEX AMPERSAND EQUALS2 NOTEQUALS
%token LESSTHAN GREATERTHAN LESSEQUALS GREATEREQUALS LESSTHAN2 GREATERTHAN2 GREATERTHAN3
%token PLUS MINUS STAR SLASH PERCENT TILDE EXCLAMATION
%type name primitiveType
%type value expression literal annotation arrayInitializer
%type conditionalExpression conditionalOrExpression conditionalAndExpression inclusiveOrExpression exclusiveOrExpression andExpression
%type equalityExpression relationalExpression shiftExpression additiveExpression multiplicativeExpression
%type unaryExpression unaryExpressionNotPlusMinus primary
%type dims
%type fullidentifier modifier typedeclspecifier typename memberend
%type dimensions
%type varargs
%type type arrayidentifier classtype typearg
%%
// ----- TOP LEVEL
// A file consists of 0-n fileparts...
file: | file { line = lexer.getLine(); } filepart;
// And a filepart is a package/import statement, javadoc comment, or class declaration.
filepart: annotation { builder.addAnnotation((Annotation) $1); } | package | import | javadoc | class | enum | SEMI;
// Package statement
package: PACKAGE fullidentifier SEMI { builder.addPackage(new PackageDef($2, line)); };
// Import statement
import: IMPORT fullidentifier SEMI { builder.addImport($2); } |
IMPORT STATIC fullidentifier SEMI { builder.addImport($3); };
// ----- JAVADOC
javadoclist:
javadoc |
javadoclist javadoc;
javadoc: JAVADOCSTART javadocdescription javadoctags JAVADOCEND;
javadocdescription:
javadoctokens {
builder.addJavaDoc(buffer());
};
javadoctokens: | javadoctokens javadoctoken;
javadoctoken:
JAVADOCLINE {
appendToBuffer($1);
}
javadoctags: | javadoctags javadoctag;
javadoctag:
JAVADOCTAG { line = lexer.getLine(); }
javadoctokens {
builder.addJavaDocTag(new TagDef($1.substring(1), buffer(), line));
};
// ----- COMMON TOKENS
// A fullidentifier is "a", "a.b", "a.b.c", "a.b.*", etc...
fullidentifier:
IDENTIFIER { $$ = $1; } |
fullidentifier DOT IDENTIFIER { $$ = $1 + '.' + $3; } |
fullidentifier DOT STAR { $$ = $1 + ".*"; };
arrayidentifier:
IDENTIFIER dimensions {
$$ = new TypeDef($1,$2);
};
dimensions:
/* empty */ { $$ = 0; }
| dimensions SQUAREOPEN SQUARECLOSE {
$$ = $1 + 1;
};
// Modifiers to methods, fields, classes, interfaces, parameters, etc...
modifier:
PUBLIC { $$ = "public"; } |
PROTECTED { $$ = "protected"; } |
PRIVATE { $$ = "private"; } |
STATIC { $$ = "static"; } |
FINAL { $$ = "final"; } |
ABSTRACT { $$ = "abstract"; } |
NATIVE { $$ = "native"; } |
SYNCHRONIZED { $$ = "synchronized"; } |
VOLATILE { $$ = "volatile"; } |
TRANSIENT { $$ = "transient"; } |
STRICTFP { $$ = "strictfp"; } ;
modifiers:
modifiers modifier { modifiers.add($2); } |
modifiers annotation { builder.addAnnotation((Annotation) $2); } |
modifiers javadoc |
;
//--------------------------------------------------------------------------------
// ANNOTATIONS
//--------------------------------------------------------------------------------
annotation:
AT name
{
annotationStack.add(annotation);
annotation = new Annotation(builder.createType($2, 0), lexer.getLine());
}
annotationParensOpt
{
$$ = annotation;
annotation = (Annotation)annotationStack.remove(annotationStack.size() - 1);
};
annotationParensOpt:
|
PARENOPEN value PARENCLOSE { annotation.setProperty("value", $2); } |
PARENOPEN valuePairs PARENCLOSE |
PARENOPEN PARENCLOSE;
valuePairs:
valuePair |
valuePairs COMMA valuePair;
valuePair:
IDENTIFIER EQUALS value { annotation.setProperty($1, $3); };
arrayInitializer:
{
annoValueListStack.add(annoValueList);
annoValueList = new ArrayList();
}
BRACEOPEN valuesOpt BRACECLOSE
{
$$ = new AnnotationValueList(annoValueList);
annoValueList = (List)annoValueListStack.remove(annoValueListStack.size() - 1);
};
valuesOpt:
|
values;
values:
value { annoValueList.add($1); } |
values COMMA value { annoValueList.add($3); };
value:
expression { $$ = $1; } |
annotation { $$ = $1; } |
arrayInitializer { $$ = $1; };
expression:
conditionalExpression { $$ = $1; };
conditionalExpression:
conditionalOrExpression { $$ = $1; } |
conditionalOrExpression QUERY expression COLON expression { $$ = new AnnotationQuery($1, $3, $5); };
conditionalOrExpression:
conditionalAndExpression { $$ = $1; } |
conditionalOrExpression VERTLINE2 conditionalAndExpression { $$ = new AnnotationLogicalOr($1, $3); };
conditionalAndExpression:
inclusiveOrExpression { $$ = $1; } |
conditionalAndExpression AMPERSAND2 inclusiveOrExpression { $$ = new AnnotationLogicalAnd($1, $3); };
inclusiveOrExpression:
exclusiveOrExpression { $$ = $1; } |
inclusiveOrExpression VERTLINE exclusiveOrExpression { $$ = new AnnotationOr($1, $3); };
exclusiveOrExpression:
andExpression { $$ = $1; } |
exclusiveOrExpression CIRCUMFLEX andExpression { $$ = new AnnotationExclusiveOr($1, $3); };
andExpression:
equalityExpression { $$ = $1; } |
andExpression AMPERSAND equalityExpression { $$ = new AnnotationAnd($1, $3); };
equalityExpression:
relationalExpression { $$ = $1; } |
equalityExpression EQUALS2 relationalExpression { $$ = new AnnotationEquals($1, $3); } |
equalityExpression NOTEQUALS relationalExpression { $$ = new AnnotationNotEquals($1, $3); };
relationalExpression:
shiftExpression { $$ = $1; } |
relationalExpression LESSEQUALS shiftExpression { $$ = new AnnotationLessEquals($1, $3); } |
relationalExpression GREATEREQUALS shiftExpression { $$ = new AnnotationGreaterEquals($1, $3); } |
relationalExpression LESSTHAN shiftExpression { $$ = new AnnotationLessThan($1, $3); } |
relationalExpression GREATERTHAN shiftExpression { $$ = new AnnotationGreaterThan($1, $3); };
shiftExpression:
additiveExpression { $$ = $1; } |
shiftExpression LESSTHAN2 additiveExpression { $$ = new AnnotationShiftLeft($1, $3); } |
shiftExpression GREATERTHAN3 additiveExpression { $$ = new AnnotationUnsignedShiftRight($1, $3); } |
shiftExpression GREATERTHAN2 additiveExpression { $$ = new AnnotationShiftRight($1, $3); };
additiveExpression:
multiplicativeExpression { $$ = $1; } |
additiveExpression PLUS multiplicativeExpression { $$ = new AnnotationAdd($1, $3); } |
additiveExpression MINUS multiplicativeExpression { $$ = new AnnotationSubtract($1, $3); };
multiplicativeExpression:
unaryExpression { $$ = $1; } |
multiplicativeExpression STAR unaryExpression { $$ = new AnnotationMultiply($1, $3); } |
multiplicativeExpression SLASH unaryExpression { $$ = new AnnotationDivide($1, $3); } |
multiplicativeExpression PERCENT unaryExpression { $$ = new AnnotationRemainder($1, $3); };
unaryExpression:
PLUS unaryExpression { $$ = new AnnotationPlusSign($2); } |
MINUS unaryExpression { $$ = new AnnotationMinusSign($2); } |
unaryExpressionNotPlusMinus { $$ = $1; };
unaryExpressionNotPlusMinus:
TILDE unaryExpression { $$ = new AnnotationNot($2); } |
EXCLAMATION unaryExpression { $$ = new AnnotationLogicalNot($2); } |
primary;
primary:
PARENOPEN primitiveType PARENCLOSE unaryExpression { $$ = new AnnotationCast(builder.createType($2, 0), $4); } |
PARENOPEN primitiveType dims PARENCLOSE unaryExpression { $$ = new AnnotationCast(builder.createType($2, $3), $5); } |
PARENOPEN name dims PARENCLOSE unaryExpressionNotPlusMinus { $$ = new AnnotationCast(builder.createType($2, $3), $5); } |
PARENOPEN name PARENCLOSE unaryExpressionNotPlusMinus { $$ = new AnnotationCast(builder.createType($2, 0), $4); } |
PARENOPEN expression PARENCLOSE { $$ = new AnnotationParenExpression($2); } |
literal { $$ = $1; } |
primitiveType dims DOT CLASS { $$ = new AnnotationTypeRef(builder.createType($1, 0)); } |
primitiveType DOT CLASS { $$ = new AnnotationTypeRef(builder.createType($1, 0)); } |
name DOT CLASS { $$ = new AnnotationTypeRef(builder.createType($1, 0)); } |
name dims DOT CLASS { $$ = new AnnotationTypeRef(builder.createType($1, 0)); } |
name { $$ = new AnnotationFieldRef($1); };
dims:
SQUAREOPEN SQUARECLOSE { $$ = 1; } |
dims SQUAREOPEN SQUARECLOSE { $$ = $1 + 1; };
name:
IDENTIFIER { $$ = $1; } |
name DOT IDENTIFIER { $$ = $1 + "." + $3; };
literal:
DOUBLE_LITERAL { $$ = new AnnotationConstant(toDouble($1), $1); } |
FLOAT_LITERAL { $$ = new AnnotationConstant(toFloat($1), $1); } |
LONG_LITERAL { $$ = new AnnotationConstant(toLong($1), $1); } |
INTEGER_LITERAL { $$ = new AnnotationConstant(toInteger($1), $1); } |
BOOLEAN_LITERAL { $$ = new AnnotationConstant(toBoolean($1), $1); } |
CHAR_LITERAL { String s = lexer.getCodeBody(); $$ = new AnnotationConstant(toChar(s), s); } |
STRING_LITERAL { String s = lexer.getCodeBody(); $$ = new AnnotationConstant(toString(s), s); };
primitiveType:
BOOLEAN { $$ = "boolean"; } |
BYTE { $$ = "byte"; } |
SHORT { $$ = "short"; } |
INT { $$ = "int"; } |
LONG { $$ = "long"; } |
CHAR { $$ = "char"; } |
FLOAT { $$ = "float"; } |
DOUBLE { $$ = "double"; };
// ----- TYPES
type:
classtype dimensions {
TypeDef td = $1;
td.dimensions = $2;
$$ = td;
};
classtype:
typedeclspecifier LESSTHAN {
TypeDef td = new TypeDef($1,0);
td.actualArgumentTypes = new ArrayList();
$$ = (TypeDef) typeStack.push(td);
} typearglist {
$$ = (TypeDef) typeStack.pop();
} GREATERTHAN {
$$ = $5;
} |
typedeclspecifier {
$$ = new TypeDef($1,0);
};
typedeclspecifier:
typename { $$ = $1; } |
classtype DOT IDENTIFIER { $$ = $1.name + '.' + $3; };
typename:
IDENTIFIER { $$ = $1; } |
typename DOT IDENTIFIER { $$ = $1 + '.' + $3; };
typearglist:
typearg { ((TypeDef) typeStack.peek()).actualArgumentTypes.add($1);}|
typearglist COMMA typearg { ((TypeDef) typeStack.peek()).actualArgumentTypes.add($3);};
typearg:
type { $$ = $1;} |
QUERY { $$ = new WildcardTypeDef();} |
QUERY EXTENDS type { $$ = new WildcardTypeDef($3, "extends");} |
QUERY SUPER type { $$ = new WildcardTypeDef($3, "super");};
opt_typeparams: | typeparams;
typeparams: LESSTHAN { typeParams = new ArrayList(); } typeparamlist GREATERTHAN;
typeparamlist:
typeparam |
typeparamlist COMMA typeparam;
typeparam:
IDENTIFIER { typeParams.add(new TypeVariableDef($1)); } |
IDENTIFIER EXTENDS {
typeVariable = new TypeVariableDef($1);
typeVariable.bounds = new ArrayList();
} typeboundlist {
typeParams.add(typeVariable);
typeVariable = null;
};
typeboundlist:
type { typeVariable.bounds.add($1); } |
typeboundlist AMPERSAND type { typeVariable.bounds.add($3); };
// ----- ENUM
enum: enum_definition BRACEOPEN enum_body BRACECLOSE {
builder.endClass();
fieldType = null;
modifiers.clear();
};
enum_definition: modifiers ENUM IDENTIFIER opt_implements {
cls.lineNumber = line;
cls.modifiers.addAll(modifiers);
cls.name = $3;
cls.type = ClassDef.ENUM;
builder.beginClass(cls);
cls = new ClassDef();
fieldType = new TypeDef($3, 0);
};
enum_body: enum_values | enum_values SEMI members;
enum_values: | enum_value | enum_value COMMA enum_values;
enum_value:
javadoclist opt_annotations enum_constructor |
opt_annotations enum_constructor;
enum_constructor:
IDENTIFIER { makeField(new TypeDef($1, 0), ""); } |
IDENTIFIER CODEBLOCK { makeField(new TypeDef($1, 0), ""); } |
IDENTIFIER PARENBLOCK { makeField(new TypeDef($1, 0), ""); } |
IDENTIFIER PARENBLOCK CODEBLOCK { makeField(new TypeDef($1, 0), ""); };
// ----- CLASS
class:
classdefinition BRACEOPEN members BRACECLOSE {
builder.endClass();
};
classdefinition:
modifiers classorinterface IDENTIFIER opt_typeparams opt_extends opt_implements {
cls.lineNumber = line;
cls.modifiers.addAll(modifiers); modifiers.clear();
cls.name = $3;
cls.typeParams = typeParams;
builder.beginClass(cls);
cls = new ClassDef();
};
classorinterface:
CLASS { cls.type = ClassDef.CLASS; } |
INTERFACE { cls.type = ClassDef.INTERFACE; } |
ANNOINTERFACE { cls.type = ClassDef.ANNOTATION_TYPE; };
opt_extends: | EXTENDS extendslist;
extendslist:
classtype { cls.extendz.add($1); } |
extendslist COMMA classtype { cls.extendz.add($3); };
opt_implements: | IMPLEMENTS implementslist;
implementslist:
classtype { cls.implementz.add($1); } |
implementslist COMMA classtype { cls.implementz.add($3); };
members: | members { line = lexer.getLine(); } member;
member:
javadoc |
fields |
method |
constructor |
static_block |
class |
enum |
SEMI;
memberend:
SEMI {
$$ = "";
}
| CODEBLOCK {
$$ = lexer.getCodeBody();
};
static_block:
modifiers CODEBLOCK { lexer.getCodeBody(); modifiers.clear(); };
// ----- FIELD
fields:
modifiers type arrayidentifier {
fieldType = $2;
makeField($3, lexer.getCodeBody());
}
extrafields memberend {
modifiers.clear();
};
extrafields: |
extrafields COMMA { line = lexer.getLine(); } arrayidentifier {
makeField($4, lexer.getCodeBody());
} |
extrafields COMMA javadoc { line = lexer.getLine(); } arrayidentifier {
makeField($5, lexer.getCodeBody());
};
// ----- METHOD
method:
modifiers typeparams type IDENTIFIER {
builder.beginMethod();
mth.typeParams = typeParams;
} methoddef dimensions opt_exceptions memberend {
mth.lineNumber = line;
mth.modifiers.addAll(modifiers); modifiers.clear();
mth.returnType = $3;
mth.dimensions = $7;
mth.name = $4;
mth.body = $9;
builder.endMethod(mth);
mth = new MethodDef();
} |
modifiers type IDENTIFIER {
builder.beginMethod();
} methoddef dimensions opt_exceptions memberend {
mth.lineNumber = line;
mth.modifiers.addAll(modifiers); modifiers.clear();
mth.returnType = $2;
mth.dimensions = $6;
mth.name = $3;
mth.body = $8;
builder.endMethod(mth);
mth = new MethodDef();
};
constructor:
modifiers IDENTIFIER {
builder.beginMethod();
} methoddef opt_exceptions memberend {
mth.lineNumber = line;
mth.modifiers.addAll(modifiers); modifiers.clear();
mth.constructor = true; mth.name = $2;
mth.body = $6;
builder.endMethod(mth);
mth = new MethodDef();
} |
modifiers typeparams IDENTIFIER {
builder.beginMethod();
mth.typeParams = typeParams;
} methoddef opt_exceptions memberend {
mth.lineNumber = line;
mth.modifiers.addAll(modifiers); modifiers.clear();
mth.constructor = true; mth.name = $3;
mth.body = $7;
builder.endMethod(mth);
mth = new MethodDef();
};
methoddef: PARENOPEN opt_params PARENCLOSE;
opt_exceptions: | THROWS exceptionlist;
exceptionlist:
fullidentifier { mth.exceptions.add($1); } |
exceptionlist COMMA fullidentifier { mth.exceptions.add($3); };
opt_params: | paramlist;
paramlist:
param |
paramlist COMMA param;
param:
opt_parammodifiers type varargs arrayidentifier {
param.name = $4.name;
param.type = $2;
param.dimensions = $4.dimensions;
param.isVarArgs = $3;
builder.addParameter(param);
param = new FieldDef();
};
varargs:
/* empty */ { $$ = false; } |
DOTDOTDOT { $$ = true; } ;
opt_annotations: | opt_annotations annotation { builder.addAnnotation((Annotation) $2); };
opt_parammodifiers: |
opt_parammodifiers modifier { param.modifiers.add($2); } |
opt_parammodifiers annotation { builder.addAnnotation((Annotation) $2); };
%%
private Lexer lexer;
private Builder builder;
private StringBuffer textBuffer = new StringBuffer();
private ClassDef cls = new ClassDef();
private MethodDef mth = new MethodDef();
private List typeParams = new ArrayList(); //for both JavaClass and JavaMethod
private List annotationStack = new ArrayList(); // Use ArrayList intead of Stack because it is unsynchronized
private Annotation annotation = null;
private List annoValueListStack = new ArrayList(); // Use ArrayList intead of Stack because it is unsynchronized
private List annoValueList = null;
private FieldDef param = new FieldDef();
private java.util.Set modifiers = new java.util.HashSet();
private TypeDef fieldType;
private TypeVariableDef typeVariable;
private Stack typeStack = new Stack();
private int line;
private int column;
private boolean debugLexer;
private void appendToBuffer(String word) {
if (textBuffer.length() > 0) {
char lastChar = textBuffer.charAt(textBuffer.length() - 1);
if (!Character.isWhitespace(lastChar)) {
textBuffer.append(' ');
}
}
textBuffer.append(word);
}
private String buffer() {
String result = textBuffer.toString().trim();
textBuffer.setLength(0);
return result;
}
public Parser(Lexer lexer, Builder builder) {
this.lexer = lexer;
this.builder = builder;
}
public void setDebugParser(boolean debug) {
yydebug = debug;
}
public void setDebugLexer(boolean debug) {
debugLexer = debug;
}
/**
* Parse file. Return true if successful.
*/
public boolean parse() {
return yyparse() == 0;
}
private int yylex() {
try {
final int result = lexer.lex();
yylval = new Value();
yylval.sval = lexer.text();
if (debugLexer) {
System.err.println("Token: " + yyname[result] + " \"" + yylval.sval + "\"");
}
return result;
}
catch(IOException e) {
return 0;
}
}
private void yyerror(String msg) {
throw new ParseException(msg, lexer.getLine(), lexer.getColumn());
}
private class Value {
Object oval;
String sval;
int ival;
boolean bval;
TypeDef type;
AnnotationValue annoval;
}
private void makeField(TypeDef field, String body) {
FieldDef fd = new FieldDef();
fd.lineNumber = line;
fd.modifiers.addAll(modifiers);
fd.name = field.name;
fd.type = fieldType;
fd.dimensions = field.dimensions;
fd.body = body;
builder.addField(fd);
}
private String convertString(String str) {
StringBuffer buf = new StringBuffer();
boolean escaped = false;
int unicode = 0;
int value = 0;
int octal = 0;
boolean consumed = false;
for(int i = 0; i < str.length(); ++ i) {
char ch = str.charAt( i );
if(octal > 0) {
if( value >= '0' && value <= '7' ) {
value = ( value << 3 ) | Character.digit( ch, 8 );
-- octal;
consumed = true;
}
else {
octal = 0;
}
if( octal == 0 ) {
buf.append( (char) value );
value = 0;
}
}
if(!consumed) {
if(unicode > 0) {
value = ( value << 4 ) | Character.digit( ch, 16 );
-- unicode;
if(unicode == 0) {
buf.append( (char)value );
value = 0;
}
}
else if(ch == '\\') {
escaped = true;
}
else if(escaped) {
if(ch == 'u' || ch == 'U') {
unicode = 4;
}
else if(ch >= '0' && ch <= '7') {
octal = (ch > '3') ? 1 : 2;
value = Character.digit( ch, 8 );
}
else {
switch( ch ) {
case 'b':
buf.append('\b');
break;
case 'f':
buf.append('\f');
break;
case 'n':
buf.append('\n');
break;
case 'r':
buf.append('\r');
break;
case 't':
buf.append('\t');
break;
case '\'':
buf.append('\'');
break;
case '\"':
buf.append('\"');
break;
case '\\':
buf.append('\\');
break;
default:
yyerror( "Illegal escape character '" + ch + "'" );
}
}
escaped = false;
}
else {
buf.append( ch );
}
}
}
return buf.toString();
}
private Boolean toBoolean(String str) {
str = str.trim();
return new Boolean( str );
}
private Integer toInteger(String str) {
str = str.trim();
Integer result;
if(str.startsWith("0x") || str.startsWith( "0X" ) ) {
result = new Integer( Integer.parseInt( str.substring( 2 ), 16 ) );
}
else if(str.length() > 1 && str.startsWith("0") ) {
result = new Integer( Integer.parseInt( str.substring( 1 ), 8 ) );
}
else {
result = new Integer( str );
}
return result;
}
private Long toLong(String str) {
str = str.trim();
Long result;
if( !str.endsWith("l") && !str.endsWith("L") ) {
yyerror( "Long literal must end with 'l' or 'L'." );
}
int len = str.length() - 1;
if(str.startsWith("0x") || str.startsWith( "0X" ) ) {
result = new Long( Long.parseLong( str.substring( 2, len ), 16 ) );
}
else if(str.startsWith("0") ) {
result = new Long( Long.parseLong( str.substring( 1, len ), 8 ) );
}
else {
result = new Long( str.substring( 0, len ) );
}
return result;
}
private Float toFloat(String str) {
str = str.trim();
return new Float( str );
}
private Double toDouble(String str) {
str = str.trim();
if( !str.endsWith("d") && !str.endsWith("D") ) {
yyerror( "Double literal must end with 'd' or 'D'." );
}
return new Double( str.substring( 0, str.length() - 1 ) );
}
/**
* Convert a character literal into a character.
*/
private Character toChar(String str) {
str = str.trim();
if( !str.startsWith("'") && !str.endsWith("'") ) {
yyerror("Character must be single quoted.");
}
String str2 = convertString( str.substring( 1, str.length() - 1 ) );
if( str2.length() != 1) {
yyerror("Only one character allowed in character constants.");
}
return new Character( str2.charAt( 0 ) );
}
/**
* Convert a string literal into a string.
*/
private String toString(String str) {
str = str.trim();
if( str.length() < 2 && !str.startsWith("\"") && !str.endsWith("\"") ) {
yyerror("String must be double quoted.");
}
String str2 = convertString( str.substring( 1, str.length() - 1 ) );
return str2;
} qdox-1.12/src/grammar/lexer.flex 0000644 0001750 0001750 00000036377 11367106370 016544 0 ustar drazzib drazzib // class headers
package com.thoughtworks.qdox.parser.impl;
import com.thoughtworks.qdox.parser.*;
%%
// class and lexer definitions
%class JFlexLexer
%public
%implements Lexer
%byaccj
%unicode
%line
%column
%{
private int classDepth = 0;
private int parenDepth = 0;
private int nestingDepth = 0;
private int annotationDepth = 0;
private int assignmentDepth = 0;
private int stateDepth = 0;
private int codeblockDepth = 0;
private int[] stateStack = new int[10];
private int braceMode = CODEBLOCK;
private int parenMode = -1;
private String className;
private boolean javaDocNewLine;
private boolean javaDocStartedContent;
private StringBuffer codeBody = new StringBuffer(8192);
private boolean newMode;
private boolean bracketMode;
private boolean anonymousMode;
private boolean appendingToCodeBody;
private boolean shouldCaptureCodeBody;
private boolean isConstructor;
public void setCaptureCodeBody(boolean shouldCaptureCodeBody) {
this.shouldCaptureCodeBody = shouldCaptureCodeBody;
}
public String text() {
return yytext();
}
public int lex() throws java.io.IOException {
return yylex();
}
public int getLine() {
return yyline + 1;
}
public int getColumn() {
return yycolumn + 1;
}
private void pushState(int newState) {
stateStack[stateDepth++] = zzLexicalState;
yybegin(newState);
}
private void popState() {
yybegin(stateStack[--stateDepth]);
}
private int peekState(int relative) {
if(relative > stateDepth) {
return -1;
}
else {
return stateStack[stateDepth - relative];
}
}
public String getCodeBody(){
String s = codeBody.toString();
codeBody = new StringBuffer(8192);
return s;
}
%}
Eol = \r|\n|\r\n
WhiteSpace = {Eol} | [ \t\f]
CommentChar = ( [^ \t\r\n*] | "*"+ [^ \t\r\n/*] )
IntegerLiteral = (( [1-9] ([0-9])* ) | ( "0" [xX] ([0-9]|[a-f]|[A-F])+ ) | ( "0" ([0-7])* ))
LongLiteral = (( [1-9] ([0-9])* ) | ( "0" [xX] ([0-9]|[a-f]|[A-F])+ ) | ( "0" ([0-7])* )) [lL]
Exponent = [eE] [+-]? ([0-9])+
FloatLiteral = ( [0-9]+ ("." [0-9]+)? ({Exponent})? ([fF])? ) |
( "." [0-9]+ ({Exponent})? ([fF])? ) |
( ([0-9])+ {Exponent} ([fF])? ) |
( ([0-9])+ ({Exponent})? [fF] )
DoubleLiteral = ( [0-9]+ ("." [0-9]+)? ({Exponent})? [dD] ) |
( "." [0-9]+ ({Exponent})? [dD] ) |
( ([0-9])+ {Exponent} [dD] ) |
( ([0-9])+ ({Exponent})? [dD] )
UnicodeChar = \\u[a-fA-F0-9]{4}
Id = ([:jletter:]|{UnicodeChar}) ([:jletterdigit:]|{UnicodeChar})*
Annotation = "@" {WhiteSpace}* {Id} ("."{Id})* {WhiteSpace}*
JavadocEnd = "*"+ "/"
%state JAVADOC JAVADOCTAG JAVADOCLINE CODEBLOCK PARENBLOCK ASSIGNMENT STRING CHAR SINGLELINECOMMENT MULTILINECOMMENT ANNOTATION ANNOSTRING ANNOCHAR ENUM
%%
{
"." { return Parser.DOT; }
"..." { return Parser.DOTDOTDOT; }
"," { return Parser.COMMA; }
"*" { return Parser.STAR; }
"package" { return Parser.PACKAGE; }
"import" { return Parser.IMPORT; }
"public" { return Parser.PUBLIC; }
"protected" { return Parser.PROTECTED; }
"private" { return Parser.PRIVATE; }
"static" { return Parser.STATIC; }
"final" { return Parser.FINAL; }
"abstract" { return Parser.ABSTRACT; }
"native" { return Parser.NATIVE; }
"strictfp" { return Parser.STRICTFP; }
"synchronized" { return Parser.SYNCHRONIZED; }
"transient" { return Parser.TRANSIENT; }
"volatile" { return Parser.VOLATILE; }
"throws" { return Parser.THROWS; }
"extends" { return Parser.EXTENDS; }
"implements" { return Parser.IMPLEMENTS; }
"super" { return Parser.SUPER; }
"[" { nestingDepth++; return Parser.SQUAREOPEN; }
"]" { nestingDepth--; return Parser.SQUARECLOSE; }
")" { nestingDepth--; return Parser.PARENCLOSE; }
"<" { return Parser.LESSTHAN; }
">" { return Parser.GREATERTHAN; }
"&" { return Parser.AMPERSAND; }
"?" { return Parser.QUERY; }
"@" {WhiteSpace}* "interface" {
classDepth++;
braceMode = YYINITIAL;
return Parser.ANNOINTERFACE;
}
"class" {
classDepth++;
braceMode = YYINITIAL;
return Parser.CLASS;
}
"interface" {
classDepth++;
braceMode = YYINITIAL;
return Parser.INTERFACE;
}
"enum" {
classDepth++;
braceMode = ENUM;
return Parser.ENUM;
}
{Annotation} "(" {
parenMode = ANNOTATION;
yypushback(text().length()-1);
getCodeBody(); /* reset codebody */
return Parser.AT;
}
"@" {
return Parser.AT;
}
"{" {
if(braceMode >= 0) {
if(braceMode == ENUM) {
isConstructor = true;
} else if (braceMode == CODEBLOCK) {
getCodeBody(); /* reset codebody */
appendingToCodeBody = true;
}
pushState(braceMode);
braceMode = -1;
yypushback(1); /* (re)enter brace in right mode */
}
else {
nestingDepth++;
braceMode = CODEBLOCK;
return Parser.BRACEOPEN;
}
}
"}" {
nestingDepth--;
classDepth--;
popState();
braceMode = CODEBLOCK;
return Parser.BRACECLOSE;
}
"/**" ~"*/" {
pushState(JAVADOC);
yypushStream(new java.io.StringReader(text().substring(2)));
return Parser.JAVADOCSTART;
}
"=" {WhiteSpace}* {
assignmentDepth = nestingDepth;
getCodeBody(); /* reset codebody */
appendingToCodeBody = true;
pushState(ASSIGNMENT);
}
"default" {
assignmentDepth = nestingDepth;
appendingToCodeBody = true;
pushState(ASSIGNMENT);
}
{Id} {
return Parser.IDENTIFIER;
}
}
{
";" { return Parser.SEMI; }
"(" {
nestingDepth++;
if( parenMode >= 0 ) {
annotationDepth = nestingDepth;
pushState(parenMode);
parenMode = -1;
}
return Parser.PARENOPEN;
}
}
{
";" { isConstructor = false; return Parser.SEMI; }
"(" {
nestingDepth++;
if(parenMode >= 0) {
annotationDepth = nestingDepth;
pushState(parenMode);
parenMode = -1;
return Parser.PARENOPEN;
}
else {
if(isConstructor) {
parenDepth = classDepth;
pushState(PARENBLOCK);
return Parser.PARENBLOCK;
}
else {
return Parser.PARENOPEN;
}
}
}
}
{
"@" { yypushback(1); pushState(JAVADOCTAG); }
[^ \t\r*@] { yypushback(1); pushState(JAVADOCLINE); }
"*"+ [ \t]* / "@" { pushState(JAVADOCTAG); }
"*"+ [ \t]? { pushState(JAVADOCLINE); }
{JavadocEnd} { popState(); yypopStream(); return Parser.JAVADOCEND; }
}
{
~{Eol} { popState(); return Parser.JAVADOCLINE; }
.* [^ \t*] / [ \t]* {JavadocEnd} { popState(); return Parser.JAVADOCLINE;}
{JavadocEnd} { popState(); popState(); yypopStream(); return Parser.JAVADOCEND; }
}
{
"@" [^ \t\n\r]+ / {JavadocEnd} { popState(); return Parser.JAVADOCTAG; }
"@" [^ \t\n\r]+ { return Parser.JAVADOCTAG; }
[ \t]+ { popState();pushState(JAVADOCLINE);}
{Eol} { popState();return Parser.JAVADOCLINE;}
}
{
"{" {
if(codeblockDepth++ > 0 ) {
codeBody.append('{');
}
}
"}" {
if (--codeblockDepth == 0) {
popState();
appendingToCodeBody = false;
braceMode = CODEBLOCK;
return Parser.CODEBLOCK;
} else {
codeBody.append('}');
}
}
}
{
"(" { ++ nestingDepth; return Parser.PARENOPEN; }
")" { if( nestingDepth-- == annotationDepth) { popState(); } return Parser.PARENCLOSE; }
"," { return Parser.COMMA; }
"=" { return Parser.EQUALS; }
"{" { nestingDepth++; return Parser.BRACEOPEN; }
"}" { nestingDepth--; return Parser.BRACECLOSE; }
"\"" { appendingToCodeBody=true; codeBody.append("\""); pushState(ANNOSTRING); }
"\'" { appendingToCodeBody=true; codeBody.append("\'"); pushState(ANNOCHAR); }
"." { return Parser.DOT; }
"?" { return Parser.QUERY; }
":" { return Parser.COLON; }
"<<" { return Parser.LESSTHAN2; }
">>>" { return Parser.GREATERTHAN3; }
">>" { return Parser.GREATERTHAN2; }
"==" { return Parser.EQUALS2; }
"!=" { return Parser.NOTEQUALS; }
"<" { return Parser.LESSTHAN; }
">" { return Parser.GREATERTHAN; }
"<=" { return Parser.LESSEQUALS; }
">=" { return Parser.GREATEREQUALS; }
"*" { return Parser.STAR; }
"/" { return Parser.SLASH; }
"%" { return Parser.PERCENT; }
"+" { return Parser.PLUS; }
"-" { return Parser.MINUS; }
"byte" { return Parser.BYTE; }
"char" { return Parser.CHAR; }
"short" { return Parser.SHORT; }
"int" { return Parser.INT; }
"long" { return Parser.LONG; }
"float" { return Parser.FLOAT; }
"double" { return Parser.DOUBLE; }
"&&" { return Parser.AMPERSAND2; }
"||" { return Parser.VERTLINE2; }
"!" { return Parser.EXCLAMATION; }
"&" { return Parser.AMPERSAND; }
"|" { return Parser.VERTLINE; }
"^" { return Parser.CIRCUMFLEX; }
"~" { return Parser.TILDE; }
{IntegerLiteral} { return Parser.INTEGER_LITERAL; }
{LongLiteral} { return Parser.LONG_LITERAL; }
{FloatLiteral} { return Parser.FLOAT_LITERAL; }
{DoubleLiteral} { return Parser.DOUBLE_LITERAL; }
"true" | "false" { return Parser.BOOLEAN_LITERAL; }
"class" { return Parser.CLASS; }
{Id} {
return Parser.IDENTIFIER;
}
"@" { return Parser.AT; }
}
{
"\"" { codeBody.append("\""); popState(); appendingToCodeBody=false; return Parser.STRING_LITERAL; }
"\\\"" { codeBody.append("\\\""); }
"\\\\" { codeBody.append("\\\\"); }
}
{
\' { codeBody.append("\'"); popState(); appendingToCodeBody=false; return Parser.CHAR_LITERAL; }
"\\'" { codeBody.append("\\'"); }
"\\\\" { codeBody.append("\\\\"); }
}
{
"(" {
nestingDepth++;
if (appendingToCodeBody) { codeBody.append("("); }
}
")" {
nestingDepth--;
if (appendingToCodeBody) { codeBody.append(")"); }
if (nestingDepth == parenDepth) {
popState();
}
}
}
{
";" {
if (nestingDepth == assignmentDepth) {
appendingToCodeBody = true;
newMode = false;
popState();
return Parser.SEMI;
} else {
codeBody.append(';');
}
}
"," {
if (nestingDepth == assignmentDepth) {
appendingToCodeBody = true;
popState();
return Parser.COMMA;
} else {
codeBody.append(',');
}
}
"{" {
codeBody.append('{');
anonymousMode = true;
nestingDepth++;
}
"}" {
codeBody.append('}');
if (anonymousMode) {
nestingDepth--;
if (nestingDepth==assignmentDepth) {
anonymousMode=false;
}
}
}
"(" {
codeBody.append('(');
parenDepth = nestingDepth++;
pushState(PARENBLOCK);
}
")" {
codeBody.append(')');
nestingDepth--;
if (nestingDepth < assignmentDepth) {
appendingToCodeBody = true;
popState();
return Parser.PARENCLOSE;
}
}
"[" { codeBody.append('['); bracketMode = true; nestingDepth++; }
"]" { codeBody.append(']'); bracketMode = false; nestingDepth--; }
"new" {
codeBody.append("new");
if (nestingDepth==assignmentDepth) {
newMode=true;
}
}
"." [ \t\r\n]* / "<" {
codeBody.append('.');
newMode = true;
}
"<" {
codeBody.append('<');
if (!bracketMode && newMode && !anonymousMode) {
nestingDepth++;
}
}
">" {
codeBody.append('>');
if (!anonymousMode) {
if (!bracketMode && newMode) {
nestingDepth--;
if (nestingDepth==assignmentDepth) {
newMode=false;
}
}
}
}
}
{
"\"" { if (appendingToCodeBody) { codeBody.append('"'); } pushState(STRING); }
\' { if (appendingToCodeBody) { codeBody.append('\''); } pushState(CHAR); }
}
{
"//" { if (appendingToCodeBody) { codeBody.append("//"); } pushState(SINGLELINECOMMENT); }
"/*" { if (appendingToCodeBody) { codeBody.append("/*"); } pushState(MULTILINECOMMENT); }
"/**/" { if (appendingToCodeBody) { codeBody.append("/**/"); } }
}
{
.|{WhiteSpace} { codeBody.append(yytext()); }
}
{
"\"" { if (appendingToCodeBody) { codeBody.append('"'); } popState(); }
"\\\"" { if (appendingToCodeBody) { codeBody.append("\\\""); } }
"\\\\" { if (appendingToCodeBody) { codeBody.append("\\\\"); } }
}
{
\' { if (appendingToCodeBody) { codeBody.append('\''); } popState(); }
"\\'" { if (appendingToCodeBody) { codeBody.append("\\'"); } }
"\\\\" { if (appendingToCodeBody) { codeBody.append("\\\\"); } }
}
{
{Eol} { if (appendingToCodeBody) { codeBody.append(yytext()); } popState(); }
}
{
"*/" { if (appendingToCodeBody) { codeBody.append("*/"); } popState(); }
}
.|\r|\n|\r\n { if (appendingToCodeBody) { codeBody.append(yytext()); } }
qdox-1.12/src/grammar/skeleton.inner 0000644 0001750 0001750 00000025522 11367241270 017413 0 ustar drazzib drazzib /*
This file is based on skeleton.nested, but this version skips resetting the line number and column.
It's used for parsing the javadoc comments. It's much more solid to extract the comment block and read it per line.
*/
/** This character denotes the end of file */
public static final int YYEOF = -1;
/** initial size of the lookahead buffer */
--- private static final int ZZ_BUFFERSIZE = ...;
/** lexical states */
--- lexical states, charmap
/* error codes */
private static final int ZZ_UNKNOWN_ERROR = 0;
private static final int ZZ_NO_MATCH = 1;
private static final int ZZ_PUSHBACK_2BIG = 2;
/* error messages for the codes above */
private static final String ZZ_ERROR_MSG[] = {
"Unkown internal scanner error",
"Error: could not match input",
"Error: pushback value was too large"
};
--- isFinal list
/** the input device */
private java.io.Reader zzReader;
/** the current state of the DFA */
private int zzState;
/** the current lexical state */
private int zzLexicalState = YYINITIAL;
/** this buffer contains the current text to be matched and is
the source of the yytext() string */
private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
/** the textposition at the last accepting state */
private int zzMarkedPos;
/** the current text position in the buffer */
private int zzCurrentPos;
/** startRead marks the beginning of the yytext() string in the buffer */
private int zzStartRead;
/** endRead marks the last character in the buffer, that has been read
from input */
private int zzEndRead;
/** number of newlines encountered up to the start of the matched text */
private int yyline;
/** the number of characters up to the start of the matched text */
private int yychar;
/**
* the number of characters from the last newline up to the start of the
* matched text
*/
private int yycolumn;
/**
* zzAtBOL == true <=> the scanner is currently at the beginning of a line
*/
private boolean zzAtBOL = true;
/** zzAtEOF == true <=> the scanner is at the EOF */
private boolean zzAtEOF;
/** denotes if the user-EOF-code has already been executed */
private boolean zzEOFDone;
/** the stack of open (nested) input streams to read from */
private java.util.Stack zzStreams = new java.util.Stack();
/**
* inner class used to store info for nested
* input streams
*/
private static final class ZzFlexStreamInfo {
java.io.Reader zzReader;
int zzEndRead;
int zzStartRead;
int zzCurrentPos;
int zzMarkedPos;
char [] zzBuffer;
boolean zzAtEOF;
boolean zzEOFDone;
/** sets all values stored in this class */
ZzFlexStreamInfo(java.io.Reader zzReader, int zzEndRead, int zzStartRead,
int zzCurrentPos, int zzMarkedPos,
char [] zzBuffer, boolean zzAtEOF) {
this.zzReader = zzReader;
this.zzEndRead = zzEndRead;
this.zzStartRead = zzStartRead;
this.zzCurrentPos = zzCurrentPos;
this.zzMarkedPos = zzMarkedPos;
this.zzBuffer = zzBuffer;
this.zzAtEOF = zzAtEOF;
this.zzEOFDone = zzEOFDone;
}
}
--- user class code
/**
* Creates a new scanner
* There is also a java.io.InputStream version of this constructor.
*
* @param in the java.io.Reader to read input from.
*/
--- constructor declaration
/**
* Refills the input buffer.
*
* @return false
, iff there was new input.
*
* @exception java.io.IOException if any I/O-Error occurs
*/
private boolean zzRefill() throws java.io.IOException {
/* first: make room (if you can) */
if (zzStartRead > 0) {
System.arraycopy(zzBuffer, zzStartRead,
zzBuffer, 0,
zzEndRead-zzStartRead);
/* translate stored positions */
zzEndRead-= zzStartRead;
zzCurrentPos-= zzStartRead;
zzMarkedPos-= zzStartRead;
zzStartRead = 0;
}
/* is the buffer big enough? */
if (zzCurrentPos >= zzBuffer.length) {
/* if not: blow it up */
char newBuffer[] = new char[zzCurrentPos*2];
System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
zzBuffer = newBuffer;
}
/* finally: fill the buffer with new input */
int numRead = zzReader.read(zzBuffer, zzEndRead,
zzBuffer.length-zzEndRead);
if (numRead > 0) {
zzEndRead+= numRead;
return false;
}
// unlikely but not impossible: read 0 characters, but not at end of stream
if (numRead == 0) {
int c = zzReader.read();
if (c == -1) {
return true;
} else {
zzBuffer[zzEndRead++] = (char) c;
return false;
}
}
// numRead < 0)
return true;
}
/**
* Closes the input stream.
*/
public final void yyclose() throws java.io.IOException {
zzAtEOF = true; /* indicate end of file */
zzEndRead = zzStartRead; /* invalidate buffer */
if (zzReader != null)
zzReader.close();
}
/**
* Stores the current input stream on a stack, and
* reads from a new stream. Lexical state, line,
* char, and column counting remain untouched.
*
* The current input stream can be restored with
* yypopstream (usually in an <> action).
*
* @param reader the new input stream to read from
*
* @see #yypopStream()
*/
public final void yypushStream(java.io.Reader reader) {
zzStreams.push(
new ZzFlexStreamInfo(zzReader, zzEndRead, zzStartRead, zzCurrentPos,
zzMarkedPos, zzBuffer, zzAtEOF)
);
zzAtEOF = false;
zzBuffer = new char[ZZ_BUFFERSIZE];
zzReader = reader;
zzEndRead = zzStartRead = 0;
zzCurrentPos = zzMarkedPos = 0;
}
/**
* Closes the current input stream and continues to
* read from the one on top of the stream stack.
*
* @throws java.util.EmptyStackException
* if there is no further stream to read from.
*
* @throws java.io.IOException
* if there was an error in closing the stream.
*
* @see #yypushStream(java.io.Reader)
*/
public final void yypopStream() throws java.io.IOException {
zzReader.close();
ZzFlexStreamInfo s = (ZzFlexStreamInfo) zzStreams.pop();
zzBuffer = s.zzBuffer;
zzReader = s.zzReader;
zzStartRead = s.zzStartRead + zzEndRead + 2; //skip javadoc-part
zzEndRead = s.zzEndRead;
zzCurrentPos = s.zzCurrentPos;
zzMarkedPos = s.zzMarkedPos ;
zzAtEOF = s.zzAtEOF;
zzEOFDone = s.zzEOFDone;
}
/**
* Returns true iff there are still streams left
* to read from on the stream stack.
*/
public final boolean yymoreStreams() {
return !zzStreams.isEmpty();
}
/**
* Resets the scanner to read from a new input stream.
* Does not close the old reader.
*
* All internal variables are reset, the old input stream
* cannot be reused (internal buffer is discarded and lost).
* Lexical state is set to ZZ_INITIAL.
*
* @param reader the new input stream
*
* @see #yypushStream(java.io.Reader)
* @see #yypopStream()
*/
public final void yyreset(java.io.Reader reader) {
zzReader = reader;
zzAtBOL = true;
zzAtEOF = false;
zzEOFDone = false;
zzEndRead = zzStartRead = 0;
zzCurrentPos = zzMarkedPos = 0;
yychar = 0;
zzLexicalState = YYINITIAL;
}
/**
* Returns the current lexical state.
*/
public final int yystate() {
return zzLexicalState;
}
/**
* Enters a new lexical state
*
* @param newState the new lexical state
*/
public final void yybegin(int newState) {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*/
public final String yytext() {
return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
}
/**
* Returns the character at position pos from the
* matched text.
*
* It is equivalent to yytext().charAt(pos), but faster
*
* @param pos the position of the character to fetch.
* A value from 0 to yylength()-1.
*
* @return the character at position pos
*/
public final char yycharat(int pos) {
return zzBuffer[zzStartRead+pos];
}
/**
* Returns the length of the matched text region.
*/
public final int yylength() {
return zzMarkedPos-zzStartRead;
}
/**
* Reports an error that occured while scanning.
*
* In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.).
*
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
*
* @param errorCode the code of the errormessage to display
*/
--- zzScanError declaration
String message;
try {
message = ZZ_ERROR_MSG[errorCode];
}
catch (ArrayIndexOutOfBoundsException e) {
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
}
--- throws clause
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* They will be read again by then next call of the scanning method
*
* @param number the number of characters to be read again.
* This number must not be greater than yylength()!
*/
--- yypushback decl (contains zzScanError exception)
if ( number > yylength() )
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
--- zzDoEOF
/**
* Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException if any I/O-Error occurs
*/
--- yylex declaration
int zzInput;
int zzAction;
--- local declarations
while (true) {
// cached fields:
int zzCurrentPosL;
int zzMarkedPosL = zzMarkedPos;
int zzEndReadL = zzEndRead;
char [] zzBufferL = zzBuffer;
char [] zzCMapL = ZZ_CMAP;
--- start admin (line, char, col count)
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
--- start admin (lexstate etc)
zzForAction: {
while (true) {
--- next input, line, col, char count, next transition, isFinal action
zzAction = zzState;
zzMarkedPosL = zzCurrentPosL;
--- line count update
}
}
}
// store back cached position
zzMarkedPos = zzMarkedPosL;
--- char count update
--- actions
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
--- eofvalue
}
else {
--- no match
}
}
}
}
--- main
}
qdox-1.12/src/test/ 0000755 0001750 0001750 00000000000 11552640342 014054 5 ustar drazzib drazzib qdox-1.12/src/test/com/ 0000755 0001750 0001750 00000000000 11552640342 014632 5 ustar drazzib drazzib qdox-1.12/src/test/com/thoughtworks/ 0000755 0001750 0001750 00000000000 11552640342 017402 5 ustar drazzib drazzib qdox-1.12/src/test/com/thoughtworks/qdox/ 0000755 0001750 0001750 00000000000 11552640346 020361 5 ustar drazzib drazzib qdox-1.12/src/test/com/thoughtworks/qdox/directorywalker/ 0000755 0001750 0001750 00000000000 11552640346 023573 5 ustar drazzib drazzib qdox-1.12/src/test/com/thoughtworks/qdox/directorywalker/DirectoryScannerTest.java 0000644 0001750 0001750 00000012637 11126631631 030557 0 ustar drazzib drazzib package com.thoughtworks.qdox.directorywalker;
import java.io.File;
import org.jmock.Mock;
import org.jmock.MockObjectTestCase;
public class DirectoryScannerTest extends MockObjectTestCase {
class MockFile extends File {
boolean isDirectory;
File[] children;
public MockFile(String pathname) {
super(pathname);
this.isDirectory = false;
}
public MockFile(String pathname, boolean isDirectory) {
super(pathname);
this.isDirectory = isDirectory;
}
public boolean isDirectory() {
return this.isDirectory;
}
public File[] listFiles() {
return children;
}
}
public DirectoryScannerTest(String s) {
super(s);
}
public void testSingleDirectory() {
MockFile rootDir = new MockFile("root", true);
rootDir.children = new File[]{new MockFile("blah.txt"), new MockFile("foo.txt"), new MockFile("pig.java")};
DirectoryScanner scanner = new DirectoryScanner(rootDir);
File[] files = scanner.scan();
assertEquals(3, files.length);
assertEquals("blah.txt", files[0].getName());
assertEquals("foo.txt", files[1].getName());
assertEquals("pig.java", files[2].getName());
}
public void testDirectoryWithSubdir() {
MockFile rootDir = new MockFile("root", true);
MockFile subDir = new MockFile("subdir", true);
subDir.children = new File[]{new MockFile("child1.txt"), new MockFile("child2.txt")};
rootDir.children = new File[]{subDir, new MockFile("foo.txt"), new MockFile("pig.java")};
DirectoryScanner scanner = new DirectoryScanner(rootDir);
File[] files = scanner.scan();
assertEquals(4, files.length);
assertEquals("child1.txt", files[0].getName());
assertEquals("child2.txt", files[1].getName());
assertEquals("foo.txt", files[2].getName());
assertEquals("pig.java", files[3].getName());
}
public void testDirectoryWithSubdirWithSubdir() {
MockFile rootDir = new MockFile("root", true);
MockFile subDir1 = new MockFile("subdir", true);
MockFile subDir2 = new MockFile("subdir2", true);
subDir2.children = new File[]{new MockFile("grandChild1.txt")};
subDir1.children = new File[]{subDir2, new MockFile("child1.txt"), new MockFile("child2.txt")};
rootDir.children = new File[]{subDir1, new MockFile("foo.txt"), new MockFile("pig.java")};
DirectoryScanner scanner = new DirectoryScanner(rootDir);
File[] files = scanner.scan();
assertEquals(5, files.length);
assertEquals("grandChild1.txt", files[0].getName());
assertEquals("child1.txt", files[1].getName());
assertEquals("child2.txt", files[2].getName());
assertEquals("foo.txt", files[3].getName());
assertEquals("pig.java", files[4].getName());
}
public void testSuffixFilter() {
MockFile rootDir = new MockFile("root", true);
rootDir.children = new File[]{new MockFile("blah.txt"), new MockFile("foo.java"), new MockFile("pig.java")};
DirectoryScanner scanner = new DirectoryScanner(rootDir);
scanner.addFilter(new SuffixFilter(".java"));
File[] files = scanner.scan();
assertEquals(2, files.length);
assertEquals("foo.java", files[0].getName());
assertEquals("pig.java", files[1].getName());
}
public void testFilterCallback() {
MockFile rootDir = new MockFile("root", true);
rootDir.children = new File[]{new MockFile("blah.txt"), new MockFile("foo.java"), new MockFile("pig.java")};
DirectoryScanner scanner = new DirectoryScanner(rootDir);
Filter mockFilter = new Filter() {
public boolean filter(File file) {
return file.getName().equals("foo.java");
}
};
scanner.addFilter(mockFilter);
File[] files = scanner.scan();
assertEquals(1, files.length);
assertEquals("foo.java", files[0].getName());
}
public void testMultipleFilters() {
MockFile rootDir = new MockFile("root", true);
rootDir.children = new File[]{new MockFile("blah.txt"), new MockFile("foo.java"),
new MockFile("pig.java"), new MockFile("foo.txt")};
DirectoryScanner scanner = new DirectoryScanner(rootDir);
scanner.addFilter(new SuffixFilter(".java"));
scanner.addFilter(new Filter() {
public boolean filter(File file) {
return file.getName().startsWith("foo");
}
});
File[] files = scanner.scan();
assertEquals(1, files.length);
assertEquals("foo.java", files[0].getName());
}
public void testFileVisitor() {
MockFile rootDir = new MockFile("root", true);
rootDir.children = new File[]{new MockFile("blah.txt"), new MockFile("foo.txt"), new MockFile("pig.java")};
DirectoryScanner scanner = new DirectoryScanner(rootDir);
Mock mockFileVisitor = new Mock(FileVisitor.class);
mockFileVisitor.expects(once()).method("visitFile").with(same(rootDir.children[0]));
mockFileVisitor.expects(once()).method("visitFile").with(same(rootDir.children[1]));
mockFileVisitor.expects(once()).method("visitFile").with(same(rootDir.children[2]));
scanner.scan((FileVisitor) mockFileVisitor.proxy());
mockFileVisitor.verify();
}
}
qdox-1.12/src/test/com/thoughtworks/qdox/AnnotationsModelTest.java 0000644 0001750 0001750 00000036466 11146334750 025357 0 ustar drazzib drazzib package com.thoughtworks.qdox;
import java.io.StringReader;
import java.util.ListIterator;
import junit.framework.TestCase;
import com.thoughtworks.qdox.model.Annotation;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField;
import com.thoughtworks.qdox.model.JavaMethod;
import com.thoughtworks.qdox.model.JavaPackage;
import com.thoughtworks.qdox.model.annotation.AnnotationAdd;
import com.thoughtworks.qdox.model.annotation.AnnotationConstant;
import com.thoughtworks.qdox.model.annotation.AnnotationFieldRef;
import com.thoughtworks.qdox.model.annotation.AnnotationTypeRef;
import com.thoughtworks.qdox.model.annotation.AnnotationValue;
import com.thoughtworks.qdox.model.annotation.AnnotationValueList;
import com.thoughtworks.qdox.model.annotation.EvaluatingVisitor;
public class AnnotationsModelTest extends TestCase {
private JavaDocBuilder builder;
private EvaluatingVisitor evaluatingVisitor = new EvaluatingVisitor() {
protected Object getFieldReferenceValue( JavaField javaField ) {
throw new UnsupportedOperationException();
}
};
protected void setUp() throws Exception {
super.setUp();
builder = new JavaDocBuilder();
builder.setDebugLexer( true );
builder.setDebugParser( true );
}
protected Annotation checkClassAnnotation( String source ) {
builder.addSource( new StringReader( source ) );
JavaClass clazz = builder.getClassByName( "Foo" );
assertEquals( "Annotations", 1, clazz.getAnnotations().length );
Annotation annotation = clazz.getAnnotations()[0];
assertEquals( "Annotation name", "Annotation", annotation.getType().getJavaClass().getFullyQualifiedName() );
return annotation;
}
public void testMarkerAnnotation() {
checkClassAnnotation( "@Annotation\nclass Foo {}" );
}
public void testEmptyAnnotation() {
checkClassAnnotation( "@Annotation()\nclass Foo {}" );
}
public void testAnnotationAnnotation() {
checkClassAnnotation( "@Annotation(@NestedAnnotation)\nclass Foo {}" );
}
public void testConstAnnotation() {
checkClassAnnotation( "@Annotation(1)\nclass Foo {}" );
}
public void testAnnotationConstants() {
String source = "@Annotation( f = 1.0, d = 1.0d, i = 1, ix = 0x1, l = 1L, lx = 0x1L, c = 'c', s = \"string\" )\nclass Foo {}";
builder.addSource( new StringReader( source ) );
JavaClass clazz = builder.getClassByName( "Foo" );
assertEquals( "Annotations", 1, clazz.getAnnotations().length );
Annotation annotation = clazz.getAnnotations()[0];
assertEquals( "Annotation name", "Annotation", annotation.getType().getJavaClass().getFullyQualifiedName() );
assertEquals( "Properties", 8, annotation.getNamedParameterMap().size() );
AnnotationConstant f = (AnnotationConstant) annotation.getProperty( "f" );
assertEquals( "f", new Float( 1 ), f.getValue() );
AnnotationConstant d = (AnnotationConstant) annotation.getProperty( "d" );
assertEquals( "d", new Double( 1 ), d.getValue() );
AnnotationConstant i = (AnnotationConstant) annotation.getProperty( "i" );
assertEquals( "i", new Integer( 1 ), i.getValue() );
AnnotationConstant ix = (AnnotationConstant) annotation.getProperty( "ix" );
assertEquals( "ix", new Integer( 1 ), ix.getValue() );
AnnotationConstant l = (AnnotationConstant) annotation.getProperty( "l" );
assertEquals( "l", new Long( 1 ), l.getValue() );
AnnotationConstant lx = (AnnotationConstant) annotation.getProperty( "lx" );
assertEquals( "lx", new Long( 1 ), lx.getValue() );
AnnotationConstant c = (AnnotationConstant) annotation.getProperty( "c" );
assertEquals( "c", new Character( 'c' ), c.getValue() );
AnnotationConstant s = (AnnotationConstant) annotation.getProperty( "s" );
assertEquals( "s", "string", s.getValue() );
}
public void testAnnotationConstantsControlChars() {
String source = "@Annotation( s1 = \"a\\nb\", s2 = \"a\\nb\", s3 = \"a\\rb\", s4 = \"a\\tb\", s5 = \"a\\u0009b\" ) class Foo {}";
builder.addSource( new StringReader( source ) );
JavaClass clazz = builder.getClassByName( "Foo" );
assertEquals( "Annotations", 1, clazz.getAnnotations().length );
Annotation annotation = clazz.getAnnotations()[0];
assertEquals( "Annotation name", "Annotation", annotation.getType().getJavaClass().getFullyQualifiedName() );
assertEquals( "Properties", 5, annotation.getPropertyMap().size() );
AnnotationConstant s1 = (AnnotationConstant) annotation.getProperty( "s1" );
assertEquals( "s1", "a\nb", s1.getValue() );
AnnotationConstant s2 = (AnnotationConstant) annotation.getProperty( "s2" );
assertEquals( "s2", "a\nb", s2.getValue() );
AnnotationConstant s3 = (AnnotationConstant) annotation.getProperty( "s3" );
assertEquals( "s3", "a\rb", s3.getValue() );
AnnotationConstant s4 = (AnnotationConstant) annotation.getProperty( "s4" );
assertEquals( "s4", "a\tb", s4.getValue() );
AnnotationConstant s5 = (AnnotationConstant) annotation.getProperty( "s5" );
assertEquals( "s5", "a\u0009b", s5.getValue() );
}
public void testNestedAnnotation() {
String source = "@Annotation( { @Inner(1), @Inner(2) } ) class Foo {}";
builder.addSource( new StringReader( source ) );
JavaClass clazz = builder.getClassByName( "Foo" );
assertEquals( "Annotations", 1, clazz.getAnnotations().length );
Annotation annotation = clazz.getAnnotations()[0];
assertEquals( "Annotation name", "Annotation", annotation.getType().getJavaClass().getFullyQualifiedName() );
assertEquals( "Properties", 1, annotation.getPropertyMap().size() );
AnnotationValueList list = (AnnotationValueList) annotation.getProperty( "value" );
assertEquals( "Inner Annotations", 2, list.getValueList().size() );
for( ListIterator i = list.getValueList().listIterator(); i.hasNext(); ) {
Annotation inner = (Annotation) i.next();
assertEquals( "Inner " + i.previousIndex(), "Inner", inner.getType().getValue() );
}
}
public void testExpressionAnnotation1() {
String source = "@Annotation( 1 + 1 ) class Foo {}";
builder.addSource( new StringReader( source ) );
JavaClass clazz = builder.getClassByName( "Foo" );
assertEquals( "Annotations", 1, clazz.getAnnotations().length );
Annotation annotation = clazz.getAnnotations()[0];
assertEquals( "Annotation name", "Annotation", annotation.getType().getJavaClass().getFullyQualifiedName() );
assertEquals( "Properties", 1, annotation.getPropertyMap().size() );
AnnotationAdd add = (AnnotationAdd) annotation.getProperty( "value" );
assertEquals( "Left", new Integer( 1 ), ((AnnotationConstant) add.getLeft()).getValue() );
assertEquals( "Right", new Integer( 1 ), ((AnnotationConstant) add.getRight()).getValue() );
}
public void testExpressionAnnotation2() {
String source = "@Annotation( \"value = \" + 1 ) class Foo {}";
builder.addSource( new StringReader( source ) );
JavaClass clazz = builder.getClassByName( "Foo" );
assertEquals( "Annotations", 1, clazz.getAnnotations().length );
Annotation annotation = clazz.getAnnotations()[0];
assertEquals( "Annotation name", "Annotation", annotation.getType().getJavaClass().getFullyQualifiedName() );
assertEquals( "Properties", 1, annotation.getPropertyMap().size() );
AnnotationAdd add = (AnnotationAdd) annotation.getProperty( "value" );
assertEquals( "Left", "value = ", ((AnnotationConstant) add.getLeft()).getValue() );
assertEquals( "Right", new Integer( 1 ), ((AnnotationConstant) add.getRight()).getValue() );
}
public void testFieldRefAnnotation() {
String source = "@Annotation( java.lang.Math.E ) class Foo {}";
builder.addSource( new StringReader( source ) );
JavaClass clazz = builder.getClassByName( "Foo" );
assertEquals( "Annotations", 1, clazz.getAnnotations().length );
Annotation annotation = clazz.getAnnotations()[0];
assertEquals( "Annotation name", "Annotation", annotation.getType().getJavaClass().getFullyQualifiedName() );
assertEquals( "Properties", 1, annotation.getPropertyMap().size() );
AnnotationFieldRef value = (AnnotationFieldRef) annotation.getProperty( "value" );
assertEquals( "type", "double", value.getField().getType().getValue() );
assertEquals( "class part", "java.lang.Math", value.getClassPart() );
assertEquals( "field part", "E", value.getFieldPart() );
}
public void testPrimitiveClassAnnotation() {
String source = "@Annotation( int.class ) class Foo {}";
builder.addSource( new StringReader( source ) );
JavaClass clazz = builder.getClassByName( "Foo" );
assertEquals( "Annotations", 1, clazz.getAnnotations().length );
Annotation annotation = clazz.getAnnotations()[0];
assertEquals( "Annotation name", "Annotation", annotation.getType().getJavaClass().getFullyQualifiedName() );
assertEquals( "Properties", 1, annotation.getPropertyMap().size() );
Object value = annotation.getProperty( "value" );
AnnotationTypeRef ref = (AnnotationTypeRef) value;
assertEquals( "value", "int", ref.getType().getValue() );
}
public void testClassAnnotation() {
String source = "@Annotation( java.util.Set.class ) class Foo {}";
builder.addSource( new StringReader( source ) );
JavaClass clazz = builder.getClassByName( "Foo" );
assertEquals( "Annotations", 1, clazz.getAnnotations().length );
Annotation annotation = clazz.getAnnotations()[0];
assertEquals( "Annotation name", "Annotation", annotation.getType().getJavaClass().getFullyQualifiedName() );
assertEquals( "Properties", 1, annotation.getPropertyMap().size() );
Object value = annotation.getProperty( "value" );
AnnotationTypeRef ref = (AnnotationTypeRef) value;
assertEquals( "value", "java.util.Set", ref.getType().getValue() );
}
protected void assertAnnotationValue( Object expected ) {
JavaClass clazz = builder.getClassByName( "Foo" );
assertEquals( "Annotations", 1, clazz.getAnnotations().length );
Annotation annotation = clazz.getAnnotations()[0];
assertEquals( "Annotation name", "Annotation", annotation.getType().getJavaClass().getFullyQualifiedName() );
assertEquals( "Properties", 1, annotation.getPropertyMap().size() );
AnnotationValue value = annotation.getProperty( "value" );
Object v = value.accept( evaluatingVisitor );
assertEquals( "Value", expected, v );
}
protected void assertAnnotationExpression( String expression, Object expected ) {
String source = "@Annotation(\n" + expression + "\n) class Foo {}";
builder.addSource( new StringReader( source ) );
assertAnnotationValue( expected );
}
public void testPrecedence() {
assertAnnotationExpression( "2 + 2 * 5", new Integer( 12 ) );
assertAnnotationExpression( "2 * 5 + 2", new Integer( 12 ) );
}
public void testLogicalExpression() {
assertAnnotationExpression( "true && false", Boolean.FALSE );
assertAnnotationExpression( "true || false", Boolean.TRUE );
assertAnnotationExpression( "!true", Boolean.FALSE );
}
public void testBitExpression() {
assertAnnotationExpression( "1 & 3", new Integer( 1 & 3 ) );
assertAnnotationExpression( "1 | 3", new Integer( 1 | 3 ) );
assertAnnotationExpression( "1 ^ 3", new Integer( 1 ^ 3 ) );
assertAnnotationExpression( "~1", new Integer( ~1 ) );
}
public void testSignExpression() {
assertAnnotationExpression( "+1", new Integer( 1 ) );
assertAnnotationExpression( "-1", new Integer( -1 ) );
assertAnnotationExpression( "--1", new Integer( 1 ) );
}
public void testAddSubMultDivExpression() {
assertAnnotationExpression( "8 / 3", new Integer( 8 / 3 ) );
assertAnnotationExpression( "8 * 3", new Integer( 8 * 3 ) );
assertAnnotationExpression( "8 + 3", new Integer( 8 + 3 ) );
assertAnnotationExpression( "8 - 3", new Integer( 8 - 3 ) );
assertAnnotationExpression( "8 % 3", new Integer( 8 % 3 ) );
assertAnnotationExpression( "\"a\" + \"b\"", "a" + "b" );
}
public void testShiftExpression() {
assertAnnotationExpression( "8 << 2", new Integer( 8 << 2 ) );
assertAnnotationExpression( "8 >> 2", new Integer( 8 >> 2 ) );
assertAnnotationExpression( "-1 >> 2", new Integer( -1 >> 2 ) );
assertAnnotationExpression( "-1 >>> 2", new Integer( -1 >>> 2 ) );
}
public void testLiteral() {
assertAnnotationExpression( "1", new Integer( 1 ) );
assertAnnotationExpression( "1l", new Long( 1 ) );
assertAnnotationExpression( "1.0", new Float( 1 ) );
assertAnnotationExpression( "1.0d", new Double( 1 ) );
}
public void testParenExpression() {
assertAnnotationExpression( "2 + (2 * 5)", new Integer( 12 ) );
assertAnnotationExpression( "(2 + 2) * 5", new Integer( 20 ) );
}
public void testCompareExpression() {
assertAnnotationExpression( "1 < 2", Boolean.TRUE );
assertAnnotationExpression( "1 > 2", Boolean.FALSE );
assertAnnotationExpression( "1 <= 2", Boolean.TRUE );
assertAnnotationExpression( "1 >= 2", Boolean.FALSE );
assertAnnotationExpression( "1 == 2", Boolean.FALSE );
assertAnnotationExpression( "1 != 2", Boolean.TRUE );
}
public void testQueryExpression() {
assertAnnotationExpression( "1 < 2 ? 0 : 3", new Integer( 0 ) );
assertAnnotationExpression( "1 > 2 ? 0 : 3", new Integer( 3 ) );
}
public void testCastExpression() {
assertAnnotationExpression( "(short)1", new Short( (short) 1 ) );
assertAnnotationExpression( "(long)(short)1", new Long( 1 ) );
assertAnnotationExpression( "(int)((short)1 + (long)3)", new Integer( 4 ) );
}
//from Qdox-98
public void testPackageWithAnnotation() throws Exception {
String source = "@javax.xml.bind.annotation.XmlSchema(namespace = \"http://docs.oasis-open.org/wsn/br-2\")\n" +
"package org.oasis_open.docs.wsn.br_2;\n" +
"public class Foo {}";
builder.addSource(new StringReader(source));
JavaPackage jPackage = builder.getClasses()[0].getPackage();
assertEquals("org.oasis_open.docs.wsn.br_2", jPackage.getName());
assertEquals("javax.xml.bind.annotation.XmlSchema", jPackage.getAnnotations()[0].getType().getValue());
assertEquals(2, jPackage.getLineNumber());
}
// http://jira.codehaus.org/browse/QDOX-135
public void testAnnotationInMethodParamList() {
String source = ""
+ "class Foo {\n"
// + " @X()\n" - does not affect test.
+ " public String xyz(@Y(1) int blah) {\n"
+ " }\n"
+ "}\n";
builder.addSource(new StringReader(source));
JavaClass clazz = builder.getClassByName("Foo");
JavaMethod mth = clazz.getMethods()[0];
assertEquals("Foo", clazz.getName());
}
}
qdox-1.12/src/test/com/thoughtworks/qdox/TestQDoxBug131.java 0000644 0001750 0001750 00000002206 11140671276 023621 0 ustar drazzib drazzib package com.thoughtworks.qdox;
import java.io.StringReader;
import junit.framework.TestCase;
import com.thoughtworks.qdox.model.JavaClass;
public class TestQDoxBug131 extends TestCase {
public void testname() throws Exception {
String sourceCode = "package com.acme.qdox;\n" +
"\n" +
"public class QDoxBugClass {\n" +
" final public static String C1 = \"C1\", C2 = \"C2\";\n" +
" final public static String[] ALL = { C1, C2 }; \n" +
" /*\n" +
" Comment\n" +
" */\n" +
" public void method() {\n" +
" System.out.println(\"This will contain the comment\");\n" +
" }\n" +
"}\n" +
"";
JavaDocBuilder builder = new JavaDocBuilder();
builder.addSource(new StringReader(sourceCode));
JavaClass aClass = builder.getClassByName("com.acme.qdox.QDoxBugClass");
assertEquals("\n System.out.println(\"This will contain the comment\");\n ",
aClass.getMethods()[0].getSourceCode());
}
}
qdox-1.12/src/test/com/thoughtworks/qdox/MethodsTest.java 0000644 0001750 0001750 00000004135 11153061716 023465 0 ustar drazzib drazzib package com.thoughtworks.qdox;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaMethod;
import com.thoughtworks.qdox.model.JavaSource;
import com.thoughtworks.qdox.model.Type;
import com.thoughtworks.qdox.model.JavaParameter;
import junit.framework.TestCase;
import java.io.StringReader;
public class MethodsTest extends TestCase {
private JavaDocBuilder builder = new JavaDocBuilder();
public void testSupportsJava5VarArgsParameter() {
JavaMethod javaMethod = buildMethod("void doStuff(AThing param1, BThing... param2);");
JavaParameter standardParam = javaMethod.getParameterByName("param1");
JavaParameter varArgsParam = javaMethod.getParameterByName("param2");
assertFalse("param1 should NOT be var args", standardParam.isVarArgs());
assertTrue("param2 should be var args", varArgsParam.isVarArgs());
}
public void testVarArgsParametersAreAlsoArrays() {
JavaMethod javaMethod = buildMethod("void doStuff(AThing param1, BThing[] param2, CThing... param3);");
Type standardType = javaMethod.getParameterByName("param1").getType();
Type arrayType = javaMethod.getParameterByName("param2").getType();
Type varArgsType = javaMethod.getParameterByName("param3").getType();
assertFalse("param1 should NOT be array", standardType.isArray());
assertTrue("param2 should be array", arrayType.isArray());
assertFalse("param3 should NOT be array", varArgsType.isArray());
}
public void testVarArgsIncludedInToString() {
JavaMethod javaMethod = buildMethod("void doStuff(AThing param1, BThing... param2);");
assertEquals("void doStuff(AThing param1, BThing... param2);\n", javaMethod.getCodeBlock());
}
private JavaMethod buildMethod(String methodSource) {
String source = "interface Something { " + methodSource + " }";
JavaSource javaSource = builder.addSource(new StringReader(source));
JavaClass javaClass = javaSource.getClasses()[0];
JavaMethod javaMethod = javaClass.getMethods()[0];
return javaMethod;
}
}
qdox-1.12/src/test/com/thoughtworks/qdox/GenericsTest.java 0000644 0001750 0001750 00000035363 11401016326 023621 0 ustar drazzib drazzib package com.thoughtworks.qdox;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField;
import com.thoughtworks.qdox.model.JavaMethod;
import junit.framework.TestCase;
import java.io.StringReader;
/**
* @author Joe Walnes
* @author Aslak Hellesøy
* @author Mike Williams
*/
public class GenericsTest extends TestCase {
private JavaDocBuilder builder = new JavaDocBuilder();
public void testShouldUnderstandSingleGenericClassDeclarations() {
String source = "" +
"public interface Foo extends Bar {}";
builder.addSource(new StringReader(source));
assertEquals("Foo", builder.getClassByName("Foo").getName());
}
public void testShouldUnderstandMultipleGenericClassDeclarations() {
String source = "" +
"public interface Foo extends Bar {}";
builder.addSource(new StringReader(source));
assertEquals("Foo", builder.getClassByName("Foo").getName());
}
public void testShouldUnderstandMultipleGenericsInMethodDeclarations() {
String source = "" +
"public interface Foo {" +
" Bar zap(Zip r);" +
"}";
builder.addSource(new StringReader(source));
assertEquals("Foo", builder.getClassByName("Foo").getName());
}
public void testShouldUnderstandOuterAndInnerClassGenericsInMethodDeclarations() {
String source = "" +
" public interface Foo {\n" +
" void zap(Outer.Inner arg);\n" +
" }";
builder.addSource(new StringReader(source));
assertEquals("Foo", builder.getClassByName("Foo").getName());
}
public void testShouldUnderstandMultipleGenericsInConstructorDeclarations() {
String source = "" +
"public class Bar {" +
" public Bar(Zip r) {}" +
"}";
builder.addSource(new StringReader(source));
assertEquals("Bar", builder.getClassByName("Bar").getName());
}
public void testShouldUnderstandMultipleGenericsInFieldDeclarations() {
String source = "" +
"public class Bar {" +
" private Foo foo;" +
"}";
builder.addSource(new StringReader(source));
assertEquals("Bar", builder.getClassByName("Bar").getName());
}
public void testShouldUnderstandNestedGenerics() {
String source = "" +
"public class Bar {" +
" private List> listOfLists;" +
"}";
builder.addSource(new StringReader(source));
assertEquals("Bar", builder.getClassByName("Bar").getName());
}
public void testShouldUnderstandFullyQualifiedTypeArguments() {
String source = "" +
"public class Bar {" +
" private List listOfDates;" +
"}";
builder.addSource(new StringReader(source));
assertEquals("Bar", builder.getClassByName("Bar").getName());
}
public void testShouldUnderstandBoundedTypeParameters() {
String source = "" +
"public class Bar {}";
builder.addSource(new StringReader(source));
assertEquals("Bar", builder.getClassByName("Bar").getName());
}
public void testShouldUnderstandComplexBoundedTypeParameters() {
String source = "" +
"public class Bar {}";
builder.addSource(new StringReader(source));
assertEquals("Bar", builder.getClassByName("Bar").getName());
}
public void testShouldUnderstandWildcardTypeArguments() {
String source = "" +
"public class Bar { private Class extends Date> klass; }";
builder.addSource(new StringReader(source));
assertEquals("Bar", builder.getClassByName("Bar").getName());
}
public void testShouldUnderstandBoundedWildcardTypeArguments() {
String source = "" +
"public class Bar { Map super String, ? extends Date> klass; }";
builder.addSource(new StringReader(source));
assertEquals("Bar", builder.getClassByName("Bar").getName());
}
public void testShouldUnderstandMethodTypeParameters() {
String source = "" +
"public class Bar {" +
" public static > T max(Collection collection) {" +
" throw new UnsupportedOperationException();" +
" }" +
"}";
builder.addSource(new StringReader(source));
assertEquals("Bar", builder.getClassByName("Bar").getName());
}
public void testGenericField() {
// Also see QDOX-77
String source = "" +
"public class Foo {\n" +
" protected Map m_env = new HashMap();\n" +
" public Object retrieve(Class klass, Object key) {\n" +
" return x;\n" +
" }\n" +
"}\n";
builder.addSource(new StringReader(source));
JavaClass fooClass = builder.getClassByName("Foo");
assertNotNull(fooClass);
assertEquals("Foo", fooClass.getName());
JavaField envField = fooClass.getFieldByName("m_env");
assertNotNull(envField);
assertEquals("Map", envField.getType().getValue());
}
public void testGenericFieldInstantiation() {
// Also see QDOX-77
String source = "" +
"public class Foo {\n" +
" protected Map m_env = new HashMap();\n" +
" public Object retrieve(Class klass, Object key) {\n" +
" return x;\n" +
" }\n" +
"}\n";
builder.addSource(new StringReader(source));
JavaClass fooClass = builder.getClassByName("Foo");
assertNotNull(fooClass);
assertEquals("Foo", fooClass.getName());
JavaField envField = fooClass.getFieldByName("m_env");
assertNotNull(envField);
assertEquals("Map", envField.getType().getValue());
}
public void testGenericFieldInstantiationHalfComplex() {
// Also see QDOX-77
String source = "" +
"public class Foo {\n" +
" protected Map, Object> m_env = new HashMap, Object>();\n" +
" public Object retrieve(Class klass, Object key) {\n" +
" return x;\n" +
" }\n" +
"}\n";
builder.addSource(new StringReader(source));
JavaClass fooClass = builder.getClassByName("Foo");
assertNotNull(fooClass);
assertEquals("Foo", fooClass.getName());
JavaField envField = fooClass.getFieldByName("m_env");
assertNotNull(envField);
assertEquals("Map", envField.getType().getValue());
}
public void testGenericFieldInstantiationComplex() {
// Also see QDOX-77
String source = "" +
"public class Foo {\n" +
" protected Map, Object> m_env = new HashMap, Object>();\n" +
" public Object retrieve(Class klass, Object key) {\n" +
" return x;\n" +
" }\n" +
"}\n";
builder.addSource(new StringReader(source));
JavaClass fooClass = builder.getClassByName("Foo");
assertNotNull(fooClass);
assertEquals("Foo", fooClass.getName());
JavaField envField = fooClass.getFieldByName("m_env");
assertNotNull(envField);
assertEquals("Map", envField.getType().getValue());
}
public void testGenericFieldInstantiationVeryComplex() {
// Also see QDOX-77
String source = "" +
"public class Foo {\n" +
" protected Map