qdox-qdox-2.0-M8/000077500000000000000000000000001325201777200135675ustar00rootroot00000000000000qdox-qdox-2.0-M8/.gitignore000066400000000000000000000000621325201777200155550ustar00rootroot00000000000000/target/ /.project /target /.classpath /.settings qdox-qdox-2.0-M8/.travis.yml000066400000000000000000000001111325201777200156710ustar00rootroot00000000000000language: java jdk: - openjdk7 - oraclejdk8 script: mvn clean verify qdox-qdox-2.0-M8/LICENSE.txt000066400000000000000000000011011325201777200154030ustar00rootroot00000000000000Copyright 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-qdox-2.0-M8/README.md000066400000000000000000000500201325201777200150430ustar00rootroot00000000000000# QDox ### Status [![Build Status](https://travis-ci.org/paul-hammant/qdox.png)](https://travis-ci.org/paul-hammant/qdox) QDox is a high speed, small footprint parser for fully extracting class/interface/method definitions (including annotations, parameters, param names). It is designed to be used by active code generators or documentation tools. Not so relevant any more, but it also also processes JavaDoc @tags # Migration from Codehaus This project used to be on Codehaus, in Subversion. The trunk of that has been git-svn-cloned to here. Maven repos have the sources jars for released versions of Qdox. The [old issues from codehaus are hosted statically on a GH-pages repo](http://paul-hammant.github.io/Old_Qdox_Issues/) # Download Maven's central repo [holds versions of QDox](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.thoughtworks.qdox%22%20AND%20a%3A%22qdox%22) # In A Nutshell A custom built parser has been built using JFlex and BYacc/J. These have been chosen because of their proven performance and they require no external libraries at runtime. The parser skims the source files only looking for things of interest such as class/interface definitions, import statements, JavaDoc and member declarations. The parser ignores things such as actual method implementations to avoid overhead (while in method blocks, curly brace counting suffices). The end result of the parser is a very simple document model containing enough information to be useful. # Frequently Asked Questions ## General ### What's the object type of an interface? The JavaClass method is used to represent both classes and interfaces. The isInterface() method allows you to distinguish between the two. When using a class, the getSuperClass() return which class is extended. If this has not been defined in the input source code, java.lang.Object is returned. When using an interface, this method ALWAYS returns null. When using a class, the getImplements() returns an array of the interfaces implemented by the class. If none are implemented, an empty array is returned. When using an interface, this returns an array of interfaces the current interface EXTENDS. ## Can I have full control over the classloader? I some cases QDox is used to generate classes for another project with it's own dependencies. This could result in class-collision. By default the JavadocBuilder will contain the classloader(s) of the current project, but by defining your own classLibrary you can have the required control. ```java /* new ClassLibrary() will give you an empty classLoader * Big chance you want at least the system classloader. */ ClassLibraryBuilder libraryBuilder = new SortedClassLibraryBuilder(); //or OrderedClassLibraryBuilder() libraryBuilder.addClassLoader( ClassLoader.getSystemClassLoader() ); JavaProjectBuilder builder = new JavaProjectBuilder( libraryBuilder ); ``` ## I'm getting an ArrayIndexOutOfBoundsException: 500. What to do? During the parsing of java files the Parser needs to remember states, which are kept in a stack. Due to recursive calls the stack can become very large. By default the size of this this stack is 500 and it can only be set during compile-time of QDox. Normally 500 per sourcefile will do, but in very, very rare cases this might be too little. The only way to increase this number is by rebuilding it. Download the sources and build it like mvn install -Dqdox.javaparser.stack=750 if you want to change it to 750. # Download QDox is available at the Maven Central. To include the most recent of QDox in your pom, include the following dependency: ```xml ${project.groupId} ${project.artifactId} ${project.version} ``` Latest stable release - QDox ${project.rel.org.thoughtworks.qdox:qdox}: binary jar | sources jar | javadoc jar | project tar.bz2 | project tar.gz | project zip # What is using QDox Project Description How QDox is Used AspectWerkz AspectWerkz is an Aspect Oriented Programming (AOP) toolkit for Java that modifies byte-code to weave in interceptors and mixins. Attributes can be used to associate interceptors and mixins with a specific class. ## Avalon Phoenix Phoenix was a micro-kernel designed and implemented on top of the Avalon framework. It provided a number of facilities to manage the environment of Server Applications. Apache cancelled the Avalon project 2004 'MetaGenerate' is part of the Phoenix toolset and picks up @phoenix prefixed JavaDoc tags to make XML manifests for the components that will be laced together in more XML to make a complete server application. ## Cocoon Apache Cocoon is an XML publishing framework that raises the usage of XML and XSLT technologies for server applications to a new level. Designed for performance and scalability around pipelined SAX processing, Cocoon offers a flexible environment based on a separation of concerns between content, logic, and style. The QDox Block reads in Java source files and fires out SAX events enabling processing by standard XML tools (such as XSLT). ## Commons Attribute Jakarta Commons Attributes provides an API to runtime metadata attributes. Attributes are specified as doclet tags and then compiled into the classpath where they can be accessed at runtime (without requiring the source). The aim is to provide a framework similar to .NET attributes. QDox is used to extract the JavaDoc tags from the source files. ## GWT-maven-plugin The gwt-maven-plugin provides support for GWT projects, including running the GWT developer tools (the compiler, shell and i18n generation) and performing support operations to help developers make GWT fit more closely in with their standard JEE web application development (debugging, managing the embedded server, running noserver, merging web.xml, generating I18N interfaces, generating Async GWT-RPC interfaces, and more) and environment (Eclipse IDE). QDox is used to generate the Async GWT-RPC interfaces based on their Service-classes. ## Ivory Ivory provides easy integration between your exiting Java classes, Avalon services, and Axis. It allows easy deployment of soap services with none of the WSDD configuration that Axis normally mandates. Attributes are used to provide additional hints to Ivory about Java classes that cannot be determined via reflection. ## maven-javadoc-plugin The Javadoc Plugin uses the Javadoc tool to generate javadocs for the specified project. When developers write code, they could forget to create (or update) the Javadoc comments. The and goals are interactive goals to fix the actual Javadoc comments. Maven 2 & 3 ## Maven is a software project management and comprehension tool. QDox is used for extraction of Javadoc tags from source files to generate plugin descriptors ## Mock Maker Mock Maker is a tool for automatically generating mock objects from custom classes to aid in testing the untestable. This supports the practises of Test Driven Development and eXtreme Programming. Mock Maker scans the source repository for any class/interface marked with the @mock JavaDoc tag and automatically creates the Mock Object for this that matches the class definition. ## Nanning Nanning is an Aspect Oriented Programming (AOP) toolkit for Java that does not require a custom compiler. It uses dynamic proxies to weave in interceptors and mixins at runtime. QDox is used to allow aspects to be applied to classes by specifiying meta-data in doclet tags. ## Paranamer Paranamer a mechamism for accessing the parameter names of methods of Java classes compiled into jars. QDox is used to parse the source and generate the parameter names list. ## Spring ME A version of Spring that not only has a very small runtime footprint (none), but also is capable of running on small handheld devices, since it does not rely on reflection. ## vDoclet vDoclet is a framework for code-generation using Velocity templates, based on annotated Java source-code. vDoclet uses QDox to produce input-data for it's templates. ## Voruta Voruta is a data access framework for embedding SQL statements in Java methods using custom JavaDoc tags and dynamic code generation at runtime. QDox is used to parse metadata and CGLib to generate implementation at runtime. ## XDoclet2 XDoclet2 is a framework for code-generation using Velocity or Jelly templates, based on annotated Java source-code. It is a rewrite of XDoclet. XDoclet2 uses QDox to produce input-data for it's templates, as well as QDox' APITestCase to validate the generated sources. # QDox Usage ## Entry Point JavaProjectBuilder is the entry point to QDox. It is responsible for parsing source code, resolving imports and storing the data. To create it, all you need to do is call the default constructor. ```java JavaProjectBuilder builder = new JavaProjectBuilder(); ``` ## Reading Source Files Java source code can then be added to the JavaProjectBuilder. Source can either be read one file at a time (using a java.io.Reader) or an entire source tree can be added recursively. ```java // Reading a single source file. builder.addSource(new FileReader("MyFile.java")); // Reading from another kind of input stream. builder.addSource(new StringReader("package test; public class Hello {}")); // Adding all .java files in a source tree (recursively). builder.addSourceTree(new File("mysrcdir")); ``` ## Resolving Class Names In order to resolve classes that have been imported using a wildcard (e.g. import java.util.*;), the ClassLibrary must be aware of other classes used in the project. ClassLibrary has 4 ways to resolve classes: * By looking at other sources that have been added. * By searching through the supplied sourceFolders * By looking in the current classpath (including the standard JRE classes). * By looking at additional ClassLoaders specified at runtime. All sources and sourcetrees added to the JavaProjectBuilder will be parsed. This is often much more than required. To increase efficiency use the ClassLibrary to add sourcefolders. Consider these files as lazy parsed sources. The current classpath is automatically set by JavaProjectBuilder. In most cases this shall be sufficient, however in some situations you may want resolve the full classes in external libraries. ```java // Get the ClassLibrary JavaProjectBuilder builder = new JavaProjectBuilder(); // Add a sourcefolder; builder.addSourceFolder( new File( "src/main/java" ) ); builder.addSourceFolder( new File( "target/generated-sources/foobar" ) ); // Add a custom ClassLoader builder.addClassLoader( myCustomClassLoader ); // Ant example : add the element's contents builder.addClassLoader( new AntClassLoader( getProject(), classpath ) ); ``` It is important that additional ClassLoaders are added before any source files are parsed. ## Navigating The Model Now the files have been parsed, move on to navigating the model. # The Model After the source code has been parsed, the content of the files can be navigated using a simple to use and intuitive object model. ## JavaSource Represents a complete .java file. This contains a collection of classes. Example Input ```java package com.blah.foo; import java.awt.*; import java.util.List; public class Class1 { ... } class Class2 { } interface Interface1 { } ``` ```java Example Code JavaProjectBuilder builder = new JavaProjectBuilder(); JavaSource src = builder.addSource(myReader); JavaPackage pkg = src.getPackage(); List imports = src.getImports(); // {"java.awt.*", // "java.util.List"} JavaClass class1 = src.getClasses().get(0); JavaClass class2 = src.getClasses().get(1); JavaClass interface1 = src.getClasses().get(2); ``` ## JavaPackage Represents the package of the class. Example input ```java package com.blah.foo; public class BarClass { ... } ``` Example Code ```java JavaProjectBuilder builder = new JavaProjectBuilder(); JavaSource src = builder.addSource(myReader); JavaPackage pkg = src.getPackage(); Collection classes = pkg.getClasses(); // BarClass String name = pkg.getName(); // "com.blah.foo" String toString = pkg.toString(); // "package com.blah.foo" conform javaAPI JavaPackage parent = pkg.getParentPackage(); // ``` ## JavaClass Represents a class or interface. This contains doclet tags, fields and methods. Information about the class definition is available, such as which classes are extended, which interfaces implemented and modifiers. ```java Example Input package com.blah.foo; import java.io.*; import com.custom.*; import com.base.SubClass; /** * @author Joe */ public abstract class MyClass extends SubClass implements Serializable, CustomInterface { private String name; public void doStuff() { ... } private int getNumber() { ... } } ``` Example Code ```java JavaProjectBuilder builder = new JavaProjectBuilder(); builder.addSource(myReader); JavaClass cls = builder.getClassByName("com.blah.foo.MyClass"); String pkg = cls.getPackage(); // "com.blah.foo" String name = cls.getName(); // "MyClass" String fullName = cls.getCanonicalName(); // "com.blah.foo.MyClass"; String canonicalName = cls.getFullyQualifiedName(); // "com.blah.foo.MyClass"; boolean isInterface = cls.isInterface(); // false boolean isPublic = cls.isPublic(); // true boolean isAbstract = cls.isAbstract(); // true boolean isFinal = cls.isFinal(); // false JavaType superClass = cls.getSuperClass(); // "com.base.SubClass"; List imps = cls.getImplements(); // {"java.io.Serializable", // "com.custom.CustomInterface"} String author = cls.getTagsByName("author").getValue(); // "joe" JavaField nameField = cls.getFields()[0]; JavaMethod doStuff = cls.getMethods()[0]; JavaMethod getNumber = cls.getMethods()[1]; JavaSource javaSource = cls.getParentSource(); ``` ## JavaField Represents a field in a class. This has doclet tags, a name and a type. Example Input ```java import java.util.Date; public class MyClass { /** * @magic */ private String email; public static Date[][] dates; } ``` Example Code ```java JavaField e = cls.getFields()[0]; JavaType eType = e.getType(); // "java.lang.String"; String eName = e.getName(); // "email"; DocletTag eTag = e.getTagsByName("magic"); // @magic boolean eArray = e.getType().isArray(); // false; JavaField d = cls.getFields()[1]; JavaType dType = d.getType(); // "java.util.Date"; String dName = d.getName(); // "dates"; DocletTag dTag = d.getTagsByName("magic"); // null boolean dArray = d.getType().isArray(); // true; int dDimensions= d.getType().getDimensions(); // 2; boolean dStatic= d.isStatic(); // true; JavaClass javaClass = d.getParentClass(); ``` ## JavaMethod Represents a method in a class. This has doclet tags, a name, return type, parameters and exceptions. Example Input ```java import java.util.Date; import java.io.*; public class MyClass { /** * @returns Lots of dates */ public static Date[] doStuff(int number, String stuff) throws RuntimeException, IOException { ... } } ``` Example Code ```java JavaMethod m = cls.getMethods()[0]; String mName = m.getName(); // "doStuff"; JavaType mReturns = m.getReturns(); // "java.util.Date"; boolean mArray = m.getReturns().isArray(); // true boolean mStatic = m.isStatic(); // true boolean mPublic = m.isPublic(); // true String doc = m.getTagByName("returns").getValue(); // "Lots of dates" List exceptions = m.getExceptions(); // {"java.lang.RuntimeException", "java.io.IOException"} JavaParameter numberParam = m.getParameters()[0]; JavaParameter stuffParam = m.getParameters()[1]; JavaClass javaClass = m.getParentClass(); ``` ## JavaParameter Represents a parameter passed to a method. This has a name and a type. ```java Example Input public class MyClass { public void stuff(int n, Object[] objects) { ... } } ``` Example Code ```java JavaMethod m = cls.getMethods()[0]; JavaParameter n = m.getParameters()[0]; String nName = n.getName(); // "n" JavaType nType = n.getType(); // "int"; JavaParameter o = m.getParameters()[1]; String oName = o.getName(); // "objects" JavaType oType = o.getType(); // "java.lang.Object"; boolean oArray = o.getType().isArray(); // true JavaMethod javaMethod = o.getParentMethod(); ``` ## JavaType Represents a specific instance of a class used by another class (such as return value, superclass, etc). The value represents the name of the class. Array dimensions are also available. Since 1.8 it's also possible to get the generic value of the Type Example Input ```java import java.util.*; public class MyClass { public void stuff(int n, Object[] objects, Date[][] dates, List stringList) { ... } } ``` Example Code ```java JavaMethod m = cls.getMethods()[0]; JavaType returns = m.getReturns(); returns.getValue(); // "void" returns.isArray(); // false returns.getDimensions(); // 0 JavaType n = m.getParameters()[0].getType(); n.getValue(); // "int" n.isArray(); // false n.getDimensions(); // 0 JavaType objects = m.getParameters()[1].getType(); objects.getValue(); // "java.lang.Object" objects.isArray(); // true objects.getDimensions(); // 1 JavaType dates = m.getParameters()[2].getType(); dates.getValue(); // "java.util.Date" dates.isArray(); // true dates.getDimensions(); // 2 JavaType stringList = m.getParameters()[3].getType(); stringList.getValue(); // "java.util.List" stringList.getGenericValue(); // "java.util.List" stringList.isArray(); // false stringList.getDimensions(); // 0 ``` ## DocletTag Represents a JavaDoc tag. Each tag has a name and a value. Optionally, the value can be broken up into tokens accessed by index or name. The JavaClass, JavaField and JavaMethod classes all support comments and DocletTags The returned DocletTag carries the name, value and methods for breaking up the value into specific parameters. Example Input ```java /** * This method does nothing at all. * * @returns A boolean of whether we care or not. * @param email Someone's email address. * @param dob Date of birth. * * @permission administrator full-access * @webservice publish=true name=myservice type=rpc */ boolean doWeCare(String email, Date dob); ``` Example Code ```java JavaMethod mth = cls.getMethods()[0]; // Access the JavaDoc comment String comment = mth.getComment(); // "This method does nothing at all." // Access a single doclet tag DocletTag returns = mth.getTagByName("returns"); returns.getName(); // "returns"; returns.getValue(); // "A boolean of whether we care or not." // Access multiple doclet tags with the same name DocletTag[] params = mth.getTagsByName("param"); params[0].getValue(); // "Someone's email address." params[1].getValue(); // "Date of birth." // Access specific parameters of a doclet tag by index DocletTag permission = mth.getTagByName("permission"); permission.getParameter[0]; // "administrator" permission.getParameter[1]; // "full-access" // Access specific parameters of a doclet tag by name DocletTag webservice = mth.getTagByName("webservice"); webservice.getNamedParameter("type"); // "rpc" webservice.getNamedParameter("name"); // "myservice" ``` # Building QDox Snapshot deployments: snapshots directory. To build QDox there are two prerequisites: Key Dependencies: 1. [Maven 3](http://maven.apache.org) 2. [BYacc/J](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 package - 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) qdox-qdox-2.0-M8/bootstrap/000077500000000000000000000000001325201777200156045ustar00rootroot00000000000000qdox-qdox-2.0-M8/pom.xml000066400000000000000000000357661325201777200151250ustar00rootroot00000000000000 4.0.0 org.sonatype.oss oss-parent 9 QDox com.thoughtworks.qdox qdox 2.0-M8 https://github.com/paul-hammant/qdox 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 github https://github.com/paul-hammant/qdox/issues scm:git:https://github.com/paul-hammant/qdox.git scm:git:ssh://git@github.com/paul-hammant/qdox.git https://github.com/paul-hammant/qdox qdox-2.0-M8 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 yyyy-MM-dd UTF-8 ${maven.build.timestamp} 500 org.apache.maven.plugins maven-clean-plugin 2.4.1 org.apache.maven.plugins maven-compiler-plugin 2.3.2 org.apache.maven.plugins maven-surefire-plugin 2.19.1 false org.apache.maven.plugins maven-jar-plugin 2.3.2 com.thoughtworks.qdox org.apache.maven.plugins maven-install-plugin 2.3.1 org.apache.maven.plugins maven-deploy-plugin 2.7 org.apache.maven.plugins maven-site-plugin 3.0 ${basedir}/src/site/templates/site.vm org.apache.maven.plugins maven-release-plugin 2.5.1 org.apache.maven.plugins maven-enforcer-plugin 1.3.1 enforce-maven enforce 3.0 de.jflex maven-jflex-plugin 1.4.3 generate ${project.build.directory}/generated-sources/parser ${basedir}/src/grammar/lexer.flex ${basedir}/src/grammar/commentlexer.flex org.codehaus.mojo exec-maven-plugin 1.2.1 javacommentparser generate-sources exec ${qdox.byaccj.executable} -v -Jnorun -Jnoconstruct -Jclass=DefaultJavaCommentParser -Jpackage=com.thoughtworks.qdox.parser.impl ${basedir}/src/grammar/commentparser.y ${project.build.directory}/generated-sources/parser/com/thoughtworks/qdox/parser/impl javasourceparser generate-sources exec ${qdox.byaccj.executable} -v -Jnorun -Jnoconstruct -Jclass=Parser -Jimplements=CommentHandler -Jsemantic=Value -Jpackage=com.thoughtworks.qdox.parser.impl -Jstack=${qdox.javaparser.stack} ${basedir}/src/grammar/parser.y ${project.build.directory}/generated-sources/parser/com/thoughtworks/qdox/parser/impl org.codehaus.mojo animal-sniffer-maven-plugin 1.7 check-java15 process-classes check org.codehaus.mojo.signature java15 1.0 org.apache.maven.plugins maven-failsafe-plugin 2.19.1 integration-test verify org.apache.maven.plugins maven-invoker-plugin 2.0.0 ${project.build.directory}/it verify ${project.build.directory}/local-repo clean test src/it/settings.xml true integration-test install run org.apache.maven.plugins maven-assembly-plugin 2.2.2 project gnu make-assembly package single junit junit 4.8.2 test org.mockito mockito-core 1.8.5 test 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 org.apache.maven.plugins maven-project-info-reports-plugin 2.8 dependencies project-team mailing-list issue-tracking license scm summary org.apache.maven.plugins maven-jxr-plugin 2.3 jxr org.codehaus.mojo cobertura-maven-plugin 2.4 org.apache.maven.plugins maven-javadoc-plugin 2.8 com.thoughtworks.qdox.* javadoc qdox-qdox-2.0-M8/src/000077500000000000000000000000001325201777200143565ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/grammar/000077500000000000000000000000001325201777200160045ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/grammar/commentlexer.flex000066400000000000000000000137671325201777200214040ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import com.thoughtworks.qdox.parser.*; %% // class and lexer definitions %class DefaultJavaCommentLexer %public %implements Lexer %byaccj %unicode %line %column %{ private int lineOffset = 1; private int columnOffset =1; private int stateDepth = 0; private int[] stateStack = new int[10]; private StringBuffer codeBody = new StringBuffer(8192); private boolean appendingToCodeBody; public int lex() throws java.io.IOException { return yylex(); } public String text() { return yytext(); } public int getLine() { return yyline + lineOffset; } public void setLineOffset(int lineOffset) { this.lineOffset = lineOffset; } public int getColumn() { return yycolumn + columnOffset; } public void setColumnOffset(int columnOffset) { this.columnOffset = columnOffset; } public String getCodeBody(){ String s = codeBody.toString(); codeBody = new StringBuffer(8192); return s; } 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]; } } %} Eol = \r|\n|\r\n JavadocEnd = "*"+ "/" %state JAVADOC JAVADOCCONTENT JAVADOCLINE JAVADOCTAG MULTILINECOMMENT SINGLELINECOMMENT %% { "//" { codeBody.append( "//" ); pushState( SINGLELINECOMMENT ); } "/**/" { codeBody.append( "/**/" ); } "/**" [*]+ "/" { yypushback(2); pushState(JAVADOC); return DefaultJavaCommentParser.JAVADOCSTART; } "/*" [*]+ { pushState( JAVADOC ); pushState( JAVADOCCONTENT ); return DefaultJavaCommentParser.JAVADOCSTART; } "/*" { codeBody.append( "/*" ); pushState( MULTILINECOMMENT ); } } { "*"+ [ \t]* / "@" { pushState(JAVADOCTAG); } "*"+ [ \t]? { pushState(JAVADOCLINE); } {JavadocEnd} { popState(); return DefaultJavaCommentParser.JAVADOCEND; } "@" { yypushback(1); pushState(JAVADOCTAG); } [^ \t\r] { yypushback(1); pushState(JAVADOCLINE); } } { [ \t]* "@" { yypushback(1); popState(); pushState(JAVADOCTAG); } [^ \t] { yypushback(1); popState(); pushState(JAVADOCLINE); } {Eol} { popState(); return DefaultJavaCommentParser.JAVADOCLINE; } } { ~{Eol} { popState(); return DefaultJavaCommentParser.JAVADOCLINE; } .* [^ \t*] / [ \t]* {JavadocEnd} { popState(); return DefaultJavaCommentParser.JAVADOCLINE; } {JavadocEnd} { popState(); popState(); return DefaultJavaCommentParser.JAVADOCEND; } } { "@" [^ \t\n\r]+ / {JavadocEnd} { popState(); return DefaultJavaCommentParser.JAVADOCTAG; } "@" [^ \t\n\r]+ { return DefaultJavaCommentParser.JAVADOCTAG; } [ \t]+ { popState(); pushState(JAVADOCLINE); } {Eol} { popState(); return DefaultJavaCommentParser.JAVADOCLINE; } } { "*/" { codeBody.append("*/"); popState(); } } { {Eol} { codeBody.append(yytext()); popState(); } } .|\r|\n|\r\n { codeBody.append(yytext()); }qdox-qdox-2.0-M8/src/grammar/commentparser.y000066400000000000000000000067051325201777200210650ustar00rootroot00000000000000%{ /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.IOException; import com.thoughtworks.qdox.builder.Builder; import com.thoughtworks.qdox.parser.Lexer; import com.thoughtworks.qdox.parser.ParseException; import com.thoughtworks.qdox.parser.structs.TagDef; %} %token JAVADOCSTART JAVADOCEND // strongly typed tokens/types %token JAVADOCTAG JAVADOCLINE %% javadoc: JAVADOCSTART javadocdescription_opt javadoctags_opt JAVADOCEND; javadocdescription_opt: | javadocdescription; javadocdescription: javadoctokens { builder.addJavaDoc(buffer()); }; javadoctokens_opt: | javadoctokens; javadoctokens: javadoctoken | javadoctokens javadoctoken; javadoctoken: JAVADOCLINE { appendToBuffer($1); }; javadoctags_opt: | javadoctags; javadoctags: javadoctag | javadoctags javadoctag; javadoctag: JAVADOCTAG { line = lexer.getLine(); } javadoctokens_opt { builder.addJavaDocTag(new TagDef($1.substring(1), buffer(), line)); }; %% private Lexer lexer; private Builder builder; private int line; private int column; private boolean debugLexer; private StringBuffer textBuffer = new StringBuffer(); public DefaultJavaCommentParser(Lexer lexer, Builder builder) { this.lexer = lexer; this.builder = builder; } public void setDebugParser(boolean debug) { yydebug = debug; } public void setDebugLexer(boolean debug) { debugLexer = debug; } 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 boolean parse() { return yyparse() == 0; } private int yylex() { try { final int result = lexer.lex(); yylval = new DefaultJavaCommentParserVal(); 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()); } qdox-qdox-2.0-M8/src/grammar/lexer.flex000066400000000000000000000543251325201777200200140ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import com.thoughtworks.qdox.parser.*; import java.util.*; %% // class and lexer definitions %class JFlexLexer %public %implements JavaLexer %byaccj %unicode %line %column %init{ java.io.InputStream qdoxProperties = this.getClass().getClassLoader().getResourceAsStream( "qdox.properties" ); if( qdoxProperties != null ) { Properties props = new Properties(); try { props.load( qdoxProperties ); stateStack = new int[ parseValue( props.getProperty( "lexer.statestack.size" ), stateStack.length ) ]; } catch ( java.io.IOException e ) { // failed to load qdoxProperties } finally { try { qdoxProperties.close(); } catch( java.io.IOException e ) { // noop, we did our best } } } %init} %{ private java.io.Writer writer; private List commentHandlers = new ArrayList(); 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 int annotatedElementLine = 0; private StringBuffer codeBody = new StringBuffer(8192); private boolean newMode; private boolean bracketMode; private boolean anonymousMode; private boolean enumConstantMode; private boolean appendingToCodeBody; private void write() { write( text() ); } private void write( String text ) { try { if( writer != null ) { writer.write( text ); } } catch( java.io.IOException ioe ) {} } public String text() { return yytext(); } public int lex() throws java.io.IOException { if(annotatedElementLine < 0) { annotatedElementLine = 0; } return yylex(); } public int getLine() { return ( annotatedElementLine == 0 ? yyline + 1 : Math.abs(annotatedElementLine) ); } public int getColumn() { return yycolumn + 1; } private void pushState(int newState) { stateStack[stateDepth++] = zzLexicalState; yybegin(newState); } private void popState() { yybegin(stateStack[--stateDepth]); } public String getCodeBody(){ String s = codeBody.toString(); codeBody = new StringBuffer(8192); return s; } public void addCommentHandler(CommentHandler handler) { this.commentHandlers.add(handler); } private int parseValue( String value, int defaultValue ) { int result; try { result = Integer.parseInt( value ); } catch( NumberFormatException e ) { result = defaultValue; } return result; } private void markAnnotatedElementLine() { if( annotatedElementLine <= 0 ) { annotatedElementLine = getLine(); } } private void resetAnnotatedElementLine() { annotatedElementLine = 0 - annotatedElementLine; } public JFlexLexer( java.io.Reader reader, java.io.Writer writer ) { this( reader ); this.writer = writer; } public JFlexLexer( java.io.InputStream stream, java.io.Writer writer ) { this( stream ); this.writer = writer; } %} Eol = \r|\n|\r\n WhiteSpace = {Eol} | [ \t\f] CommentChar = ( [^ \t\r\n*] | "*"+ [^ \t\r\n/*] ) DecimalNumeral = ( [0-9] | [1-9] [_0-9]* [0-9] ) Digits = ( [0-9] | [0-9] [_0-9]* [0-9] ) HexDigits = ( [0-9a-fA-F] | [0-9a-fA-F] [_0-9a-fA-F]* [0-9a-fA-F] ) HexNumeral = ( "0" [xX] {HexDigits} ) OctalNumeral = ( "0" [_0-7]* [0-7] ) BinaryNumeral = ( "0" [bB] ( [01] | [01] [_01]* [01] ) ) IntegerLiteral = ( {DecimalNumeral} | {BinaryNumeral} | {HexNumeral} | {OctalNumeral} ) ([lL])? Exponent = [eE] [+-]? {DecimalNumeral} FloatingPointLiteral = ( {DecimalFloatingPointLiteral} | {HexadecimalFloatingPointLiteral} ) DecimalFloatingPointLiteral = ( {Digits} ("." {Digits})? ({Exponent})? ([dDfF])? ) | ( "." {Digits} ({Exponent})? ([dDfF])?) | ( {Digits} {Exponent} ([dDfF])?) | ( {Digits} ({Exponent} )? ([dDfF]) ) BinaryExponent = [pP] [+-]? ({DecimalNumeral})+ HexSignificand = ( {HexNumeral} "."? ) | ( "0" [xX] ( {HexDigits} )? "." ( {HexDigits} ) ) HexadecimalFloatingPointLiteral = {HexSignificand} {BinaryExponent} ([dDfF])? UnicodeChar = \\u[a-fA-F0-9]{4} Id = ([:jletter:]|{UnicodeChar}) ([:jletterdigit:]|{UnicodeChar})* JavadocEnd = "*"+ "/" %state JAVADOC JAVADOCTAG JAVADOCLINE CODEBLOCK PARENBLOCK ASSIGNMENT STRING CHAR SINGLELINECOMMENT MULTILINECOMMENT ANNOTATION ANNOSTRING ANNOCHAR ARGUMENTS NAME %state ANNOTATIONTYPE ENUM MODULE TYPE ANNOTATIONNOARG ATANNOTATION %state NAME_OR_MODIFIER %% { "open" { if ( classDepth == 0 ) { return Parser.OPEN; } else { return Parser.IDENTIFIER; } } "module" { if ( classDepth == 0 ) { pushState(MODULE); pushState(NAME); return Parser.MODULE; } else { return Parser.IDENTIFIER; } } } { {Id} / {WhiteSpace}* "." { popState(); pushState(NAME); return Parser.IDENTIFIER; } "static" { return Parser.STATIC; } "transitive" { return Parser.TRANSITIVE; } } { {WhiteSpace} { popState(); } } { "." { return Parser.DOT; } "..." { return Parser.DOTDOTDOT; } "," { return Parser.COMMA; } "*" { popState(); return Parser.STAR; } "package" { markAnnotatedElementLine(); pushState(NAME); return Parser.PACKAGE; } "import" { pushState(NAME); return Parser.IMPORT; } "public" { markAnnotatedElementLine(); return Parser.PUBLIC; } "protected" { markAnnotatedElementLine(); return Parser.PROTECTED; } "private" { markAnnotatedElementLine(); return Parser.PRIVATE; } "static" { markAnnotatedElementLine(); return Parser.STATIC; } "final" { markAnnotatedElementLine(); return Parser.FINAL; } "abstract" { markAnnotatedElementLine(); return Parser.ABSTRACT; } "native" { markAnnotatedElementLine(); return Parser.NATIVE; } "strictfp" { markAnnotatedElementLine(); return Parser.STRICTFP; } "synchronized" { markAnnotatedElementLine(); return Parser.SYNCHRONIZED; } "transient" { markAnnotatedElementLine(); return Parser.TRANSIENT; } "volatile" { markAnnotatedElementLine(); return Parser.VOLATILE; } "throws" { return Parser.THROWS; } "extends" { return Parser.EXTENDS; } "implements" { return Parser.IMPLEMENTS; } "super" { return Parser.SUPER; } "new" { return Parser.NEW; } "[" { 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" { markAnnotatedElementLine(); classDepth++; braceMode = ANNOTATIONTYPE; pushState(NAME); return Parser.ANNOINTERFACE; } "class" { markAnnotatedElementLine(); classDepth++; braceMode = TYPE; pushState(NAME); return Parser.CLASS; } "interface" { markAnnotatedElementLine(); classDepth++; braceMode = TYPE; pushState(NAME); return Parser.INTERFACE; } "enum" { markAnnotatedElementLine(); classDepth++; braceMode = ENUM; pushState(NAME); return Parser.ENUM; } "@" { markAnnotatedElementLine(); pushState(ATANNOTATION); return Parser.AT; } "{" { resetAnnotatedElementLine(); if(braceMode >= 0) { if(braceMode == ENUM) { enumConstantMode = true; } else if (braceMode == CODEBLOCK) { getCodeBody(); /* reset codebody */ appendingToCodeBody = true; } pushState(braceMode); braceMode = -1; yypushback(1); /* (re)enter brace in right mode */ } else { nestingDepth++; if (enumConstantMode && yystate() == ENUM) { braceMode = TYPE; } else { braceMode = CODEBLOCK; } return Parser.BRACEOPEN; } } "}" { nestingDepth--; classDepth--; popState(); if ( yystate() == ENUM && enumConstantMode) { braceMode = TYPE; } else { braceMode = CODEBLOCK; } return Parser.BRACECLOSE; } "/**" ~"*/" { for( CommentHandler handler: commentHandlers ) { handler.onComment( text(), getLine(), getColumn() ); } } "=" {WhiteSpace}* { assignmentDepth = nestingDepth; getCodeBody(); /* reset codebody */ appendingToCodeBody = true; pushState(ASSIGNMENT); } } { "." { return Parser.DOT; } {Id} / {WhiteSpace}* "." { return Parser.IDENTIFIER; } {Id} / {WhiteSpace}* "(" { parenMode = ANNOTATION; getCodeBody(); /* reset codebody */; popState(); resetAnnotatedElementLine(); return Parser.IDENTIFIER; } {Id} { resetAnnotatedElementLine(); popState(); return Parser.IDENTIFIER; } } { ";" { resetAnnotatedElementLine(); return Parser.SEMI; } "(" { nestingDepth++; if( parenMode >= 0 ) { annotationDepth = nestingDepth; pushState(parenMode); parenMode = -1; } return Parser.PARENOPEN; } } { "{" { return Parser.BRACEOPEN; } "}" { popState(); return Parser.BRACECLOSE; } "," { pushState(NAME); return Parser.COMMA; } ";" { return Parser.SEMI; } "exports" { pushState(NAME); return Parser.EXPORTS; } "opens" { pushState(NAME); return Parser.OPENS; } "provides" { pushState(NAME); return Parser.PROVIDES; } "requires" { pushState(NAME_OR_MODIFIER); return Parser.REQUIRES; } "to" { pushState(NAME); return Parser.TO; } "uses" { pushState(NAME); return Parser.USES; } "with" { pushState(NAME); return Parser.WITH; } } { ";" { enumConstantMode = false; braceMode = CODEBLOCK; return Parser.SEMI; } "(" { nestingDepth++; if(parenMode >= 0) { annotationDepth = nestingDepth; pushState(parenMode); parenMode = -1; return Parser.PARENOPEN; } else if(enumConstantMode) { annotationDepth = nestingDepth; pushState(ARGUMENTS); return Parser.PARENOPEN; } else { return Parser.PARENOPEN; } } } { "default" { return Parser.DEFAULT; } } { "default" { assignmentDepth = nestingDepth; appendingToCodeBody = true; pushState(ASSIGNMENT); } } { {Id} / {WhiteSpace}* "." { return Parser.IDENTIFIER; } {Id} / {WhiteSpace}* [;{] { resetAnnotatedElementLine(); popState(); return Parser.IDENTIFIER; } {Id} { popState(); return Parser.IDENTIFIER; } } { {Id} { return Parser.IDENTIFIER; } } { "{" { if(codeblockDepth++ > 0 ) { codeBody.append('{'); } } "}" { if (--codeblockDepth == 0) { popState(); appendingToCodeBody = false; braceMode = CODEBLOCK; return Parser.CODEBLOCK; } else { codeBody.append('}'); } } } { "{" { nestingDepth++; return Parser.BRACEOPEN; } "}" { nestingDepth--; return Parser.BRACECLOSE; } } { "{" { pushState(CODEBLOCK); braceMode = -1; yypushback(1); /* (re)enter brace in right mode */ } "}" { return Parser.BRACECLOSE; } } { "(" { ++ nestingDepth; return Parser.PARENOPEN; } ")" { if( nestingDepth-- == annotationDepth) { popState(); } return Parser.PARENCLOSE; } "[" { return Parser.SQUAREOPEN; } "]" { return Parser.SQUARECLOSE; } "," { return Parser.COMMA; } "=" { return Parser.EQUALS; } "*=" { return Parser.STAREQUALS; } "/=" { return Parser.SLASHEQUALS; } "%=" { return Parser.PERCENTEQUALS; } "+=" { return Parser.PLUSEQUALS; } "-=" { return Parser.MINUSEQUALS; } "<<=" { return Parser.LESSTHAN2EQUALS; } ">>=" { return Parser.GREATERTHAN2EQUALS; } ">>>=" { return Parser.GREATERTHAN3EQUALS; } "&=" { return Parser.AMPERSANDEQUALS; } "^=" { return Parser.CIRCUMFLEXEQUALS; } "|=" { return Parser.VERTLINEEQUALS; } "++" { return Parser.PLUSPLUS; } "--" { return Parser.MINUSMINUS; } "\"" { appendingToCodeBody=true; codeBody.append("\""); pushState(ANNOSTRING); } "\'" { appendingToCodeBody=true; codeBody.append("\'"); pushState(ANNOCHAR); } "." { return Parser.DOT; } "?" { return Parser.QUERY; } "::" { return Parser.COLONCOLON; } ":" { 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; } {FloatingPointLiteral} { return Parser.FLOAT_LITERAL; } "true" | "false" { return Parser.BOOLEAN_LITERAL; } "class" { return Parser.CLASS; } "new" { return Parser.NEW; } {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(); } } } { ";" { resetAnnotatedElementLine(); 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('}'); 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-qdox-2.0-M8/src/grammar/parser.y000066400000000000000000001724251325201777200175050ustar00rootroot00000000000000%{ /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import com.thoughtworks.qdox.builder.Builder; import com.thoughtworks.qdox.parser.*; import com.thoughtworks.qdox.parser.expression.*; import com.thoughtworks.qdox.parser.structs.*; import java.io.IOException; import java.util.LinkedList; import java.util.List; import java.util.Stack; %} %token SEMI DOT DOTDOTDOT COMMA STAR PERCENT EQUALS ANNOSTRING ANNOCHAR SLASH PLUS MINUS %token STAREQUALS SLASHEQUALS PERCENTEQUALS PLUSEQUALS MINUSEQUALS LESSTHAN2EQUALS GREATERTHAN2EQUALS GREATERTHAN3EQUALS AMPERSANDEQUALS CIRCUMFLEXEQUALS VERTLINEEQUALS %token PACKAGE IMPORT PUBLIC PROTECTED PRIVATE STATIC FINAL ABSTRACT NATIVE STRICTFP SYNCHRONIZED TRANSIENT VOLATILE DEFAULT %token OPEN MODULE REQUIRES TRANSITIVE EXPORTS OPENS TO USES PROVIDES WITH %token CLASS INTERFACE ENUM ANNOINTERFACE THROWS EXTENDS IMPLEMENTS SUPER DEFAULT NEW %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 COLONCOLON AT %token CODEBLOCK PARENBLOCK %token BYTE SHORT INT LONG CHAR FLOAT DOUBLE BOOLEAN // strongly typed tokens/types %token IDENTIFIER %token BOOLEAN_LITERAL %token INTEGER_LITERAL %token FLOAT_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 %token PLUSPLUS MINUSMINUS %token SUPER %token EQUALS STAREQUALS SLASHEQUALS PERCENTEQUALS PLUSEQUALS MINUSEQUALS LESSTHAN2EQUALS GREATERTHAN2EQUALS GREATERTHAN3EQUALS AMPERSANDEQUALS CIRCUMFLEXEQUALS VERTLINEEQUALS %type PrimitiveType ReferenceType ArrayType ClassOrInterfaceType %type Expression Literal Annotation ElementValue ElementValueArrayInitializer %type ConditionalExpression ConditionalOrExpression ConditionalAndExpression InclusiveOrExpression ExclusiveOrExpression AndExpression %type EqualityExpression RelationalExpression ShiftExpression AdditiveExpression MultiplicativeExpression %type UnaryExpression UnaryExpressionNotPlusMinus PreIncrementExpression PreDecrementExpression Primary PrimaryNoNewArray ArrayCreationExpression MethodInvocation MethodReference ClassInstanceCreationExpression %type PostfixExpression PostIncrementExpression PostDecrementExpression CastExpression Assignment LeftHandSide AssignmentExpression %type Dims Dims_opt %type QualifiedIdentifier TypeDeclSpecifier MethodBody AssignmentOperator ModuleName %type Type ReferenceType Wildcard WildcardBounds VariableDeclaratorId ClassOrInterfaceType TypeArgument %% // Source: Java Language Specification - Third Edition // The Java(TM) Language Specification - Java SE 8 Edition ( Chapter 19. Syntax ) // ------------------------------ // Productions from �7 (Packages) // ------------------------------ // CompilationUnit: // [PackageDeclaration] {ImportDeclaration} {TypeDeclaration} // {ImportDeclaration} ModuleDeclaration CompilationUnit: CompilationDeclaration | CompilationUnit CompilationDeclaration ; CompilationDeclaration: Annotation | ImportDeclaration | ModuleDeclaration | PackageDeclaration | TypeDeclaration ; // ModuleDeclaration: // {Annotation} [open] module ModuleName { {ModuleStatement} } ModuleDeclaration: OPEN MODULE ModuleName { ModuleDef module = new ModuleDef($3); module.setOpen(true); builder.setModule(module); } BRACEOPEN ModuleStatements_opt BRACECLOSE | MODULE ModuleName { builder.setModule(new ModuleDef($2)); } BRACEOPEN ModuleStatements_opt BRACECLOSE ; // ModuleName: // Identifier // ModuleName . Identifier ModuleName: QualifiedIdentifier ; ModuleNameList: ModuleName { moduleTargets.add($1); } | ModuleNameList COMMA ModuleName { moduleTargets.add($3); } ; // ModuleStatement: // requires {RequiresModifier} ModuleName ; // exports PackageName [to ModuleName {, ModuleName}] ; // opens PackageName [to ModuleName {, ModuleName}] ; // uses TypeName ; // provides TypeName with TypeName {, TypeName} ; ModuleStatement: REQUIRES RequiresModifiers_opt ModuleName SEMI { ModuleDef.RequiresDef req = new ModuleDef.RequiresDef($3, modifiers); modifiers = new java.util.LinkedHashSet(); req.setLineNumber(line); builder.addRequires(req); } | EXPORTS QualifiedIdentifier /* =PackageName */ { exp = new ModuleDef.ExportsDef($2); exp.setLineNumber(line); } ToDeclaration_opt SEMI { exp.getTargets().addAll(moduleTargets); moduleTargets = new LinkedList(); builder.addExports(exp); } | OPENS QualifiedIdentifier /* =PackageName */ { opn = new ModuleDef.OpensDef($2); opn.setLineNumber(line); } ToDeclaration_opt SEMI { opn.getTargets().addAll(moduleTargets); moduleTargets = new LinkedList(); builder.addOpens(opn); } | USES Type /* =TypeName */ SEMI { ModuleDef.UsesDef uss = new ModuleDef.UsesDef($2); uss.setLineNumber(line); builder.addUses(uss); } | PROVIDES Type /* =TypeName */ { prv = new ModuleDef.ProvidesDef($2); prv.setLineNumber(line); } WITH TypeList SEMI { prv.getImplementations().addAll(typeList); builder.addProvides(prv); } ; ModuleStatements_opt: | ModuleStatements_opt ModuleStatement ; RequiresModifier: TRANSITIVE { modifiers.add("transitive"); } | STATIC { modifiers.add("static"); } ; RequiresModifiers_opt: | RequiresModifiers_opt RequiresModifier ; ToDeclaration_opt: | TO ModuleNameList ; // PackageDeclaration: // {PackageModifier} package Identifier {. Identifier} ; // PackageModifier: // Annotation PackageDeclaration: PACKAGE { line = lexer.getLine(); } QualifiedIdentifier /* =PackageName */SEMI { builder.addPackage(new PackageDef($3, line)); } ; // ImportDeclaration: // SingleTypeImportDeclaration // TypeImportOnDemandDeclaration // SingleStaticImportDeclaration // StaticImportOnDemandDeclaration ImportDeclaration: SingleTypeImportDeclaration | TypeImportOnDemandDeclaration | SingleStaticImportDeclaration | StaticImportOnDemandDeclaration ; // SingleTypeImportDeclaration: // import TypeName ; SingleTypeImportDeclaration: IMPORT QualifiedIdentifier SEMI { builder.addImport( $2 ); } ; // TypeImportOnDemandDeclaration: // import PackageOrTypeName . * ; TypeImportOnDemandDeclaration: IMPORT QualifiedIdentifier DOT STAR SEMI { builder.addImport( $2 + ".*" ); } ; // SingleStaticImportDeclaration: // import static TypeName . Identifier ; SingleStaticImportDeclaration: IMPORT STATIC QualifiedIdentifier SEMI { builder.addImport( "static " + $3); } ; // StaticImportOnDemandDeclaration: // import static TypeName . * ; StaticImportOnDemandDeclaration: IMPORT STATIC QualifiedIdentifier DOT STAR SEMI { builder.addImport( "static " + $3 + ".*" ); } ; // TypeDeclaration: // ClassDeclaration // InterfaceDeclaration // ; TypeDeclaration: ClassDeclaration | InterfaceDeclaration | SEMI ; // ----------------------------- // Productions from �8 (Classes) // ----------------------------- // ClassDeclaration: // NormalClassDeclaration // EnumDeclaration ClassDeclaration: NormalClassDeclaration | EnumDeclaration ; // NormalClassDeclaration: // {ClassModifier} class Identifier [TypeParameters] [Superclass] [Superinterfaces] ClassBody NormalClassDeclaration: Modifiers_opt CLASS IDENTIFIER { cls.setType(ClassDef.CLASS); cls.setLineNumber(lexer.getLine()); cls.getModifiers().addAll(modifiers); modifiers.clear(); cls.setName( $3 ); } TypeParameters_opt Superclass_opt Superinterfaces_opt { cls.setTypeParameters(typeParams); builder.beginClass(cls); cls = new ClassDef(); } ClassBody { builder.endClass(); } ; // TypeParameters: // < TypeParameterList > TypeParameters: LESSTHAN { typeParams = new LinkedList(); } TypeParameterList GREATERTHAN ; TypeParameters_opt: | TypeParameters ; // TypeParameterList: // TypeParameter {, TypeParameter} TypeParameterList: TypeParameter | TypeParameterList COMMA TypeParameter ; // Superclass: // extends ClassType Superclass_opt: | EXTENDS ReferenceType { cls.getExtends().add($2); } ; // Superinterfaces: // implements InterfaceTypeList Superinterfaces_opt: | IMPLEMENTS TypeList { cls.getImplements().addAll( typeList ); typeList.clear(); } ; // InterfaceTypeList: // InterfaceType {, InterfaceType} //// -> InterfaceTypeList is for QDox the same as TypeList // ClassBody: // { { ClassBodyDeclaration } } ClassBody: BRACEOPEN ClassBodyDeclarations_opt BRACECLOSE ; ClassBody_opt: | ClassBody ; // ClassBodyDeclaration: // ClassMemberDeclaration // InstanceInitializer // StaticInitializer // ConstructorDeclaration // ## for now StaticInitializer includes InstanceInitializer due to parsing errors ClassBodyDeclaration: StaticInitializer | ClassMemberDeclaration | ConstructorDeclaration ; ClassBodyDeclarations_opt: | ClassBodyDeclarations_opt { line = lexer.getLine(); } ClassBodyDeclaration ; // ClassMemberDeclaration: // FieldDeclaration // MethodDeclaration // ClassDeclaration // InterfaceDeclaration // ; ClassMemberDeclaration: FieldDeclaration | MethodDeclaration | ClassDeclaration | InterfaceDeclaration | SEMI ; // FieldDeclaration: // {FieldModifier} UnannType VariableDeclaratorList ; FieldDeclaration: Modifiers_opt Type VariableDeclaratorId { fieldType = $2; // we're doing some lexer magic: lexer.getCodeBody() contains [= VariableInitializer] makeField($3, lexer.getCodeBody(), false); builder.beginField(fd); builder.endField(); } extrafields SEMI { modifiers.clear(); } ; extrafields: | extrafields COMMA { line = lexer.getLine(); } VariableDeclaratorId { // we're doing some lexer magic: lexer.getCodeBody() contains [= VariableInitializer] makeField($4, lexer.getCodeBody(), false); builder.beginField(fd); builder.endField(); } ; // VariableDeclaratorId: // Identifier [Dims] VariableDeclaratorId: IDENTIFIER Dims_opt { $$ = new TypeDef($1,$2); } ; // MethodDeclaration: // {MethodModifier} MethodHeader MethodBody MethodDeclaration: Modifiers_opt MethodHeader MethodBody { mth.setBody($3); builder.endMethod(mth); mth = new MethodDef(); } ; // VariableInitializer: // Expression // ArrayInitializer // VariableInitializer: ArrayInitializer // | Expression // ; // MethodHeader: // Result MethodDeclarator [Throws] // TypeParameters {Annotation} Result MethodDeclarator [Throws] // MethodDeclarator: // Identifier ( [FormalParameterList] ) [Dims] //## MethodDeclarator must be part of MethodHeader so Parser recognizes this as a Method MethodHeader: TypeParameters Type /* =Result */ IDENTIFIER { builder.beginMethod(); mth.setLineNumber(lexer.getLine()); mth.getModifiers().addAll(modifiers); modifiers.clear(); mth.setTypeParams(typeParams); mth.setReturnType($2); mth.setName($3); } PARENOPEN FormalParameterList_opt PARENCLOSE Dims_opt Throws_opt { mth.setDimensions($8); } | TypeParameters Annotation Type /* =Result */ IDENTIFIER { builder.beginMethod(); mth.setLineNumber(lexer.getLine()); mth.getModifiers().addAll(modifiers); modifiers.clear(); mth.setTypeParams(typeParams); mth.setReturnType($3); mth.setName($4); } PARENOPEN FormalParameterList_opt PARENCLOSE Dims_opt Throws_opt { mth.setDimensions($9); } | Type /* =Result */ IDENTIFIER { builder.beginMethod(); mth.setLineNumber(lexer.getLine()); mth.getModifiers().addAll(modifiers); modifiers.clear(); mth.setReturnType($1); mth.setName($2); } PARENOPEN FormalParameterList_opt PARENCLOSE Dims_opt Throws_opt { mth.setDimensions($7); }; // FormalParameterList: // FormalParameters , LastFormalParameter // LastFormalParameter FormalParameterList: FormalParameters COMMA LastFormalParameter | LastFormalParameter ; FormalParameterList_opt: | FormalParameterList ; // FormalParameters: // FormalParameter {, FormalParameter} // ReceiverParameter {, FormalParameter} FormalParameters: FormalParameter | FormalParameters COMMA FormalParameter // | ReceiverParameter {, FormalParameter} // | ReceiverParameter COMMA FormalParameter ; // FormalParameter: // {VariableModifier} UnannType VariableDeclaratorId FormalParameter: Modifiers_opt Type VariableDeclaratorId { param.getModifiers().addAll(modifiers); modifiers.clear(); param.setType($2); param.setName($3.getName()); param.setDimensions($3.getDimensions()); param.setVarArgs(false); builder.addParameter(param); param = new FieldDef(); } ; // LastFormalParameter: // {VariableModifier} UnannType {Annotation} ... VariableDeclaratorId // FormalParameter LastFormalParameter: Modifiers_opt Type DOTDOTDOT VariableDeclaratorId { param.getModifiers().addAll(modifiers); modifiers.clear(); param.setType($2); param.setName($4.getName()); param.setDimensions($4.getDimensions()); param.setVarArgs(true); builder.addParameter(param); param = new FieldDef(); } | FormalParameter ; // ReceiverParameter: // {Annotation} UnannType [Identifier .] this // ## todo // Throws: // throws ExceptionTypeList Throws_opt: | THROWS ExceptionTypeList ; // ExceptionTypeList: // ExceptionType {, ExceptionType} ExceptionTypeList: ClassOrInterfaceType /* =ExceptionType */ { mth.getExceptions().add($1); } | ExceptionTypeList COMMA ClassOrInterfaceType /* =ExceptionType */ { mth.getExceptions().add($3); } ; // MethodBody: // Block // ; MethodBody: CODEBLOCK { $$ = lexer.getCodeBody(); } | SEMI { $$ = ""; } ; // InstanceInitializer: // CODEBLOCK // { // InitDef def = new InitDef(); // def.setBlockContent(lexer.getCodeBody()); // builder.addInitializer(def); // }; // StaticInitializer: // static Block StaticInitializer: Modifiers_opt CODEBLOCK { InitDef def = new InitDef(); def.setStatic(modifiers.contains("static"));modifiers.clear(); def.setBlockContent(lexer.getCodeBody()); builder.addInitializer(def); } ; // ConstructorDeclaration: // {ConstructorModifier} ConstructorDeclarator [Throws] ConstructorBody ConstructorDeclaration: Modifiers_opt IDENTIFIER { builder.beginConstructor(); mth.setLineNumber(lexer.getLine()); mth.getModifiers().addAll(modifiers); modifiers.clear(); mth.setConstructor(true); mth.setName($2); } PARENOPEN FormalParameterList_opt PARENCLOSE Throws_opt MethodBody /* =ConstructorBody */ { mth.setBody($8); builder.endConstructor(mth); mth = new MethodDef(); } | Modifiers_opt TypeParameters IDENTIFIER { builder.beginConstructor(); mth.setLineNumber(lexer.getLine()); mth.setTypeParams(typeParams); mth.getModifiers().addAll(modifiers); modifiers.clear(); mth.setConstructor(true); mth.setName($3); } PARENOPEN FormalParameterList_opt PARENCLOSE Throws_opt CODEBLOCK { mth.setBody(lexer.getCodeBody()); builder.endConstructor(mth); mth = new MethodDef(); } ; // ConstructorDeclarator: // [TypeParameters] SimpleTypeName ( [FormalParameterList] ) // ** ConstructorBody, ExplicitConstructorInvocation not used by QDox, out of scope // ConstructorBody: // { [ExplicitConstructorInvocation] [BlockStatements] } // ExplicitConstructorInvocation: // [TypeArguments] this ( [ArgumentList] ) ; // [TypeArguments] super ( [ArgumentList] ) ; // ExpressionName . [TypeArguments] super ( [ArgumentList] ) ; // Primary . [TypeArguments] super ( [ArgumentList] ) ; // EnumDeclaration: // {ClassModifier} enum Identifier [Superinterfaces] EnumBody EnumDeclaration: Modifiers_opt ENUM IDENTIFIER { cls.setLineNumber(lexer.getLine()); cls.getModifiers().addAll(modifiers); cls.setName( $3 ); cls.setType(ClassDef.ENUM); builder.beginClass(cls); cls = new ClassDef(); fieldType = new TypeDef($3, 0); } Superinterfaces_opt EnumBody ; // EnumBody: // { [EnumConstantList] [,] [EnumBodyDeclarations] } /* The optional COMMA causes trouble for the parser For that reason the adjusted options of EnumConstants_opt, which will accept all cases */ EnumBody: BRACEOPEN EnumConstants_opt EnumBodyDeclarations_opt BRACECLOSE { builder.endClass(); fieldType = null; modifiers.clear(); } ; // EnumConstantList: // EnumConstant {, EnumConstant} // EnumConstants: // EnumConstant // EnumConstants , EnumConstant EnumConstants_opt: | EnumConstants_opt COMMA | EnumConstants_opt EnumConstant ; // EnumConstant: // {EnumConstantModifier} Identifier [( [ArgumentList] )] [ClassBody] EnumConstant: Annotations_opt IDENTIFIER { TypeDef td = new TypeDef($2, 0); typeStack.push(td); makeField( td, "", true ); builder.beginField( fd ); } Arguments_opt ClassBody_opt { builder.endField(); typeStack.pop(); } ; // EnumBodyDeclarations: // ; {ClassBodyDeclaration} EnumBodyDeclarations_opt: | SEMI ClassBodyDeclarations_opt ; // ----------------------------- // Productions from �9 (Interfaces) // ----------------------------- // InterfaceDeclaration: // NormalInterfaceDeclaration // AnnotationTypeDeclaration InterfaceDeclaration: NormalInterfaceDeclaration | AnnotationTypeDeclaration ; // NormalInterfaceDeclaration: // {InterfaceModifier} interface Identifier [TypeParameters] [ExtendsInterfaces] InterfaceBody NormalInterfaceDeclaration: Modifiers_opt INTERFACE { cls.setType(ClassDef.INTERFACE); cls.setLineNumber(lexer.getLine()); cls.getModifiers().addAll(modifiers); modifiers.clear(); } IDENTIFIER TypeParameters_opt ExtendsInterfaces_opt { cls.setName( $4 ); cls.setTypeParameters(typeParams); builder.beginClass(cls); cls = new ClassDef(); } ClassBody { builder.endClass(); } ; // ExtendsInterfaces: // extends InterfaceTypeList ExtendsInterfaces: EXTENDS TypeList { cls.getExtends().addAll( typeList ); typeList.clear(); } ; ExtendsInterfaces_opt: | ExtendsInterfaces ; // InterfaceBody: // { {InterfaceMemberDeclaration} } // InterfaceMemberDeclaration: // ConstantDeclaration // InterfaceMethodDeclaration // ClassDeclaration // InterfaceDeclaration // ; // ConstantDeclaration: // {ConstantModifier} UnannType VariableDeclaratorList ; // ConstantModifier: // Annotation public // static final // InterfaceMethodDeclaration: // {InterfaceMethodModifier} MethodHeader MethodBody // InterfaceMethodModifier: // Annotation public // abstract default static strictfp // AnnotationTypeDeclaration: // {InterfaceModifier} @ interface Identifier AnnotationTypeBody AnnotationTypeDeclaration: Modifiers_opt ANNOINTERFACE IDENTIFIER { cls.setType(ClassDef.ANNOTATION_TYPE); cls.setLineNumber(lexer.getLine()); cls.getModifiers().addAll(modifiers); modifiers.clear(); cls.setName( $3 ); builder.beginClass(cls); cls = new ClassDef(); } ClassBody { builder.endClass(); } ; // AnnotationTypeBody: // { {AnnotationTypeMemberDeclaration} } // AnnotationTypeMemberDeclaration: // AnnotationTypeElementDeclaration // ConstantDeclaration // ClassDeclaration // InterfaceDeclaration // ; // AnnotationTypeElementDeclaration: // {AnnotationTypeElementModifier} UnannType Identifier ( ) [Dims] [DefaultValue] ; // AnnotationTypeElementModifier: // Annotation public // abstract // DefaultValue: // default ElementValue // Annotation: // NormalAnnotation // MarkerAnnotation // SingleElementAnnotation // NormalAnnotation: // @ TypeName ( [ElementValuePairList] ) // MarkerAnnotation: // @ TypeName // SingleElementAnnotation: // @ TypeName ( ElementValue ) Annotation: AT { line = lexer.getLine(); } QualifiedIdentifier { AnnoDef annotation = new AnnoDef( new TypeDef($3) ); annotation.setLineNumber(line); annotationStack.addFirst(annotation); } _AnnotationParens_opt { AnnoDef annotation = annotationStack.removeFirst(); if(annotationStack.isEmpty()) { builder.addAnnotation(annotation); } $$ = annotation; } ; // ElementValuePairList: // ElementValuePair { , ElementValuePair } ElementValuePairList: ElementValuePair | ElementValuePairList COMMA ElementValuePair ; // ElementValuePair: // Identifier = ElementValue ElementValuePair: IDENTIFIER EQUALS ElementValue { annotationStack.getFirst().getArgs().put($1, $3); } ; // ElementValue: // ConditionalExpression // ElementValueArrayInitializer // Annotation ElementValue: ConditionalExpression | Annotation | ElementValueArrayInitializer ; // ElementValueArrayInitializer: // { [ElementValueList] [,] } /* Specs say: { ElementValues_opt COMMA_opt } The optional COMMA causes trouble for the parser For that reason the adjusted options of ElementValues_opt, which will accept all cases */ ElementValueArrayInitializer: { annoValueListStack.add(annoValueList); annoValueList = new LinkedList(); } BRACEOPEN ElementValues_opt BRACECLOSE { $$ = new ElemValueListDef(annoValueList); annoValueList = annoValueListStack.remove(annoValueListStack.size() - 1); } ; // AnnotationElement: // ElementValuePairList // ElementValue AnnotationElement_opt: | ElementValuePairList | ElementValue { annotationStack.getFirst().getArgs().put("value", $1); } ; ElementValues_opt: | ElementValues_opt ElementValue { annoValueList.add($2); } | ElementValues_opt COMMA; //-------------------------------------------------------- _AnnotationParens_opt: | PARENOPEN AnnotationElement_opt PARENCLOSE ; Annotations_opt: | Annotations_opt Annotation; // ----------------------------- // Productions from �10 (Arrays) // ----------------------------- // // ArrayInitializer: // { [VariableInitializerList] [,] } // ArrayInitializer: BRACEOPEN VariableInitializerList_opt BRACECLOSE // ; // // VariableInitializerList: // VariableInitializer {, VariableInitializer} // VariableInitializerList: VariableInitializerList VariableInitializer // | VariableInitializerList COMMA // ; // VariableInitializerList_opt: // | VariableInitializerList // ; // ---------------------------------- // Productions from �15 (Expressions) // ---------------------------------- // Primary: // PrimaryNoNewArray // ArrayCreationExpression Primary: PrimaryNoNewArray | ArrayCreationExpression ; // PrimaryNoNewArray: // Literal // TypeName {[ ]} . class // void . class // this // TypeName . this // ( Expression ) // ClassInstanceCreationExpression // FieldAccess // ArrayAccess // MethodInvocation // MethodReference PrimaryNoNewArray: Literal | PrimitiveType Dims_opt DOT CLASS { $$ = new TypeRefDef(new TypeDef($1.getName(), $2)); } | PARENOPEN Expression PARENCLOSE { $$ = new ParenExpressionDef($2); } | ClassInstanceCreationExpression | QualifiedIdentifier DOT CLASS { $$ = new TypeRefDef(new TypeDef($1, 0)); } | QualifiedIdentifier Dims DOT CLASS { $$ = new TypeRefDef(new TypeDef($1, $2)); } | MethodInvocation | MethodReference | QualifiedIdentifier { $$ = new FieldRefDef($1); } ; // ClassInstanceCreationExpression: // new [TypeArguments] {Annotation} Identifier [TypeArgumentsOrDiamond] ( [ArgumentList] ) [ClassBody] // ExpressionName . new [TypeArguments] {Annotation} Identifier [TypeArgumentsOrDiamond] ( [ArgumentList] ) [ClassBody] // Primary . new [TypeArguments] {Annotation} Identifier [TypeArgumentsOrDiamond] ( [ArgumentList] ) [ClassBody] //// TypeArguments_opt confuses parser ClassInstanceCreationExpression: NEW TypeArguments IDENTIFIER TypeArgumentsOrDiamond_opt PARENOPEN ArgumentList_opt PARENCLOSE CODEBLOCK_opt { CreatorDef creator = new CreatorDef(); creator.setCreatedName( $3 ); $$ = creator; } | NEW IDENTIFIER TypeArgumentsOrDiamond_opt PARENOPEN ArgumentList_opt PARENCLOSE CODEBLOCK_opt { CreatorDef creator = new CreatorDef(); creator.setCreatedName( $2 ); $$ = creator; } ; CODEBLOCK_opt: | CODEBLOCK ; // TypeArgumentsOrDiamond: // TypeArguments // <> TypeArgumentsOrDiamond: TypeArguments | LESSTHAN GREATERTHAN ; TypeArgumentsOrDiamond_opt: | TypeArgumentsOrDiamond ; // FieldAccess: // Primary . Identifier // super . Identifier // TypeName . super . Identifier // ArrayAccess: // ExpressionName [ Expression ] // PrimaryNoNewArray [ Expression ] // MethodInvocation: // MethodName ( [ArgumentList] ) // TypeName . [TypeArguments] Identifier ( [ArgumentList] ) // ExpressionName . [TypeArguments] Identifier ( [ArgumentList] ) // Primary . [TypeArguments] Identifier ( [ArgumentList] ) // super . [TypeArguments] Identifier ( [ArgumentList] ) // TypeName . super . [TypeArguments] Identifier ( [ArgumentList] ) MethodInvocation: IDENTIFIER PARENOPEN ArgumentList_opt PARENCLOSE { $$ = new MethodInvocationDef($1, null); } | QualifiedIdentifier PARENOPEN ArgumentList_opt PARENCLOSE { $$ = new MethodInvocationDef($1, null); } | QualifiedIdentifier DOT TypeParameters IDENTIFIER PARENOPEN ArgumentList_opt PARENCLOSE { $$ = new MethodInvocationDef($1, null); } | SUPER DOT TypeParameters_opt IDENTIFIER PARENOPEN ArgumentList_opt PARENCLOSE { $$ = new MethodInvocationDef("super." + $1, null); } | QualifiedIdentifier DOT SUPER DOT TypeParameters_opt IDENTIFIER PARENOPEN ArgumentList_opt PARENCLOSE { $$ = new MethodInvocationDef($1 + ".super", null); } ; // ArgumentList: // Expression {, Expression} ArgumentList: Expression { builder.addArgument( (ExpressionDef) $1); } | ArgumentList COMMA Expression { builder.addArgument( (ExpressionDef) $3); } ; ArgumentList_opt: | ArgumentList ; // MethodReference: // ExpressionName :: [TypeArguments] Identifier // ReferenceType :: [TypeArguments] Identifier // Primary :: [TypeArguments] Identifier // super :: [TypeArguments] Identifier // TypeName . super :: [TypeArguments] Identifier // ClassType :: [TypeArguments] new // ArrayType :: new MethodReference: QualifiedIdentifier COLONCOLON TypeArguments_opt IDENTIFIER { $$ = new MethodReferenceDef(); } | SUPER COLONCOLON TypeArguments_opt IDENTIFIER { $$ = new MethodReferenceDef(); } | QualifiedIdentifier COLONCOLON NEW { $$ = new MethodReferenceDef(); } | ArrayType COLONCOLON TypeArguments_opt IDENTIFIER { $$ = new MethodReferenceDef(); } ; // ArrayCreationExpression: // new PrimitiveType DimExprs [Dims] // new ClassOrInterfaceType DimExprs [Dims] // new PrimitiveType Dims ArrayInitializer // new ClassOrInterfaceType Dims ArrayInitializer ArrayCreationExpression: NEW PrimitiveType DimExprs Dims_opt { CreatorDef creator = new CreatorDef(); creator.setCreatedName( $2.getName() ); $$ = creator; } | NEW ClassOrInterfaceType DimExprs Dims_opt { CreatorDef creator = new CreatorDef(); creator.setCreatedName( $2.getName() ); $$ = creator; } | NEW PrimitiveType Dims CODEBLOCK /* =ArrayInitializer */ { CreatorDef creator = new CreatorDef(); creator.setCreatedName( $2.getName() ); $$ = creator; } | NEW ClassOrInterfaceType Dims CODEBLOCK /* =ArrayInitializer */ { CreatorDef creator = new CreatorDef(); creator.setCreatedName( $2.getName() ); $$ = creator; } ; // DimExprs: // DimExpr {DimExpr} DimExprs: DimExpr | DimExprs DimExpr ; // DimExpr: // {Annotation} [ Expression ] DimExpr: SQUAREOPEN Expression SQUARECLOSE ; // ConstantExpression: // Expression // Expression: // LambdaExpression // AssignmentExpression Expression: AssignmentExpression ; // LambdaExpression: // LambdaParameters -> LambdaBody // LambdaParameters: // Identifier // ( [FormalParameterList] ) // ( InferredFormalParameterList ) // InferredFormalParameterList: // Identifier {, Identifier} // LambdaBody: // Expression // Block // AssignmentExpression: // ConditionalExpression // Assignment AssignmentExpression: ConditionalExpression | Assignment ; // Assignment: // LeftHandSide AssignmentOperator Expression Assignment: LeftHandSide AssignmentOperator Expression { $$ = new AssignmentDef($1, $2, $3); } ; // LeftHandSide: // ExpressionName // FieldAccess // ArrayAccess LeftHandSide: QualifiedIdentifier { $$ = new FieldRefDef($1); } ; // AssignmentOperator: // = // *= // /= // %= // += // -= // <<= // >>= // >>>= // &= // ^= // |= AssignmentOperator: EQUALS | STAREQUALS | SLASHEQUALS | PERCENTEQUALS | PLUSEQUALS | MINUSEQUALS | LESSTHAN2EQUALS | GREATERTHAN2EQUALS | GREATERTHAN3EQUALS | AMPERSANDEQUALS | CIRCUMFLEXEQUALS | VERTLINEEQUALS ; // ConditionalExpression: // ConditionalOrExpression // ConditionalOrExpression ? Expression : ConditionalExpression ConditionalExpression: ConditionalOrExpression | ConditionalOrExpression QUERY Expression COLON ConditionalExpression { $$ = new QueryDef($1, $3, $5); } ; // ConditionalOrExpression: // ConditionalAndExpression // ConditionalOrExpression || ConditionalAndExpression ConditionalOrExpression: ConditionalAndExpression | ConditionalOrExpression VERTLINE2 ConditionalAndExpression { $$ = new LogicalOrDef($1, $3); } ; // ConditionalAndExpression: // InclusiveOrExpression // ConditionalAndExpression && InclusiveOrExpression ConditionalAndExpression: InclusiveOrExpression | ConditionalAndExpression AMPERSAND2 InclusiveOrExpression { $$ = new LogicalAndDef($1, $3); } ; // InclusiveOrExpression: // ExclusiveOrExpression // InclusiveOrExpression | ExclusiveOrExpression InclusiveOrExpression: ExclusiveOrExpression | InclusiveOrExpression VERTLINE ExclusiveOrExpression { $$ = new OrDef($1, $3); } ; // ExclusiveOrExpression: // AndExpression // ExclusiveOrExpression ^ AndExpression ExclusiveOrExpression: AndExpression | ExclusiveOrExpression CIRCUMFLEX AndExpression { $$ = new ExclusiveOrDef($1, $3); } ; // AndExpression: // EqualityExpression // AndExpression & EqualityExpression AndExpression: EqualityExpression | AndExpression AMPERSAND EqualityExpression { $$ = new AndDef($1, $3); } ; // EqualityExpression: // RelationalExpression // EqualityExpression == RelationalExpression // EqualityExpression != RelationalExpression EqualityExpression: RelationalExpression | EqualityExpression EQUALS2 RelationalExpression { $$ = new EqualsDef($1, $3); } | EqualityExpression NOTEQUALS RelationalExpression { $$ = new NotEqualsDef($1, $3); } ; // RelationalExpression: // ShiftExpression // RelationalExpression < ShiftExpression // RelationalExpression > ShiftExpression // RelationalExpression <= ShiftExpression // RelationalExpression >= ShiftExpression // RelationalExpression instanceof ReferenceType RelationalExpression: ShiftExpression | RelationalExpression LESSTHAN ShiftExpression { $$ = new LessThanDef($1, $3); } | RelationalExpression GREATERTHAN ShiftExpression { $$ = new GreaterThanDef($1, $3); } | RelationalExpression LESSEQUALS ShiftExpression { $$ = new LessEqualsDef($1, $3); } | RelationalExpression GREATEREQUALS ShiftExpression { $$ = new GreaterEqualsDef($1, $3); } ; // ShiftExpression: // AdditiveExpression // ShiftExpression << AdditiveExpression // ShiftExpression >> AdditiveExpression // ShiftExpression >>> AdditiveExpression ShiftExpression: AdditiveExpression | ShiftExpression LESSTHAN2 AdditiveExpression { $$ = new ShiftLeftDef($1, $3); } | ShiftExpression GREATERTHAN2 AdditiveExpression { $$ = new ShiftRightDef($1, $3); } | ShiftExpression GREATERTHAN3 AdditiveExpression { $$ = new UnsignedShiftRightDef($1, $3); } ; // AdditiveExpression: // MultiplicativeExpression // AdditiveExpression + MultiplicativeExpression // AdditiveExpression - MultiplicativeExpression AdditiveExpression: MultiplicativeExpression | AdditiveExpression PLUS MultiplicativeExpression { $$ = new AddDef($1, $3); } | AdditiveExpression MINUS MultiplicativeExpression { $$ = new SubtractDef($1, $3); } ; // MultiplicativeExpression: // UnaryExpression // MultiplicativeExpression * UnaryExpression // MultiplicativeExpression / UnaryExpression // MultiplicativeExpression % UnaryExpression MultiplicativeExpression: UnaryExpression | MultiplicativeExpression STAR UnaryExpression { $$ = new MultiplyDef($1, $3); } | MultiplicativeExpression SLASH UnaryExpression { $$ = new DivideDef($1, $3); } | MultiplicativeExpression PERCENT UnaryExpression { $$ = new RemainderDef($1, $3); } ; // UnaryExpression: // PreIncrementExpression // PreDecrementExpression // + UnaryExpression // - UnaryExpression // UnaryExpressionNotPlusMinus UnaryExpression: PreIncrementExpression | PreDecrementExpression | PLUS UnaryExpression { $$ = new PlusSignDef($2); } | MINUS UnaryExpression { $$ = new MinusSignDef($2); } | UnaryExpressionNotPlusMinus ; // PreIncrementExpression: // ++ UnaryExpression PreIncrementExpression: PLUSPLUS UnaryExpression { $$ = new PreIncrementDef($2); } ; // PreDecrementExpression: // -- UnaryExpression PreDecrementExpression: MINUSMINUS UnaryExpression { $$ = new PreDecrementDef($2); } ; // UnaryExpressionNotPlusMinus: // PostfixExpression // ~ UnaryExpression // ! UnaryExpression // CastExpression UnaryExpressionNotPlusMinus: PostfixExpression | TILDE UnaryExpression { $$ = new NotDef($2); } | EXCLAMATION UnaryExpression { $$ = new LogicalNotDef($2); } | CastExpression ; // PostfixExpression: // Primary // ExpressionName // PostIncrementExpression // PostDecrementExpression PostfixExpression: Primary | PostIncrementExpression | PostDecrementExpression ; // PostIncrementExpression: // PostfixExpression ++ PostIncrementExpression: PostfixExpression PLUSPLUS { $$ = new PostIncrementDef($1); } ; // PostDecrementExpression: // PostfixExpression -- PostDecrementExpression: PostfixExpression MINUSMINUS { $$ = new PostDecrementDef($1); } ; // CastExpression: // ( PrimitiveType ) UnaryExpression // ( ReferenceType {AdditionalBound} ) UnaryExpressionNotPlusMinus // ( ReferenceType {AdditionalBound} ) LambdaExpression CastExpression: PARENOPEN PrimitiveType Dims_opt PARENCLOSE UnaryExpression { $$ = new CastDef(new TypeDef($2.getName(), $3), $5); } | PARENOPEN QualifiedIdentifier PARENCLOSE UnaryExpressionNotPlusMinus { $$ = new CastDef(new TypeDef($2, 0), $4); } | PARENOPEN QualifiedIdentifier Dims PARENCLOSE UnaryExpressionNotPlusMinus { $$ = new CastDef(new TypeDef($2, $3), $5); } ; // -------------------------------------------------- // Productions from §4 (Types, Values, and Variables) // -------------------------------------------------- // Type: // PrimitiveType // ReferenceType Type: PrimitiveType | ReferenceType ; // PrimitiveType: // {Annotation} NumericType // {Annotation} boolean // NumericType: // IntegralType // FloatingPointType // IntegralType: // byte short int long char // FloatingPointType: // float double // ReferenceType: // ClassOrInterfaceType // TypeVariable // ArrayType ReferenceType: ArrayType | ClassOrInterfaceType ; // ClassOrInterfaceType: // ClassType // InterfaceType // ClassType: // {Annotation} Identifier [TypeArguments] // ClassOrInterfaceType . {Annotation} Identifier [TypeArguments] // InterfaceType: // ClassType // TypeVariable: // {Annotation} Identifier // ArrayType: // PrimitiveType Dims // ClassOrInterfaceType Dims // TypeVariable Dims ArrayType: ClassOrInterfaceType Dims { TypeDef td = $1; td.setDimensions($2); $$ = td; } | PrimitiveType Dims { TypeDef td = $1; td.setDimensions($2); $$ = td; } ; // Dims: // {Annotation} [ ] {{Annotation} [ ]} Dims: SQUAREOPEN SQUARECLOSE { $$ = 1; } | Dims SQUAREOPEN SQUARECLOSE { $$ = $1 + 1; }; Dims_opt: { $$ = 0; } | Dims ; // TypeParameter: // {TypeParameterModifier} Identifier [TypeBound] TypeParameter: IDENTIFIER { typeVariable = new TypeVariableDef($1); typeVariable.setBounds(new LinkedList()); } TypeBound_opt { typeParams.add(typeVariable); typeVariable = null; }; // TypeBound: // extends TypeVariable // extends ClassOrInterfaceType {AdditionalBound} TypeBound: EXTENDS ClassOrInterfaceType { typeVariable.setBounds(new LinkedList()); typeVariable.getBounds().add($2); } AdditionalBound_opts ; TypeBound_opt: | TypeBound ; // AdditionalBound: // & InterfaceType AdditionalBound: AMPERSAND ClassOrInterfaceType { typeVariable.getBounds().add($2); } ; AdditionalBound_opts: | AdditionalBound AdditionalBound_opts ; // TypeArguments: // < TypeArgumentList > TypeArguments: LESSTHAN { typeStack.peek().setActualArgumentTypes(new LinkedList()); } TypeArgumentList GREATERTHAN ; TypeArguments_opt: | TypeArguments ; // TypeArgumentList: // TypeArgument {, TypeArgument} TypeArgumentList: TypeArgument { (typeStack.peek()).getActualArgumentTypes().add($1); } | TypeArgumentList COMMA TypeArgument { (typeStack.peek()).getActualArgumentTypes().add($3); } ; // TypeArgument: // ReferenceType // Wildcard TypeArgument: ReferenceType | Wildcard ; // Wildcard: // {Annotation} ? [WildcardBounds] Wildcard: QUERY WildcardBounds { $$ = $2; } | QUERY { $$ = new WildcardTypeDef(); } ; // WildcardBounds: // extends ReferenceType // super ReferenceType WildcardBounds: EXTENDS ReferenceType { $$ = new WildcardTypeDef($2, "extends" ); } | SUPER ReferenceType { $$ = new WildcardTypeDef($2, "super" ); } ; //======================================================== // QualifiedIdentifier: // Identifier { . Identifier } QualifiedIdentifier: IDENTIFIER | QualifiedIdentifier DOT IDENTIFIER { $$ = $1 + '.' + $3; } ; // TypeName: // Identifier // PackageOrTypeName . Identifier // PackageOrTypeName: // Identifier // PackageOrTypeName . Identifier //======================================================== // PrimitiveType: // byte // short // char // int // long // float // double // boolean PrimitiveType: BYTE { $$ = new TypeDef("byte"); } | SHORT { $$ = new TypeDef("short"); } | CHAR { $$ = new TypeDef("char"); } | INT { $$ = new TypeDef("int"); } | LONG { $$ = new TypeDef("long"); } | FLOAT { $$ = new TypeDef("float"); } | DOUBLE { $$ = new TypeDef("double"); } | BOOLEAN { $$ = new TypeDef("boolean"); } ; // Actually // ClassOrInterfaceType: ClassType | InterfaceType; // ClassType: TypeDeclSpecifier TypeArguments_opt // InterfaceType: TypeDeclSpecifier TypeArguments_opt // Parser can't see the difference ClassOrInterfaceType: TypeDeclSpecifier { TypeDef td = new TypeDef($1,0); $$ = typeStack.push(td); } TypeArguments_opt { $$ = typeStack.pop(); }; // Actually // TypeDeclSpecifier: TypeName | ClassOrInterfaceType . Identifier // TypeName: Identifier | TypeName . Identifier TypeDeclSpecifier: QualifiedIdentifier | ClassOrInterfaceType DOT IDENTIFIER { $$ = $1.getName() + '.' + $3; }; //======================================================== // TypeList: // ReferenceType { , ReferenceType } TypeList: ReferenceType { typeList.add( $1 ); } | TypeList COMMA ReferenceType { typeList.add( $3 ); } ; //======================================================== Modifiers_opt: | Modifiers_opt Modifier; // Modifier: // Annotation // public // protected // private // static // abstract // final // native // synchronized // transient // volatile // strictfp Modifier: Annotation | PUBLIC { modifiers.add("public"); } | PROTECTED { modifiers.add("protected"); } | PRIVATE { modifiers.add("private"); } | STATIC { modifiers.add("static"); } | FINAL { modifiers.add("final"); } | ABSTRACT { modifiers.add("abstract"); } | NATIVE { modifiers.add("native"); } | SYNCHRONIZED { modifiers.add("synchronized"); } | VOLATILE { modifiers.add("volatile"); } | TRANSIENT { modifiers.add("transient"); } | STRICTFP { modifiers.add("strictfp"); } | DEFAULT { modifiers.add("default"); } ; Arguments_opt: | PARENOPEN ArgumentList_opt PARENCLOSE ; //======================================================== // Literal: // IntegerLiteral // FloatingPointLiteral // CharacterLiteral // StringLiteral // BooleanLiteral // NullLiteral Literal: INTEGER_LITERAL { $$ = new ConstantDef($1, Integer.class); } | FLOAT_LITERAL { $$ = new ConstantDef($1, Float.class); } | CHAR_LITERAL { String s = lexer.getCodeBody(); $$ = new ConstantDef(s, Character.class); } | STRING_LITERAL { String s = lexer.getCodeBody(); $$ = new ConstantDef(s, String.class); } | BOOLEAN_LITERAL { $$ = new ConstantDef($1, Boolean.class); } ; //======================================================== %% private JavaLexer lexer; private Builder builder; private StringBuilder textBuffer = new StringBuilder(); private ClassDef cls = new ClassDef(); private MethodDef mth = new MethodDef(); private FieldDef fd; private ModuleDef.ExportsDef exp; private ModuleDef.OpensDef opn; private ModuleDef.ProvidesDef prv; private List moduleTargets = new LinkedList(); private List typeParams = new LinkedList(); //for both JavaClass and JavaMethod private LinkedList annotationStack = new LinkedList(); // Use LinkedList instead of Stack because it is unsynchronized private List> annoValueListStack = new LinkedList>(); // Use LinkedList instead of Stack because it is unsynchronized private List annoValueList = null; private FieldDef param = new FieldDef(); private java.util.Set modifiers = new java.util.LinkedHashSet(); private TypeDef fieldType; private TypeVariableDef typeVariable; private Stack typeStack = new Stack(); private List typeList = new LinkedList(); 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( JavaLexer lexer, Builder builder ) { lexer.addCommentHandler( this ); 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; ElemValueDef annoval; } private void makeField(TypeDef field, String body, boolean enumConstant) { fd = new FieldDef( field.getName() ); fd.setName(field.getName()); fd.setLineNumber(lexer.getLine()); fd.getModifiers().addAll(modifiers); fd.setType( fieldType ); fd.setDimensions(field.getDimensions()); fd.setEnumConstant(enumConstant); fd.setBody(body); } public void onComment( String comment, int line, int column ) { DefaultJavaCommentLexer commentLexer = new DefaultJavaCommentLexer( new java.io.StringReader( comment ) ); commentLexer.setLineOffset( line ); commentLexer.setColumnOffset( column ); DefaultJavaCommentParser commentParser = new DefaultJavaCommentParser( commentLexer, builder); commentParser.setDebugLexer( this.debugLexer ); commentParser.setDebugParser( this.yydebug ); commentParser.parse(); }qdox-qdox-2.0-M8/src/it/000077500000000000000000000000001325201777200147725ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/lambda-examples/000077500000000000000000000000001325201777200200265ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/lambda-examples/LambdaExamples01.zip000066400000000000000000000472311325201777200236010ustar00rootroot00000000000000PK zCLambdaExamples01/PK|C LambdaExamples01/build.xmlVMo8W A"mŢM{̈́" Jwdɑԗ8&כ|*xDѫ]6ԕ^5bET;Zz頑 i[k(4B'gZ|VnxUi7$P.Vg6#5*5X4[`k=VOR2V)@vшNM~GBns9>>*+~Dcu/^',"ݢY(,01I&U<"4@gaWSdMӄ$U _W@n?C){$9멃RZ eP"IТUhZR]G~/Q!UVdW'@ch B6T*e]Tt ln'-$:6 k6SNPRx̩J `Tu>c19~*jʥpH ݹN(n`BDhCU!J#-jC3qt{lv%$_SitK tf\q𗉎ch !C +2&ˋ| ganM,Gy:z/H]r f}b"&cWL6U7֨i] evhlJ_ƨ^P!==_jO gM˜bzظZR@|{i)i"[ЏL_i{g^fȣmbτHᩱoޥ$zT?E2,tNҨ^\7-;Eېur f4%%NiMSQ6: 2]:PK1GB.QRLambdaExamples01/manifest.mf 1 0 *v-E5؂i%rUmRr8-JQ Q[-V9PDɹPK |CLambdaExamples01/nbproject/PK|C/ '9)LambdaExamples01/nbproject/build-impl.xml=ks7+fYݍBcg6H8Rv\f+5$!qlrJֹ߯{0$%K*4Fwh4nH.IUeq;yL}[VI3'j]ʚ$yB:'UR WGy|FfI^4er^.V+Q}G `yg2J?M*_*#ӵ:#@u.Y97n, ~dՂ4 Ɋ dF@mNCx&ˣiVUZf봬.E=Ɗ#^sh`7jMLlMuR7ݵTYƴhGc Iu;\zP k]ݲ@UDaz{`L@sA%4:$y JULNbJ?}GeZP0l{ՆZN™]C`r^pEZ5DSطPJ@->;KzEQ_AK^Yl72+ 4@ a[de{CFlD'g.cϋKp~k ~Ò?_4_%`Nkۭ8 vIj@ Aa ?Iy'8[,/ T!f~| R,:uh #"Pz&ݡZb7ʧl;: ŵ*ۥEW'V.*-AK9hp!ߨSdKj0s hx@Y @xpQVNhˬA@H :M믿'iVY50 fl %P$@:ḱ]n6ͦ28|ROsŹ SI!6?qbOwCRޑ~z:~p=T Cm2:jg[6)(ʁVɋ[>6k(ɳ7K?-4hQ _qWs_eeN67DT ᜃ-Z8pT"}sБR?g$ 3m7zm9miFVќ+ ֘3RLaӴ:3гumA7Ib۩;hj3Ց T7K'| )nY0DV$)WڡU7`tcB;zQHM['#vXY1XI>q p6Gvn[Y )1E;[B=(e3m.ݙS&־hVi˻$KGeAўƗ+1q8K *SSϯ<0])Eʀ7H$'lf[Ð 6f7,huG Ѱ@xR*}ډmf0{FfZaP,K]ȬkmrSmUQRitkHgD]Y76.:GhM9UrȿUoVhMkSm)>IU }+e8#ׁRS<V^/PBI+GBQ!iet) E [Wypsh⿖z7+Qgժt%;h=Q_o X$NQgh c" Vi^ʪ[;/P)[ C#)0聹Aa&sD0zű(| ?J[K[ܴu 7}IN .HA go lfkM R%r\(\V2 m(iImC*zGd ,X&`YCpf#UˢdtS%qcP +:~bw:Y"j"-bJGZ$kEQ/i9Q#l03Jx{Kxf lIؿmx^Gf=ˁ_r8 U;>v^e$9Qʦk zuwhN ,˅y閏mQx͔;%j jcN_R}U:]WOdJ̅Y iqSD`ޕ|GVs`JU'5X\.7Dz9JwΨS=p_fOEz߭Mfpߝ6L$tQ.)KL?"څO av(j%֨hkg-+l.!S4[";rZ*POWcBiX|Anʕ. Ҟ +Ӑ:a1;.]wc@H[w?++3Ȣ @羉U\=4Ԃ~o1=,`zk'=eɌ|A*s0x&"^8ƷށSϚrsɘi4m 6/:9ϖ\_c-vʮGR+ȨD7iuEi,ڑYv+n(rqqAϐjg;)v||zIy"@oGt]u( (;0-Iۍm?aw|.x=dˌ1Pup 3f0 sZ(MYv"?2C;>_tݹ@huɭS0_jsctr 7ݗOk9%KWc)4؟/G0jC.xjEhPs`p'ǑMq8IcA`CA׆;r^Pψ ]ҧsX{%X.\6Gn+LSdwFމi\+ûG@sUAY =#: C;|$cel2G D٭g'j:/Ba pBGMQcuCK(e?R%bDe94lc#Y 7&նbz'7;9e"V8o+)Kl5q/eEQ6,b% v64})zR,ܰPud]0ʬʔVNH@\b\&[zÈfB|SѾ_5M>@9)XZ`3idgUC]tz*ll}D:}84CF;l9cd)xv>ʼn—0O00iU7H!c;cʪ/5d]BYLJO.Pv>j >%dN ˺5%TtlgyËWϟ2y}cF#q&q,Z^zcwMsg{elbo U}!-*ͮL-}nGWYUx͑UE',X[y'o١*<# 1O⠑}l(S9r^)y/tGJ:@G=hyf\(ghEpo. kcFekأLfy(;kJV8ПlV yOnȏ7 7cmv4^@rPx6#rpY˃<:d _<ݖ5@TMA 0beڢt/0-sv4M)o~SiDoēXMrXz-;5%ryTpI]M9"w6.q3ʡGB]Ka)[]p$AG9`9xR.Xi} 6IWʕ9әGRHl.guP`89{2:}m/¤CG%F[fILJMа0:'aCt~i}Moo㮵?lpk.q Q'0z&udM-?}vLM (W4V zFM+a,*-| <_m:KsoocOϟN>wxsN)1cj\u,Vkxo ]~(ܒOa_ڐWI5}:rLMwQ] D^t)v*&zw75>u$ZBygFMU$T?[z|zi4Je)Y:m^÷w`ŤEC.,>ֳͪagyiS_.iԹ{[Δ~Y,LR'WsRPO'ulaK|)nKGbO}îԮ"6Ɍfu1 '=rlj$],ԗp/A}{ogRrO菟srE]\{ZW Gjs.>47ᗎz3 }#( Pb:V8ꑊW,*]՛eqDKtm_ :CcT99xѺle]"8#"T+Beq_L f5 &  V.:5Hݡ' .:"#t|̄`Rܻ퀨@ ]ӭ$AkKֶr}I[;sCbӅIi4/]'4TTM%#9qPTuk{CZ'E>s ;ɂ 6zbS%6'|m GZ'??yXg` =rNƵyV:.)Ѫ+ȡhD֨#p5Ć'aȽ. \3-!DgEQƚ}@nژA$SΒb`R\@EƺV~sy?};BCoT1.'Yo A+e*j''Khj~lMP¿K 8ll!>m!M,4gKwds<[ΈtBc8D O(q0>ЎZ 9&an-х/Z\51@[JSj[&;COqO;'*ȊUyU-_UeNeev,i)Z蹢Sy}'m=>4[_= uY|pÔGV'3:"3h&?r҂A O[64C0.5'دk xED#[Ih&p!~JNkʺgҕ6^?H#WZ!X`ࡃFFyC=,=v+(Ftd JNMV@Kjي WU7qKq/9.ø60wĶ^F6q7g\W^/"<{ (^f5O+"R8#|.^R"06EĊ_eEg1_Ƶ_*A3;_uM@Л+=6 i[{S!(8P|7<:ApFvu޼MiZnUH[@š\Q}?tӖ2V &k޹ٖGKY>M ,n!L&q`]e;31U}7^') ;\7x hfTC ",eX_)wjmȼ"ތww;/h"si;/yoj*ۄutfʷnڼϕQwo4fZѭ/wsBի'[l6Z,}~Ov*jU\ђ^ hoYIU>v1hq/>| Fo}>~UJꚆUx]_ΞM)WcHEyU_/yւ#8ڑC8Dl%c()=Tcߨ\z* ~:Ȥ(Nm)8+qV 6^k<^Fz\t\A}: Ǿ^Ozk-lbO]o@2h>uǘӷ̮'9}z߉0Tyߤ ū?-U sRBU. ;qA[7i7PK|C~R.LambdaExamples01/nbproject/genfiles.properties}1O0kM̀hX ٹ4ǎ O*T'J|VT(vϻu~b[\%G:o,rPKYC&P.LambdaExamples01/nbproject/private/private.xml0 <x2AĻ>Xm/Q 'zl}mxyMFB'TTkH.Ee ӣ fx IibDe|LƋ !R#6WxIʵ~kNp^ZBbY@ 3WlT_]hXTOPK|CJS_ -LambdaExamples01/nbproject/project.propertiesUMo7WpNFEx(hZ: FY6\ܵ@Ï]Iȇ|X"Dk0m7- * ^  T::/[0Rtt>C`s AQQb=DPo_3{R4hP ZzۓKvϷ-+!]u,1 o#Sj)ss#*E9]mebKΆ]gG]H(okvq] r؀!!u{[/ ABw&[8vazcepwpN/%T/ Zc]E[T6t?k pl蝏w*l*~ yȊp7g뾆y{8=!I ɱY2?L#(TH.f3mg3*)Yh jE*g^z'̶Z"asw}ZG = u,6Ԧ<ܓVc_ xW Z`<6|{zwL3Dž^nIi-H{``<85y2"^r&vNCEUȴb\ò G\{GHb)%}O #pd}T\tu$5 I'Uͼ&XܓBnh-qCΧeF_R:0oȺJP~ dZ?&&<erωsC ҩxAeu`i^Gj|*zQcOjHW.,t(G0$*_?SK"v >XMrJu:|]qʋ=׺׹rKg jWXݳ,Lt`PK1GB+|e?&LambdaExamples01/nbproject/project.xmlN0y \rS9qpmp4qҔ |4d{rw5؆pkښOt"D߁B.1#s{.1[_MANjz=X'u ֌SL;DI[t-Qƌ-]@мJr7IrM%"_;a QK~ ֣Hsꧧḑa3&`Rf1`uŰ;RNOmЋP4&؟{VѶC6%)>52TV+}Tn3$V =䕕7ddJ&9gF2Zu)(O+^09S-lPYiglQUc};[$T'sBl#rU>.iv u,`TS'#("ti=5EjNTv-J/$s,Fb"}0Hm3ӅAp,.Zw1jCT9}'t7%:cE5CT+\Td|OeHx9OTi]|:'&߾[dm{YhONƓRs>uůO>}7syZVZxH c_PKtCo S;LambdaExamples01/src/com/example/lambda/ComparatorTest.javaN@~#VN%iPA T]T]\KbόfݙM *"}wlG5mU*/ִ2];T#R+[U\&,͞ /WvI#gi)R#WT_et0sg0!ǍkԤM^f7o$H/g5pݙBX3 QD>YdCl"Aj±1JºTU8{o\O:YRh#Xy_,Oia)j'j>?tvg;XZ3LambdaExamples01/src/com/example/lambda/Gender.java+HLNLOUHKH-IIMJIRRpH,-/RN  s&d&+*楤)T+:(hZ.PK3uCkj9LambdaExamples01/src/com/example/lambda/ListenerTest.javaSj@}W ~Zd&%B$RX[KZ;j%KJ[!9眙U.$r9GAJE;mR2S̶dJE>ɴ)(gw~pIVN\#1%L)0.)QcI7wesMw]O,k v[bгCS^JKH9G4`#X2~XΞt6/27qz ]F"zܯ#_UN1 PKeXVB>1LambdaExamples01/src/com/example/lambda/Main.javam;0D=Ŗ"9@$ZhQl ˢ3ҼHdu'ǝ#?N4J*<"Ϙۙ!-RL6!vB_*s eSŚV%߸Hܦ OIb'[oVPKVB##(3LambdaExamples01/src/com/example/lambda/Person.java͗YoF+|/&d'rhcǀ ڼ\*5rު*AXfvv=YSXfO&IS?&I"3aIqwdKR؟sN>B28>v.I)6kvOąN^F1[2&EY -t k I/+JޕT>sMWúB ME%E!%R(6KfS'ugC :Xoe[JUڨ9Ub `SU@TE}"8ņ]Fϭi 9zmz6p4і6WEn:`/HMIj20ӞCUYo0ߴ'}N#cP9b4;ES77R7Qh5G#òI֫uuȎ&y1ԃԌ*>ّS[َ/o68 Ek<6%SvیdRa¯Ӷ_S.4x助ډT J} TR*=[Y3 3Wuϡ˪ZdK68ÜtUfkZz-圭hDt*T `eMwש7j2%8/xrdi7{rTًڛwUjVJr[`3;j6{EnGjN\Sޕ"OS@|} Ɉ[rDeQ7<:PKyCV9LambdaExamples01/src/com/example/lambda/RunnableTest.javaOK@)^zJ&7`a 1tMc|wmjXf޾1v!TZfe'(\5_3)C ݛ6ow9R*c/=u`4;_!y3j^^Mc`³=XG2ӽ:qBŋ(Σ}cOyA~Y'ǭSyؓ1mM5wᲗ`W6Npu*7-|HFAe>PK }CLambdaExamples01/test/PK zCALambdaExamples01/PK|C /LambdaExamples01/build.xmlPK1GB.QR/LambdaExamples01/manifest.mfPK |CALambdaExamples01/nbproject/PK|C/ '9)LambdaExamples01/nbproject/build-impl.xmlPK|C~R.H-LambdaExamples01/nbproject/genfiles.propertiesPK |C#A.LambdaExamples01/nbproject/private/PK |C4.LambdaExamples01/nbproject/private/config.propertiesPK|C%o5#/LambdaExamples01/nbproject/private/private.propertiesPKYC&P./LambdaExamples01/nbproject/private/private.xmlPK|CJS_ -0LambdaExamples01/nbproject/project.propertiesPK1GB+|e?&4LambdaExamples01/nbproject/project.xmlPK |CA5LambdaExamples01/src/PK |CA5LambdaExamples01/src/com/PK |C!A36LambdaExamples01/src/com/example/PK zC(Ar6LambdaExamples01/src/com/example/lambda/PKzC}46LambdaExamples01/src/com/example/lambda/#Untitled-1#PKtCo S;;LambdaExamples01/src/com/example/lambda/ComparatorTest.javaPKoGBkH>XZ3<LambdaExamples01/src/com/example/lambda/Gender.javaPK3uCkj9=LambdaExamples01/src/com/example/lambda/ListenerTest.javaPKeXVB>1?LambdaExamples01/src/com/example/lambda/Main.javaPKVB##(3h@LambdaExamples01/src/com/example/lambda/Person.javaPKyCV9DLambdaExamples01/src/com/example/lambda/RunnableTest.javaPK }CA4FLambdaExamples01/test/PKhFqdox-qdox-2.0-M8/src/it/lambda-examples/invoker.properties000066400000000000000000000000761325201777200236240ustar00rootroot00000000000000invoker.goals = org.codehaus.mojo:exec-maven-plugin:1.3.1:javaqdox-qdox-2.0-M8/src/it/lambda-examples/pom.xml000066400000000000000000000014051325201777200213430ustar00rootroot00000000000000 4.0.0 com.thoughtworks.qdox.it lambda-examples 01 pom http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html#section2 com.thoughtworks.qdox qdox @project.version@ qdox-qdox-2.0-M8/src/it/lambda-examples/test.properties000066400000000000000000000001361325201777200231230ustar00rootroot00000000000000exec.mainClass = com.thoughtworks.qdox.tools.QDoxTester exec.arguments = LambdaExamples01.zipqdox-qdox-2.0-M8/src/it/lambda-examples/verify.groovy000066400000000000000000000004631325201777200226040ustar00rootroot00000000000000def buildLog = new File( basedir, "build.log" ) // zip contains 6 java files assert buildLog.text.contains( "Success: 6" ) // zip contains 10 non-java files assert buildLog.text.contains( "Failure: 10" ) assert buildLog.text.contains( "Error : 0" ) assert buildLog.text.contains( "Total : 16" ) qdox-qdox-2.0-M8/src/it/qdox-223/000077500000000000000000000000001325201777200162515ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-223/pom.xml000066400000000000000000000022661325201777200175740ustar00rootroot00000000000000 4.0.0 com.thoughtworks.qdox.it parent 1.0 com.thoughtworks.qdox.it qdox-223 1.0 org.apache.maven.plugins maven-compiler-plugin 2.3.2 com.thoughtworks.qdox qdox @project.version@ junit junit 4.8.2 qdox-qdox-2.0-M8/src/it/qdox-223/src/000077500000000000000000000000001325201777200170405ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-223/src/main/000077500000000000000000000000001325201777200177645ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-223/src/main/java/000077500000000000000000000000001325201777200207055ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-223/src/main/java/com/000077500000000000000000000000001325201777200214635ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-223/src/main/java/com/AnnotationA.java000066400000000000000000000000601325201777200245350ustar00rootroot00000000000000package com; public @interface AnnotationA { } qdox-qdox-2.0-M8/src/it/qdox-223/src/main/java/com/x/000077500000000000000000000000001325201777200217325ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-223/src/main/java/com/x/QClass.java000066400000000000000000000001171325201777200237620ustar00rootroot00000000000000package com.x; public class QClass { public void someMethod() { } } qdox-qdox-2.0-M8/src/it/qdox-223/src/main/java/com/x/package-info.java000066400000000000000000000000411325201777200251140ustar00rootroot00000000000000@com.AnnotationA() package com.x;qdox-qdox-2.0-M8/src/it/qdox-223/src/main/java/com/y/000077500000000000000000000000001325201777200217335ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-223/src/main/java/com/y/BClass.java000066400000000000000000000001211325201777200237370ustar00rootroot00000000000000package com.y; public class BClass { public void someMethod() { } } qdox-qdox-2.0-M8/src/it/qdox-223/src/main/java/com/y/package-info.java000066400000000000000000000000411325201777200251150ustar00rootroot00000000000000@com.AnnotationA() package com.y;qdox-qdox-2.0-M8/src/it/qdox-223/src/test/000077500000000000000000000000001325201777200200175ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-223/src/test/java/000077500000000000000000000000001325201777200207405ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-223/src/test/java/MissingAnnotationsTest.java000066400000000000000000000015001325201777200262660ustar00rootroot00000000000000import static org.junit.Assert.*; import java.io.File; import org.junit.Test; import com.thoughtworks.qdox.JavaProjectBuilder; public class MissingAnnotationsTest { @Test public void packageInfoAnnotationsMissing() { //package y, package-info not first file, deprecated annotation found JavaProjectBuilder builder = new JavaProjectBuilder(); builder.addSourceTree(new File("./src/main/java/com/y")); assertEquals(1, builder.getPackages().iterator().next().getAnnotations().size()); //package x, package-info not first file, test fails, deprecated annotation not found builder = new JavaProjectBuilder(); builder.addSourceTree(new File("./src/main/java/com/x")); assertEquals(1, builder.getPackages().iterator().next().getAnnotations().size()); } } qdox-qdox-2.0-M8/src/it/qdox-224/000077500000000000000000000000001325201777200162525ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-224/pom.xml000066400000000000000000000024251325201777200175720ustar00rootroot00000000000000 4.0.0 com.thoughtworks.qdox.it parent 1.0 com.thoughtworks.qdox.it qdox-224 1.0 org.apache.maven.plugins maven-compiler-plugin 2.3.2 com.thoughtworks.qdox qdox @project.version@ commons-lang commons-lang 2.1 sources junit junit 4.8.2 test qdox-qdox-2.0-M8/src/it/qdox-224/src/000077500000000000000000000000001325201777200170415ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-224/src/test/000077500000000000000000000000001325201777200200205ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-224/src/test/java/000077500000000000000000000000001325201777200207415ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-224/src/test/java/ClasspathSourcesTest.java000066400000000000000000000023661325201777200257410ustar00rootroot00000000000000import static org.junit.Assert.*; import java.io.File; import java.util.Collections; import org.junit.Test; import com.thoughtworks.qdox.JavaProjectBuilder; import com.thoughtworks.qdox.model.*; public class ClasspathSourcesTest { @Test public void testCommonsLangSources() throws Exception { JavaProjectBuilder builder = new JavaProjectBuilder(); builder.addClassLoader( ClassLoader.getSystemClassLoader() ); JavaClass clazz = builder.getClassByName( "org.apache.commons.lang.BitField" ); JavaMethod method = clazz.getMethods().get( 0 ); assertEquals( "getValue", method.getName() ); assertEquals( "holder", method.getParameters().get( 0 ).getName() ); assertEquals( "see", method.getTags().get( 0 ).getName() ); assertEquals( "#setValue(int,int)", method.getTags().get( 0 ).getValue() ); assertEquals( "param", method.getTags().get( 1 ).getName() ); assertEquals( "holder the int data containing the bits we're interested\r\n in", method.getTags().get( 1 ).getValue() ); assertEquals( "return", method.getTags().get( 2 ).getName() ); assertEquals( "the selected bits, shifted right appropriately", method.getTags().get( 2 ).getValue() ); } } qdox-qdox-2.0-M8/src/it/qdox-241/000077500000000000000000000000001325201777200162515ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-241/pom.xml000066400000000000000000000025271325201777200175740ustar00rootroot00000000000000 4.0.0 com.thoughtworks.qdox.it parent 1.0 com.thoughtworks.qdox.it qdox-241 1.0-SNAPSHOT Set the StateStack size of the lexer through qdox.properties org.apache.maven.plugins maven-compiler-plugin 2.3.2 com.thoughtworks.qdox qdox @project.version@ junit junit 4.8.2 qdox-qdox-2.0-M8/src/it/qdox-241/src/000077500000000000000000000000001325201777200170405ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-241/src/main/000077500000000000000000000000001325201777200177645ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-241/src/main/resources/000077500000000000000000000000001325201777200217765ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-241/src/main/resources/qdox.properties000066400000000000000000000000321325201777200250620ustar00rootroot00000000000000lexer.statestack.size = 15qdox-qdox-2.0-M8/src/it/qdox-241/src/test/000077500000000000000000000000001325201777200200175ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-241/src/test/java/000077500000000000000000000000001325201777200207405ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-241/src/test/java/QDoxPropertiesTest.java000066400000000000000000000010651325201777200253750ustar00rootroot00000000000000import static org.junit.Assert.*; import java.io.File; import org.junit.Test; import com.thoughtworks.qdox.JavaProjectBuilder; import com.thoughtworks.qdox.model.JavaSource; public class QDoxPropertiesTest { @Test public void customStateStackSize() throws Exception { JavaProjectBuilder builder = new JavaProjectBuilder(); JavaSource source = builder.addSource( new File("./src/test/resources/Test.java") ); assertNotNull( source.getClassByName( "Test$A$B$C$D$E$F$G$H$I$J$K$L$M$N" ) ); } } qdox-qdox-2.0-M8/src/it/qdox-241/src/test/resources/000077500000000000000000000000001325201777200220315ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/qdox-241/src/test/resources/Test.java000066400000000000000000000031211325201777200236100ustar00rootroot00000000000000public interface Test { interface A { interface B { interface C { interface D { interface E { interface F { interface G { interface H { interface I { interface J { interface K { interface L { interface M { interface N { } } } } } } } } } } } } } } } qdox-qdox-2.0-M8/src/it/settings.xml000066400000000000000000000031741325201777200173610ustar00rootroot00000000000000 it-repo true local.central @localRepositoryUrl@ true true local.central @localRepositoryUrl@ true true qdox-qdox-2.0-M8/src/it/setup-parent/000077500000000000000000000000001325201777200174215ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/it/setup-parent/invoker.properties000066400000000000000000000000271325201777200232130ustar00rootroot00000000000000invoker.goals = installqdox-qdox-2.0-M8/src/it/setup-parent/pom.xml000066400000000000000000000013731325201777200207420ustar00rootroot00000000000000 4.0.0 com.thoughtworks.qdox.it parent pom 1.0 9 1.6 1.6 qdox-qdox-2.0-M8/src/main/000077500000000000000000000000001325201777200153025ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/000077500000000000000000000000001325201777200162235ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/000077500000000000000000000000001325201777200170015ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/000077500000000000000000000000001325201777200215515ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/000077500000000000000000000000001325201777200225245ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/JavaProjectBuilder.java000066400000000000000000000304321325201777200271100ustar00rootroot00000000000000package com.thoughtworks.qdox; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Reader; import java.net.URL; import java.util.Collection; import java.util.LinkedList; import com.thoughtworks.qdox.directorywalker.DirectoryScanner; import com.thoughtworks.qdox.directorywalker.FileVisitor; import com.thoughtworks.qdox.directorywalker.SuffixFilter; import com.thoughtworks.qdox.library.ClassLibraryBuilder; import com.thoughtworks.qdox.library.ErrorHandler; import com.thoughtworks.qdox.library.SortedClassLibraryBuilder; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaModule; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaSource; /** * This is the improved version of the JavaDocBuilder of QDox 1.x, which has the following tasks: *
    *
  • Provide adders for all kind of resources, such as classloaders, java files and source directories
  • *
  • Provide setters to enable the debug-mode for the Lexer and Parser (which are used when parsing sourcefiles) and * the encoding *
  • Provide getter for retrieving Java Object Models from these libraries, such as JavaSources, JavaClasses and * JavaPackages
  • *
  • Provide a method to search through all the parsed JavaClasses
  • *
  • Provide store and load methods for the JavaProjectBuilder
  • *
  • Provide the option to set an ErrorHandler
  • *
* By default the JavaProjectBuilder will use the {@link com.thoughtworks.qdox.library.SortedClassLibraryBuilder}, which means it doesn't matter in * which order you add the resources, first all sources and sourcefolders, followed by the classloaders. Another * implementation for the ClassLibraryBuilder is the {@link com.thoughtworks.qdox.library.OrderedClassLibraryBuilder}, which preserves the order in * which resources are added. By creating a new JavaProjectBuilder with your own ClassLibraryBuilder you can decide * which loading strategy should be used. * * @author Robert Scholte * @since 2.0 */ public class JavaProjectBuilder { private final ClassLibraryBuilder classLibraryBuilder; // Constructors /** * Default constructor, which will use the {@link SortedClassLibraryBuilder} implementation * and add the default classloaders */ public JavaProjectBuilder() { this.classLibraryBuilder = new SortedClassLibraryBuilder(); classLibraryBuilder.appendDefaultClassLoaders(); } /** * Custom constructor, so another resource loading strategy can be defined * * @param classLibraryBuilder custom implementation of {@link ClassLibraryBuilder} */ public JavaProjectBuilder( ClassLibraryBuilder classLibraryBuilder ) { this.classLibraryBuilder = classLibraryBuilder; } // Lexer and Parser -setters /** * Enable the debugmode for the Lexer * * @param debugLexer true to enable, false to disable * @return this javaProjectBuilder itself */ public JavaProjectBuilder setDebugLexer( boolean debugLexer ) { classLibraryBuilder.setDebugLexer( debugLexer ); return this; } /** * Enable the debugmode for the Parser * * @param debugParser true to enable, false to disable * @return this javaProjectBuilder itself */ public JavaProjectBuilder setDebugParser( boolean debugParser ) { classLibraryBuilder.setDebugParser( debugParser ); return this; } /** * Sets the encoding when using Files or URL's to parse. * * @param encoding the encoding to use for {@link java.io.File} or {@link java.net.URL} * @return this javaProjectBuilder itself */ public JavaProjectBuilder setEncoding( String encoding ) { classLibraryBuilder.setEncoding( encoding ); return this; } /** * Sets the errorHandler which will be triggered when a parse exception occurs. * * @param errorHandler the errorHandler * @return this javaProjectBuilder itself */ public JavaProjectBuilder setErrorHandler( ErrorHandler errorHandler ) { classLibraryBuilder.setErrorHander( errorHandler ); return this; } /** * Add a java source from a file to this JavaProjectBuilder * * @param file a java file * @return the {@link JavaSource} of the parsed file * @throws IOException if file is a directory or can't be read */ public JavaSource addSource( File file ) throws IOException { return classLibraryBuilder.addSource( file ); } /** * Add a java source from a URL to this JavaProjectBuilder * * @param url the url * @return the {@link JavaSource} of the parsed file * @throws IOException if the url can't be read */ public JavaSource addSource( URL url ) throws IOException { return classLibraryBuilder.addSource( url ); } /** * Add a java source from a Reader to this JavaProjectBuilder * * @param reader the reader * @return the {@link JavaSource} of the parsed reader content */ public JavaSource addSource( Reader reader ) { return classLibraryBuilder.addSource( reader ); } /** * Add a sourcefolder to this javaprojectbuilder, but don't parse any file. This is a lazy parser. Only if a * JavaClass is called it will be searched by matching the package with the folder structure and the classname with * the filename * * @param sourceFolder the sourcefolder to add * @return the {@link JavaModule} when the sourceFolder has a module-info, otherwise {@code null} * @see #addSourceTree(File) */ public JavaModule addSourceFolder( File sourceFolder ) { return classLibraryBuilder.addSourceFolder( sourceFolder ); } /** * Add all java files of the {@code directory} recursively * * @param directory the directory from which all java files should be parsed. */ public void addSourceTree( File directory ) { FileVisitor visitor = new FileVisitor() { public void visitFile( File badFile ) { throw new RuntimeException( "Cannot read file : " + badFile.getName() ); } }; addSourceTree( directory, visitor ); } /** * Add all java files of the {@code directory} recursively * * @param directory the directory from which all java files should be parsed. * @param errorHandler a fileVisitor which will be triggered when an {@link IOException} occurs. */ public void addSourceTree( File directory, final FileVisitor errorHandler ) { DirectoryScanner scanner = new DirectoryScanner( directory ); scanner.addFilter( new SuffixFilter( ".java" ) ); scanner.scan( new FileVisitor() { public void visitFile( File currentFile ) { try { addSource( currentFile ); } catch ( IOException e ) { errorHandler.visitFile( currentFile ); } } } ); } /** * Add the {@link java.lang.ClassLoader} to this JavaProjectBuilder * * @param classLoader the classloader to add */ public void addClassLoader( ClassLoader classLoader ) { classLibraryBuilder.appendClassLoader( classLoader ); } // Java Object Model -getters /** * Try to retrieve a {@link JavaClass} by its name. * * @param name the fully qualified name of the class * @return the matching JavaClass, otherwise null */ public JavaClass getClassByName( String name ) { return classLibraryBuilder.getClassLibrary().getJavaClass( name ); } /** * Get all the sources added. This will only contain the sources added as sourcefile, sourcetree or sourcefolder. * * @return a list of sources * @see #addSource(File) * @see #addSource(Reader) * @see #addSourceFolder(File) * @see #addSourceTree(File) */ public Collection getSources() { return classLibraryBuilder.getClassLibrary().getJavaSources(); } /** * Retrieve all classes which were added by sources * * @return a list of javaclasses, never null * @see #addSource(File) * @see #addSource(Reader) * @see #addSourceFolder(File) * @see #addSourceTree(File) */ public Collection getClasses() { return classLibraryBuilder.getClassLibrary().getJavaClasses(); } /** * Try to retrieve a {@link JavaPackage} by its name. * * @param name the package name * @return the matching JavaPackage, otherwise null */ public JavaPackage getPackageByName( String name ) { return classLibraryBuilder.getClassLibrary().getJavaPackage( name ); } /** * Retrieve all packages which were added by sources. * * @return a list of packages, never null * @see #addSource(File) * @see #addSource(Reader) * @see #addSourceFolder(File) * @see #addSourceTree(File) */ public Collection getPackages() { return classLibraryBuilder.getClassLibrary().getJavaPackages(); } public Collection getModules() { return classLibraryBuilder.getClassLibrary().getJavaModules(); } // Searcher public Collection search( Searcher searcher ) { Collection result = new LinkedList(); Collection classArray = classLibraryBuilder.getClassLibrary().getJavaClasses(); for ( JavaClass cls : classArray ) { if ( searcher.eval( cls ) ) { result.add( cls ); } } return result; } /** * Persist the classLibraryBuilder to a file * * @param file the file to serialize to * @throws IOException Any exception thrown by the underlying OutputStream */ public void save( File file ) throws IOException { FileOutputStream fos = new FileOutputStream( file ); ObjectOutputStream out = new ObjectOutputStream( fos ); try { out.writeObject( classLibraryBuilder ); } finally { out.close(); fos.close(); } } /** * Note that after loading JavaDocBuilder classloaders need to be re-added. * * @param file the file to load * @return the deserialized project builder * @throws IOException when file could not be deserialized */ public static JavaProjectBuilder load( File file ) throws IOException { FileInputStream fis = new FileInputStream( file ); ObjectInputStream in = new ObjectInputStream( fis ); JavaProjectBuilder builder; try { ClassLibraryBuilder libraryBuilder = (ClassLibraryBuilder) in.readObject(); builder = new JavaProjectBuilder( libraryBuilder ); } catch ( ClassNotFoundException e ) { throw new Error( "Couldn't load class : " + e.getMessage() ); } finally { in.close(); fis.close(); } return builder; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/Searcher.java000066400000000000000000000023451325201777200251270ustar00rootroot00000000000000package com.thoughtworks.qdox; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import com.thoughtworks.qdox.model.JavaClass; /** * A filter which evaluates the JavaClass and decides if it's part of the criteria. * * */ public interface Searcher { /** * Evaluate the class * * @param cls the class to evaluate * @return true if this class should be part of the criteria, otherwise false */ boolean eval( JavaClass cls ); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/builder/000077500000000000000000000000001325201777200241525ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/builder/Builder.java000066400000000000000000000050571325201777200264120ustar00rootroot00000000000000package com.thoughtworks.qdox.builder; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.net.URL; import com.thoughtworks.qdox.model.JavaModule; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.parser.expression.ExpressionDef; import com.thoughtworks.qdox.parser.structs.AnnoDef; import com.thoughtworks.qdox.parser.structs.ClassDef; import com.thoughtworks.qdox.parser.structs.FieldDef; import com.thoughtworks.qdox.parser.structs.InitDef; import com.thoughtworks.qdox.parser.structs.MethodDef; import com.thoughtworks.qdox.parser.structs.ModuleDef; import com.thoughtworks.qdox.parser.structs.PackageDef; import com.thoughtworks.qdox.parser.structs.TagDef; import com.thoughtworks.qdox.writer.ModelWriterFactory; public interface Builder { void setModelWriterFactory( ModelWriterFactory writer ); void setUrl( URL url ); void setModule( ModuleDef moduleDef ); void addExports( ModuleDef.ExportsDef exports ); void addRequires( ModuleDef.RequiresDef requires ); void addOpens( ModuleDef.OpensDef opens ); void addProvides( ModuleDef.ProvidesDef provides ); void addUses( ModuleDef.UsesDef uses ); void addPackage( PackageDef packageDef ); void addImport( String importName ); void addJavaDoc( String text ); void addJavaDocTag( TagDef def ); void beginClass( ClassDef def ); void endClass(); void addInitializer( InitDef def ); void beginConstructor(); void endConstructor( MethodDef def ); void beginMethod(); void endMethod( MethodDef def ); void beginField( FieldDef def ); void endField(); void addParameter( FieldDef def ); void addAnnotation( AnnoDef annotation ); void addArgument( ExpressionDef argument ); JavaSource getSource(); JavaModule getModuleInfo(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/builder/ModelBuilderFactory.java000066400000000000000000000026171325201777200307220ustar00rootroot00000000000000package com.thoughtworks.qdox.builder; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.Serializable; import com.thoughtworks.qdox.builder.impl.ModelBuilder; import com.thoughtworks.qdox.library.ClassLibrary; /** * The ModelBuilderFactory for constructing ModelBuilders * * @author Robert Scholte * */ public interface ModelBuilderFactory extends Serializable { /** * Return a new instance of a ModelBuilder. * Parsers will use exactly one instance per java source file or class. * * @param library the classLibrary * @return a new ModelBuilder */ ModelBuilder newInstance( ClassLibrary library ); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/builder/TypeAssembler.java000066400000000000000000000077541325201777200276110ustar00rootroot00000000000000package com.thoughtworks.qdox.builder; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.LinkedList; import java.util.List; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.impl.DefaultJavaParameterizedType; import com.thoughtworks.qdox.model.impl.DefaultJavaWildcardType; import com.thoughtworks.qdox.model.impl.DefaultJavaWildcardType.BoundType; import com.thoughtworks.qdox.model.impl.DefaultJavaType; import com.thoughtworks.qdox.parser.structs.TypeDef; import com.thoughtworks.qdox.parser.structs.WildcardTypeDef; import com.thoughtworks.qdox.type.TypeResolver; /** * An assembler to transform a {@link TypeDef} to a {@link DefaultJavaType} * * @author Robert Scholte * @since 2.0 */ public final class TypeAssembler { private TypeAssembler() { } /** * this one is specific for those cases where dimensions can be part of both the type and identifier i.e. private * String[] matrix[]; //field public abstract String[] getMatrix[](); //method * * @param typeDef the type definition * @param dimensions the array-depth * @param typeResolver the typeResolver * @return the Type */ public static DefaultJavaType createUnresolved( TypeDef typeDef, int dimensions, TypeResolver typeResolver) { DefaultJavaType result; if ( typeDef instanceof WildcardTypeDef ) { WildcardTypeDef wildcard = (WildcardTypeDef) typeDef; if( wildcard.getTypeDef() != null ) { JavaType type = createUnresolved( wildcard.getTypeDef(), typeResolver ); DefaultJavaWildcardType.BoundType boundType = null; if( "extends".equals( wildcard.getWildcardExpressionType() ) ) { boundType = BoundType.EXTENDS; } else if( "super".equals( wildcard.getWildcardExpressionType() ) ) { boundType = BoundType.SUPER; } result = new DefaultJavaWildcardType( type , boundType ); } else { result = new DefaultJavaWildcardType(); } } else { DefaultJavaParameterizedType typeResult = new DefaultJavaParameterizedType( null, typeDef.getName(), typeDef.getDimensions() + dimensions, typeResolver ); if ( typeDef.getActualArgumentTypes() != null && !typeDef.getActualArgumentTypes().isEmpty() ) { List actualArgumentTypes = new LinkedList(); for ( TypeDef actualArgType : typeDef.getActualArgumentTypes() ) { actualArgumentTypes.add( TypeAssembler.createUnresolved( actualArgType, typeResolver ) ); } typeResult.setActualArgumentTypes( actualArgumentTypes ); } result = typeResult; } return result; } /** * @param typeDef the type definition * @param typeResolver the typeResolver * @return the Type */ public static DefaultJavaType createUnresolved( TypeDef typeDef, TypeResolver typeResolver ) { return createUnresolved( typeDef, 0, typeResolver ); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/builder/impl/000077500000000000000000000000001325201777200251135ustar00rootroot00000000000000DefaultJavaAnnotationAssembler.java000066400000000000000000000455551325201777200337740ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/builder/implpackage com.thoughtworks.qdox.builder.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.LinkedList; import java.util.List; import java.util.Map; import com.thoughtworks.qdox.builder.TypeAssembler; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.expression.Add; import com.thoughtworks.qdox.model.expression.And; import com.thoughtworks.qdox.model.expression.AnnotationValue; import com.thoughtworks.qdox.model.expression.AnnotationValueList; import com.thoughtworks.qdox.model.expression.Assignment; import com.thoughtworks.qdox.model.expression.Cast; import com.thoughtworks.qdox.model.expression.Constant; import com.thoughtworks.qdox.model.expression.Divide; import com.thoughtworks.qdox.model.expression.Equals; import com.thoughtworks.qdox.model.expression.ExclusiveOr; import com.thoughtworks.qdox.model.expression.Expression; import com.thoughtworks.qdox.model.expression.FieldRef; import com.thoughtworks.qdox.model.expression.GreaterEquals; import com.thoughtworks.qdox.model.expression.GreaterThan; import com.thoughtworks.qdox.model.expression.LessEquals; import com.thoughtworks.qdox.model.expression.LessThan; import com.thoughtworks.qdox.model.expression.LogicalAnd; import com.thoughtworks.qdox.model.expression.LogicalNot; import com.thoughtworks.qdox.model.expression.LogicalOr; import com.thoughtworks.qdox.model.expression.MinusSign; import com.thoughtworks.qdox.model.expression.Multiply; import com.thoughtworks.qdox.model.expression.Not; import com.thoughtworks.qdox.model.expression.NotEquals; import com.thoughtworks.qdox.model.expression.Or; import com.thoughtworks.qdox.model.expression.ParenExpression; import com.thoughtworks.qdox.model.expression.PlusSign; import com.thoughtworks.qdox.model.expression.PostDecrement; import com.thoughtworks.qdox.model.expression.PostIncrement; import com.thoughtworks.qdox.model.expression.PreDecrement; import com.thoughtworks.qdox.model.expression.PreIncrement; import com.thoughtworks.qdox.model.expression.Query; import com.thoughtworks.qdox.model.expression.Remainder; import com.thoughtworks.qdox.model.expression.ShiftLeft; import com.thoughtworks.qdox.model.expression.ShiftRight; import com.thoughtworks.qdox.model.expression.Subtract; import com.thoughtworks.qdox.model.expression.TypeRef; import com.thoughtworks.qdox.model.expression.UnsignedShiftRight; import com.thoughtworks.qdox.model.impl.DefaultJavaAnnotation; import com.thoughtworks.qdox.parser.expression.AddDef; import com.thoughtworks.qdox.parser.expression.AndDef; import com.thoughtworks.qdox.parser.expression.AssignmentDef; import com.thoughtworks.qdox.parser.expression.CastDef; import com.thoughtworks.qdox.parser.expression.ConstantDef; import com.thoughtworks.qdox.parser.expression.CreatorDef; import com.thoughtworks.qdox.parser.expression.DivideDef; import com.thoughtworks.qdox.parser.expression.ElemValueDef; import com.thoughtworks.qdox.parser.expression.ElemValueListDef; import com.thoughtworks.qdox.parser.expression.ElemValueTransformer; import com.thoughtworks.qdox.parser.expression.EqualsDef; import com.thoughtworks.qdox.parser.expression.ExclusiveOrDef; import com.thoughtworks.qdox.parser.expression.FieldRefDef; import com.thoughtworks.qdox.parser.expression.GreaterEqualsDef; import com.thoughtworks.qdox.parser.expression.GreaterThanDef; import com.thoughtworks.qdox.parser.expression.LessEqualsDef; import com.thoughtworks.qdox.parser.expression.LessThanDef; import com.thoughtworks.qdox.parser.expression.LogicalAndDef; import com.thoughtworks.qdox.parser.expression.LogicalNotDef; import com.thoughtworks.qdox.parser.expression.LogicalOrDef; import com.thoughtworks.qdox.parser.expression.MethodInvocationDef; import com.thoughtworks.qdox.parser.expression.MethodReferenceDef; import com.thoughtworks.qdox.parser.expression.MinusSignDef; import com.thoughtworks.qdox.parser.expression.MultiplyDef; import com.thoughtworks.qdox.parser.expression.NotDef; import com.thoughtworks.qdox.parser.expression.NotEqualsDef; import com.thoughtworks.qdox.parser.expression.OrDef; import com.thoughtworks.qdox.parser.expression.ParenExpressionDef; import com.thoughtworks.qdox.parser.expression.PlusSignDef; import com.thoughtworks.qdox.parser.expression.PostDecrementDef; import com.thoughtworks.qdox.parser.expression.PostIncrementDef; import com.thoughtworks.qdox.parser.expression.PreDecrementDef; import com.thoughtworks.qdox.parser.expression.PreIncrementDef; import com.thoughtworks.qdox.parser.expression.QueryDef; import com.thoughtworks.qdox.parser.expression.RemainderDef; import com.thoughtworks.qdox.parser.expression.ShiftLeftDef; import com.thoughtworks.qdox.parser.expression.ShiftRightDef; import com.thoughtworks.qdox.parser.expression.SubtractDef; import com.thoughtworks.qdox.parser.expression.TypeRefDef; import com.thoughtworks.qdox.parser.expression.UnsignedShiftRightDef; import com.thoughtworks.qdox.parser.structs.AnnoDef; import com.thoughtworks.qdox.parser.structs.TypeDef; import com.thoughtworks.qdox.type.TypeResolver; public class DefaultJavaAnnotationAssembler implements ElemValueTransformer { private JavaClass declaringClass; private ClassLibrary classLibrary; private TypeResolver typeResolver; public DefaultJavaAnnotationAssembler( JavaClass declaringClass, ClassLibrary classLibrary, TypeResolver typeResolver ) { this.declaringClass = declaringClass; this.classLibrary = classLibrary; this.typeResolver = typeResolver; } public DefaultJavaAnnotation assemble( AnnoDef annoDef ) { DefaultJavaAnnotation annotation = new DefaultJavaAnnotation( createType( annoDef.getTypeDef(), 0 ) ); annotation.setLineNumber( annoDef.getLineNumber() ); for ( Map.Entry annoVal : annoDef.getArgs().entrySet() ) { annotation.setProperty( annoVal.getKey(), annoVal.getValue().transform( this ) ); } return annotation; } public Expression assemble( ElemValueDef annoDef ) { return annoDef.transform( this ); } private JavaClass createType( TypeDef typeDef, int dimensions ) { if ( typeDef == null ) { return null; } return TypeAssembler.createUnresolved( typeDef, dimensions, typeResolver ); } /** {@inheritDoc} */ public AnnotationValue transform( AnnoDef annoDef ) { return assemble( annoDef); } /** {@inheritDoc} */ public AnnotationValue transform( ElemValueListDef elemValueListDef ) { List parsedList = new LinkedList(); for ( ElemValueDef val : elemValueListDef.getValueList() ) { parsedList.add( val.transform( this ) ); } return new AnnotationValueList( parsedList ); } /** {@inheritDoc} */ public AnnotationValue transform( AddDef annotationAdd ) { AnnotationValue left = annotationAdd.getLeft().transform( this ); AnnotationValue right = annotationAdd.getRight().transform( this ); return new Add( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( AndDef annotationAnd ) { AnnotationValue left = annotationAnd.getLeft().transform( this ); AnnotationValue right = annotationAnd.getRight().transform( this ); return new And( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( DivideDef annotationDivide ) { AnnotationValue left = annotationDivide.getLeft().transform( this ); AnnotationValue right = annotationDivide.getRight().transform( this ); return new Divide( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( EqualsDef annotationEquals ) { AnnotationValue left = annotationEquals.getLeft().transform( this ); AnnotationValue right = annotationEquals.getRight().transform( this ); return new Equals( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( ExclusiveOrDef annotationExclusiveOr ) { AnnotationValue left = annotationExclusiveOr.getLeft().transform( this ); AnnotationValue right = annotationExclusiveOr.getRight().transform( this ); return new ExclusiveOr( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( GreaterEqualsDef annotationGreaterEquals ) { AnnotationValue left = annotationGreaterEquals.getLeft().transform( this ); AnnotationValue right = annotationGreaterEquals.getRight().transform( this ); return new GreaterEquals( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( GreaterThanDef annotationGreaterThan ) { AnnotationValue left = annotationGreaterThan.getLeft().transform( this ); AnnotationValue right = annotationGreaterThan.getRight().transform( this ); return new GreaterThan( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( LessEqualsDef annotationLessEquals ) { AnnotationValue left = annotationLessEquals.getLeft().transform( this ); AnnotationValue right = annotationLessEquals.getRight().transform( this ); return new LessEquals( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( LessThanDef annotationLessThan ) { AnnotationValue left = annotationLessThan.getLeft().transform( this ); AnnotationValue right = annotationLessThan.getRight().transform( this ); return new LessThan( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( LogicalAndDef annotationLogicalAnd ) { AnnotationValue left = annotationLogicalAnd.getLeft().transform( this ); AnnotationValue right = annotationLogicalAnd.getRight().transform( this ); return new LogicalAnd( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( LogicalOrDef annotationLogicalOr ) { AnnotationValue left = annotationLogicalOr.getLeft().transform( this ); AnnotationValue right = annotationLogicalOr.getRight().transform( this ); return new LogicalOr( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( MultiplyDef annotationMultiply ) { AnnotationValue left = annotationMultiply.getLeft().transform( this ); AnnotationValue right = annotationMultiply.getRight().transform( this ); return new Multiply( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( NotEqualsDef annotationNotEquals ) { AnnotationValue left = annotationNotEquals.getLeft().transform( this ); AnnotationValue right = annotationNotEquals.getRight().transform( this ); return new NotEquals( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( OrDef annotationOr ) { AnnotationValue left = annotationOr.getLeft().transform( this ); AnnotationValue right = annotationOr.getRight().transform( this ); return new Or( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( RemainderDef annotationRemainder ) { AnnotationValue left = annotationRemainder.getLeft().transform( this ); AnnotationValue right = annotationRemainder.getRight().transform( this ); return new Remainder( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( ShiftLeftDef annotationShiftLeft ) { AnnotationValue left = annotationShiftLeft.getLeft().transform( this ); AnnotationValue right = annotationShiftLeft.getRight().transform( this ); return new ShiftLeft( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( ShiftRightDef annotationShiftRight ) { AnnotationValue left = annotationShiftRight.getLeft().transform( this ); AnnotationValue right = annotationShiftRight.getRight().transform( this ); return new ShiftRight( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( SubtractDef annotationSubtract ) { AnnotationValue left = annotationSubtract.getLeft().transform( this ); AnnotationValue right = annotationSubtract.getRight().transform( this ); return new Subtract( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( UnsignedShiftRightDef annotationUnsignedShiftRight ) { AnnotationValue left = annotationUnsignedShiftRight.getLeft().transform( this ); AnnotationValue right = annotationUnsignedShiftRight.getRight().transform( this ); return new UnsignedShiftRight( left, right ); } /** {@inheritDoc} */ public AnnotationValue transform( CastDef annotationCast ) { JavaType type = createType( annotationCast.getTypeDef(), annotationCast.getTypeDef().getDimensions() ); AnnotationValue value = annotationCast.getElemDef().transform( this ); return new Cast( type, value ); } /** {@inheritDoc} */ public AnnotationValue transform( ConstantDef annotationConstant ) { AnnotationValue result; String image = annotationConstant.getValue(); Class type = annotationConstant.getType(); if ( type == Integer.class ) { result = Constant.newIntegerLiteral( image ); } else if ( type == String.class ) { result = Constant.newStringLiteral( image ); } else if ( type == Boolean.class ) { result = Constant.newBooleanLiteral( image ); } else if ( type == Character.class ) { result = Constant.newCharacterLiteral( image ); } else if ( type == Float.class ) { result = Constant.newFloatingPointLiteral( image ); } else { result = null; // unknown?? } return result; } /** {@inheritDoc} */ public AnnotationValue transform( FieldRefDef annotationFieldRef ) { FieldRef result; String name = annotationFieldRef.getName(); result = new FieldRef( name ); result.setDeclaringClass( declaringClass ); result.setClassLibrary( classLibrary ); return result; } /** {@inheritDoc} */ public AnnotationValue transform( LogicalNotDef annotationLogicalNot ) { AnnotationValue value = annotationLogicalNot.getElemValueDef().transform( this ); return new LogicalNot( value ); } /** {@inheritDoc} */ public AnnotationValue transform( MinusSignDef annotationMinusSign ) { AnnotationValue value = annotationMinusSign.getElemValueDef().transform( this ); return new MinusSign( value ); } /** {@inheritDoc} */ public AnnotationValue transform( NotDef annotationNot ) { AnnotationValue value = annotationNot.getElemValueDef().transform( this ); return new Not( value ); } /** {@inheritDoc} */ public AnnotationValue transform( ParenExpressionDef annotationParenExpression ) { AnnotationValue value = annotationParenExpression.getElemValueDef().transform( this ); return new ParenExpression( value ); } /** {@inheritDoc} */ public AnnotationValue transform( PlusSignDef annotationPlusSign ) { AnnotationValue value = annotationPlusSign.getElemValueDef().transform( this ); return new PlusSign( value ); } /** {@inheritDoc} */ public AnnotationValue transform( QueryDef annotationQuery ) { AnnotationValue condition = annotationQuery.getCondition().transform( this ); AnnotationValue trueExpression = annotationQuery.getTrueExpression().transform( this ); AnnotationValue falseExpression = annotationQuery.getFalseExpression().transform( this ); return new Query( condition, trueExpression, falseExpression ); } /** {@inheritDoc} */ public AnnotationValue transform( TypeRefDef annotationTypeRef ) { JavaType type = createType( annotationTypeRef.getTypeDef(), annotationTypeRef.getTypeDef().getDimensions() ); return new TypeRef( type ); } public AnnotationValue transform( AssignmentDef assignmentDef ) { Expression leftHandSide = assignmentDef.getLetfHandSide().transform( this ); String operator = assignmentDef.getOperator(); Expression assignmentExpression = assignmentDef.getAssignmentExpression().transform( this ); return new Assignment( leftHandSide, operator, assignmentExpression ); } public AnnotationValue transform( PreIncrementDef preIncrementDef ) { return new PreIncrement( preIncrementDef.getElemValueDef().transform( this ) ); } public AnnotationValue transform( PreDecrementDef preDecrementDef ) { return new PreDecrement( preDecrementDef.getElemValueDef().transform( this ) ); } public AnnotationValue transform( PostIncrementDef postIncrement ) { return new PostIncrement( postIncrement.getElemValueDef().transform( this ) ); } public AnnotationValue transform( PostDecrementDef postDecrementDef ) { return new PostDecrement( postDecrementDef.getElemValueDef().transform( this ) ); } public AnnotationValue transform( MethodInvocationDef methodInvocationDef ) { return null; } public AnnotationValue transform( MethodReferenceDef methodReferenceDef ) { return null; } public AnnotationValue transform( CreatorDef newCreator ) { return null; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/builder/impl/EvaluatingVisitor.java000066400000000000000000000775001325201777200314460ustar00rootroot00000000000000package com.thoughtworks.qdox.builder.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.Collections; import java.util.LinkedList; import java.util.List; import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.expression.Add; import com.thoughtworks.qdox.model.expression.And; import com.thoughtworks.qdox.model.expression.AnnotationValue; import com.thoughtworks.qdox.model.expression.AnnotationValueList; import com.thoughtworks.qdox.model.expression.Assignment; import com.thoughtworks.qdox.model.expression.Cast; import com.thoughtworks.qdox.model.expression.Constant; import com.thoughtworks.qdox.model.expression.Divide; import com.thoughtworks.qdox.model.expression.Equals; import com.thoughtworks.qdox.model.expression.ExclusiveOr; import com.thoughtworks.qdox.model.expression.ExpressionVisitor; import com.thoughtworks.qdox.model.expression.FieldRef; import com.thoughtworks.qdox.model.expression.GreaterEquals; import com.thoughtworks.qdox.model.expression.GreaterThan; import com.thoughtworks.qdox.model.expression.LessEquals; import com.thoughtworks.qdox.model.expression.LessThan; import com.thoughtworks.qdox.model.expression.LogicalAnd; import com.thoughtworks.qdox.model.expression.LogicalNot; import com.thoughtworks.qdox.model.expression.LogicalOr; import com.thoughtworks.qdox.model.expression.MethodInvocation; import com.thoughtworks.qdox.model.expression.MinusSign; import com.thoughtworks.qdox.model.expression.Multiply; import com.thoughtworks.qdox.model.expression.Not; import com.thoughtworks.qdox.model.expression.NotEquals; import com.thoughtworks.qdox.model.expression.Or; import com.thoughtworks.qdox.model.expression.ParenExpression; import com.thoughtworks.qdox.model.expression.PlusSign; import com.thoughtworks.qdox.model.expression.PostDecrement; import com.thoughtworks.qdox.model.expression.PostIncrement; import com.thoughtworks.qdox.model.expression.PreDecrement; import com.thoughtworks.qdox.model.expression.PreIncrement; import com.thoughtworks.qdox.model.expression.Query; import com.thoughtworks.qdox.model.expression.Remainder; import com.thoughtworks.qdox.model.expression.ShiftLeft; import com.thoughtworks.qdox.model.expression.ShiftRight; import com.thoughtworks.qdox.model.expression.Subtract; import com.thoughtworks.qdox.model.expression.TypeRef; import com.thoughtworks.qdox.model.expression.UnsignedShiftRight; /** * Visitor that evaluates annotation expressions. *

* Users of this class must override {@link EvaluatingVisitor#getFieldReferenceValue(JavaField)} to return values for * referenced fields. * * @author Jochen Kuhnle */ public class EvaluatingVisitor implements ExpressionVisitor { public Object getValue( JavaAnnotation annotation, String property ) { Object result = null; AnnotationValue value = annotation.getProperty( property ); if ( value != null ) { result = value.accept( this ); } return result; } public List getListValue( JavaAnnotation annotation, String property ) { Object value = getValue( annotation, property ); List list = null; if ( value != null ) { if ( value instanceof List ) { list = (List) value; } else { list = Collections.singletonList( value ); } } return list; } /** * Return the result type of a binary operator *

* Performs binary numeric promotion as specified in the Java Language Specification, * * @param left the left hand side instance * @param right the right hand side instance * @return the expected result Class * @see section 5.6.1 */ protected static Class resultType( final Object left, final Object right ) { Class type = void.class; if ( left instanceof String || right instanceof String ) { type = String.class; } else if ( left instanceof Number && right instanceof Number ) { if ( left instanceof Double || right instanceof Double ) { type = Double.class; } else if ( left instanceof Float || right instanceof Float ) { type = Float.class; } else if ( left instanceof Long || right instanceof Long ) { type = Long.class; } else { type = Integer.class; } } return type; } /** * Return the numeric result type of a binary operator *

* Performs binary numeric promotion as specified in the Java Language Specification, * * @param left the left hand side instance * @param right the right hand side instance * @return the expected result Class * @see section 5.6.1 */ protected static Class numericResultType( final Object left, final Object right ) { Class type = void.class; if ( left instanceof Number && right instanceof Number ) { if ( left instanceof Long || right instanceof Long ) { type = Long.class; } else if ( left instanceof Integer || right instanceof Integer ) { type = Integer.class; } } return type; } /** * Return the result type of an unary operator *

* Performs unary numeric promotion as specified in the Java Language Specification, * * @param value the instance * @return the expected result Class * @see section 5.6.2 */ protected static Class unaryNumericResultType( final Object value ) { Class type = void.class; if ( value instanceof Byte || value instanceof Short || value instanceof Character || value instanceof Integer ) { type = Integer.class; } else if ( value instanceof Long ) { type = Long.class; } return type; } protected static Class unaryResultType( final Object value ) { Class type = unaryNumericResultType( value ); if ( type == void.class ) { if ( value instanceof Float ) { type = Float.class; } else if ( value instanceof Double ) { type = Double.class; } } return type; } /** {@inheritDoc} */ public Object visit( JavaAnnotation annotation ) throws UnsupportedOperationException { throw new UnsupportedOperationException( "Illegal annotation value '" + annotation + "'." ); } /** {@inheritDoc} */ public Object visit( Add op ) { Object left = op.getLeft().accept( this ); Object right = op.getRight().accept( this ); Class type = resultType( left, right ); Object result; if ( type == String.class ) { result = left.toString() + right.toString(); } else if ( type == Double.class ) { result = Double.valueOf( ( (Number) left ).doubleValue() + ( (Number) right ).doubleValue() ); } else if ( type == Float.class ) { result = Float.valueOf( ( (Number) left ).floatValue() + ( (Number) right ).floatValue() ); } else if ( type == Long.class ) { result = Long.valueOf( ( (Number) left ).longValue() + ( (Number) right ).longValue() ); } else if ( type == Integer.class ) { result = Integer.valueOf( ( (Number) left ).intValue() + ( (Number) right ).intValue() ); } else { throw new IllegalArgumentException( "Cannot evaluate '" + op + "'." ); } return result; } /** {@inheritDoc} */ public Object visit( Constant constant ) { return constant.getValue(); } /** {@inheritDoc} */ public Object visit( Divide op ) { Object left = op.getLeft().accept( this ); Object right = op.getRight().accept( this ); Class type = resultType( left, right ); Object result; if ( type == Double.class ) { result = Double.valueOf( ( (Number) left ).doubleValue() / ( (Number) right ).doubleValue() ); } else if ( type == Float.class ) { result = Float.valueOf( ( (Number) left ).floatValue() / ( (Number) right ).floatValue() ); } else if ( type == Long.class ) { result = Long.valueOf( ( (Number) left ).longValue() / ( (Number) right ).longValue() ); } else if ( type == Integer.class ) { result = Integer.valueOf( ( (Number) left ).intValue() / ( (Number) right ).intValue() ); } else { throw new IllegalArgumentException( "Cannot evaluate '" + op + "'." ); } return result; } /** {@inheritDoc} */ public Object visit( FieldRef fieldRef ) { JavaField javaField = fieldRef.getField(); if ( javaField == null ) { throw new IllegalArgumentException( "Cannot resolve field reference '" + fieldRef + "'." ); } if ( !(javaField.isFinal() && javaField.isStatic() ) ) { throw new IllegalArgumentException( "Field reference '" + fieldRef + "' must be static and final." ); } return getFieldReferenceValue( javaField ); } protected Object getFieldReferenceValue( JavaField javaField ) { throw new UnsupportedOperationException("getFieldReferenceValue(JavaField) has not been implemented."); } /** {@inheritDoc} */ public Object visit( GreaterThan op ) { Object left = op.getLeft().accept( this ); Object right = op.getRight().accept( this ); Class type = resultType( left, right ); boolean result; if ( type == Double.class ) { result = ( (Number) left ).doubleValue() > ( (Number) right ).doubleValue(); } else if ( type == Float.class ) { result = ( (Number) left ).floatValue() > ( (Number) right ).floatValue(); } else if ( type == Long.class ) { result = ( (Number) left ).longValue() > ( (Number) right ).longValue(); } else if ( type == Integer.class ) { result = ( (Number) left ).intValue() > ( (Number) right ).intValue(); } else { throw new IllegalArgumentException( "Cannot evaluate '" + op + "'." ); } return result ? Boolean.TRUE : Boolean.FALSE; } /** {@inheritDoc} */ public Object visit( LessThan op ) { Object left = op.getLeft().accept( this ); Object right = op.getRight().accept( this ); Class type = resultType( left, right ); boolean result; if ( type == Double.class ) { result = ( (Number) left ).doubleValue() < ( (Number) right ).doubleValue(); } else if ( type == Float.class ) { result = ( (Number) left ).floatValue() < ( (Number) right ).floatValue(); } else if ( type == Long.class ) { result = ( (Number) left ).longValue() < ( (Number) right ).longValue(); } else if ( type == Integer.class ) { result = ( (Number) left ).intValue() < ( (Number) right ).intValue(); } else { throw new IllegalArgumentException( "Cannot evaluate '" + op + "'." ); } return result ? Boolean.TRUE : Boolean.FALSE; } /** {@inheritDoc} */ public Object visit( Multiply op ) { Object left = op.getLeft().accept( this ); Object right = op.getRight().accept( this ); Class type = resultType( left, right ); Object result; if ( type == Double.class ) { result = Double.valueOf( ( (Number) left ).doubleValue() * ( (Number) right ).doubleValue() ); } else if ( type == Float.class ) { result = Float.valueOf( ( (Number) left ).floatValue() * ( (Number) right ).floatValue() ); } else if ( type == Long.class ) { result = Long.valueOf( ( (Number) left ).longValue() * ( (Number) right ).longValue() ); } else if ( type == Integer.class ) { result = Integer.valueOf( ( (Number) left ).intValue() * ( (Number) right ).intValue() ); } else { throw new IllegalArgumentException( "Cannot evaluate '" + op + "'." ); } return result; } /** {@inheritDoc} */ public Object visit( ParenExpression parenExpression ) { return parenExpression.getValue().accept( this ); } /** {@inheritDoc} */ public Object visit( Subtract op ) { Object left = op.getLeft().accept( this ); Object right = op.getRight().accept( this ); Class type = resultType( left, right ); Object result; if ( type == Double.class ) { result = Double.valueOf( ( (Number) left ).doubleValue() - ( (Number) right ).doubleValue() ); } else if ( type == Float.class ) { result = Float.valueOf( ( (Number) left ).floatValue() - ( (Number) right ).floatValue() ); } else if ( type == Long.class ) { result = Long.valueOf( ( (Number) left ).longValue() - ( (Number) right ).longValue() ); } else if ( type == Integer.class ) { result = Integer.valueOf( ( (Number) left ).intValue() - ( (Number) right ).intValue() ); } else { throw new IllegalArgumentException( "Cannot evaluate '" + op + "'." ); } return result; } /** {@inheritDoc} */ public JavaType visit( TypeRef typeRef ) { return typeRef.getType(); } /** {@inheritDoc} */ public List visit( AnnotationValueList valueList ) { List list = new LinkedList(); for ( AnnotationValue value : valueList.getValueList() ) { Object v = value.accept( this ); list.add( v ); } return list; } /** {@inheritDoc} */ public Object visit( And and ) { Object left = and.getLeft().accept( this ); Object right = and.getRight().accept( this ); Class type = numericResultType( left, right ); Object result; if ( type == Long.class ) { result = Long.valueOf( ( (Number) left ).longValue() & ( (Number) right ).longValue() ); } else if ( type == Integer.class ) { result = Integer.valueOf( ( (Number) left ).intValue() & ( (Number) right ).intValue() ); } else { throw new IllegalArgumentException( "Cannot evaluate '" + and + "'." ); } return result; } /** {@inheritDoc} */ public Object visit( GreaterEquals greaterEquals ) { Object left = greaterEquals.getLeft().accept( this ); Object right = greaterEquals.getRight().accept( this ); Class type = resultType( left, right ); boolean result; if ( type == Double.class ) { result = ( (Number) left ).doubleValue() >= ( (Number) right ).doubleValue(); } else if ( type == Float.class ) { result = ( (Number) left ).floatValue() >= ( (Number) right ).floatValue(); } else if ( type == Long.class ) { result = ( (Number) left ).longValue() >= ( (Number) right ).longValue(); } else if ( type == Integer.class ) { result = ( (Number) left ).intValue() >= ( (Number) right ).intValue(); } else { throw new IllegalArgumentException( "Cannot evaluate '" + greaterEquals + "'." ); } return result ? Boolean.TRUE : Boolean.FALSE; } /** {@inheritDoc} */ public Object visit( LessEquals lessEquals ) { Object left = lessEquals.getLeft().accept( this ); Object right = lessEquals.getRight().accept( this ); Class type = resultType( left, right ); boolean result; if ( type == Double.class ) { result = ( (Number) left ).doubleValue() <= ( (Number) right ).doubleValue(); } else if ( type == Float.class ) { result = ( (Number) left ).floatValue() <= ( (Number) right ).floatValue(); } else if ( type == Long.class ) { result = ( (Number) left ).longValue() <= ( (Number) right ).longValue(); } else if ( type == Integer.class ) { result = ( (Number) left ).intValue() <= ( (Number) right ).intValue(); } else { throw new IllegalArgumentException( "Cannot evaluate '" + lessEquals + "'." ); } return result ? Boolean.TRUE : Boolean.FALSE; } /** {@inheritDoc} */ public Object visit( LogicalAnd and ) { Object left = and.getLeft().accept( this ); Object right = and.getRight().accept( this ); boolean result; if ( left instanceof Boolean && right instanceof Boolean ) { result = ( (Boolean) left ).booleanValue() && ( (Boolean) right ).booleanValue(); } else { throw new IllegalArgumentException( "Cannot evaluate '" + and + "'." ); } return result ? Boolean.TRUE : Boolean.FALSE; } /** {@inheritDoc} */ public Object visit( LogicalNot not ) { Object value = not.getValue().accept( this ); boolean result; if ( value instanceof Boolean ) { result = !( (Boolean) value ).booleanValue(); } else { throw new IllegalArgumentException( "Cannot evaluate '" + not + "'." ); } return result ? Boolean.TRUE : Boolean.FALSE; } /** {@inheritDoc} */ public Object visit( LogicalOr or ) { Object left = or.getLeft().accept( this ); Object right = or.getRight().accept( this ); boolean result; if ( left instanceof Boolean && right instanceof Boolean ) { result = ( (Boolean) left ).booleanValue() || ( (Boolean) right ).booleanValue(); } else { throw new IllegalArgumentException( "Cannot evaluate '" + or + "'." ); } return result ? Boolean.TRUE : Boolean.FALSE; } /** {@inheritDoc} */ public Object visit( MinusSign sign ) { Object value = sign.getValue().accept( this ); Class type = unaryResultType( value ); Object result; if ( type == Integer.class ) { result = Integer.valueOf( -( (Integer) value ).intValue() ); } else if ( type == Long.class ) { result = Long.valueOf( -( (Long) value ).longValue() ); } else if ( type == Float.class ) { result = Float.valueOf( -( (Float) value ).floatValue() ); } else if ( type == Double.class ) { result = Double.valueOf( -( (Double) value ).intValue() ); } else { throw new IllegalArgumentException( "Cannot evaluate '" + sign + "'." ); } return result; } /** {@inheritDoc} */ public Object visit( Not not ) { Object value = not.getValue().accept( this ); Object type = unaryNumericResultType( value ); Object result; if ( type == Long.class ) { result = Long.valueOf( ~( (Long) value ).longValue() ); } else if ( type == Integer.class ) { result = Integer.valueOf( ~( (Integer) value ).intValue() ); } else { throw new IllegalArgumentException( "Cannot evaluate '" + not + "'." ); } return result; } /** {@inheritDoc} */ public Object visit( Or or ) { Object left = or.getLeft().accept( this ); Object right = or.getRight().accept( this ); Class type = numericResultType( left, right ); Object result; if ( type == Long.class ) { result = Long.valueOf( ( (Number) left ).longValue() | ( (Number) right ).longValue() ); } else if ( type == Integer.class ) { result = Integer.valueOf( ( (Number) left ).intValue() | ( (Number) right ).intValue() ); } else { throw new IllegalArgumentException( "Cannot evaluate '" + or + "'." ); } return result; } /** {@inheritDoc} */ public Object visit( PlusSign sign ) { Object value = sign.getValue().accept( this ); Object result; if ( value instanceof Number ) { result = value; } else { throw new IllegalArgumentException( "Cannot evaluate '" + sign + "'." ); } return result; } /** {@inheritDoc} */ public Object visit( Remainder remainder ) { Object left = remainder.getLeft().accept( this ); Object right = remainder.getRight().accept( this ); Class type = resultType( left, right ); Object result; if ( type == Double.class ) { result = Double.valueOf( ( (Number) left ).doubleValue() % ( (Number) right ).doubleValue() ); } else if ( type == Float.class ) { result = Float.valueOf( ( (Number) left ).floatValue() % ( (Number) right ).floatValue() ); } else if ( type == Long.class ) { result = Long.valueOf( ( (Number) left ).longValue() % ( (Number) right ).longValue() ); } else if ( type == Integer.class ) { result = Integer.valueOf( ( (Number) left ).intValue() % ( (Number) right ).intValue() ); } else { throw new IllegalArgumentException( "Cannot evaluate '" + remainder + "'." ); } return result; } /** {@inheritDoc} */ public Object visit( ShiftLeft shiftLeft ) { Object left = shiftLeft.getLeft().accept( this ); Object right = shiftLeft.getRight().accept( this ); Class type = numericResultType( left, right ); Object result; if ( type == Long.class ) { result = Long.valueOf( ( (Number) left ).longValue() << ( (Number) right ).longValue() ); } else if ( type == Integer.class ) { result = Integer.valueOf( ( (Number) left ).intValue() << ( (Number) right ).intValue() ); } else { throw new IllegalArgumentException( "Cannot evaluate '" + shiftLeft + "'." ); } return result; } /** {@inheritDoc} */ public Object visit( ShiftRight shiftRight ) { Object left = shiftRight.getLeft().accept( this ); Object right = shiftRight.getRight().accept( this ); Class type = numericResultType( left, right ); Object result; if ( type == Long.class ) { result = Long.valueOf( ( (Number) left ).longValue() >> ( (Number) right ).longValue() ); } else if ( type == Integer.class ) { result = Integer.valueOf( ( (Number) left ).intValue() >> ( (Number) right ).intValue() ); } else { throw new IllegalArgumentException( "Cannot evaluate '" + shiftRight + "'." ); } return result; } /** {@inheritDoc} */ public Object visit( UnsignedShiftRight shiftRight ) { Object left = shiftRight.getLeft().accept( this ); Object right = shiftRight.getRight().accept( this ); Class type = numericResultType( left, right ); Object result; if ( type == Long.class ) { result = Long.valueOf( ( (Number) left ).longValue() >>> ( (Number) right ).longValue() ); } else if ( type == Integer.class ) { result = Integer.valueOf( ( (Number) left ).intValue() >>> ( (Number) right ).intValue() ); } else { throw new IllegalArgumentException( "Cannot evaluate '" + shiftRight + "'." ); } return result; } /** {@inheritDoc} */ public Object visit( Equals annotationEquals ) { Object left = annotationEquals.getLeft().accept( this ); Object right = annotationEquals.getRight().accept( this ); Class type = resultType( left, right ); boolean result; if ( type == Double.class ) { result = ( (Number) left ).doubleValue() == ( (Number) right ).doubleValue(); } else if ( type == Float.class ) { result = ( (Number) left ).floatValue() == ( (Number) right ).floatValue(); } else if ( type == Long.class ) { result = ( (Number) left ).longValue() == ( (Number) right ).longValue(); } else if ( type == Integer.class ) { result = ( (Number) left ).intValue() == ( (Number) right ).intValue(); } else { result = ( left == right ); } return result ? Boolean.TRUE : Boolean.FALSE; } /** {@inheritDoc} */ public Object visit( ExclusiveOr annotationExclusiveOr ) { Object left = annotationExclusiveOr.getLeft().accept( this ); Object right = annotationExclusiveOr.getRight().accept( this ); Class type = numericResultType( left, right ); Object result; if ( type == Long.class ) { result = Long.valueOf( ( (Number) left ).longValue() ^ ( (Number) right ).longValue() ); } else if ( type == Integer.class ) { result = Integer.valueOf( ( (Number) left ).intValue() ^ ( (Number) right ).intValue() ); } else { throw new IllegalArgumentException( "Cannot evaluate '" + annotationExclusiveOr + "'." ); } return result; } /** {@inheritDoc} */ public Object visit( NotEquals annotationNotEquals ) { Object left = annotationNotEquals.getLeft().accept( this ); Object right = annotationNotEquals.getRight().accept( this ); Class type = resultType( left, right ); boolean result; if ( type == Double.class ) { result = ( (Number) left ).doubleValue() != ( (Number) right ).doubleValue(); } else if ( type == Float.class ) { result = ( (Number) left ).floatValue() != ( (Number) right ).floatValue(); } else if ( type == Long.class ) { result = ( (Number) left ).longValue() != ( (Number) right ).longValue(); } else if ( type == Integer.class ) { result = ( (Number) left ).intValue() != ( (Number) right ).intValue(); } else { result = ( left != right ); } return result ? Boolean.TRUE : Boolean.FALSE; } /** {@inheritDoc} */ public Object visit( Query annotationQuery ) { Object value = annotationQuery.getCondition().accept( this ); if ( !( value instanceof Boolean ) ) { throw new IllegalArgumentException( "Cannot evaluate '" + annotationQuery + "'." ); } AnnotationValue expression = ( (Boolean) value ).booleanValue() ? annotationQuery.getTrueExpression() : annotationQuery.getFalseExpression(); return expression.accept( this ); } /** {@inheritDoc} */ public Object visit( Cast annotationCast ) { Object value = annotationCast.getValue().accept( this ); JavaType type = annotationCast.getType(); Object result; if ( type instanceof JavaClass && ( (JavaClass) type ).isPrimitive() && value instanceof Number ) { Number n = (Number) value; String typeName = type.getFullyQualifiedName(); if ( typeName.equals( "byte" ) ) { result = Byte.valueOf( n.byteValue() ); } else if ( typeName.equals( "char" ) ) { result = Character.valueOf( (char) n.intValue() ); } else if ( typeName.equals( "short" ) ) { result = Short.valueOf( n.shortValue() ); } else if ( typeName.equals( "int" ) ) { result = Integer.valueOf( n.intValue() ); } else if ( typeName.equals( "long" ) ) { result = Long.valueOf( n.longValue() ); } else if ( typeName.equals( "float" ) ) { result = Float.valueOf( n.floatValue() ); } else if ( typeName.equals( "double" ) ) { result = Double.valueOf( n.doubleValue() ); } else { throw new IllegalArgumentException( "Cannot evaluate '" + annotationCast + "'." ); } } else { try { result = Class.forName( type.getFullyQualifiedName() ).cast( value ); } catch ( ClassNotFoundException e ) { throw new IllegalArgumentException( "Cannot evaluate '" + annotationCast + "'." ); } } return result; } /** {@inheritDoc} */ public Object visit( PreDecrement preDecrement ) { throw new IllegalArgumentException( "Cannot evaluate '" + preDecrement + "'." ); } /** {@inheritDoc} */ public Object visit( PreIncrement preIncrement ) { throw new IllegalArgumentException( "Cannot evaluate '" + preIncrement + "'." ); } /** {@inheritDoc} */ public Object visit( PostDecrement postDecrement ) { throw new IllegalArgumentException( "Cannot evaluate '" + postDecrement + "'." ); } /** {@inheritDoc} */ public Object visit( PostIncrement postIncrement ) { throw new IllegalArgumentException( "Cannot evaluate '" + postIncrement + "'." ); } /** {@inheritDoc} */ public Object visit( Assignment assignment ) { throw new IllegalArgumentException( "Cannot evaluate '" + assignment + "'." ); } /** {@inheritDoc} */ public Object visit( MethodInvocation methodInvocation ) { throw new IllegalArgumentException( "Cannot evaluate '" + methodInvocation + "'." ); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/builder/impl/ModelBuilder.java000066400000000000000000000566501325201777200303410ustar00rootroot00000000000000package com.thoughtworks.qdox.builder.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.net.URL; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Set; import com.thoughtworks.qdox.builder.Builder; import com.thoughtworks.qdox.builder.TypeAssembler; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.DocletTagFactory; import com.thoughtworks.qdox.model.JavaAnnotatedElement; import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaConstructor; import com.thoughtworks.qdox.model.JavaExecutable; import com.thoughtworks.qdox.model.JavaGenericDeclaration; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaModule; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.JavaTypeVariable; import com.thoughtworks.qdox.model.expression.Expression; import com.thoughtworks.qdox.model.impl.AbstractBaseJavaEntity; import com.thoughtworks.qdox.model.impl.DefaultJavaClass; import com.thoughtworks.qdox.model.impl.DefaultJavaConstructor; import com.thoughtworks.qdox.model.impl.DefaultJavaField; import com.thoughtworks.qdox.model.impl.DefaultJavaInitializer; import com.thoughtworks.qdox.model.impl.DefaultJavaMethod; import com.thoughtworks.qdox.model.impl.DefaultJavaModule; import com.thoughtworks.qdox.model.impl.DefaultJavaModuleDescriptor; import com.thoughtworks.qdox.model.impl.DefaultJavaModuleDescriptor.DefaultJavaExports; import com.thoughtworks.qdox.model.impl.DefaultJavaModuleDescriptor.DefaultJavaOpens; import com.thoughtworks.qdox.model.impl.DefaultJavaModuleDescriptor.DefaultJavaProvides; import com.thoughtworks.qdox.model.impl.DefaultJavaModuleDescriptor.DefaultJavaRequires; import com.thoughtworks.qdox.model.impl.DefaultJavaModuleDescriptor.DefaultJavaUses; import com.thoughtworks.qdox.model.impl.DefaultJavaPackage; import com.thoughtworks.qdox.model.impl.DefaultJavaParameter; import com.thoughtworks.qdox.model.impl.DefaultJavaSource; import com.thoughtworks.qdox.model.impl.DefaultJavaType; import com.thoughtworks.qdox.model.impl.DefaultJavaTypeVariable; import com.thoughtworks.qdox.parser.expression.ExpressionDef; import com.thoughtworks.qdox.parser.structs.AnnoDef; import com.thoughtworks.qdox.parser.structs.ClassDef; import com.thoughtworks.qdox.parser.structs.FieldDef; import com.thoughtworks.qdox.parser.structs.InitDef; import com.thoughtworks.qdox.parser.structs.MethodDef; import com.thoughtworks.qdox.parser.structs.ModuleDef; import com.thoughtworks.qdox.parser.structs.ModuleDef.ExportsDef; import com.thoughtworks.qdox.parser.structs.ModuleDef.OpensDef; import com.thoughtworks.qdox.parser.structs.ModuleDef.ProvidesDef; import com.thoughtworks.qdox.parser.structs.ModuleDef.RequiresDef; import com.thoughtworks.qdox.parser.structs.ModuleDef.UsesDef; import com.thoughtworks.qdox.parser.structs.PackageDef; import com.thoughtworks.qdox.parser.structs.TagDef; import com.thoughtworks.qdox.parser.structs.TypeDef; import com.thoughtworks.qdox.parser.structs.TypeVariableDef; import com.thoughtworks.qdox.type.TypeResolver; import com.thoughtworks.qdox.writer.ModelWriterFactory; /** * @author Joe Walnes * @author Robert Scholte */ public class ModelBuilder implements Builder { private final DefaultJavaSource source; private DefaultJavaModule module; private DefaultJavaModuleDescriptor moduleDescriptor; private LinkedList classStack = new LinkedList(); private List parameterList = new LinkedList(); private DefaultJavaConstructor currentConstructor; private DefaultJavaMethod currentMethod; private DefaultJavaField currentField; private List currentAnnoDefs; private List currentArguments; private String lastComment; private List lastTagSet = new LinkedList(); private ClassLibrary classLibrary; private DocletTagFactory docletTagFactory; private ModelWriterFactory modelWriterFactory; public ModelBuilder( ClassLibrary classLibrary, DocletTagFactory docletTagFactory ) { this.classLibrary = classLibrary; this.docletTagFactory = docletTagFactory; this.source = new DefaultJavaSource( classLibrary ); this.currentAnnoDefs = new LinkedList(); this.currentArguments = new LinkedList(); } /** {@inheritDoc} */ public void setModelWriterFactory( ModelWriterFactory modelWriterFactory ) { this.modelWriterFactory = modelWriterFactory; source.setModelWriterFactory( modelWriterFactory ); } /** {@inheritDoc} */ public void setModule( final ModuleDef moduleDef ) { this.moduleDescriptor = new DefaultJavaModuleDescriptor(moduleDef.getName()); this.module = new DefaultJavaModule(moduleDef.getName(), moduleDescriptor); } /** {@inheritDoc} */ public void addExports( ExportsDef exportsDef ) { // for now use anonymous modules List targets = new ArrayList(exportsDef.getTargets().size()); for ( String moduleName : exportsDef.getTargets() ) { targets.add( new DefaultJavaModule( moduleName, null ) ); } DefaultJavaExports exports = new DefaultJavaExports( new DefaultJavaPackage(exportsDef.getSource()), targets ); exports.setLineNumber( exportsDef.getLineNumber() ); exports.setModelWriterFactory( modelWriterFactory ); moduleDescriptor.addExports( exports ); } /** {@inheritDoc} */ public void addOpens( OpensDef opensDef ) { // for now use anonymous modules List targets = new ArrayList(opensDef.getTargets().size()); for ( String moduleName : opensDef.getTargets() ) { targets.add( new DefaultJavaModule( moduleName, null ) ); } DefaultJavaOpens exports = new DefaultJavaOpens( new DefaultJavaPackage(opensDef.getSource()), targets ); exports.setLineNumber( opensDef.getLineNumber() ); exports.setModelWriterFactory( modelWriterFactory ); moduleDescriptor.addOpens( exports ); } /** {@inheritDoc} */ public void addProvides( ProvidesDef providesDef ) { JavaClass service = createType( providesDef.getService(), 0 ); List implementations = new LinkedList(); for ( TypeDef implementType : providesDef.getImplementations() ) { implementations.add( createType( implementType, 0 ) ); } DefaultJavaProvides provides = new DefaultJavaProvides( service, implementations ); provides.setLineNumber( providesDef.getLineNumber() ); provides.setModelWriterFactory( modelWriterFactory ); moduleDescriptor.addProvides( provides ); } /** {@inheritDoc} */ public void addRequires( RequiresDef requiresDef ) { JavaModule module = new DefaultJavaModule( requiresDef.getName(), null ); DefaultJavaRequires requires = new DefaultJavaRequires( module, requiresDef.getModifiers() ); requires.setLineNumber( requiresDef.getLineNumber() ); requires.setModelWriterFactory( modelWriterFactory ); moduleDescriptor.addRequires( requires ); } /** {@inheritDoc} */ public void addUses( UsesDef usesDef ) { DefaultJavaUses uses = new DefaultJavaUses( createType( usesDef.getService(), 0 ) ); uses.setLineNumber( usesDef.getLineNumber() ); uses.setModelWriterFactory( modelWriterFactory ); moduleDescriptor.addUses( uses ); } /** {@inheritDoc} */ public void addPackage( PackageDef packageDef ) { DefaultJavaPackage jPackage = new DefaultJavaPackage( packageDef.getName() ); jPackage.setClassLibrary( classLibrary ); jPackage.setLineNumber( packageDef.getLineNumber() ); jPackage.setModelWriterFactory( modelWriterFactory ); addJavaDoc( jPackage ); setAnnotations( jPackage ); source.setPackage( jPackage ); } /** {@inheritDoc} */ public void addImport( String importName ) { source.addImport( importName ); } /** {@inheritDoc} */ public void addJavaDoc( String text ) { lastComment = text; } /** {@inheritDoc} */ public void addJavaDocTag( TagDef tagDef ) { lastTagSet.add( tagDef ); } /** {@inheritDoc} */ public void beginClass(ClassDef def) { DefaultJavaClass newClass = new DefaultJavaClass( source ); newClass.setLineNumber( def.getLineNumber() ); newClass.setModelWriterFactory( modelWriterFactory ); // basic details newClass.setName( def.getName() ); newClass.setInterface( ClassDef.INTERFACE.equals( def.getType() ) ); newClass.setEnum( ClassDef.ENUM.equals( def.getType() ) ); newClass.setAnnotation( ClassDef.ANNOTATION_TYPE.equals( def.getType() ) ); // superclass if ( newClass.isInterface() ) { newClass.setSuperClass( null ); } else if ( !newClass.isEnum() ) { newClass.setSuperClass( def.getExtends().size() > 0 ? createType( def.getExtends().iterator().next(), 0 ) : null ); } // implements Set implementSet = newClass.isInterface() ? def.getExtends() : def.getImplements(); List implementz = new LinkedList(); for ( TypeDef implementType : implementSet ) { implementz.add( createType( implementType, 0 ) ); } newClass.setImplementz( implementz ); // modifiers newClass.setModifiers( new LinkedList( def.getModifiers() ) ); // typeParameters if ( def.getTypeParameters() != null ) { List> typeParams = new LinkedList>(); for ( TypeVariableDef typeVariableDef : def.getTypeParameters() ) { typeParams.add( createTypeVariable( typeVariableDef, (JavaClass) newClass ) ); } newClass.setTypeParameters( typeParams ); } // javadoc addJavaDoc( newClass ); // // ignore annotation types (for now) // if (ClassDef.ANNOTATION_TYPE.equals(def.type)) { // System.out.println( currentClass.getFullyQualifiedName() ); // return; // } // annotations setAnnotations( newClass ); classStack.addFirst( bindClass( newClass ) ); } protected DefaultJavaClass bindClass( DefaultJavaClass newClass ) { if ( currentField != null ) { classStack.getFirst().addClass( newClass ); currentField.setEnumConstantClass( newClass ); } else if ( !classStack.isEmpty() ) { classStack.getFirst().addClass( newClass ); newClass.setDeclaringClass( classStack.getFirst() ); } else { source.addClass( newClass ); } return newClass; } /** {@inheritDoc} */ public void endClass() { classStack.removeFirst(); } /** * this one is specific for those cases where dimensions can be part of both the type and identifier * i.e. private String[] matrix[]; //field * public abstract String[] getMatrix[](); //method * * @param typeDef * @param dimensions * @return the Type */ private DefaultJavaType createType( TypeDef typeDef, int dimensions ) { if ( typeDef == null ) { return null; } TypeResolver typeResolver; if(classStack.isEmpty()) { typeResolver = TypeResolver.byPackageName( source.getPackageName(), classLibrary, source.getImports() ); } else { typeResolver = TypeResolver.byClassName( classStack.getFirst().getBinaryName(), classLibrary, source.getImports() ); } return TypeAssembler.createUnresolved( typeDef, dimensions, typeResolver ); } private void addJavaDoc( AbstractBaseJavaEntity entity ) { entity.setComment( lastComment ); List tagList = new LinkedList(); for ( TagDef tagDef : lastTagSet ) { tagList.add( docletTagFactory.createDocletTag( tagDef.getName(), tagDef.getText(), (JavaAnnotatedElement) entity, tagDef.getLineNumber() ) ); } entity.setTags( tagList ); lastTagSet.clear(); lastComment = null; } /** {@inheritDoc} */ public void addInitializer( InitDef def ) { DefaultJavaInitializer initializer = new DefaultJavaInitializer(); initializer.setLineNumber( def.getLineNumber() ); initializer.setBlock( def.getBlockContent() ); initializer.setStatic( def.isStatic() ); classStack.getFirst().addInitializer( initializer ); } /** {@inheritDoc} */ public void beginConstructor() { currentConstructor = new DefaultJavaConstructor(); currentConstructor.setDeclaringClass( classStack.getFirst() ); currentConstructor.setModelWriterFactory( modelWriterFactory ); addJavaDoc( currentConstructor ); setAnnotations( currentConstructor ); classStack.getFirst().addConstructor( currentConstructor ); } /** {@inheritDoc} */ public void endConstructor( MethodDef def ) { currentConstructor.setLineNumber( def.getLineNumber() ); // basic details currentConstructor.setName( def.getName() ); // typeParameters if ( def.getTypeParams() != null ) { List> typeParams = new LinkedList>(); for ( TypeVariableDef typeVariableDef : def.getTypeParams() ) { typeParams.add( createTypeVariable( typeVariableDef, (JavaConstructor) currentConstructor ) ); } currentConstructor.setTypeParameters( typeParams ); } // exceptions List exceptions = new LinkedList(); for ( TypeDef type : def.getExceptions() ) { exceptions.add( createType( type, 0 ) ); } currentConstructor.setExceptions( exceptions ); // modifiers currentConstructor.setModifiers( new LinkedList( def.getModifiers() ) ); if ( !parameterList.isEmpty() ) { currentConstructor.setParameters( new ArrayList( parameterList ) ); parameterList.clear(); } currentConstructor.setSourceCode( def.getBody() ); } /** {@inheritDoc} */ public void beginMethod() { currentMethod = new DefaultJavaMethod(); if ( currentField == null ) { currentMethod.setDeclaringClass( classStack.getFirst() ); classStack.getFirst().addMethod( currentMethod ); } currentMethod.setModelWriterFactory( modelWriterFactory ); addJavaDoc( currentMethod ); setAnnotations( currentMethod ); } /** {@inheritDoc} */ public void endMethod( MethodDef def ) { currentMethod.setLineNumber( def.getLineNumber() ); // basic details currentMethod.setName( def.getName() ); currentMethod.setReturns( createType( def.getReturnType(), def.getDimensions() ) ); // typeParameters if ( def.getTypeParams() != null ) { List> typeParams = new LinkedList>(); for ( TypeVariableDef typeVariableDef : def.getTypeParams() ) { typeParams.add( createTypeVariable( typeVariableDef, (JavaMethod) currentMethod ) ); } currentMethod.setTypeParameters( typeParams ); } // exceptions List exceptions = new LinkedList(); for ( TypeDef type : def.getExceptions() ) { exceptions.add( createType( type, 0 ) ); } currentMethod.setExceptions( exceptions ); // modifiers currentMethod.setDefault( def.getModifiers().remove( "default" ) ); currentMethod.setModifiers( new LinkedList( def.getModifiers() ) ); if ( !parameterList.isEmpty() ) { currentMethod.setParameters( new ArrayList( parameterList ) ); parameterList.clear(); } currentMethod.setSourceCode( def.getBody() ); } private DefaultJavaTypeVariable createTypeVariable( TypeVariableDef typeVariableDef, G genericDeclaration) { if ( typeVariableDef == null ) { return null; } JavaClass declaringClass = getContext( genericDeclaration ); TypeResolver typeResolver = TypeResolver.byClassName( declaringClass.getBinaryName(), classLibrary, source.getImports() ); DefaultJavaTypeVariable result = new DefaultJavaTypeVariable( typeVariableDef.getName(), typeResolver ); if ( typeVariableDef.getBounds() != null && !typeVariableDef.getBounds().isEmpty() ) { List bounds = new LinkedList(); for ( TypeDef typeDef : typeVariableDef.getBounds() ) { bounds.add( createType( typeDef, 0 ) ); } result.setBounds( bounds ); } return result; } private static JavaClass getContext( JavaGenericDeclaration genericDeclaration ) { JavaClass result; if ( genericDeclaration instanceof JavaClass ) { result = (JavaClass) genericDeclaration; } else if ( genericDeclaration instanceof JavaExecutable ) { result = ( (JavaExecutable) genericDeclaration ).getDeclaringClass(); } else { throw new IllegalArgumentException( "Unknown JavaGenericDeclaration implementation" ); } return result; } /** {@inheritDoc} */ public void beginField( FieldDef def ) { currentField = new DefaultJavaField( def.getName() ); currentField.setDeclaringClass( classStack.getFirst() ); currentField.setLineNumber( def.getLineNumber() ); currentField.setModelWriterFactory( modelWriterFactory ); currentField.setType( createType( def.getType(), def.getDimensions() ) ); currentField.setEnumConstant( def.isEnumConstant() ); // modifiers { currentField.setModifiers( new LinkedList( def.getModifiers() ) ); } // code body currentField.setInitializationExpression( def.getBody() ); // javadoc addJavaDoc( currentField ); // annotations setAnnotations( currentField ); } /** {@inheritDoc} */ public void endField() { if ( currentArguments != null && !currentArguments.isEmpty() ) { TypeResolver typeResolver; if( classStack.isEmpty() ) { typeResolver = TypeResolver.byPackageName( source.getPackageName(), classLibrary, source.getImports() ); } else { typeResolver = TypeResolver.byClassName( classStack.getFirst().getBinaryName(), classLibrary, source.getImports() ); } //DefaultExpressionTransformer?? DefaultJavaAnnotationAssembler assembler = new DefaultJavaAnnotationAssembler( currentField.getDeclaringClass(), classLibrary, typeResolver ); List arguments = new LinkedList(); for ( ExpressionDef annoDef : currentArguments ) { arguments.add( assembler.assemble( annoDef ) ); } currentField.setEnumConstantArguments( arguments ); currentArguments.clear(); } classStack.getFirst().addField(currentField); currentField = null; } /** {@inheritDoc} */ public void addParameter( FieldDef fieldDef ) { DefaultJavaParameter jParam = new DefaultJavaParameter( createType( fieldDef.getType(), fieldDef.getDimensions() ), fieldDef.getName(), fieldDef.isVarArgs() ); if( currentMethod != null ) { jParam.setExecutable( currentMethod ); } else { jParam.setExecutable( currentConstructor ); } jParam.setModelWriterFactory( modelWriterFactory ); addJavaDoc( jParam ); setAnnotations( jParam ); parameterList.add( jParam ); } private void setAnnotations( final AbstractBaseJavaEntity entity ) { if ( !currentAnnoDefs.isEmpty() ) { TypeResolver typeResolver; if( classStack.isEmpty() ) { typeResolver = TypeResolver.byPackageName( source.getPackageName(), classLibrary, source.getImports() ); } else { typeResolver = TypeResolver.byClassName( classStack.getFirst().getBinaryName(), classLibrary, source.getImports() ); } DefaultJavaAnnotationAssembler assembler = new DefaultJavaAnnotationAssembler( entity.getDeclaringClass(), classLibrary, typeResolver ); List annotations = new LinkedList(); for ( AnnoDef annoDef : currentAnnoDefs ) { annotations.add( assembler.assemble( annoDef ) ); } entity.setAnnotations( annotations ); currentAnnoDefs.clear(); } } // Don't resolve until we need it... class hasn't been defined yet. /** {@inheritDoc} */ public void addAnnotation( AnnoDef annotation ) { currentAnnoDefs.add( annotation ); } /** {@inheritDoc} */ public void addArgument( ExpressionDef argument ) { currentArguments.add( argument ); } /** {@inheritDoc} */ public JavaSource getSource() { return source; } /** {@inheritDoc} */ public JavaModule getModuleInfo() { return module; } /** {@inheritDoc} */ public void setUrl( URL url ) { source.setURL( url ); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/builder/impl/package-info.java000066400000000000000000000002671325201777200303070ustar00rootroot00000000000000/** * Provides the default implementation of the classes which transform the structs from the JavaParser to the Java model elements */ package com.thoughtworks.qdox.builder.impl;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/builder/package-info.java000066400000000000000000000002151325201777200273370ustar00rootroot00000000000000/** * Provides classes which transform the structs from the JavaParser to the Java model elements */ package com.thoughtworks.qdox.builder;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/directorywalker/000077500000000000000000000000001325201777200257365ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/directorywalker/DirectoryScanner.java000066400000000000000000000053661325201777200320710ustar00rootroot00000000000000package com.thoughtworks.qdox.directorywalker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; import java.util.Collection; import java.util.HashSet; import java.util.LinkedList; import java.util.List; /** * A directory scanner, which can scan files based on optional filters. */ public class DirectoryScanner { private File file; private Collection filters = new HashSet(); /** * * @param file the directory (or file) to scan */ public DirectoryScanner( File file ) { this.file = file; } /** * Add a filter to this scanner. * * @param filter the filter */ public void addFilter( Filter filter ) { this.filters.add( filter ); } /** * * @return a list of files matching the filters, never null */ public List scan() { final List result = new LinkedList(); walk( new FileVisitor() { public void visitFile( File file ) { result.add( file ); } }, this.file ); return result; } /** * Scans the directory. Every file not filtered out by a filter fill be passed to the {@code fileVisitor} * * @param fileVisitor handler for matching files. */ public void scan( FileVisitor fileVisitor ) { walk( fileVisitor, this.file ); } private void walk( FileVisitor visitor, File current ) { if ( current.isDirectory() ) { File[] currentFiles = current.listFiles(); for ( int i = 0; i < currentFiles.length; i++ ) { walk( visitor, currentFiles[i] ); } } else { for ( Filter filter : this.filters ) { if ( !filter.filter( current ) ) { return; } } visitor.visitFile( current ); } } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/directorywalker/FileVisitor.java000066400000000000000000000020131325201777200310340ustar00rootroot00000000000000package com.thoughtworks.qdox.directorywalker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; /** * A File visitor */ public interface FileVisitor { /** * * @param file the file to visit */ void visitFile( File file ); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/directorywalker/Filter.java000066400000000000000000000021351325201777200300270ustar00rootroot00000000000000package com.thoughtworks.qdox.directorywalker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; public interface Filter { /** * * @param file the file to filter * @return returns true if the file matches the filter expression, otherwise false */ boolean filter( File file ); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/directorywalker/SuffixFilter.java000066400000000000000000000027611325201777200312210ustar00rootroot00000000000000package com.thoughtworks.qdox.directorywalker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; /** * * A file filter based on its suffix * */ public class SuffixFilter implements Filter { private String suffixFilter; /** * * @param suffixFilter the suffix which will be matched for every file, must not be null */ public SuffixFilter( String suffixFilter ) { this.suffixFilter = suffixFilter; } /** * @param file the file to filter * @return true if the file ends with the specified suffix, otherwise false */ public boolean filter( File file ) { return file.getName().endsWith( this.suffixFilter ); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/directorywalker/package-info.java000066400000000000000000000002131325201777200311210ustar00rootroot00000000000000/** * Provides classes to visit all files within a directory matching a certain filter */ package com.thoughtworks.qdox.directorywalker;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/library/000077500000000000000000000000001325201777200241705ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/library/AbstractClassLibrary.java000066400000000000000000000276341325201777200311250ustar00rootroot00000000000000package com.thoughtworks.qdox.library; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.net.URL; import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.List; import com.thoughtworks.qdox.builder.Builder; import com.thoughtworks.qdox.builder.ModelBuilderFactory; import com.thoughtworks.qdox.builder.impl.ModelBuilder; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaModule; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.model.impl.DefaultDocletTagFactory; import com.thoughtworks.qdox.model.impl.DefaultJavaPackage; import com.thoughtworks.qdox.parser.structs.ClassDef; import com.thoughtworks.qdox.writer.ModelWriterFactory; /** * A ClassLibrary can be compared with a java classloader. * Its main task is to serve JavaClasses based on the Fully Qualified Name. * AbstractClassLibraries hold a reference a parent library, in which way they can be chained. * Besides that it contains a context only for this library. * * @author Robert Scholte * @since 2.0 */ public abstract class AbstractClassLibrary implements ClassLibrary { private AbstractClassLibrary parentClassLibrary; private ModelBuilderFactory modelBuilderFactory; private ModelWriterFactory modelWriterFactory; private JavaClassContext context = new JavaClassContext(); /** * constructor for root ClassLibrary */ public AbstractClassLibrary() { } /** * constructor for chained ClassLibrary * @param parent the parent library */ public AbstractClassLibrary( AbstractClassLibrary parent ) { this.parentClassLibrary = parent; } public Collection getJavaModules() { Collection modules = null; if ( parentClassLibrary != null ) { modules = parentClassLibrary.getJavaModules(); } return modules; } /** * First checks if there's a JavaClass available in the private context by this name. Otherwise try to resolve it by * the concrete class. If there's still no JavaClass, ask the parent (if available) to resolve it. * * @param name the binary name of the class * @return the JavaClass matching the name, otherwise null */ public final JavaClass getJavaClass( String name ) { return getJavaClass( name, false ); } public final JavaClass getJavaClass( String name, boolean createStub ) { JavaClass result = context.getClassByName( name ); if ( result == null ) { result = resolveJavaClass( name ); if ( result != null ) { context.add( result ); context.add( result.getSource() ); JavaPackage contextPackage = context.getPackageByName( result.getPackageName() ); if( contextPackage == null ) { DefaultJavaPackage newContextPackage = new DefaultJavaPackage( result.getPackageName() ); newContextPackage.setClassLibrary( this ); context.add( newContextPackage ); contextPackage = newContextPackage; } contextPackage.getClasses().addAll( result.getNestedClasses() ); } } if ( result == null && parentClassLibrary != null ) { result = parentClassLibrary.getJavaClass( name ); } if (result == null && createStub) { result = createStub(name); } return result; } private JavaClass createStub( String name ) { Builder unknownBuilder = getModelBuilder(); unknownBuilder.beginClass( new ClassDef( name ) ); unknownBuilder.endClass(); JavaSource unknownSource = unknownBuilder.getSource(); return unknownSource.getClasses().get( 0 ); } /** * The implementation should check it's sources to see if it can build a JavaClass Model If not, just return null; * Once found it will be mapped, so there's no need to keep a reference to this object. * * @param name the fully qualified name * @return the resolved JavaClass, otherwise null */ protected abstract JavaClass resolveJavaClass( String name ); public Collection getJavaSources() { return context.getSources(); } /** * * * @param filter the classlibrary filter * @return JavaSources matching the filter */ protected final Collection getJavaSources( ClassLibraryFilter filter) { List result = new LinkedList(); if(filter.accept(this)) { result.addAll( context.getSources() ); } if ( parentClassLibrary != null ) { result.addAll( parentClassLibrary.getJavaSources( filter ) ); } return Collections.unmodifiableList( result ); } /** * Get all the classes of the current {@link AbstractClassLibrary}. * Subclasses can overwrite this method by including the following code *
 
     * public List<JavaClass> getClasses()
     * {
     *   return getJavaClasses( new ClassLibraryFilter()
     *   {
     *      public boolean accept( AbstractClassLibrary classLibrary )
     *      {
     *          return true;
     *      }
     *   });
     * }
     * 
* This example would return all created {@link JavaClass } objects, including those from the classloaders. * * @return all JavaClasses of this ClassLibrary */ public Collection getJavaClasses() { return context.getClasses(); } /** * Subclasses can call this method to gather all JavaClass object, including those from the parent. * * @param filter the classlibrary filter * @return JavaClasses matching the filter */ protected final Collection getJavaClasses( ClassLibraryFilter filter) { List result = new LinkedList(); if(filter.accept(this)) { result.addAll( context.getClasses() ); } if ( parentClassLibrary != null ) { result.addAll( parentClassLibrary.getJavaClasses( filter ) ); } return Collections.unmodifiableList( result ); } /** * Get all packages of the current {@link AbstractClassLibrary}. * Subclasses can overwrite this method by including the following code *
 
     * public List<JavaPackage> getJavaPackages()
     * {
     *   return getJavaPackages( new ClassLibraryFilter()
     *   {
     *      public boolean accept( AbstractClassLibrary classLibrary )
     *      {
     *          return true;
     *      }
     *   });
     * }
     * 
* This example would return all created {@link JavaPackage } objects, including those from the classloaders. * * @return all JavaPackages of this ClassLibrary */ public Collection getJavaPackages() { return context.getPackages(); } /** * @param name the fully qualified name * @return the JavaPackage matching the name, otherwise null */ public final JavaPackage getJavaPackage( String name ) { JavaPackage result = context.getPackageByName( name ); if (result == null) { result = resolveJavaPackage( name ); if (result != null) { context.add(result); } } if(result == null && parentClassLibrary != null ) { result = parentClassLibrary.getJavaPackage( name ); } return result; } protected abstract JavaPackage resolveJavaPackage(String name); protected final Collection getJavaPackages( ClassLibraryFilter filter) { List result = new LinkedList(); if( filter.accept( this ) ) { result.addAll( context.getPackages() ); } if ( parentClassLibrary != null ) { result.addAll( parentClassLibrary.getJavaPackages( filter ) ); } return Collections.unmodifiableList( result ); } /** * First checks if the context already has a JavaClass with this name. * If not, find out if this classlibrary is able to build a model for this class * Otherwise ask the parent if it could build a JavaClass. * * @param name the fully qualified name * @return true if there is a reference, otherwise false */ public boolean hasClassReference( String name ) { boolean result = context.getClassByName( name ) != null; if ( !result ) { result = containsClassReference( name ); } if ( !result && parentClassLibrary != null ) { result = parentClassLibrary.hasClassReference( name ); } return result; } /** * This method is used to detect if there's a match with this classname. * The name could be constructed based on imports and inner class paths. * * @param name the fully qualified name of the class * @return true if this ClassLibrary has a reference to this class. */ protected abstract boolean containsClassReference( String name ); /** * Set the ModelBuilderFactory for this classLibrary. * * @param factory the model builder factory */ public final void setModelBuilderFactory( ModelBuilderFactory factory ) { this.modelBuilderFactory = factory; } /** * Set the ModelWriterFactory for this class. * * @param factory the model writer factory */ public final void setModelWriterFactory( ModelWriterFactory factory ) { this.modelWriterFactory = factory; } protected final ModelWriterFactory getModelWriterFactory() { return modelWriterFactory; } protected final ModelBuilderFactory getModelBuilderFactory() { return modelBuilderFactory; } /** * If there's a modelBuilderFactory available, ask it for a new instance. * Otherwise, return a default ModelBuilder. * In both cases, pass this library as argument. * * @return a new instance of a ModelBuilder, never null */ protected Builder getModelBuilder() { ModelBuilder result; if ( modelBuilderFactory != null ) { result = modelBuilderFactory.newInstance( this ); } else { result = new ModelBuilder( this, new DefaultDocletTagFactory() ); } result.setModelWriterFactory( modelWriterFactory ); return result; } protected Builder getModelBuilder( URL url ) { Builder result = getModelBuilder(); result.setUrl( url ); return result; } /** * A filter to use when checking all ancestors. * * @author Robert Scholte */ interface ClassLibraryFilter { /** * * @param classLibrary * @return */ boolean accept( AbstractClassLibrary classLibrary ); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/library/ClassLibrary.java000066400000000000000000000065351325201777200274360ustar00rootroot00000000000000package com.thoughtworks.qdox.library; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.Serializable; import java.util.Collection; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaModule; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaSource; /** * Main methods of a ClassLibrary, which can be used by every Model * * @author Robert Scholte * @since 2.0 */ public interface ClassLibrary extends Serializable { /** * Check if this library holds a reference based on the name. * * @param name the (binary) name trying to resolve * @return true if the classLibrary has a reference, otherwise false */ boolean hasClassReference( String name ); /** * Get the JavaClass or null if it's not possible * * @param name The (binary) name of the JavaClass * @return the JavaClass, otherwise null */ JavaClass getJavaClass( String name ); /** * Try to retrieve the JavaClass by the (binary) name. * If the JavaClss doesn't exist and createStub is true make a stub, otherwise return null * * @param name the name of the class * @param createStub force creation of a stub if the class can't be found * @return the JavaClass, might be null depending on the value of createStub. */ JavaClass getJavaClass( String name, boolean createStub ); /** * Return all JavaClasses of the current library. * It's up to the library to decide if also collects JavaClasses from it's ancestors * * @return all JavaClasses as a List, never null */ Collection getJavaClasses(); /** * Return all JavaSources of the current library. * It's up to the library to decide if also collects JavaSources from it's ancestors * * @return all JavaSources as a List, never null */ Collection getJavaSources(); /** * Get the JavaPackage or null if it's not possible * * @param name The fully qualified name of the JavaPackage * @return The package, otherwise null */ JavaPackage getJavaPackage( String name ); /** * Return all JavaPackages of the current library. * It's up to the library to decide if also collects JavaPackages from it's ancestors * * @return all JavaPackages as a List, never null */ Collection getJavaPackages(); Collection getJavaModules(); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/library/ClassLibraryBuilder.java000066400000000000000000000140551325201777200307410ustar00rootroot00000000000000package com.thoughtworks.qdox.library; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.io.Serializable; import java.net.URL; import com.thoughtworks.qdox.builder.ModelBuilderFactory; import com.thoughtworks.qdox.model.JavaModule; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.writer.ModelWriterFactory; /** * This builder helps to construct a library. * All kinds of sourcetypes are supported and it's up to the implementation how to bind these types. * For instance: The {@link SortedClassLibraryBuilder} bundles all classloaders, all sourcefolders and all sources. * The {@link OrderedClassLibraryBuilder} on the other hand keeps track of the order in which sourcetypes are added. * * @author Robert Scholte * @since 2.0 */ public interface ClassLibraryBuilder extends Serializable { /** * Append a classloader and return itself * * @param classLoader the classloader to add * @return this ClassLibraryBuilder instance */ ClassLibraryBuilder appendClassLoader( ClassLoader classLoader ); /** * Add the defaultClassLoaders and return itse * * @return this ClassLibraryBuilder instance */ ClassLibraryBuilder appendDefaultClassLoaders(); /** * * @param sourceFolder the source folder * @return this ClassLibraryBuilder instance */ ClassLibraryBuilder appendSourceFolder( File sourceFolder ); /** * * @param stream the Java source as stream * @return this ClassLibraryBuilder instance * @throws IOException if an IOException is thrown, e.g. unsupported encoding */ ClassLibraryBuilder appendSource( InputStream stream ) throws IOException; /** * * @param reader the Java source as reader * @return this ClassLibraryBuilder instance */ ClassLibraryBuilder appendSource( Reader reader ); /** * * @param url the Java source as URL * @return this ClassLibraryBuilder instance * @throws IOException if an IOException occurs */ ClassLibraryBuilder appendSource( URL url ) throws IOException; /** * * @param file the Java source as file * @return this ClassLibraryBuilder instance * @throws IOException if an IOException occurs */ ClassLibraryBuilder appendSource( File file ) throws IOException; /** * * @param stream the Java source as stream * @return the created JavaSource * @throws IOException if an IOException is thrown, e.g. unsupported encoding */ JavaSource addSource( InputStream stream ) throws IOException; /** * Add the source content of the reader to the ClassLibrary and return the generated JavaSource * * @param reader the Java source as reader * @return the created JavaSource */ JavaSource addSource( Reader reader ); /** * * @param url the Java source as URL * @return the created JavaSource * @throws IOException if an IOException occurs */ JavaSource addSource( URL url ) throws IOException; /** * * @param file the Java source as file * @return the created JavaSource * @throws IOException if an IOException occurs */ JavaSource addSource( File file ) throws IOException; /** * Set to {@code true} to enable debug logging for the lexer * * @param debugLexer the debug logging flag * @return this ClassLibraryBuilder instance */ ClassLibraryBuilder setDebugLexer( boolean debugLexer ); /** * Set to {@code true} to enable debug logging for the parser * * @param debugParser the debug logging flag * @return this ClassLibraryBuilder instance */ ClassLibraryBuilder setDebugParser( boolean debugParser ); /** * * @param encoding set the encoding * @return this ClassLibraryBuilder instance */ ClassLibraryBuilder setEncoding( String encoding ); /** * Define the {@link ModelBuilderFactory} which the parsers should use to construct the JavaModel Objects * * @param factory the modelBuilderFactory * @return this ClassLibraryBuilder instance */ ClassLibraryBuilder setModelBuilderFactory( ModelBuilderFactory factory ); /** * Define the {@link ModelWriterFactory} which is used by the classes when calling for the codeBlock. * * @param factory the modelWriterFactory * @return this ClassLibraryBuilder instance */ ClassLibraryBuilder setModelWriterFactory( ModelWriterFactory factory ); /** * Get the library based on the strategy of the implementation * * @return the constructed ClassLibrary */ ClassLibrary getClassLibrary(); /** * Can handle ParseExceptions instead of crashing. * Has only effect on the appendSource() methods * * @param errorHandler the errorHandler * @return this ClassLibraryBuilder instance */ ClassLibraryBuilder setErrorHander( ErrorHandler errorHandler ); /** * * @param sourceFolder the sourcefolder * @return the module info if the sourcefolder has a module-info.java, otherwise {@code null} * @since 2.0 */ JavaModule addSourceFolder( File sourceFolder ); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/library/ClassLoaderLibrary.java000066400000000000000000000160711325201777200305610ustar00rootroot00000000000000package com.thoughtworks.qdox.library; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import com.thoughtworks.qdox.builder.Builder; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.impl.DefaultJavaPackage; import com.thoughtworks.qdox.parser.JavaLexer; import com.thoughtworks.qdox.parser.ParseException; import com.thoughtworks.qdox.parser.impl.BinaryClassParser; import com.thoughtworks.qdox.parser.impl.JFlexLexer; import com.thoughtworks.qdox.parser.impl.Parser; /** * Important!! Be sure to add a classloader with the bootstrap classes. *

* Normally you can generate your classLibrary like this:
* * ClassLibrary classLibrary = new ClassLibrary(); * classLibrary.addDefaultLoader(); * *

*

* If you want full control over the classLoaders you might want to create your library like:
* * ClassLibrary classLibrary = new ClassLibrary( ClassLoader.getSystemClassLoader() ) * *

* * @author Joe Walnes * @author Aslak Hellesøy * @author Robert Scholte * @since 2.0 */ public class ClassLoaderLibrary extends AbstractClassLibrary { private transient List classLoaders = new LinkedList(); private boolean defaultClassLoadersAdded = false; private boolean debugLexer; private boolean debugParser; private ErrorHandler errorHandler; public ClassLoaderLibrary( AbstractClassLibrary parent ) { super( parent ); } public ClassLoaderLibrary( AbstractClassLibrary parent, ClassLoader classLoader ) { super( parent ); this.classLoaders.add( classLoader ); } public void addClassLoader( ClassLoader classLoader ) { classLoaders.add( classLoader ); } public void addDefaultLoader() { if ( !defaultClassLoadersAdded ) { classLoaders.add( getClass().getClassLoader() ); classLoaders.add( Thread.currentThread().getContextClassLoader() ); } defaultClassLoadersAdded = true; } @Override protected JavaClass resolveJavaClass( final String name ) { JavaClass result = null; for ( ClassLoader classLoader : classLoaders ) { String resource = name; if ( resource.indexOf( '$' ) > 0 ) { resource = resource.split( "$" )[0]; } resource = resource.replace( '.', '/' ) + ".java"; InputStream sourceStream = classLoader.getResourceAsStream( resource ); if ( sourceStream != null ) { Builder builder = getModelBuilder(); JavaLexer lexer = new JFlexLexer( sourceStream ); Parser parser = new Parser( lexer, builder ); parser.setDebugLexer( debugLexer ); parser.setDebugParser( debugParser ); try { if ( parser.parse() ) { result = builder.getSource().getClassByName( name ); break; } } catch ( ParseException pe ) { pe.setSourceInfo( resource ); if ( errorHandler != null ) { errorHandler.handle( pe ); } else { throw pe; } } } if ( result == null ) { try { Class clazz = classLoader.loadClass( name ); if ( clazz.getDeclaringClass() != null ) { clazz = clazz.getDeclaringClass(); } Builder builder = getModelBuilder(); BinaryClassParser parser = new BinaryClassParser( clazz, builder ); if ( parser.parse() ) { result = builder.getSource().getClassByName( name ); break; } } catch ( ClassNotFoundException e ) { } } } return result; } @Override protected JavaPackage resolveJavaPackage(String name) { DefaultJavaPackage result = null; Package pckg = Package.getPackage(name); if(pckg != null) { result = new DefaultJavaPackage(name); result.setClassLibrary( this ); } return result; } private void readObject( ObjectInputStream in ) throws IOException, ClassNotFoundException { in.defaultReadObject(); classLoaders = new LinkedList(); if ( defaultClassLoadersAdded ) { defaultClassLoadersAdded = false; addDefaultLoader(); } } @Override protected boolean containsClassReference( String name ) { boolean result = false; for(Iterator iter = classLoaders.iterator();!result && iter.hasNext(); ) { ClassLoader classLoader = (ClassLoader) iter.next(); try { Class clazz = classLoader.loadClass( name ); result = ( clazz != null ); } catch ( ClassNotFoundException e ) { } } return result; } /** * Set to {@code true} to enable debug logging for the lexer * * @param debugLexer the debug logging flag */ public void setDebugLexer( boolean debugLexer ) { this.debugLexer = debugLexer; } /** * Set to {@code true} to enable debug logging for the parser * * @param debugParser the debug logging flag */ public void setDebugParser( boolean debugParser ) { this.debugParser = debugParser; } public void setErrorHandler( ErrorHandler errorHandler ) { this.errorHandler = errorHandler; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/library/ClassNameLibrary.java000066400000000000000000000037721325201777200302370ustar00rootroot00000000000000package com.thoughtworks.qdox.library; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import com.thoughtworks.qdox.builder.Builder; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.parser.structs.ClassDef; /** * This library always resolve a className by generating an empty JavaClass Model * * @author Robert Scholte * @since 2.0 */ public class ClassNameLibrary extends AbstractClassLibrary { @Override protected JavaClass resolveJavaClass( String name ) { Builder unknownBuilder = getModelBuilder(); String[] names = name.split( "\\$" ); for(int i=0;i classMap = new LinkedHashMap(); private Map packageMap = new LinkedHashMap(); private Set sourceSet = new LinkedHashSet(); public JavaClassContext(){ } /** * Retrieve the {@link JavaClass} based on the {@code name}. * * @param name the fully qualified name of the class * @return the stored JavaClass, otherwise null */ public JavaClass getClassByName(String name) { return classMap.get( name ); } /** * Remove and return the {@link JavaClass} based on the {@code name}. * * @param name the fully qualified name of the class * @return the removed JavaClass, otherwise null */ public JavaClass removeClassByName(String name) { return classMap.remove( name ); } /** * Return all stored JavaClasses * * @return a list of JavaClasses, never null */ public List getClasses() { return Collections.unmodifiableList( new LinkedList(classMap.values()) ); } /** * Store this {@link JavaClass} based on its fully qualified name * * @param javaClass the JavaClass to add */ public void add(JavaClass javaClass) { classMap.put(javaClass.getBinaryName(), javaClass); } /** * Retrieve the {@link JavaPackage} based on the {@code name}. * * @param name the fully qualified name of the package * @return the stored JavaPackage, otherwise null */ public JavaPackage getPackageByName( String name ) { return packageMap.get( name ); } /** * Remove and return the {@link JavaPackage} based on the {@code name}. * * @param name the fully qualified name of the class * @return the removed JavaPackage, otherwise null */ public JavaPackage removePackageByName( String name ) { return packageMap.remove( name ); } /** * A null-safe implementation to store a {@link JavaPackage} in this context * * @param jPackage the JavaPackage to add */ public void add( JavaPackage jPackage ) { if(jPackage != null) { packageMap.put( jPackage.getName(), jPackage ); } } /** * Return all stored JavaPackages * * @return a list of JavaPackages, never null */ public List getPackages() { return Collections.unmodifiableList( new LinkedList(packageMap.values()) ); } /** * Store a {@link JavaSource} in this context * * @param source the JavaSource to add */ public void add( JavaSource source ) { sourceSet.add( source ); } /** * Return all stored JavaSources * * @return a list of JavaSources, never null */ public List getSources() { return Collections.unmodifiableList( new LinkedList(sourceSet) ); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/library/OrderedClassLibraryBuilder.java000066400000000000000000000263131325201777200322460ustar00rootroot00000000000000package com.thoughtworks.qdox.library; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.net.URL; import com.thoughtworks.qdox.builder.ModelBuilderFactory; import com.thoughtworks.qdox.model.JavaModule; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.writer.ModelWriterFactory; /** * This library resolves JavaClasses in the order in which class sources are added. * * @author Robert Scholte * @since 2.0 */ public class OrderedClassLibraryBuilder implements ClassLibraryBuilder { private AbstractClassLibrary classLibrary; private boolean debugLexer; private boolean debugParser; private String encoding; private ErrorHandler errorHandler; private ModelBuilderFactory modelBuilderFactory; private ModelWriterFactory modelWriterFactory; /** * Default constructor which sets the root classLibrary to ClassNameLibrary. * This way every class will be resolved, even if it's not on the classpath. * */ public OrderedClassLibraryBuilder() { this.classLibrary = new ClassNameLibrary(); } /** * Constructor for which you can set the root ClassLibrary * If you set this to null, all classes should be available on the classpath. * * @param rootClassLibrary the parent Classlibrary */ public OrderedClassLibraryBuilder( AbstractClassLibrary rootClassLibrary ) { this.classLibrary = rootClassLibrary; } /* * (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#appendClassLoader(java.lang.ClassLoader) */ public ClassLibraryBuilder appendClassLoader( ClassLoader classLoader ) { if ( !( classLibrary instanceof ClassLoaderLibrary ) ) { classLibrary = newClassLoaderLibrary( classLibrary ); } ClassLoaderLibrary classLoaderLibrary = (ClassLoaderLibrary) classLibrary; classLoaderLibrary.addClassLoader( classLoader ); classLoaderLibrary.setModelBuilderFactory( modelBuilderFactory ); classLoaderLibrary.setModelWriterFactory( modelWriterFactory ); classLoaderLibrary.setDebugLexer( debugLexer ); classLoaderLibrary.setDebugParser( debugParser ); classLoaderLibrary.setErrorHandler( errorHandler ); return this; } /* * (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#appendDefaultClassLoaders() */ public ClassLibraryBuilder appendDefaultClassLoaders() { if ( !( classLibrary instanceof ClassLoaderLibrary ) ) { classLibrary = newClassLoaderLibrary( classLibrary ); } ClassLoaderLibrary classLoaderLibrary = (ClassLoaderLibrary) classLibrary; classLoaderLibrary.addDefaultLoader(); classLoaderLibrary.setModelBuilderFactory( modelBuilderFactory ); classLoaderLibrary.setModelWriterFactory( modelWriterFactory ); return this; } /* (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#addSourceFolder(java.io.File) */ public ClassLibraryBuilder appendSourceFolder( File sourceFolder ) { if ( !( classLibrary instanceof SourceFolderLibrary ) ) { classLibrary = newSourceFolderLibrary( classLibrary ); } SourceFolderLibrary sourceFolderLibrary = (SourceFolderLibrary) classLibrary; prepareSourceLibrary( sourceFolderLibrary ); sourceFolderLibrary.addSourceFolder( sourceFolder ); return this; } /* (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#addSource(java.io.InputStream) */ public ClassLibraryBuilder appendSource( InputStream stream ) throws IOException { SourceLibrary sourceLibrary = getSourceLibrary(); sourceLibrary.addSource( stream ); return this; } /* (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#addSource(java.io.Reader) */ public ClassLibraryBuilder appendSource( Reader reader ) { SourceLibrary sourceLibrary = getSourceLibrary(); sourceLibrary.addSource( reader ); return this; } /* (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#setDebugLexer(boolean) */ public ClassLibraryBuilder setDebugLexer( boolean debugLexer ) { this.debugLexer = debugLexer; return this; } /* (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#setDebugParser(boolean) */ public ClassLibraryBuilder setDebugParser( boolean debugParser ) { this.debugParser = debugParser; return this; } /* * (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#setEncoding(java.lang.String) */ public ClassLibraryBuilder setEncoding( String encoding ) { this.encoding = encoding; return this; } /* * (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#setErrorHander(com.thoughtworks.qdox.library.ErrorHandler) */ public ClassLibraryBuilder setErrorHander( ErrorHandler errorHandler ) { this.errorHandler = errorHandler; return this; } /* * (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#setModelBuilderFactory(com.thoughtworks.qdox.builder.ModelBuilderFactory) */ public ClassLibraryBuilder setModelBuilderFactory( ModelBuilderFactory modelBuilderFactory ) { this.modelBuilderFactory = modelBuilderFactory; return this; } /* * (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#setModelWriterFactory(com.thoughtworks.qdox.writer.ModelWriterFactory) */ public ClassLibraryBuilder setModelWriterFactory( ModelWriterFactory modelWriterFactory ) { this.modelWriterFactory = modelWriterFactory; return this; } /* (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#getClassLibrary() */ public ClassLibrary getClassLibrary() { return classLibrary; } /* * (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#appendSource(java.net.URL) */ public ClassLibraryBuilder appendSource( URL url ) throws IOException { SourceLibrary sourceLibrary = getSourceLibrary(); sourceLibrary.addSource( url ); return this; } /* * (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#appendSource(java.io.File) */ public ClassLibraryBuilder appendSource( File file ) throws IOException { SourceLibrary sourceLibrary = getSourceLibrary(); sourceLibrary.addSource( file ); return this; } /* * (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#addSource(java.io.InputStream) */ public JavaSource addSource( InputStream stream ) throws IOException { SourceLibrary sourceLibrary = getSourceLibrary(); return sourceLibrary.addSource( stream ); } /* * (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#addSource(java.io.Reader) */ public JavaSource addSource( Reader reader ) { SourceLibrary sourceLibrary = getSourceLibrary(); return sourceLibrary.addSource( reader ); } /* * (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#addSource(java.net.URL) */ public JavaSource addSource( URL url ) throws IOException { SourceLibrary sourceLibrary = getSourceLibrary(); return sourceLibrary.addSource( url ); } /* * (non-Javadoc) * @see com.thoughtworks.qdox.library.ClassLibraryBuilder#addSource(java.io.File) */ public JavaSource addSource( File file ) throws IOException { SourceLibrary sourceLibrary = getSourceLibrary(); return sourceLibrary.addSource( file ); } public JavaModule addSourceFolder( File sourceFolder ) { SourceFolderLibrary sourceFolderLibrary = getSourceFolderLibrary(); return sourceFolderLibrary.addSourceFolder( sourceFolder ); } private void prepareSourceLibrary( SourceLibrary sourceLibrary ) { sourceLibrary.setModelBuilderFactory( modelBuilderFactory ); sourceLibrary.setModelWriterFactory( modelWriterFactory ); sourceLibrary.setDebugLexer( debugLexer ); sourceLibrary.setDebugParser( debugParser ); sourceLibrary.setEncoding( encoding ); sourceLibrary.setErrorHandler( errorHandler ); } protected final SourceLibrary getSourceLibrary() { if ( !( classLibrary instanceof SourceLibrary ) ) { classLibrary = newSourceLibrary( classLibrary ); } SourceLibrary sourceLibrary = (SourceLibrary) classLibrary; prepareSourceLibrary( sourceLibrary ); return sourceLibrary; } private SourceFolderLibrary getSourceFolderLibrary() { if ( !( classLibrary instanceof SourceFolderLibrary ) ) { classLibrary = newSourceFolderLibrary( classLibrary ); } SourceFolderLibrary library = (SourceFolderLibrary) classLibrary; prepareSourceLibrary( library ); return library; } /** * Ability to override the implementation of ClassLoaderLibrary * * @param parentLibrary the parent library * @return a new ClassLoaderLibrary instance * @since 2.0 */ protected ClassLoaderLibrary newClassLoaderLibrary( AbstractClassLibrary parentLibrary ) { return new ClassLoaderLibrary( parentLibrary ); } /** * Ability to override the implementation of SourceLibrary * * @param parentLibrary the parent library * @return a new SourceLibrary instance * @since 2.0 */ protected SourceLibrary newSourceLibrary( AbstractClassLibrary parentLibrary ) { return new SourceLibrary( parentLibrary ); } /** * Ability to override the implementation of SourceFolderLibrary * * @param parentLibrary the parent library * @return a new SourceFolderLibrary instance * @since 2.0 */ protected SourceFolderLibrary newSourceFolderLibrary( AbstractClassLibrary parentLibrary ) { return new SourceFolderLibrary( parentLibrary ); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/library/SortedClassLibraryBuilder.java000066400000000000000000000125701325201777200321220ustar00rootroot00000000000000package com.thoughtworks.qdox.library; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.net.URL; import com.thoughtworks.qdox.builder.ModelBuilderFactory; import com.thoughtworks.qdox.model.JavaModule; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.writer.ModelWriterFactory; /** * @author Robert Scholte * @since 2.0 */ public class SortedClassLibraryBuilder implements ClassLibraryBuilder { private final ClassNameLibrary classNameLibrary; private final ClassLoaderLibrary classLoaderLibrary; private final SourceFolderLibrary sourceFolderLibrary; private final SourceLibrary sourceLibrary; public SortedClassLibraryBuilder() { classNameLibrary = new ClassNameLibrary(); classLoaderLibrary = new ClassLoaderLibrary( classNameLibrary ); sourceFolderLibrary = new SourceFolderLibrary( classLoaderLibrary ); sourceLibrary = new SourceLibrary( sourceFolderLibrary ); } public ClassLibraryBuilder appendClassLoader( ClassLoader classLoader ) { classLoaderLibrary.addClassLoader( classLoader ); return this; } public ClassLibraryBuilder appendDefaultClassLoaders() { classLoaderLibrary.addDefaultLoader(); return this; } public ClassLibraryBuilder appendSourceFolder( File sourceFolder ) { sourceFolderLibrary.addSourceFolder( sourceFolder ); return this; } public ClassLibraryBuilder appendSource( InputStream stream ) throws IOException { sourceLibrary.addSource( stream ); return this; } public ClassLibraryBuilder appendSource( Reader reader ) { sourceLibrary.addSource( reader ); return this; } public ClassLibraryBuilder appendSource( URL url ) throws IOException { sourceLibrary.addSource( url ); return this; } public ClassLibraryBuilder appendSource( File file ) throws IOException { sourceLibrary.addSource( file ); return this; } public ClassLibraryBuilder setDebugLexer( boolean debugLexer ) { classLoaderLibrary.setDebugLexer( debugLexer ); sourceFolderLibrary.setDebugLexer( debugLexer ); sourceLibrary.setDebugLexer( debugLexer ); return this; } public ClassLibraryBuilder setDebugParser( boolean debugParser ) { classLoaderLibrary.setDebugParser( debugParser ); sourceFolderLibrary.setDebugParser( debugParser ); sourceLibrary.setDebugParser( debugParser ); return this; } public ClassLibraryBuilder setEncoding( String encoding ) { sourceFolderLibrary.setEncoding( encoding ); sourceLibrary.setEncoding( encoding ); return this; } public ClassLibraryBuilder setErrorHander( ErrorHandler errorHandler ) { classLoaderLibrary.setErrorHandler( errorHandler ); sourceFolderLibrary.setErrorHandler( errorHandler ); sourceLibrary.setErrorHandler( errorHandler ); return this; } public ClassLibraryBuilder setModelBuilderFactory( ModelBuilderFactory factory ) { classNameLibrary.setModelBuilderFactory( factory ); classLoaderLibrary.setModelBuilderFactory( factory ); sourceFolderLibrary.setModelBuilderFactory( factory ); sourceLibrary.setModelBuilderFactory( factory ); return this; } public ClassLibraryBuilder setModelWriterFactory( ModelWriterFactory modelWriterFactory ) { classNameLibrary.setModelWriterFactory( modelWriterFactory ); classLoaderLibrary.setModelWriterFactory( modelWriterFactory ); sourceFolderLibrary.setModelWriterFactory( modelWriterFactory ); sourceLibrary.setModelWriterFactory( modelWriterFactory ); return this; } public ClassLibrary getClassLibrary() { return sourceLibrary; } public JavaSource addSource( InputStream stream ) throws IOException { return sourceLibrary.addSource( stream ); } public JavaSource addSource( Reader reader ) { return sourceLibrary.addSource( reader ); } public JavaSource addSource( URL url ) throws IOException { return sourceLibrary.addSource( url ); } public JavaSource addSource( File file ) throws IOException { return sourceLibrary.addSource( file ); } public JavaModule addSourceFolder( File sourceFolder ) { return sourceFolderLibrary.addSourceFolder( sourceFolder ); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/library/SourceFolderLibrary.java000066400000000000000000000111621325201777200307550ustar00rootroot00000000000000package com.thoughtworks.qdox.library; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaModule; import com.thoughtworks.qdox.model.JavaSource; /** * * @author Robert Scholte * @since 2.0 */ public class SourceFolderLibrary extends SourceLibrary { private List sourceFolders = new LinkedList(); public SourceFolderLibrary( AbstractClassLibrary parent ) { super( parent ); } public SourceFolderLibrary( AbstractClassLibrary parent, File sourceFolder ) { super( parent ); this.sourceFolders.add( sourceFolder ); } public JavaModule addSourceFolder( File sourceFolder ) { this.sourceFolders.add( sourceFolder ); return resolveJavaModule( sourceFolder ); } @Override public Collection getJavaModules() { return resolveJavaModules(); } private Collection resolveJavaModules() { Collection modules = new ArrayList(sourceFolders.size()); for ( File sourceFolder : sourceFolders ) { JavaModule module = resolveJavaModule( sourceFolder ); if( module != null) { modules.add( module ); } } return modules; } private JavaModule resolveJavaModule( File sourceFolder ) { JavaModule result = null; File moduleInfoFile = new File( sourceFolder, "module-info.java" ); if ( moduleInfoFile.isFile() ) { try { result = parse( new FileReader( moduleInfoFile ), moduleInfoFile.toURI().toURL() ).getModuleInfo(); } catch ( FileNotFoundException e ) { // noop } catch ( MalformedURLException e ) { // noop } } return result; } @Override protected JavaClass resolveJavaClass( String className ) { JavaClass result = super.resolveJavaClass( className ); for ( File sourceFolder : sourceFolders ) { String mainClassName = className.split( "\\$" )[0]; File classFile = new File( sourceFolder, mainClassName.replace( '.', File.separatorChar ) + ".java" ); if ( classFile.isFile() ) { try { JavaSource source = parse( new FileReader( classFile ), classFile.toURI().toURL() ).getSource(); result = source.getClassByName( className ); break; } catch ( FileNotFoundException e ) { } catch ( MalformedURLException e ) { } } } return result; } /** * Loops over the sourceFolder to find a classReference. * It will try to map the className to a file. * */ @Override protected boolean containsClassReference( String className ) { boolean result = super.containsClassReference( className ); for ( Iterator iterator = sourceFolders.iterator(); !result && iterator.hasNext(); ) { File sourceFolder = (File) iterator.next(); String mainClassName = className.split( "\\$" )[0]; File classFile = new File( sourceFolder, mainClassName.replace( '.', File.separatorChar ) + ".java" ); result = ( classFile.exists() && classFile.isFile() ); } return result; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/library/SourceLibrary.java000066400000000000000000000313151325201777200276230ustar00rootroot00000000000000package com.thoughtworks.qdox.library; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.UnsupportedEncodingException; import java.net.URL; import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.List; import com.thoughtworks.qdox.builder.Builder; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.model.impl.DefaultJavaPackage; import com.thoughtworks.qdox.parser.JavaLexer; import com.thoughtworks.qdox.parser.ParseException; import com.thoughtworks.qdox.parser.impl.JFlexLexer; import com.thoughtworks.qdox.parser.impl.Parser; /** * This Library will immediately parse the source and keeps its reference to a private context. * Once the superclass explicitly asks for an instance if will be moved to the context f the supoerclass. * If there's a request to get a certain JavaModel Object from a SourceLibrary, it will check all ancestor SourceLibraries as well. * * @author Robert Scholte * @since 2.0 */ public class SourceLibrary extends AbstractClassLibrary { // parser and unused JavaSources, JavaClasses and JavaPackages private JavaClassContext context = new JavaClassContext(); private boolean debugLexer; private boolean debugParser; private static final String DEFAULT_ENCODING = System.getProperty("file.encoding"); private String encoding; private ErrorHandler errorHandler; /** * Create a new instance of SourceLibrary and chain it to the parent * * @param parent the parent classLibrary */ public SourceLibrary( AbstractClassLibrary parent ) { super( parent ); } /** * Add a {@link Reader} containing java code to this library * * @param reader a {@link Reader} which should contain java code * @return The constructed {@link JavaSource} object of this reader * @throws ParseException if this content couldn't be parsed to a JavaModel */ public JavaSource addSource( Reader reader ) throws ParseException { return addSource( reader, null ); } private JavaSource addSource( Reader reader, URL url ) { Builder builder = parse( reader, url ); JavaSource source = null; if( builder != null ) { source = builder.getSource(); registerJavaSource(source); } return source; } /** * Add an {@link InputStream} containing java code to this library * * @param stream an {@link InputStream} which should contain java code * @return The constructed {@link JavaSource} object of this stream * @throws ParseException if this content couldn't be parsed to a JavaModel * @throws IOException if an IOException occurs */ public JavaSource addSource( InputStream stream ) throws ParseException, IOException { Builder builder = parse( stream, null ); JavaSource source = null; if( builder != null) { source= builder.getSource(); registerJavaSource(source); } return source; } /** * Add a {@link URL} containing java code to this library * * @param url a {@link URL} which should contain java code * @return The constructed {@link JavaSource} object of this url * @throws ParseException if this content couldn't be parsed to a JavaModel * @throws IOException if an IOException occurs */ public JavaSource addSource( URL url ) throws ParseException, IOException { return addSource( new InputStreamReader( url.openStream(), encoding), url ); } /** * Add a {@link File} containing java code to this library * * @param file a {@link File} which should contain java code * @return The constructed {@link JavaSource} object of this file * @throws ParseException if this content couldn't be parsed to a JavaModel * @throws IOException if an IOException occurs */ public JavaSource addSource( File file ) throws ParseException, IOException { JavaSource result = null; if ( !"package-info.java".equals( file.getName() ) ) { if ( "module-info.java".equals( file.getName() ) ) { // No parse specifications yet return result; } Builder builder = parse( new FileInputStream( file ), file.toURI().toURL() ); if ( builder != null ) { result = builder.getSource(); } // if an error is handled by the errorHandler the result will be null if( result != null ) { if( getJavaPackage( result.getPackageName() ) == null ) { File packageInfo = new File(file.getParentFile(), "package-info.java"); if( packageInfo.exists() ) { JavaPackage pckg = parse( new FileInputStream( packageInfo ), packageInfo.toURI().toURL() ).getSource().getPackage(); context.add( pckg ); } } registerJavaSource(result); } } return result; } Builder parse( Reader reader, URL url ) throws ParseException { try { return parse( new JFlexLexer( reader ), url ); } finally { try { reader.close(); } catch ( IOException e ) { } } } Builder parse( InputStream stream, URL url ) throws ParseException, UnsupportedEncodingException { try { return parse( new JFlexLexer( new InputStreamReader( stream, getEncoding() ) ), url ); } finally { try { stream.close(); } catch ( IOException e ) { } } } private Builder parse( JavaLexer lexer, URL url ) throws ParseException { Builder builder = getModelBuilder(); builder.setUrl( url ); Parser parser = new Parser( lexer, builder ); parser.setDebugLexer( debugLexer ); parser.setDebugParser( debugParser ); try { if ( parser.parse() ) { return builder; } } catch( ParseException pe ) { if ( url != null ) { pe.setSourceInfo( url.toExternalForm() ); } if( errorHandler != null ) { errorHandler.handle( pe ); } else { throw pe; } } return null; } @Override protected JavaClass resolveJavaClass( String name ) { // abstractLibrary only calls this when it can't find the source itself. // it will take over the reference return context.removeClassByName( name ); } @Override protected JavaPackage resolveJavaPackage(String name) { return context.removePackageByName( name ); } /** * * @param source the source, might be null */ protected final void registerJavaSource( JavaSource source ) { if ( source != null ) { context.add( source ); registerJavaPackage( source.getPackage() ); for ( JavaClass cls : source.getClasses() ) { registerJavaClass( cls ); } } } private void registerJavaPackage( JavaPackage pckg ) { String pckgName = ( pckg == null || pckg.getName() == null ? "" : pckg.getName() ); if( getJavaPackage( pckgName ) == null ) { DefaultJavaPackage packageInfo = new DefaultJavaPackage( pckgName ); packageInfo.setClassLibrary( this ); context.add( packageInfo ); } } private void registerJavaClass(JavaClass cls) { if (cls != null) { context.add( cls ); getJavaPackage( cls.getPackageName() ).getClasses().add( cls ); } for( JavaClass innerCls : cls.getNestedClasses()) { registerJavaClass( innerCls ); } } /** * Use the Lexer in debug mode * * @param debugLexer the debug logging flag */ public final void setDebugLexer( boolean debugLexer ) { this.debugLexer = debugLexer; } public final boolean isDebugLexer() { return debugLexer; } /** * Use the Parser in debug mode * * @param debugParser the debug logging flag */ public final void setDebugParser( boolean debugParser ) { this.debugParser = debugParser; } public final boolean isDebugParser() { return debugParser; } /** * Sets the encoding to use when parsing a URL or InputStreamReader * * @param encoding the source encoding */ public final void setEncoding( String encoding ) { this.encoding = encoding; } public final String getEncoding() { return encoding == null ? DEFAULT_ENCODING : encoding; } public final void setErrorHandler( ErrorHandler errorHandler ) { this.errorHandler = errorHandler; } public final ErrorHandler getErrorHandler() { return errorHandler; } /** * Get all classes, including those from parent SourceLibraries */ @Override public Collection getJavaClasses() { List result = new LinkedList(); List unusedClasses = context.getClasses(); Collection usedClasses = getJavaClasses( new ClassLibraryFilter() { public boolean accept( AbstractClassLibrary classLibrary ) { return (classLibrary instanceof SourceLibrary); } }); result.addAll( usedClasses ); result.addAll( unusedClasses ); return Collections.unmodifiableList( result ); } /** * Get all packages, including those from parent SourceLibraries */ @Override public Collection getJavaPackages() { List result = new LinkedList(); List unusedPackages = context.getPackages(); Collection usedPackages = getJavaPackages( new ClassLibraryFilter() { public boolean accept( AbstractClassLibrary classLibrary ) { return (classLibrary instanceof SourceLibrary); } }); result.addAll( usedPackages ); result.addAll( unusedPackages ); return Collections.unmodifiableList( result ); } /** * Get all sources, including those from parent SourceLibraries */ @Override public Collection getJavaSources() { List result = new LinkedList(); List unusedSources = context.getSources(); Collection usedSources = getJavaSources( new ClassLibraryFilter() { public boolean accept( AbstractClassLibrary classLibrary ) { return (classLibrary instanceof SourceLibrary); } }); result.addAll( usedSources ); result.addAll( unusedSources ); return Collections.unmodifiableList( result ); } @Override protected boolean containsClassReference( String name ) { return context.getClassByName( name ) != null; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/library/package-info.java000066400000000000000000000015261325201777200273630ustar00rootroot00000000000000/** * Provides classes to construct a classloader-like structure of libraries * * There are two types of ClassLibraryBuilders: *
    *
  • SortedClassLibraryBuilder, which bundles the libraries by type
  • *
  • OrderedClassLibraryBuilder, which respects the order of added libraries
  • *
* * There are four types of ClassLibraries: *
    *
  • ClassLoaderLibrary, which uses the classpath to search for sources or binaries
  • *
  • SourceLibrary, which uses a specific sourcefile
  • *
  • SourceFolderLibrary, which tries to locate sourcefiles by translating the package to folders
  • *
  • ClassNameLibrary, which generates an anonymous class, as if it would exist
  • *
* */ package com.thoughtworks.qdox.library;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/000077500000000000000000000000001325201777200236245ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/BeanProperty.java000066400000000000000000000033241325201777200271030ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * @author Aslak Hellesøy * @version $Revision$ */ public interface BeanProperty { /** * The name of the bean, which is based on the name of the mutator or accessor, not on the field. * * @return the name of the bean */ String getName(); /** * The type of the bean, either used as argument type of the mutator or return type of the accessor. * * @return the type of the bean */ JavaType getType(); /** * This can return both the isProperty if the property is of type {@link Boolean} or * getProperty for any other type of {@link Object}. * * @return the getter, otherwise null */ JavaMethod getAccessor(); /** * The setter-method of the bean. * * @return the setter, otherwise null */ JavaMethod getMutator(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/DocletTag.java000066400000000000000000000041261325201777200263400ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.Serializable; import java.util.List; import java.util.Map; /** * @author Joe Walnes * @author Aslak Hellesøy * @version $Revision$ */ public interface DocletTag extends Serializable { /** * The name of the doclet tag. * * @return the tag name */ String getName(); /** * The full value of the doclet tag. * * @return the full tag-value */ String getValue(); /** * * * @return a list of whitespace-separated tag parameters */ List getParameters(); /** * @param key name of a named-parameter * @return the matching value, otherwise null */ String getNamedParameter( String key ); /** * @return a Map containing all the named-parameters, never null */ Map getNamedParameterMap(); /** * The line number of the source where this tag occurred. * * @return the line number where the tag occurred, otherwise -1 */ int getLineNumber(); /** * The element to which this tag applies. * * @return the annotated element, should never be null * @since 1.4 */ JavaAnnotatedElement getContext(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/DocletTagFactory.java000066400000000000000000000027511325201777200276720ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.Serializable; /** * @author Aslak Hellesøy * @version $Revision$ */ public interface DocletTagFactory extends Serializable { /** * * @param tag the tag * @param text the text * @param context the context * @param lineNumber the line number * @return the doclet tag * @since 1.5 */ DocletTag createDocletTag( String tag, String text, JavaAnnotatedElement context, int lineNumber ); /** * * @param tag the tag * @param text the text * @return the doclet tag * @since 1.5 */ DocletTag createDocletTag(String tag, String text); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaAnnotatedElement.java000066400000000000000000000057021325201777200305240ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.List; /** *

* Equivalent of {@link java.lang.reflect.AnnotatedElement}, providing the most important methods. * Where the original AnnotatedElement uses an Array, the JavaAnnotatedElement is using a {@link List}. *

*

* Where you can use Annotations, you can also use JavaDoc. For that reason all JavaDoc methods have been added to this interface. *

* * @author Robert Scholte * @since 2.0 * */ public interface JavaAnnotatedElement extends JavaModel { // Methods from AnnotatedElement /** * * Equivalent of {@link java.lang.reflect.AnnotatedElement#getAnnotations()} * * @return a list of Annotations, never null */ List getAnnotations(); // JavaDoc specific methods /** * Retrieve the javadoc comment of this annotated element. * This is the part between /** and the */, but without the doclet tags * * @return the comment, otherwise null */ String getComment(); /** * Retrieve all defined doclet tags. * * @return a list of DocletTags, never null */ List getTags(); /** * Retrieve all doclettags with a specific name. * * @param name the name of the doclet tag * @return a list of doclettags, never null */ List getTagsByName( String name ); /** * Retrieve the doclettag by the specified name. * If there are more than one tags, only return the first one. * * @param name the name of the doclettag trying to retrieve * @return the first doclettag matching the name, otherwise null */ DocletTag getTagByName( String name ); /** * Convenience method for getTagByName(String).getNamedParameter(String) * that also checks for null tag. * * @param tagName the tag name * @param parameterName the parameter name * @return the value of the matching parameter, otherwise null * @since 1.3 */ String getNamedParameter(String tagName, String parameterName); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaAnnotation.java000066400000000000000000000023721325201777200274070ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.Map; import com.thoughtworks.qdox.model.expression.AnnotationValue; public interface JavaAnnotation extends JavaModel { /** * @return the annotation type */ JavaClass getType(); Map getPropertyMap(); AnnotationValue getProperty(String name); Map getNamedParameterMap(); Object getNamedParameter(String key); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaClass.java000066400000000000000000000360751325201777200263510ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.List; import com.thoughtworks.qdox.library.ClassLibrary; /** * Equivalent of {@link java.lang.Class}, providing the most important methods. * Where the original Class is using an Array, this model is using a List. * * @author Robert Scholte */ public interface JavaClass extends JavaModel, JavaType, JavaAnnotatedElement, JavaGenericDeclaration { /** * The compilation unit, which includes the imports, the public and anonymous classes * * @return the {@link JavaSource} of this element */ JavaSource getSource(); /** * (API description of {@link java.lang.Class#isInterface()}) *

* Determines if the specified Class object represents an interface type. *

* * @return true if this object represents an interface, otherwise false */ boolean isInterface(); /** * (API description of {@link java.lang.Class#isEnum()}) *

* Returns true if and only if this class was declared as an enum in the source code. *

* * @return true if this object represents an enum, otherwise false */ boolean isEnum(); /** * (API description of {@link java.lang.Class#isAnnotation()}) *

Returns true if this Class object represents an annotation type. * Note that if this method returns true, {@link #isInterface()} would also return true, as all annotation types are also interfaces. *

* * @return true if this object represents an annotation, otherwise false * @since 2.0 */ boolean isAnnotation(); JavaClass getDeclaringClass(); JavaType getSuperClass(); /** * Shorthand for getSuperClass().getJavaClass() with null checking. * @return the super class as {@link JavaClass} */ JavaClass getSuperJavaClass(); List getImplements(); /** * Equivalent of {@link java.lang.Class#getInterfaces()} * Determines the interfaces implemented by the class or interface represented by this object. * * @return a list of interfaces, never null * @since 2.0 */ List getInterfaces(); String getCodeBlock(); JavaSource getParentSource(); /** * Equivalent of {@link java.lang.Class#getPackage()} * @return the package */ JavaPackage getPackage(); /** * If this class has a package, the packagename will be returned. * Otherwise an empty String. * * @return the name of the package, otherwise an empty String */ String getPackageName(); /** * @since 1.3 * @return true if this class is an inner class, otherwise false */ boolean isInner(); /** * Equivalent of {@link java.lang.Class#getMethods()} * * @return the methods declared or overridden in this class */ List getMethods(); /** * Equivalent of {@link java.lang.Class#getConstructors()} * * @return the list of constructors * @since 2.0 */ List getConstructors(); /** * * @param parameterTypes the parameter types of the constructor, can be null * @return the matching constructor, otherwise null * @since 2.0 */ JavaConstructor getConstructor(List parameterTypes); /** * * @param parameterTypes the parameter types of the constructor, can be null * @param varArg define is the constructor has varArgs * @return the matching constructor, otherwise null * @since 2.0 */ JavaConstructor getConstructor(List parameterTypes, boolean varArg); /** * Return declared methods and optionally the inherited methods * * @param superclasses {@code true} if inherited methods should be returned as well * @return all methods * @since 1.3 */ List getMethods( boolean superclasses ); /** * * @param name the name of the method * @param parameterTypes the parameter types of the method, can be null. * @return the matching method, otherwise null */ JavaMethod getMethodBySignature( String name, List parameterTypes ); /** * This should be the signature for getMethodBySignature. * * @param name the name of the method * @param parameterTypes the parameter types of the method, can be {@code null} * @param varArgs define if the method has varArgs * @return the matching method, otherwise {@code null} */ JavaMethod getMethod( String name, List parameterTypes, boolean varArgs ); /** * * @param name the name of the method * @param parameterTypes the parameter types of the method, can be {@code null} * @param superclasses to define if superclasses should be included as well * @return the matching method, otherwise {@code null} */ JavaMethod getMethodBySignature( String name, List parameterTypes, boolean superclasses ); /** * * @param name the name of the method * @param parameterTypes the parameter types of the method, can be {@code null} * @param superclasses {@code true} if inherited methods should be matched as well * @param varArg define if the method has varArgs * @return the matching method, otherwise {@code null} */ JavaMethod getMethodBySignature( String name, List parameterTypes, boolean superclasses, boolean varArg ); /** * * @param name the name of the method * @param parameterTypes the parameter types of the method, can be {@code null} * @param superclasses {@code true} if inherited methods should be matched as well * @return the matching methods, otherwise {@code null} */ List getMethodsBySignature( String name, List parameterTypes, boolean superclasses ); /** * * @param name the name of the method * @param parameterTypes the parameter types of the method, can be {@code null} * @param superclasses {@code true} if inherited methods should be matched as well * @param varArg define if the method has varArgs * @return the matching methods, otherwise {@code null} */ List getMethodsBySignature( String name, List parameterTypes, boolean superclasses, boolean varArg ); /** * Equivalent of {@link java.lang.Class#getFields()} * * @return a list of fiels, never {@code null} */ List getFields(); /** * Equivalent of {@link java.lang.Class#getField(String)}, where this method can resolve every field * * @param name the name of the field * @return the field */ JavaField getFieldByName( String name ); /** * Based on {@link java.lang.Class#getEnumConstants()}. * * * @return a List of enum constants if this class is an enum, otherwise {@code null} */ List getEnumConstants(); /** * * @param name the name of the enum constant * @return the enumConstant matching the {@code name}, otherwise null */ JavaField getEnumConstantByName( String name ); /** * Equivalent of {@link Class#getDeclaredClasses()} * * @return a list of declared classes, never null * @since 1.3 */ List getNestedClasses(); JavaClass getNestedClassByName( String name ); /** * @param fullyQualifiedName the FQN to match with * @return {@code true} if this is of type FQN, otherwise {@code false} * @since 1.3 */ boolean isA( String fullyQualifiedName ); /** * @param javaClass the JavaClass to match with * @return {@code true} if this is of type {@literal javaClass}, otherwise {@code false} * @since 1.3 */ boolean isA( JavaClass javaClass ); /** * Returns the depth of this array, 0 if it's not an array * * @return The depth of this array, at least 0 * @since 2.0 */ int getDimensions(); /** * * @return true if this JavaClass is an array, otherwise false * @since 2.0 */ boolean isArray(); /** * * @return true if this JavaClass is a void, otherwise false * @since 2.0 (was part of Type since 1.6) */ boolean isVoid(); /** * Equivalent of {@link Class#getComponentType()} * If this type is an array, return its component type * * @return the type of array if it's one, otherwise null */ JavaClass getComponentType(); /** * Gets bean properties without looking in superclasses or interfaces. * * @return the bean properties * @since 1.3 */ List getBeanProperties(); /** * * @param superclasses to define if superclasses should be included as well * @return the bean properties * @since 1.3 */ List getBeanProperties( boolean superclasses ); /** * Gets bean property without looking in superclasses or interfaces. * * @param propertyName the name of the property * @return the bean property * @since 1.3 */ BeanProperty getBeanProperty( String propertyName ); /** * @param propertyName the name of the property * @param superclasses to define if superclasses should be included as well * @return the bean property * @since 1.3 */ BeanProperty getBeanProperty( String propertyName, boolean superclasses ); /** * Equivalent of {@link Class#getClasses()} * Gets the known derived classes. That is, subclasses or implementing classes. * @return the derived classes */ List getDerivedClasses(); List getTagsByName( String name, boolean superclasses ); ClassLibrary getJavaClassLibrary(); /** * A list if {@link JavaInitializer}, either static or instance initializers. * * @return a List of initializers */ List getInitializers(); /** * Equivalent of {@link java.lang.Class#getName()}. * * @return the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String. */ String getName(); /** * Equivalent of {@link java.lang.Class#getSimpleName()}. * * @return the simple name of the underlying class as given in the source code. * @since 2.0 */ String getSimpleName(); /** * Equivalent of {@link Class#getModifiers()} * * This does not follow the java-api * The Class.getModifiers() returns an int, which should be decoded with the {@link java.lang.reflect.Modifier}. * This method will return a list of strings representing the modifiers. * If this member was extracted from a source, it will keep its order. * Otherwise if will be in the preferred order of the java-api. * * @return all modifiers is this member */ List getModifiers(); /** * (API description of {@link java.lang.reflect.Modifier#isPublic(int)}) *

* Return true if the class includes the public modifier, false otherwise. *

* * @return true if class has the public modifier, otherwise false */ boolean isPublic(); /** * (API description of {@link java.lang.reflect.Modifier#isProtected(int)}) *

* Return true if the class includes the protected modifier, false otherwise. *

* * @return true if class has the protected modifier, otherwise false */ boolean isProtected(); /** * (API description of {@link java.lang.reflect.Modifier#isPrivate(int)}) *

* Return true if the class includes the private modifier, false otherwise. *

* * @return true if class has the private modifier, otherwise false */ boolean isPrivate(); /** * (API description of {@link java.lang.reflect.Modifier#isFinal(int)}) *

* Return true if the class includes the final modifier, false otherwise. *

* * @return true if class has the final modifier, otherwise false */ boolean isFinal(); /** * (API description of {@link java.lang.reflect.Modifier#isStatic(int)}) *

* Return true if the class includes the static modifier, false otherwise. *

* * @return true if class the static modifier, otherwise false */ boolean isStatic(); /** * (API description of {@link java.lang.reflect.Modifier#isAbstract(int)}) * * Return true if the class includes the abstract modifier, false otherwise. * * @return true if class has the abstract modifier, otherwise false */ boolean isAbstract(); /** * Equivalent of {@link java.lang.Class#isPrimitive()} * * @return true if this class represents a primitive, otherwise false */ boolean isPrimitive(); /** * (API description of {@link java.lang.Class#toString()}) * * Converts the object to a string. * The string representation is the string "class" or "interface", followed by a space, and then by the fully qualified name of the class in the format returned by getName. * If this Class object represents a primitive type, this method returns the name of the primitive type. * If this Class object represents void this method returns "void". * * @return a string representation of this class object. */ @Override String toString(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaConstructor.java000066400000000000000000000041001325201777200276110ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.Serializable; import java.util.List; /** * Modeled equivalent of {@link java.lang.reflect.Constructor}, providing the most important methods. * Where the original Constructor is using an Array, this model is using a {@link List}. * * @author Robert Scholte * @since 2.0 */ public interface JavaConstructor extends JavaModel, JavaAnnotatedElement, JavaGenericDeclaration, JavaMember, JavaExecutable, Serializable { // Utility methods /** * Returns true if this constructor matches the parameterTypes, assuming it's a non-varArg constructor. * * @param parameterTypes the parameter types * @return true if signature matches, otherwise false */ boolean signatureMatches( List parameterTypes ); /** * Returns true if this constructor matches the parameterTypes and matches the varArg argument. * * @param parameterTypes the parameter types * @param varArgs {@code true} if the last argument should be a varArg, otherwise {@code false} * @return true if signature matches, otherwise false */ boolean signatureMatches( List parameterTypes, boolean varArgs ); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaExecutable.java000066400000000000000000000042251325201777200273550ustar00rootroot00000000000000package com.thoughtworks.qdox.model; import java.util.List; /** * A shared interface for the common functionality of Method and Constructor. * * @author Robert Scholte * @since 2.0 * * @see java.lang.reflect.Executable */ public interface JavaExecutable extends JavaAnnotatedElement, JavaGenericDeclaration, JavaMember { JavaClass getDeclaringClass(); /** * Equivalent of {@link java.lang.reflect.Executable#getExceptionTypes()} * * @return a list of Exceptions, never null */ List getExceptions(); List getExceptionTypes(); /** * * @param name the name of the parameter * @return the {@link JavaParameter} matching the name, otherwise null */ JavaParameter getParameterByName( String name ); /** * Equivalent of {@link java.lang.reflect.Executable#getParameterTypes()}, where a JavaParameter also contains the original name if available. * * @return a list of JavaParameters, never null */ List getParameters(); /** * Equivalent of {@link java.lang.reflect.Executable#getParameterTypes()} * * @return a list of JavaParameters, never null * @since 1.12 */ List getParameterTypes(); /** * If a class inherits this method from a generic class or interface, you can use this method to get the resolved parameter types * * @param resolve {@code true} if the resolved types should be returned, otherwise {@code false} * @return the parameter types * @since 1.12 */ List getParameterTypes( boolean resolve ); /** * Get the original source code of the body of this method. * * @return Code as string. */ String getSourceCode(); /** * Equivalent of {@link java.lang.reflect.Executable#isVarArgs()} * * @return true if the final parameter is a varArg, otherwise false */ boolean isVarArgs(); String getCallSignature(); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaField.java000066400000000000000000000044101325201777200263130ustar00rootroot00000000000000package com.thoughtworks.qdox.model; import java.util.List; import com.thoughtworks.qdox.model.expression.Expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * Modeled equivalent of {@link java.lang.reflect.Field}, providing the most important methods. * Where the original Field is using an Array, this model is using a {@link java.util.List}. * */ public interface JavaField extends JavaAnnotatedElement, JavaMember, JavaModel { // Methods of Field /** * Equivalent of {@link java.lang.reflect.Field#getType()} * * @return the type of this field, should never be null. */ JavaClass getType(); // Source methods /** * The in-code representation of this field. * * @return the complete representation of this field */ String getCodeBlock(); /** * Get the original expression used to initialize the field. * * @return initialization as string. */ String getInitializationExpression(); /** * Equivalent of {@link java.lang.reflect.Field#isEnumConstant()} * * @return true if this field is an enum constant, otherwise false * @since 2.0 */ boolean isEnumConstant(); /** * * @return the classBody of the enum constant * @since 2.0 */ JavaClass getEnumConstantClass(); /** * * * @return the arguments of the enum constant * @since 2.0 */ List getEnumConstantArguments(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaGenericDeclaration.java000066400000000000000000000026231325201777200310160ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.List; /** * Equivalent of {@link java.lang.reflect.GenericDeclaration}. * Where the original GenericDeclaration uses an Array, the JavaGenericDeclaration is using a {@link List}. * * @author Robert Scholte * @since 2.0 */ public interface JavaGenericDeclaration { /** * Equivalent of {@link java.lang.reflect.GenericDeclaration#getTypeParameters()} * * @param the type * @return a list of typeParameters, never null */ List> getTypeParameters(); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaInitializer.java000066400000000000000000000030651325201777200275600ustar00rootroot00000000000000package com.thoughtworks.qdox.model; import java.io.Serializable; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * A {@link JavaClass} can have contain one of the following initializers: *
    *
  • A static initializer declared in a class is executed when the class is initialized
  • *
  • An instance initializer declared in a class is executed when an instance of the class is created
  • *
* * In code this would look like: *
 * public class Example {
 * 
 *  static {
 *    // static initializer
 *  }
 * 
 *  {
 *    // instance initializer
 *  }
 *  
 * }
 * 
* * @author Robert Scholte * @since 2.0 */ public interface JavaInitializer extends Serializable { boolean isStatic(); String getBlockContent(); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaMember.java000066400000000000000000000105071325201777200265030ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.List; /** * JavaModel representation of a {@link java.lang.reflect.Member} including related methods of {@link java.lang.reflect.Modifier} * * @author Robert Scholte * @since 2.0 */ public interface JavaMember { /** * Equivalent of {@link java.lang.reflect.Member#getModifiers()} * * This does not follow the java-api * With the Member-class, getModifiers returns an int, which should be decoded with the Modifier. * If this member was extracted from a source, it will keep its order. * Otherwise if will be in the preferred order of the java-api. * * @return all modifiers is this member */ List getModifiers(); /** * Equivalent of {@link java.lang.reflect.Member#getDeclaringClass()} * * @return the declaring class */ JavaClass getDeclaringClass(); /** * Equivalent of {@link java.lang.reflect.Member#getName()} * * @return the name of this member */ String getName(); /** * Equivalent of {@link java.lang.reflect.Modifier#isAbstract(int)} * * @return true if this member is abstract, otherwise false */ boolean isAbstract(); /** * Equivalent of {@link java.lang.reflect.Modifier#isFinal(int)} * * @return true is this member is final, otherwise false */ boolean isFinal(); /** * Equivalent of {@link java.lang.reflect.Modifier#isNative(int)} * * @return true if this member is native, otherwise false */ boolean isNative(); /** * Equivalent of {@link java.lang.reflect.Modifier#isPrivate(int)} * * @return true if this member is private, otherwise false */ boolean isPrivate(); /** * Equivalent of {@link java.lang.reflect.Modifier#isProtected(int)} * * @return true if this member is protected; otherwise false */ boolean isProtected(); /** * Equivalent of {@link java.lang.reflect.Modifier#isPublic(int)} * * @return true if this member is public, otherwise false */ boolean isPublic(); /** * Equivalent of {@link java.lang.reflect.Modifier#isStatic(int)} * * @return true if this member is static, otherwise false */ boolean isStatic(); /** * Equivalent of {@link java.lang.reflect.Modifier#isStrict(int)} * * @return true if this member is strictfp, otherwise false */ boolean isStrictfp(); /** * Equivalent of {@link java.lang.reflect.Modifier#isSynchronized(int)} * * @return true if this member is synchronized, otherwise false */ boolean isSynchronized(); /** * Equivalent of {@link java.lang.reflect.Modifier#isTransient(int)} * * @return true if this member is transient, otherwise false */ boolean isTransient(); /** * Equivalent of {@link java.lang.reflect.Modifier#isVolatile(int)} * * @return true if this member is volatile, otherwise false */ boolean isVolatile(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaMethod.java000066400000000000000000000114451325201777200265160ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.List; public interface JavaMethod extends JavaAnnotatedElement, JavaMember, JavaModel, JavaGenericDeclaration, JavaExecutable { /** * * @return the return type */ JavaClass getReturns(); /** * @param withModifiers {@code true} if modifiers should be added, otherwise {@code false} * @return the declaration signature * @since 1.3 */ String getDeclarationSignature( boolean withModifiers ); /** * @return the call signature * @since 1.3 */ String getCallSignature(); /** * This method is NOT varArg aware. * * @param name the name of the method * @param parameterTypes the parameter types of the method, can be null * @return true if this method matches the signature, otherwise false */ boolean signatureMatches( String name, List parameterTypes ); /** * @param name the name of the method * @param parameterTypes the parameter types, can be null * @param varArg true is signature should match a varArg-method, otherwise false * @return true if this method matches the signature, otherwise false */ boolean signatureMatches( String name, List parameterTypes, boolean varArg ); /** * Returns true if this method follows the bean convention of being an accessor. * *
     *   public String getName();             // true
     *   public boolean isValid()             // true
     *   public String getName( String def ); // false, it has a parameter
     *   public String gettingUp();           // false, 'get' is not followed by an uppercase character
     *   public boolean isolate();            // false, 'is' is not followed by an uppercase character
     *   public static String getName();      // false, it is static
     * 
* * @return true if this method is a Java Bean accessor, otherwise false * @since 1.3 */ boolean isPropertyAccessor(); /** * Returns true if this method follows the bean convention of being an mutator. * *
     *  public void setName(String name);        // true
     *  public void setUp();                     // false, it has no parameter
     *  public void settingUp(String def);       // false, 'set' is not followed by an uppercase character
     *  public static void setName(String name); // false, it is static
     * 
* * @return true if this method is a Java Bean mutator, otherwise false * @since 1.3 */ boolean isPropertyMutator(); /** * @return the type of the property this method represents, or null if this method * is not a property mutator or property accessor. * @since 1.3 */ JavaType getPropertyType(); /** * @return the name of the property this method represents, or null if this method * is not a property mutator or property accessor. * @since 1.3 */ String getPropertyName(); List getTagsByName( String name, boolean inherited ); /** * Equivalent of java.lang.reflect.Method.getReturnType() * * @return the return type * @since 1.12 */ JavaType getReturnType(); /** * If a class inherits this method from a generic class or interface, you can use this method to get the resolved return type * * @param resolve define if generic should be resolved * @return the return type * @since 1.12 */ JavaType getReturnType( boolean resolve ); DocletTag getTagByName( String string, boolean b ); /** * Equivalent {@link java.lang.reflect.Method#isDefault()} * * @return {@code true} if this is a default method of an interface, otherwise {@code false} * @since 2.0 */ boolean isDefault(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaModel.java000066400000000000000000000022011325201777200263240ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.Serializable; public interface JavaModel extends Serializable { /** * * @return the codeblock */ String getCodeBlock(); /** * The line number where this element started * * @return the line number of this element */ int getLineNumber(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaModelUtils.java000066400000000000000000000040701325201777200273530ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public final class JavaModelUtils { private JavaModelUtils() { // hide constructor for utility class } /** *

* Try to resolve the class by the {@code name}, either relative from {@code cls} * as the fully qualified name. *

* Note:the name must match the {@code cls} itself or one of its nested classes. * * @param cls the declaring class * @param name the name * @return the matching class, otherwise null * @see JavaClass#getJavaClassLibrary() */ public static JavaClass getClassByName( JavaClass cls, String name ) { JavaClass result = null; if ( cls.getBinaryName().equals( name ) ) { result = cls; } else if ( cls.getName().equals( name ) ) { result = cls; } else { for ( JavaClass innerCls : cls.getNestedClasses() ) { result = getClassByName( innerCls, name ); if ( result != null ) { break; } } } return result; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaModule.java000066400000000000000000000002611325201777200265150ustar00rootroot00000000000000package com.thoughtworks.qdox.model; public interface JavaModule { String getName(); boolean isNamed(); JavaModuleDescriptor getDescriptor(); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaModuleDescriptor.java000066400000000000000000000042741325201777200305640ustar00rootroot00000000000000package com.thoughtworks.qdox.model; import java.util.Collection; public interface JavaModuleDescriptor { boolean isOpen(); String getName(); Collection getExports(); Collection getOpens(); Collection getProvides(); Collection getRequires(); Collection getUses(); /** * Represents the following ModuleStatement:
* * exports SOURCE [to TARGET{, TARGET}]; * * where SOURCE matches a PackageName and TARGET matches a ModuleName * * @author Robert Scholte */ static interface JavaExports { JavaPackage getSource(); Collection getTargets(); } /** * Represents the following ModuleStatement:
* * opens SOURCE [to TARGET{, TARGET}]; * * where SOURCE matches a PackageName and TARGET matches a ModuleName * * @author Robert Scholte */ static interface JavaOpens { JavaPackage getSource(); Collection getTargets(); } /** * Represents the following ModuleStatement:
* * provides SERVICE with PROVIDER; * * where SERVICE matches a TypeName and TARGET matches a TypeName * * @author Robert Scholte * */ static interface JavaProvides { JavaClass getService(); Collection getProviders(); } /** * Represents the following ModuleStatement:
* * requires [public] [static] NAME; * * Where NAME matches a ModuleName * * @author Robert Scholte * */ static interface JavaRequires { JavaModule getModule(); boolean isTransitive(); boolean isStatic(); Collection getModifiers(); } /** * Represents the following ModuleStatement:
* * uses NAME; * * Where NAME matches a TypeName * * @author Robert Scholte * */ static interface JavaUses { JavaClass getService(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaPackage.java000066400000000000000000000051151325201777200266260ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.Collection; import com.thoughtworks.qdox.library.ClassLibrary; public interface JavaPackage extends JavaModel, JavaAnnotatedElement { /** * Returns all the classes found for the package. * * @return all the classes found for the package, never null */ Collection getClasses(); /** * Try to get any class of this package by name. * The name can be both the fully qualified name or just the name of the class. * * @param name the (fully qualified) name of the class * @return the matching class, otherwise null * @since 2.0 */ JavaClass getClassByName( String name ); /** * The parent of this package * * For instance: the package of java.lang.reflect is java.lang * * @return the parent package, otherwise null */ JavaPackage getParentPackage(); /** * For instance: one of the children of java.lang would be java.lang.reflect * * @return all the children of this package , never null */ Collection getSubPackages(); /** * Equivalent of {@link Package#getName()} * * @return the name, should never be null */ String getName(); /** * The {@link ClassLibrary} of this package. * * @return the classLibrary, should never be null */ ClassLibrary getJavaClassLibrary(); /** * Equivalent of {@link Package#toString()} * * @return the string representation of the package. */ String toString(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaParameter.java000066400000000000000000000054531325201777200272200ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * JavaParameter is an extended version of JavaClass and doesn't exist in the java api. * * @author Robert Scholte * */ public interface JavaParameter extends JavaAnnotatedElement, JavaType { /** * * @return the name of the parameter */ String getName(); /** * * @return the type of this parameter */ JavaType getType(); JavaClass getJavaClass(); /** * Returns the declaring method or constructor of this parameter * * @return the declaring method or constructor */ JavaExecutable getExecutable(); /** * The declaring class of the declaring method of this parameter. * * @return the declaring class of the declaring method */ JavaClass getDeclaringClass(); /** * Is this a Java 5 var args type specified using three dots. e.g. void doStuff(Object... thing) * * @return {@code true} if this parameter is a varArg, otherwise {@code false} * @since 1.6 */ boolean isVarArgs(); /** * * @return the value of the type, never null */ String getValue(); /** * * @return the FQN of the type, never null */ String getFullyQualifiedName(); /** * @return the canonical name of the type, never null * @since 2.0 */ String getCanonicalName(); /** * @return the resolved value of the type * @since 1.10 */ String getResolvedValue(); /** * * @return the resolved generic value of the type, never null * @since 2.0 */ String getResolvedGenericValue(); /** * * @return the resolved FQN, never null * @since 2.0 */ String getResolvedFullyQualifiedName(); /** * * @return the resolved generic FQN, never null * @since 2.0 */ String getResolvedGenericFullyQualifiedName(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaParameterizedType.java000066400000000000000000000021411325201777200307250ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.List; /** * Equivalent of {@link java.lang.reflect.ParameterizedType}. * * @since 2.0 * @author Robert Scholte */ public interface JavaParameterizedType extends JavaType { List getActualTypeArguments(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaSource.java000066400000000000000000000055611325201777200265400ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.net.URL; import java.util.List; import com.thoughtworks.qdox.library.ClassLibrary; /** * The root of every JavaModel, even for those based on binary classes. * * @author Robert Scholte */ public interface JavaSource { /** * @return the URL of the source file * @since 1.4 */ URL getURL(); /** * The package of this source or null * * @return the package */ JavaPackage getPackage(); /** * Retrieve all the import * * @return the imports, never null */ List getImports(); /** * A List with all direct classes of this source, never null * * @return a list of JavaClasses, never null */ List getClasses(); /** * Complete code representation of this source * * @return the code block of this source */ String getCodeBlock(); /** * If there's a package, return the packageName, followed by a dot, otherwise an empty String * * @return the class name prefix, otherwise an empty String */ String getClassNamePrefix(); /** * Try to get the JavaClass child based on its name relative to the package. * This doesn't try to resolve it by recursion. * * @param name the name of the class * @return the resolved JavaClass, otherwise null */ JavaClass getNestedClassByName( String name ); /** * Try to get any class of this source by name. * The name can be both the fully qualified name or just the name of the class. * * @param name the (fully qualified) name of the class * @return the matching class, otherwise null * @since 2.0 */ JavaClass getClassByName( String name ); ClassLibrary getJavaClassLibrary(); /** * Returns the name of the package or an empty String if there's no package * * @return the package name, otherwise an empty String */ String getPackageName(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaType.java000066400000000000000000000137161325201777200262220ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * Equivalent of {@link java.lang.reflect.Type}. * */ public interface JavaType { /** *
* The class or interface must be named by its binary name, which must meet the following constraints: *
    *
  • The binary name of a top level type is its canonical name.
  • *
  • The binary name of a member type consists of the binary name of its immediately enclosing type, followed by $, followed by the simple name of the member.
  • *
*
* * @return the binary name * @since 2.0 * @see https://docs.oracle.com/javase/specs/jls/se8/html/jls-13.html#jls-13.1 */ String getBinaryName(); /** * Equivalent of (@link {@link java.lang.Class#getCanonicalName()}. * * @return the canonical name of this class */ String getCanonicalName(); /** * The canonical name with generic information. * * @return the generic canonical name */ String getGenericCanonicalName(); /** *
* Every primitive type, named package, top level class, and top level interface has a fully qualified name: *
    *
  • The fully qualified name of a primitive type is the keyword for that primitive type, namely byte, short, char, int, long, float, double, or boolean.
  • *
  • The fully qualified name of a named package that is not a subpackage of a named package is its simple name.
  • *
  • The fully qualified name of a named package that is a subpackage of another named package consists of the fully qualified name of the containing package, followed by ".", followed by the simple (member) name of the subpackage.
  • *
  • The fully qualified name of a top level class or top level interface that is declared in an unnamed package is the simple name of the class or interface.
  • *
  • The fully qualified name of a top level class or top level interface that is declared in a named package consists of the fully qualified name of the package, followed by ".", followed by the simple name of the class or interface.
  • *
* Each member class, member interface, and array type may have a fully qualified name: *
    *
  • A member class or member interface M of another class or interface C has a fully qualified name if and only if C has a fully qualified name.
  • *
  • In that case, the fully qualified name of M consists of the fully qualified name of C, followed by ".", followed by the simple name of M.
  • *
  • An array type has a fully qualified name if and only if its element type has a fully qualified name.
  • *
  • In that case, the fully qualified name of an array type consists of the fully qualified name of the component type of the array type followed by "[]".
  • *
*
* * Some examples how names will be translated *
     * Object > java.lang.Object
     * java.util.List > java.util.List
     * ?  > ?
     * T  > T
     * anypackage.Outer.Inner > anypackage.Outer.Inner
     * String[][] > java.lang.String[][]
     * 
* * @return the fully qualified name, never null * @see JavaClass#getComponentType() * @see #getBinaryName() * @see https://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.7 */ // @TODO make clear difference between FQN and canonicalName, specs say FQN can be null String getFullyQualifiedName(); /** * The fully qualified name with generic information. * * @return the generic fully qualified name */ String getGenericFullyQualifiedName(); /** * If there's a reference to this class, use the value used in the code. Otherwise return the simple name. * When including all imports, you should be safe to use this method. * This won't return generics, so it's java1.4 safe. * * Examples: *
     *  private String fieldA;             // getValue() will return "String"
     *  private java.lang.String fieldA;   // getValue() will return "java.lang.String"
     *  private List>String> aList;  // getValue() will return "List"
     * 
* * @return the name of the class as used in the source */ String getValue(); /** * A java5+ representation of the class. * When including all imports, you should be safe to use this method. * * Examples: *
     *  private String fieldA;             // getValue() will return "String"
     *  private java.lang.String fieldA;   // getValue() will return "java.lang.String"
     *  private List>String> aList;  // getValue() will return "List>String>"
     * 
* @return the generic name of the class as used in the source */ String getGenericValue(); String toGenericString(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaTypeVariable.java000066400000000000000000000020721325201777200276610ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.List; public interface JavaTypeVariable extends JavaType { D getGenericDeclaration(); String getName(); List getBounds(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/JavaWildcardType.java000066400000000000000000000017371325201777200276740ustar00rootroot00000000000000package com.thoughtworks.qdox.model; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * Equivalent of {@link java.lang.reflect.WildcardType} */ public interface JavaWildcardType extends JavaType { }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/000077500000000000000000000000001325201777200260235ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/Add.java000066400000000000000000000026251325201777200273630ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class Add extends BinaryOperator { public Add( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " + " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " + " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/And.java000066400000000000000000000026251325201777200273750ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class And extends BinaryOperator { public And( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " & " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " & " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/AnnotationValue.java000066400000000000000000000022261325201777200317770ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * Interface for all annotation model elements * * @author Jochen Kuhnle */ public interface AnnotationValue extends Expression { /** * Accept a visitor for this value. * * @param visitor Visitor * @return Visitor result */ Object accept( ExpressionVisitor visitor ); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/AnnotationValueList.java000066400000000000000000000040741325201777200326360ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.Iterator; import java.util.LinkedList; import java.util.List; public class AnnotationValueList implements AnnotationValue { private final List valueList; public AnnotationValueList( List valueList ) { this.valueList = valueList; } public List getValueList() { return valueList; } @Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append( '{' ); for ( Iterator i = valueList.iterator(); i.hasNext(); ) { buf.append( i.next().toString() ); if ( i.hasNext() ) { buf.append( ", " ); } } buf.append( '}' ); return buf.toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public List getParameterValue() { List list = new LinkedList(); for ( AnnotationValue value : valueList ) { list.add( value.getParameterValue() ); } return list; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/Assignment.java000066400000000000000000000034131325201777200307770ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class Assignment implements AnnotationValue { private Expression leftHandSide; private String operator; private Expression assignmentExpression; public Assignment( Expression leftHandSide, String operator, Expression assignmentExpression ) { this.leftHandSide = leftHandSide; this.operator = operator; this.assignmentExpression = assignmentExpression; } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public Object getParameterValue() { return leftHandSide.getParameterValue() + " " + operator + ' ' + assignmentExpression.getParameterValue(); } @Override public String toString() { return leftHandSide.toString() + ' ' + operator + ' ' + assignmentExpression.toString(); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/BinaryOperator.java000066400000000000000000000024061325201777200316300ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public abstract class BinaryOperator implements AnnotationValue { private AnnotationValue left; private AnnotationValue right; public BinaryOperator( AnnotationValue left, AnnotationValue right ) { this.left = left; this.right = right; } public AnnotationValue getLeft() { return left; } public AnnotationValue getRight() { return right; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/Cast.java000066400000000000000000000032561325201777200275660ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import com.thoughtworks.qdox.model.JavaType; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class Cast implements AnnotationValue { private final JavaType type; private final AnnotationValue value; public Cast( JavaType type, AnnotationValue value ) { this.type = type; this.value = value; } public JavaType getType() { return this.type; } public AnnotationValue getValue() { return this.value; } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return "(" + type.getCanonicalName() + ") " + value.getParameterValue(); } @Override public String toString() { return "(" + type.toString() + ") " + value.toString(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/Constant.java000066400000000000000000000220041325201777200304550ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import java.util.regex.Pattern; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public abstract class Constant implements AnnotationValue { private final String image; private Constant( String image ) { this.image = image; } public abstract Object getValue(); public static Constant newBooleanLiteral( final String value ) { return new Constant( value ) { @Override public Object getValue() { return toBoolean( value ); } }; } public static Constant newCharacterLiteral( final String value ) { return new Constant( value ) { @Override public Object getValue() { return toChar( value ); } }; } public static Constant newFloatingPointLiteral( final String value ) { return new Constant( value ) { @Override public Object getValue() { return toFloatingPointLiteral( value ); } }; } public static Constant newIntegerLiteral( final String value ) { return new Constant( value ) { @Override public Object getValue() { return toIntegerLiteral( value ); } }; } public static Constant newStringLiteral( final String value ) { return new Constant( value ) { @Override public Object getValue() { return toString( value ); } }; } public String getImage() { return image; } @Override public String toString() { return image; } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return image; } protected static String convertString( String str ) { StringBuilder buf = new StringBuilder(); 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 ( 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 if ( ch == '\\' ) { escaped = true; } else { buf.append( ch ); } } } return buf.toString(); } protected static Boolean toBoolean( String value ) { return Boolean.valueOf( value ); } protected static Number toIntegerLiteral( String value ) { String literal = value.replaceAll( "_", "" ); Number result; int radix = 10; // default int offset = 0; if ( Pattern.compile( "^0[xX]" ).matcher( literal ).find() ) { radix = 16; offset = 2; } else if ( Pattern.compile( "^0[bB]" ).matcher( literal ).find() ) { radix = 2; offset = 2; } else if ( Pattern.compile( "^0[0-7]" ).matcher( literal ).find() ) { radix = 8; offset = 1; } if ( Pattern.compile( "[lL]$" ).matcher( literal ).find() ) { result = Long.valueOf( literal.substring( offset, literal.length() - 1 ), radix ); } else { result = Integer.valueOf( literal.substring( offset ), radix ); } return result; } protected static Number toFloatingPointLiteral( String value ) { String literal = value.replaceAll( "_", "" ); Number result; if ( Pattern.compile( "[dD]$" ).matcher( literal ).find() ) { result = Double.valueOf( literal.substring( 0, literal.length() - 1 ) ); } else if ( Pattern.compile( "[fF]$" ).matcher( literal ).find() ) { result = Float.valueOf( literal.substring( 0, literal.length() - 1 ) ); } else { result = Float.valueOf( literal ); } return result; } /** * Convert a character literal into a character. * * @param value the single quoted value * @return the transformed char * @throws IllegalArgumentException if value is not a character literal */ protected static Character toChar( String value ) throws IllegalArgumentException { if ( !value.startsWith( "'" ) && !value.endsWith( "'" ) ) { throw new IllegalArgumentException( "Character must be single quoted." ); } String literal = convertString( value.substring( 1, value.length() - 1 ) ); if ( literal.length() != 1 ) { throw new IllegalArgumentException( "Only one character allowed in character constants." ); } return Character.valueOf( literal.charAt( 0 ) ); } /** * Convert a string literal into a string. * * @param value the double quoted value * @return the transformed String * @throws IllegalArgumentException if value is not a String literal */ protected static String toString( String value ) throws IllegalArgumentException { if ( value.length() < 2 && !value.startsWith( "\"" ) && !value.endsWith( "\"" ) ) { throw new IllegalArgumentException( "String must be double quoted." ); } return convertString( value.substring( 1, value.length() - 1 ) ); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/Divide.java000066400000000000000000000026331325201777200300760ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class Divide extends BinaryOperator { public Divide( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " / " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " / " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/Equals.java000066400000000000000000000026351325201777200301260ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class Equals extends BinaryOperator { public Equals( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " == " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " == " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/ExclusiveOr.java000066400000000000000000000026451325201777200311450ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class ExclusiveOr extends BinaryOperator { public ExclusiveOr( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " ^ " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " ^ " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/Expression.java000066400000000000000000000021341325201777200310250ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public interface Expression { /** * Get a parameter value for {@link com.thoughtworks.qdox.model.JavaAnnotation#getNamedParameter(String)}. * * @return Parameter value */ Object getParameterValue(); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/ExpressionVisitor.java000066400000000000000000000050511325201777200324060ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import com.thoughtworks.qdox.model.JavaAnnotation; /** * Visitor class for the annotation model elements * * @author Jochen Kuhnle */ public interface ExpressionVisitor { Object visit( Add add ); Object visit( Subtract subtract ); Object visit( Multiply multiply ); Object visit( Divide divide ); Object visit( GreaterThan greaterThan ); Object visit( LessThan lessThan ); Object visit( JavaAnnotation annotation ); Object visit( Constant constant ); Object visit( ParenExpression expression ); Object visit( AnnotationValueList valueList ); Object visit( TypeRef typeRef ); Object visit( FieldRef fieldRef ); Object visit( LessEquals lessEquals ); Object visit( GreaterEquals greaterEquals ); Object visit( Remainder remainder ); Object visit( Or or ); Object visit( And and ); Object visit( ShiftLeft left ); Object visit( ShiftRight right ); Object visit( Not not ); Object visit( LogicalOr or ); Object visit( LogicalAnd and ); Object visit( LogicalNot not ); Object visit( MinusSign sign ); Object visit( PlusSign sign ); Object visit( UnsignedShiftRight right ); Object visit( Equals annotationEquals ); Object visit( NotEquals annotationNotEquals ); Object visit( ExclusiveOr annotationExclusiveOr ); Object visit( Query annotationQuery ); Object visit( Cast annotationCast ); Object visit( PreDecrement preDecrement ); Object visit( PreIncrement preIncrement ); Object visit( PostDecrement postDecrement ); Object visit( PostIncrement postIncrement ); Object visit( Assignment assignment ); Object visit( MethodInvocation methodInvocation ); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/FieldRef.java000066400000000000000000000112631325201777200303510ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.StringTokenizer; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaField; public class FieldRef implements AnnotationValue { private final int[] parts; private final String name; private JavaClass declaringClass; private ClassLibrary classLibrary; private JavaField field; private int fieldIndex = -1; /** * @param name the field name, not null */ public FieldRef( String name ) { this.name = name; int length = new StringTokenizer( name, "." ).countTokens(); this.parts = new int[length + 1]; this.parts[0] = -1; for ( int i = 1; i < length; ++i ) { this.parts[i] = name.indexOf( '.', this.parts[i - 1] + 1 ); } this.parts[length] = name.length(); } public String getName() { return name; } public String getNamePrefix( int end ) { return name.substring( 0, parts[end + 1] ); } public String getNamePart( int index ) { return name.substring( parts[index] + 1, parts[index + 1] ); } public int getPartCount() { return parts.length - 1; } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getName(); } @Override public String toString() { return getName(); } public void setDeclaringClass( JavaClass declaringClass ) { this.declaringClass = declaringClass; } public void setClassLibrary( ClassLibrary classLibrary ) { this.classLibrary = classLibrary; } public String getClassPart() { String result = null; if ( getField() != null ) { result = name.substring( 0, parts[fieldIndex] ); } return result; } public String getFieldPart() { String result = null; if ( getField() != null ) { result = name.substring( parts[fieldIndex] + 1 ); } return result; } protected JavaField resolveField( JavaClass javaClass, int start, int end ) { JavaField field = null; for ( int i = start; i < end; ++i ) { field = javaClass.getFieldByName( getNamePart( i ) ); if ( field == null ) { break; } } return field; } public JavaField getField() { if ( fieldIndex < 0 ) { JavaClass declaringClass = getDeclaringClass(); if ( declaringClass != null ) { field = resolveField( declaringClass, 0, parts.length - 1 ); fieldIndex = 0; } if ( field == null ) { ClassLibrary classLibrary = getClassLibrary(); if ( classLibrary != null ) { for ( int i = 0; i < parts.length - 1; ++i ) { String className = getNamePrefix( i ); if ( classLibrary.hasClassReference( className ) ) { JavaClass javaClass = classLibrary.getJavaClass( className ); fieldIndex = i + 1; field = resolveField( javaClass, i + 1, parts.length - 1 ); break; } } } } } return field; } private JavaClass getDeclaringClass() { return declaringClass; } private ClassLibrary getClassLibrary() { return classLibrary; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/GreaterEquals.java000066400000000000000000000026531325201777200314400ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class GreaterEquals extends BinaryOperator { public GreaterEquals( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " >= " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " >= " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/GreaterThan.java000066400000000000000000000026451325201777200311010ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class GreaterThan extends BinaryOperator { public GreaterThan( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " > " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " > " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/LessEquals.java000066400000000000000000000026451325201777200307560ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class LessEquals extends BinaryOperator { public LessEquals( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " <= " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " <= " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/LessThan.java000066400000000000000000000026371325201777200304170ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class LessThan extends BinaryOperator { public LessThan( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " < " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " < " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/LogicalAnd.java000066400000000000000000000026451325201777200306720ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class LogicalAnd extends BinaryOperator { public LogicalAnd( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " && " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " && " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/LogicalNot.java000066400000000000000000000025131325201777200307220ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class LogicalNot extends UnaryOperator { public LogicalNot( AnnotationValue value ) { super( value ); } @Override public String toString() { return "!" + getValue().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return "!" + getValue().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/LogicalOr.java000066400000000000000000000026431325201777200305460ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class LogicalOr extends BinaryOperator { public LogicalOr( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " || " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " || " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/MethodInvocation.java000066400000000000000000000031451325201777200321430ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.List; public class MethodInvocation implements AnnotationValue { private String methodName; private List arguments; public MethodInvocation( String methodName, List arguments ) { this.methodName = methodName; this.arguments = arguments; } /** {@inheritDoc} */ public Object getParameterValue() { return null; } public String getMethodName() { return methodName; } public List getArguments() { return arguments; } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/MinusSign.java000066400000000000000000000025111325201777200306010ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class MinusSign extends UnaryOperator { public MinusSign( AnnotationValue value ) { super( value ); } @Override public String toString() { return "-" + getValue().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return "-" + getValue().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/Multiply.java000066400000000000000000000026371325201777200305150ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class Multiply extends BinaryOperator { public Multiply( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " * " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " * " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/Not.java000066400000000000000000000024751325201777200274360ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class Not extends UnaryOperator { public Not( AnnotationValue value ) { super( value ); } @Override public String toString() { return "~" + getValue().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return "~" + getValue().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/NotEquals.java000066400000000000000000000026431325201777200306060ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class NotEquals extends BinaryOperator { public NotEquals( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " != " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " != " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/Or.java000066400000000000000000000026231325201777200272510ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class Or extends BinaryOperator { public Or( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " | " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " | " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/ParenExpression.java000066400000000000000000000027151325201777200320200ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class ParenExpression implements AnnotationValue { private AnnotationValue value; public ParenExpression( AnnotationValue value ) { this.value = value; } public AnnotationValue getValue() { return value; } @Override public String toString() { return "(" + value.toString() + ")"; } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return "(" + value.getParameterValue() + ")"; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/PlusSign.java000066400000000000000000000025071325201777200304360ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class PlusSign extends UnaryOperator { public PlusSign( AnnotationValue value ) { super( value ); } @Override public String toString() { return "+" + getValue().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return "+" + getValue().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/PostDecrement.java000066400000000000000000000025771325201777200314550ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class PostDecrement extends UnaryOperator { public PostDecrement( AnnotationValue value ) { super( value ); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getValue().getParameterValue() + "--"; } @Override public String toString() { return getValue().toString() + "--"; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/PostIncrement.java000066400000000000000000000025771325201777200314730ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class PostIncrement extends UnaryOperator { public PostIncrement( AnnotationValue value ) { super( value ); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getValue().getParameterValue() + "++"; } @Override public String toString() { return getValue().toString() + "++"; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/PreDecrement.java000066400000000000000000000025751325201777200312540ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class PreDecrement extends UnaryOperator { public PreDecrement( AnnotationValue value ) { super( value ); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return "--" + getValue().getParameterValue(); } @Override public String toString() { return "--" + getValue().toString(); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/PreIncrement.java000066400000000000000000000025751325201777200312720ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class PreIncrement extends UnaryOperator { public PreIncrement( AnnotationValue value ) { super( value ); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return "++" + getValue().getParameterValue(); } @Override public String toString() { return "++" + getValue().toString(); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/Query.java000066400000000000000000000041171325201777200277760ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class Query implements AnnotationValue { private final AnnotationValue condition; private final AnnotationValue trueExpression; private final AnnotationValue falseExpression; public Query( AnnotationValue condition, AnnotationValue trueExpression, AnnotationValue falseExpression ) { this.condition = condition; this.trueExpression = trueExpression; this.falseExpression = falseExpression; } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } public AnnotationValue getCondition() { return this.condition; } public AnnotationValue getTrueExpression() { return this.trueExpression; } public AnnotationValue getFalseExpression() { return this.falseExpression; } /** {@inheritDoc} */ public String getParameterValue() { return condition.getParameterValue().toString() + " ? " + trueExpression.getParameterValue() + " : " + falseExpression.getParameterValue(); } @Override public String toString() { return condition.toString() + " ? " + trueExpression.toString() + " : " + falseExpression.toString(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/Remainder.java000066400000000000000000000026411325201777200305770ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class Remainder extends BinaryOperator { public Remainder( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " * " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " * " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/ShiftLeft.java000066400000000000000000000026431325201777200305630ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class ShiftLeft extends BinaryOperator { public ShiftLeft( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " << " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " << " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/ShiftRight.java000066400000000000000000000026451325201777200307500ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class ShiftRight extends BinaryOperator { public ShiftRight( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " >> " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " >> " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/Subtract.java000066400000000000000000000026371325201777200304650ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class Subtract extends BinaryOperator { public Subtract( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " - " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " - " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/TypeRef.java000066400000000000000000000027031325201777200302460ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import com.thoughtworks.qdox.model.JavaType; public class TypeRef implements AnnotationValue { private JavaType type; public TypeRef( JavaType type ) { this.type = type; } public JavaType getType() { return type; } @Override public String toString() { return type.getValue() + ".class"; } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return type.getValue() + ".class"; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/UnaryOperator.java000066400000000000000000000021511325201777200314770ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public abstract class UnaryOperator implements AnnotationValue { private AnnotationValue value; public UnaryOperator( AnnotationValue value ) { this.value = value; } public AnnotationValue getValue() { return value; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/UnsignedShiftRight.java000066400000000000000000000026671325201777200324510ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class UnsignedShiftRight extends BinaryOperator { public UnsignedShiftRight( AnnotationValue left, AnnotationValue right ) { super( left, right ); } @Override public String toString() { return getLeft().toString() + " >>> " + getRight().toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public String getParameterValue() { return getLeft().getParameterValue() + " >>> " + getRight().getParameterValue(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/expression/package-info.java000066400000000000000000000001571325201777200312150ustar00rootroot00000000000000/** * Provides classes reflecting the Java expressions. */ package com.thoughtworks.qdox.model.expression;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/000077500000000000000000000000001325201777200245655ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/AbstractBaseJavaEntity.java000066400000000000000000000072631325201777200317750ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.Serializable; import java.util.Collections; import java.util.LinkedList; import java.util.List; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaSource; public abstract class AbstractBaseJavaEntity extends AbstractJavaModel implements Serializable { private JavaSource source; private List annotations = Collections.emptyList(); private String comment; private List tags = Collections.emptyList(); public AbstractBaseJavaEntity() { super(); } public JavaSource getSource() { return source; } public void setSource(JavaSource source) { this.source = source; } public List getAnnotations() { return annotations; } public void setAnnotations( List annotations ) { this.annotations = annotations; } /** * Not every entity has a parentClass, but AnnotationFieldRef requires access to it. * When used with JavaClass, don't confuse this with getSuperClass() * * @return the surrounding class */ public JavaClass getDeclaringClass() { return null; } public String getComment() { return comment; } public void setComment( String comment ) { this.comment = comment; } public List getTags() { return tags; } public List getTagsByName( String name ) { List specifiedTags = new LinkedList(); for ( DocletTag docletTag : tags ) { if ( docletTag.getName().equals( name ) ) { specifiedTags.add( docletTag ); } } return specifiedTags; } public DocletTag getTagByName( String name ) { for ( DocletTag docletTag : tags ) { if ( docletTag.getName().equals( name ) ) { return docletTag; } } return null; } /** * Convenience method for getTagByName(String).getNamedParameter(String) that also checks for null tag. * * @param tagName the name of the docletTag * @param parameterName the name of the parameter * @return the value of the named parameter * @since 1.3 */ public String getNamedParameter( String tagName, String parameterName ) { DocletTag tag = getTagByName( tagName ); return ( tag != null ? tag.getNamedParameter( parameterName ) : null ); } public void setTags( List tagList ) { this.tags = tagList; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/AbstractInheritableJavaEntity.java000066400000000000000000000025121325201777200333410ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.List; import com.thoughtworks.qdox.model.DocletTag; /** * @author Aslak Hellesøy * @version $Revision$ */ public abstract class AbstractInheritableJavaEntity extends AbstractJavaEntity { public DocletTag getTagByName(String name, boolean inherited) { List tags = getTagsByName(name, inherited); return tags.size() > 0 ? tags.get(0) : null; } public abstract List getTagsByName(String name, boolean inherited); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/AbstractJavaEntity.java000066400000000000000000000121761325201777200312010ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.Collections; import java.util.List; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaModel; public abstract class AbstractJavaEntity extends AbstractBaseJavaEntity implements JavaModel { private List modifiers = Collections.emptyList(); private JavaClass declaringClass; private String name; /** * Return list of modifiers as Strings. * (public, private, protected, final, abstract, static) * @return a list of modifiers, never null */ public List getModifiers() { return modifiers; } public void setModifiers(List modifiers) { this.modifiers = modifiers; } /** * Equivalent of {@link java.lang.reflect.Modifier#isAbstract(int)} * * @return true if entity is abstract, otherwise false */ public boolean isAbstract() { return isModifierPresent("abstract"); } /** * Equivalent of {@link java.lang.reflect.Modifier#isPublic(int)} * * @return true if entity is public, otherwise false */ public boolean isPublic() { return isModifierPresent("public"); } /** * Equivalent of {@link java.lang.reflect.Modifier#isPrivate(int)} * * @return true if entity is private, otherwise false */ public boolean isPrivate() { return isModifierPresent("private"); } /** * Equivalent of {@link java.lang.reflect.Modifier#isProtected(int)} * * @return true if entity is protected, otherwise false */ public boolean isProtected() { return isModifierPresent("protected"); } /** * Equivalent of {@link java.lang.reflect.Modifier#isStatic(int)} * * @return true if entity is static, otherwise false */ public boolean isStatic() { return isModifierPresent("static"); } /** * Equivalent of {@link java.lang.reflect.Modifier#isFinal(int)} * * @return true if entity is final, otherwise false */ public boolean isFinal() { return isModifierPresent("final"); } /** * Equivalent of {@link java.lang.reflect.Modifier#isSynchronized(int)} * * @return true if entity is sunchronized, otherwise false */ public boolean isSynchronized() { return isModifierPresent("synchronized"); } /** * Equivalent of {@link java.lang.reflect.Modifier#isTransient(int)} * * @return true if entity is transient, otherwise false */ public boolean isTransient() { return isModifierPresent("transient"); } /** * Equivalent of {@link java.lang.reflect.Modifier#isVolatile(int)} * * @return true if entity is volatile, otherwise false * @since 1.4 */ public boolean isVolatile() { return isModifierPresent("volatile"); } /** * Equivalent of {@link java.lang.reflect.Modifier#isNative(int)} * * @return true if entity is native, otherwise false * @since 1.4 */ public boolean isNative() { return isModifierPresent("native"); } /** * Equivalent of {@link java.lang.reflect.Modifier#isStrict(int)} * * @return true if entity is strictfp, otherwise false * @since 1.4 */ public boolean isStrictfp() { return isModifierPresent("strictfp"); } /** * Returns true if one of the modifiers matches the {@code modifier} * * @param modifier the modifier * @return true if the modifier is present, otherwise false */ private boolean isModifierPresent(String modifier) { return modifiers.contains(modifier); } public void setDeclaringClass( JavaClass declaringClass ) { this.declaringClass = declaringClass; } /** {@inheritDoc} */ @Override public JavaClass getDeclaringClass() { return declaringClass; } public String getName() { return name; } public void setName(String name) { this.name = name; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/AbstractJavaModel.java000066400000000000000000000032111325201777200307530ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import com.thoughtworks.qdox.model.JavaModel; import com.thoughtworks.qdox.writer.ModelWriter; import com.thoughtworks.qdox.writer.ModelWriterFactory; import com.thoughtworks.qdox.writer.impl.DefaultModelWriter; /** * Every element of a class, including the class itself is a javaModel. * While being constructed by a ModelBuilder, they all must have a reference to the same source. * If a ModelWriterFactory is set, it must be the same for every element of this source, otherwise the defaultModelWriter is used. * * @author Robert Scholte * */ public abstract class AbstractJavaModel implements JavaModel { private ModelWriterFactory modelWriterFactory; private int lineNumber = -1; public AbstractJavaModel() { super(); } /** {@inheritDoc} */ public int getLineNumber() { return lineNumber; } public void setLineNumber(int lineNumber) { this.lineNumber = lineNumber; } /** * * @param modelWriterFactory the modelWriterFactory * @since 2.0 */ public void setModelWriterFactory( ModelWriterFactory modelWriterFactory ) { this.modelWriterFactory = modelWriterFactory; } /* (non-Javadoc) * @see com.thoughtworks.qdox.model.JavaSource#getModelWriter() */ public ModelWriter getModelWriter() { ModelWriter result; if (modelWriterFactory != null) { result = modelWriterFactory.newInstance(); } else { result = new DefaultModelWriter(); } return result; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultBeanProperty.java000066400000000000000000000037121325201777200313520ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import com.thoughtworks.qdox.model.BeanProperty; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaType; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class DefaultBeanProperty implements BeanProperty { private final String name; private JavaMethod accessor; private JavaMethod mutator; private JavaType type; public DefaultBeanProperty( String name ) { this.name = name; } /** {@inheritDoc} */ public String getName() { return name; } public void setType( JavaType type ) { this.type = type; } /** {@inheritDoc} */ public JavaType getType() { return type; } /** {@inheritDoc} */ public JavaMethod getAccessor() { return accessor; } public void setAccessor( JavaMethod accessor ) { this.accessor = accessor; } /** {@inheritDoc} */ public JavaMethod getMutator() { return mutator; } public void setMutator( JavaMethod mutator ) { this.mutator = mutator; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultDocletTag.java000066400000000000000000000052101325201777200306010ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.List; import java.util.Map; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaAnnotatedElement; import com.thoughtworks.qdox.model.util.TagParser; public class DefaultDocletTag implements DocletTag { private final String name; private final String value; private final int lineNumber; private List parameters; private Map namedParameters; private JavaAnnotatedElement context; public DefaultDocletTag( String name, String value, JavaAnnotatedElement context, int lineNumber ) { this.name = name; this.value = value; this.context = context; this.lineNumber = lineNumber; } public DefaultDocletTag( String name, String value ) { this( name, value, null, 0 ); } /** {@inheritDoc} */ public String getName() { return name; } /** {@inheritDoc} */ public String getValue() { return value; } /** {@inheritDoc} */ public List getParameters() { if ( parameters == null ) { parameters = TagParser.parseParameters( value ); } return parameters; } /** {@inheritDoc} */ public Map getNamedParameterMap() { if ( namedParameters == null ) { namedParameters = TagParser.parseNamedParameters( value ); } return namedParameters; } /** {@inheritDoc} */ public String getNamedParameter( String key ) { return (String) getNamedParameterMap().get( key ); } /** {@inheritDoc} */ public final JavaAnnotatedElement getContext() { return context; } /** {@inheritDoc} */ public int getLineNumber() { return lineNumber; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultDocletTagFactory.java000066400000000000000000000027711325201777200321420ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.DocletTagFactory; import com.thoughtworks.qdox.model.JavaAnnotatedElement; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * @author Aslak Hellesøy * @version $Revision$ */ public class DefaultDocletTagFactory implements DocletTagFactory { /** {@inheritDoc} */ public DocletTag createDocletTag( String tag, String text, JavaAnnotatedElement context, int lineNumber ) { return new DefaultDocletTag(tag, text, context, lineNumber); } /** {@inheritDoc} */ public DocletTag createDocletTag(String tag, String text) { return createDocletTag(tag, text, null, 0); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaAnnotation.java000066400000000000000000000102221325201777200316460ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.Serializable; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.expression.AnnotationValue; import com.thoughtworks.qdox.model.expression.ExpressionVisitor; /** * @author Eric Redmond */ public class DefaultJavaAnnotation extends AbstractJavaModel implements AnnotationValue, Serializable, JavaAnnotation { private final JavaClass type; /** * Annotation properties as AnnotationValues *

* This map contains the parsed AnnotationValue for each property and allows access to the full parse tree, * including typerefs and expressions. */ private final Map properties = new LinkedHashMap(); /** * Annotation properties as Parameters */ private final Map namedParameters = new LinkedHashMap(); public DefaultJavaAnnotation( JavaClass type, Map namedParameters ) { this.type = type; if ( properties != null ) { for ( Entry entry : properties.entrySet() ) { String name = entry.getKey(); AnnotationValue value = entry.getValue(); setProperty( name, value ); } } } public DefaultJavaAnnotation( JavaClass type ) { this( type, null ); } public final void setProperty( String name, AnnotationValue value ) { properties.put( name, value ); namedParameters.put( name, value.getParameterValue() ); } /** {@inheritDoc} */ public JavaClass getType() { return type; } /** {@inheritDoc} */ public Object getNamedParameter( String key ) { return namedParameters.get( key ); } /** {@inheritDoc} */ public Map getNamedParameterMap() { return namedParameters; } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writeAnnotation( this ).toString(); } /** {@inheritDoc} */ public Object accept( ExpressionVisitor visitor ) { return visitor.visit( this ); } /** {@inheritDoc} */ public DefaultJavaAnnotation getParameterValue() { return this; } /** {@inheritDoc} */ public Map getPropertyMap() { return properties; } /** {@inheritDoc} */ public AnnotationValue getProperty( String name ) { return properties.get( name ); } @Override public String toString() { StringBuilder result = new StringBuilder(); result.append( '@' ); result.append( type.getFullyQualifiedName() ); result.append( '(' ); if ( !namedParameters.isEmpty() ) { for ( Iterator> i = namedParameters.entrySet().iterator(); i.hasNext(); ) { result.append( i.next() ); if ( i.hasNext() ) { result.append( ',' ); } } } result.append( ')' ); return result.toString(); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaClass.java000066400000000000000000000563761325201777200306250ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.model.BeanProperty; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaConstructor; import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaInitializer; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.model.JavaType; /** * @author Joe Walnes * @author Aslak Hellesøy */ public class DefaultJavaClass extends AbstractInheritableJavaEntity implements JavaClass { private List constructors = new LinkedList(); private List methods = new LinkedList(); private List fields = new LinkedList(); private List classes = new LinkedList(); private boolean anInterface; private boolean anEnum; private boolean anAnnotation; private JavaType superClass; private List implementz = new LinkedList(); private List initializers = new LinkedList(); private List> typeParameters = new LinkedList>(); // sourceless class can use this property private JavaPackage javaPackage; protected DefaultJavaClass() { } public DefaultJavaClass( String name ) { setName( name ); } public DefaultJavaClass( JavaSource source ) { setSource( source ); } /** {@inheritDoc} */ public boolean isInterface() { return anInterface; } /** {@inheritDoc} */ public boolean isPrimitive() { final String name = getName(); return "void".equals( name ) || "boolean".equals( name ) || "byte".equals( name ) || "char".equals( name ) || "short".equals( name ) || "int".equals( name ) || "long".equals( name ) || "float".equals( name ) || "double".equals( name ); } /** {@inheritDoc} */ public boolean isVoid() { return "void".equals( getName() ); } /** {@inheritDoc} */ public boolean isEnum() { return anEnum; } /** {@inheritDoc} */ public boolean isAnnotation() { return anAnnotation; } /** {@inheritDoc} */ public boolean isArray() { return false; } /** {@inheritDoc} */ public JavaClass getComponentType() { return null; } /** {@inheritDoc} */ public int getDimensions() { return 0; } /** {@inheritDoc} */ public JavaType getSuperClass() { JavaType result = null; JavaClass OBJECT_JAVACLASS = getJavaClassLibrary().getJavaClass( "java.lang.Object" ); JavaClass ENUM_JAVACLASS = getJavaClassLibrary().getJavaClass( "java.lang.Enum" ); boolean iAmJavaLangObject = OBJECT_JAVACLASS.equals( this ); if ( anEnum ) { result = ENUM_JAVACLASS; } else if ( !anInterface && !anAnnotation && ( superClass == null ) && !iAmJavaLangObject ) { result = OBJECT_JAVACLASS; } else { result = superClass; } return result; } /** {@inheritDoc} */ public JavaClass getSuperJavaClass() { JavaClass result = null; JavaType superType = getSuperClass(); if ( superType instanceof JavaClass ) { result = ( JavaClass ) superType; } return result; } /** {@inheritDoc} */ public List getImplements() { return new LinkedList( implementz ); } /** {@inheritDoc} */ public List getInterfaces() { return new LinkedList( implementz ); } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writeClass( this ).toString(); } public void setInterface( boolean anInterface ) { this.anInterface = anInterface; } public void setEnum( boolean anEnum ) { this.anEnum = anEnum; } public void setAnnotation( boolean anAnnotation ) { this.anAnnotation = anAnnotation; } public void addConstructor( JavaConstructor constructor ) { constructors.add( constructor ); } public void addMethod( JavaMethod meth ) { methods.add( meth ); } public void setSuperClass( JavaType type ) { if ( anEnum ) { throw new IllegalArgumentException( "enums cannot extend other classes" ); } superClass = type; } public void setImplementz( List implementz ) { this.implementz = implementz; } /** {@inheritDoc} */ public List> getTypeParameters() { return typeParameters; } public void setTypeParameters( List> typeParameters ) { this.typeParameters = typeParameters; } public void addField( JavaField javaField ) { fields.add( javaField ); } /** * Only used when constructing the model by hand / without source * * @param javaPackage the package */ public void setJavaPackage( JavaPackage javaPackage ) { this.javaPackage = javaPackage; } /** {@inheritDoc} */ public JavaSource getParentSource() { return ( getDeclaringClass() != null ? getDeclaringClass().getParentSource() : super.getSource() ); } /** {@inheritDoc} */ @Override public JavaSource getSource() { return getParentSource(); } /** {@inheritDoc} */ public JavaPackage getPackage() { return getParentSource() != null ? getParentSource().getPackage() : javaPackage; } /** {@inheritDoc} */ public String getPackageName() { JavaPackage pckg = getPackage(); return ( pckg != null && pckg.getName() != null ) ? pckg.getName() : ""; } /** {@inheritDoc} */ public String getSimpleName() { return getName(); } /** {@inheritDoc} */ public String getBinaryName() { return ( getDeclaringClass() == null ? getCanonicalName() : getDeclaringClass().getBinaryName() + '$' + getSimpleName() ); } /** {@inheritDoc} */ public String getFullyQualifiedName() { if(isPrimitive()) { return getName(); } else if ( getDeclaringClass() == null ) { return (getPackage() == null ? "" : getPackage().getName() + '.') +getSimpleName(); } else { return getDeclaringClass().getFullyQualifiedName() + "." + getSimpleName(); } } /** {@inheritDoc} */ public String getGenericFullyQualifiedName() { return getFullyQualifiedName(); } /** {@inheritDoc} */ public String getCanonicalName() { return getFullyQualifiedName().replace( '$', '.' ); } /** {@inheritDoc} */ public String getGenericCanonicalName() { return getCanonicalName(); } /** {@inheritDoc} */ public String getValue() { return getCanonicalName().substring( getSource().getClassNamePrefix().length() ); } /** {@inheritDoc} */ public String getGenericValue() { return getValue(); } /** {@inheritDoc} */ public boolean isInner() { return getDeclaringClass() != null; } /** {@inheritDoc} */ public List getInitializers() { return initializers; } /** {@inheritDoc} */ public List getConstructors() { return constructors; } /** {@inheritDoc} */ public JavaConstructor getConstructor( List parameterTypes ) { return getConstructor( parameterTypes, false ); } /** {@inheritDoc} */ public JavaConstructor getConstructor( List parameterTypes, boolean varArgs ) { for ( JavaConstructor constructor : getConstructors() ) { if ( constructor.signatureMatches( parameterTypes, varArgs ) ) { return constructor; } } return null; } /** {@inheritDoc} */ public List getMethods() { return methods; } /** {@inheritDoc} */ public List getMethods( boolean superclasses ) { if ( superclasses ) { return new LinkedList( getMethodsFromSuperclassAndInterfaces( this, this ).values() ); } else { return getMethods(); } } private static Map getMethodsFromSuperclassAndInterfaces( JavaClass rootClass, JavaClass callingClazz ) { Map result = new LinkedHashMap(); for ( JavaMethod method : callingClazz.getMethods() ) { if ( !method.isPrivate() ) { String signature = method.getDeclarationSignature( false ); result.put( signature, method ); } } JavaClass superclass = callingClazz.getSuperJavaClass(); if ( superclass != null ) { Map superClassMethods = getMethodsFromSuperclassAndInterfaces( callingClazz, superclass ); for ( Map.Entry methodEntry : superClassMethods.entrySet() ) { if ( !result.containsKey( methodEntry.getKey() ) ) { JavaMethod method; if ( superclass.equals( rootClass ) ) { method = methodEntry.getValue(); } else { method = new JavaMethodDelegate( callingClazz, methodEntry.getValue() ); } result.put( methodEntry.getKey(), method ); } } } for ( JavaClass clazz : callingClazz.getInterfaces() ) { Map interfaceMethods = getMethodsFromSuperclassAndInterfaces( callingClazz, clazz ); for ( Map.Entry methodEntry : interfaceMethods.entrySet() ) { if ( !result.containsKey( methodEntry.getKey() ) ) { JavaMethod method; if ( clazz.equals( rootClass ) ) { method = methodEntry.getValue(); } else { method = new JavaMethodDelegate( callingClazz, methodEntry.getValue() ); } result.put( methodEntry.getKey(), method ); } } } return result; } /** {@inheritDoc} */ public JavaMethod getMethodBySignature( String name, List parameterTypes ) { return getMethod( name, parameterTypes, false ); } /** {@inheritDoc} */ public JavaMethod getMethod( String name, List parameterTypes, boolean varArgs ) { for ( JavaMethod method : getMethods() ) { if ( method.signatureMatches( name, parameterTypes, varArgs ) ) { return method; } } return null; } /** {@inheritDoc} */ public JavaMethod getMethodBySignature( String name, List parameterTypes, boolean superclasses ) { return getMethodBySignature( name, parameterTypes, superclasses, false ); } /** {@inheritDoc} */ public JavaMethod getMethodBySignature( String name, List parameterTypes, boolean superclasses, boolean varArg ) { List result = getMethodsBySignature( name, parameterTypes, superclasses, varArg ); return ( result.size() > 0 ) ? result.get( 0 ) : null; } /** {@inheritDoc} */ public List getMethodsBySignature( String name, List parameterTypes, boolean superclasses ) { return getMethodsBySignature( name, parameterTypes, superclasses, false ); } /** {@inheritDoc} */ public List getMethodsBySignature( String name, List parameterTypes, boolean superclasses, boolean varArg ) { List result = new LinkedList(); JavaMethod methodInThisClass = getMethod( name, parameterTypes, varArg ); if ( methodInThisClass != null ) { result.add( methodInThisClass ); } if ( superclasses ) { JavaClass superclass = getSuperJavaClass(); if ( superclass != null ) { JavaMethod method = superclass.getMethodBySignature( name, parameterTypes, true, varArg ); // todo: ideally we should check on package privacy too. oh well. if ( ( method != null ) && !method.isPrivate() ) { result.add( new JavaMethodDelegate( this, method ) ); } } for ( JavaClass clazz : getInterfaces() ) { JavaMethod method = clazz.getMethodBySignature( name, parameterTypes, true, varArg ); if ( method != null ) { result.add( new JavaMethodDelegate( this, method ) ); } } } return result; } /** {@inheritDoc} */ public List getFields() { return fields; } /** {@inheritDoc} */ public JavaField getFieldByName( String name ) { for ( JavaField field : getFields() ) { if ( field.getName().equals( name ) ) { return field; } } return null; } /** {@inheritDoc} */ public List getEnumConstants() { List result = isEnum() ? new LinkedList() : null; if ( isEnum() ) { for ( JavaField field : getFields() ) { if ( field.isEnumConstant() ) { result.add( field ); } } } return result; } /** {@inheritDoc} */ public JavaField getEnumConstantByName( String name ) { JavaField field = getFieldByName( name ); return field.isEnumConstant() ? field : null; } public void addInitializer( JavaInitializer initializer ) { initializers.add( initializer ); } public void addClass( JavaClass cls ) { classes.add( cls ); } /** {@inheritDoc} */ public List getNestedClasses() { return classes; } /** {@inheritDoc} */ public JavaClass getNestedClassByName( String name ) { int separatorIndex = name.indexOf( '.' ); String directInnerClassName = ( separatorIndex > 0 ? name.substring( 0, separatorIndex ) : name ); for ( JavaClass jClass : getNestedClasses() ) { if ( jClass.getName().equals( directInnerClassName ) ) { if ( separatorIndex > 0 ) { return jClass.getNestedClassByName( name.substring( separatorIndex + 1 ) ); } else { return jClass; } } } return null; } /** {@inheritDoc} */ public boolean isA( String fullClassName ) { if ( fullClassName == null ) { return false; } if ( fullClassName.equals( getFullyQualifiedName() ) ) { return true; } for ( JavaClass implementz : getInterfaces() ) { if ( implementz.isA( fullClassName ) ) { return true; } } JavaClass superClass = getSuperJavaClass(); if ( superClass != null ) { return superClass.isA( fullClassName ); } return false; } /** {@inheritDoc} */ public boolean isA( JavaClass javaClass ) { if ( this == javaClass ) { return true; } else if ( this.equals( javaClass ) ) { return true; } else if ( javaClass != null ) { // ask our interfaces for ( JavaClass intrfc : getInterfaces() ) { if ( intrfc.isA( javaClass ) ) { return true; } } // ask our superclass JavaClass superClass = getSuperJavaClass(); if ( superClass != null ) { return superClass.isA( javaClass ); } } return false; } /** {@inheritDoc} */ public List getBeanProperties() { return getBeanProperties( false ); } /** {@inheritDoc} */ public List getBeanProperties( boolean superclasses ) { Map beanPropertyMap = getBeanPropertyMap( superclasses ); Collection beanPropertyCollection = beanPropertyMap.values(); return new LinkedList( beanPropertyCollection ); } private Map getBeanPropertyMap( boolean superclasses ) { List superMethods = getMethods( superclasses ); Map beanPropertyMap = new LinkedHashMap(); // loop over the methods. for ( JavaMethod superMethod : superMethods ) { if ( superMethod.isPropertyAccessor() ) { String propertyName = superMethod.getPropertyName(); DefaultBeanProperty beanProperty = getOrCreateProperty( beanPropertyMap, propertyName ); beanProperty.setAccessor( superMethod ); beanProperty.setType( superMethod.getPropertyType() ); } else if ( superMethod.isPropertyMutator() ) { String propertyName = superMethod.getPropertyName(); DefaultBeanProperty beanProperty = getOrCreateProperty( beanPropertyMap, propertyName ); beanProperty.setMutator( superMethod ); beanProperty.setType( superMethod.getPropertyType() ); } } return new LinkedHashMap( beanPropertyMap ); } private DefaultBeanProperty getOrCreateProperty( Map beanPropertyMap, String propertyName ) { DefaultBeanProperty result = beanPropertyMap.get( propertyName ); if ( result == null ) { result = new DefaultBeanProperty( propertyName ); beanPropertyMap.put( propertyName, result ); } return result; } /** {@inheritDoc} */ public BeanProperty getBeanProperty( String propertyName ) { return getBeanProperty( propertyName, false ); } /** {@inheritDoc} */ public BeanProperty getBeanProperty( String propertyName, boolean superclasses ) { return getBeanPropertyMap( superclasses ).get( propertyName ); } /** {@inheritDoc} */ public List getDerivedClasses() { List result = new LinkedList(); for ( JavaClass clazz : getSource().getJavaClassLibrary().getJavaClasses() ) { if ( clazz.isA( this ) && !( clazz == this ) ) { result.add( clazz ); } } return result; } /** {@inheritDoc} */ @Override public List getTagsByName( String name, boolean superclasses ) { return getTagsRecursive( this, name, superclasses ); } private List getTagsRecursive( JavaClass javaClass, String name, boolean superclasses ) { Set result = new LinkedHashSet(); result.addAll( javaClass.getTagsByName( name ) ); if ( superclasses ) { JavaClass superclass = javaClass.getSuperJavaClass(); if ( superclass != null ) { result.addAll( getTagsRecursive( superclass, name, superclasses ) ); } for ( JavaClass intrfc : javaClass.getInterfaces() ) { if ( intrfc != null ) { result.addAll( getTagsRecursive( intrfc, name, superclasses ) ); } } } return new LinkedList( result ); } /** * @see java.lang.Class#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); if ( isPrimitive() ) { sb.append( getName() ); } else { sb.append( isInterface() ? "interface" : "class" ); sb.append( " " ); sb.append( getFullyQualifiedName() ); } return sb.toString(); } public String toGenericString() { return toString(); } @Override public int hashCode() { return 2 + getFullyQualifiedName().hashCode(); } // ideally this shouldn't be required, but we must as long as Types can be created without classLibrary @Override public boolean equals( Object obj ) { if ( this == obj ) { return true; } if ( !( obj instanceof JavaClass ) ) { return false; } JavaClass clazz = (JavaClass) obj; return this.getFullyQualifiedName().equals( clazz.getFullyQualifiedName() ); } /** {@inheritDoc} */ public ClassLibrary getJavaClassLibrary() { return getSource().getJavaClassLibrary(); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaConstructor.java000066400000000000000000000077331325201777200320760ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import java.util.Collections; import java.util.Iterator; import java.util.List; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaConstructor; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.JavaTypeVariable; /** * * @author Robert * @since 2.0 */ public class DefaultJavaConstructor extends DefaultJavaExecutable implements JavaConstructor { private List> typeParameters = Collections.emptyList(); public void setTypeParameters( List> typeParameters ) { this.typeParameters = typeParameters; } /** {@inheritDoc} */ public List> getTypeParameters() { return typeParameters; } /** {@inheritDoc} */ public boolean signatureMatches( List parameterTypes ) { return signatureMatches( parameterTypes, false ); } /** {@inheritDoc} */ @Override public boolean signatureMatches( List parameterTypes, boolean varArgs ) { return super.signatureMatches( parameterTypes, varArgs ); } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writeConstructor( this ).toString(); } @Override public String toString() { StringBuilder result = new StringBuilder(); if ( isPrivate() ) { result.append( "private " ); } else if ( isProtected() ) { result.append( "protected " ); } else if ( isPublic() ) { result.append( "public " ); } if ( getDeclaringClass() != null ) { result.append( getDeclaringClass().getFullyQualifiedName() ); } result.append( "(" ); for ( Iterator paramIter = getParameters().iterator(); paramIter.hasNext();) { String typeValue = DefaultJavaType.getResolvedValue( paramIter.next().getType(), getTypeParameters() ); result.append( typeValue ); if ( paramIter.hasNext() ) { result.append( "," ); } } result.append( ")" ); if ( getExceptions().size() > 0 ) { result.append( " throws " ); for ( Iterator excIter = getExceptions().iterator(); excIter.hasNext(); ) { result.append( excIter.next().getValue() ); if ( excIter.hasNext() ) { result.append( "," ); } } } return result.toString(); } @Override public int hashCode() { int hashCode = 3 + getName().hashCode(); hashCode *= 31 + getParameters().hashCode(); return hashCode; } @Override public boolean equals( Object obj ) { if ( this == obj ) { return true; } if ( !( obj instanceof JavaConstructor ) ) { return false; } JavaConstructor c = (JavaConstructor) obj; if ( c.getDeclaringClass() != null ? !c.getDeclaringClass().equals( this.getDeclaringClass() ) : this.getDeclaringClass() != null ) { return false; } if ( !c.getName().equals( getName() ) ) { return false; } List myParams = getParameters(); List otherParams = c.getParameters(); if ( otherParams.size() != myParams.size() ) { return false; } for ( int i = 0; i < myParams.size(); i++ ) { if ( !otherParams.get( i ).equals( myParams.get( i ) ) ) { return false; } } return this.isVarArgs() == c.isVarArgs(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaExecutable.java000066400000000000000000000150771325201777200316320ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaExecutable; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.JavaType; /** * The BaseMethod contains all methods used by both JavaMethod and JavaConstructor * * @author Robert Scholte * */ public abstract class DefaultJavaExecutable extends AbstractInheritableJavaEntity implements JavaExecutable { private List parameters = Collections.emptyList(); private List exceptions = Collections.emptyList(); private boolean varArgs; private String sourceCode; /** {@inheritDoc} */ public List getParameters() { return parameters; } /** {@inheritDoc} */ public JavaParameter getParameterByName( String name ) { for (JavaParameter parameter : getParameters()) { if (parameter.getName().equals(name)) { return parameter; } } return null; } /** {@inheritDoc} */ public List getExceptions() { return new LinkedList( exceptions ); } /** {@inheritDoc} */ public List getExceptionTypes() { return new LinkedList( exceptions ); } /** {@inheritDoc} */ public boolean isVarArgs() { return varArgs; } public void setParameters( List javaParameters ) { parameters = javaParameters; this.varArgs = javaParameters.get( javaParameters.size() -1 ).isVarArgs(); } public void setExceptions( List exceptions ) { this.exceptions = exceptions; } protected boolean signatureMatches( List parameterTypes, boolean varArgs ) { List parameterTypeList; if( parameterTypes == null) { parameterTypeList = Collections.emptyList(); } else { parameterTypeList = parameterTypes; } if (parameterTypeList.size() != this.getParameters().size()) { return false; } for (int i = 0; i < getParameters().size(); i++) { if (!getParameters().get(i).getType().equals(parameterTypes.get(i))) { return false; } } return (this.varArgs == varArgs); } /** {@inheritDoc} */ @Override public boolean isPublic() { return super.isPublic() || (getDeclaringClass() != null ? getDeclaringClass().isInterface() : false); } /** {@inheritDoc} */ @Override public List getTagsByName( String name, boolean inherited ) { JavaClass cls = getDeclaringClass(); List types = new LinkedList(); for (JavaParameter parameter : getParameters()) { types.add(parameter.getType()); } List methods = cls.getMethodsBySignature(getName(), types, true); List result = new LinkedList(); for (JavaMethod method : methods) { List tags = method.getTagsByName(name); for (DocletTag tag : tags) { if(!result.contains(tag)) { result.add(tag); } } } return result; } /** {@inheritDoc} */ public List getParameterTypes() { return getParameterTypes( false ); } /** {@inheritDoc} */ public List getParameterTypes( boolean resolve ) { List result = new LinkedList(); for ( JavaParameter parameter : this.getParameters() ) { result.add( parameter.getType() ); } return result; } /** {@inheritDoc} */ public String getSourceCode() { return sourceCode; } public void setSourceCode( String sourceCode ) { this.sourceCode = sourceCode; } public String getCallSignature() { return getSignature( false, false ); } // only here for shared signature-code. protected JavaType getReturns() { return null; } /** * @since 1.3 */ protected String getSignature( boolean withModifiers, boolean isDeclaration ) { StringBuilder result = new StringBuilder(); if ( withModifiers ) { for ( String modifier : getModifiers() ) { // check for public, protected and private if ( modifier.startsWith( "p" ) ) { result.append( modifier ).append( ' ' ); } } for ( String modifier : getModifiers() ) { // check for public, protected and private if ( !modifier.startsWith( "p" ) ) { result.append( modifier ).append( ' ' ); } } } if ( isDeclaration && getReturns() != null ) { result.append( getReturns().getGenericCanonicalName() ); result.append( ' ' ); } result.append( getName() ); result.append( '(' ); for ( ListIterator iter = getParameters().listIterator(); iter.hasNext(); ) { JavaParameter parameter = iter.next(); if ( isDeclaration ) { result.append( parameter.getType().getGenericCanonicalName() ); if ( parameter.isVarArgs() ) { result.append( "..." ); } result.append( ' ' ); } result.append( parameter.getName() ); if ( iter.hasNext() ) { result.append( ", " ); } } result.append( ')' ); if ( isDeclaration && !getExceptions().isEmpty() ) { result.append( " throws " ); for ( Iterator excIter = getExceptions().iterator(); excIter.hasNext(); ) { result.append( excIter.next().getGenericCanonicalName() ); if ( excIter.hasNext() ) { result.append( ", " ); } } } return result.toString(); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaField.java000066400000000000000000000117361325201777200305720ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import java.util.List; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.expression.Expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class DefaultJavaField extends AbstractJavaEntity implements JavaField { private JavaClass type; private String initializationExpression; private boolean enumConstant; private JavaClass enumConstantClass; private List enumConstantArguments; public DefaultJavaField( String name ) { setName( name ); } public DefaultJavaField( JavaClass type, String name ) { this( name ); this.type = type; } /** {@inheritDoc} */ public JavaClass getType() { return type; } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writeField( this ).toString(); } public void setType( JavaClass type ) { this.type = type; } /** {@inheritDoc} */ public String getInitializationExpression() { return initializationExpression; } public void setInitializationExpression( String initializationExpression ) { this.initializationExpression = initializationExpression; } /** {@inheritDoc} */ public boolean isEnumConstant() { return enumConstant; } public void setEnumConstant( boolean enumConstant ) { this.enumConstant = enumConstant; } /** {@inheritDoc} */ public List getEnumConstantArguments() { return enumConstantArguments; } public void setEnumConstantArguments( List enumConstantArguments ) { this.enumConstantArguments = enumConstantArguments; } /** {@inheritDoc} */ public JavaClass getEnumConstantClass() { return enumConstantClass; } public void setEnumConstantClass( JavaClass enumConstantClass ) { this.enumConstantClass = enumConstantClass; } /** * @see java.lang.reflect.Field#toString() */ @Override public String toString() { StringBuilder result = new StringBuilder(); if ( isPrivate() ) { result.append( "private " ); } else if ( isProtected() ) { result.append( "protected " ); } else if ( isPublic() ) { result.append( "public " ); } if ( isStatic() ) { result.append( "static " ); } if ( isFinal() ) { result.append( "final " ); } if ( isTransient() ) { result.append( "transient " ); } if ( isVolatile() ) { result.append( "volatile " ); } result.append( type.getValue() ).append( ' ' ); result.append( getDeclaringClass().getFullyQualifiedName() ).append( '.' ).append( getName() ); return result.toString(); } /** * Compares this Field against the specified object. Returns true if the objects are the same. Two * Field objects are the same if they were declared by the same class and have the same name and type. */ @Override public boolean equals( Object obj ) { if ( this == obj ) { return true; } if ( !( obj instanceof JavaField ) ) { return false; } JavaField fld = (JavaField) obj; if ( !fld.getDeclaringClass().equals( this.getDeclaringClass() ) ) { return false; } if ( !fld.isEnumConstant() == this.isEnumConstant() ) { return false; } // Don't see any reason to compare the Type. Otherwise it's already invalid return fld.getName().equals( this.getName() ); } @Override public int hashCode() { int hashCode = 5; if ( getDeclaringClass() != null ) { hashCode *= 31 + getDeclaringClass().hashCode(); } if ( getName() != null ) { hashCode *= 37 + getName().hashCode(); } return hashCode; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaInitializer.java000066400000000000000000000033411325201777200320230ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import com.thoughtworks.qdox.model.JavaInitializer; /** * * @author Robert Scholte * @since 2.0 */ public class DefaultJavaInitializer extends AbstractJavaModel implements JavaInitializer { private boolean staticInitializer; private String blockContent; /** {@inheritDoc} */ public boolean isStatic() { return staticInitializer; } public void setStatic( boolean staticInitializer ) { this.staticInitializer = staticInitializer; } /** {@inheritDoc} */ public String getBlockContent() { return blockContent; } public void setBlock( String codeBlock ) { this.blockContent = codeBlock; } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writeInitializer( this ).toString(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaMethod.java000066400000000000000000000225401325201777200307620ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.beans.Introspector; import java.util.Collections; import java.util.Iterator; import java.util.List; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.JavaTypeVariable; public class DefaultJavaMethod extends DefaultJavaExecutable implements JavaMethod { private boolean defaultMethod; private JavaClass returns; private List> typeParameters = Collections.emptyList(); /** * The default constructor */ public DefaultJavaMethod() { } /** * Create new method without parameters and return type * * @param name the name of the method */ public DefaultJavaMethod(String name) { setName(name); } /** * Create a new method without parameters * * @param returns the return type * @param name the name of this method */ public DefaultJavaMethod(JavaClass returns, String name) { this.returns = returns; setName(name); } /** {@inheritDoc} */ public boolean isDefault() { return defaultMethod; } public void setDefault( boolean defaultMethod ) { this.defaultMethod = defaultMethod; } /** {@inheritDoc} */ public JavaClass getReturns() { return returns; } public void setTypeParameters( List> typeParameters ) { this.typeParameters = typeParameters; } /** {@inheritDoc} */ public List> getTypeParameters() { return typeParameters; } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writeMethod( this ).toString(); } /** {@inheritDoc} */ public String getDeclarationSignature( boolean withModifiers ) { return getSignature(withModifiers, true); } /** * Define the return type of this method * * @param returns the return type */ public void setReturns(JavaClass returns) { this.returns = returns; } @Override public boolean equals( Object obj ) { if ( this == obj ) { return true; } if ( !( obj instanceof JavaMethod ) ) { return false; } JavaMethod other = (JavaMethod) obj; if ( other.getDeclaringClass() != null ? !other.getDeclaringClass().equals( this.getDeclaringClass() ) : this.getDeclaringClass() != null ) { return false; } //use 'this' from here to make it better readable if ( other.getName() != null ? !other.getName().equals( this.getName() ) : this.getName() != null ) { return false; } if ( other.getReturnType() != null ? !other.getReturnType().equals( this.getReturns() ) : this.getReturns() != null ) { return false; } List thisParams = this.getParameters(); List otherParams = other.getParameters(); if ( otherParams.size() != thisParams.size() ) { return false; } for ( int i = 0; i < thisParams.size(); i++ ) { if ( !otherParams.get( i ).equals( thisParams.get( i ) ) ) { return false; } } return this.isVarArgs() == other.isVarArgs(); } @Override public int hashCode() { int hashCode = 7; if ( getDeclaringClass() != null ) { hashCode *= 31 + getDeclaringClass().hashCode(); } if ( getName() != null ) { hashCode *= 37 + getName().hashCode(); } hashCode *= 41 + getParameters().hashCode(); if ( returns != null ) { hashCode *= 43 + returns.hashCode(); } return hashCode; } /** {@inheritDoc} */ public boolean isPropertyAccessor() { if ( isStatic() ) { return false; } if ( getParameters().size() != 0 ) { return false; } if ( getName().startsWith( "is" ) ) { return ( getName().length() > 2 && Character.isUpperCase( getName().charAt( 2 ) ) ); } if ( getName().startsWith( "get" ) ) { return ( getName().length() > 3 && Character.isUpperCase( getName().charAt( 3 ) ) ); } return false; } /** {@inheritDoc} */ public boolean isPropertyMutator() { if ( isStatic() ) { return false; } if ( getParameters().size() != 1 ) { return false; } if ( getName().startsWith( "set" ) ) { return ( getName().length() > 3 && Character.isUpperCase( getName().charAt( 3 ) ) ); } return false; } /** {@inheritDoc} */ public JavaType getPropertyType() { if ( isPropertyAccessor() ) { return getReturns(); } if ( isPropertyMutator() ) { return getParameters().get(0).getType(); } return null; } /** {@inheritDoc} */ public String getPropertyName() { int start = -1; if ( getName().startsWith( "get" ) || getName().startsWith( "set" ) ) { start = 3; } else if ( getName().startsWith( "is" ) ) { start = 2; } else { return null; } return Introspector.decapitalize( getName().substring( start ) ); } @Override public String toString() { StringBuilder result = new StringBuilder(); if ( isPrivate() ) { result.append( "private " ); } else if ( isProtected() ) { result.append( "protected " ); } else if ( isPublic() ) { result.append( "public " ); } if ( isAbstract() ) { result.append( "abstract " ); } if ( isStatic() ) { result.append( "static " ); } if ( isFinal() ) { result.append( "final " ); } if ( isSynchronized() ) { result.append( "synchronized " ); } if ( isNative() ) { result.append( "native " ); } result.append( getReturns().getFullyQualifiedName() ).append( ' ' ); if ( getDeclaringClass() != null ) { result.append( getDeclaringClass().getBinaryName() ); result.append( "." ); } result.append( getName() ); result.append( "(" ); for ( int paramIndex = 0; paramIndex < getParameters().size(); paramIndex++ ) { if ( paramIndex > 0 ) { result.append( "," ); } JavaType originalType = getParameters().get( paramIndex ).getType(); JavaTypeVariable typeVariable = DefaultJavaType.resolve( originalType, getTypeParameters() ); result.append( typeVariable == null ? originalType.getFullyQualifiedName() : typeVariable.getBounds().get( 0 ).getFullyQualifiedName() ); } result.append( ")" ); if ( getExceptions().size() > 0 ) { result.append( " throws " ); for ( Iterator excIter = getExceptions().iterator(); excIter.hasNext(); ) { result.append( excIter.next().getFullyQualifiedName() ); if ( excIter.hasNext() ) { result.append( "," ); } } } return result.toString(); } /** {@inheritDoc} */ public JavaType getReturnType() { return getReturnType( false ); } /** {@inheritDoc} */ public JavaType getReturnType( boolean resolve ) { return returns; } /** {@inheritDoc} */ public boolean signatureMatches( String name, List parameterTypes ) { return signatureMatches( name, parameterTypes, false ); } /** {@inheritDoc} */ public boolean signatureMatches( String name, List parameterTypes, boolean varArg ) { if ( !name.equals( this.getName() ) ) { return false; } return signatureMatches( parameterTypes, varArg ); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaModule.java000066400000000000000000000016351325201777200307710ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import com.thoughtworks.qdox.model.JavaModule; import com.thoughtworks.qdox.model.JavaModuleDescriptor; public class DefaultJavaModule extends AbstractJavaModel implements JavaModule { private String name; private JavaModuleDescriptor descriptor; public DefaultJavaModule( String name, JavaModuleDescriptor descriptor ) { this.name = name; this.descriptor = descriptor; } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writeModuleDescriptor( this.descriptor ).toString(); } /** {@inheritDoc} */ public String getName() { return name; } /** {@inheritDoc} */ public boolean isNamed() { return name != null; } /** {@inheritDoc} */ public JavaModuleDescriptor getDescriptor() { return descriptor; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaModuleDescriptor.java000066400000000000000000000172401325201777200330270ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaModule; import com.thoughtworks.qdox.model.JavaModuleDescriptor; import com.thoughtworks.qdox.model.JavaPackage; public class DefaultJavaModuleDescriptor implements JavaModuleDescriptor { private String name; private boolean open; private Collection requires = new ArrayList(); private Collection exports = new ArrayList(); private Collection opens = new ArrayList(); private Collection uses = new ArrayList(); private Collection provides = new ArrayList(); public DefaultJavaModuleDescriptor( String name ) { this.name = name; } /** {@inheritDoc} */ public String getName() { return name; } public void setOpen( boolean open ) { this.open = open; } /** {@inheritDoc} */ public boolean isOpen() { return open; } public void addExports( DefaultJavaExports exports ) { this.exports.add( exports ); } /** {@inheritDoc} */ public Collection getExports() { return Collections.unmodifiableCollection( exports ); } public void addOpens( DefaultJavaOpens opens ) { this.opens.add( opens ); } /** {@inheritDoc} */ public Collection getOpens() { return Collections.unmodifiableCollection( opens ); } public void addRequires( DefaultJavaRequires requires ) { this.requires.add( requires ); } /** {@inheritDoc} */ public Collection getRequires() { return Collections.unmodifiableCollection( requires ); } public void addProvides( DefaultJavaProvides provides ) { this.provides.add( provides); } /** {@inheritDoc} */ public Collection getProvides() { return Collections.unmodifiableCollection( provides ); } public void addUses( DefaultJavaUses uses) { this.uses.add( uses ); } /** {@inheritDoc} */ public Collection getUses() { return Collections.unmodifiableCollection( uses ); } public static class DefaultJavaExports extends AbstractJavaModel implements JavaModuleDescriptor.JavaExports { private JavaPackage source; private Collection targets; public DefaultJavaExports( JavaPackage source, Collection targets ) { this.source = source; this.targets = targets; } /** {@inheritDoc} */ public JavaPackage getSource() { return source; } /** {@inheritDoc} */ public Collection getTargets() { if( targets == null ) { return Collections.emptyList(); } else { return targets; } } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writeModuleExports( this ).toString(); } } public static class DefaultJavaOpens extends AbstractJavaModel implements JavaModuleDescriptor.JavaOpens { private JavaPackage source; private Collection targets; public DefaultJavaOpens( JavaPackage source, Collection targets ) { this.source = source; this.targets = targets; } public String source() { return source.getName(); } /** {@inheritDoc} */ public JavaPackage getSource() { return source; } /** {@inheritDoc} */ public Collection getTargets() { if( targets == null ) { return Collections.emptyList(); } else { return targets; } } public Set targets() { if( targets == null ) { return Collections.emptySet(); } else { Set targetValues = new LinkedHashSet( targets.size() ); for ( JavaModule target : targets ) { targetValues.add( target.getName() ); } return Collections.unmodifiableSet( targetValues ); } } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writeModuleOpens( this ).toString(); } } public static class DefaultJavaProvides extends AbstractJavaModel implements JavaModuleDescriptor.JavaProvides { private JavaClass service; private List providers; public DefaultJavaProvides( JavaClass service, List providers ) { super(); this.service = service; this.providers = providers; } /** {@inheritDoc} */ public JavaClass getService() { return service; } /** {@inheritDoc} */ public List getProviders() { return providers; } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writeModuleProvides( this ).toString(); } } public static class DefaultJavaRequires extends AbstractJavaModel implements JavaModuleDescriptor.JavaRequires { private JavaModule module; private Collection modifiers; public DefaultJavaRequires( JavaModule module, Collection modifiers ) { this.module = module; this.modifiers = modifiers; } /** {@inheritDoc} */ public JavaModule getModule() { return module; } /** {@inheritDoc} */ public boolean isTransitive() { return getModifiers().contains( "transitive" ); } /** {@inheritDoc} */ public boolean isStatic() { return getModifiers().contains( "static" ); } /** {@inheritDoc} */ public Collection getModifiers() { if( modifiers == null ) { return Collections.emptyList(); } else { return modifiers; } } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writeModuleRequires( this ).toString(); } } public static class DefaultJavaUses extends AbstractJavaModel implements JavaModuleDescriptor.JavaUses { private JavaClass service; public DefaultJavaUses( JavaClass service ) { this.service = service; } /** {@inheritDoc} */ public JavaClass getService() { return service; } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writeModuleUses( this ).toString(); } } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaPackage.java000066400000000000000000000103111325201777200310660ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.Collection; import java.util.LinkedList; import java.util.List; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaModelUtils; import com.thoughtworks.qdox.model.JavaPackage; /** * The default implementation of {@link JavaPackage}, representing a {@link Package}. * * @since 1.9 */ public class DefaultJavaPackage extends AbstractBaseJavaEntity implements JavaPackage { private ClassLibrary classLibrary; private String name; private List classes = new LinkedList(); /** * * @param name the name of the package, should never be null */ public DefaultJavaPackage(String name) { this.name= name; } /** {@inheritDoc} */ public String getName() { return name; } public void setName(String name) { this.name = name; } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writePackage(this).toString(); } public void setClassLibrary( ClassLibrary classLibrary ) { this.classLibrary = classLibrary; } /** {@inheritDoc} */ public ClassLibrary getJavaClassLibrary() { return classLibrary; } public void addClass(JavaClass clazz) { classes.add(clazz); } /** {@inheritDoc} */ public Collection getClasses() { //avoid infinitive recursion if (this == classLibrary.getJavaPackage( name )) { return classes; } else { return classLibrary.getJavaPackage( name ).getClasses(); } } /** {@inheritDoc} */ public JavaClass getClassByName(String name) { JavaClass result = null; for ( JavaClass candidateCls : classes ) { result = JavaModelUtils.getClassByName( candidateCls, name ); if ( result != null ) { result = candidateCls; break; } } return result; } /** {@inheritDoc} */ public JavaPackage getParentPackage() { String parentName = name.substring( 0, name.lastIndexOf( '.' ) ); return classLibrary.getJavaPackage( parentName ); } /** {@inheritDoc} */ public List getSubPackages() { String expected = name + "."; Collection jPackages = classLibrary.getJavaPackages(); List retList = new LinkedList(); for (JavaPackage jPackage : jPackages) { String pName = jPackage.getName(); if (pName.startsWith(expected) && !(pName.substring(expected.length()).indexOf(".") > -1)) { retList.add(classLibrary.getJavaPackage( pName )); } } return retList; } @Override public boolean equals( Object o ) { if ( this == o ) { return true; } if ( !( o instanceof JavaPackage ) ) { return false; } JavaPackage that = (JavaPackage) o; return ( name.equals( that.getName() ) ); } @Override public int hashCode() { return 11 + name.hashCode(); } @Override public String toString() { return "package " + name; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaParameter.java000066400000000000000000000113341325201777200314610ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.JavaExecutable; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class DefaultJavaParameter extends AbstractBaseJavaEntity implements JavaParameter { private String name; private JavaClass type; private JavaExecutable executable; private boolean varArgs; public DefaultJavaParameter( JavaClass type, String name ) { this( type, name, false ); } public DefaultJavaParameter( JavaClass type, String name, boolean varArgs ) { this.name = name; this.type = type; this.varArgs = varArgs; } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writeParameter( this ).toString(); } public void setName( String name ) { this.name = name; } /** {@inheritDoc} */ public String getName() { return name; } /** {@inheritDoc} */ public JavaType getType() { return type; } /** {@inheritDoc} */ public JavaClass getJavaClass() { return type; } /** {@inheritDoc} */ public JavaExecutable getExecutable() { return executable; } public void setExecutable( JavaExecutable executable ) { this.executable = executable; } /** {@inheritDoc} */ @Override public JavaClass getDeclaringClass() { return getExecutable().getDeclaringClass(); } /** {@inheritDoc} */ public boolean isVarArgs() { return varArgs; } /** {@inheritDoc} */ public String getBinaryName() { return type.getBinaryName(); } /** {@inheritDoc} */ public String getFullyQualifiedName() { return type.getFullyQualifiedName(); } /** {@inheritDoc} */ public String getCanonicalName() { return type.getCanonicalName(); } /** {@inheritDoc} */ public String getValue() { return type.getValue(); } /** {@inheritDoc} */ public String getGenericCanonicalName() { return type.getGenericCanonicalName(); } /** {@inheritDoc} */ public String getGenericFullyQualifiedName() { return type.getGenericFullyQualifiedName(); } /** {@inheritDoc} */ public String getResolvedValue() { return DefaultJavaType.getResolvedValue( type, getExecutable().getTypeParameters() ); } /** {@inheritDoc} */ public String getResolvedFullyQualifiedName() { return DefaultJavaType.getResolvedFullyQualifiedName( type, getExecutable().getTypeParameters() ); } /** {@inheritDoc} */ public String getResolvedGenericValue() { return DefaultJavaType.getResolvedGenericValue( type, getExecutable().getTypeParameters() ); } /** {@inheritDoc} */ public String getResolvedGenericFullyQualifiedName() { return DefaultJavaType.getResolvedGenericFullyQualifiedName( type, getExecutable().getTypeParameters() ); } @Override public int hashCode() { return 13 + ( isVarArgs() ? 1 : 0 ) + getType().hashCode(); } @Override public boolean equals( Object obj ) { if ( this == obj ) { return true; } if ( !( obj instanceof JavaParameter ) ) { return false; } JavaParameter p = (JavaParameter) obj; // name should not be used in equality check. return getType().equals( p.getType() ) && isVarArgs() == p.isVarArgs(); } @Override public String toString() { return getResolvedValue() + " "+ name; } /** {@inheritDoc} */ public String getGenericValue() { return type.getGenericValue(); } /** {@inheritDoc} */ public String toGenericString() { return type.toGenericString(); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaParameterizedType.java000066400000000000000000000101231325201777200331720ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.Collections; import java.util.Iterator; import java.util.List; import com.thoughtworks.qdox.model.JavaParameterizedType; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.type.TypeResolver; public class DefaultJavaParameterizedType extends DefaultJavaType implements JavaParameterizedType { private List actualArgumentTypes = Collections.emptyList(); public DefaultJavaParameterizedType( String fullName, String name, int dimensions, TypeResolver typeResolver ) { super( fullName, name, dimensions, typeResolver ); } /** {@inheritDoc} */ public List getActualTypeArguments() { return actualArgumentTypes; } public void setActualArgumentTypes( List actualArgumentTypes ) { this.actualArgumentTypes = actualArgumentTypes; } /** {@inheritDoc} */ @Override public String getGenericValue() { StringBuilder result = new StringBuilder( name ); if ( !actualArgumentTypes.isEmpty() ) { result.append( "<" ); for ( Iterator iter = actualArgumentTypes.iterator(); iter.hasNext(); ) { result.append( iter.next().getGenericValue() ); if ( iter.hasNext() ) { result.append( "," ); } } result.append( ">" ); } for ( int i = 0; i < getDimensions(); i++ ) { result.append( "[]" ); } return result.toString(); } /** {@inheritDoc} */ @Override public String getGenericCanonicalName() { String base = isArray() ? getComponentType().getCanonicalName() : getCanonicalName(); StringBuilder result = new StringBuilder( base ); if ( !actualArgumentTypes.isEmpty() ) { result.append( "<" ); for ( Iterator iter = actualArgumentTypes.iterator(); iter.hasNext(); ) { result.append( iter.next().getGenericCanonicalName() ); if ( iter.hasNext() ) { result.append( "," ); } } result.append( ">" ); } for ( int i = 0; i < getDimensions(); i++ ) { result.append( "[]" ); } return result.toString(); } /** {@inheritDoc} */ @Override public String getGenericFullyQualifiedName() { StringBuilder result = new StringBuilder( isResolved() ? fullName : name ); if ( !actualArgumentTypes.isEmpty() ) { result.append( "<" ); for ( Iterator iter = actualArgumentTypes.iterator(); iter.hasNext(); ) { result.append( iter.next().getGenericFullyQualifiedName() ); if ( iter.hasNext() ) { result.append( "," ); } } result.append( ">" ); } for ( int i = 0; i < getDimensions(); i++ ) { result.append( "[]" ); } return result.toString(); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaSource.java000066400000000000000000000110531325201777200307770ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.Serializable; import java.net.URL; import java.util.Collections; import java.util.LinkedList; import java.util.List; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaModelUtils; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.writer.ModelWriter; import com.thoughtworks.qdox.writer.ModelWriterFactory; import com.thoughtworks.qdox.writer.impl.DefaultModelWriter; public class DefaultJavaSource implements JavaSource, Serializable { private final ClassLibrary classLibrary; private ModelWriterFactory modelWriterFactory; private JavaPackage pkg; private final List imports = new LinkedList(); private List classes = new LinkedList(); private URL url; /** * Default constructor for the Default JavaSource * * @param classLibrary the classLibrary, should not be null */ public DefaultJavaSource( ClassLibrary classLibrary ) { this.classLibrary = classLibrary; } /** * @param url the URL of the source file * @since 1.4 */ public void setURL(URL url) { this.url = url; } /** {@inheritDoc} */ public URL getURL() { return url; } /** {@inheritDoc} */ public JavaPackage getPackage() { return pkg; } public void setPackage(JavaPackage pkg) { this.pkg = pkg; } public void addImport(String imp) { imports.add(imp); } /** {@inheritDoc} */ public List getImports() { return imports; } public void addClass(JavaClass cls) { classes.add(cls); } /** {@inheritDoc} */ public List getClasses() { return Collections.unmodifiableList( classes ); } /** {@inheritDoc} */ public String getCodeBlock() { return getModelWriter().writeSource( this ).toString(); } @Override public String toString() { return getCodeBlock(); } /** {@inheritDoc} */ public String getClassNamePrefix() { return ( pkg == null ? "" : pkg.getName() + '.' ); } /** {@inheritDoc} */ public JavaClass getNestedClassByName(String name) { JavaClass result = null; for (JavaClass candidateCls : classes) { if (candidateCls.getName().equals(name)) { result = candidateCls; break; } } return result; } /** {@inheritDoc} */ public JavaClass getClassByName(String name) { JavaClass result = null; for ( JavaClass candidateCls : classes ) { result = JavaModelUtils.getClassByName( candidateCls, name ); if ( result != null ) { break; } } return result; } /** {@inheritDoc} */ public ClassLibrary getJavaClassLibrary() { return classLibrary; } /** {@inheritDoc} */ public String getPackageName() { return ( pkg == null ? "" : pkg.getName() ); } /** * * @param modelWriterFactory the modelWriterFactory * @since 2.0 */ public void setModelWriterFactory( ModelWriterFactory modelWriterFactory ) { this.modelWriterFactory = modelWriterFactory; } private ModelWriter getModelWriter() { ModelWriter result; if ( modelWriterFactory != null ) { result = modelWriterFactory.newInstance(); } else { result = new DefaultModelWriter(); } return result; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaType.java000066400000000000000000000641531325201777200304710ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.Serializable; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.model.BeanProperty; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaConstructor; import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaGenericDeclaration; import com.thoughtworks.qdox.model.JavaInitializer; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaParameterizedType; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.JavaTypeVariable; import com.thoughtworks.qdox.type.TypeResolver; /** * The default implementation for {@link JavaType} * * @author Robert Scholte * @since 2.0 */ public class DefaultJavaType implements JavaClass, JavaType, Serializable { protected final String name; protected String fullName; private int dimensions; private TypeResolver typeResolver; DefaultJavaType( String name, TypeResolver typeResolver ) { this.name = name; this.typeResolver = typeResolver; } DefaultJavaType(String fullName, String name, int dimensions, TypeResolver typeResolver) { this.fullName = fullName; this.name = name; this.dimensions = dimensions; this.typeResolver = typeResolver; } /** * Should only be used by primitives, since they don't have a classloader. * * @param fullName the name of the primitive * @param dimensions number of dimensions */ DefaultJavaType(String fullName, int dimensions) { this.name = fullName; this.fullName = fullName; this.dimensions = dimensions; } /** * Should only be used by primitives and wildcard, since they don't have a classloader. * * @param fullName the name of the primitive or ? */ DefaultJavaType( String fullName ) { this( fullName, 0 ); } /** {@inheritDoc} */ public String getBinaryName() { return resolveRealClass().getBinaryName(); } /** {@inheritDoc} */ public String getSimpleName() { StringBuilder result = new StringBuilder( resolveRealClass().getSimpleName() ); for (int i = 0; i < dimensions; i++) { result.append("[]"); } return result.toString(); } /** {@inheritDoc} */ public String getFullyQualifiedName() { StringBuilder result = new StringBuilder( resolveRealClass().getFullyQualifiedName() ); for (int i = 0; i < dimensions; i++) { result.append("[]"); } return result.toString(); } /** {@inheritDoc}*/ public JavaClass getComponentType() { return isArray() ? resolveRealClass() : null; } /** {@inheritDoc}*/ public String getValue() { StringBuilder result = new StringBuilder( name ); for (int i = 0; i < dimensions; i++) { result.append("[]"); } return result.toString(); } /** {@inheritDoc}*/ public String getGenericValue() { StringBuilder result = new StringBuilder( getValue() ); for ( int i = 0; i < dimensions; i++ ) { result.append( "[]" ); } return result.toString(); } protected static String getGenericValue( JavaType base, List> typeVariableList ) { StringBuilder result = new StringBuilder( getResolvedValue( base, typeVariableList ) ); for ( Iterator iter = getActualTypeArguments( base ).iterator(); iter.hasNext(); ) { result.append( DefaultJavaType.resolve( base, typeVariableList ) ); if ( iter.hasNext() ) { result.append( "," ); } } return result.toString(); } private static List getActualTypeArguments( JavaType base ) { List result; if ( base instanceof JavaParameterizedType ) { result = ( (JavaParameterizedType) base ).getActualTypeArguments(); } else { result = Collections.emptyList(); } return result; } protected static String getResolvedValue( JavaType base, List> typeParameters ) { String result = base.getValue(); for ( JavaTypeVariable typeParameter : typeParameters ) { if ( typeParameter.getName().equals( base.getValue() ) ) { result = typeParameter.getBounds().get( 0 ).getValue(); break; } } return result; } protected static JavaTypeVariable resolve( JavaType base, List> typeParameters ) { JavaTypeVariable result = null; // String result = getGenericValue(typeParameters); for ( JavaTypeVariable typeParameter : typeParameters ) { if ( typeParameter.getName().equals( base.getValue() ) ) { result = typeParameter; break; } } return result; } protected boolean isResolved() { if ( fullName == null && typeResolver != null ) { fullName = typeResolver.resolveType( name ); } return ( fullName != null ); } /** {@inheritDoc} */ public boolean isArray() { return dimensions > 0; } /** {@inheritDoc} */ public int getDimensions() { return dimensions; } /** * Equivalent of {@link Class#toString()}. * Converts the object to a string. * * @return a string representation of this type. * @see Class#toString() */ @Override public String toString() { return getFullyQualifiedName(); } /** * Returns getGenericValue() extended with the array information * *

     * Object > java.lang.Object
     * Object[] > java.lang.Object[]
     * List<Object> > java.lang.List<java.lang.Object>
     * Outer.Inner > Outer$Inner
     * Outer.Inner<Object>[][] > Outer$Inner<java.lang.Object>[][] 
     * 
* @return a generic string representation of this type. */ public String toGenericString() { return getGenericFullyQualifiedName(); } @Override public boolean equals( Object obj ) { if ( this == obj ) { return true; } if ( !( obj instanceof JavaType ) ) { return false; } JavaType t = (JavaType) obj; return getFullyQualifiedName().equals( t.getFullyQualifiedName() ); } @Override public int hashCode() { return getFullyQualifiedName().hashCode(); } private JavaClass resolveRealClass() { JavaClass result = null; String qualifiedName = isResolved() ? fullName : name; if ( isPrimitive( qualifiedName ) ) { result = new DefaultJavaClass( qualifiedName ); } else { result = typeResolver.getJavaClass( qualifiedName ); } return result; } /** * @param type the type to match with * @return {@code true} if this type if of type, otherwise {@code false} * @since 1.3 */ public boolean isA( JavaType type ) { if ( this == type ) { return true; } else { return this.isA( type ); } } /** {@inheritDoc} */ public boolean isPrimitive() { return isPrimitive( getValue() ); } private static boolean isPrimitive( String value ) { return "void".equals(value) || "boolean".equals(value) || "byte".equals(value) || "char".equals(value) || "short".equals(value) || "int".equals(value) || "long".equals(value) || "float".equals(value) || "double".equals(value); } /** {@inheritDoc} */ public boolean isVoid() { return "void".equals(getValue()); } /** * Consider the following example * *
     *  public abstract class AbstractClass<T> 
     *  {
     *    private T value;
     *    
     *    public AbstractClass( T value ) { this.value = value; }
     *    
     *    public T getValue() { return value; }
     *  }
     *  
     *  public class ConcreteClass extends AbstractClass<String>
     *  {
     *    public ConcreteClass( String s ) { super( s ); }
     *  }
     *  
*

* We want to know the resolved returnType when calling ConcreteClass.getValue(). * The expected type is String. *

* *
    *
  • {@code this} would be T
  • *
  • {@code declaringClass} would be AbstractClass, since that's where T is used
  • *
  • {@code callingClass} would be ConcreteClass
  • *
* * @param base the base * @param declaringClass the declaring class * @param callingClass the calling class * @return the resolved type */ protected static JavaType resolve( JavaType base, JavaClass declaringClass, JavaClass callingClass ) { JavaType result = base; String concreteClassName; if ( base instanceof JavaClass ) { JavaClass baseClass = (JavaClass) base; concreteClassName = ( baseClass.isArray() ? baseClass.getComponentType().getFullyQualifiedName() : baseClass.getFullyQualifiedName() ); } else { concreteClassName = base.getFullyQualifiedName(); } int typeIndex = getTypeVariableIndex( declaringClass, concreteClassName ); if ( typeIndex >= 0 ) { String fqn = declaringClass.getFullyQualifiedName(); if ( callingClass.getSuperClass() != null && fqn.equals( callingClass.getSuperClass().getFullyQualifiedName() ) ) { result = getActualTypeArguments( callingClass.getSuperClass() ).get( typeIndex ); } else { for ( JavaClass implement : callingClass.getInterfaces() ) { if ( fqn.equals( implement.getFullyQualifiedName() ) ) { JavaType actualType = getActualTypeArguments( implement ).get( typeIndex ); TypeResolver typeResolver = TypeResolver.byPackageName( implement.getSource().getPackageName(), implement.getSource().getJavaClassLibrary(), implement.getSource().getImports() ); JavaType resolvedType = new DefaultJavaType( actualType.getFullyQualifiedName(), actualType.getValue(), getDimensions( base ), typeResolver ); result = resolve( resolvedType , implement, implement ); break; } else { // no direct interface available, try indirect result = resolve( base, implement, callingClass ); } } } } List actualTypeArguments = getActualTypeArguments(base); if ( !actualTypeArguments.isEmpty() ) { String value = base.getValue(); if( value.indexOf( '[' ) > 0 ) { value = value.substring( 0, value.indexOf( '[' ) ); } TypeResolver typeResolver = TypeResolver.byPackageName(null, declaringClass.getJavaClassLibrary(), null ); DefaultJavaParameterizedType typeResult = new DefaultJavaParameterizedType( concreteClassName, value, getDimensions( base ), typeResolver ); List actualTypes = new LinkedList(); for ( JavaType actualArgType : actualTypeArguments ) { actualTypes.add( resolve( actualArgType, declaringClass, callingClass ) ); } typeResult.setActualArgumentTypes( actualTypes ); result = typeResult; } return result; } private static int getDimensions( JavaType type ) { return type instanceof JavaClass ? ( (JavaClass) type ).getDimensions() : 0; } private static int getTypeVariableIndex( JavaClass declaringClass, String fqn ) { int typeIndex = -1; for ( JavaTypeVariable typeVariable : declaringClass.getTypeParameters() ) { typeIndex++; if ( typeVariable.getFullyQualifiedName().equals( fqn ) ) { return typeIndex; } } return -1; } /** {@inheritDoc} */ public String getGenericFullyQualifiedName() { StringBuilder result = new StringBuilder( isResolved() ? fullName : name ); for ( int i = 0; i < dimensions; i++ ) { result.append( "[]" ); } return result.toString(); } /** {@inheritDoc} */ public String getGenericCanonicalName() { StringBuilder result = new StringBuilder( getCanonicalName() ); for ( int i = 0; i < dimensions; i++ ) { result.append( "[]" ); } return result.toString(); } protected static String getResolvedGenericValue( JavaType base, List> typeParameters ) { StringBuilder result = new StringBuilder(); JavaTypeVariable variable = resolve( base, typeParameters ); result.append( variable == null ? base.getValue() : variable.getBounds().get(0).getValue() ); List actualTypeArguments = getActualTypeArguments( base ); if ( !actualTypeArguments.isEmpty() ) { result.append( "<" ); for ( Iterator iter = actualTypeArguments.iterator(); iter.hasNext(); ) { result.append( getGenericValue( iter.next(), typeParameters) ); if ( iter.hasNext() ) { result.append( "," ); } } result.append( ">" ); } if( base instanceof JavaClass ) { for ( int i = 0; i < ( (JavaClass) base ).getDimensions(); i++ ) { result.append( "[]" ); } } return result.toString(); } protected static String getResolvedGenericFullyQualifiedName( JavaType base, List> typeParameters ) { StringBuilder result = new StringBuilder(); JavaTypeVariable variable = resolve( base, typeParameters ); result.append( variable == null ? base.getFullyQualifiedName() : variable.getBounds().get(0).getFullyQualifiedName() ); List actualTypeArguments = getActualTypeArguments( base ); if ( !actualTypeArguments.isEmpty() ) { result.append( "<" ); for ( Iterator iter = actualTypeArguments.iterator(); iter.hasNext(); ) { result.append( getResolvedFullyQualifiedName( iter.next(), typeParameters) ); if ( iter.hasNext() ) { result.append( "," ); } } result.append( ">" ); } if ( base instanceof JavaClass ) { for ( int i = 0; i < ( (JavaClass) base ).getDimensions(); i++ ) { result.append( "[]" ); } } return result.toString(); } protected static String getResolvedFullyQualifiedName( JavaType base, List> typeParameters ) { JavaTypeVariable variable = resolve( base, typeParameters ); return (variable == null ? base.getFullyQualifiedName() : variable.getBounds().get(0).getFullyQualifiedName() ); } //Delegating methods /** {@inheritDoc} */ public JavaSource getSource() { return resolveRealClass().getSource(); } /** {@inheritDoc} */ public int getLineNumber() { return resolveRealClass().getLineNumber(); } /** {@inheritDoc} */ public boolean isInterface() { return resolveRealClass().isInterface(); } /** {@inheritDoc} */ public List getAnnotations() { return resolveRealClass().getAnnotations(); } /** {@inheritDoc} */ public boolean isEnum() { return resolveRealClass().isEnum(); } /** {@inheritDoc} */ public String getComment() { return resolveRealClass().getComment(); } /** {@inheritDoc} */ public List getTags() { return resolveRealClass().getTags(); } /** {@inheritDoc} */ public boolean isAnnotation() { return resolveRealClass().isAnnotation(); } /** {@inheritDoc} */ public List getTagsByName( String name ) { return resolveRealClass().getTagsByName( name ); } /** {@inheritDoc} */ public DocletTag getTagByName( String name ) { return resolveRealClass().getTagByName( name ); } /** {@inheritDoc} */ public JavaType getSuperClass() { return resolveRealClass().getSuperClass(); } /** {@inheritDoc} */ public JavaClass getSuperJavaClass() { return resolveRealClass().getSuperJavaClass(); } /** {@inheritDoc} */ public List getImplements() { return resolveRealClass().getImplements(); } /** {@inheritDoc} */ public List getInterfaces() { return resolveRealClass().getInterfaces(); } /** {@inheritDoc} */ public String getNamedParameter( String tagName, String parameterName ) { return resolveRealClass().getNamedParameter( tagName, parameterName ); } /** {@inheritDoc} */ public String getCodeBlock() { return resolveRealClass().getCodeBlock(); } /** {@inheritDoc} */ public List> getTypeParameters() { return resolveRealClass().getTypeParameters(); } /** {@inheritDoc} */ public JavaSource getParentSource() { return resolveRealClass().getParentSource(); } /** {@inheritDoc} */ public JavaPackage getPackage() { return resolveRealClass().getPackage(); } /** {@inheritDoc} */ public String getPackageName() { return resolveRealClass().getPackageName(); } /** {@inheritDoc} */ public boolean isInner() { return resolveRealClass().isInner(); } /** {@inheritDoc} */ public List getInitializers() { return resolveRealClass().getInitializers(); } /** {@inheritDoc} */ public List getMethods() { return resolveRealClass().getMethods(); } /** {@inheritDoc} */ public List getConstructors() { return resolveRealClass().getConstructors(); } /** {@inheritDoc} */ public JavaConstructor getConstructor( List parameterTypes ) { return resolveRealClass().getConstructor( parameterTypes ); } /** {@inheritDoc} */ public JavaConstructor getConstructor( List parameterTypes, boolean varArg ) { return resolveRealClass().getConstructor( parameterTypes, varArg ); } /** {@inheritDoc} */ public List getMethods( boolean superclasses ) { return resolveRealClass().getMethods( superclasses ); } /** {@inheritDoc} */ public JavaMethod getMethodBySignature( String name, List parameterTypes ) { return resolveRealClass().getMethodBySignature( name, parameterTypes ); } /** {@inheritDoc} */ public JavaMethod getMethod( String name, List parameterTypes, boolean varArgs ) { return resolveRealClass().getMethod( name, parameterTypes, varArgs ); } /** {@inheritDoc} */ public JavaMethod getMethodBySignature( String name, List parameterTypes, boolean superclasses ) { return resolveRealClass().getMethodBySignature( name, parameterTypes, superclasses ); } /** {@inheritDoc} */ public JavaMethod getMethodBySignature( String name, List parameterTypes, boolean superclasses, boolean varArg ) { return resolveRealClass().getMethodBySignature( name, parameterTypes, superclasses, varArg ); } /** {@inheritDoc} */ public List getMethodsBySignature( String name, List parameterTypes, boolean superclasses ) { return resolveRealClass().getMethodsBySignature( name, parameterTypes, superclasses ); } /** {@inheritDoc} */ public List getMethodsBySignature( String name, List parameterTypes, boolean superclasses, boolean varArg ) { return resolveRealClass().getMethodsBySignature( name, parameterTypes, superclasses, varArg ); } /** {@inheritDoc} */ public List getFields() { return resolveRealClass().getFields(); } /** {@inheritDoc} */ public JavaField getFieldByName( String name ) { return resolveRealClass().getFieldByName( name ); } /** {@inheritDoc} */ public List getEnumConstants() { return resolveRealClass().getEnumConstants(); } /** {@inheritDoc} */ public JavaField getEnumConstantByName( String name ) { return resolveRealClass().getEnumConstantByName( name ); } /** {@inheritDoc} */ public List getNestedClasses() { return resolveRealClass().getNestedClasses(); } /** {@inheritDoc} */ public JavaClass getNestedClassByName( String name ) { return resolveRealClass().getNestedClassByName( name ); } /** {@inheritDoc} */ public boolean isA( String fullClassName ) { return resolveRealClass().isA( fullClassName ); } /** {@inheritDoc} */ public boolean isA( JavaClass javaClass ) { return resolveRealClass().isA( javaClass ); } /** {@inheritDoc} */ public List getBeanProperties() { return resolveRealClass().getBeanProperties(); } /** {@inheritDoc} */ public List getBeanProperties( boolean superclasses ) { return resolveRealClass().getBeanProperties( superclasses ); } /** {@inheritDoc} */ public BeanProperty getBeanProperty( String propertyName ) { return resolveRealClass().getBeanProperty( propertyName ); } /** {@inheritDoc} */ public BeanProperty getBeanProperty( String propertyName, boolean superclasses ) { return resolveRealClass().getBeanProperty( propertyName, superclasses ); } /** {@inheritDoc} */ public List getDerivedClasses() { return resolveRealClass().getDerivedClasses(); } /** {@inheritDoc} */ public List getTagsByName( String name, boolean superclasses ) { return resolveRealClass().getTagsByName( name, superclasses ); } /** {@inheritDoc} */ public ClassLibrary getJavaClassLibrary() { return resolveRealClass().getJavaClassLibrary(); } /** {@inheritDoc} */ public String getName() { return resolveRealClass().getName(); } /** {@inheritDoc} */ public String getCanonicalName() { StringBuilder result = new StringBuilder( resolveRealClass().getCanonicalName() ); for (int i = 0; i < dimensions; i++) { result.append("[]"); } return result.toString(); } /** {@inheritDoc} */ public List getModifiers() { return resolveRealClass().getModifiers(); } /** {@inheritDoc} */ public boolean isPublic() { return resolveRealClass().isPublic(); } /** {@inheritDoc} */ public boolean isProtected() { return resolveRealClass().isProtected(); } /** {@inheritDoc} */ public boolean isPrivate() { return resolveRealClass().isPrivate(); } /** {@inheritDoc} */ public boolean isFinal() { return resolveRealClass().isFinal(); } /** {@inheritDoc} */ public boolean isStatic() { return resolveRealClass().isStatic(); } /** {@inheritDoc} */ public boolean isAbstract() { return resolveRealClass().isAbstract(); } /** {@inheritDoc} */ public JavaClass getDeclaringClass() { return resolveRealClass().getDeclaringClass(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaTypeVariable.java000066400000000000000000000104351325201777200321310ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.Iterator; import java.util.List; import com.thoughtworks.qdox.model.JavaGenericDeclaration; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.JavaTypeVariable; import com.thoughtworks.qdox.type.TypeResolver; /** * Equivalent of {@link java.lang.reflect.TypeVariable} * * @author Robert Scholte * @since 1.10 */ public class DefaultJavaTypeVariable extends DefaultJavaType implements JavaTypeVariable { private List bounds; private D genericDeclaration; public DefaultJavaTypeVariable( String name, TypeResolver typeResolver ) { super( name, typeResolver ); } /** {@inheritDoc} */ public List getBounds() { return bounds; } /** * @param bounds the bounds to set */ public void setBounds( List bounds ) { this.bounds = bounds; } /** {@inheritDoc} */ public D getGenericDeclaration() { return genericDeclaration; } @Override public String getFullyQualifiedName() { return getValue(); } @Override public String getGenericFullyQualifiedName() { StringBuilder result = new StringBuilder(); result.append( '<' ); result.append( super.getFullyQualifiedName() ); if ( bounds != null && !bounds.isEmpty() ) { result.append( " extends " ); for ( Iterator iter = bounds.iterator(); iter.hasNext(); ) { result.append( iter.next().getGenericFullyQualifiedName() ); if ( iter.hasNext() ) { result.append( " & " ); } } } result.append( '>' ); return result.toString(); } @Override public String getCanonicalName() { return super.getValue(); } @Override public String getGenericCanonicalName() { StringBuilder result = new StringBuilder(); result.append( '<' ); result.append( super.getGenericCanonicalName() ); if ( bounds != null && !bounds.isEmpty() ) { result.append( " extends " ); for ( Iterator iter = bounds.iterator(); iter.hasNext(); ) { result.append( iter.next().getGenericCanonicalName() ); if ( iter.hasNext() ) { result.append( " & " ); } } } result.append( '>' ); return result.toString(); } @Override public String getGenericValue() { StringBuilder result = new StringBuilder(); result.append( '<' ); result.append( getValue() ); if ( bounds != null && !bounds.isEmpty() ) { result.append( " extends " ); for ( Iterator iter = bounds.iterator(); iter.hasNext(); ) { result.append( iter.next().getGenericValue() ); if ( iter.hasNext() ) { result.append( "," ); } } } result.append( '>' ); return result.toString(); } @Override public String getName() { return getValue(); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaWildcardType.java000066400000000000000000000100031325201777200321240ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import java.util.Collections; import java.util.List; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.JavaWildcardType; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * Equivalent of {@link java.lang.reflect.WildcardType} * This class supports both the 'super' and 'extends' wildcards. For <?> you must use the normal Type, because ? * itself can't be generic * * @author Robert Scholte */ public class DefaultJavaWildcardType extends DefaultJavaType implements JavaWildcardType { public static enum BoundType { EXTENDS, SUPER } private BoundType boundType; private List bounds; public DefaultJavaWildcardType() { super( "?" ); bounds = Collections.emptyList(); } public DefaultJavaWildcardType( JavaType type, BoundType boundType ) { this(); bounds = Collections.singletonList( type ); this.boundType = boundType; } @Override public String getFullyQualifiedName() { StringBuilder builder = getPreparedStringBuilder(); for( JavaType type : bounds ) { builder.append( type.getFullyQualifiedName() ); } return builder.toString(); } @Override public String getGenericValue() { StringBuilder builder = getPreparedStringBuilder(); for( JavaType type : bounds ) { builder.append( type.getGenericValue() ); } return builder.toString(); } @Override public String getGenericFullyQualifiedName() { StringBuilder builder = getPreparedStringBuilder(); for( JavaType type : bounds ) { builder.append( type.getGenericFullyQualifiedName() ); } return builder.toString(); } @Override public String getCanonicalName() { StringBuilder builder = getPreparedStringBuilder(); for( JavaType type : bounds ) { builder.append( type.getCanonicalName() ); } return builder.toString(); } @Override public String getGenericCanonicalName() { StringBuilder builder = getPreparedStringBuilder(); for( JavaType type : bounds ) { builder.append( type.getGenericCanonicalName() ); } return builder.toString(); } @Override public String getValue() { StringBuilder builder = getPreparedStringBuilder(); for( JavaType type : bounds ) { builder.append( type.getValue() ); } return builder.toString(); } @Override public String toGenericString() { StringBuilder builder = getPreparedStringBuilder(); for( JavaType type : bounds ) { builder.append( type.toGenericString() ); } return builder.toString(); } private StringBuilder getPreparedStringBuilder() { StringBuilder builder = new StringBuilder( "?" ); if( BoundType.EXTENDS.equals( boundType ) ) { builder.append( " extends " ); } else if( BoundType.SUPER.equals( boundType ) ) { builder.append( " super " ); } return builder; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/JavaMethodDelegate.java000066400000000000000000000226261325201777200311150ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.LinkedList; import java.util.List; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.JavaTypeVariable; import com.thoughtworks.qdox.type.TypeResolver; /** * This class can be used to access overridden methods while keeping a reference to the original class. * This is especially useful when trying to resolve generics * * @author Robert Scholte * @since 1.12 */ public class JavaMethodDelegate implements JavaMethod { private JavaClass callingClass; private JavaMethod originalMethod; public JavaMethodDelegate( JavaClass callingClass, JavaMethod originalMethod ) { this.callingClass = callingClass; this.originalMethod = originalMethod; } public JavaType getReturnType( boolean resolve ) { JavaType result = originalMethod.getReturnType( resolve ); if (result != null) { String originalValue = result.getValue(); result = DefaultJavaType.resolve( result, originalMethod.getDeclaringClass(), callingClass ); //According to java-specs, if it could be resolved the upper boundary, so Object, should be returned if ( !resolve && !this.getReturns().getFullyQualifiedName().equals( result.getFullyQualifiedName() ) ) { TypeResolver typeResolver = TypeResolver.byClassName( callingClass.getBinaryName(), callingClass.getJavaClassLibrary(), callingClass.getSource().getImports() ); result = new DefaultJavaType( "java.lang.Object", originalValue, 0, typeResolver ); } } return result; } /** {@inheritDoc} */ public List getParameterTypes( boolean resolve ) { List result = new LinkedList(); for ( JavaType type : originalMethod.getParameterTypes( resolve ) ) { JavaType curType = DefaultJavaType.resolve( type, originalMethod.getDeclaringClass(), callingClass ); // According to java-specs, if it could be resolved the upper boundary, so Object, should be returned if ( !resolve && !type.getFullyQualifiedName().equals( curType.getFullyQualifiedName() ) ) { result.add( new DefaultJavaType( "java.lang.Object", 0 ) ); } else { result.add( curType ); } } return result; } @Override public boolean equals( Object obj ) { return originalMethod.equals( obj ); } /** {@inheritDoc} */ public List getAnnotations() { return originalMethod.getAnnotations(); } /** {@inheritDoc} */ public String getCallSignature() { return originalMethod.getCallSignature(); } /** {@inheritDoc} */ public String getCodeBlock() { return originalMethod.getCodeBlock(); } /** {@inheritDoc} */ public String getComment() { return originalMethod.getComment(); } /** {@inheritDoc} */ public JavaClass getDeclaringClass() { return originalMethod.getDeclaringClass(); } /** {@inheritDoc} */ public String getDeclarationSignature( boolean withModifiers ) { return originalMethod.getDeclarationSignature( withModifiers ); } /** {@inheritDoc} */ public List getExceptions() { return originalMethod.getExceptions(); } /** {@inheritDoc} */ public List getExceptionTypes() { return originalMethod.getExceptionTypes(); } /** {@inheritDoc} */ public boolean isDefault() { return originalMethod.isDefault(); } /** {@inheritDoc} */ public int getLineNumber() { return originalMethod.getLineNumber(); } /** {@inheritDoc} */ public List getModifiers() { return originalMethod.getModifiers(); } /** {@inheritDoc} */ public String getName() { return originalMethod.getName(); } /** {@inheritDoc} */ public String getNamedParameter( String tagName, String parameterName ) { return originalMethod.getNamedParameter( tagName, parameterName ); } /** {@inheritDoc} */ public JavaParameter getParameterByName( String name ) { return originalMethod.getParameterByName( name ); } /** {@inheritDoc} */ public List getParameters() { return originalMethod.getParameters(); } /** {@inheritDoc} */ public String getPropertyName() { return originalMethod.getPropertyName(); } /** {@inheritDoc} */ public JavaType getPropertyType() { return originalMethod.getPropertyType(); } /** {@inheritDoc} */ public JavaClass getReturns() { return originalMethod.getReturns(); } /** {@inheritDoc} */ public String getSourceCode() { return originalMethod.getSourceCode(); } /** {@inheritDoc} */ public DocletTag getTagByName( String name, boolean inherited ) { return originalMethod.getTagByName( name, inherited ); } /** {@inheritDoc} */ public DocletTag getTagByName( String name ) { return originalMethod.getTagByName( name ); } /** {@inheritDoc} */ public List getTags() { return originalMethod.getTags(); } /** {@inheritDoc} */ public List getTagsByName( String name, boolean inherited ) { return originalMethod.getTagsByName( name, inherited ); } /** {@inheritDoc} */ public List getTagsByName( String name ) { return originalMethod.getTagsByName( name ); } /** {@inheritDoc} */ public List> getTypeParameters() { return originalMethod.getTypeParameters(); } @Override public int hashCode() { return originalMethod.hashCode(); } /** {@inheritDoc} */ public boolean isAbstract() { return originalMethod.isAbstract(); } /** {@inheritDoc} */ public boolean isFinal() { return originalMethod.isFinal(); } /** {@inheritDoc} */ public boolean isNative() { return originalMethod.isNative(); } /** {@inheritDoc} */ public boolean isPrivate() { return originalMethod.isPrivate(); } /** {@inheritDoc} */ public boolean isPropertyAccessor() { return originalMethod.isPropertyAccessor(); } /** {@inheritDoc} */ public boolean isPropertyMutator() { return originalMethod.isPropertyMutator(); } /** {@inheritDoc} */ public boolean isProtected() { return originalMethod.isProtected(); } /** {@inheritDoc} */ public boolean isPublic() { return originalMethod.isPublic(); } /** {@inheritDoc} */ public boolean isStatic() { return originalMethod.isStatic(); } /** {@inheritDoc} */ public boolean isStrictfp() { return originalMethod.isStrictfp(); } /** {@inheritDoc} */ public boolean isSynchronized() { return originalMethod.isSynchronized(); } /** {@inheritDoc} */ public boolean isTransient() { return originalMethod.isTransient(); } /** {@inheritDoc} */ public boolean isVarArgs() { return originalMethod.isVarArgs(); } /** {@inheritDoc} */ public boolean isVolatile() { return originalMethod.isVolatile(); } /** {@inheritDoc} */ public boolean signatureMatches( String name, List parameterTypes, boolean varArg ) { return originalMethod.signatureMatches( name, parameterTypes, varArg ); } /** {@inheritDoc} */ public boolean signatureMatches( String name, List parameterTypes ) { return originalMethod.signatureMatches( name, parameterTypes ); } /** {@inheritDoc} */ @Override public String toString() { return originalMethod.toString(); } /** {@inheritDoc} */ public JavaType getReturnType() { return getReturnType( false ); } /** {@inheritDoc} */ public List getParameterTypes() { return getParameterTypes( false ); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/impl/package-info.java000066400000000000000000000003431325201777200277540ustar00rootroot00000000000000/** * Provides the default implementation of the classes reflecting the Java model elements. * These classes are often richer then their java.reflect equivalent. */ package com.thoughtworks.qdox.model.impl;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/package-info.java000066400000000000000000000002701325201777200270120ustar00rootroot00000000000000/** * Provides classes reflecting the Java model elements. * These classes are often richer then their java.reflect equivalent. */ package com.thoughtworks.qdox.model;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/util/000077500000000000000000000000001325201777200246015ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/util/TagParser.java000066400000000000000000000126721325201777200273440ustar00rootroot00000000000000package com.thoughtworks.qdox.model.util; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.IOException; import java.io.StreamTokenizer; import java.io.StringReader; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; public final class TagParser { private TagParser() { // hide utility class constructor } /** * Create a StreamTokenizer suitable for parsing the tag text. * * @param tagValue the tag value * @return the tokenizer */ static StreamTokenizer makeTokenizer(String tagValue) { StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(tagValue)); tokenizer.resetSyntax(); tokenizer.wordChars('A','Z'); tokenizer.wordChars('a','z'); tokenizer.wordChars('0','9'); tokenizer.wordChars('-','-'); tokenizer.wordChars('_','_'); tokenizer.wordChars('.','.'); tokenizer.wordChars('<','<'); tokenizer.wordChars('>','>'); tokenizer.quoteChar('\''); tokenizer.quoteChar('"'); tokenizer.whitespaceChars(' ',' '); tokenizer.whitespaceChars('\t','\t'); tokenizer.whitespaceChars('\n','\n'); tokenizer.whitespaceChars('\r','\r'); tokenizer.eolIsSignificant(false); return tokenizer; } /** * Extract a Map of named parameters * * @param tagValue the tag value * @return a Map with the parameter names and their values */ public static Map parseNamedParameters(String tagValue) { Map paramMap = new LinkedHashMap(); StreamTokenizer tokenizer = makeTokenizer(tagValue); try { while (tokenizer.nextToken() == StreamTokenizer.TT_WORD) { String key = tokenizer.sval; if (tokenizer.nextToken() != '=') { break; } switch (tokenizer.nextToken()) { case StreamTokenizer.TT_WORD: case '"': case '\'': paramMap.put(key, tokenizer.sval); default: break; } } } catch (IOException e) { // ignore } return paramMap; } /** * Extract an array of positional parameters * * @param tagValue the tag value * @return an array with words */ public static String[] parseWords(String tagValue) { StreamTokenizer tokenizer = makeTokenizer(tagValue); List wordList = new ArrayList(); try { while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) { if (tokenizer.sval == null) { wordList.add(Character.toString((char)tokenizer.ttype)); } else { wordList.add(tokenizer.sval); } } } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("error tokenizing tag"); } return wordList.toArray(new String[0]); } /** * Extract an array of parameters as name or name=value representation * * @param tagValue the tag value * @return the names of the parameters * @since 1.11 */ public static List parseParameters(String tagValue) { StreamTokenizer tokenizer = makeTokenizer(tagValue); List wordList = new LinkedList(); try { while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) { StringBuilder param = new StringBuilder(); if (tokenizer.sval != null) { param.append( tokenizer.sval ); } //check for parameterValues while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) { if(tokenizer.sval == null && ('=' == (char)tokenizer.ttype || ','== (char)tokenizer.ttype)){ param.append( Character.toString( (char)tokenizer.ttype ) ); //file was parsed correctly, so this works. tokenizer.nextToken(); param.append(tokenizer.sval); } else { tokenizer.pushBack(); break; } } wordList.add(param.toString()); } } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("error tokenizing tag"); } return wordList; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/model/util/package-info.java000066400000000000000000000001671325201777200277740ustar00rootroot00000000000000/** * Provides utility classes supporting the construction of the models */ package com.thoughtworks.qdox.model.util;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/package-info.java000066400000000000000000000001371325201777200257140ustar00rootroot00000000000000/** * Provides classes to start constructing a java project */ package com.thoughtworks.qdox;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/000077500000000000000000000000001325201777200240205ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/CommentHandler.java000066400000000000000000000027361325201777200275730ustar00rootroot00000000000000package com.thoughtworks.qdox.parser; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * JavaDoc is not part of the Java Language Specification, it should be treated as a special type of comment. This means * it can appear almost everywhere, although there are only a few places where JavaDoc has effect. When the parser has * finished a comment, it will trigger the commentHandler by calling the onComment-method. * * @author Robert Scholte * @since 2.0 */ public interface CommentHandler { /** * Called if the parser hits a comment * * @param comment the comment * @param line the line number * @param column the column number */ void onComment( String comment, int line, int column ); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/CommentScanner.java000066400000000000000000000024321325201777200276000ustar00rootroot00000000000000package com.thoughtworks.qdox.parser; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * Classes implementing this interface can trigger the handler for every time it has parsed a comment. * * @author Robert Scholte * @since 2.0 */ public interface CommentScanner { /** * Register this handler as a comment-listener. * If scanner hits a comment, all handlers will be triggered. * * @param handler the commentHandler to add to the CommentScanner */ void addCommentHandler( CommentHandler handler ); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/JavaLexer.java000066400000000000000000000017201325201777200265440ustar00rootroot00000000000000package com.thoughtworks.qdox.parser; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * The Lexer-interface for Java sources * * @since 2.0 */ public interface JavaLexer extends Lexer, CommentScanner { } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/Lexer.java000066400000000000000000000020151325201777200257400ustar00rootroot00000000000000package com.thoughtworks.qdox.parser; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.IOException; public interface Lexer { int lex() throws IOException; String text(); int getLine(); int getColumn(); String getCodeBody(); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/ParseException.java000066400000000000000000000044531325201777200276220ustar00rootroot00000000000000package com.thoughtworks.qdox.parser; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * Thrown to indicate an error during parsing */ public class ParseException extends RuntimeException { /** * The line where the ParserException occurred */ private int line = -1; /** * The column where the ParserException occurred */ private int column = -1; /** * The sourceInfo of where the exception occurred */ private String sourceInfo; /** * Default constructor for the ParseException * * @param message the message * @param line the line number * @param column the column number */ public ParseException( String message, int line, int column ) { super( message ); this.line = line; this.column = column; } public int getLine() { return line; } public int getColumn() { return column; } public void setSourceInfo( String sourceInfo ) { this.sourceInfo = sourceInfo; } @Override public String getMessage() { StringBuilder buffer = new StringBuilder( super.getMessage() ); if ( line >= 0 ) { buffer.append( " @[" ).append( line ); if ( column >= 0 ) { buffer.append( ',' ).append( column ); } buffer.append( ']' ); } if ( sourceInfo != null ) { buffer.append( " in " ).append( sourceInfo ); } return buffer.toString(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/000077500000000000000000000000001325201777200262175ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/AddDef.java000066400000000000000000000021471325201777200301750ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class AddDef extends BinaryOperatorDef { public AddDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/AndDef.java000066400000000000000000000021511325201777200302020ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class AndDef extends BinaryOperatorDef { public AndDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/AssignmentDef.java000066400000000000000000000033311325201777200316110ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class AssignmentDef extends ExpressionDef { private ElemValueDef letfHandSide; private String operator; private ElemValueDef assignmentExpression; public AssignmentDef( ElemValueDef letfHandSide, String operator, ElemValueDef assignmentExpression ) { this.letfHandSide = letfHandSide; this.operator = operator; this.assignmentExpression = assignmentExpression; } public ElemValueDef getLetfHandSide() { return letfHandSide; } public String getOperator() { return operator; } public ElemValueDef getAssignmentExpression() { return assignmentExpression; } /** {@inheritDoc} */ public U transform( ElemValueTransformer transformer ) { return transformer.transform(this); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/BinaryOperatorDef.java000066400000000000000000000024451325201777200324460ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public abstract class BinaryOperatorDef extends ExpressionDef { private final ElemValueDef lhs; private final ElemValueDef rhs; public BinaryOperatorDef(ElemValueDef lhs, ElemValueDef rhs) { this.lhs = lhs; this.rhs = rhs; } /** * @return the lhs */ public ElemValueDef getLeft() { return lhs; } /** * @return the rhs */ public ElemValueDef getRight() { return rhs; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/CastDef.java000066400000000000000000000026611325201777200304000ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; import com.thoughtworks.qdox.parser.structs.TypeDef; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class CastDef extends ExpressionDef { private final TypeDef typeDef; private final ElemValueDef elemDef; public CastDef( TypeDef type, ElemValueDef value ) { this.typeDef = type; this.elemDef = value; } public TypeDef getTypeDef() { return typeDef; } public ElemValueDef getElemDef() { return elemDef; } /** {@inheritDoc} */ public U transform( ElemValueTransformer transformer ) { return transformer.transform( this ); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/ConstantDef.java000066400000000000000000000026161325201777200312770ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class ConstantDef extends ExpressionDef { private final String value; private Class type; public ConstantDef( String value, Class type ) { this.value = value; this.type = type; } public Class getType() { return type; } public String getValue() { return value; } @Override public String toString() { return value; } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/CreatorDef.java000066400000000000000000000040231325201777200310770ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; import java.util.List; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class CreatorDef extends ExpressionDef { private List typeArguments; private String createdName; private List arguments; private String classBody; public List getTypeArguments() { return typeArguments; } public void setTypeArguments( List typeArguments ) { this.typeArguments = typeArguments; } public String getCreatedName() { return createdName; } public void setCreatedName( String createdName ) { this.createdName = createdName; } public List getArguments() { return arguments; } public void setArguments( List arguments ) { this.arguments = arguments; } public String getClassBody() { return classBody; } public void setClassBody( String classBody ) { this.classBody = classBody; } /** {@inheritDoc} */ public U transform( ElemValueTransformer transformer ) { return transformer.transform( this ); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/DivideDef.java000066400000000000000000000021621325201777200307060ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class DivideDef extends BinaryOperatorDef { public DivideDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/ElemValueDef.java000066400000000000000000000002241325201777200313560ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; public interface ElemValueDef { U transform(ElemValueTransformer transformer); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/ElemValueListDef.java000066400000000000000000000010551325201777200322150ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; import java.util.List; public class ElemValueListDef implements ElemValueDef{ private List valueList; public ElemValueListDef(List annoValueList) { this.valueList = annoValueList; } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } /** * @return the valueList */ public List getValueList() { return valueList; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/ElemValueTransformer.java000066400000000000000000000060351325201777200331700ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import com.thoughtworks.qdox.parser.structs.AnnoDef; public interface ElemValueTransformer { U transform( AnnoDef annoDef ); U transform( AddDef annotationAdd ); U transform( AndDef annotationAnd ); U transform( DivideDef annotationDivide ); U transform( EqualsDef annotationEquals ); U transform( ExclusiveOrDef annotationExclusiveOr ); U transform( GreaterEqualsDef annotationGreaterEquals ); U transform( GreaterThanDef annotationGreaterThan ); U transform( LessEqualsDef annotationLessEquals ); U transform( LessThanDef annotationLessThan ); U transform( LogicalAndDef annotationLogicalAnd ); U transform( LogicalOrDef annotationLogicalOr ); U transform( MultiplyDef annotationMultiply ); U transform( NotEqualsDef annotationNotEquals ); U transform( OrDef annotationOr ); U transform( RemainderDef annotationRemainder ); U transform( ShiftLeftDef annotationShiftLeft ); U transform( ShiftRightDef annotationShiftRight ); U transform( SubtractDef annotationSubtract ); U transform( UnsignedShiftRightDef annotationUnsignedShiftRight ); U transform( CastDef annotationCast ); U transform( ConstantDef annotationConstant ); U transform( FieldRefDef annotationFieldRef ); U transform( LogicalNotDef annotationLogicalNot ); U transform( MinusSignDef annotationMinusSign ); U transform( NotDef annotationNot ); U transform( ParenExpressionDef annotationParenExpression ); U transform( PlusSignDef annotationPlusSign ); U transform( QueryDef annotationQuery ); U transform( TypeRefDef annotationTypeRef ); U transform( ElemValueListDef elemValueListDef ); U transform( AssignmentDef assignmentDef ); U transform( PostIncrementDef postIncrement ); U transform( PostDecrementDef postDecrementDef ); U transform( PreDecrementDef preDecrementDef ); U transform( PreIncrementDef preIncrementDef ); U transform( MethodInvocationDef methodInvocationDef ); U transform( MethodReferenceDef methodReferenceDef ); U transform( CreatorDef newCreator ); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/EqualsDef.java000066400000000000000000000021611325201777200307330ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class EqualsDef extends BinaryOperatorDef { public EqualsDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/ExclusiveOrDef.java000066400000000000000000000021731325201777200317540ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class ExclusiveOrDef extends BinaryOperatorDef { public ExclusiveOrDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/ExpressionDef.java000066400000000000000000000016651325201777200316500ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public abstract class ExpressionDef implements ElemValueDef { } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/FieldRefDef.java000066400000000000000000000022751325201777200311670ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class FieldRefDef extends ExpressionDef { private final String name; public FieldRefDef( String name ) { this.name = name; } public String getName() { return name; } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/GreaterEqualsDef.java000066400000000000000000000021771325201777200322540ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class GreaterEqualsDef extends BinaryOperatorDef { public GreaterEqualsDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/GreaterThanDef.java000066400000000000000000000021731325201777200317100ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class GreaterThanDef extends BinaryOperatorDef { public GreaterThanDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/LessEqualsDef.java000066400000000000000000000021711325201777200315630ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class LessEqualsDef extends BinaryOperatorDef { public LessEqualsDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/LessThanDef.java000066400000000000000000000021661325201777200312270ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class LessThanDef extends BinaryOperatorDef { public LessThanDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/LogicalAndDef.java000066400000000000000000000021711325201777200314770ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class LogicalAndDef extends BinaryOperatorDef { public LogicalAndDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/LogicalNotDef.java000066400000000000000000000021461325201777200315370ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class LogicalNotDef extends UnaryOperatorDef { public LogicalNotDef(ElemValueDef value) { super(value); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/LogicalOrDef.java000066400000000000000000000021671325201777200313620ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class LogicalOrDef extends BinaryOperatorDef { public LogicalOrDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/MethodInvocationDef.java000066400000000000000000000030311325201777200327500ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.List; public class MethodInvocationDef extends ExpressionDef { private String methodName; private List arguments; public MethodInvocationDef( String methodName, List arguments ) { this.methodName = methodName; this.arguments = arguments; } public String getMethodName() { return methodName; } public List getArguments() { return arguments; } /** {@inheritDoc} */ public U transform( ElemValueTransformer transformer ) { return transformer.transform( this ); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/MethodReferenceDef.java000066400000000000000000000004011325201777200325330ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; public class MethodReferenceDef extends ExpressionDef { /** {@inheritDoc} */ public U transform( ElemValueTransformer transformer ) { return transformer.transform( this ); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/MinusSignDef.java000066400000000000000000000021241325201777200314140ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class MinusSignDef extends UnaryOperatorDef { public MinusSignDef(ElemValueDef value) { super(value); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/MultiplyDef.java000066400000000000000000000021661325201777200313250ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class MultiplyDef extends BinaryOperatorDef { public MultiplyDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/NotDef.java000066400000000000000000000021331325201777200302400ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class NotDef extends UnaryOperatorDef { public NotDef(ElemValueDef value) { super(value); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/NotEqualsDef.java000066400000000000000000000021641325201777200314170ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class NotEqualsDef extends BinaryOperatorDef { public NotEqualsDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/OrDef.java000066400000000000000000000021511325201777200300600ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class OrDef extends BinaryOperatorDef { public OrDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/ParenExpressionDef.java000066400000000000000000000024521325201777200326310ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class ParenExpressionDef extends ExpressionDef { private final ElemValueDef elemValueDef; public ParenExpressionDef(ElemValueDef value) { this.elemValueDef = value; } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } /** * @return the elemValueDef */ public ElemValueDef getElemValueDef() { return elemValueDef; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/PlusSignDef.java000066400000000000000000000021221325201777200312420ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class PlusSignDef extends UnaryOperatorDef { public PlusSignDef(ElemValueDef value) { super(value); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/PostDecrementDef.java000066400000000000000000000022601325201777200322550ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class PostDecrementDef extends UnaryOperatorDef { public PostDecrementDef( ElemValueDef elemValueDef ) { super( elemValueDef ); } /** {@inheritDoc} */ public U transform( ElemValueTransformer transformer ) { return transformer.transform( this ); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/PostIncrementDef.java000066400000000000000000000022601325201777200322730ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class PostIncrementDef extends UnaryOperatorDef { public PostIncrementDef( ElemValueDef elemValueDef ) { super( elemValueDef ); } /** {@inheritDoc} */ public U transform( ElemValueTransformer transformer ) { return transformer.transform( this ); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/PreDecrementDef.java000066400000000000000000000022561325201777200320630ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class PreDecrementDef extends UnaryOperatorDef { public PreDecrementDef( ElemValueDef elemValueDef ) { super( elemValueDef ); } /** {@inheritDoc} */ public U transform( ElemValueTransformer transformer ) { return transformer.transform( this ); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/PreIncrementDef.java000066400000000000000000000022561325201777200321010ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class PreIncrementDef extends UnaryOperatorDef { public PreIncrementDef( ElemValueDef elemValueDef ) { super( elemValueDef ); } /** {@inheritDoc} */ public U transform( ElemValueTransformer transformer ) { return transformer.transform( this ); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/QueryDef.java000066400000000000000000000032631325201777200306120ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class QueryDef extends ExpressionDef { private final ElemValueDef cond; private final ElemValueDef trueExpr; private final ElemValueDef falseExpr; public QueryDef(ElemValueDef cond, ElemValueDef trueExpr, ElemValueDef falseExpr) { this.cond = cond; this.trueExpr = trueExpr; this.falseExpr = falseExpr; } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } /** * @return the cond */ public ElemValueDef getCondition() { return cond; } /** * @return the trueExpr */ public ElemValueDef getTrueExpression() { return trueExpr; } /** * @return the falseExpr */ public ElemValueDef getFalseExpression() { return falseExpr; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/RemainderDef.java000066400000000000000000000021671325201777200314150ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class RemainderDef extends BinaryOperatorDef { public RemainderDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/ShiftLeftDef.java000066400000000000000000000021671325201777200313770ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class ShiftLeftDef extends BinaryOperatorDef { public ShiftLeftDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/ShiftRightDef.java000066400000000000000000000021711325201777200315550ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class ShiftRightDef extends BinaryOperatorDef { public ShiftRightDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/SubtractDef.java000066400000000000000000000021651325201777200312740ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class SubtractDef extends BinaryOperatorDef { public SubtractDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/TypeRefDef.java000066400000000000000000000023771325201777200310700ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import com.thoughtworks.qdox.parser.structs.TypeDef; public class TypeRefDef extends ExpressionDef { private TypeDef typeDef; public TypeRefDef(TypeDef typeDef) { this.typeDef = typeDef; } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } public TypeDef getTypeDef() { return typeDef; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/UnaryOperatorDef.java000066400000000000000000000022511325201777200323130ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public abstract class UnaryOperatorDef extends ExpressionDef { private final ElemValueDef elemValueDef; public UnaryOperatorDef(ElemValueDef elemValueDef) { this.elemValueDef = elemValueDef; } /** * @return the elemValueDef */ public ElemValueDef getElemValueDef() { return elemValueDef; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/UnsignedShiftRightDef.java000066400000000000000000000022141325201777200332500ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.expression; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class UnsignedShiftRightDef extends BinaryOperatorDef { public UnsignedShiftRightDef(ElemValueDef lhs, ElemValueDef rhs) { super(lhs, rhs); } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/expression/package-info.java000066400000000000000000000002001325201777200313760ustar00rootroot00000000000000/** * Provides classes which make it possible to resolve expression values */ package com.thoughtworks.qdox.parser.expression;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/impl/000077500000000000000000000000001325201777200247615ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/impl/BinaryClassParser.java000066400000000000000000000172251325201777200312220ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Member; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Set; import java.util.StringTokenizer; import com.thoughtworks.qdox.builder.Builder; import com.thoughtworks.qdox.parser.structs.ClassDef; import com.thoughtworks.qdox.parser.structs.FieldDef; import com.thoughtworks.qdox.parser.structs.MethodDef; import com.thoughtworks.qdox.parser.structs.PackageDef; import com.thoughtworks.qdox.parser.structs.TypeDef; public class BinaryClassParser { private Class declaringClazz; private Builder binaryBuilder; public BinaryClassParser( Class declaringClazz, Builder modelBuilder ) { this.declaringClazz = declaringClazz; this.binaryBuilder = modelBuilder; } public boolean parse() { try { if(declaringClazz.getPackage() != null) { binaryBuilder.addPackage( new PackageDef( declaringClazz.getPackage().getName() ) ); } addClass( declaringClazz ); return true; } catch ( NoClassDefFoundError e ) { return false; } } private void addClass( Class clazz ) { ClassDef classDef = new ClassDef( clazz.getSimpleName() ); // Set the extended class and interfaces. Class[] interfaces = clazz.getInterfaces(); if ( clazz.isEnum() ) { classDef.setType( ClassDef.ENUM ); } else if ( clazz.isAnnotation() ) { classDef.setType( ClassDef.ANNOTATION_TYPE ); } else if ( clazz.isInterface() ) { classDef.setType( ClassDef.INTERFACE ); for ( int i = 0; i < interfaces.length; i++ ) { Class anInterface = interfaces[i]; classDef.getExtends().add( new TypeDef( anInterface.getName() ) ); } } else { for ( int i = 0; i < interfaces.length; i++ ) { Class anInterface = interfaces[i]; classDef.getImplements().add( new TypeDef( anInterface.getName() ) ); } Class superclass = clazz.getSuperclass(); if ( superclass != null ) { classDef.getExtends().add( new TypeDef( superclass.getName() ) ); } } addModifiers( classDef.getModifiers(), clazz.getModifiers() ); binaryBuilder.beginClass( classDef ); // add the constructors // // This also adds the default constructor if any which is different // to the source code as that does not create a default constructor // if no constructor exists. Constructor[] constructors = clazz.getDeclaredConstructors(); for ( int i = 0; i < constructors.length; i++ ) { binaryBuilder.beginConstructor(); MethodDef methodDef = createMethodDef( constructors[i] ); binaryBuilder.endConstructor( methodDef ); } // add the methods Method[] methods = clazz.getDeclaredMethods(); for ( int i = 0; i < methods.length; i++ ) { binaryBuilder.beginMethod(); MethodDef methodDef = createMethodDef( methods[i] ); binaryBuilder.endMethod( methodDef ); } Field[] fields = clazz.getDeclaredFields(); for ( int i = 0; i < fields.length; i++ ) { addField( fields[i] ); } Class[] classes = clazz.getDeclaredClasses(); for ( int i = 0; i < classes.length; i++ ) { addClass( classes[i] ); } binaryBuilder.endClass(); } private static void addModifiers( Set set, int modifier ) { String modifierString = Modifier.toString( modifier ); for ( StringTokenizer stringTokenizer = new StringTokenizer( modifierString ); stringTokenizer.hasMoreTokens(); ) { set.add( stringTokenizer.nextToken() ); } } private void addField( Field field ) { FieldDef fieldDef = new FieldDef( field.getName() ); Class fieldType = field.getType(); fieldDef.setType( getTypeDef( fieldType ) ); fieldDef.setDimensions( getDimension( fieldType ) ); fieldDef.setEnumConstant( field.isEnumConstant() ); addModifiers( fieldDef.getModifiers(), field.getModifiers() ); binaryBuilder.beginField( fieldDef ); binaryBuilder.endField(); } private MethodDef createMethodDef( Member member ) { MethodDef methodDef = new MethodDef(); // The name of constructors are qualified. Need to strip it. // This will work for regular methods too, since -1 + 1 = 0 int lastDot = member.getName().lastIndexOf( '.' ); methodDef.setName( member.getName().substring( lastDot + 1 ) ); addModifiers( methodDef.getModifiers(), member.getModifiers() ); Class[] exceptions; Class[] parameterTypes; if ( member instanceof Method ) { methodDef.setConstructor( false ); // For some stupid reason, these methods are not defined in Member, // but in both Method and Construcotr. exceptions = ( (Method) member ).getExceptionTypes(); parameterTypes = ( (Method) member ).getParameterTypes(); Class returnType = ( (Method) member ).getReturnType(); methodDef.setReturnType( getTypeDef( returnType ) ); methodDef.setDimensions( getDimension( returnType ) ); } else { methodDef.setConstructor( true ); exceptions = ( (Constructor) member ).getExceptionTypes(); parameterTypes = ( (Constructor) member ).getParameterTypes(); } for ( int j = 0; j < exceptions.length; j++ ) { Class exception = exceptions[j]; methodDef.getExceptions().add( getTypeDef( exception ) ); } for ( int j = 0; j < parameterTypes.length; j++ ) { FieldDef param = new FieldDef( "p" + j ); Class parameterType = parameterTypes[j]; param.setType( getTypeDef( parameterType ) ); param.setDimensions( getDimension( parameterType ) ); binaryBuilder.addParameter( param ); } return methodDef; } private static int getDimension( Class c ) { return c.getName().lastIndexOf( '[' ) + 1; } private static String getTypeName( Class c ) { return c.getComponentType() != null ? c.getComponentType().getName() : c.getName(); } private static TypeDef getTypeDef( Class c ) { return new TypeDef( getTypeName( c ) ); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/impl/package-info.java000066400000000000000000000001541325201777200301500ustar00rootroot00000000000000/** * Provides the implementations of the Lexers and Parsers */ package com.thoughtworks.qdox.parser.impl;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/package-info.java000066400000000000000000000001571325201777200272120ustar00rootroot00000000000000/** * Provides interfaces and exceptions for both Lexers and Parsers */ package com.thoughtworks.qdox.parser;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/structs/000077500000000000000000000000001325201777200255275ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/structs/AnnoDef.java000066400000000000000000000032061325201777200277050ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.structs; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.LinkedHashMap; import java.util.Map; import com.thoughtworks.qdox.parser.expression.ElemValueTransformer; import com.thoughtworks.qdox.parser.expression.ElemValueDef; public class AnnoDef extends LocatedDef implements ElemValueDef { private TypeDef typeDef; private final Map args = new LinkedHashMap(); public AnnoDef( TypeDef typeDef ) { this.typeDef = typeDef; } public AnnoDef getValue() { return this; } /** {@inheritDoc} */ public U transform(ElemValueTransformer transformer) { return transformer.transform(this); } public TypeDef getTypeDef() { return typeDef; } public Map getArgs() { return args; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/structs/ClassDef.java000066400000000000000000000063601325201777200300630ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.structs; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; public class ClassDef extends LocatedDef { public static final String CLASS = "class"; public static final String INTERFACE = "interface"; public static final String ENUM = "enum"; public static final String ANNOTATION_TYPE = "@interface"; private String name = ""; private Set modifiers = new LinkedHashSet(); private List typeParams = new LinkedList(); private Set extendz = new LinkedHashSet(); private Set implementz = new LinkedHashSet(); private String type = CLASS; public ClassDef() { } public ClassDef( String name ) { this.name = name; } /** * @param name the name to set */ public void setName( String name ) { this.name = name; } /** * @return the name */ public String getName() { return name; } @Override public String toString() { StringBuilder result = new StringBuilder(); result.append( getModifiers() ); result.append( ' ' ); result.append( getType() ); result.append( ' ' ); result.append( getName() ); // typeParams result.append( " extends " ); result.append( getExtends() ); result.append( " implements " ); result.append( getImplements() ); return result.toString(); } public void setModifiers( Set modifiers ) { this.modifiers = modifiers; } public Set getModifiers() { return modifiers; } public void setType( String type ) { this.type = type; } public String getType() { return type; } public void setImplements( Set implementz ) { this.implementz = implementz; } public Set getImplements() { return implementz; } public void setExtends( Set extendz ) { this.extendz = extendz; } public Set getExtends() { return extendz; } public void setTypeParameters( List typeParams ) { this.typeParams = typeParams; } public List getTypeParameters() { return typeParams; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/structs/FieldDef.java000066400000000000000000000063501325201777200300400ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.structs; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.LinkedHashSet; import java.util.Set; /** * Used for both fields and parameters */ public class FieldDef extends LocatedDef { private String name; private TypeDef type; private Set modifiers = new LinkedHashSet(); private int dimensions; private boolean isVarArgs; private boolean isEnumConstant; private String body; public FieldDef() { } public FieldDef( String name ) { this.name = name; } /** * @param name the name to set */ public void setName( String name ) { this.name = name; } /** * @return the name */ public String getName() { return name; } /** * @param type the type to set */ public void setType( TypeDef type ) { this.type = type; } /** * @return the type */ public TypeDef getType() { return type; } /** * @param dimensions the dimensions to set */ public void setDimensions( int dimensions ) { this.dimensions = dimensions; } /** * @return the dimensions */ public int getDimensions() { return dimensions; } /** * @param isVarArgs the isVarArgs to set */ public void setVarArgs( boolean isVarArgs ) { this.isVarArgs = isVarArgs; } /** * @return the isVarArgs */ public boolean isVarArgs() { return isVarArgs; } /** * @param body the body to set */ public void setBody( String body ) { this.body = body; } /** * @return the body */ public String getBody() { return body; } /** * @param modifiers the modifiers to set */ public void setModifiers( Set modifiers ) { this.modifiers = modifiers; } /** * @return the modifiers */ public Set getModifiers() { return modifiers; } /** * @return true if this field is an enum constant, otherwise false */ public boolean isEnumConstant() { return isEnumConstant; } /** * @param isEnumConstant value to specify if this field is an enum constant or not */ public void setEnumConstant( boolean isEnumConstant ) { this.isEnumConstant = isEnumConstant; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/structs/InitDef.java000066400000000000000000000032221325201777200277130ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.structs; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * * @author Robert Scholte * @since 2.0 */ public class InitDef extends LocatedDef { private boolean staticInitializer; private String blockContent; public InitDef() { } public InitDef( String blockContent, boolean staticInitializer ) { this.staticInitializer = staticInitializer; this.blockContent = blockContent; } public boolean isStatic() { return staticInitializer; } public void setStatic( boolean staticInitializer ) { this.staticInitializer = staticInitializer; } public String getBlockContent() { return blockContent; } public void setBlockContent( String block ) { this.blockContent = block; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/structs/LocatedDef.java000066400000000000000000000024111325201777200303620ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.structs; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class LocatedDef { private int lineNumber; private int columnNumber; public void setLineNumber( int lineNumber ) { this.lineNumber = lineNumber; } public int getLineNumber() { return lineNumber; } public void setColumnNumber( int columnNumber ) { this.columnNumber = columnNumber; } public int getColumnNumber() { return columnNumber; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/structs/MethodDef.java000066400000000000000000000061261325201777200302360ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.structs; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; public class MethodDef extends LocatedDef { private String name = ""; private List typeParams; private TypeDef returnType; private Set modifiers = new LinkedHashSet(); private Set exceptions = new LinkedHashSet(); private boolean constructor = false; private int dimensions; private String body; @Override public String toString() { StringBuilder result = new StringBuilder(); result.append( getModifiers() ); result.append( ' ' ); result.append( ( getReturnType() != null ? getReturnType().toString() : "" ) ); for ( int i = 0; i < getDimensions(); i++ ) { result.append( "[]" ); } result.append( ' ' ); result.append( getName() ); result.append( '(' ); result.append( getTypeParams() ); result.append( ')' ); result.append( " throws " ); result.append( getExceptions() ); result.append( getBody() ); return result.toString(); } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setReturnType(TypeDef returnType) { this.returnType = returnType; } public TypeDef getReturnType() { return returnType; } public void setModifiers(Set modifiers) { this.modifiers = modifiers; } public Set getModifiers() { return modifiers; } public void setConstructor(boolean constructor) { this.constructor = constructor; } public boolean isConstructor() { return constructor; } public void setBody(String body) { this.body = body; } public String getBody() { return body; } public void setDimensions(int dimensions) { this.dimensions = dimensions; } public int getDimensions() { return dimensions; } public void setExceptions(Set exceptions) { this.exceptions = exceptions; } public Set getExceptions() { return exceptions; } public void setTypeParams( List typeParams ) { this.typeParams = typeParams; } public List getTypeParams() { return typeParams; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/structs/ModuleDef.java000066400000000000000000000056501325201777200302440ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.structs; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; public class ModuleDef extends LocatedDef { private boolean open; private String name; public ModuleDef( String name ) { super(); this.name = name; } public String getName() { return name; } public void setOpen( boolean open ) { this.open = open; } public boolean isOpen() { return open; } public static class ExportsDef extends LocatedDef { private String source; private Set targets = new LinkedHashSet(); public ExportsDef( String source ) { this.source = source; } public ExportsDef( String source, Set modifiers ) { this.source = source; } public String getSource() { return source; } public Set getTargets() { return targets; } } public static class OpensDef extends LocatedDef { private String source; private Set targets = new LinkedHashSet(); public OpensDef( String source ) { this.source = source; } public OpensDef( String source, Set modifiers ) { this.source = source; } public String getSource() { return source; } public Set getTargets() { return targets; } } public static class ProvidesDef extends LocatedDef { private TypeDef service; private List implementations = new LinkedList(); public ProvidesDef( TypeDef service ) { this.service = service; } public TypeDef getService() { return service; } public List getImplementations() { return implementations; } } public static class RequiresDef extends LocatedDef { private String name; private Set modifiers; public RequiresDef( String name, Set modifiers ) { super(); this.name = name; this.modifiers = modifiers; } public String getName() { return name; } public Set getModifiers() { return modifiers; } } public static class UsesDef extends LocatedDef { private TypeDef service; public UsesDef( TypeDef service ) { this.service = service; } public TypeDef getService() { return service; } } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/structs/PackageDef.java000066400000000000000000000023371325201777200303510ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.structs; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class PackageDef extends LocatedDef { private String name; public PackageDef(String name) { this.name = name; } public PackageDef(String name, int lineNumber) { this.name = name; this.setLineNumber( lineNumber ); } /** * @return the name */ public String getName() { return name; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/structs/TagDef.java000066400000000000000000000032301325201777200275220ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.structs; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class TagDef extends LocatedDef { private String name; private String text; public TagDef( String name, String text, int lineNumber ) { this.name = name; this.text = text; this.setLineNumber( lineNumber ); } public TagDef( String name, String text ) { this( name, text, -1 ); } public String getName() { return name; } public String getText() { return text; } @Override public String toString() { StringBuilder result = new StringBuilder(); result.append( '@' ); result.append( name ); result.append( " => \"" ); result.append( text ); result.append( "\" @ line " ); result.append( getLineNumber() ); return result.toString(); } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/structs/TypeDef.java000066400000000000000000000044141325201777200277350ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.structs; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.List; public class TypeDef { private String name; private int dimensions; private List actualArgumentTypes; public TypeDef(String name, int dimensions) { this.name = name; this.dimensions = dimensions; } public TypeDef(String name) { this(name, 0); } public String getName() { return name; } public int getDimensions() { return dimensions; } public void setDimensions( int dimensions ) { this.dimensions = dimensions; } @Override public boolean equals(Object obj) { TypeDef typeDef = (TypeDef) obj; return typeDef.name.equals(name) && typeDef.dimensions == dimensions && (typeDef.getActualArgumentTypes() != null ? typeDef.getActualArgumentTypes().equals(getActualArgumentTypes()): getActualArgumentTypes() == null); } @Override public int hashCode() { return name.hashCode() + dimensions + (getActualArgumentTypes() == null ? 0 : getActualArgumentTypes().hashCode()); } /** * @param actualArgumentTypes the actualArgumentTypes to set */ public void setActualArgumentTypes( List actualArgumentTypes ) { this.actualArgumentTypes = actualArgumentTypes; } /** * @return the actualArgumentTypes */ public List getActualArgumentTypes() { return actualArgumentTypes; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/structs/TypeVariableDef.java000066400000000000000000000026221325201777200314020ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.structs; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.List; public class TypeVariableDef { private String name; private List bounds; public TypeVariableDef(String name) { this.name = name; } public TypeVariableDef(String name, List bounds) { super(); this.name = name; this.bounds = bounds; } public void setBounds( List bounds ) { this.bounds = bounds; } public String getName() { return name; } public List getBounds() { return bounds; } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/structs/WildcardTypeDef.java000066400000000000000000000032511325201777200314050ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.structs; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * WildcardTypeDef must be a subclass of TypeDef, so it can be used in other classes. * But here are only 2 fields interesting: typeDef and wildcardExpressionType * typeDef itself can be generic, so it must be resolvable * wildcardExpressionType is super or extends * * * @author Robert Scholte * */ public class WildcardTypeDef extends TypeDef { private TypeDef typeDef; private String wildcardExpressionType; //super or extends public WildcardTypeDef() { super("?"); } public WildcardTypeDef(TypeDef typeDef, String wildcardExpressionType) { super( typeDef.getName(), typeDef.getDimensions() ); this.typeDef = typeDef; this.wildcardExpressionType = wildcardExpressionType; } public TypeDef getTypeDef() { return typeDef; } public String getWildcardExpressionType() { return wildcardExpressionType; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/parser/structs/package-info.java000066400000000000000000000002701325201777200307150ustar00rootroot00000000000000/** * Provides simple models to be constructed by the parser. * With these objects the ModeLbuilder constructs a complete Java Model */ package com.thoughtworks.qdox.parser.structs;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/tools/000077500000000000000000000000001325201777200236645ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/tools/QDoxTester.java000066400000000000000000000146041325201777200265760ustar00rootroot00000000000000package com.thoughtworks.qdox.tools; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import com.thoughtworks.qdox.JavaProjectBuilder; import com.thoughtworks.qdox.directorywalker.DirectoryScanner; import com.thoughtworks.qdox.directorywalker.FileVisitor; import com.thoughtworks.qdox.directorywalker.SuffixFilter; import com.thoughtworks.qdox.parser.ParseException; /** * Tool for testing that QDox can parse Java source code. * * @author Joe Walnes */ public class QDoxTester { public static interface Reporter { void success(String id); void parseFailure(String id, int line, int column, String reason); void error(String id, Throwable throwable); } private final Reporter reporter; public QDoxTester(Reporter reporter) { this.reporter = reporter; } public void checkZipOrJarFile(File file) throws IOException { ZipFile zipFile = new ZipFile(file); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry zipEntry = entries.nextElement(); if( zipEntry.isDirectory() ) { continue; } InputStream inputStream = zipFile.getInputStream(zipEntry); try { verify(file.getName() + "!" + zipEntry.getName(), inputStream); } finally { inputStream.close(); } } } public void checkDirectory(File dir) { DirectoryScanner directoryScanner = new DirectoryScanner(dir); directoryScanner.addFilter(new SuffixFilter(".java")); directoryScanner.scan(new FileVisitor() { public void visitFile(File file) { try { checkJavaFile(file); } catch (IOException e) { // ? } } }); } public void checkJavaFile(File file) throws IOException { InputStream inputStream = new FileInputStream(file); try { verify(file.getName(), inputStream); } finally { inputStream.close(); } } private void verify(String id, InputStream inputStream) { try { JavaProjectBuilder builder = new JavaProjectBuilder(); builder.addSource(new BufferedReader(new InputStreamReader(inputStream))); reporter.success(id); } catch (ParseException parseException) { reporter.parseFailure(id, parseException.getLine(), parseException.getColumn(), parseException.getMessage()); } catch (Exception otherException) { reporter.error(id, otherException); } } public static void main(String[] args) throws IOException { if (args.length == 0) { System.err.println("Tool that verifies that QDox can parse some Java source."); System.err.println(); System.err.println("Usage: java " + QDoxTester.class.getName() + " src1 [src2] [src3]..."); System.err.println(); System.err.println("Each src can be a single .java file, or a directory/zip/jar containing multiple source files"); System.exit(-1); } ConsoleReporter reporter = new ConsoleReporter(System.out); QDoxTester qDoxTester = new QDoxTester(reporter); for (int i = 0; i < args.length; i++) { File file = new File(args[i]); if (file.isDirectory()) { qDoxTester.checkDirectory(file); } else if (file.getName().endsWith(".java")) { qDoxTester.checkJavaFile(file); } else if (file.getName().endsWith(".jar") || file.getName().endsWith(".zip")) { qDoxTester.checkZipOrJarFile(file); } else { System.err.println("Unknown input <" + file.getName() + ">. Should be zip, jar, java or directory"); } } reporter.writeSummary(); } private static class ConsoleReporter implements Reporter { private final PrintStream out; private int success; private int failure; private int error; private int dotsWrittenThisLine; public ConsoleReporter(PrintStream out) { this.out = out; } public void success(String id) { success++; if (++dotsWrittenThisLine > 80) { newLine(); } out.print('.'); } private void newLine() { dotsWrittenThisLine = 0; out.println(); out.flush(); } public void parseFailure(String id, int line, int column, String reason) { newLine(); out.println("* " + id); out.println(" [" + line + ":" + column + "] " + reason); failure++; } public void error(String id, Throwable throwable) { newLine(); out.println("* " + id); throwable.printStackTrace(out); error++; } public void writeSummary() { newLine(); out.println("-- Summary --------------"); out.println("Success: " + success); out.println("Failure: " + failure); out.println("Error : " + error); out.println("Total : " + (success + failure + error)); out.println("-------------------------"); } } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/tools/package-info.java000066400000000000000000000000601325201777200270470ustar00rootroot00000000000000/** * */ package com.thoughtworks.qdox.tools;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/type/000077500000000000000000000000001325201777200235055ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/type/TypeResolver.java000066400000000000000000000212001325201777200270060ustar00rootroot00000000000000package com.thoughtworks.qdox.type; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.model.JavaClass; /** * A per JavaClass resolver of types * * @author Robert Scholte * @since 2.0 */ public class TypeResolver { private static final Set PRIMITIVE_TYPES = new HashSet(); private final Map resolvedTypeCache = new HashMap(); private final String pckg; private final String declaringClass; private final ClassLibrary classLibrary; private final Collection imports; static { PRIMITIVE_TYPES.add("boolean"); PRIMITIVE_TYPES.add("byte"); PRIMITIVE_TYPES.add("char"); PRIMITIVE_TYPES.add("double"); PRIMITIVE_TYPES.add("float"); PRIMITIVE_TYPES.add("int"); PRIMITIVE_TYPES.add("long"); PRIMITIVE_TYPES.add("short"); PRIMITIVE_TYPES.add("void"); } private TypeResolver( String pckg, String declaringClass, ClassLibrary classLibrary, Collection imports ) { this.pckg = pckg; this.declaringClass = declaringClass; this.classLibrary = classLibrary; this.imports = imports != null ? imports : Collections.emptyList(); } /** * Type resolver in case there's no declaring class, e.g. using extends, implements and annotations on a toplevel class * * @param binaryName the binary name of the package * @param classLibrary the class library * @param imports the imports, can be {@code null} * @return the typeResolver */ public static TypeResolver byPackageName( String binaryName, ClassLibrary classLibrary, Collection imports ) { return new TypeResolver( binaryName, null, classLibrary, imports ); } /** * * @param binaryName the class in which context a type is used. * @param classLibrary the class library * @param imports the imports, can be {@code null} * @return the typeResolver */ public static TypeResolver byClassName( String binaryName, ClassLibrary classLibrary, Collection imports ) { int dotIndex = binaryName.lastIndexOf( '.' ); String pckg = dotIndex > 0 ? binaryName.substring( 0, dotIndex ) : null; return new TypeResolver( pckg, binaryName, classLibrary, imports ); } public JavaClass resolveJavaClass( String typeName ) { return classLibrary.getJavaClass( resolveType( typeName ) ); } public JavaClass getJavaClass( String binaryName ) { return classLibrary.getJavaClass( binaryName ); } public String resolveType( String typeName ) { String result = resolvedTypeCache.get( typeName ); if ( result == null ) { if ( declaringClass != null ) { int dollarIndex = declaringClass.indexOf( '$' ); while( result == null && dollarIndex > 0 ) { String subType = declaringClass.substring( 0, dollarIndex + 1 ) + typeName; result = resolveFromLibrary( subType ); dollarIndex = declaringClass.indexOf( '$', dollarIndex + 1 ); } if (result == null) { String nestedBinaryName = declaringClass + '$' + typeName.replace( '.', '$' ); result = resolveFromLibrary( nestedBinaryName ); } } if ( result == null ) { result = resolveTypeInternal( typeName ); } if ( result != null ) { resolvedTypeCache.put( typeName, result ); } } return result; } /** * Resolves a type name *

* Follows the * Java Language Specification, Version 3.0. *

* Current resolution order is: *

    *
  1. Single-Type-Import Declaration
  2. *
  3. Type-Import-on-Demand Declaration
  4. *
  5. Automatic Imports
  6. *
* * @param typeName the name to resolve * @return the resolved type name, otherwise null */ private String resolveTypeInternal( String typeName ) { String resolvedName = null; lookup: { // primitive types if ( PRIMITIVE_TYPES.contains( typeName ) ) { resolvedName = typeName; break lookup; } String outerName = typeName; String nestedName = typeName.replace( '.', '$' ); int dotpos = typeName.indexOf( '.' ); if ( dotpos >= 0 ) { outerName = typeName.substring( 0, dotpos ); } // Check single-type-import with fully qualified name resolvedName = resolveImportedType( typeName, nestedName, true ); if ( resolvedName != null ) { break lookup; } // Check single-type-import with outer name resolvedName = resolveImportedType( outerName, nestedName, false ); if ( resolvedName != null ) { break lookup; } // check for class in the same package if ( pckg != null ) { resolvedName = resolveFullyQualifiedType( pckg + '.' + typeName ); if ( resolvedName != null ) { break lookup; } } // check for a class globally resolvedName = resolveFullyQualifiedType( typeName ); if ( resolvedName != null ) { break lookup; } // check for a class in the same package if ( pckg != null ) { resolvedName = resolveFromLibrary( pckg + "$" + nestedName ); if ( resolvedName != null ) { break lookup; } } // try java.lang.* resolvedName = resolveFromLibrary( "java.lang." + nestedName ); if ( resolvedName != null ) { break lookup; } // Check type-import-on-demand resolvedName = resolveImportedType( "*", nestedName, false ); if ( resolvedName != null ) { break lookup; } } return resolvedName; } private String resolveImportedType( String importSpec, String typeName, boolean fullMatch ) { String resolvedName = null; String dotSuffix = "." + importSpec; for ( String imprt : imports ) { // static imports can refer to inner classes if ( imprt.startsWith( "static " ) ) { imprt = imprt.substring( 7 ); } if ( imprt.equals( importSpec ) || ( !fullMatch && imprt.endsWith( dotSuffix ) ) ) { String candidateName = imprt.equals(importSpec) ? imprt : imprt.substring(0, imprt.length() - importSpec.length()) + typeName; resolvedName = resolveFullyQualifiedType( candidateName ); if ( resolvedName == null && !"*".equals( importSpec ) ) { resolvedName = candidateName; } if ( resolvedName != null ) { break; } } } return resolvedName; } private String resolveFromLibrary(String typeName) { return classLibrary.hasClassReference( typeName ) ? typeName : null; } private String resolveFullyQualifiedType(String typeName) { int indexOfLastDot = typeName.lastIndexOf('.'); if (indexOfLastDot >= 0) { String root = typeName.substring(0,indexOfLastDot); String leaf = typeName.substring(indexOfLastDot+1); String resolvedTypeName = resolveFullyQualifiedType(root + '$' + leaf); if(resolvedTypeName != null) { return resolvedTypeName; } } if( classLibrary.hasClassReference( typeName )) { return typeName; } return null; } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/writer/000077500000000000000000000000001325201777200240405ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/writer/ModelWriter.java000066400000000000000000000147661325201777200271560ustar00rootroot00000000000000package com.thoughtworks.qdox.writer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaConstructor; import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaInitializer; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaModuleDescriptor; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.JavaSource; /** * Interface for a custom ModelWriter. * * QDox doesn't keep any formatting information of the original source file (if it's there). * With a ModelWriter you can specify the way elements look if you write them to any output. * * * @author Robert Scholte * @since 2.0 */ public interface ModelWriter { /** * Write the complete source file * * A standard source writer should write: *
    *
  • the package
  • *
  • the imports
  • *
  • the classes
  • *
* * @param src the source * @return itself */ ModelWriter writeSource( JavaSource src ); /** * Write the java package * * A standard package writer should write: *
    *
  • the javadoc
  • *
  • the annotations
  • *
  • the package signature
  • *
* * @param pkg the package * @return itself */ ModelWriter writePackage( JavaPackage pkg ); /** * Write the java class * * A standard class writer should write: *
    *
  • the javadoc
  • *
  • the annotations
  • *
  • the class signature, containing: *
      *
    • the fields
    • *
    • the constructors
    • *
    • the methods
    • *
    *
  • *
* * @param cls the class * @return itself */ ModelWriter writeClass( JavaClass cls ); /** * Write the java field * * A standard field writer should write: *
    *
  • the javadoc
  • *
  • the annotations
  • *
  • the field signature
  • *
* * @param fld the field * @return itself */ ModelWriter writeField( JavaField fld ); /** * Write the java annotation * * A standard annotation writer should write: *
    *
  • the annotation signature
  • *
* * @param ann the annotation * @return itself */ ModelWriter writeAnnotation( JavaAnnotation ann ); /** * Write the java method * * A standard method writer should write: *
    *
  • the javadoc
  • *
  • the annotations
  • *
  • the method signature, containing: *
      *
    • the parameters
    • *
    *
  • *
* * @param mth the method * @return itself */ ModelWriter writeMethod( JavaMethod mth ); /** * Write the java parameter * * A standard parameter writer should write: *
    *
  • the javadoc
  • *
  • the annotations
  • *
  • the parameter signature
  • *
* * @param prm the parameter * @return itself */ ModelWriter writeParameter( JavaParameter prm ); /** * Write the java constructor. * * A standard constructor writer should write: *
    *
  • the javadoc
  • *
  • the annotations
  • *
  • the constructor signature, containing: *
      *
    • the parameters
    • *
    *
  • *
* * @param cns the constructor * @return itself */ ModelWriter writeConstructor( JavaConstructor cns ); /** * Write the initializer. * * @param init the initializer * @return itself */ ModelWriter writeInitializer( JavaInitializer init ); /** * Write the module descriptor * * A standard module descriptor writer should write: *
    *
  • the javadoc
  • *
  • the annotations
  • *
  • the module signature, containing: *
      *
    • the requires statements
    • *
    • the exports statements
    • *
    • the opens statements
    • *
    • the uses statements
    • *
    • the provides statements
    • *
    *
  • *
* * @param descriptor the module declaration * @return itself */ ModelWriter writeModuleDescriptor( JavaModuleDescriptor descriptor ); /** * Write the module descriptors exports * * @param exports the exports module statement * @return itself */ ModelWriter writeModuleExports( JavaModuleDescriptor.JavaExports exports ); /** * Write the module descriptors opens * * @param opens the opens module statement * @return itself */ ModelWriter writeModuleOpens( JavaModuleDescriptor.JavaOpens opens ); /** * Write the module descriptors provides * * @param provides the provides module statement * @return itself */ ModelWriter writeModuleProvides( JavaModuleDescriptor.JavaProvides provides ); /** * Write the module descriptors requires * * @param requires the requires module statement * @return itself */ ModelWriter writeModuleRequires( JavaModuleDescriptor.JavaRequires requires ); /** * Write the module descriptors uses * * @param uses the uses module statement * @return itself */ ModelWriter writeModuleUses( JavaModuleDescriptor.JavaUses uses ); }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/writer/ModelWriterFactory.java000066400000000000000000000021041325201777200304650ustar00rootroot00000000000000package com.thoughtworks.qdox.writer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * Factory for constructing a new {@link ModelWriter} */ public interface ModelWriterFactory { /** * When called, a new instance must be returned. * * @return a new ModelWriter */ ModelWriter newInstance(); } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/writer/impl/000077500000000000000000000000001325201777200250015ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/writer/impl/DefaultModelWriter.java000066400000000000000000000446261325201777200314220ustar00rootroot00000000000000package com.thoughtworks.qdox.writer.impl; import java.util.Collection; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Map; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaAnnotatedElement; import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaConstructor; import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaInitializer; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaModule; import com.thoughtworks.qdox.model.JavaModuleDescriptor; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaExports; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaOpens; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaProvides; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaRequires; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaUses; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.expression.AnnotationValue; import com.thoughtworks.qdox.model.expression.Expression; import com.thoughtworks.qdox.writer.ModelWriter; public class DefaultModelWriter implements ModelWriter { private IndentBuffer buffer = new IndentBuffer(); /** * All information is written to this buffer. * When extending this class you should write to this buffer * * @return the buffer */ protected final IndentBuffer getBuffer() { return buffer; } /** {@inheritDoc} */ public ModelWriter writeSource( JavaSource source ) { // package statement writePackage( source.getPackage() ); // import statement for ( String imprt : source.getImports() ) { buffer.write( "import " ); buffer.write( imprt ); buffer.write( ';' ); buffer.newline(); } if ( source.getImports().size() > 0 ) { buffer.newline(); } // classes for ( ListIterator iter = source.getClasses().listIterator(); iter.hasNext(); ) { JavaClass cls = iter.next(); writeClass( cls ); if ( iter.hasNext() ) { buffer.newline(); } } return this; } /** {@inheritDoc} */ public ModelWriter writePackage( JavaPackage pckg ) { if ( pckg != null ) { commentHeader( pckg ); buffer.write( "package " ); buffer.write( pckg.getName() ); buffer.write( ';' ); buffer.newline(); buffer.newline(); } return this; } /** {@inheritDoc} */ public ModelWriter writeClass( JavaClass cls ) { commentHeader( cls ); writeAccessibilityModifier( cls.getModifiers() ); writeNonAccessibilityModifiers( cls.getModifiers() ); buffer.write( cls.isEnum() ? "enum " : cls.isInterface() ? "interface " : cls.isAnnotation() ? "@interface " : "class " ); buffer.write( cls.getName() ); // subclass if ( cls.getSuperClass() != null ) { String className = cls.getSuperClass().getFullyQualifiedName(); if ( !"java.lang.Object".equals( className ) && !"java.lang.Enum".equals( className ) ) { buffer.write( " extends " ); buffer.write( cls.getSuperClass().getGenericCanonicalName() ); } } // implements if ( cls.getImplements().size() > 0 ) { buffer.write( cls.isInterface() ? " extends " : " implements " ); for ( ListIterator iter = cls.getImplements().listIterator(); iter.hasNext(); ) { buffer.write( iter.next().getGenericCanonicalName() ); if ( iter.hasNext() ) { buffer.write( ", " ); } } } return writeClassBody( cls ); } private ModelWriter writeClassBody( JavaClass cls ) { buffer.write( " {" ); buffer.newline(); buffer.indent(); // fields for ( JavaField javaField : cls.getFields() ) { buffer.newline(); writeField( javaField ); } // constructors for ( JavaConstructor javaConstructor : cls.getConstructors() ) { buffer.newline(); writeConstructor( javaConstructor ); } // methods for ( JavaMethod javaMethod : cls.getMethods() ) { buffer.newline(); writeMethod( javaMethod ); } // inner-classes for ( JavaClass innerCls : cls.getNestedClasses() ) { buffer.newline(); writeClass( innerCls ); } buffer.deindent(); buffer.newline(); buffer.write( '}' ); buffer.newline(); return this; } /** {@inheritDoc} */ public ModelWriter writeInitializer( JavaInitializer init ) { if ( init.isStatic() ) { buffer.write( "static " ); } buffer.write( '{' ); buffer.newline(); buffer.indent(); buffer.write( init.getBlockContent() ); buffer.deindent(); buffer.newline(); buffer.write( '}' ); buffer.newline(); return this; } /** {@inheritDoc} */ public ModelWriter writeField( JavaField field ) { commentHeader( field ); writeAllModifiers( field.getModifiers() ); if ( !field.isEnumConstant() ) { buffer.write( field.getType().getGenericCanonicalName() ); buffer.write( ' ' ); } buffer.write( field.getName() ); if ( field.isEnumConstant() ) { if ( field.getEnumConstantArguments() != null && !field.getEnumConstantArguments().isEmpty() ) { buffer.write( "( " ); for( Iterator iter = field.getEnumConstantArguments().listIterator(); iter.hasNext(); ) { buffer.write( iter.next().getParameterValue().toString() ); if( iter.hasNext() ) { buffer.write( ", " ); } } buffer.write( " )" ); } if ( field.getEnumConstantClass() != null ) { writeClassBody( field.getEnumConstantClass() ); } } else { if ( field.getInitializationExpression() != null && field.getInitializationExpression().length() > 0 ) { { buffer.write( " = " ); } buffer.write( field.getInitializationExpression() ); } } buffer.write( ';' ); buffer.newline(); return this; } /** {@inheritDoc} */ public ModelWriter writeConstructor( JavaConstructor constructor ) { commentHeader( constructor ); writeAllModifiers( constructor.getModifiers() ); buffer.write( constructor.getName() ); buffer.write( '(' ); for ( ListIterator iter = constructor.getParameters().listIterator(); iter.hasNext(); ) { writeParameter( iter.next() ); if ( iter.hasNext() ) { buffer.write( ", " ); } } buffer.write( ')' ); if ( constructor.getExceptions().size() > 0 ) { buffer.write( " throws " ); for ( Iterator excIter = constructor.getExceptions().iterator(); excIter.hasNext(); ) { buffer.write( excIter.next().getGenericCanonicalName() ); if ( excIter.hasNext() ) { buffer.write( ", " ); } } } buffer.write( " {" ); buffer.newline(); if ( constructor.getSourceCode() != null ) { buffer.write( constructor.getSourceCode() ); } buffer.write( '}' ); buffer.newline(); return this; } /** {@inheritDoc} */ public ModelWriter writeMethod( JavaMethod method ) { commentHeader( method ); writeAccessibilityModifier( method.getModifiers() ); writeNonAccessibilityModifiers( method.getModifiers() ); buffer.write( method.getReturnType().getGenericCanonicalName() ); buffer.write( ' ' ); buffer.write( method.getName() ); buffer.write( '(' ); for ( ListIterator iter = method.getParameters().listIterator(); iter.hasNext(); ) { writeParameter( iter.next() ); if ( iter.hasNext() ) { buffer.write( ", " ); } } buffer.write( ')' ); if ( method.getExceptions().size() > 0 ) { buffer.write( " throws " ); for ( Iterator excIter = method.getExceptions().iterator(); excIter.hasNext(); ) { buffer.write( excIter.next().getGenericCanonicalName() ); if ( excIter.hasNext() ) { buffer.write( ", " ); } } } if ( method.getSourceCode() != null && method.getSourceCode().length() > 0 ) { buffer.write( " {" ); buffer.newline(); buffer.write( method.getSourceCode() ); buffer.write( '}' ); buffer.newline(); } else { buffer.write( ';' ); buffer.newline(); } return this; } private void writeNonAccessibilityModifiers( Collection modifiers ) { for ( String modifier : modifiers ) { if ( !modifier.startsWith( "p" ) ) { buffer.write( modifier ); buffer.write( ' ' ); } } } private void writeAccessibilityModifier( Collection modifiers ) { for ( String modifier : modifiers ) { if ( modifier.startsWith( "p" ) ) { buffer.write( modifier ); buffer.write( ' ' ); } } } private void writeAllModifiers( List modifiers ) { for ( String modifier : modifiers ) { buffer.write( modifier ); buffer.write( ' ' ); } } /** {@inheritDoc} */ public ModelWriter writeAnnotation( JavaAnnotation annotation ) { buffer.write( '@' ); buffer.write( annotation.getType().getGenericCanonicalName() ); if ( !annotation.getPropertyMap().isEmpty() ) { buffer.indent(); buffer.write( '(' ); Iterator> iterator = annotation.getPropertyMap().entrySet().iterator(); while ( iterator.hasNext() ) { Map.Entry entry = iterator.next(); buffer.write( entry.getKey() ); buffer.write( '=' ); buffer.write( entry.getValue().toString() ); if ( iterator.hasNext() ) { buffer.write( ',' ); buffer.newline(); } } buffer.write( ')' ); buffer.deindent(); } buffer.newline(); return this; } /** {@inheritDoc} */ public ModelWriter writeParameter( JavaParameter parameter ) { commentHeader( parameter ); buffer.write( parameter.getGenericCanonicalName() ); if ( parameter.isVarArgs() ) { buffer.write( "..." ); } buffer.write( ' ' ); buffer.write( parameter.getName() ); return this; } protected void commentHeader( JavaAnnotatedElement entity ) { if ( entity.getComment() != null || ( entity.getTags().size() > 0 ) ) { buffer.write( "/**" ); buffer.newline(); if ( entity.getComment() != null && entity.getComment().length() > 0 ) { buffer.write( " * " ); buffer.write( entity.getComment().replaceAll( "\n", "\n * " ) ); buffer.newline(); } if ( entity.getTags().size() > 0 ) { if ( entity.getComment() != null && entity.getComment().length() > 0 ) { buffer.write( " *" ); buffer.newline(); } for ( DocletTag docletTag : entity.getTags() ) { buffer.write( " * @" ); buffer.write( docletTag.getName() ); if ( docletTag.getValue().length() > 0 ) { buffer.write( ' ' ); buffer.write( docletTag.getValue() ); } buffer.newline(); } } buffer.write( " */" ); buffer.newline(); } if ( entity.getAnnotations() != null ) { for ( JavaAnnotation annotation : entity.getAnnotations() ) { writeAnnotation( annotation ); } } } /** {@inheritDoc} */ public ModelWriter writeModuleDescriptor( JavaModuleDescriptor descriptor ) { if( descriptor.isOpen() ) { buffer.write( "open " ); } buffer.write( "module " + descriptor.getName() + " {"); buffer.newline(); buffer.indent(); for ( JavaRequires requires : descriptor.getRequires() ) { buffer.newline(); writeModuleRequires( requires ); } for ( JavaExports exports : descriptor.getExports() ) { buffer.newline(); writeModuleExports( exports ); } for ( JavaOpens opens : descriptor.getOpens() ) { buffer.newline(); writeModuleOpens( opens ); } for ( JavaProvides provides : descriptor.getProvides() ) { buffer.newline(); writeModuleProvides( provides ); } for ( JavaUses uses : descriptor.getUses() ) { buffer.newline(); writeModuleUses( uses ); } buffer.newline(); buffer.deindent(); buffer.write( '}' ); buffer.newline(); return this; } /** {@inheritDoc} */ public ModelWriter writeModuleExports( JavaExports exports ) { buffer.write( "exports " ); buffer.write( exports.getSource().getName() ); if( !exports.getTargets().isEmpty() ) { buffer.write( " to " ); Iterator targets = exports.getTargets().iterator(); while( targets.hasNext() ) { JavaModule target = targets.next(); buffer.write( target.getName() ); if( targets.hasNext() ) { buffer.write( ", " ); } } } buffer.write( ';' ); buffer.newline(); return this; } /** {@inheritDoc} */ public ModelWriter writeModuleOpens( JavaOpens opens ) { buffer.write( "opens " ); buffer.write( opens.getSource().getName() ); if( !opens.getTargets().isEmpty() ) { buffer.write( " to " ); Iterator targets = opens.getTargets().iterator(); while( targets.hasNext() ) { JavaModule target = targets.next(); buffer.write( target.getName() ); if( targets.hasNext() ) { buffer.write( ", " ); } } } buffer.write( ';' ); buffer.newline(); return this; } /** {@inheritDoc} */ public ModelWriter writeModuleProvides( JavaProvides provides ) { buffer.write( "provides " ); buffer.write( provides.getService().getName() ); buffer.write( " with " ); Iterator providers = provides.getProviders().iterator(); while( providers.hasNext() ) { JavaClass provider = providers.next(); buffer.write( provider.getName() ); if( providers.hasNext() ) { buffer.write( ", " ); } } buffer.write( ';' ); buffer.newline(); return null; } /** {@inheritDoc} */ public ModelWriter writeModuleRequires( JavaRequires requires ) { buffer.write( "requires " ); writeAccessibilityModifier( requires.getModifiers() ); writeNonAccessibilityModifiers( requires.getModifiers() ); buffer.write( requires.getModule().getName() ); buffer.write( ';' ); buffer.newline(); return this; } /** {@inheritDoc} */ public ModelWriter writeModuleUses( JavaUses uses ) { buffer.write( "uses " ); buffer.write( uses.getService().getName() ); buffer.write( ';' ); buffer.newline(); return this; } @Override public String toString() { return buffer.toString(); } }qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/writer/impl/IndentBuffer.java000066400000000000000000000036761325201777200302330ustar00rootroot00000000000000package com.thoughtworks.qdox.writer.impl; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class IndentBuffer { private String eol = "\n"; private String indentation = "\t"; private StringBuffer buffer = new StringBuffer(); private int depth = 0; private boolean newLine; public void setEol( String eol ) { this.eol = eol; } public void setIndentation( String indentation ) { this.indentation = indentation; } public void write( String s ) { checkNewLine(); buffer.append( s ); } public void write( char s ) { checkNewLine(); buffer.append( s ); } public void newline() { buffer.append( eol ); newLine = true; } public void indent() { depth++; } public void deindent() { depth--; } @Override public String toString() { return buffer.toString(); } private void checkNewLine() { if ( newLine ) { for ( int i = 0; i < depth; i++ ) { buffer.append( indentation ); } newLine = false; } } } qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/writer/impl/package-info.java000066400000000000000000000002231325201777200301650ustar00rootroot00000000000000/** * Provides the default implementation of classes to write Java model elements in any style. */ package com.thoughtworks.qdox.writer.impl;qdox-qdox-2.0-M8/src/main/java/com/thoughtworks/qdox/writer/package-info.java000066400000000000000000000001541325201777200272270ustar00rootroot00000000000000/** * Provides classes to write Java model elements in any style */ package com.thoughtworks.qdox.writer;qdox-qdox-2.0-M8/src/site/000077500000000000000000000000001325201777200153225ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/site/apt/000077500000000000000000000000001325201777200161065ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/site/apt/migrationplan.apt.vm000066400000000000000000000164641325201777200221140ustar00rootroot00000000000000Migrating to QDox 2.0 QDox 2.0 is *<>* 100% backwards compatible with previous versions. We've decided to move from java1.4 to java5, since support for java1.4 has ended ages ago. Nowadays most applications are moving to java5 and so should QDox. Here are the required steps to take to move to QDox 2.x * Replace <> with <> * Refactor every javamodel array to generic <> or <> objects, for example: <> will become <>> * Redefined getValue(). This would normally return the FQN, but now it'll return the value as used in the code(when available). * Redefined getFullyQualifiedName(). This used to return the classname, but according to the specs it should also return the array dimensions. To get the classname, use <>. [] Below is a table which maps the non-abstract classes to the refactored or suggested interface or class. The classes which are not mentioned have been removed or are implementations which should be called by their interfaces. *------------------------------------------------------*-----------------------------------------------------------------------* || QDox-1.x || QDox-2.x | *------------------------------------------------------+-----------------------------------------------------------------------+ | c.t.q.JavaDocBuilder\ | c.t.q.JavaProjectBuilder\ | | \ | \ | *------------------------------------------------------+-----------------------------------------------------------------------+ | c.t.q.model.Annotation\ | \ | | c.t.q.model.ClassLibrary\ | and \ | | \ | \ | | c.t.q.model.ModelBuilder\ | and c.t.q.builder.impl.ModelBuilder\ | | c.t.q.model.Type\ | \ | | c.t.q.model.TypeVariable\ | \ | | c.t.q.model.WildcardType\ | \ | *------------------------------------------------------+-----------------------------------------------------------------------+ | c.t.q.model.annotation.AnnotationAdd\ | c.t.q.model.expression.Add\ | | c.t.q.model.annotation.AnnotationAnd\ | c.t.q.model.expression.And\ | | c.t.q.model.annotation.AnnotationBinaryOperator\ | c.t.q.model.expression.BinaryOperator\ | | c.t.q.model.annotation.AnnotationCast\ | c.t.q.model.expression.Cast\ | | c.t.q.model.annotation.AnnotationConstant\ | c.t.q.model.expression.Constant\ | | c.t.q.model.annotation.AnnotationDivide\ | c.t.q.model.expression.Divide\ | | c.t.q.model.annotation.AnnotationEquals\ | c.t.q.model.expression.Equals\ | | c.t.q.model.annotation.AnnotationExclusiveOr\ | c.t.q.model.expression.ExclusiveOr\ | | c.t.q.model.annotation.AnnotationFieldRef\ | c.t.q.model.expression.FieldRef\ | | c.t.q.model.annotation.AnnotationGreaterEquals\ | c.t.q.model.expression.GreaterEquals\ | | c.t.q.model.annotation.AnnotationGreaterThan\ | c.t.q.model.expression.GreaterThan\ | | c.t.q.model.annotation.AnnotationLessEquals\ | c.t.q.model.expression.LessEquals\ | | c.t.q.model.annotation.AnnotationLessThan\ | c.t.q.model.expression.LessThan\ | | c.t.q.model.annotation.AnnotationLogicalAnd\ | c.t.q.model.expression.LogicalAnd\ | | c.t.q.model.annotation.AnnotationLogicalNot\ | c.t.q.model.expression.LogicalNot\ | | c.t.q.model.annotation.AnnotationLogicalOr\ | c.t.q.model.expression.LogicalOr\ | | c.t.q.model.annotation.AnnotationMinusSign\ | c.t.q.model.expression.MinusSign\ | | c.t.q.model.annotation.AnnotationMultiply\ | c.t.q.model.expression.Multiply\ | | c.t.q.model.annotation.AnnotationNot\ | c.t.q.model.expression.Not\ | | c.t.q.model.annotation.AnnotationNotEquals\ | c.t.q.model.expression.NotEquals\ | | c.t.q.model.annotation.AnnotationOr\ | c.t.q.model.expression.Or\ | | c.t.q.model.annotation.AnnotationParenExpression\ | c.t.q.model.expression.ParenExpression\ | | c.t.q.model.annotation.AnnotationPlusSign\ | c.t.q.model.expression.PlusSign\ | | c.t.q.model.annotation.AnnotationQuery\ | c.t.q.model.expression.Query\ | | c.t.q.model.annotation.AnnotationRemainder\ | c.t.q.model.expression.Remainder\ | | c.t.q.model.annotation.AnnotationShiftLeft\ | c.t.q.model.expression.ShiftLeft\ | | c.t.q.model.annotation.AnnotationShiftRight\ | c.t.q.model.expression.ShiftRight\ | | c.t.q.model.annotation.AnnotationSubtract\ | c.t.q.model.expression.Subtract\ | | c.t.q.model.annotation.AnnotationTypeRef\ | c.t.q.model.expression.TypeRef\ | | c.t.q.model.annotation.AnnotationUnaryOperator\ | c.t.q.model.expression.UnaryOperator\ | | c.t.q.model.annotation.AnnotationUnsignedShiftRight\ | c.t.q.model.expression.UnsignedShiftRight\ | | c.t.q.model.annotation.AnnotationValueList\ | c.t.q.model.expression.AnnotationValueList\ | | c.t.q.model.annotation.EvaluatingVisitor\ | c.t.q.model.expression.ExpressionVisitor\ | | c.t.q.model.annotation.RecursiveAnnotationVisitor\ | >\ | *------------------------------------------------------+-----------------------------------------------------------------------+ qdox-qdox-2.0-M8/src/site/fml/000077500000000000000000000000001325201777200161005ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/site/fml/faq.fml000066400000000000000000000063041325201777200173520ustar00rootroot00000000000000 General What's the objecttype of an interface?

The JavaClass method is used to represent both classes and interfaces. The isInterface() method allows you to distinguish between the two.

When using a class, the getSuperClass() return which class is extended. If this has not been defined in the input source code, java.lang.Object is returned. When using an interface, this method ALWAYS returns null.

When using a class, the getImplements() returns an array of the interfaces implemented by the class. If none are implemented, an empty array is returned. When using an interface, this returns an array of interfaces the current interface EXTENDS.

Can I have full control over the classloader?

I some cases QDox is used to generate classes for another project with it's own dependencies. This could result in class-collision. By default the JavadocBuilder will contain the classloader(s) of the current project, but by defining your own classLibrary you can have the required control. /* new ClassLibrary() will give you an empty classLoader * Big chance you want at least the system classloader. */ ClassLibraryBuilder libraryBuilder = new SortedClassLibraryBuilder(); //or OrderedClassLibraryBuilder() libraryBuilder.addClassLoader( ClassLoader.getSystemClassLoader() ); JavaProjectBuilder builder = new JavaProjectBuilder( libraryBuilder );

I'm getting an ArrayIndexOutOfBoundsException: 500. What to do?

During the parsing of java files the Parser needs to remember states, which are kept in a stack. Due to recursive calls the stack can become very large. By default the size of this this stack is 500 and it can only be set during compile-time of QDox. Normally 500 per sourcefile will do, but in very, very rare cases this might be too little. The only way to increase this number is by rebuilding it. Download the sources and build it like mvn install -Dqdox.javaparser.stack=750 if you want to change it to 750.

qdox-qdox-2.0-M8/src/site/resources/000077500000000000000000000000001325201777200173345ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/site/resources/css/000077500000000000000000000000001325201777200201245ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/site/resources/css/style.css000066400000000000000000000170461325201777200220060ustar00rootroot00000000000000/*--------------------------------------------------------------------------- * Two- and three-column layout */ #banner { margin 5px; } #left { position: absolute; z-index: 2; left: 8px; width: 184px; top: 125px; bottom: 8px; margin: 0px; padding: 0px; } #right { position: absolute; z-index: 1; right: 8px; width: 184px; top: 125px; bottom: 8px; margin: 0px; padding: 0px; } .Content3Column { position: absolute; top: 125px; bottom: 8px; left: 208px; right: 216px; } .Content2Column { position: absolute; top: 125px; bottom: 8px; left: 208px; right: 16px; } #center { z-index: 3; margin: 0px; border: none; padding-bottom: 8px; } /*--------------------------------------------------------------------------- * Bradcrumbs */ .xleft, #bannerLeft img { float:left; } .xright, #bannerRight { float:right; } div.clear { clear:both; visibility:hidden; } #breadcrumbs { background-image:url(../images/breadcrumbs.jpg); height:13px; padding:5px 10px 14px 20px; } #breadcrumbs { font-size:x-small; margin:0; } /*--------------------------------------------------------------------------- * Default element styles */ body { padding: 0px; margin: 0px; border: 0px; font-family: helvetica, arial, sans-serif; font-size: 12px; background-color: white; color: black; } h1, h2, h3, h4, h5, h6 { margin: 0px; border: 0px; padding: 0px; font-weight: normal; } a:link { color: #9cf; } a:active { color: red; } a:hover { color: red; } a:visited { color: black; } iframe { width:100%; height: 800px; border: 0px; } img { border: 0px; padding: 0px; margin: 0px; } p { border: 0px; padding: 0px; margin: 0px; margin-bottom: 10px; } blockquote { margin-bottom: 10px; } table { width:100%; padding-bottom: 6px; } td { font-size: 12px; padding: 2px; } th { font-size: 12px; font-weight: bold; white-space: nowrap; padding: 2px; } th.Row { text-align: left; vertical-align: top; } ul, ol { border: 0px; padding: 0px; margin-top: 0px; margin-bottom: 12px; margin-left: 20px; } tr.a { background-color: #7EB2E4; } tr.b { background-color: #BDD7F0; } /*--------------------------------------------------------------------------- * Page banner */ #banner { margin: 5px; border: 0px; padding: 0px; background-color: white; color: #06c; vertical-align: bottom; } #banner a { text-decoration: none; } #banner a:visited { color: #9cf; } #banner a:hover { color: red; } #banner a:active { color: red; } #versions { position: absolute; width: auto; right: 0px; top: 0px; margin: 8px; font-weight: normal; } /*--------------------------------------------------------------------------- * Page content */ #content { margin: 0px; background-color: white; color: black; height: 100%; } #content h1 { width: 100%; font-size: 18px; background-color: #06c; color: white; padding: 2px; padding-left: 6px; margin-top: 24px; margin-bottom: 12px; } #content .FirstChild { /* IE doesn't understand first-child pseudoelement */ margin-top: 0px; } #content a { text-decoration: underline; } #content a:link { color: #06c; } #content a:visited { color: #06c; } #content a:active { color: red; } #content a:hover { color: red; } #content h2 { margin-top: 24px; border-top: 1px solid #99CCFF; margin-bottom: 16px; font-size: 15px; font-weight: bold; background: transparent url(../images/blue2white.jpg) repeat-y; padding: 2px; } #content h3 { padding-left: 13px; border-bottom: 1px solid #99CCFF; } #content li { margin-bottom: 6px; } #content th { background-color: #3E8BD9; } .Source pre { padding: 4px; font-family: courier new, monospace; font-size: 11px; border: 1px dashed #06c; background-color: #eeeeee; color: black; } .Source:before { margin: 0px; padding: 0px; border: 0px; font-size: inherit; line-spacing: 100%; } .highlight { background-color: #cff; border: 1px dotted #06c; padding: 5px; } /* The following are for images, but can also apply to div's containing images. */ #content .Float { float: right; margin-left: 8px; margin-right: 0px; margin-top: 8px; margin-bottom: 8px; } #content .Diagram { display: block; margin-left: auto; margin-right: auto; margin-top: 8px; margin-bottom: 8px; } #content .Inline { display: inline; } ul.referenceSummary { list-style: none; font-family: monospace; display: inline-table; } .RuleOfThumb { font-weight: bold; } /*--------------------------------------------------------------------------- * Side panels */ .SidePanel { background-color: white; padding: 0px; font-size: 12px; } .SidePanel h5 { /* menugroup-headers */ margin: 0px; border: 0px; padding: 4px; color: #06c; font-size: 12px; font-weight: bold; background: url(../images/white2blue.jpg); } .SidePanel a { text-decoration: none; } .SidePanel a:link { color: #06c; } .SidePanel a:visited { color: #06c; } .SidePanel a:active { color: red; } .SidePanel a:hover { color: red; } /*--------------------------------------------------------------------------- * Menus */ .MenuGroup { border-top: 2px solid #06c; margin-bottom: 8px; background: white; color: #06c; } .MenuGroup ul { margin: 0px; padding-left: 20px; list-style-type: none; } .MenuGroup ul ul { padding-left: 0px; } .MenuGroup li { padding: 2px; list-style-position: outside; } .MenuGroup .currentLink { color: #06c; } .MenuGroup li.collapsed { list-style-image: url(../images/arrow_blue_collapsed.png); } .MenuGroup li.expanded { list-style-image: url(../images/arrow_blue_expanded.png); } .MenuGroup li.expanded ul { margin-left: 5px; } .MenuGroup li.none { list-style-image: none; } /*--------------------------------------------------------------------------- * News panel */ .NewsGroup { border-left: 1px solid #06c; border-top: 1px solid #06c; border-bottom: 1px solid white; /* IE workaround */ margin-bottom: 8px; color: #06c; } .NewsItem { margin: 4px; } .NewsDate { font-weight: bold; margin: 0px; padding: 0px; } .NewsText { padding: 0px; margin: 0px; margin-bottom: 8px; } .NewsText a { text-decoration: underline; } .NewsText a:link { color: #06c; } .NewsText a:visited { color: #06c; } .NewsText a:active { color: red; } .NewsText a:hover { color: red; } .NewsMore { font-size: smaller; margin: 4px; margin-top: 8px; text-align: left; } .NewsGroup td { font-size: 12px; } /*--------------------------------------------------------------------------- * Document meta-information */ .Meta { margin-top: 64px; font-size: smaller; color: #C0C0C0; text-align: right; } .Meta a { text-decoration: underline; } .Meta a:link { color: #C0C0C0; } .Meta a:visited { color: #C0C0C0; } .Meta a:active { color: red; } .Meta a:hover { color: red; }qdox-qdox-2.0-M8/src/site/resources/images/000077500000000000000000000000001325201777200206015ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/site/resources/images/arrow_blue_collapsed.png000066400000000000000000000025541325201777200255040ustar00rootroot00000000000000PNG  IHDRasBIT|dsRGBgAMA a pHYs+tEXtSoftwareAdobe Fireworks CS3FtEXtCreation Time2/17/08 XtEXtXML:com.adobe.xmp Adobe Fireworks CS3 2008-02-17T02:36:45Z 2008-03-24T19:00:42Z image/png 5RdIDAT8Oc & ߾ qSrVl˜(C{Ɂ!! 7BqB< \\ V3_(.زf iqcp,A ~f5'?IENDB`qdox-qdox-2.0-M8/src/site/resources/images/arrow_blue_expanded.png000066400000000000000000000026041325201777200253220ustar00rootroot00000000000000PNG  IHDRasBIT|dsRGBgAMA a pHYs+tEXtSoftwareAdobe Fireworks CS3FtEXtCreation Time2/17/08 XtEXtXML:com.adobe.xmp Adobe Fireworks CS3 2008-02-17T02:36:45Z 2008-03-24T19:00:42Z image/png 5RdIDAT8Oc & ѷo+Ö "o20X# A8Q6v@`C }\\z`_!l  0Nϰ%ٸV<v $?#kbla)r{IENDB`qdox-qdox-2.0-M8/src/site/resources/images/blue2white.jpg000066400000000000000000000015021325201777200233530ustar00rootroot00000000000000JFIFC  !"$"$C" }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbr $4%&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz ?QҊ+phHQNQP:ӅRcBQRƇSRe )íTQEKSTQNQH:QEIHQJ(pEK(L( (cC(E,c(P֖)2J(T:Ө) NQR1”QEK(pKE,hu(PJQI;6/2>k!1;?V1<)9%11>.>+=CEB)=/9HIG%@3?3C&=.D1A=DKLTDLo>LILf>JNOM7K,G=L1GQSPAMRR[2QVWU8O=NAQPVWYpZ\YNU5TPXKWGWGQ`b_UaX]_bpS]cclbdzfheKaI`G__f[fZd_hXalnkXhQdWfdllngpWjrtqurksxyvyxjvnwesdrhtiwrzw{pv}|twn{w~҃t~~v芌~э​퓔Еˑ⚜뜜♠գܦΣɢթÞ舘鲴櫱ல۶ٶεշǺ¿ܿȼſ,d H*\ȰÇ#JHŋ3jȱǏ CIɓ(S\ɲ˗0cʜI͛8sɳϟ@ JѣH*]ʴӧPJJիXjʵׯ`Ê%ٳ]PԀA rJ,0(q8>I5>fO;s1cjB\Ҍ1 1,#4Vi4,! g `x>Ts}1PYp^8r0Bδӎ<5dE6],48 0"K-jIeX84 <а6hVbAC&!I(ӴꪫB/t`+&F$(8E/J)Բ4|C9W8R25{&J2!BLִj 03qbv -D5?LGsS 3pu# 4d`k|<O>s XEg}*^ҽ zj5XCP9H@\c~d74ח}o>cC' -(=arl!vADȉ>q 1<@ы\@+$P<!M  >GDEjF5nUcd@ZA>r2 k\Dhp_|I"{l{ "g#Ax 0/cEJG(}x pbЌoxKx),E"VP2p86΁ot04q#57XVB{cl H1 'Ak%FD ր FHB! hÆN0F 3l;2ǯqTn(d#3@ ݸR*'k<఍W U<'F4 #."ݢ T=j΂K)42ɞrd;@Qj  2W3b@Mͮ,`/ž/.iZP>7L8!ҵ * 5\z` 4;}ܣy6(/y y*qdp[nd RbԲ"|#k QTMd4h(>q H2y8f4':Bn7lFGS"A׍J j>b}PJd>*"!r^a<"h5.ߨ/HK,qls<ۑgQ@)C'YHwaQ0F7ĹɎq .E({esD هn_ Kfr|Zv!~@f /,lU(aXJE?5! b|Ļ[q E"jJZу p/Q InG "!jqݾZoKFs$ [ \z-U)XrF, f9xe|~*~GD|ֈaƟ=*a0(E'j#kK% `3)^5+H[m}Z:rTɷڏ|v"6Fq9+!4ʰ1j W$[mRȠ # ;Kr9AӕW]?Ċݘu6| PTrςHPmS5B&!vhE7W eGψP@4Xqm@z>"-a9q^H^$"腅)P-pwdg @P 0~qS& Wfp rAW İ @5."4}WW >4`~pG~a9z: r '0cn#Fbh`fPsP @` 3/٧ 'x4:0Wٕ" | @$g<( r1{]eF`_p]cX2|0V[g nm׀pp\`x & -X's g!B k !*ܰ"0pFPӀﷇ8DB2` W:<{D8"DBP'/ WXЍD@ $H%A4pȆHS +XwX[NjH1 a2 / UJy 3wDQ|ߠ؍0]Ԑg(ЊDB.ath]!@q0Heaip9c $D@j+xj$W@s8qpyUtW )"!Њ+"Fyx1!:j@q}@lfa) # E~w"00X$ uUloh!yf_ rA*aw~u9@q*}w`{D Dd@5fH؍8 |%&A< %E8AFu@0"tA$`(`gat Mi驝y;gpi( hiPV [%7py0a9p&QGHuɠ;k FP NdADXI'c  O }P%*0J-@_%t*9`l8Z wdTdV/pi P.ʤ$xL까/ږqQPD ` ]X EJ@ٞ@s 1ؙfI`dS}[$zx AFY @qqP@ (‡XB&~P9}({@@p馢FAdk\*xI[ =WjI)p 0 ` p n@L 5d9d --@S*eԨ"0jl(~YƝ0z| IkjPvƪ jl7i8M(` t#a__c 1E0KJ)Zu=d~*`+ 1a`Uup37Ʊ1`v2t/j10Pİ +@L; ,/I&~`6<dו]l?ۀX[TNP{-HvI0Yl_+ѩ 10dS֞X 0 1c!@LNEr#j`e3ID[rQ0Ytc Jkq o2%Z5 C8BKAF$kDF̛I@pPs` `h w ׀]w@ X,_x(-8av4OPIySA$KHW )UNjDHBQ;D1usc0wLd`+lt4Ps &'E00f^ /g 0xlj` 9P[@hD By C 3@fjPsPevڦא@d#I[K +@ecFODp ` *bBtw\`ϻ:ˠ aGg IJP 0 5_θ0]kC[)k@ v`7?T0  "IP@T]X " AD\ Wyp` >;,(Wr PiS]@V]6ǘ )&hQ;Ɓot@fb @ WAګ mo^p |0ƀ}3-|P,ɢlT"s܀ DS"Q0Ѯa`6pLf5r1 J,AMWx.8 p91@ȰR%p  & صe2&' ? @ZSr!  O:Yxr w5G 0Ѐ ֞@p*6ڊp&0. ' S W,8r} ̠ aڀ @/@ j  wQ|@ W1 -WIڐǕt .cU@sȇpN.c 8d$mo  ak ې"} >25pSxG/]'b3dNIG  6` 6nc i0 ؠ  {. R @Y`WWsUgăj9~Y~a2Bnnm p .pJPP am gC_5 @ s`:H 1-a83/Q(w!.tʊ LJ!~} ЇՑA թ{kA@ P:^D bw"5A!B-2 O GQtXMI`G,1S3 ư\' `& l3263@/zY A.8 v  L ]qm +a `=+ hOT$QH B}*B)'o!W2!Sr!l;$B@V}?)*ml$@ C^X'C#@ ?]/i^'Q{Sg\8\ta;ye(^xuF0x8p f]Q|G^Ś)=`#M1[(Zm.R&ynjDv 8Q`…h#NYWɾ~N{SƏzML"I~Qb]o*z=J[V)J\V8#KQrͮytÞ];v|};+t|##Fy1V~[W<_J{~ jhrۭ79n8!' Ǿ0ÌC9'DbNDC0CVE 3qD?| (iTP#%dnY`1JCJ(2K!餄T닩lƕN90Aa`M4IG4N;ӽ>32e9.nM6ElȡRK/E1{O:y t38-EoTl1x SYg5 1о@B!6g2$` X5Zioh**B򌡩Ŵ+~uNrB7P?Gny"@3! P`0%t8j2մdZ:t? _ ;y rc^ TjUW.":A" M7t'@n(o$QUƴNWՔ$T8~{\p]]+7T-D'WL'EhHRW*[P~Wۃ/^XC\nHzI?aw ߘc&NV@6Q+grZ+eBe/oxg j'k|pѢBJÑm+hVl2ֵwjGX'7fP|AE3 HUW(&9ҖOk!ҕAP cjGˀ^5|S0DTDzi~4j)MY5q ?Nޗ,+fl P5Bȷm1W,/-ɐ 2`6h9mt?ņ`H 5[X W7X#M!AKih2\Gx K88w Bj 9S{'4yXǰSv;=fYqt& d28T6_)B=jdߨ bPrSHNkE}@p|Ald/őUȲ?~ͅܛ!ͺ^Zhb^@N-3qtZ1МќVآᷝ.þ+Z!{,G ;fnHWR ͷ}sų.`jcy۶4-NgwL>XrJQ@Hmk5G}O"_hhH*P*k è *1H硪$r%^spD"Py~I8sOrh9\c$U6dVk}Nu+ukmKw$=AF+&nˌT4W5,J8L.)KpOֳ5{醨|ph\pl:"}{I<fU$PJP`R)T*3xėT*1dGFdp?#xy.g<鶸]p 8w }a*TY֚GpKiPJlTgE 0fb,E!kZ_4kKbѴ,a3"0dL3t.. !lj+ W7f#4?TǾyXG++AF.~2Ej#;1pM`hp?$ZᶔL#?ŏ=h2cY1q&i`Y 0}7㋮OcZ {^:I{#mvOd@xPOݕO'ud'6l u:XKaf)N22L uq?2o܏7@Yiyruw *IQj)M7bHmLmPye0ܛZaGJ35Z ̻?z1{ 4G[›e'/hP䣁>.6oZ\C`;{ݒ~}yֵ-؉Ao`Ed*̀;8pd=l8X%'9MoV1iZԐdpasYvQޏ"7Mbzf W@mqSPm4 G?qY(s0@g.@pbьo[oa`yDS}[eb/.o!E j}~o(Ny#&`K|<2E6D-3 $䐎"Ìp0v71'^^g"H3r;|t|ko&5ぃ]Xc5 1'NrMjyfhb!"DΜā ft֗(?Q"7䗔?\ȶP*_<)Ͻƽm2VqưY0T E[p6\V2,q3gQmx\܀|VŲÙNF97f%1,3oR|jh(>Ѣ"g42v9aLSQ3v?kW~у=TyH]s}^|}~`JLb$Wau1 xޖkb4{re+Bۏ=\ӟ#tԳ- MynUE,X?66 /wʔ*3;ppwn%j*? 8E:SL5EZX[KVZZpt?Y j] ߾0VJm0l9생[ hN4s/W뾇?EA /ԇrym74<|sy13:sǛF>崩kaܕ,礮'*-֗N`m yo/؋podښ8lhj> n^ߵ/᣹ prV@pJ4 dYriYngE?;jL>z[NX n uI`WVOy0sr{Oa,$aPV҇;Oi)qTBSEAJO=,F8BL]2|.kGϏZNM>Ն%ֻDDyɽku6V,`wbb".+x8&Qy B$čնv1]LG;<0n{{8Cq=V\q؇&0{^:p Ri'I|;.#xoM% "ؘ!9'CY5=~OXKiu8I<њ~> SP5Hֺ!W/OjTU^X&, fxvX, |wѺ~4jr44fMe hЩ.Oj:'F4C!c#@d#h_Iݨ|U3[pw5 xWy^#<4AܪGqaXR:YсVM"oqŹO]6])IuڋÜܑ\JB+ TKK\PAv?}dUo,YNd\pawax* b(0H(L r}=K*|Zp&:`eH1]= 78Cm^1c0mX˛TGn2.gYxl}}t/OHs!ima n KؐxVUϔt&5u,, "4u-x+KzS"I)!գf:Kh$x}|肽ȼ0*p~ wt%x r9k?cMrֲ{H=E۸'肮{M9%ZKdm۶Z4< vk蟾/=rT`k*1]ґGgt.KgZ [J*@9yjn..N gn3CZ2Mނ6h<J i& !}aoh@?hf~iɪ{DŽor yR}^V~$n{bm%bb46[B{].ϴ6օ{MiC2R f>BY|SQ(I\7, _7pY0wnF#4Ҧ/g`nkG:voOQGvZki Uoa4"/s! "~|gS'ډ24q{tu(P!ILV'@,|p@ɘ\k퍟3- e$N郯88h c':N]\+fHIː'}#7± LvjP>s{2l<(|̔gXY/pv ] s';*z%O ylvWՃŋKG]~WI<,O(u,[/F_T 5t̺d=8ӠvAܹ$dPC" ^B S^K>L[x=A#ۖ2]Ib(z>|Oo+ | KX;9($bD/D'-@~ u?y0h8{ieƁ|T I}ɦn7ԡX=ǿBŵu+V4MXPLgM 2 % !|fweGdp2G!g94 >p$j5Sz/[qqn?) WElSXod>\]e˖6pY,{H.baSæ<_8D ֤Nvp[|.&0 GS*><$rpE&N!YILegfxp~*BgUj,;[4:o#tEe=c^ =;bȡT| HE%$*I4:/lNt`7w,Ir% bV)`[MF+$*dzĬ ]\VPChkM8}K,?O|a厁n%Zà9$!_t?7o1Y+6b?SkHW<@s`*bONtD]b *Yl^a+Yݧ:18%&@@UW^T7?RfkBs Jk0%SLUHި\3@$wwlzͶ}BVh }w^S>aT0 ,CdLw0E~cYR߇X{#ʵI J h(Yf0>lDMnk:t҇8lK@!2tX|s\E:?^P$/d34DGOwLWڎt63< *O'ϳ߂8 }Z/nqQ&38Ll+ƇDyUՃ8XFvԘVКX̟;fgQTj5C?~lke, ` 6. K K )xyf!I^KQG5hc/n=Nt_A_ˆtGϫԭK󯭄懻qee(7JOenT>WEq{b  By1UFi>CaSL UZx6WTx锅(}G@| %#'&ߣ?+g5ThwX$ȚWрO0n,mX(Օ^gWu6LK,wYEt\ɋn0B Ud(ۖ{2:5,N 3h.0iliq4.P*ƀ3LTiq-rUe;u"@;n%R ,S_POX{ͫW}=?{Gmwf/VF͒{ˌ,^&Ȱ7*mw[K-Rh4@W w}$/,&"$1-RW@(( pS뱕KYOj=apؕѡeEuԱli9yZ>f0qQH/c|?(A|HГ[%|2q LGU\z؛ jp:>9D+--mR.vx߮w0v rW;gW 5on.l\73`pNYxhMUk6Z7wV?+_4ou] 'pE{bŬ^jU>4_Ƣ]Axťohj*0`,LX 53d]xB@IBMHvrӠ K3գS1@|q//x<BYƐt|cR F(MMM i NPӹ%+% T-<219Dx*Q$2l~"P-w}o˖àJ) 28a fB&g5LH'u^ :L3H'gEoh_=]jos8lvl^O|r?^mۘN~桯~vs<,cQ1ۆĴK@XH' b^W>.K4'*.Bm=eP%yI|A{D7> 9 g gm)㮒ke-ɌHyCCᑔ<dGeL#Gct0$A"'d}ή-:Ul 9׻r/itͫwͮr}W!ru^_ˋ WZa!fu2(ٹ~ԂP%P5l7Rm-'b>zG?2%:XSZX*ֻ!I5YJ=i6XoC%ZM(7ޙyQ\bSڪ9ZQa!(y'h BgNJI2`~BA'(Apc"+!fvXլe⥴֙>M{m]rӟ%v,w$ @PP.GDsǁ#7' Q'( 5jl4zdJ6 NE?b$=_UzZgGY9>ܜ\+"HTZMdC,d~?۞.-aAkyfϲ&:.Qqx? ukz)̾l2,.ZMuXtW/`題Z=VcYBZuQSU^jdrfu=t\l{sVWLآ2g;\.׹8fFXwwzrFU0*/%0Ӊ*#~㿨 TRP!X'M*hNhO3' h+~3+V8DU']I?X ?ڝ;W"ieX]w 0M3|mwC1~K 鱸5Q:5ݤ]"S{`\-w\Bv^3H"a([(d{)[ΌecNϱrSF(bƌX1_Myӟ32UNB 9Xa,/gzATEB^=EGA\א,C>D/@$={ti^˞h*lwj^"Nq !>J8Es񍕞 1$PȖyC+oW<1~ #Y QH3Y;v\ _H( rKuWV777èvvvb%h-_I~ HƧGDŽZJ֊*uZi*I*4T(_L$“fI5VsGjb.$՚k`:G suz3eb`\R $f\\lzZXP\V)꾸ZzƯ|; fq.ڢ|WQz"%@jcJDfPOq :NJg$K "9 w*l>=J=r6mղBa-:>.s-E@fݬ=hpȖaANd,2ebT{/3]{s=>D.)pɺH-jI^~{ !՜}e@k䗌=OnCBCRMK9 fEf)p ?~?jDJ6THnE?)d#XQtaMM+C2.@/(AL(h1XQsS6W&TRߔ C]*;(wҠd$̒AL}P 18Hh@e–8 7-H J7,< @h_5kYs'r^D1-mMrhG%D&_VMe a] zw]rBYڻ VX$a`il APAV˅K 7_w$J88+kK`8" X0s U'=TQ5xF%QLfSXꠐJBjEv;.0wJيʰٔxWGlۼ4ن()#ԤC\8zlHymMMP\<*i,b%ts}`oKeEUarqlZpD%G"knnf^>3Ѱwx+m+*L$KE @8.p#=ZHv)tBĻO~k[TJ 7FNdGUþA'suG#C0;ư JA>I%R.G]-c^? 38 s@]J UyXG[/9S"@hw2~p\]Q_,-x Ɵ[U)8:;|X[}xJ6K `_.]2pM}c+/v\R(e+ZÆ߫lՓ$L$U'Bz28n=`Zp\,eCc+oLJs,a2ݹ n,vddAa仜"]V>sEȡT'p=zpLzp:@"k{\Z:ZCNœvYtzvjgCUJ a*ifyĖJMk{FEla/V_,侁+o%PWw޺_2#wS ON >iϝw_Tó)!t;iXv):/9&#?aw!i%=RvVY&y"a\tPYrɮ{ͷRjHv/]:{nO9鲠 +"n" EJT@Ҫ޳ͨ "֮p Ti 9NV̯R_jtMfL|UQF6OKT^;*Ih);i Jeecc_9pij;썟ޮI5lQa}Rߪ.aSC9 o")Z2xEx㍭cs:Zs~MW*- VɍäF a=+8mYLM 3*bEؓyyUua 4i ^te:Hĺnq@VH5*O_|#TivC;8\5MbaKqvJg׋ݸwpw+{I#*CU ϽgvY,QOCrK ҉7x ?X a4- PNk01 H\t+۝ZUOcӘMWW HK? =<>Q쁽TTZW5߱Եˇ}4krwi/5q8]!/)o:XX|roΚ XLT&.WD3K篾dom]_#\f'Fa]1@[뇽cX!,%HUOd=K(C/t3vg' p)'GrG/\X[Msm]N93?zuĢ[KKW7 o=Ol;'"?`wÛ}dGX+*闖'S6k<|Ec5#$[=-z,d̛ E~1EGw?7bƇx\FK:;$q5 n8|#vFW0ʅ(`^}Z E`QPǦ'gw:0L|;Ʌξt?Tw-0u슶7{Cu'h:jbmjj8PpGuR9c ů=u ?Kq XQ x|W'{H2 Fh7}$'li"J޲&F" RWV{}̗F*95., BDL|26 L4Nm4),km.g 57б@MலXF#V64/t׾ԒEɧǏ웞`6bj9Hs|?|«2b\ Xfۤ*-,Mں/w;)TO_2sƶϬ=:Fqv~ohPO>TP:5 zcXR(w4ˋ=Ҵ UF \PBfg-4 W{}֥UX0Uf]#[F^ETp=űxӎe <\n5}#k\R ]s`*ڠ9J ,%ݜ;n7-X/GǷPd$N3I@z jCOY{y"ʘLh%Xx[g6(}SeK7h@ <zt0KS「T $M #׹@ A| Ƌkk:v+9 䦼[$DzrW>B]>/9{n?{Oz{Krb8c7uSv4Sg ]+f(QxULۜs7D7DCPxݮWv<<ЩJFZgF W6 s9G> +v>'=v*Z #OSo`!`8XC~ۿq yCfSx.p1n_6c@7=xHaPmżDCژ]z>m6gP'(46Nbmÿ>Uٱ0tK) _n%oFf._]k1$cӵgf~->z'dGFI%VEUR\7!dUQ2,SW<%xm3ϛ ]ljNR i .+Y!ZbƖή|pG+Au ]ծcX 2\*qp)W;QX1'M/<`#ҿB wE ˛{qa8H,@o|>ݪ$*}3.Ƴ==mK/AaJ"<O'%_"늸U y1$52^^1ѷ1kݘ` nV$'MKR+$njrǶy/HH`KNH[3_3t@T8 &QSm%Kig)-iTV+N[ ǷvP7|o뻛l:**D߭)G x\6+ϠM̟PگwTz.*vG(͸d+{$p=05N#'}?t6f"mZ ԣM%%cNE^ 6JtxK8]k /l[<';`Iuij۟".١@mS{ns3_ӵ; U nRyJ3(}쉬4caH+tZ>NTo;;[ UAg  UA7? y1Tm\F-gFg>gT׃%TW"*o%DlZ>Zt)3ߋVH @O]#g2TnQV*W zF/N[|I=\,"7/8_'ᖶyms_:ضb_:]`Ba>+]E"$襇W&Sҗe(VAT23'2WYYɳF𻌅m̯s.zU)!w#=-V_tvb*]]0ܠnH둸5/OU`aisj\,&e&qZQ̪gFEZܸgA(7"D\G~4/f=Adt}n߿;7UԶs:zȤSSڠ{׆l:E}d̆ b]Y@tV".XOdQLs2yf8/ɾ}3vR6aW.X.w?TN͊.+)KfejJKJϗHJ9L:29<`zDvA+0* ~[:P_}8q5J{=p2T\p8a|ց+ȗ@GAG2]dଂ;6W:r.( [9Y/psUhs댢EEk( Ct J?t~qhQBP@s 9y n1ج8Vd/v_@u4UO HFtb U2>C)aljVJ٩ jll:Ŵ=ΣM6MZۈVipIkJcj'k0Gr%-y|+Ѹd7*aE3N{@0X*\.gRU X[HyJ(E`Y͈_ wod,:TYA^hͪ*^*~[K* b̔tT5%SnU 7tDrYTTء:ćE|ˮR_+U1V cvɲ UʖjdUSPzt O;W/)]*e'̒/W~F]GMR fNy%~Ϧi31=_L$*g{TEؙ}1#4~7 ᬞTi@IMU[P zܑ +M}feUcSƉ͇ vђge671%ߣSIOu#2庑)s6HBN@Bwo~z::I(}`нJǻ\rOgT%v2i d*כ{FA.zi;Hz Af60 - {xStH\bљ2=䟇TԾ8umW?| q f VWm@I,;iۧ羆cP2^~K?Ѵ@1xS_1 %x/xVXq:Ă?8Ax{?\u[IENDB`qdox-qdox-2.0-M8/src/site/resources/images/white2blue.jpg000066400000000000000000000013701325201777200233560ustar00rootroot00000000000000JFIFC  !"$"$C" }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbr $4%&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz ?j-V3R^Nj(H-TWL $TTWDi%U%E %w"ꤴQ]00R^RZ(*KުKҊ+&*KU&"j袺ba"袺"sȩ7z(?qdox-qdox-2.0-M8/src/site/site.xml000066400000000000000000000035161325201777200170150ustar00rootroot00000000000000 Codehaus QDox ./images/tekton_logo.png http://qdox.codehaus.org/index.html qdox-qdox-2.0-M8/src/site/templates/000077500000000000000000000000001325201777200173205ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/site/templates/site.vm000066400000000000000000000306361325201777200206400ustar00rootroot00000000000000 #macro ( link $href $name ) #if ( ( $href.toLowerCase().startsWith("http") || $href.toLowerCase().startsWith("https") ) ) $name #else $name #end #end #macro ( banner $banner $id ) #if ( $banner ) #if( $banner.href ) #else #end #end #end #macro ( links $links ) #set ( $counter = 0 ) #foreach( $item in $links ) #set ( $counter = $counter + 1 ) #set ( $currentItemHref = $PathTool.calculateLink( $item.href, $relativePath ) ) #set ( $currentItemHref = $currentItemHref.replaceAll( "\\", "/" ) ) #link( $currentItemHref $item.name ) #if ( $links.size() > $counter ) | #end #end #end #macro ( breadcrumbs $breadcrumbs ) #set ( $counter = 0 ) #foreach( $item in $breadcrumbs ) #set ( $counter = $counter + 1 ) #set ( $currentItemHref = $PathTool.calculateLink( $item.href, $relativePath ) ) #set ( $currentItemHref = $currentItemHref.replaceAll( "\\", "/" ) ) #if ( $currentItemHref == $alignedFileName || $currentItemHref == "" ) $item.name #else #link( $currentItemHref $item.name ) #end #if ( $breadcrumbs.size() > $counter ) > #end #end #end #macro ( displayTree $display $item ) #if ( $item && $item.items && $item.items.size() > 0 ) #foreach( $subitem in $item.items ) #set ( $subitemHref = $PathTool.calculateLink( $subitem.href, $relativePath ) ) #set ( $subitemHref = $subitemHref.replaceAll( "\\", "/" ) ) #set ( $display = false ) #if ( $alignedFileName == $subitemHref ) #set ( $display = true ) #end #displayTree( $display $subitem ) #end #end #end #macro ( menuItem $item ) #set ( $collapse = "none" ) #set ( $currentItemHref = $PathTool.calculateLink( $item.href, $relativePath ) ) #set ( $currentItemHref = $currentItemHref.replaceAll( "\\", "/" ) ) #if ( $item && $item.items && $item.items.size() > 0 ) #if ( $item.collapse == false ) #set ( $collapse = "expanded" ) #else ## By default collapsed #set ( $collapse = "collapsed" ) #end #set ( $display = false ) #displayTree( $display $item ) #if ( $alignedFileName == $currentItemHref || $display ) #set ( $collapse = "expanded" ) #end #end
  • #if ( $item.img ) #if ( ! ( $item.img.toLowerCase().startsWith("http") || $item.img.toLowerCase().startsWith("https") ) ) #set ( $src = $PathTool.calculateLink( $item.img, $relativePath ) ) #set ( $src = $src.replaceAll( "\\", "/" ) ) #else #end #end #if ( $alignedFileName == $currentItemHref ) $item.name #else #link( $currentItemHref $item.name ) #end #if ( $item && $item.items && $item.items.size() > 0 ) #if ( $collapse == "expanded" )
      #foreach( $subitem in $item.items ) #menuItem( $subitem ) #end
    #end #end
  • #end #macro ( mainMenu $menus ) #foreach( $menu in $menus ) #end #end #macro ( copyright ) #if ( $project ) #set ( $currentYear = ${currentDate.year} + 1900 ) #if ( ${project.inceptionYear} && ( ${project.inceptionYear} != ${currentYear.toString()} ) ) ${project.inceptionYear}-${currentYear} #else ${currentYear} #end #if ( ${project.organization} && ${project.organization.name} ) ${project.organization.name} #end #end #end #macro ( publishDate $position $publishDate $version ) #if ( $publishDate && $publishDate.format ) #set ( $format = $publishDate.format ) #else #set ( $format = "yyyy-MM-dd" ) #end $dateFormat.applyPattern( $format ) #set ( $dateToday = $dateFormat.format( $currentDate ) ) #if ( $publishDate && $publishDate.position ) #set ( $datePosition = $publishDate.position ) #else #set ( $datePosition = "left" ) #end #if ( $version ) #if ( $version.position ) #set ( $versionPosition = $version.position ) #else #set ( $versionPosition = "left" ) #end #else #set ( $version = "" ) #set ( $versionPosition = "left" ) #end #set ( $breadcrumbs = $decoration.body.breadcrumbs ) #set ( $links = $decoration.body.links ) #if ( $datePosition.equalsIgnoreCase( "right" ) && $links && $links.size() > 0 ) #set ( $prefix = " |" ) #else #set ( $prefix = "" ) #end #if ( $datePosition.equalsIgnoreCase( $position ) ) #if ( ( $datePosition.equalsIgnoreCase( "right" ) ) || ( $datePosition.equalsIgnoreCase( "bottom" ) ) ) $prefix $i18n.getString( "site-renderer", $locale, "template.lastpublished" ): $dateToday #if ( $versionPosition.equalsIgnoreCase( $position ) )  | $i18n.getString( "site-renderer", $locale, "template.version" ): ${project.version} #end #elseif ( ( $datePosition.equalsIgnoreCase( "navigation-bottom" ) ) || ( $datePosition.equalsIgnoreCase( "navigation-top" ) ) )
    $i18n.getString( "site-renderer", $locale, "template.lastpublished" ): $dateToday #if ( $versionPosition.equalsIgnoreCase( $position ) )  | $i18n.getString( "site-renderer", $locale, "template.version" ): ${project.version} #end
    #elseif ( $datePosition.equalsIgnoreCase("left") )
    $i18n.getString( "site-renderer", $locale, "template.lastpublished" ): $dateToday #if ( $versionPosition.equalsIgnoreCase( $position ) )  | $i18n.getString( "site-renderer", $locale, "template.version" ): ${project.version} #end #if ( $breadcrumbs && $breadcrumbs.size() > 0 ) | #breadcrumbs( $breadcrumbs ) #end
    #end #elseif ( $versionPosition.equalsIgnoreCase( $position ) ) #if ( ( $versionPosition.equalsIgnoreCase( "right" ) ) || ( $versionPosition.equalsIgnoreCase( "bottom" ) ) ) $prefix $i18n.getString( "site-renderer", $locale, "template.version" ): ${project.version} #elseif ( ( $versionPosition.equalsIgnoreCase( "navigation-bottom" ) ) || ( $versionPosition.equalsIgnoreCase( "navigation-top" ) ) )
    $i18n.getString( "site-renderer", $locale, "template.version" ): ${project.version}
    #elseif ( $versionPosition.equalsIgnoreCase("left") )
    $i18n.getString( "site-renderer", $locale, "template.version" ): ${project.version} #if ( $breadcrumbs && $breadcrumbs.size() > 0 ) | #breadcrumbs( $breadcrumbs ) #end
    #end #elseif ( $position.equalsIgnoreCase( "left" ) ) #if ( $breadcrumbs && $breadcrumbs.size() > 0 )
    #breadcrumbs( $breadcrumbs )
    #end #end #end #macro ( poweredByLogo $poweredBy ) #if( $poweredBy ) #foreach ($item in $poweredBy) #if( $item.href ) #set ( $href = $PathTool.calculateLink( $item.href, $relativePath ) ) #set ( $href = $href.replaceAll( "\\", "/" ) ) #else #set ( $href="http://maven.apache.org/" ) #end #if( $item.name ) #set ( $name = $item.name ) #else #set ( $name = $i18n.getString( "site-renderer", $locale, "template.builtby" ) ) #set ( $name = "${name} Maven" ) #end #if( $item.img ) #set ( $img = $item.img ) #else #set ( $img = "images/logos/maven-feather.png" ) #end #set ( $img = $PathTool.calculateLink( $img, $relativePath ) ) #set ( $img = $img.replaceAll( "\\", "/" ) ) $name #end #if( $poweredBy.isEmpty() ) $i18n.getString( #end #else $i18n.getString( #end #end $title #foreach( $author in $authors ) #end #if ( $decoration.body.head ) #foreach( $item in $decoration.body.head.getChildren() ) ## Workaround for DOXIA-150 due to a non-desired behaviour in p-u ## @see org.codehaus.plexus.util.xml.Xpp3Dom#toString() ## @see org.codehaus.plexus.util.xml.Xpp3Dom#toUnescapedString() #set ( $documentHeader = "" ) #set ( $documentHeader = $documentHeader.replaceAll( "\\", "" ) ) #if ( $item.name == "script" ) $StringUtils.replace( $item.toUnescapedString(), $documentHeader, "" ) #else $StringUtils.replace( $item.toString(), $documentHeader, "" ) #end #end #end

    ${title}

    ${bodyContent}
    #mainMenu( $decoration.body.menus )
    qdox-qdox-2.0-M8/src/site/xhtml/000077500000000000000000000000001325201777200164565ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/site/xhtml/download.xhtml000066400000000000000000000040371325201777200213470ustar00rootroot00000000000000 Download

    QDox is available at the Maven Central. To include the most recent of QDox in your pom, include the following dependency:

      	 <dependency>
      	   <groupId>${project.groupId}</groupId>
      	   <artifactId>${project.artifactId}</artifactId>
      	   <version>${project.version}</version>
      	 </dependency>
      	  	

    Latest stable release - QDox ${project.rel.org.thoughtworks.qdox:qdox}: binary jar | sources jar | javadoc jar | project tar.bz2 | project tar.gz | project zip

    Snapshot deployments: snapshots directory.

    qdox-qdox-2.0-M8/src/site/xhtml/index.xhtml000066400000000000000000000023721325201777200206470ustar00rootroot00000000000000 Overview

    QDox

    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.

    In A Nutshell

    A custom built parser has been built using JFlex and BYacc/J. These have been chosen because of their proven performance and they require no external libraries at runtime.

    The parser skims the source files only looking for things of interest such as class/interface definitions, import statements, JavaDoc and member declarations. The parser ignores things such as actual method implementations to avoid overhead (while in method blocks, curly brace counting suffices).

    The end result of the parser is a very simple document model containing enough information to be useful.

    Getting Started

    1. Download it.
    2. Use it.

    qdox-qdox-2.0-M8/src/site/xhtml/license.xhtml000066400000000000000000000015631325201777200211630ustar00rootroot00000000000000 The License

    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-qdox-2.0-M8/src/site/xhtml/migration.xhtml000066400000000000000000000030201325201777200215200ustar00rootroot00000000000000

    Migrating to QDox 2.0

    Farewell JavaDocBuilder, hello JavaProjectBuilder

    Farewell OrderedMap, hello LinkedHashMap

    Before JDK1.3 there was no implementation available which could hold the order in which entries were added to a Map. With JDK1.4 the LinkedHashMap was introduced. We've decided to make use of this class which also means projects using QDox need at least JDK1.4. If you want QDox to parse code with an older JDK version, you'll have to configure the ClassLoaderLibrary feeding it with the required classloaders.

    Farewell JavaClass, hello JavaClass

    Looks like nothing has changed, but we've decided to change all models to interfaces and give them a default implementation. This way we can hide all methods which the ModelBuilder needs to build the model and you'll only see those methods which are interesting for you. This also means that the default implementations looks much more like plain old Java Objects, its binding logic has been moved to the ModelBuilder.

    Farewell AbstractQDoxTask for Ant

    We've decided to remove this Abstract AntTask. It doesn't belong in the core of QDox, but it's an prepared Ant Task to use QDox. Although we'd defined this dependency as optional, it kind of spoiled the pom.xml.

    Farewell APITestCase for JUnit3

    Summary

    • Use the JavaProjectBuilder instead of the JavaDocBuilder
    • QDox requires at least JDK1.4
    qdox-qdox-2.0-M8/src/site/xhtml/model.xhtml000066400000000000000000000445121325201777200206420ustar00rootroot00000000000000 The Model

    After the source code has been parsed, the content of the files can be navigated using a simple to use and intuitive object model.

    JavaSource

    Represents a complete .java file. This contains a collection of classes.

    Example Input

        package com.blah.foo;
        
        import java.awt.*;
        import java.util.List;
        
        public class Class1 {
          ...
        }
        
        class Class2 {
        }
        
        interface Interface1 {
        }
                

    Example Code

        JavaProjectBuilder builder = new JavaProjectBuilder();
        JavaSource src = builder.addSource(myReader);
        
        JavaPackage pkg      = src.getPackage(); 
        List<String> imports     = src.getImports(); // {"java.awt.*",
                                             //  "java.util.List"}
        
        JavaClass class1     = src.getClasses().get(0);
        JavaClass class2     = src.getClasses().get(1);
        JavaClass interface1 = src.getClasses().get(2);
                

    JavaPackage

    Represents the package of the class.

    Example input

        package com.blah.foo;
        
        public class BarClass  {
        ...
        }
      

    Example Code

        JavaProjectBuilder builder = new JavaProjectBuilder();
        JavaSource src = builder.addSource(myReader);
        
        JavaPackage pkg      = src.getPackage();
        
        Collection<JavaClass> classes  = pkg.getClasses(); // BarClass
        String name          = pkg.getName(); // "com.blah.foo"
        String toString      = pkg.toString(); // "package com.blah.foo" conform javaAPI
        JavaPackage parent   = pkg.getParentPackage(); //
      

    JavaClass

    Represents a class or interface. This contains doclet tags, fields and methods. Information about the class definition is available, such as which classes are extended, which interfaces implemented and modifiers.

    Example Input

        package com.blah.foo;
        
        import java.io.*;
        import com.custom.*;
        import com.base.SubClass;
        
        /**
         * @author Joe
         */
        public abstract class MyClass extends SubClass
                    implements Serializable, CustomInterface  {
        
          private String name;
          public void doStuff() { ... }
          private int getNumber() { ... }
        
        }
      

    Example Code

        JavaProjectBuilder builder = new JavaProjectBuilder();
        builder.addSource(myReader);
        
        JavaClass cls = builder.getClassByName("com.blah.foo.MyClass");
        
        String pkg      = cls.getPackage();            // "com.blah.foo"
        String name     = cls.getName();               // "MyClass"
        String fullName = cls.getCanonicalName(); // "com.blah.foo.MyClass";
        String canonicalName = cls.getFullyQualifiedName(); // "com.blah.foo.MyClass";
        boolean isInterface = cls.isInterface();       // false
        
        boolean isPublic   = cls.isPublic();   // true
        boolean isAbstract = cls.isAbstract(); // true
        boolean isFinal    = cls.isFinal();    // false
        
        JavaType superClass = cls.getSuperClass(); // "com.base.SubClass";
        List<JavaType> imps     = cls.getImplements(); // {"java.io.Serializable",
                                               //  "com.custom.CustomInterface"}
        
        String author = cls.getTagsByName("author").getValue(); // "joe"
        
        JavaField nameField = cls.getFields()[0];
        JavaMethod doStuff = cls.getMethods()[0];
        JavaMethod getNumber = cls.getMethods()[1];
        
        JavaSource javaSource = cls.getParentSource();
      

    JavaField

    Represents a field in a class. This has doclet tags, a name and a type.

    Example Input

        import java.util.Date;
        
        public class MyClass  {
        
          /**
           * @magic
           */
          private String email;
        
          public static Date[][] dates;
        
        }
                

    Example Code

        JavaField e = cls.getFields()[0];
        
        JavaType eType     = e.getType(); // "java.lang.String";
        String eName   = e.getName(); // "email";
        DocletTag eTag = e.getTagsByName("magic"); // @magic
        boolean eArray = e.getType().isArray(); // false;
        
        JavaField d = cls.getFields()[1];
        
        JavaType dType     = d.getType(); // "java.util.Date";
        String dName   = d.getName(); // "dates";
        DocletTag dTag = d.getTagsByName("magic"); // null
        boolean dArray = d.getType().isArray(); // true;
        int dDimensions= d.getType().getDimensions(); // 2;
        boolean dStatic= d.isStatic(); // true;
        
        JavaClass javaClass = d.getParentClass();
                

    JavaMethod

    Represents a method in a class. This has doclet tags, a name, return type, parameters and exceptions.

    Example Input

        import java.util.Date;
        import java.io.*;
        
        public class MyClass  {
        
          /**
           * @returns Lots of dates
           */
          public static Date[] doStuff(int number,
                                       String stuff)
                    throws RuntimeException, IOException {
            ...
          }
        
        }
      

    Example Code

        JavaMethod m = cls.getMethods()[0];
        
        String mName = m.getName(); // "doStuff";
        JavaType mReturns = m.getReturns(); // "java.util.Date";
        boolean mArray = m.getReturns().isArray(); // true
        boolean mStatic = m.isStatic(); // true
        boolean mPublic = m.isPublic(); // true
        
        String doc = m.getTagByName("returns").getValue();
          // "Lots of dates"
        
        List<JavaType> exceptions = m.getExceptions();
          // {"java.lang.RuntimeException", "java.io.IOException"}
        
        JavaParameter numberParam = m.getParameters()[0];
        JavaParameter stuffParam = m.getParameters()[1];
        
        JavaClass javaClass = m.getParentClass();
      

    JavaParameter

    Represents a parameter passed to a method. This has a name and a type.

    Example Input

        public class MyClass  {
        
          public void stuff(int n, Object[] objects) {
            ...
          }
        
        }
      

    Example Code

        JavaMethod m = cls.getMethods()[0];
        
        JavaParameter n = m.getParameters()[0];
        String nName = n.getName(); // "n"
        JavaType nType   = n.getType(); // "int";
        
        JavaParameter o = m.getParameters()[1];
        String oName   = o.getName(); // "objects"
        JavaType oType     = o.getType(); // "java.lang.Object";
        boolean oArray = o.getType().isArray(); // true
        
        JavaMethod javaMethod = o.getParentMethod();
      

    JavaType

    Represents a specific instance of a class used by another class (such as return value, superclass, etc). The value represents the name of the class. Array dimensions are also available. Since 1.8 it's also possible to get the generic value of the Type

    Example Input

         stringList) {
            ...
          }
        
        }
        ]]>
      

    Example Code

        JavaMethod m = cls.getMethods()[0];
        
        JavaType returns = m.getReturns();
        returns.getValue(); // "void"
        returns.isArray(); // false
        returns.getDimensions(); // 0
        
        JavaType n = m.getParameters()[0].getType();
        n.getValue(); // "int"
        n.isArray(); // false
        n.getDimensions(); // 0
        
        JavaType objects = m.getParameters()[1].getType();
        objects.getValue(); // "java.lang.Object"
        objects.isArray(); // true
        objects.getDimensions(); // 1
        
        JavaType dates = m.getParameters()[2].getType();
        dates.getValue(); // "java.util.Date"
        dates.isArray(); // true
        dates.getDimensions(); // 2
        
        JavaType stringList = m.getParameters()[3].getType();
        stringList.getValue(); // "java.util.List"
        stringList.getGenericValue(); // "]]>
        stringList.isArray(); // false
        stringList.getDimensions(); // 0
              

    DocletTag

    Represents a JavaDoc tag. Each tag has a name and a value. Optionally, the value can be broken up into tokens accessed by index or name.

    The JavaClass, JavaField and JavaMethod classes all support comments and DocletTags

    The returned DocletTag carries the name, value and methods for breaking up the value into specific parameters.

    Example Input

        /**
         * This method does nothing at all.
         *
         * @returns A boolean of whether we care or not.
         * @param email Someone's email address.
         * @param dob Date of birth.
         *
         * @permission administrator full-access
         * @webservice publish=true name=myservice type=rpc
         */
        boolean doWeCare(String email, Date dob);
                

    Example Code

        JavaMethod mth = cls.getMethods()[0];
        
        // Access the JavaDoc comment
        String comment = mth.getComment();
          // "This method does nothing at all."
        
        // Access a single doclet tag
        DocletTag returns = mth.getTagByName("returns");
        returns.getName(); // "returns";
        returns.getValue(); // "A boolean of whether we care or not."
        
        // Access multiple doclet tags with the same name
        DocletTag[] params = mth.getTagsByName("param");
        params[0].getValue(); // "Someone's email address."
        params[1].getValue(); // "Date of birth."
        
        // Access specific parameters of a doclet tag by index
        DocletTag permission = mth.getTagByName("permission");
        permission.getParameter[0]; // "administrator"
        permission.getParameter[1]; // "full-access"
        
        // Access specific parameters of a doclet tag by name
        DocletTag webservice = mth.getTagByName("webservice");
        webservice.getNamedParameter("type"); // "rpc"
        webservice.getNamedParameter("name"); // "myservice"
               
    qdox-qdox-2.0-M8/src/site/xhtml/upgrade.xhtml000066400000000000000000000132641325201777200211710ustar00rootroot00000000000000 Upgrading

    Upgrading to 1.10.1 or above

    This section describes what needs to be done when upgrading to QDox 1.10.1.

    Things that might break your code

    In some cases the Type.toString() was inconsequent (QDOX-182) so we had to change the implementation. If you use this in combination with innerClasses you should use Type.getFullyQualifiedName() to get the same result.

    Upgrading to 1.10 or above

    This section describes what needs to be done when upgrading to QDox 1.10.

    Things that might break your code

    The toString()-method in most of the JavaObjects under com.thoughtworks.qdox.models used to return the corresponding codeblock. This method has been renamed to getCodeBlock(). The toString() will follow the Java API Specs as described for each equivalent object under the java.lang-package. Some methods require extra attention, because there's not an exact match. Watch out for differences between Type and JavaClass.
    Java APIQDOX
    ((java.lang.Method) aMethod).getReturnsType().toString()((com.thoughtworks.qdox.model.JavaMethod) aMethod).getReturns().toString()

    com.thoughtworks.qdox.model.Type.getValue() will return the typeName for usage in the code. The new method com.thoughtworks.qdox.model.Type.getFullQualifiedName() will return the FQN as defined by the java specs. Normally they would return the same value, but pay attention when using inner classes.

    Upgrading to 1.9 or above

    This section describes what needs to be done when upgrading to QDox 1.9.

    Things that might break your code

    In both JavaClass and JavaSource the getPackage() returns an object of type JavaPackage instead of a String. To get the same result as before use getPackage().getName() .

    Upgrading to 1.6 or above

    This section describes what needs to be done when upgrading to QDox 1.6. For an extensive list of changes (most of them backwards compatible), please see the Changes Report.

    Things that might break your code

    In JavaClass the getInnerClasses() method has been renamed to getNestedClasses(). The old name remains as a (deprecated) synonym.

    With support for generic types, we've introduced a bug affecting the use of "<" and ">" in initialisers (see QDOX-71).

    Upgrading to 1.5

    This section describes what needs to be done when upgrading to QDox 1.5. For an extensive list of changes (most of them backwards compatible), please see the Changes Report.

    Things that might break your code

    The DocletTag interface no longer contains a setContext() method. That information is now provided via DocletTagFactory, where createDocletTag() now requires an additional "context" parameter.

    The parser now passes tag-data to Builders using a new TagDef structure.

    Upgrading to 1.3

    This section describes what needs to be done when upgrading to QDox 1.3. For an extensive list of changes (most of them backwards compatible), please see the Changes Report.

    Things that might break your code

    (Thanks to Peter Donald for contributing this list).

    qdox-qdox-2.0-M8/src/site/xhtml/usage.xhtml000066400000000000000000000057601325201777200206500ustar00rootroot00000000000000 QDox Usage

    Entry Point

    JavaProjectBuilder is the entry point to QDox. It is responsible for parsing source code, resolving imports and storing the data.

    To create it, all you need to do is call the default constructor.

    JavaProjectBuilder builder = new JavaProjectBuilder();
    

    Reading Source Files

    Java source code can then be added to the JavaProjectBuilder. Source can either be read one file at a time (using a java.io.Reader) or an entire source tree can be added recursively.

    // Reading a single source file.
    builder.addSource(new FileReader("MyFile.java"));
    
    // Reading from another kind of input stream.
    builder.addSource(new StringReader("package test; public class Hello {}"));
    
    // Adding all .java files in a source tree (recursively).
    builder.addSourceTree(new File("mysrcdir"));
    

    Resolving Class Names

    In order to resolve classes that have been imported using a wildcard (e.g. import java.util.*;), the ClassLibrary must be aware of other classes used in the project.

    ClassLibrary has 4 ways to resolve classes:

    • By looking at other sources that have been added.
    • By searching through the supplied sourceFolders
    • By looking in the current classpath (including the standard JRE classes).
    • By looking at additional ClassLoaders specified at runtime.

    All sources and sourcetrees added to the JavaProjectBuilder will be parsed. This is often much more than required. To increase efficiency use the ClassLibrary to add sourcefolders. Consider these files as lazy parsed sources.

    The current classpath is automatically set by JavaProjectBuilder. In most cases this shall be sufficient, however in some situations you may want resolve the full classes in external libraries.

    // Get the ClassLibrary
    JavaProjectBuilder builder = new JavaProjectBuilder();
    
    // Add a sourcefolder;
    builder.addSourceFolder( new File( "src/main/java" ) );
    builder.addSourceFolder( new File( "target/generated-sources/foobar" ) );
    
    // Add a custom ClassLoader
    builder.addClassLoader( myCustomClassLoader );
    
    // Ant example : add the <classpath> element's contents
    builder.addClassLoader( new AntClassLoader( getProject(), classpath ) );
    

    It is important that additional ClassLoaders are added before any source files are parsed.

    Navigating The Model

    Now the files have been parsed, move on to navigating the model.

    qdox-qdox-2.0-M8/src/site/xhtml/whouses.xhtml000066400000000000000000000175541325201777200212450ustar00rootroot00000000000000 Who is using QDox

    Project Description How QDox is Used
    AspectWerkz AspectWerkz is an Aspect Oriented Programming (AOP) toolkit for Java that modifies byte-code to weave in interceptors and mixins. Attributes can be used to associate interceptors and mixins with a specific class.
    Avalon Phoenix Phoenix was a micro-kernel designed and implemented on top of the Avalon framework. It provided a number of facilities to manage the environment of Server Applications. Apache cancelled the Avalon project 2004 'MetaGenerate' is part of the Phoenix toolset and picks up @phoenix prefixed JavaDoc tags to make XML manifests for the components that will be laced together in more XML to make a complete server application.
    Cocoon Apache Cocoon is an XML publishing framework that raises the usage of XML and XSLT technologies for server applications to a new level. Designed for performance and scalability around pipelined SAX processing, Cocoon offers a flexible environment based on a separation of concerns between content, logic, and style. The QDox Block reads in Java source files and fires out SAX events enabling processing by standard XML tools (such as XSLT).
    Commons Attributes Jakarta Commons Attributes provides an API to runtime metadata attributes. Attributes are specified as doclet tags and then compiled into the classpath where they can be accessed at runtime (without requiring the source). The aim is to provide a framework similar to .NET attributes. QDox is used to extract the JavaDoc tags from the source files.
    GWT-maven-plugin The gwt-maven-plugin provides support for GWT projects, including running the GWT developer tools (the compiler, shell and i18n generation) and performing support operations to help developers make GWT fit more closely in with their standard JEE web application development (debugging, managing the embedded server, running noserver, merging web.xml, generating I18N interfaces, generating Async GWT-RPC interfaces, and more) and environment (Eclipse IDE). QDox is used to generate the Async GWT-RPC interfaces based on their Service-classes.
    Ivory Ivory provides easy integration between your exiting Java classes, Avalon services, and Axis. It allows easy deployment of soap services with none of the WSDD configuration that Axis normally mandates. Attributes are used to provide additional hints to Ivory about Java classes that cannot be determined via reflection.
    maven-javadoc-plugin The Javadoc Plugin uses the Javadoc tool to generate javadocs for the specified project. When developers write code, they could forget to create (or update) the Javadoc comments. The <fix> and <test-fix> goals are interactive goals to fix the actual Javadoc comments.
    Maven 2 Maven is a software project management and comprehension tool. QDox is used for extraction of Javadoc tags from source files to generate plugin descriptors
    Mock Maker Mock Maker is a tool for automatically generating mock objects from custom classes to aid in testing the untestable. This supports the practises of Test Driven Development and eXtreme Programming. Mock Maker scans the source repository for any class/interface marked with the @mock JavaDoc tag and automatically creates the Mock Object for this that matches the class definition.
    Nanning Nanning is an Aspect Oriented Programming (AOP) toolkit for Java that does not require a custom compiler. It uses dynamic proxies to weave in interceptors and mixins at runtime. QDox is used to allow aspects to be applied to classes by specifiying meta-data in doclet tags.
    Paranamer Paranamer a mechamism for accessing the parameter names of methods of Java classes compiled into jars QDox is used to parse the source and generate the parameter names list.
    Spring ME A version of Spring that not only has a very small runtime footprint (none), but also is capable of running on small handheld devices, since it does not rely on reflection.
    vDoclet vDoclet is a framework for code-generation using Velocity templates, based on annotated Java source-code. vDoclet uses QDox to produce input-data for it's templates.
    Voruta Voruta is a data access framework for embedding SQL statements in Java methods using custom JavaDoc tags and dynamic code generation at runtime. QDox is used to parse metadata and CGLib to generate implementation at runtime.
    XDoclet2 XDoclet2 is a framework for code-generation using Velocity or Jelly templates, based on annotated Java source-code. It is a rewrite of XDoclet. XDoclet2 uses QDox to produce input-data for it's templates, as well as QDox' APITestCase to validate the generated sources.

    qdox-qdox-2.0-M8/src/test/000077500000000000000000000000001325201777200153355ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/000077500000000000000000000000001325201777200162565ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/X.java000066400000000000000000000003421325201777200173270ustar00rootroot00000000000000public class X { enum EnumWithConstructors { c( "hello" ), d(); int someField; EnumWithConstructors() { } EnumWithConstructors( String x ) { } } } qdox-qdox-2.0-M8/src/test/java/com/000077500000000000000000000000001325201777200170345ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/000077500000000000000000000000001325201777200216045ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/000077500000000000000000000000001325201777200225575ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/AnnotationExpressionTest.java000066400000000000000000000140111325201777200304510ustar00rootroot00000000000000package com.thoughtworks.qdox; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.StringReader; import java.util.Arrays; import java.util.Collection; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import com.thoughtworks.qdox.builder.impl.EvaluatingVisitor; import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.expression.AnnotationValue; import com.thoughtworks.qdox.parser.ParseException; @RunWith( Parameterized.class ) public class AnnotationExpressionTest { private JavaProjectBuilder builder; private String expression; private Object parsedResult; public AnnotationExpressionTest( String expression, Object parsedResult ) { this.expression = expression; this.parsedResult = parsedResult; } @Before public void setUp() { builder = new JavaProjectBuilder(); } @Parameters public static Collection createParameters() { return Arrays.asList( new Object[][] { // testPrecedence { "2 + 2 * 5", new Integer( 12 ) }, { "2 * 5 + 2", new Integer( 12 ) }, { "2+2*5", new Integer( 12 ) }, { "2*5+2", new Integer( 12 ) }, // testLogicalExpression { "true && false", Boolean.FALSE }, { "true || false", Boolean.TRUE }, { "!true", Boolean.FALSE }, // testBitExpression { "1 & 3", new Integer( 1 & 3 ) }, { "1 | 3", new Integer( 1 | 3 ) }, { "1 ^ 3", new Integer( 1 ^ 3 ) }, { "~1", new Integer( ~1 ) }, // testSignExpression { "+1", new Integer( 1 ) }, { "-1", new Integer( -1 ) }, //{ "--1", new Integer( --1 ) }, // testAddSubMultDivExpression { "8 / 3", new Integer( 8 / 3 ) }, { "8 * 3", new Integer( 8 * 3 ) }, { "8 + 3", new Integer( 8 + 3 ) }, { "8 - 3", new Integer( 8 - 3 ) }, { "8 % 3", new Integer( 8 % 3 ) }, { "\"a\" + \"b\"", "a" + "b" }, // testShiftExpression { "8 << 2", new Integer( 8 << 2 ) }, { "8 >> 2", new Integer( 8 >> 2 ) }, { "-1 >> 2", new Integer( -1 >> 2 ) }, { "-1 >>> 2", new Integer( -1 >>> 2 ) }, // testLiteral { "1", new Integer( 1 ) }, { "1l", new Long( 1 ) }, { "1.0", new Float( 1 ) }, { "1.0d", new Double( 1 ) }, // testParenExpression { "2 + (2 * 5)", new Integer( 12 ) }, { "(2 + 2) * 5", new Integer( 20 ) }, // testCompareExpression { "1 < 2", Boolean.TRUE }, { "1 > 2", Boolean.FALSE }, { "1 <= 2", Boolean.TRUE }, { "1 >= 2", Boolean.FALSE }, { "1 == 2", Boolean.FALSE }, { "1 != 2", Boolean.TRUE }, // testQueryExpression { "1 < 2 ? 0 : 3", new Integer( 0 ) }, { "1 > 2 ? 0 : 3", new Integer( 3 ) }, // testCastExpression { "(short)1", new Short( (short) 1 ) }, { "(long)(short)1", new Long( 1 ) }, { "(int)((short)1 + (long)3)", new Integer( 4 ) }, // test Array-valued single-element annotation { "{\"Children\", \"Unscrupulous dentists\"}", Arrays.asList( new String[] { "Children", "Unscrupulous dentists" } ) }, // test Array-valued annotation ending with a comma { "{\"deprecated\", }", Arrays.asList( new String[] { "deprecated" } ) }, // Binary Literals (added to JDK7) { "(byte)0b00100001", Byte.parseByte( "100001", 2 ) }, { "(short)0b0110000101000101", Short.parseShort( "0110000101000101", 2 ) }, { "0b101", Integer.parseInt( "101", 2 ) }, { "0B101", Integer.parseInt( "101", 2 ) }, { "0b00010000101000101101000010100010110100001010001011010000101000101L", Long.parseLong( "00010000101000101101000010100010110100001010001011010000101000101", 2 ) }, // Underscores in Numeric Literals (added to JDK7) { "1234_5678", Integer.parseInt( "12345678" ) }, { "1234_5678_9012_3456L", Long.valueOf( "1234567890123456" ) }, { "0xFF_EC_DE_5EL", Long.valueOf( "FFECDE5E", 16 ) }, { "0x7fff_ffff_ffff_ffffL", Long.valueOf( "7fffffffffffffff", 16 ) }, { "(byte) 0b0010_0101 ", Byte.parseByte( "00100101", 2 ) }, { "5_______2", Integer.parseInt( "52" ) }, { "0x5_2", Integer.parseInt( "52", 16 ) }, { "0_52", Integer.parseInt( "52", 8 ) }, { "05_2", Integer.parseInt( "52", 8 ) }, } ); } @Test public void testExpression() { assertAnnotationExpression( expression, parsedResult ); } protected void assertAnnotationExpression( String expression, Object expected ) { String source = "@Annotation(\n" + expression + "\n) class Foo {}"; try { builder.addSource( new StringReader( source ) ); assertAnnotationValue( expected ); } catch ( ParseException pe ) { fail( pe.getMessage() + "Failed to parse '" + source + "'" ); } } protected void assertAnnotationValue( Object expected ) { JavaClass clazz = builder.getClassByName( "Foo" ); assertEquals( "Annotations", 1, clazz.getAnnotations().size() ); JavaAnnotation annotation = clazz.getAnnotations().get( 0 ); assertEquals( "Annotation name", "Annotation", annotation.getType().getFullyQualifiedName() ); assertEquals( "Properties", 1, annotation.getPropertyMap().size() ); AnnotationValue value = annotation.getProperty( "value" ); Object v = value.accept( new EvaluatingVisitor() ); assertEquals( "Value", expected, v ); } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/AnnotationsModelTest.java000066400000000000000000000255371325201777200275540ustar00rootroot00000000000000package com.thoughtworks.qdox; import java.io.StringReader; import java.util.ListIterator; import junit.framework.TestCase; import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.expression.Add; import com.thoughtworks.qdox.model.expression.AnnotationValue; import com.thoughtworks.qdox.model.expression.AnnotationValueList; import com.thoughtworks.qdox.model.expression.Constant; import com.thoughtworks.qdox.model.expression.FieldRef; import com.thoughtworks.qdox.model.expression.TypeRef; public class AnnotationsModelTest extends TestCase { private JavaProjectBuilder builder; @Override protected void setUp() throws Exception { builder = new JavaProjectBuilder(); //builder.setDebugLexer( true ); //builder.setDebugParser( true ); } protected JavaAnnotation checkClassAnnotation( String source ) { builder.addSource( new StringReader( source ) ); JavaClass clazz = builder.getClassByName( "Foo" ); assertEquals( "Annotations", 1, clazz.getAnnotations().size() ); JavaAnnotation annotation = clazz.getAnnotations().get( 0 ); assertEquals( "Annotation name", "Annotation", annotation.getType().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().size() ); JavaAnnotation annotation = clazz.getAnnotations().get( 0 ); assertEquals( "Annotation name", "Annotation", annotation.getType().getFullyQualifiedName() ); assertEquals( "Properties", 8, annotation.getNamedParameterMap().size() ); Constant f = (Constant) annotation.getProperty( "f" ); assertEquals( "f", new Float( 1 ), f.getValue() ); Constant d = (Constant) annotation.getProperty( "d" ); assertEquals( "d", new Double( 1 ), d.getValue() ); Constant i = (Constant) annotation.getProperty( "i" ); assertEquals( "i", new Integer( 1 ), i.getValue() ); Constant ix = (Constant) annotation.getProperty( "ix" ); assertEquals( "ix", new Integer( 1 ), ix.getValue() ); Constant l = (Constant) annotation.getProperty( "l" ); assertEquals( "l", new Long( 1 ), l.getValue() ); Constant lx = (Constant) annotation.getProperty( "lx" ); assertEquals( "lx", new Long( 1 ), lx.getValue() ); Constant c = (Constant) annotation.getProperty( "c" ); assertEquals( "c", new Character( 'c' ), c.getValue() ); Constant s = (Constant) 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().size() ); JavaAnnotation annotation = clazz.getAnnotations().get( 0 ); assertEquals( "Annotation name", "Annotation", annotation.getType().getFullyQualifiedName() ); assertEquals( "Properties", 5, annotation.getPropertyMap().size() ); Constant s1 = (Constant) annotation.getProperty( "s1" ); assertEquals( "s1", "a\nb", s1.getValue() ); Constant s2 = (Constant) annotation.getProperty( "s2" ); assertEquals( "s2", "a\nb", s2.getValue() ); Constant s3 = (Constant) annotation.getProperty( "s3" ); assertEquals( "s3", "a\rb", s3.getValue() ); Constant s4 = (Constant) annotation.getProperty( "s4" ); assertEquals( "s4", "a\tb", s4.getValue() ); Constant s5 = (Constant) 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().size() ); JavaAnnotation annotation = clazz.getAnnotations().get( 0 ); assertEquals( "Annotation name", "Annotation", annotation.getType().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(); ) { JavaAnnotation inner = (JavaAnnotation) 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().size() ); JavaAnnotation annotation = clazz.getAnnotations().get( 0 ); assertEquals( "Annotation name", "Annotation", annotation.getType().getFullyQualifiedName() ); assertEquals( "Properties", 1, annotation.getPropertyMap().size() ); Add add = (Add) annotation.getProperty( "value" ); assertEquals( "Left", new Integer( 1 ), ( (Constant) add.getLeft() ).getValue() ); assertEquals( "Right", new Integer( 1 ), ( (Constant) 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().size() ); JavaAnnotation annotation = clazz.getAnnotations().get( 0 ); assertEquals( "Annotation name", "Annotation", annotation.getType().getFullyQualifiedName() ); assertEquals( "Properties", 1, annotation.getPropertyMap().size() ); Add add = (Add) annotation.getProperty( "value" ); assertEquals( "Left", "value = ", ( (Constant) add.getLeft() ).getValue() ); assertEquals( "Right", new Integer( 1 ), ( (Constant) 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().size() ); JavaAnnotation annotation = clazz.getAnnotations().get( 0 ); assertEquals( "Annotation name", "Annotation", annotation.getType().getFullyQualifiedName() ); assertEquals( "Properties", 1, annotation.getPropertyMap().size() ); FieldRef value = (FieldRef) 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().size() ); JavaAnnotation annotation = clazz.getAnnotations().get( 0 ); assertEquals( "Annotation name", "Annotation", annotation.getType().getFullyQualifiedName() ); assertEquals( "Properties", 1, annotation.getPropertyMap().size() ); Object value = annotation.getProperty( "value" ); TypeRef ref = (TypeRef) 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().size() ); JavaAnnotation annotation = clazz.getAnnotations().get( 0 ); assertEquals( "Annotation name", "Annotation", annotation.getType().getFullyQualifiedName() ); assertEquals( "Properties", 1, annotation.getPropertyMap().size() ); Object value = annotation.getProperty( "value" ); TypeRef ref = (TypeRef) value; assertEquals( "value", "java.util.Set", ref.getType().getValue() ); } // from Qdox-98 public void testPackageWithAnnotation() { 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 {}"; JavaClass cls = builder.addSource( new StringReader( source ) ).getClasses().get( 0 ); JavaPackage jPackage = cls.getPackage(); assertEquals( "org.oasis_open.docs.wsn.br_2", jPackage.getName() ); assertEquals( "javax.xml.bind.annotation.XmlSchema", jPackage.getAnnotations().get( 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" ); assertEquals( "Foo", clazz.getName() ); JavaMethod mth = clazz.getMethods().get( 0 ); JavaAnnotation paramAnn = mth.getParameterByName( "blah" ).getAnnotations().get( 0 ); assertEquals( "@Y(value=1)", paramAnn.toString() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/AnnotationsTest.java000066400000000000000000000236461325201777200265720ustar00rootroot00000000000000package com.thoughtworks.qdox; import java.io.StringReader; import java.util.Collections; import junit.framework.TestCase; import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.expression.FieldRef; public class AnnotationsTest extends TestCase { private JavaProjectBuilder builder; public AnnotationsTest() { builder = new JavaProjectBuilder(); // builder.setDebugLexer( true ); // builder.setDebugParser( true ); } public void testShouldIgnoreSimpleClassAnnotation() { String source = "" + "@Fnord\n" + "public interface Foo extends Bar {}\n"; builder.addSource( new StringReader( source ) ); assertEquals( "Foo", builder.getClassByName( "Foo" ).getName() ); } public void testShouldIgnoreSimpleMethodAnnotation() { String source = "" + "public class X {\n" + " @Fnord public void snort() {}\n" + "}\n"; builder.addSource( new StringReader( source ) ); JavaClass fooClass = builder.getClassByName( "X" ); assertEquals( "X", fooClass.getName() ); assertEquals( 1, fooClass.getMethods().size() ); assertEquals( "snort", fooClass.getMethods().get( 0 ).getName() ); } public void testShouldIgnoreMethodParameterAnnotation() { String source = "" + "public class X {\n" + " String field = new String( \"hey\" );\n" + " public void setX(@name String x) {}\n" + "}\n"; builder.addSource( new StringReader( source ) ); JavaClass fooClass = builder.getClassByName( "X" ); assertEquals( "X", fooClass.getName() ); assertEquals( 1, fooClass.getMethods().size() ); assertEquals( "setX", fooClass.getMethods().get( 0 ).getName() ); } public void testShouldIgnoreComplexClassAnnotations() { String source = "" + "@Fnord(pi = 3.14, e = m*c*c)\n" + "public interface Foo extends Bar {\n" + " @Fnord(pi = 3.14, e = m*c*c)\n" + " void doStuff() { }\n" + "}\n"; builder.addSource( new StringReader( source ) ); assertEquals( "Foo", builder.getClassByName( "Foo" ).getName() ); } public void testShouldIgnoreSingleMemberClassAnnotations() { String source = "" + "@Fnord(\"xyz\")\n" + "@Blat(Math.MAXINT)\n" + "public interface Foo extends Bar {\n" + " @Fnord(\"xyz\")\n" + " @Blat(Math.MAXINT)\n" + " void doStuff() { }\n" + "}\n"; builder.addSource( new StringReader( source ) ); assertEquals( "Foo", builder.getClassByName( "Foo" ).getName() ); } public void testShouldIgnoreArrayValuedSingleMemberClassAnnotations() { String source = "/** @hey=\"yo\" someval = \"yep\" */" + "@ Endorsers({(\"Children\"), \"Unscrupulous dentists\"})\n" + "public class Lollipop {\n" + " @Cheese( hey=@ano({\"Edam\", \"Gruyere\", 2}), t=5.5f, c=4)\n" + " void doStuff() { }\n" + "}\n"; builder.addSource( new StringReader( source ) ); assertNotNull( builder.getClassByName( "Lollipop" ) ); } public void testShouldIgnoreComplexSingleMemberClassAnnotations() { String source = "" + "@Author(@Name(first = \"Joe\", last = true))\n" // I won't take it personally! ;) -joe + "public class BitTwiddle {\n" + " @Author(@Name(first = \'c\', last = 2.5e3f))\n" + " void doStuff() { }\n" + "}\n"; builder.addSource( new StringReader( source ) ); assertNotNull( builder.getClassByName( "BitTwiddle" ) ); assertNotNull( builder.getClassByName( "BitTwiddle" ).getAnnotations().get( 0 ).getNamedParameter( "value" ) ); assertEquals( "Author", builder.getClassByName( "BitTwiddle" ).getMethodBySignature( "doStuff", Collections.emptyList() ).getAnnotations().get( 0 ).getType().getValue() ); } public void testShouldIgnoreAnnotationDeclaration() { String source = "package org.jabba;\n" + "@MyAnno\n" + "public @interface Note {\n" + " String text;\n" + "}\n"; builder.addSource( new StringReader( source ) ); assertEquals( 1, builder.getClasses().size() ); } public void testShouldIgnoreAnnotationWithClassType() { String source = "" + "@Fnord(String.class)\n" + "public interface Foo extends Bar {}\n"; builder.addSource( new StringReader( source ) ); assertEquals( "Foo", builder.getClassByName( "Foo" ).getName() ); } // from QDOX-97 public void testShouldIgnoreAttributeAnnotation() { String source = "" + "public interface Foo {\n" + " String echo(@WebParam java.lang.String msg);\n" + "}\n"; builder.addSource( new StringReader( source ) ); assertEquals( "Foo", builder.getClassByName( "Foo" ).getName() ); } // from QDOX-101 public void testShouldNotChokeOnDoubleAttributeAnnotationAndGenerics() { String source = "" + "public class Person {\n" + " @XmlJavaTypeAdapter(CollapsedStringAdapter.class)\n" + " @XmlID\n" + " protected String name;\n" + " public List getAddress() {\n" + " return address;\n" + " }" + "}\n"; builder.addSource( new StringReader( source ) ); assertEquals( "Person", builder.getClassByName( "Person" ).getName() ); } // from QDOX-108 public void testFQNAnnotations() { String source = "" + "@com.mycompany.Fnord(a=1)\n" + "public interface Foo extends Bar {}\n"; builder.addSource( new StringReader( source ) ); assertEquals( "Foo", builder.getClassByName( "Foo" ).getName() ); } // from QDOX-113 public void testAnnotationWithParameter() { String source = "public class Foo{\n" + "@Editor(FileEditor.class)\n" + "public void setFile(File file) { this.file = file; }" + "}"; builder.addSource( new StringReader( source ) ); } // from QDOX-128 public void testQuotedStringAnnotation() { String source = "@Anno(run = \"1.0\")" + "public interface Foo {}"; builder.addSource( new StringReader( source ) ); assertEquals( "\"1.0\"", builder.getClassByName( "Foo" ).getAnnotations().get( 0 ).getProperty( "run" ).getParameterValue() ); } // from QDOX-135 public void testAnnotationInMethodParamList() { String source = "" + "class Foo {\n" + " @X()\n" + " public String xyz(@Y(1) int blah) {\n" + " }\n" + "}\n"; builder.addSource( new StringReader( source ) ); JavaClass clazz = builder.getClassByName( "Foo" ); JavaMethod mth = clazz.getMethods().get( 0 ); assertEquals( "Foo", clazz.getName() ); assertEquals( "X", mth.getAnnotations().get( 0 ).getType().getName() ); } // from QDOX-142 public void testEmptyParameterListAnnotation() { String source = "@MyAnnotation()\n" + "public class MyClass {}"; JavaClass cls = builder.addSource( new StringReader( source ) ).getClasses().get( 0 ); assertEquals( "MyAnnotation", cls.getAnnotations().get( 0 ).getType().getValue() ); } public void testMethodAnnotationBeforeComment() { String source = "class Foo {\n" + "@Override\n" + "/**\n" + " * " + " */" + " public boolean isPostback() { return true;}\n" + "}"; JavaClass cls = builder.addSource( new StringReader( source ) ).getClasses().get( 0 ); assertEquals( "Override", cls.getMethods().get( 0 ).getAnnotations().get( 0 ).getType().getValue() ); assertEquals( "java.lang.Override", cls.getMethods().get( 0 ).getAnnotations().get( 0 ).getType().getFullyQualifiedName() ); } public void testEnumsWithAnnotations() { String source = "class Foo {\n" + " public enum BasicType {\n" + " @XmlEnumValue(\"text\")\n" + " TEXT(\"text\"),\n" + "" + " @XmlEnumValue(\"value\")\n" + " VALUE(\"value\") }\n" + "}"; builder.addSource( new StringReader( source ) ); } public void testParameterAnnotations() { String source = "class Foo {\n" + " @NativeAccessible\n" + " static void get_tmp_dir( String targetfilename, @ParamInfo( direction = ParamInfo.Direction.OUT ) byte[] tmpDirOutput ) throws IOException {}\n" + "}"; JavaClass cls = builder.addSource( new StringReader( source ) ).getClasses().get( 0 ); JavaMethod jMethod = cls.getMethods().get( 0 ); assertEquals( "NativeAccessible", jMethod.getAnnotations().get( 0 ).getType().getValue() ); JavaAnnotation annotation = jMethod.getParameters().get( 1 ).getAnnotations().get( 0 ); assertEquals( "ParamInfo", annotation.getType().getValue() ); assertEquals( "ParamInfo.Direction.OUT", annotation.getProperty( "direction" ).getParameterValue() ); } public void testFieldRefAnnotation() { String source = "public class Foo {\n" + " final String s = \"unchecked\";\n" + " @SuppressWarnings( s )\n" + " public void testNothing() { }\n " + "}"; JavaClass cls = builder.addSource( new StringReader( source ) ).getClasses().get( 0 ); JavaMethod method = cls.getMethods().get( 0 ); FieldRef suppressWarnings = (FieldRef) method.getAnnotations().get( 0 ).getProperty( "value" ); assertEquals( cls.getFields().get( 0 ), suppressWarnings.getField() ); } public void testDoubleEscapedString() { JavaProjectBuilder builder = new JavaProjectBuilder(); String source = "public class Foo {\n" + "@SuppressWarnings({\"abc\\\\d\"})\n" + "private void bar() { } }"; builder.addSource( new StringReader( source ) ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/ClassResolutionTest.java000066400000000000000000000073771325201777200274310ustar00rootroot00000000000000package com.thoughtworks.qdox; import java.io.StringReader; import junit.framework.TestCase; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.JavaType; public class ClassResolutionTest extends TestCase { public void testNestedClassesResolvedAcrossPackageBoundaries() { // input sources String source1 = "" + "package package1;" + "public class Class1 {" + " public static final class NestedClass {}" + "}"; String source2 = "" + "package package2;" + "import package1.Class1;" + "public class Class2 {" + " public void doStuff(Class1.NestedClass arg) {}" + "}"; // parse JavaProjectBuilder builder = new JavaProjectBuilder(); builder.addSource( new StringReader( source1 ) ); builder.addSource( new StringReader( source2 ) ); // find the parameter JavaClass class2 = builder.getClassByName( "package2.Class2" ); JavaMethod method = class2.getMethods().get( 0 ); JavaParameter parameter = method.getParameters().get( 0 ); JavaType type = parameter.getType(); // verify assertEquals( "Should include fully qualified name", "package1.Class1$NestedClass", type.getBinaryName() ); assertEquals( "Should include fully qualified name", "package1.Class1.NestedClass", type.getFullyQualifiedName() ); } public void testSurvivesStaticImports() { // input sources String source = "" + "package package2;" + "import static package1.Class1.VALUE;" + "public class Class2 {" + " public void doStuff(String arg) {}" + "}"; // parse JavaProjectBuilder builder = new JavaProjectBuilder(); builder.addSource( new StringReader( source ) ); // find the parameter JavaClass class2 = builder.getClassByName( "package2.Class2" ); assertNotNull( class2 ); } public void testAnonymousClass() { JavaProjectBuilder builder = new JavaProjectBuilder(); String source = "" + "public class AnimatedAlgorithm {\n" + " private SelectionListener mySelectionListener = new SelectionListenerAdapter() {\n" + " public void selectionEvent() {\n" + " for (int i = 0; i < recalcers.size(); i++) {\n" + " int something = 5;" + " }\n" + " }\n" + " };\n" + "}"; builder.addSource( new StringReader( source ) ); } // from QDOX-86 public void testInnerClassInMethod() { JavaProjectBuilder builder = new JavaProjectBuilder(); String source = "package some.pack;\n" + "class Test {\n" + "void some(Inner.Inner2 a) {}\n" + "static interface Inner {\n" + "static interface Inner2 { }\n" + "}\n" + "}"; builder.addSource( new StringReader( source ) ); JavaMethod method = builder.getClassByName( "some.pack.Test" ).getMethods().get( 0 ); JavaParameter parameter = method.getParameters().get( 0 ); assertEquals( "some.pack.Test$Inner$Inner2", parameter.getJavaClass().getBinaryName() ); assertEquals( "some.pack.Test$Inner$Inner2", parameter.getType().getBinaryName() ); assertEquals( "some.pack.Test$Inner$Inner2", parameter.getBinaryName() ); assertEquals( "some.pack.Test.Inner.Inner2", parameter.getJavaClass().getFullyQualifiedName() ); assertEquals( "some.pack.Test.Inner.Inner2", parameter.getType().getFullyQualifiedName() ); assertEquals( "some.pack.Test.Inner.Inner2", parameter.getFullyQualifiedName() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/EmptyTestClasses.java000066400000000000000000000001561325201777200267000ustar00rootroot00000000000000package com.thoughtworks.qdox; public class EmptyTestClasses { } class Spoon {} class Fork {} class Knife {}qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/EnumsModelTest.java000066400000000000000000000231111325201777200263300ustar00rootroot00000000000000package com.thoughtworks.qdox; import java.io.File; import java.io.StringReader; import java.net.URL; import java.net.URLClassLoader; import java.util.List; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaField; import junit.framework.TestCase; public class EnumsModelTest extends TestCase { // These tests verify that we can access enum fields in the model. // This is a sequel to EnumsTest.java. public void testAddEmptyEnumsToModel() { String source = "" + "public enum Enum1 {}\n" + "enum Enum2 {;}\n"; JavaProjectBuilder javaDocBuilder = new JavaProjectBuilder(); javaDocBuilder.addSource(new StringReader(source)); JavaClass enum1 = javaDocBuilder.getClassByName("Enum1"); assertTrue(enum1.isEnum()); JavaClass enum2 = javaDocBuilder.getClassByName("Enum2"); assertTrue(enum2.isEnum()); } public void testAddSimpleEnumsToModel() { String source = "" + "public enum Enum1 { a, b }" + "class X { " + " enum Enum2 { c, /** some doc */ d } " + " int someField; " + "}"; JavaProjectBuilder javaDocBuilder = new JavaProjectBuilder(); javaDocBuilder.addSource(new StringReader(source)); JavaClass cls = javaDocBuilder.getClassByName("X"); assertEquals("int", cls.getFieldByName("someField").getType().getValue()); // sanity check JavaClass enum1 = javaDocBuilder.getClassByName("Enum1"); assertTrue(enum1.isEnum()); JavaClass enum2 = javaDocBuilder.getClassByName("X$Enum2"); assertTrue(enum2.isEnum()); //--- List fields1 = enum1.getFields(); // printFields( fields1 ); assertEquals(2, fields1.size()); JavaField enum1a = fields1.get(0); assertNull( enum1a.getComment() ); assertEquals( 1, enum1a.getModifiers().size() ); assertEquals( "public", enum1a.getModifiers().get(0) ); assertEquals( 0, enum1a.getAnnotations().size() ); assertEquals( "Enum1", enum1a.getType().toString() ); assertEquals( "a", enum1a.getName() ); //--- List fields2 = enum2.getFields(); // printFields( fields2 ); assertEquals(2, fields2.size()); JavaField enum2d = fields2.get(1); assertNotNull( enum2d.getComment() ); assertEquals( 0, enum2d.getModifiers().size() ); assertEquals( 0, enum2d.getAnnotations().size() ); assertEquals( "X$Enum2", enum2d.getType().getBinaryName() ); assertEquals( "X.Enum2", enum2d.getType().getFullyQualifiedName() ); assertEquals( "d", enum2d.getName() ); //--- } public void testAddEnumImplementingInterfaceToModel() { String source = "" + "public enum Enum1 implements java.io.Serializable { a, b }"; JavaProjectBuilder javaDocBuilder = new JavaProjectBuilder(); javaDocBuilder.addSource(new StringReader(source)); JavaClass cls = javaDocBuilder.getClassByName("Enum1"); assertTrue(cls.isEnum()); assertTrue(cls.isA("java.io.Serializable")); } public void testAddEnumWithAnnotationToModel() { String source = "" + "public enum Enum1 implements java.io.Serializable { a, @Deprecated b }"; JavaProjectBuilder javaDocBuilder = new JavaProjectBuilder(); javaDocBuilder.addSource(new StringReader(source)); JavaClass cls = javaDocBuilder.getClassByName("Enum1"); assertTrue(cls.isEnum()); assertTrue(cls.isA("java.io.Serializable")); //--- List fields = cls.getFields(); // printFields( fields ); assertEquals(2, fields.size()); JavaField enum1b = fields.get(1); assertNull( enum1b.getComment() ); assertEquals( 1, enum1b.getModifiers().size() ); assertEquals( "public", enum1b.getModifiers().get(0) ); assertEquals( 1, enum1b.getAnnotations().size() ); assertEquals( "@java.lang.Deprecated()", enum1b.getAnnotations().get(0).toString() ); assertEquals( "Enum1", enum1b.getType().toString() ); assertEquals( "b", enum1b.getName() ); //--- } public void testAddEnumWithFieldAndConstructorsToModelSource() { String source = "" + "class X {\n" + " enum EnumWithConstructors {\n" + " c(\"hello\"), d();\n" + "\n" + " int someField;\n" + "\n" + " EnumWithConstructors() {}\n" + "\n" + " EnumWithConstructors(String x) {\n" + " }\n" + " }\n" + "}"; JavaProjectBuilder javaDocBuilder = new JavaProjectBuilder(); javaDocBuilder.addSource(new StringReader(source)); JavaClass cls = javaDocBuilder.getClassByName("X$EnumWithConstructors"); assertTrue(cls.isEnum()); assertEquals("int", cls.getFieldByName("someField").getType().getValue()); // sanity check //--- List fields = cls.getFields(); // printFields( fields ); assertEquals(3, fields.size()); // includes c, d, and someField JavaField enum1c = fields.get(0); assertNull( enum1c.getComment() ); assertEquals( 0, enum1c.getModifiers().size() ); assertEquals( 0, enum1c.getAnnotations().size() ); assertEquals( "X$EnumWithConstructors", enum1c.getType().getBinaryName() ); assertEquals( "X.EnumWithConstructors", enum1c.getType().getFullyQualifiedName() ); assertEquals( "c", enum1c.getName() ); //--- JavaField enum1d = fields.get(1); assertNull( enum1d.getComment() ); assertEquals( 0, enum1d.getModifiers().size() ); assertEquals( "X$EnumWithConstructors", enum1d.getType().getBinaryName() ); assertEquals( "X.EnumWithConstructors", enum1d.getType().getFullyQualifiedName() ); assertEquals( "d", enum1d.getName() ); //--- } public void testAddEnumWithFieldAndConstructorsToModelBinary() throws Exception { JavaProjectBuilder javaDocBuilder = new JavaProjectBuilder(); javaDocBuilder.addClassLoader( new URLClassLoader( new URL[] { new File("target/test-classes/").toURI().toURL() } ) ); JavaClass cls = javaDocBuilder.getClassByName("X$EnumWithConstructors"); assertTrue(cls.isEnum()); assertEquals("int", cls.getFieldByName("someField").getType().getValue()); // sanity check //--- List fields = cls.getFields(); JavaField enum1c = fields.get(0); assertNull( enum1c.getComment() ); assertEquals( 0, enum1c.getAnnotations().size() ); assertEquals( "X$EnumWithConstructors", enum1c.getType().getBinaryName() ); assertEquals( "X.EnumWithConstructors", enum1c.getType().getFullyQualifiedName() ); assertEquals( "c", enum1c.getName() ); //--- JavaField enum1d = fields.get(1); assertNull( enum1d.getComment() ); assertEquals( "X$EnumWithConstructors", enum1d.getType().getBinaryName() ); assertEquals( "X.EnumWithConstructors", enum1d.getType().getFullyQualifiedName() ); assertEquals( "d", enum1d.getName() ); //--- } public void testAddEnumsWithMethodsToModel() { String source = "" + "public enum Animal {\n" + " \n" + " DUCK { public void speak() { System.out.println(\"quack!\"); } },\n" + " CHICKEN { public void speak() { System.out.println(\"cluck!\"); } };\n" + "\n" + " public abstract void speak();\n" + "}"; JavaProjectBuilder javaDocBuilder = new JavaProjectBuilder(); javaDocBuilder.addSource(new StringReader(source)); JavaClass cls = javaDocBuilder.getClassByName("Animal"); assertTrue(cls.isEnum()); } //for qdox-118 public void testEnumWithJavaDocAndAnnotation() { String source = "public enum TestEnum\n" + "{\n" + "/**\n" + "* Blah blah\n" + "*/\n" + "@MyAnno\n" + "TEST;\n" + "}\n"; JavaProjectBuilder javaDocBuilder = new JavaProjectBuilder(); javaDocBuilder.addSource(new StringReader(source)); } /* private void printFields(final JavaField fields[]) { for(int i=0; iJoe Walnes * @author Aslak Hellesøy * @author Mike Williams */ public class GenericsTest extends TestCase { private JavaProjectBuilder builder = new JavaProjectBuilder(); 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 klass; }"; builder.addSource(new StringReader(source)); assertEquals("Bar", builder.getClassByName("Bar").getName()); } public void testShouldUnderstandBoundedWildcardTypeArguments() { String source = "" + "public class Bar { Map 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, ?>, Object> m_env = new HashMap, Object>, 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 testJiraQdox66() { // Also see QDOX-77 String source = "" + "public class Foo {\n" + " protected Map m_env = new HashMap();\n" + " public T 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()); } // QDOX-207 public void testMethodReturnTypeExtends() { String superSource = "public abstract class Test {\n" + " private T me;\n" + " public Test(T me) {\n" + " this.me = me;\n" + " }\n" + " public T getValue() {\n" + " return me;\n" + " }\n" + " }"; String subSource = "public class StringTest extends Test {\n" + " public StringTest(String s) {\n" + " super(s);\n" + " }\n" + " }"; builder.addSource( new StringReader( superSource ) ); builder.addSource( new StringReader( subSource ) ); JavaMethod method = builder.getClassByName( "StringTest" ).getMethodBySignature( "getValue", null, true ); assertEquals( "T", method.getReturnType(false).getValue() ); assertEquals( "java.lang.Object", method.getReturnType().getFullyQualifiedName() ); assertEquals( "java.lang.Object", method.getReturnType( false ).getFullyQualifiedName() ); assertEquals( "java.lang.String", method.getReturnType( true ).getFullyQualifiedName() ); } //GWT-186 public void testMethodReturnTypeImplements() { String source1="public interface GenericDao {\n" + "public List getAll();\n" + "public TEntity getRandom();\n" + "public TEntity findById(TKey key);\n" + "public TEntity persist(TEntity entity);\n" + "public TEntity[] persist(TEntity[] entities);\n" + "public void delete(TEntity entity);\n" + "public Map asMap();" + "}\r\n"; String source2="public interface SubjectDao extends GenericDao {\n" + "public List getEnabledSubjects();\n" + "}\r\n"; String source3="public interface SubjectService extends RemoteService, SubjectDao {\r\n" + "}"; builder.addSource( new StringReader( source1 ) ); builder.addSource( new StringReader( source2 ) ); builder.addSource( new StringReader( source3 ) ); JavaMethod method = builder.getClassByName( "GenericDao" ).getMethodBySignature( "getRandom", null, true ); assertEquals( "TEntity", method.getReturnType( true ).getGenericValue() ); method = builder.getClassByName( "GenericDao" ).getMethodBySignature( "getAll", null, true ); assertEquals( "List", method.getReturnType( true ).getGenericValue() ); method = builder.getClassByName( "GenericDao" ).getMethodBySignature( "asMap", null, true ); assertEquals( "Map", method.getReturnType( true ).getGenericValue() ); method = builder.getClassByName( "SubjectDao" ).getMethodBySignature( "getRandom", null, true ); assertEquals( "Subject", method.getReturnType( true ).getGenericValue() ); method = builder.getClassByName( "SubjectDao" ).getMethodBySignature( "getAll", null, true ); assertEquals( "List", method.getReturnType( true ).getGenericValue() ); method = builder.getClassByName( "SubjectDao" ).getMethodBySignature( "asMap", null, true ); assertEquals( "Map", method.getReturnType( true ).getGenericFullyQualifiedName() ); assertEquals( "Map", method.getReturnType( true ).getGenericValue() ); method = builder.getClassByName( "SubjectService" ).getMethodBySignature( "getRandom", null, true ); assertEquals( "Subject", method.getReturnType( true ).getGenericValue() ); method = builder.getClassByName( "SubjectService" ).getMethodBySignature( "getAll", null, true ); assertEquals( "List", method.getReturnType( true ).getGenericValue() ); method = builder.getClassByName( "SubjectService" ).getMethodBySignature( "asMap", null, true ); assertEquals( "Map", method.getReturnType( true ).getGenericFullyQualifiedName() ); assertEquals( "Map", method.getReturnType( true ).getGenericValue() ); JavaType tEntity = mock( JavaType.class ); when( tEntity.getFullyQualifiedName() ).thenReturn( "TEntity[]" ); method = builder.getClassByName( "SubjectDao" ).getMethodBySignature( "persist", Collections.singletonList( tEntity ), true ); assertNotNull( method ); assertEquals( "Subject[]", method.getParameterTypes( true ).get( 0 ).getGenericFullyQualifiedName() ); } //for QDOX-210 public void testResolveTypeGetMethod() { String source1="import java.util.*;" + "public interface GenericDao {\n" + "public List getAll();\n" + "public TEntity getRandom();\n" + "public TEntity findById(TKey key);\n" + "public TEntity persist(TEntity entity);\n" + "public TEntity[] persist(TEntity[] entities);\n" + "public void delete(TEntity entity);\n" + "public Map asMap();" + "}\r\n"; String source2="public interface SubjectDao extends GenericDao {\n" + "}"; String source3="public interface SubjectService extends RemoteService, SubjectDao {\r\n" + "}"; String source4="public interface RemoteService {}"; builder.addSource( new StringReader( source1 ) ); builder.addSource( new StringReader( source2 ) ); builder.addSource( new StringReader( source3 ) ); builder.addSource( new StringReader( source4 ) ); JavaClass clazz = builder.getClassByName( "SubjectService" ); JavaMethod method = clazz.getMethods( true ).get(0); assertEquals( "getAll", method.getName() ); assertEquals( "java.util.List", method.getReturnType( true ).getGenericFullyQualifiedName() ); assertEquals( "List", method.getReturnType( true ).getGenericValue() ); method = clazz.getMethods( true ).get(2); assertEquals( "findById", method.getName() ); assertEquals( "java.lang.Long", method.getParameterTypes( true ).get(0).getGenericFullyQualifiedName() ); assertEquals( "Long", method.getParameterTypes( true ).get(0).getGenericValue() ); } // for QDOX-239 public void testFieldWithWildcardType() { StringBuilder b = new StringBuilder("package test;\n"); b.append("import java.util.ArrayList;\n"); b.append("import java.util.Map;\n"); b.append("public class TestClass{\n"); b.append("public ArrayList> list;\n}"); builder.addSource(new StringReader(b.toString())); JavaClass javaClass = builder.getClassByName( "test.TestClass" ); JavaField field = javaClass.getFields().get( 0 ); assertTrue( field.getType() instanceof JavaParameterizedType ); JavaParameterizedType paramType = (JavaParameterizedType) field.getType(); assertTrue( paramType.getActualTypeArguments().get( 0 ) instanceof JavaWildcardType); JavaWildcardType wildcardType = (JavaWildcardType) paramType.getActualTypeArguments().get( 0 ); assertEquals("? extends java.util.Map", wildcardType.getGenericFullyQualifiedName() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/JSR14Test.java000066400000000000000000000733551325201777200251020ustar00rootroot00000000000000package com.thoughtworks.qdox; import java.io.StringReader; import junit.framework.TestCase; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaGenericDeclaration; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.JavaTypeVariable; /** * QDOX-54 Support for retrieval of generic type information (JSR 14) * * Some core-classes have been changed, but most interfaces are kept the same. * Most important is the method Type.getGenericValue(), which does exactly what it says. * The WildcardType is added as a subclass of Type. This way we can easily define these types of Types * * * @author Robert Scholte * */ public class JSR14Test extends TestCase { private JavaProjectBuilder builder = new JavaProjectBuilder(); public void testSimpleSingleParameterizedTypeMethod() { JavaMethod javaMethod = buildMethod("java.util.List getList();"); assertEquals("java.util.List", javaMethod.getReturns().getFullyQualifiedName()); assertEquals("java.util.List", javaMethod.getReturns().getGenericFullyQualifiedName()); assertEquals("java.util.List", javaMethod.getReturns().getValue()); assertEquals("java.util.List", javaMethod.getReturns().getGenericValue()); } public void testSimpleWildcardTypeMethod() { JavaMethod javaMethod = buildMethod("java.util.List getList();"); assertEquals("java.util.List", javaMethod.getReturns().getGenericValue()); } public void testSimpleExtendsWildcardTypeMethod() { JavaMethod javaMethod = buildMethod("java.util.List getList();"); assertEquals("java.util.List", javaMethod.getReturns().getFullyQualifiedName()); assertEquals("java.util.List", javaMethod.getReturns().getGenericFullyQualifiedName()); assertEquals("java.util.List", javaMethod.getReturns().getValue()); assertEquals("java.util.List", javaMethod.getReturns().getGenericValue()); } public void testSimpleSuperWildcardTypeMethod() { JavaMethod javaMethod = buildMethod("java.util.List getList();"); assertEquals("java.util.List", javaMethod.getReturns().getFullyQualifiedName()); assertEquals("java.util.List", javaMethod.getReturns().getGenericFullyQualifiedName()); assertEquals("java.util.List", javaMethod.getReturns().getValue()); assertEquals("java.util.List", javaMethod.getReturns().getGenericValue()); } public void testSimpleMultiParameterizedTypeMethod() { JavaMethod javaMethod = buildMethod("java.util.Map getMap();"); assertEquals("java.util.Map", javaMethod.getReturns().getFullyQualifiedName()); assertEquals("java.util.Map", javaMethod.getReturns().getGenericFullyQualifiedName()); assertEquals("java.util.Map", javaMethod.getReturns().getValue()); assertEquals("java.util.Map", javaMethod.getReturns().getGenericValue()); } public void testComplexSingleParameterizedTypeMethod() { JavaMethod javaMethod = buildMethod("java.util.List> getList();"); assertEquals("java.util.List", javaMethod.getReturns().getFullyQualifiedName()); assertEquals("java.util.List>", javaMethod.getReturns().getGenericFullyQualifiedName()); assertEquals("java.util.List", javaMethod.getReturns().getValue()); assertEquals("java.util.List>", javaMethod.getReturns().getGenericValue()); } public void testComplexMultiParameterizedTypeMethod() { JavaMethod javaMethod = buildMethod("java.util.Map> getMap();"); assertEquals("java.util.Map", javaMethod.getReturns().getFullyQualifiedName()); assertEquals("java.util.Map>", javaMethod.getReturns().getGenericFullyQualifiedName()); assertEquals("java.util.Map", javaMethod.getReturns().getValue()); assertEquals("java.util.Map>", javaMethod.getReturns().getGenericValue()); } private JavaMethod buildMethod(String methodSource) { String source = "interface Something { " + methodSource + " }"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaMethod javaMethod = javaClass.getMethods().get(0); return javaMethod; } public void testSimpleSingleParameterizedTypeField() { String source = "public class Something { " + "public java.util.List aList;" + " }"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaField javaField = javaClass.getFieldByName("aList"); assertEquals("java.util.List", javaField.getType().getFullyQualifiedName()); assertEquals("java.util.List", javaField.getType().getGenericFullyQualifiedName()); assertEquals("java.util.List", javaField.getType().getValue()); assertEquals("java.util.List", javaField.getType().getGenericValue()); } public void testSimpleMultiParameterizedTypeField() { String source = "public class Something { " + "public java.util.Map aMap;" + " }"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaField javaField = javaClass.getFieldByName("aMap"); assertEquals("java.util.Map", javaField.getType().getFullyQualifiedName()); assertEquals("java.util.Map", javaField.getType().getGenericFullyQualifiedName()); assertEquals("java.util.Map", javaField.getType().getValue()); assertEquals("java.util.Map", javaField.getType().getGenericValue()); } public void testSimpleWildcardTypeField() { String source = "public class Something { " + "public java.util.List aList;" + " }"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaField javaField = javaClass.getFieldByName("aList"); assertEquals("java.util.List", javaField.getType().getGenericValue()); } public void testSimpleExtendsWildcardTypeField() { String source = "public class Something { " + "public java.util.List aList;" + " }"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaField javaField = javaClass.getFieldByName("aList"); assertEquals("java.util.List", javaField.getType().getFullyQualifiedName()); assertEquals("java.util.List", javaField.getType().getGenericFullyQualifiedName()); assertEquals("java.util.List", javaField.getType().getValue()); assertEquals("java.util.List", javaField.getType().getGenericValue()); } public void testSimpleSuperWildcardTypeField() { String source = "public class Something { " + "public java.util.List aList;" + " }"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaField javaField = javaClass.getFieldByName("aList"); assertEquals("java.util.List", javaField.getType().getFullyQualifiedName()); assertEquals("java.util.List", javaField.getType().getGenericFullyQualifiedName()); assertEquals("java.util.List", javaField.getType().getValue()); assertEquals("java.util.List", javaField.getType().getGenericValue()); } public void testComplexSingleParameterizedTypeField() { String source = "public class Something { " + "public java.util.List> aList;" + " }"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaField javaField = javaClass.getFieldByName("aList"); assertEquals("java.util.List", javaField.getType().getFullyQualifiedName()); assertEquals("java.util.List>", javaField.getType().getGenericFullyQualifiedName()); assertEquals("java.util.List", javaField.getType().getValue()); assertEquals("java.util.List>", javaField.getType().getGenericValue()); } public void testComplexMultiParameterizedTypeField() { String source = "public class Something { " + "public java.util.List> aList;" + " }"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaField javaField = javaClass.getFieldByName("aList"); assertEquals("java.util.List", javaField.getType().getFullyQualifiedName()); assertEquals("java.util.List>", javaField.getType().getGenericFullyQualifiedName()); assertEquals("java.util.List", javaField.getType().getValue()); assertEquals("java.util.List>", javaField.getType().getGenericValue()); } public void testSimpleSingleParameterizedTypeParameter() { JavaMethod javaMethod = buildMethod("void setList(java.util.List aList);"); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getFullyQualifiedName()); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getGenericFullyQualifiedName()); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getValue()); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getGenericValue()); } public void testSimpleWildcardTypeParameter() { JavaMethod javaMethod = buildMethod("void setList(java.util.List aList);"); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getGenericValue()); } public void testSimpleExtendsWildcardTypeParameter() { JavaMethod javaMethod = buildMethod("void setList(java.util.List aList);"); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getFullyQualifiedName()); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getGenericFullyQualifiedName()); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getValue()); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getGenericValue()); } public void testSimpleSuperWildcardTypeParameter() { JavaMethod javaMethod = buildMethod("void setList(java.util.List aList);"); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getFullyQualifiedName()); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getGenericFullyQualifiedName()); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getValue()); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getGenericValue()); } public void testSimpleMultiParameterizedTypeParameter() { JavaMethod javaMethod = buildMethod("void setMap(java.util.Map aMap);"); assertEquals("java.util.Map", javaMethod.getParameterByName("aMap").getType().getFullyQualifiedName()); assertEquals("java.util.Map", javaMethod.getParameterByName("aMap").getType().getGenericFullyQualifiedName()); assertEquals("java.util.Map", javaMethod.getParameterByName("aMap").getType().getValue()); assertEquals("java.util.Map", javaMethod.getParameterByName("aMap").getType().getGenericValue()); } public void testComplexSingleParameterizedTypeParameter() { JavaMethod javaMethod = buildMethod("void setList(java.util.List> aList);"); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getFullyQualifiedName()); assertEquals("java.util.List>", javaMethod.getParameterByName("aList").getType().getGenericFullyQualifiedName()); assertEquals("java.util.List", javaMethod.getParameterByName("aList").getType().getValue()); assertEquals("java.util.List>", javaMethod.getParameterByName("aList").getType().getGenericValue()); } public void testComplexMultiParameterizedTypeParameter() { JavaMethod javaMethod = buildMethod("void setMap(java.util.Map> aMap);"); assertEquals("java.util.Map", javaMethod.getParameterByName("aMap").getType().getFullyQualifiedName()); assertEquals("java.util.Map>", javaMethod.getParameterByName("aMap").getType().getGenericFullyQualifiedName()); assertEquals("java.util.Map", javaMethod.getParameterByName("aMap").getType().getValue()); assertEquals("java.util.Map>", javaMethod.getParameterByName("aMap").getType().getGenericValue()); } public void testSimpleSingleParameterizedTypeClassExtends() { String source = "public class Something extends java.util.List {}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaType superClass = javaClass.getSuperClass(); assertEquals("java.util.List", superClass.getFullyQualifiedName()); assertEquals("java.util.List", superClass.getGenericFullyQualifiedName()); assertEquals("java.util.List", superClass.getValue()); assertEquals("java.util.List", superClass.getGenericValue()); } public void testSimpleMultiParameterizedTypeClassExtends() { String source = "public class Something extends java.util.Map {}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaType superClass = javaClass.getSuperClass(); assertEquals("java.util.Map", superClass.getFullyQualifiedName()); assertEquals("java.util.Map", superClass.getGenericFullyQualifiedName()); assertEquals("java.util.Map", superClass.getValue()); assertEquals("java.util.Map", superClass.getGenericValue()); } public void testSimpleWildcardTypeClassExtends() { String source = "public class Something extends java.util.List{}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaType superClass = javaClass.getSuperClass(); assertEquals("java.util.List", superClass.getGenericValue()); } public void testSimpleExtendsWildcardTypeClassExtends() { String source = "public class Something extends java.util.List {}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaType superClass = javaClass.getSuperClass(); assertEquals("java.util.List", superClass.getFullyQualifiedName()); assertEquals("java.util.List", superClass.getGenericFullyQualifiedName()); assertEquals("java.util.List", superClass.getValue()); assertEquals("java.util.List", superClass.getGenericValue()); } public void testSimpleSuperWildcardTypeClassExtends() { String source = "public class Something extends java.util.List {}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaType superClass = javaClass.getSuperClass(); assertEquals("java.util.List", superClass.getFullyQualifiedName()); assertEquals("java.util.List", superClass.getGenericFullyQualifiedName()); assertEquals("java.util.List", superClass.getValue()); assertEquals("java.util.List", superClass.getGenericValue()); } public void testComplexSingleParameterizedTypeClassExtends() { String source = "public class Something extends java.util.List> {}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaType superClass = javaClass.getSuperClass(); assertEquals("java.util.List", superClass.getFullyQualifiedName()); assertEquals("java.util.List>", superClass.getGenericFullyQualifiedName()); assertEquals("java.util.List", superClass.getValue()); assertEquals("java.util.List>", superClass.getGenericValue()); } public void testComplexMultiParameterizedTypeClassExtends() { String source = "public class Something extends java.util.List> {}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaType superClass = javaClass.getSuperClass(); assertEquals("java.util.List", superClass.getFullyQualifiedName()); assertEquals("java.util.List>", superClass.getGenericFullyQualifiedName()); assertEquals("java.util.List", superClass.getValue()); assertEquals("java.util.List>", superClass.getGenericValue()); } public void testSimpleSingleParameterizedTypeClassImplements() { String source = "public class Something implements java.util.List {}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaType implementsClass = javaClass.getImplements().get(0); assertEquals("java.util.List", implementsClass.getFullyQualifiedName()); assertEquals("java.util.List", implementsClass.getGenericFullyQualifiedName()); assertEquals("java.util.List", implementsClass.getValue()); assertEquals("java.util.List", implementsClass.getGenericValue()); } public void testSimpleMultiParameterizedTypeClassImplements() { String source = "public class Something implements java.util.Map {}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaType implementsClass = javaClass.getImplements().get(0); assertEquals("java.util.Map", implementsClass.getFullyQualifiedName()); assertEquals("java.util.Map", implementsClass.getGenericFullyQualifiedName()); assertEquals("java.util.Map", implementsClass.getValue()); assertEquals("java.util.Map", implementsClass.getGenericValue()); } public void testSimpleWildcardTypeClassImplements() { String source = "public class Something implements java.util.List{}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaType implementsClass = javaClass.getImplements().get(0); assertEquals("java.util.List", implementsClass.getGenericValue()); } public void testSimpleExtendsWildcardTypeClassImplements() { String source = "public class Something implements java.util.List {}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaType implementsClass = javaClass.getImplements().get(0); assertEquals("java.util.List", implementsClass.getFullyQualifiedName()); assertEquals("java.util.List", implementsClass.getGenericFullyQualifiedName()); assertEquals("java.util.List", implementsClass.getValue()); assertEquals("java.util.List", implementsClass.getGenericValue()); } public void testSimpleSuperWildcardTypeClassImplements() { String source = "public class Something implements java.util.List {}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaType implementsClass = javaClass.getImplements().get(0); assertEquals("java.util.List", implementsClass.getFullyQualifiedName()); assertEquals("java.util.List", implementsClass.getGenericFullyQualifiedName()); assertEquals("java.util.List", implementsClass.getValue()); assertEquals("java.util.List", implementsClass.getGenericValue()); } public void testComplexSingleParameterizedTypeClassImplements() { String source = "public class Something implements java.util.List> {}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaType implementsClass = javaClass.getImplements().get(0); assertEquals("java.util.List", implementsClass.getFullyQualifiedName()); assertEquals("java.util.List>", implementsClass.getGenericFullyQualifiedName()); assertEquals("java.util.List", implementsClass.getValue()); assertEquals("java.util.List>", implementsClass.getGenericValue()); } public void testComplexMultiParameterizedTypeClassImplements() { String source = "public class Something implements java.util.List> {}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaType implementsClass = javaClass.getImplements().get(0); assertEquals("java.util.List", implementsClass.getFullyQualifiedName()); assertEquals("java.util.List>", implementsClass.getGenericFullyQualifiedName()); assertEquals("java.util.List", implementsClass.getValue()); assertEquals("java.util.List>", implementsClass.getGenericValue()); } public void testSimpleTypeVariable() { String source = "public class Something {\n" + " public void doStuff(T param) {}\n" + "}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaMethod javaMethod = javaSource.getClasses().get(0).getMethods().get(0); assertEquals( 1, javaMethod.getTypeParameters().size()); JavaTypeVariable typeVariable = javaMethod.getTypeParameters().get(0); assertEquals( "T", typeVariable.getName() ); assertEquals( "T", typeVariable.getFullyQualifiedName()); assertEquals( "", typeVariable.getGenericValue()); assertEquals( "", typeVariable.getGenericFullyQualifiedName()); assertEquals( "T", typeVariable.getValue()); } public void testComplexTypeVariable() { String source = "class Collections {\n" + "public static void copy(List dest, List src){}\n" + "}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaMethod javaMethod = javaSource.getClasses().get(0).getMethods().get(0); JavaTypeVariable typeVariable0 = javaMethod.getTypeParameters().get(0); assertEquals("T", typeVariable0.getName()); assertEquals("T", typeVariable0.getFullyQualifiedName()); assertEquals("", typeVariable0.getGenericValue()); assertEquals("", typeVariable0.getGenericFullyQualifiedName()); assertEquals("T", typeVariable0.getValue()); JavaTypeVariable typeVariable1 = javaMethod.getTypeParameters().get(1); assertEquals("S", typeVariable1.getName()); assertEquals("S", typeVariable1.getFullyQualifiedName()); assertEquals("", typeVariable1.getGenericValue()); assertEquals("", typeVariable1.getGenericFullyQualifiedName()); assertEquals("S", typeVariable1.getValue()); } public void testComplexTypeVariableMultipleBounds() { String source = "class Collections\n" + "public static >\n" + "T max(Collection coll) {\n" + "return null;}\n"; } //for qdox-150 // second assert is based on java's Method.toString() // http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Method.html#toString() // 3rd and 4th are resolved Types, based on in method public void testGenericMethodDeclarationSingleParameter() { String source = "package com.thoughtworks.qdox;" + "import java.util.*;\n" + "public class TestQDOX150 {\n" + " public List myMethod( T request ) throws Exception {\n" + " return null;\n" + " }\n" + "}\n"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaMethod javaMethod = javaClass.getMethods().get(0); JavaParameter paramType = javaMethod.getParameters().get(0); JavaType returnType = javaMethod.getReturns(); assertEquals("myMethod(request)", javaMethod.getCallSignature()); assertEquals("public java.util.List com.thoughtworks.qdox.TestQDOX150.myMethod(java.lang.StringBuffer) throws java.lang.Exception", javaMethod.toString()); assertEquals("StringBuffer", paramType.getResolvedValue()); assertEquals("java.lang.StringBuffer", paramType.getResolvedFullyQualifiedName()); assertEquals("StringBuffer", paramType.getResolvedGenericValue()); assertEquals("java.util.List", returnType.getFullyQualifiedName()); assertEquals("java.util.List", returnType.getGenericFullyQualifiedName()); assertEquals("List", returnType.getValue()); assertEquals("List", returnType.getGenericValue()); } public void testGenericMethodDeclarationMultipleParameters() { String source = "package com.thoughtworks.qdox;" + "import java.util.*;\n" + "public class TestQDOX150 {\n" + " public List myMethod( T request, List list ) throws Exception {\n" + " return null;\n" + " }\n" + "}\n"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaMethod javaMethod = javaClass.getMethods().get(0); JavaParameter paramType = javaMethod.getParameters().get(1); assertEquals("myMethod(request, list)", javaMethod.getCallSignature()); assertEquals("public java.util.List com.thoughtworks.qdox.TestQDOX150.myMethod(java.lang.StringBuffer,java.util.List) throws java.lang.Exception", javaMethod.toString()); assertEquals("List", paramType.getResolvedValue()); assertEquals("java.util.List", paramType.getResolvedFullyQualifiedName()); assertEquals("List", paramType.getResolvedGenericValue()); assertEquals("java.util.List", paramType.getResolvedGenericFullyQualifiedName()); } //for QDOX-167 public void testGenericTypedMethodCall() { String source = "import java.util.*;\n" + "\n" + "public class MyClass\n" + "{\n" + "\n" + " private static final Map map1 = Collections.emptyMap();\n" + "\n" + " private static final Map map2 = Collections. emptyMap();\n" + "\n" + "}"; builder.addSource(new StringReader(source)); } // For QDox-205 public void testClassTypeParameters() { String source1 = "class GenericControllerImpl>\n" + " implements GenericController\n {}"; String source2 = "class GroupControllerImpl extends\n" + " GenericControllerImpl\n {}"; String source3 = "interface GenericController {}"; JavaClass genericControllerImpl = builder.addSource(new StringReader(source1)).getClasses().get(0); JavaClass groupControllerImpl = builder.addSource(new StringReader(source2)).getClasses().get(0); JavaClass genericController = builder.addSource(new StringReader(source3)).getClasses().get(0); assertEquals( 3, genericControllerImpl.getTypeParameters().size() ); assertEquals( 0, groupControllerImpl.getTypeParameters().size() ); assertEquals( 2, genericController.getTypeParameters().size() ); } // For QDOX-206 public void testGenericsAndArrays() { JavaMethod method = buildMethod( "public Map test(Map input);" ); assertEquals("Map", method.getReturns().toGenericString()); assertEquals("Map", method.getParameters().get(0).getType().toGenericString()); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/JavaProjectBuilderTest.java000066400000000000000000002274331325201777200300140ustar00rootroot00000000000000package com.thoughtworks.qdox; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.same; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.NotSerializableException; import java.io.Reader; import java.io.StringReader; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import com.thoughtworks.qdox.library.ClassLibraryBuilder; import com.thoughtworks.qdox.library.ErrorHandler; import com.thoughtworks.qdox.library.OrderedClassLibraryBuilder; import com.thoughtworks.qdox.model.BeanProperty; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaConstructor; import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaGenericDeclaration; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.JavaParameterizedType; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.JavaTypeVariable; import com.thoughtworks.qdox.model.util.SerializationUtils; import com.thoughtworks.qdox.parser.ParseException; import com.thoughtworks.qdox.testdata.PropertyClass; import junit.framework.TestCase; public class JavaProjectBuilderTest extends TestCase { private JavaProjectBuilder builder; @Override protected void setUp() throws Exception { super.setUp(); builder = new JavaProjectBuilder(); createFile("target/test-source/com/blah/Another.java", "com.blah", "Another"); createFile("target/test-source/com/blah/Ignore.notjava", "com.blah", "Ignore"); createFile("target/test-source/com/blah/Thing.java", "com.blah", "Thing"); createFile("target/test-source/com/blah/subpackage/Cheese.java", "com.blah.subpackage", "Cheese"); } @Override protected void tearDown() throws Exception { super.tearDown(); deleteDir("target/test-source"); } public void testParsingMultipleJavaFiles() { JavaSource source1 = builder.addSource(new StringReader(createTestClassList())); JavaSource source2 = builder.addSource(new StringReader(createTestClass())); Collection sources = builder.getSources(); assertEquals(2, sources.size()); JavaClass testClassList = source1.getClasses().get(0); assertEquals("TestClassList", testClassList.getName()); assertEquals("TestClass", testClassList.getSuperClass().getValue()); assertEquals("com.thoughtworks.util.TestClass", testClassList.getSuperClass().getFullyQualifiedName()); JavaClass testClass = source2.getClasses().get(0); assertEquals("TestClass", testClass.getName()); JavaClass testClassListByName = builder.getClassByName("com.thoughtworks.qdox.TestClassList"); assertEquals("TestClassList", testClassListByName.getName()); JavaClass testClassByName = builder.getClassByName("com.thoughtworks.util.TestClass"); assertEquals("TestClass", testClassByName.getName()); } private String createTestClassList() { StringBuffer buffer = new StringBuffer(); buffer.append("package com.thoughtworks.qdox;"); buffer.append("import com.thoughtworks.util.*;"); buffer.append("public class TestClassList extends TestClass{"); buffer.append("private int numberOfTests;"); buffer.append("public int getNumberOfTests(){return numberOfTests;}"); buffer.append("public void setNumberOfTests(int numberOfTests){this.numberOfTests = numberOfTests;}"); buffer.append("}"); return buffer.toString(); } private String createTestClass() { StringBuffer buffer = new StringBuffer(); buffer.append("package com.thoughtworks.util;"); buffer.append("public class TestClass{"); buffer.append("public void test(){}"); buffer.append("}"); return buffer.toString(); } public void testParseWithInnerClass() { JavaSource source = builder.addSource(new StringReader(createOuter())); Collection sources = builder.getSources(); assertEquals(1, sources.size()); JavaClass outer = source.getClasses().get(0); assertEquals("Outer", outer.getName()); assertEquals("foo.bar.Outer", outer.getFullyQualifiedName()); assertEquals(1, outer.getFields().size()); assertEquals("int", outer.getFields().get(0).getType().getValue()); assertEquals(1, outer.getMethods().size()); assertEquals("outerMethod", outer.getMethods().get(0).getName()); assertEquals(1, outer.getNestedClasses().size()); JavaClass inner = outer.getNestedClasses().get(0); assertEquals("Inner", inner.getName()); assertEquals("foo.bar.Outer$Inner", inner.getBinaryName()); assertEquals("foo.bar.Outer.Inner", inner.getFullyQualifiedName()); assertEquals(1, inner.getMethods().size()); assertEquals("innerMethod", inner.getMethods().get(0).getName()); } public void testGetClasses() { builder.addSource(new StringReader(createOuter())); Collection classes = builder.getClasses(); assertEquals(2, classes.size()); } public void testGetPackagesShowsOnePackageAndTwoClasses() { builder.addSourceTree(new File("target/test-source")); Collection packages = builder.getPackages(); assertEquals(2, packages.size()); JavaPackage comBlah = builder.getPackageByName( "com.blah" ); JavaPackage comBlahSubpackage = builder.getPackageByName( "com.blah.subpackage" ); assertEquals("com.blah.subpackage", comBlahSubpackage.getName()); assertEquals(1, comBlahSubpackage.getClasses().size()); assertNotNull("Cheese", comBlahSubpackage.getClassByName( "Cheese" ) ); assertEquals(2, comBlah.getClasses().size()); assertNotNull( comBlah.getClassByName( "Another" )); assertNotNull( comBlah.getClassByName( "Thing" )); assertEquals(comBlah, comBlahSubpackage.getParentPackage()); assertNull(comBlah.getParentPackage()); Collection comBlahSubpackages = comBlah.getSubPackages(); assertEquals(1, comBlahSubpackages.size()); assertEquals(comBlahSubpackage, comBlahSubpackages.iterator().next()); assertEquals(0, comBlahSubpackage.getSubPackages().size()); } private String createOuter() { StringBuffer buffer = new StringBuffer(); buffer.append("package foo.bar;"); buffer.append("public class Outer {"); buffer.append(" private int numberOfTests;"); buffer.append(" class Inner {"); buffer.append(" public int innerMethod(){return System.currentTimeMillis();}"); buffer.append(" }"); buffer.append(" public void outerMethod(int count){}"); buffer.append("}"); return buffer.toString(); } public void testSourceTree() { builder.addSourceTree(new File("target/test-source")); assertNotNull(builder.getClassByName("com.blah.Thing")); assertNotNull(builder.getClassByName("com.blah.Another")); assertNotNull(builder.getClassByName("com.blah.subpackage.Cheese")); } public void testRecordFile() throws Exception { JavaSource source = builder.addSource(new File("target/test-source/com/blah/Thing.java")); Collection sources = builder.getSources(); assertEquals(1, sources.size()); assertEquals(new File("target/test-source/com/blah/Thing.java").toURL(), source.getURL()); } public void testSearcher() { builder.addSourceTree( new File( "target/test-source" ) ); Collection results = builder.search( new Searcher() { public boolean eval( JavaClass cls ) { return cls.getPackage().getName().equals( "com.blah" ); } } ); assertEquals( 2, results.size() ); List classNames = new ArrayList(); for ( JavaClass cls : results ) { classNames.add( cls.getName() ); } Collections.sort( classNames ); assertEquals( "Another", classNames.get( 0 ) ); assertEquals( "Thing", classNames.get( 1 ) ); } private void createFile(String fileName, String packageName, String className) throws Exception { File file = new File(fileName); file.getParentFile().mkdirs(); FileWriter writer = new FileWriter(file); writer.write("// this file generated by JavaDocBuilderTest - feel free to delete it\n"); writer.write("package " + packageName + ";\n\n"); writer.write("public class " + className + " {\n\n // empty\n\n}\n"); writer.close(); } private void deleteDir(String path) { File dir = new File(path); File[] children = dir.listFiles(); for (int i = 0; i < children.length; i++) { File file = children[i]; if (file.isDirectory()) { deleteDir(file.getAbsolutePath()); } else { file.delete(); } } dir.delete(); } public void testDefaultClassLoader() { String in = "" + "package x;" + "import java.util.*;" + "import java.awt.*;" + "class X extends List {}"; builder.addSource(new StringReader(in)); JavaClass cls = builder.getClassByName("x.X"); assertEquals("List", cls.getSuperClass().getValue()); assertEquals("java.util.List", cls.getSuperClass().getFullyQualifiedName()); } public void testAddMoreClassLoaders() { builder = new JavaProjectBuilder(new OrderedClassLibraryBuilder(null)); builder.addClassLoader(new ClassLoader() { @Override public Class loadClass(String name) throws ClassNotFoundException { if("com.thoughtworks.qdox.Spoon".equals(name)) { return Spoon.class; //Located inside com.thoughtworks.qdox.TestClasses.java } else { throw new ClassNotFoundException(name); } } }); builder.addClassLoader(new ClassLoader() { @Override public Class loadClass(String name) throws ClassNotFoundException { if("com.thoughtworks.qdox.Fork".equals(name)) { return Fork.class; //Located inside com.thoughtworks.qdox.TestClasses.java } else { throw new ClassNotFoundException(name); } } }); String in = "" + "package x;" + "import java.util.*;" + "import com.thoughtworks.qdox.*;" + "class X {" + " Spoon a();" + " Fork b();" + " Cabbage c();" + "}"; builder.addSource(new StringReader(in)); // be sure no default classloaders have been added assertNull(builder.getClassByName(Knife.class.getName())); JavaClass cls = builder.getClassByName("x.X"); assertEquals("Spoon", cls.getMethods().get(0).getReturns().getValue()); assertEquals("com.thoughtworks.qdox.Spoon", cls.getMethods().get(0).getReturns().getFullyQualifiedName()); assertEquals("Fork", cls.getMethods().get(1).getReturns().getValue()); assertEquals("com.thoughtworks.qdox.Fork", cls.getMethods().get(1).getReturns().getFullyQualifiedName()); // unresolved assertEquals("Cabbage", cls.getMethods().get(2).getReturns().getValue()); } public void testOldfashionedExtraClassesAreSupported() { String in = "" + "package oldfashioned;" + "public class Ping {" + "}" + "class Bar {" + "}"; builder.addSource(new StringReader(in)); assertEquals(2, builder.getClasses().size()); assertNotNull(builder.getClassByName("oldfashioned.Ping")); assertNotNull(builder.getClassByName("oldfashioned.Bar")); } public void testBinaryClassesAreFound() { String in = "" + "package x;" + "import java.util.*;" + "class X {" + " ArrayList a();" + "}"; builder.addSource(new StringReader(in)); JavaClass cls = builder.getClassByName("x.X"); JavaType returnType = cls.getMethods().get(0).getReturns(); JavaClass returnClass = builder.getClassByName(returnType.getFullyQualifiedName()); assertEquals("java.util.ArrayList", returnClass.getFullyQualifiedName()); boolean foundList = false; for (JavaType type : returnClass.getImplements()) { if (type.getValue().equals("java.util.List")) { foundList = true; } } assertTrue(foundList); // See if interfaces work too. JavaClass list = builder.getClassByName("java.util.List"); assertTrue(list.isInterface()); assertNull(list.getSuperJavaClass()); assertEquals("java.util.Collection", list.getImplements().get(0).getValue()); } public void testSuperclassOfObjectIsNull() { JavaClass object = builder.getClassByName("java.lang.Object"); JavaClass objectSuper = object.getSuperJavaClass(); assertNull(objectSuper); } /* Various test for isA. Tests interface extension, interface implementation and class extension. Immediate and chained. java.util.Collection | interface extension java.util.List | interface implemention java.util.AbstractList | class extension java.util.ArrayList */ public void testConcreteClassCanBeTestedForImplementedClassesAndInterfaces() { JavaClass arrayList = builder.getClassByName("java.util.ArrayList"); assertTrue("should be Object", arrayList.isA("java.lang.Object")); assertTrue("should be Collection", arrayList.isA("java.util.Collection")); assertTrue("should be List", arrayList.isA("java.util.List")); assertTrue("should be AbstractList", arrayList.isA("java.util.AbstractList")); assertTrue("should be ArrayList", arrayList.isA("java.util.ArrayList")); assertFalse("should not be Map", arrayList.isA("java.util.Map")); } public void testAbstractClassCanBeTestedForImplementedClassesAndInterfaces() { JavaClass abstractList = builder.getClassByName("java.util.AbstractList"); assertTrue("should be Object", abstractList.isA("java.lang.Object")); assertTrue("should be Collection", abstractList.isA("java.util.Collection")); assertTrue("should be List", abstractList.isA("java.util.List")); assertTrue("should be AbstractList", abstractList.isA("java.util.AbstractList")); assertFalse("should not be ArrayList", abstractList.isA("java.util.ArrayList")); assertFalse("should not be Map", abstractList.isA("java.util.Map")); } public void testInterfaceCanBeTestedForImplementedInterfaces() { JavaClass list = builder.getClassByName("java.util.List"); assertTrue("should be Collection", list.isA("java.util.Collection")); assertTrue("should be List", list.isA("java.util.List")); assertFalse("should not be ArrayList", list.isA("java.util.ArrayList")); assertFalse("should not be Map", list.isA("java.util.Map")); assertFalse("should not be Object", list.isA("java.lang.Object")); // I think! ;) } public void testClassCanBeTestedForNonexistantClasses() { String in = "" + "package food;" + "class Sausage extends food.Meat implements food.Proteine {" + "}"; builder.addSource(new StringReader(in)); JavaClass sausage = builder.getClassByName("food.Sausage"); assertTrue(sausage.isA("food.Meat")); assertTrue(sausage.isA("food.Proteine")); } public void testClassesCanBeAddedLater() { testClassCanBeTestedForNonexistantClasses(); assertEquals(1, builder.getClasses().size()); JavaClass sausage = builder.getClassByName("food.Sausage"); assertFalse(sausage.isA("global.Stuff")); String in = "" + "package food;" + "class Meat extends global.Stuff {" + "}"; builder.addSource(new StringReader(in)); assertEquals(2, builder.getClasses().size()); assertTrue(sausage.isA("global.Stuff")); } public void testImageIconBeanProperties() { JavaClass imageIcon = builder.getClassByName("javax.swing.ImageIcon"); assertNull(imageIcon.getBeanProperty("class")); BeanProperty clazz = imageIcon.getBeanProperty("class", true); assertNotNull(clazz.getAccessor()); assertNull(clazz.getMutator()); BeanProperty iconHeight = imageIcon.getBeanProperty("iconHeight"); assertNotNull(iconHeight.getAccessor()); assertNull(iconHeight.getMutator()); BeanProperty image = imageIcon.getBeanProperty("image"); assertNotNull(image.getAccessor()); assertNotNull(image.getMutator()); } public void testDerivedClassesAreFound() { /* Collection | interface extension List | interface implemention AbstractList | class extension ArrayList */ builder.addSource(new StringReader("public interface Collection {}")); builder.addSource(new StringReader("public interface List extends Collection {}")); builder.addSource(new StringReader("public class AbstractList implements List {}")); builder.addSource(new StringReader("public class ArrayList extends AbstractList {}")); JavaClass collection = builder.getClassByName("Collection"); JavaClass list = builder.getClassByName("List"); JavaClass abstractList = builder.getClassByName("AbstractList"); JavaClass arrayList = builder.getClassByName("ArrayList"); List derivedClassesOfCollection = collection.getDerivedClasses(); List derivedClassesOfList = list.getDerivedClasses(); List derivedClassesOfAbstractList = abstractList.getDerivedClasses(); List derivedClassesOfArrayList = arrayList.getDerivedClasses(); assertEquals(3, derivedClassesOfCollection.size()); assertEquals(2, derivedClassesOfList.size()); assertEquals(1, derivedClassesOfAbstractList.size()); assertEquals(0, derivedClassesOfArrayList.size()); } public void testSourcePropertyClass() throws IOException { builder.addSource(new File("src/test/java/com/thoughtworks/qdox/testdata/PropertyClass.java")); JavaClass propertyClass = builder.getClassByName("com.thoughtworks.qdox.testdata.PropertyClass"); assertEquals(1, propertyClass.getBeanProperties().size()); // test ctor, methods and fields assertEquals(6, propertyClass.getMethods().size()); assertEquals(2, propertyClass.getConstructors().size()); JavaConstructor ctor = propertyClass.getConstructor(null); JavaConstructor ctor2 = propertyClass.getConstructor(Collections.singletonList((JavaType) propertyClass)); JavaMethod getFoo = propertyClass.getMethodBySignature("getFoo", null); JavaMethod isBar = propertyClass.getMethodBySignature("isBar", null); JavaMethod get = propertyClass.getMethodBySignature("get", null); JavaType intType = mock( JavaType.class ); when( intType.getFullyQualifiedName() ).thenReturn( "int" ); JavaMethod set = propertyClass.getMethodBySignature( "set", Collections.singletonList( (JavaType) intType ) ); JavaMethod protectedMethod = propertyClass.getMethodBySignature("protectedMethod", null); JavaMethod privateMethod = propertyClass.getMethodBySignature("privateMethod", null); JavaMethod shouldntBeInherited = propertyClass.getMethodBySignature("getShouldntBeInherited", null); assertNotNull(ctor); assertNotNull(ctor2); assertNotNull(getFoo); assertNotNull(isBar); assertNotNull(get); assertNotNull(set); assertNotNull(protectedMethod); assertNotNull(privateMethod); assertNull(shouldntBeInherited); assertTrue(getFoo.isStatic()); assertFalse(isBar.isStatic()); assertFalse(get.isStatic()); assertFalse(set.isStatic()); assertFalse(protectedMethod.isStatic()); assertFalse(privateMethod.isStatic()); assertTrue(get.isFinal()); assertFalse(set.isFinal()); assertTrue(ctor2.isProtected()); assertTrue(protectedMethod.isProtected()); assertTrue(privateMethod.isPrivate()); List fields = propertyClass.getFields(); assertEquals(3, fields.size()); } public void testSourceDefaultCtor() throws Exception { builder.addSource(new File("src/test/resources/com/thoughtworks/qdox/testdata/DefaultCtor.java")); JavaClass javaClass = builder.getClassByName("com.thoughtworks.qdox.testdata.DefaultCtor"); JavaMethod ctor = javaClass.getMethodBySignature("DefaultCtor", null); assertNull(ctor); } public void testBinaryDefaultCtor() { JavaClass javaClass = builder.getClassByName("com.thoughtworks.qdox.testdata.DefaultCtor"); JavaMethod ctor = javaClass.getMethodBySignature("DefaultCtor", null); assertNull(ctor); } /* * The JavaDocBuilder has to be serializable, With JavaProjectBuilder, we only need to serialize the ClassLibraryBuilder */ public void testSerializable() { JavaSource source = builder.addSource(new StringReader("package test; public class X{}")); assertEquals("X", source.getClasses().get(0).getName()); try { SerializationUtils.serializedCopy(builder); fail("JavaProjectBuilder should not serializable"); } catch(RuntimeException ex) { if ( !(ex.getCause() instanceof NotSerializableException)) { fail("Unexpected RuntimeException caught: " + ex.getMessage()); } } } public void testSaveAndRestore() throws Exception { File file = new File("target/test-source/cache.obj"); builder.addSourceTree(new File("target/test-source")); builder.save(file); JavaProjectBuilder newBuilder = JavaProjectBuilder.load(file); assertNotNull(newBuilder.getClassByName("com.blah.subpackage.Cheese")); newBuilder.addSource(new StringReader("package x; import java.util.*; class Z extends List{}")); assertEquals("List", newBuilder.getClassByName("x.Z").getSuperClass().getValue()); assertEquals("java.util.List", newBuilder.getClassByName("x.Z").getSuperClass().getFullyQualifiedName()); } public void testSaveAndRestoreWithoutDefaultClassloaders() throws Exception { builder = new JavaProjectBuilder( new OrderedClassLibraryBuilder() ); File file = new File("target/test-source/cache.obj"); builder.addSourceTree(new File("target/test-source")); builder.save(file); JavaProjectBuilder newBuilder = JavaProjectBuilder.load(file); assertNotNull(newBuilder.getClassByName("com.blah.subpackage.Cheese")); newBuilder.addSource(new StringReader("package x; import java.util.*; class Z extends List{}")); //Here it's just List, since there we didn't use the defaultClassLoaders assertEquals("List", newBuilder.getClassByName("x.Z").getSuperClass().getValue()); } public void testSuperClassOfAnInterfaceReturnsNull() { String in = "package x; interface I {}"; builder.addSource(new StringReader(in)); JavaClass cls = builder.getClassByName("x.I"); assertNull("Should probably return null", cls.getSuperJavaClass()); } public void testMethodsFromSuperclassesCanBeRetrieved() { String goodListSource = "" + "package x;" + "import java.util.*;" + "/**" + " * @foo bar" + " */" + "class GoodList extends ArrayList {" + " public void good() {}" + " private void myown() {}" + "}"; builder.addSource(new StringReader(goodListSource)); String betterListSource = "" + "package x;" + "/**" + " * @foo zap" + " */" + "class BetterList extends GoodList {" + " public void better() {}" + "}"; builder.addSource(new StringReader(betterListSource)); JavaClass betterList = builder.getClassByName("x.BetterList"); assertNull(betterList.getMethodBySignature("good", null)); assertNotNull(betterList.getMethodBySignature("good", null, true)); assertNotNull(betterList.getMethodBySignature("size", null, true)); assertNull("Shouldn't be able to get private methods", betterList.getMethodBySignature("myown", null, true)); } public void testTagLineNumbersAndSourceInTags() { String jallaSource = "" + "package x;\n" + "import java.util.*;\n" + "/**\n" + " * @line4 foo\n" + " * @line5 overflows onto\n" + " * line6\n" + " */\n" + "class Jalla extends ArrayList {\n" + "}\n"; builder.addSource(new StringReader(jallaSource)); JavaClass jalla = builder.getClassByName("x.Jalla"); DocletTag line4 = jalla.getTagByName("line4"); assertEquals(4, line4.getLineNumber()); assertSame(line4.getContext(), jalla); DocletTag line5 = jalla.getTagByName("line5"); assertEquals(5, line5.getLineNumber()); } public void testGetLineNumberForAbstractEntities() { String src = "" + "package x;\n" + "import java.util.*;\n" + "\n" + "class Foo {\n" + " int i;\n" + " int getI() { return i; }\n" + "}\n"; builder.addSource(new StringReader(src)); JavaClass fooClass = builder.getClassByName("x.Foo"); assertEquals(4, fooClass.getLineNumber()); JavaField iField = fooClass.getFieldByName("i"); assertEquals(5, iField.getLineNumber()); JavaMethod getIMethod = fooClass.getMethodBySignature("getI", Collections.EMPTY_LIST); assertEquals(6, getIMethod.getLineNumber()); } public void testJiraQdox14() { String source = "" + "package foo; \n" + "class Outer { \n" + " Inner field1; \n" + " class Inner { \n" + " Outer.Inner field2; \n" + " } \n" + "} \n" + ""; builder.addSource(new StringReader(source)); JavaClass outer = builder.getClassByName("foo.Outer"); JavaClass inner = outer.getNestedClasses().get(0); assertEquals("foo.Outer$Inner", inner.getBinaryName()); assertEquals("foo.Outer.Inner", inner.getFullyQualifiedName()); JavaField field1 = outer.getFieldByName("field1"); JavaClass type = field1.getType(); assertEquals("foo.Outer$Inner", type.getBinaryName()); assertEquals("foo.Outer.Inner", type.getFullyQualifiedName()); } public void testJiraQdox16() { String source = "" + "/**Hip hop won*t stop*/" + "class x{}"; builder.addSource(new StringReader(source)); JavaClass x = builder.getClassByName("x"); assertEquals("Hip hop won*t stop", x.getComment()); } public void testCommentsCanHaveNewlines() { String source = "" + "/** Hello\n" + "* world!" + "*/" + "class x{}"; builder.addSource(new StringReader(source)); JavaClass x = builder.getClassByName("x"); assertEquals("Hello\nworld!", x.getComment()); } public void testTagValuesCanSpanMultipleLines() { String source = "" + "/**\n" + " * @bar.baz foo=\"this is\\\n" + " * multilined\"\n" + " */\n" + "class x{}"; builder.addSource(new StringReader(source)); JavaClass x = builder.getClassByName("x"); DocletTag tag = x.getTagByName("bar.baz"); assertEquals("foo=\"this is\\\n multilined\"", tag.getValue()); assertEquals("this is\n multilined", tag.getNamedParameter("foo")); } public void testJiraQdox19() { String source = "" + "class x { \n" + " /**\n" + " * @y z\n" + " * \n" + " */\n" + " String m();\n" + "}\n" + ""; builder.addSource(new StringReader(source)); JavaClass x = builder.getClassByName("x"); JavaMethod m = x.getMethods().get(0); DocletTag foo = m.getTagByName("y"); assertEquals("z", foo.getValue()); } public void testTagInheritance() { String X = "" + "/** @c x */" + "class X {" + " /** \n" + " * @m x \n" + " * @s f\n" + " */" + " void i(){}" + "}"; String Y = "" + "/** @c y */" + "class Y extends X {" + " /** @m y */" + " void i(){}" + "}"; builder.addSource(new StringReader(X)); builder.addSource(new StringReader(Y)); JavaClass y = builder.getClassByName("Y"); List c = y.getTagsByName("c", true); assertEquals(2, c.size()); assertEquals("y", c.get(0).getValue()); assertEquals("x", c.get(1).getValue()); JavaMethod i = y.getMethodBySignature("i", null); List m = i.getTagsByName("m", true); assertEquals(2, m.size()); assertEquals("y", m.get(0).getValue()); assertEquals("x", m.get(1).getValue()); DocletTag s = i.getTagByName("s", true); assertEquals("f", s.getValue()); } public void testJiraQdox27() { String sourceCode = "" + "package com.acme.thing;\n" + "\n" + "/**" + " * This class does something." + " **/" + "public class AClassName {\n" + "}"; builder.addSource(new StringReader(sourceCode)); JavaClass aClass = builder.getClassByName("com.acme.thing.AClassName"); assertNotNull(aClass); } public void testJiraQdox39() { String sourceCode = "" + "public class A {\n" + " int i,j=2,k[];" + "}"; builder.addSource(new StringReader(sourceCode)); JavaClass a = builder.getClassByName("A"); assertEquals(3, a.getFields().size()); assertEquals("i", a.getFields().get(0).getName()); assertEquals("int", a.getFields().get(0).getType().toString()); assertEquals("j", a.getFields().get(1).getName()); assertEquals("int", a.getFields().get(1).getType().toString()); assertEquals("k", a.getFields().get(2).getName()); assertEquals("int[]", a.getFields().get(2).getType().toString()); } public void testJiraQdox40() { String sourceCode = "" + "package foo.bar;" + "public class Outer {" + " class WrappedInternalContextAdapter implements InternalContextAdapter {" + " }" + "}"; builder.addSource(new StringReader(sourceCode)); JavaClass clazz = builder.getClassByName("foo.bar.Outer"); assertEquals(1, clazz.getNestedClasses().size()); } public void testParseErrorLocationShouldBeAvailable() { String badSource = "" + "package x;\n" + "import java.util.*;\n" + "class Bad [\n"; try { builder.addSource(new StringReader(badSource)); fail("ParseException expected"); } catch (ParseException e) { assertEquals(3, e.getLine()); assertEquals(11, e.getColumn()); } } public void testJiraQdox35() { String sourceCode = "package pack; public class Foo extends Bar implements Zap {}"; builder.addSource(new StringReader(sourceCode)); JavaClass clazz = builder.getClassByName("pack.Foo"); assertEquals(1, clazz.getInterfaces().size()); // Ideally the fully qualified names should be the pack.Zap and pack.Bar, // but this will do for now to fix the NPE bug. assertEquals("Zap", clazz.getInterfaces().get(0).getFullyQualifiedName()); assertEquals("Bar", clazz.getSuperJavaClass().getFullyQualifiedName()); } /** * @french.english * cheese="fromage" * fish="poisson" * * @band.singer * doors=morrison * cure=smith */ public void testShouldShouldReportTagParameterKeys() { String sourceCode = "" + " /**\n" + " * @french.english\r\n" + " * cheese=\"fromage\"\n\r" + " * fish=\"poisson\"\r" + " */\n" + " class MultiLine{}"; JavaClass multiline = builder.addSource(new StringReader(sourceCode)).getClasses().get(0); DocletTag frenchEnglish = multiline.getTagByName("french.english"); Set expected = new HashSet(); expected.add("cheese"); expected.add("fish"); assertEquals(expected,frenchEnglish.getNamedParameterMap().keySet()); } public void testJiraQdox58() { builder.addSource(new StringReader( "class Y implements SomeInterface { }") ); Collection results = builder.search(new Searcher() { public boolean eval(JavaClass javaClass) { return javaClass.isA("SomeInterface"); } }); assertEquals(1, results.size()); } public void testJiraQdox63() { builder.addSource( new StringReader( "package p1;\n" + "class A {\n" + " static class Inner {}\n" + "}" ) ); builder.addSource( new StringReader( "package p2;\n" + "import p1.A;\n" + "class B {\n" + " A.Inner innerField;\n" + "}" ) ); JavaClass innerClass = builder.getClassByName("p1.A").getNestedClassByName("Inner"); JavaField innerField = builder.getClassByName("p2.B").getFieldByName("innerField"); assertEquals(innerClass, innerField.getType() ); assertEquals("p1.A$Inner", innerField.getType().getBinaryName()); assertEquals("p1.A.Inner", innerField.getType().getFullyQualifiedName()); } public void testJiraQdox71() { String sourceCode = "" + "package foo;" + "public class C {" + " boolean flag = (X < Y);" + "}"; builder.addSource(new StringReader(sourceCode)); } public void testReadMultipleMethodAnnotations() { String sourceCode = "" + "public class C {" + " @Annotation\n" + " @AnotherAnnotation\n" + " public void aMethod() {}\n" + "}"; JavaSource javaSource = builder.addSource(new StringReader(sourceCode)); JavaMethod javaMethod = javaSource.getClasses().get(0).getMethods().get(0); assertEquals("aMethod", javaMethod.getName()); } public void testReadMultipleClassAnnotations() { String sourceCode = "" + "@Annotation\n" + "@AnotherAnnotation\n" + "public class C {" + " public void aMethod() {}\n" + "}"; JavaSource javaSource = builder.addSource(new StringReader(sourceCode)); JavaClass javaClass = javaSource.getClasses().get(0); assertEquals("C", javaClass.getName()); } public void testMethodBody() { String sourceCode = "" + "public class X {\n" + " public void doStuff() {\n" + " System.out.println(\"hi\"); // comment\n" + " Foo x = new Cheese().get()[4]; /*x*/\n" + " } // not this \n" + "}"; JavaSource javaSource = builder.addSource(new StringReader(sourceCode)); JavaClass javaClass = javaSource.getClasses().get(0); JavaMethod javaMethod = javaClass.getMethods().get(0); String expected = "" + " System.out.println(\"hi\"); // comment\n" + " Foo x = new Cheese().get()[4]; /*x*/"; assertEquals(expected.trim(), javaMethod.getSourceCode().trim()); } public void testMethodBodyWithConfusingCurlies() { String sourceCode = "" + "public class X {\n" + " public void doStuff() {\n" + " System.out.println(\"}}} \\\"\"); // }\n" + " Foo x = new Cheese().get()[4]; /*}}*/ /etc\n" + " } // not this \n" + "}"; JavaSource javaSource = builder.addSource(new StringReader(sourceCode)); JavaClass javaClass = javaSource.getClasses().get(0); JavaMethod javaMethod = javaClass.getMethods().get(0); String expected = "" + " System.out.println(\"}}} \\\"\"); // }\n" + " Foo x = new Cheese().get()[4]; /*}}*/ /etc\n"; assertEquals(expected.trim(), javaMethod.getSourceCode().trim()); } public void testMethodBodyWithPrecedingStaticBlock() { String sourceCode = "" + "public class X {\n" + " static {\n" + " System.out.println(\"static\");\n" + " }\n" + " public void doStuff() {\n" + " System.out.println(\"hi\"); // comment\n" + " Foo x = new Cheese().get()[4]; /*x*/\n" + " } // not this \n" + "}"; JavaSource javaSource = builder.addSource(new StringReader(sourceCode)); JavaClass javaClass = javaSource.getClasses().get(0); JavaMethod javaMethod = javaClass.getMethods().get(0); String expected = "" + " System.out.println(\"hi\"); // comment\n" + " Foo x = new Cheese().get()[4]; /*x*/"; assertEquals(expected.trim(), javaMethod.getSourceCode().trim()); } public void testFieldDefinition() { String sourceCode = "" + "public class X {\n" + " int x = new FlubberFactory(\"}\"){}.doCheese(spam/*c*/)\n" + " [9] /*comment*/ //more\n; /*somethingelse*/" + "}"; JavaSource javaSource = builder.addSource(new StringReader(sourceCode)); JavaClass javaClass = javaSource.getClasses().get(0); JavaField javaField = javaClass.getFields().get(0); String expected = "" + "new FlubberFactory(\"}\"){}.doCheese(spam/*c*/)\n" + " [9] /*comment*/ //more"; assertEquals(expected.trim(), javaField.getInitializationExpression().trim()); } public void testNewlessArrays() { String source = "" + "public class Thing {\n" + " long[] bad = {1,2,3};\n" + // as opposed to bad = new long[] {1,2,3}. "}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaField field = javaSource.getClasses().get(0).getFieldByName("bad"); assertEquals("{1,2,3}", field.getInitializationExpression().trim()); } public void testDefaultsToThrowingExceptionWhenNotParseable() throws Exception { createFile("target/test-source/com/blah/Bad.java", "com.blah", "@%! BAD {}}}}"); try { builder.addSourceTree(new File("target/test-source")); fail("Expected exception"); } catch (ParseException expectedException) { // Good! } } public void testContinuesProcessingAfterBadFileIfCustomHandlerPermits() throws Exception { createFile("target/test-source/com/blah/Bad.java", "com.blah", "@%! BAD {}}}}"); ErrorHandler mockErrorHandler = mock(ErrorHandler.class); builder.setErrorHandler( mockErrorHandler ); builder.addSourceTree(new File("target/test-source")); assertNotNull(builder.getClassByName("com.blah.Thing")); verify( mockErrorHandler ).handle( any( ParseException.class ) ); } public void testBinaryClassFieldModifiers() { JavaClass javaClass = builder.getClassByName(PropertyClass.class.getName()); assertEquals("Class", PropertyClass.class.getName(), javaClass.getFullyQualifiedName()); JavaField javaField = javaClass.getFieldByName("aField"); assertNotNull("Field", javaField); Set modifiers = new HashSet(javaField.getModifiers()); assertEquals("Modifier count", 2, javaField.getModifiers().size()); assertTrue("Static", modifiers.contains("static")); assertTrue("Public", modifiers.contains("public")); } public void testMultipleFieldsWithJavaDoc() { String sourceCode = "class Thing {\n" + " /** some doc */\n" + " int a = 1,\n" + " /** more doc */\n" + " b = 2,\n" + " /** etc */\n" + " c = 3; }"; JavaClass javaClass = builder.addSource(new StringReader(sourceCode)).getClasses().get(0); JavaField fieldA = javaClass.getFieldByName("a"); assertEquals("some doc", fieldA.getComment()); JavaField fieldB = javaClass.getFields().get(1); assertEquals("more doc", fieldB.getComment()); JavaField fieldC = javaClass.getFields().get(2); assertEquals("etc", fieldC.getComment()); } public void testValueRemainsIntact() { String in = "" + "package x;\n" + "/**\n" + " * @tag aa count(*) bbb * ccc dd=e f='g' i = \"xx\"\n" + " */\n" + "class X {}"; JavaProjectBuilder builder = new JavaProjectBuilder(); builder.addSource(new StringReader(in)); DocletTag tag = builder.getClassByName("x.X").getTagByName("tag"); assertEquals("aa count(*) bbb * ccc dd=e f='g' i = \"xx\"", tag.getValue()); } public void testJiraQdox117() { String sourceCode = "" + "public class foo {\n" + "{ dosomething(); }\n" + "@Test (description=\"test blah blah\")\n" + "public void myTest() {}\n" + "}"; JavaSource javaSource = builder.addSource(new StringReader(sourceCode)); JavaClass javaClass = javaSource.getClasses().get(0); JavaMethod javaMethod = javaClass.getMethods().get(0); assertEquals("\"test blah blah\"", javaMethod.getAnnotations().get(0).getNamedParameter("description").toString()); } public void testJiraQdox131() { 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" + ""; 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().get(0).getSourceCode()); } public void testJiraQdox134() { String sourceCode = "/**\n" + "*\n" + "@myTag name=TestClass attrs=Something1,Something2,Something3\n" + "*/\n" + "public class TestClassImpl {\r\n" + "}"; JavaClass jClass = builder.addSource(new StringReader(sourceCode)).getClasses().get(0); assertEquals( Arrays.asList( new String[] {"name=TestClass","attrs=Something1,Something2,Something3"}), jClass.getTags().get(0).getParameters()); //assertTrue( Arrays.equals( new String[] {"name=TestClass","attrs=Something1,Something2,Something3"}, jClass.getTags()[0].getParameters() )); } //for qdox-146 public void testWhitespaceCanBeRetainedInJavadoc() { String sourceCode = "" + "package com.acme.thing;\n" + "\n" + "/**\n" + " * This class does something.\n" + " * chalala\n" + " * cha ** lala\n" + " **/\n" + "public class AClassName {\n" + "}"; builder.addSource(new StringReader(sourceCode)); JavaClass aClass = builder.getClassByName("com.acme.thing.AClassName"); assertEquals("This class does something.\n" + " chalala\n" + " cha ** lala", aClass.getComment()); } //for qdox-152 public void testExtendedClass() { String source = "import javax.faces.component.UIOutput;" + "public abstract class AbstractSayHello extends UIOutput {\n" + "}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); assertEquals("UIOutput", javaClass.getSuperClass().getValue()); assertEquals("javax.faces.component.UIOutput", javaClass.getSuperClass().getFullyQualifiedName()); } //for QDox-154 public void testImplicitJavadocCommentOrder() { String source = "" + "public class Foo {\n" + " /**\n" + " * A Javadoc sample.\n" + " *\n" + " * @return The size.\n" + " */\n" + " public long getSize()\n" + " {\n" + " return 0;\n" + " }\n" + "\n" + " /**\n" + " * @return The size.\n" + " *\n" + " * A Javadoc sample.\n" + " */\n" + " public long getSize2()\n" + " {\n" + " return 0;\n" + " }\n" + "}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); JavaMethod method1 = javaClass.getMethods().get(0); assertEquals( "A Javadoc sample.", method1.getComment()); assertEquals( "The size.", method1.getTagByName( "return" ).getValue()); JavaMethod method2 = javaClass.getMethods().get(1); assertEquals( "The size.\n\nA Javadoc sample.", method2.getTagByName( "return" ).getValue()); } //for qdox-155 public void testCharField() { String source = "public class Foo {\n" + "public static final char SEPARATOR = ',';" + "}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); assertEquals(javaClass.getFieldByName( "SEPARATOR" ).getInitializationExpression(), "','"); } //for qdox-157 public void testCommentBetweenFields() { String source = "public class Foo {\n" + "public static final String TEST1 = \"test1\";\n" + "// TODO: blabla\n" + "public static final String TEST2 = \"test2\";\n" + "}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); assertEquals(javaClass.getFieldByName( "TEST2" ).getInitializationExpression(), "\"test2\""); } public void testAnnotationWithComment() { String source = "@OneToMany(cascade = {/* CascadeType.PERSIST */}, fetch = FetchType.LAZY)\n" + "public class Foo{}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); assertNotNull(javaClass.getAnnotations().get(0).getNamedParameter("cascade")); } /** * According to sun specs: Starting with Javadoc 1.4, the leading asterisks are optional * @throws Exception */ public void testJavadocWithoutStartingAsterisks() { String source = " /**\n" + " Some text\n" + "more text\n" + "\t and even more\n" + " \n" + " @throws Exception\n" + "@deprecated" + " */\n" + "public class Foo{}"; JavaSource javaSource = builder.addSource(new StringReader(source)); JavaClass javaClass = javaSource.getClasses().get(0); assertEquals("Some text\nmore text\nand even more", javaClass.getComment()); assertEquals("throws", javaClass.getTags().get(0).getName()); assertEquals("Exception", javaClass.getTags().get(0).getValue()); assertEquals("deprecated", javaClass.getTags().get(1).getName()); } // for QDOX-189 public void testFinalAnnotationParam() { String source = "public final class WSEndpointReference {\n" + " public void writeTo(final @NotNull String localName, @NotNull XMLStreamWriter w) throws XMLStreamException {\n" + " }\n" + "}"; builder.addSource(new StringReader(source)); } // for QDOX-190 public void testTwoCommentsBeforeEnumValue() { String source = "public enum Source {\n" + " /** comment 1 */ \n" + " /** comment 2 */\n" + " JDK1_2(\"1.2\");\n" + "}\n"; JavaSource src = builder.addSource(new StringReader(source)); assertEquals( "comment 2", src.getClasses().get(0).getFieldByName( "JDK1_2" ).getComment() ); } //for QDOX-191 public void testLeftShift() { String source = "private static class Flags {\n" + " static final Flags LEFT_JUSTIFY = new Flags(1 << 0);\n" + "}\n"; builder.addSource(new StringReader(source)); } public void testGenericConstructor() { String source = "public class MXBeanSupport {\n" + " public MXBeanSupport(T resource, Class mxbeanInterface)\n" + " throws NotCompliantMBeanException {\n" + " } \n" + "}"; builder.addSource(new StringReader(source)); } // for QDOX-195 public void testSharedPackageJavaClasses() { String source1 = "@javax.xml.bind.annotation.XmlSchema(namespace = \"http://docs.oasis-open.org/wsn/br-2\")\n" + "package com.foo;\n" + "public class Bar1 {}"; String source2 = "package com.foo;\n" + "public class Bar2{}"; JavaSource javaSource1 = builder.addSource(new StringReader(source1)); JavaSource javaSource2 = builder.addSource(new StringReader(source2)); JavaPackage jPackage = builder.getPackageByName("com.foo"); assertEquals( 2, jPackage.getClasses().size() ); assertEquals( 2, javaSource1.getPackage().getClasses().size() ); assertEquals( 2, javaSource2.getPackage().getClasses().size() ); assertNotSame( javaSource1.getPackage(), javaSource2.getPackage() ); assertEquals( 1, javaSource1.getPackage().getAnnotations().size() ); assertEquals( 0, javaSource2.getPackage().getAnnotations().size() ); assertEquals( 2, javaSource1.getPackage().getLineNumber() ); assertEquals( 1, javaSource2.getPackage().getLineNumber() ); } public void testSourceFolder() { builder.addSourceFolder( new File("target/test-source") ); String source = "package com.foo;\n" + "import com.blah.*;\n" + "public abstract class Me {\n" + " public abstract Thing getThing(); " + "}"; builder.addSource( new StringReader( source ) ); JavaClass clazz = builder.addSource( new StringReader( source ) ).getClasses().get(0); JavaClass thing = clazz.getMethods().get(0).getReturns(); assertEquals("com.blah.Thing", thing.getFullyQualifiedName()); assertNotNull(thing.getSource()); } // for QDOX-208 public void testMethodLineNumber() { String source = "package com.foo;\n" + "public class Bar {\n" + " public void method1() \n" + " {}\n" + "\n" + " /**\n" + " * Method with javadoc\n" + " */\n" + " public void method1() { \n" + " }\n" + "}"; JavaClass clazz = builder.addSource( new StringReader( source ) ).getClasses().get(0); assertEquals( 2, clazz.getLineNumber() ); assertEquals( 3, clazz.getMethods().get(0).getLineNumber() ); assertEquals( 9, clazz.getMethods().get(1).getLineNumber() ); } // for QDOX-209 public void testAnnotationMap() { String source = "import javax.persistence.JoinColumn;\n" + "public class Instruction {\n" + " private static final int something = 40;\n" + " //-----------------------------------------------------------------------\r\n" + " @JoinColumn(name=\"test\",bla=\"hi\")\n" + " int testfield;\r\n" + "}"; builder.addSource(new StringReader( source )); JavaClass classByName = builder.getClassByName("Instruction"); JavaField fieldByName = classByName.getFieldByName("testfield"); List annotations = fieldByName.getAnnotations(); // Now we do have the annotation "JoinColumn" in annotations[0] Map propertyMap = annotations.get(0).getNamedParameterMap(); // This one works assertEquals("\"hi\"", propertyMap.get("bla")); String string = (String) propertyMap.get("name"); // This one does not work assertEquals("\"test\"", string); } public void testEnumConstantArguments() { String source = "public enum AssignmentOperators {" + " EQ ( a = b )," + " TMSEQ ( a *= b )," + " DVDEQ ( a /= b )," + " MODEQ ( a %= b )," + " PLEQ ( a += b )," + " MNEQ ( a -= b )," + " LT2EQ ( a <<= b )," + " GT2EQ ( a >>= b )," + " GT3EQ ( a >>>= b )," + " ANDEQ ( a &= b )," + " XOREQ ( a ^= b )," + " OREQ ( a |= b )" + " }"; JavaClass cls = builder.addSource(new StringReader( source )).getClassByName( "AssignmentOperators" ); JavaField xoreq = cls.getFieldByName( "XOREQ" ); assertEquals( 1, xoreq.getEnumConstantArguments().size() ); assertEquals( "a ^= b", xoreq.getEnumConstantArguments().get(0).getParameterValue() ); } public void testIncrementAndDecrement() { String source = "public enum Expression {" + " POSTINC ( a++ )," + " POSTDEC ( a-- )," + " PREINC ( ++a )," + " PREDEC ( --a )" + " }"; JavaClass cls = builder.addSource(new StringReader( source )).getClassByName( "Expression" ); JavaField postInc = cls.getFieldByName( "POSTINC" ); assertEquals( 1, postInc.getEnumConstantArguments().size() ); assertEquals( "a++", postInc.getEnumConstantArguments().get( 0 ).getParameterValue() ); } // for QDOX-230 public void testInterfaceAnnotations() { String source = "@RemoteServiceRelativePath(\"greetings\")\r\n" + "public interface GreetingService extends RemoteService {\r\n" + " String greetServer(String name) throws IllegalArgumentException;\r\n" + "}"; builder.addSource(new StringReader( source )); JavaClass cls = builder.getClassByName( "GreetingService" ); assertEquals( 1, cls.getAnnotations().size() ); } // for QDOX-243 public void testReadsGenericsInGenericType() { final String sourceCode = "" + "package foo;\n" + "public static class DummyOne {\n" + " public static java.util.list, String>> crazyType() { return null; }\n" + "}\n"; builder.addSource( new java.io.StringReader( sourceCode ) ); JavaClass qDoxClass = builder.getClassByName( "foo.DummyOne" ); JavaMethod qDoxMethod = qDoxClass.getMethodBySignature( "crazyType", null ); JavaParameterizedType returnType = (JavaParameterizedType) qDoxMethod.getReturnType(); assertEquals( "java.util.Map,java.lang.String>", returnType.getActualTypeArguments().get( 0 ).getGenericFullyQualifiedName() ); assertEquals( "java.util.Map,java.lang.String>", returnType.getActualTypeArguments().get( 0 ).getGenericCanonicalName() ); } // for QDOX-244 public void testReadsGenericTypeParameters() { final String sourceCode = "" + "package foo;\n" + "public static class DummyOne {\n" + " public static > T genericTypeParam(T x) { return null; }\n" + "}\n"; builder.addSource( new java.io.StringReader( sourceCode ) ); JavaClass qDoxClass = builder.getClassByName( "foo.DummyOne" ); JavaMethod qDoxMethod = qDoxClass.getMethods().get(0); JavaTypeVariable result = qDoxMethod.getTypeParameters().get( 0 ); assertEquals( ">", result.getGenericFullyQualifiedName() ); assertEquals( ">", result.getGenericCanonicalName() ); } // for QDOX-245 public void testReadsGenerifiedParameterTypes() { final String sourceCode = "" + "package foo;\n" + "public static class DummyOne {\n" + " public static String withGenerifiedParam(java.util.Collection> things) { return null; }\n" + "}\n"; builder.addSource(new java.io.StringReader(sourceCode)); JavaClass qDoxClass = builder.getClassByName("foo.DummyOne"); JavaMethod qDoxMethod = qDoxClass.getMethods().get(0); JavaType result = qDoxMethod.getParameterTypes(true).get( 0 ); assertEquals("java.util.Collection>", result.getGenericFullyQualifiedName()); assertEquals("java.util.Collection>", result.getGenericCanonicalName()); } // for QDOX-253 public void testConstructorHasAnnotation() { JavaProjectBuilder builder = new JavaProjectBuilder(); String source = "public class Foo { private String apiPath; public Foo(@Value(\"${api.path}\") String apiPath) {this.apiPath = apiPath}}"; JavaClass qDoxClass = builder.addSource( new StringReader( source ) ).getClassByName( "Foo" ); assertEquals( 1, qDoxClass.getConstructors().size() ); JavaConstructor qDoxConstructor = qDoxClass.getConstructors().get( 0 ); assertEquals( 1, qDoxConstructor.getParameters().size() ); JavaParameter qDoxParameter = qDoxConstructor.getParameters().get( 0 ); assertEquals( "apiPath", qDoxParameter.getName() ); assertEquals( qDoxConstructor, qDoxParameter.getExecutable() ); } // for QDOX-255 public void testPackageAnnotation() { String source = "@Anot\r\n" + "package net.jcs.jboilerdowntest;\r\n" + "import net.jcs.annotation.Anot;"; JavaProjectBuilder builder = new JavaProjectBuilder(); JavaPackage pckg = builder.addSource( new StringReader( source) ).getPackage(); assertEquals( "net.jcs.jboilerdowntest", pckg.getName() ); assertEquals( 1, pckg.getAnnotations().size() ); } public void testCanonicalName() { String source = "package com.foo;\b" + "public class Outer {\n" + "public class Inner {\n" + "public class Core {}\n" + "}\n" + "}\n"; JavaClass cls = builder.addSource( new StringReader( source ) ).getClasses().get( 0 ); assertEquals( "com.foo.Outer", cls.getFullyQualifiedName() ); assertEquals( "com.foo.Outer", cls.getCanonicalName() ); cls = cls.getNestedClassByName( "Inner" ); assertEquals( "com.foo.Outer$Inner", cls.getBinaryName() ); assertEquals( "com.foo.Outer.Inner", cls.getFullyQualifiedName() ); assertEquals( "com.foo.Outer.Inner", cls.getCanonicalName() ); cls = cls.getNestedClassByName( "Core" ); assertEquals( "com.foo.Outer$Inner$Core", cls.getBinaryName() ); assertEquals( "com.foo.Outer.Inner.Core", cls.getFullyQualifiedName() ); assertEquals( "com.foo.Outer.Inner.Core", cls.getCanonicalName() ); } public void testEnumConstantMethods() { String source = "public enum MethodLocationOfEnumMethod\n" + "{\n" + " A()\n" + " {\n" + " @Override\n" + " private void method()\n" + " {\n" + " };\n" + " };\n" + " public abstract void method();\n" + " private void test()\n" + " {\n" + " };\n" + " \n" + " String name = \"x\";" + "}"; builder.addSource( new StringReader( source ) ); JavaClass cls = builder.getClassByName( "MethodLocationOfEnumMethod" ); assertEquals( 2, cls.getMethods().size() ); assertEquals( "method", cls.getMethods().get( 0 ).getName() ); assertEquals( true, cls.getMethods().get( 0 ).isAbstract() ); assertEquals( "test", cls.getMethods().get( 1 ).getName() ); } // QDOX-240 public void testComplexEnum() { String source = "import java.util.HashMap;\r\n" + "\r\n" + "public enum MyEnum {\r\n" + " MAP(new HashMap()); // Parser throws java.util.EmptyStackException\r\n" + " \r\n" + " public final Object defaultValue;\r\n" + " \r\n" + " private MyEnum(Object defaultValue) {\r\n" + " this.defaultValue = defaultValue;\r\n" + " }\r\n" + "}"; builder.addSource( new StringReader( source ) ); } public void testFQNField() { String source = "import java.text.SimpleDateFormat;\r\n" + "public class Car {\r\n" + " private java.text.SimpleDateFormat format;\r\n" + "}"; JavaProjectBuilder builder = new JavaProjectBuilder(); builder.addSource(new StringReader( source )); JavaField field = builder.getClassByName("Car").getFieldByName("format"); assertEquals( "java.text.SimpleDateFormat", field.getType().getFullyQualifiedName()); } // Github #12 public void testSamePackage() { String source = "package com.fg.rtdoc.test;\n" + "public class Test extends Extend implements Iface {}"; String iface = "package com.fg.rtdoc.test;\n" + "public interface Iface {}"; JavaProjectBuilder builder = new JavaProjectBuilder(); builder.addSource(new StringReader( iface )); JavaClass clz = builder.addSource(new StringReader( source )).getClassByName( "Test" ); assertEquals( "com.fg.rtdoc.test.Iface", clz.getInterfaces().get(0).getFullyQualifiedName() ); } // Github #16 public void testBeanProperties() { String zothParent = "public class ZothParent {\n" + " private String name;\n" + " public String getName() {\n" + " return name;\n" + " }\n" + " public void setName(String name) {\n" + " this.name = name;\n" + " }\n" + "}"; String zothChild = "public class ZothChild // extends ZothParent\n" + "{\n" + " private int age;\n" + " public int getAge() {\n" + " return age;\n" + " }\n" + " public void setAge(int age) {\n" + " this.age = age;\n" + " }\n" + "}"; JavaProjectBuilder builder = new JavaProjectBuilder(); builder.addSource(new StringReader( zothParent )); JavaClass zothClass = builder.addSource(new StringReader( zothChild )).getClassByName( "ZothChild" ); assertEquals( "java.lang.Object", zothClass.getSuperClass().getBinaryName()); assertEquals( 2, zothClass.getBeanProperties( true ).size() ); } // Github #31 public void testParseEnumWithConstructor() throws Exception { String source = "public enum SomeEnum {\n" + " VALUE1(\"hello\", 1, new String[]{\"hello\", \"world\"});\n" + " SomeEnum(String string, int integer, String[] stringArray) {\n" + " }\r\n" + "}"; builder.setDebugParser( true ); builder.addSource( new StringReader( source ) ); } // Github #39 public void testInnerClassInterfaces() throws Exception { String sourceA = "public class A implements Itf1 {\n" + " class B implements Itf2 {}\n" + "}"; String sourceItf1 = "interface Itf1 {}"; String sourceItf2 = "interface Itf2 {}"; builder.addSource( new StringReader( sourceItf1 ) ); builder.addSource( new StringReader( sourceItf2 ) ); builder.addSource( new StringReader( sourceA ) ); JavaClass classA = builder.getClassByName( "A$B" ); assertTrue( classA.getImplements().equals( Arrays.asList( builder.getClassByName( "Itf2" ) ) ) ); } public void testDeclarationSignatureWithGenerics() { String source = "import java.util.List;" + "public interface Test {" + " public List findById(java.lang.Long id);" + "}"; String model = "package com.amaral.model;" + "public class EntityModel {}"; JavaProjectBuilder builder = new JavaProjectBuilder(); builder.addSource(new StringReader( source )); builder.addSource(new StringReader( model )); JavaMethod findById = builder.getClassByName( "Test" ).getMethods().get(0); assertEquals( "public java.util.List findById(java.lang.Long id)", findById.getDeclarationSignature( true ) ); } public void testOneLineJavadoc() { String source = "package foo.bar;\n" + "/***/\n" + "public class MyClass{\n" + "} "; builder.addSource( new StringReader( source ) ); } public void testMethodReferences() { String source = "public enum AmazonClients {\n" + " ECS(AmazonECSClient::new),\n" + " ECR(AmazonECRClient::new);\n" + "}"; builder.addSource( new StringReader( source ) ); } public void testAnonymousEnumConstructor() { String source = "package parent;\n" + "public enum MyEnum {\n" + " VALUE(new Runnable() {\n" + " @Override\n" + " public void run() { }\n" + " });\n" + " MyEnum(Runnable function) { }\n" + "}"; builder.addSource( new StringReader( source ) ); } public void testModuleWithComment() { String source = "/**\r\n" + " * TODO javadoc\r\n" + " */\r\n" + "module maven.moduleinfo.comments {\r\n" + " // this comment fails the build\r\n" + " exports maven.reproducer.moduleinfo;\r\n" + "}\r\n"; builder.addSource( new StringReader( source ) ); } public void testLineNumbers() { String source = "package foo.bar;\n" + "/** some javadoc */\n" + "public \n" + "class MyClass {\n" + "public static final String CONSTANT1 = \"default value\";\n" + "public static final String CONSTANT2 = \"default value\";}\n" + "interface \n" + "MyInterface {\n" + "public void method1( String aString );\n" + "@Override\n" + "void method2( String aString );}\n" + "public \n" + "enum MyEnum{}\n" + "@interface \n" + "MyAnnoInterface{}\n" + "interface NewLineInterface \n" + "{}"; // builder.setDebugLexer( true ); builder.setDebugParser( true ); JavaSource jSource = builder.addSource( new StringReader( source ) ); assertEquals( 3, jSource.getClassByName( "MyClass" ).getLineNumber() ); assertEquals( 5, jSource.getClassByName( "MyClass" ).getFieldByName( "CONSTANT1" ).getLineNumber() ); assertEquals( 6, jSource.getClassByName( "MyClass" ).getFieldByName( "CONSTANT2" ).getLineNumber() ); assertEquals( 7, jSource.getClassByName( "MyInterface" ).getLineNumber() ); assertEquals( 9, jSource.getClassByName( "MyInterface" ).getMethods().get( 0 ).getLineNumber() ); assertEquals( 10, jSource.getClassByName( "MyInterface" ).getMethods().get( 1 ).getAnnotations().get( 0 ).getLineNumber() ); assertEquals( 11, jSource.getClassByName( "MyInterface" ).getMethods().get( 1 ).getLineNumber() ); assertEquals( 12, jSource.getClassByName( "MyEnum" ).getLineNumber() ); assertEquals( 14, jSource.getClassByName( "MyAnnoInterface" ).getLineNumber() ); assertEquals( 16, jSource.getClassByName( "NewLineInterface" ).getLineNumber() ); } public void testSetDebugLexer() { ClassLibraryBuilder classLibraryBuilder = mock( ClassLibraryBuilder.class ); boolean debugLexer = true; builder = new JavaProjectBuilder( classLibraryBuilder ); JavaProjectBuilder projectBuilder = builder.setDebugLexer( debugLexer ); verify( classLibraryBuilder ).setDebugLexer( debugLexer ); assertSame( builder, projectBuilder ); } public void testSetDebugParser() { ClassLibraryBuilder classLibraryBuilder = mock( ClassLibraryBuilder.class ); boolean debugParser = true; builder = new JavaProjectBuilder( classLibraryBuilder ); JavaProjectBuilder projectBuilder = builder.setDebugParser( debugParser ); verify( classLibraryBuilder ).setDebugParser( debugParser ); assertSame( builder, projectBuilder ); } public void testSetEncoding() { ClassLibraryBuilder classLibraryBuilder = mock( ClassLibraryBuilder.class ); String encoding = "UTF-8"; builder = new JavaProjectBuilder( classLibraryBuilder ); JavaProjectBuilder projectBuilder = builder.setEncoding( encoding ); verify( classLibraryBuilder ).setEncoding( same( encoding ) ); assertSame( builder, projectBuilder ); } public void testSetErrorHandler() { ClassLibraryBuilder classLibraryBuilder = mock( ClassLibraryBuilder.class ); ErrorHandler errorHandler = mock( ErrorHandler.class ); builder = new JavaProjectBuilder( classLibraryBuilder ); JavaProjectBuilder projectBuilder = builder.setErrorHandler( errorHandler ); verify( classLibraryBuilder ).setErrorHander( same( errorHandler ) ); assertSame( builder, projectBuilder ); } public void testAddClassLoader() { ClassLibraryBuilder classLibraryBuilder = mock( ClassLibraryBuilder.class ); ClassLoader classLoader = mock( ClassLoader.class ); builder = new JavaProjectBuilder( classLibraryBuilder ); builder.addClassLoader( classLoader ); verify( classLibraryBuilder ).appendClassLoader( same( classLoader ) ); } public void testAddFileSource() throws Exception { ClassLibraryBuilder classLibraryBuilder = mock( ClassLibraryBuilder.class ); File file = mock( File.class ); JavaSource source = mock( JavaSource.class ); when( classLibraryBuilder.addSource( file ) ).thenReturn( source ); builder = new JavaProjectBuilder( classLibraryBuilder ); JavaSource addedSource = builder.addSource( file ); verify( classLibraryBuilder ).addSource( same( file ) ); assertSame( addedSource, source ); } public void testAddReaderSource() { ClassLibraryBuilder classLibraryBuilder = mock( ClassLibraryBuilder.class ); Reader reader = mock( Reader.class ); JavaSource source = mock( JavaSource.class ); when( classLibraryBuilder.addSource( reader ) ).thenReturn( source ); builder = new JavaProjectBuilder( classLibraryBuilder ); JavaSource addedSource = builder.addSource( reader ); verify( classLibraryBuilder ).addSource( same( reader ) ); assertSame( addedSource, source ); } public void testAddURLSource() throws Exception { ClassLibraryBuilder classLibraryBuilder = mock( ClassLibraryBuilder.class ); URL url = new URL( "http://localhost" ); JavaSource source = mock( JavaSource.class ); when( classLibraryBuilder.addSource( url ) ).thenReturn( source ); builder = new JavaProjectBuilder( classLibraryBuilder ); JavaSource addedSource = builder.addSource( url ); verify( classLibraryBuilder ).addSource( same( url ) ); assertSame( addedSource, source ); } public void testAddSourceFolder() { ClassLibraryBuilder classLibraryBuilder = mock( ClassLibraryBuilder.class ); File file = mock( File.class ); builder = new JavaProjectBuilder( classLibraryBuilder ); builder.addSourceFolder( file ); verify( classLibraryBuilder ).addSourceFolder( same( file ) ); } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/MethodsTest.java000066400000000000000000000045501325201777200256710ustar00rootroot00000000000000package com.thoughtworks.qdox; import java.io.StringReader; import junit.framework.TestCase; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.JavaSource; public class MethodsTest extends TestCase { private JavaProjectBuilder builder = new JavaProjectBuilder(); 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);" ); JavaClass standardType = javaMethod.getParameterByName( "param1" ).getJavaClass(); JavaClass arrayType = javaMethod.getParameterByName( "param2" ).getJavaClass(); JavaClass varArgsType = javaMethod.getParameterByName( "param3" ).getJavaClass(); 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 testSupportDefaultMethods() { JavaMethod javaMethod = buildMethod( "default String additionalStuff() { return \"\"; }" ); assertTrue( javaMethod.isDefault() ); } 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().get( 0 ); JavaMethod javaMethod = javaClass.getMethods().get( 0 ); return javaMethod; } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/TestMultipleLevelGenericInheritance.java000066400000000000000000000052531325201777200325210ustar00rootroot00000000000000package com.thoughtworks.qdox; import java.io.Reader; import java.io.StringReader; import java.util.List; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import com.thoughtworks.qdox.JavaProjectBuilder; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaType; public class TestMultipleLevelGenericInheritance { private JavaProjectBuilder builder; @Before public void setUp() { builder = createBuilder(); } @Test public void testMethodParametersOfIheritedMethodsAreCorrect() { final JavaClass clazz = builder.getClassByName( "HelloService" ); final List methods = clazz.getMethods( true ); JavaMethod method; method = methods.get( 0 ); Assert.assertEquals( "get", method.getName() ); method = methods.get( 1 ); Assert.assertEquals( "set", method.getName() ); assertFirstParameterIs( "Dto", method ); method = methods.get( 2 ); Assert.assertEquals( "validate", method.getName() ); assertFirstParameterIs( "Dto", method ); } private void assertFirstParameterIs( final String type, final JavaMethod method ) { List parameterTypes; parameterTypes = method.getParameterTypes( true ); Assert.assertEquals( 1, parameterTypes.size() ); Assert.assertEquals( type, parameterTypes.get( 0 ).getCanonicalName() ); } private JavaProjectBuilder createBuilder() { final JavaProjectBuilder builder = new JavaProjectBuilder(); builder.addSource( getDtoClass() ); builder.addSource( getGetterClass() ); builder.addSource( getSetterClass() ); builder.addSource( getValidatorClass() ); builder.addSource( getHelloService() ); return builder; } private Reader getDtoClass() { return new StringReader( "public class Dto {}" ); } private Reader getGetterClass() { return new StringReader( "public interface Getter { T get(); }" ); } private Reader getValidatorClass() { return new StringReader( "public interface Validator { void validate(T obj); }" ); } private Reader getSetterClass() { return new StringReader( "public interface Setter extends Validator { void set(T obj); }" ); } private Reader getHelloService() { return new StringReader( "public interface HelloService extends Getter, Setter {}" ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/builder/000077500000000000000000000000001325201777200242055ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/builder/impl/000077500000000000000000000000001325201777200251465ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/builder/impl/EvaluatingVisitorTest.java000066400000000000000000001451551325201777200323430ustar00rootroot00000000000000package com.thoughtworks.qdox.builder.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.Collections; import java.util.List; import org.junit.Test; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.expression.Add; import com.thoughtworks.qdox.model.expression.And; import com.thoughtworks.qdox.model.expression.AnnotationValue; import com.thoughtworks.qdox.model.expression.AnnotationValueList; import com.thoughtworks.qdox.model.expression.Cast; import com.thoughtworks.qdox.model.expression.Divide; import com.thoughtworks.qdox.model.expression.Equals; import com.thoughtworks.qdox.model.expression.ExclusiveOr; import com.thoughtworks.qdox.model.expression.FieldRef; import com.thoughtworks.qdox.model.expression.GreaterEquals; import com.thoughtworks.qdox.model.expression.GreaterThan; import com.thoughtworks.qdox.model.expression.LessEquals; import com.thoughtworks.qdox.model.expression.LessThan; import com.thoughtworks.qdox.model.expression.LogicalAnd; import com.thoughtworks.qdox.model.expression.LogicalNot; import com.thoughtworks.qdox.model.expression.LogicalOr; import com.thoughtworks.qdox.model.expression.MinusSign; import com.thoughtworks.qdox.model.expression.Multiply; import com.thoughtworks.qdox.model.expression.Not; import com.thoughtworks.qdox.model.expression.NotEquals; import com.thoughtworks.qdox.model.expression.Or; import com.thoughtworks.qdox.model.expression.ParenExpression; import com.thoughtworks.qdox.model.expression.PlusSign; import com.thoughtworks.qdox.model.expression.Query; import com.thoughtworks.qdox.model.expression.Remainder; import com.thoughtworks.qdox.model.expression.ShiftLeft; import com.thoughtworks.qdox.model.expression.ShiftRight; import com.thoughtworks.qdox.model.expression.Subtract; import com.thoughtworks.qdox.model.expression.TypeRef; import com.thoughtworks.qdox.model.expression.UnsignedShiftRight; public class EvaluatingVisitorTest { private EvaluatingVisitor visitor = new EvaluatingVisitorStub(); @Test public void testUnaryNumericResultTypeInteger() { assertEquals( Integer.class, EvaluatingVisitor.unaryNumericResultType( 0 ) ); assertEquals( Integer.class, EvaluatingVisitor.unaryNumericResultType( (byte) 0 ) ); assertEquals( Integer.class, EvaluatingVisitor.unaryNumericResultType( (short) 0 ) ); assertEquals( Integer.class, EvaluatingVisitor.unaryNumericResultType( (char) 0 ) ); } @Test public void testUnaryNumericResultTypeLong() { assertEquals( Long.class, EvaluatingVisitor.unaryNumericResultType( 0L ) ); } @Test public void testUnaryNumericResultTypeVoid() { assertEquals( void.class, EvaluatingVisitor.unaryNumericResultType( new Object() ) ); assertEquals( void.class, EvaluatingVisitor.unaryNumericResultType( (double) 0 ) ); assertEquals( void.class, EvaluatingVisitor.unaryNumericResultType( (float) 0 ) ); assertEquals( void.class, EvaluatingVisitor.unaryNumericResultType( null ) ); } @Test public void testUnaryResultTypeInteger() { assertEquals( Integer.class, EvaluatingVisitor.unaryResultType( 0 ) ); assertEquals( Integer.class, EvaluatingVisitor.unaryResultType( (byte) 0 ) ); assertEquals( Integer.class, EvaluatingVisitor.unaryResultType( (short) 0 ) ); assertEquals( Integer.class, EvaluatingVisitor.unaryResultType( (char) 0 ) ); } @Test public void testUnaryResultTypeLong() { assertEquals( Long.class, EvaluatingVisitor.unaryResultType( 0L ) ); } @Test public void testUnaryResultTypeDouble() { assertEquals( Double.class, EvaluatingVisitor.unaryResultType( (double) 0 ) ); } @Test public void testUnaryResultTypeFloat() { assertEquals( Float.class, EvaluatingVisitor.unaryResultType( (float) 0 ) ); } @Test public void testUnaryResultTypeVoid() { assertEquals( void.class, EvaluatingVisitor.unaryResultType( new Object() ) ); assertEquals( void.class, EvaluatingVisitor.unaryResultType( null ) ); } @Test public void testNumericResultTypeLong() { assertEquals( Long.class, EvaluatingVisitor.numericResultType( (long) 0, (long) 0 ) ); assertEquals( Long.class, EvaluatingVisitor.numericResultType( (int) 0, (long) 0 ) ); assertEquals( Long.class, EvaluatingVisitor.numericResultType( (long) 0, (int) 0 ) ); } @Test public void testNumericResultTypeInteger() { assertEquals( Integer.class, EvaluatingVisitor.numericResultType( (int) 0, (int) 0 ) ); assertEquals( Integer.class, EvaluatingVisitor.numericResultType( (short) 0, (int) 0 ) ); assertEquals( Integer.class, EvaluatingVisitor.numericResultType( (int) 0, (short) 0 ) ); } @Test public void testNumericResultTypeVoid() { assertEquals( void.class, EvaluatingVisitor.numericResultType( (double) 0, (double) 0 ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( (float) 0, (double) 0 ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( (double) 0, (float) 0 ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( (float) 0, (float) 0 ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( (double) 0, new Object() ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( (float) 0, new Object() ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( (long) 0, new Object() ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( (int) 0, new Object() ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( new Object(), (double) 0 ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( new Object(), (float) 0 ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( new Object(), (long) 0 ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( new Object(), (int) 0 ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( (double) 0, null ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( (float) 0, null ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( (long) 0, null ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( (int) 0, null ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( null, (double) 0 ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( null, (float) 0 ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( null, (long) 0 ) ); assertEquals( void.class, EvaluatingVisitor.numericResultType( null, (int) 0 ) ); } @Test public void testResultTypeDouble() { // If either operand is of type double, the other is converted to double. assertEquals( Double.class, EvaluatingVisitor.resultType( (double) 0, (double) 0 ) ); assertEquals( Double.class, EvaluatingVisitor.resultType( (float) 0, (double) 0 ) ); assertEquals( Double.class, EvaluatingVisitor.resultType( (int) 0, (double) 0 ) ); assertEquals( Double.class, EvaluatingVisitor.resultType( (double) 0, (float) 0 ) ); assertEquals( Double.class, EvaluatingVisitor.resultType( (double) 0, (int) 0 ) ); } @Test public void testResultTypeFloat() { // Otherwise, if either operand is of type float, the other is converted to float. assertEquals( Float.class, EvaluatingVisitor.resultType( (float) 0, (float) 0 ) ); assertEquals( Float.class, EvaluatingVisitor.resultType( (int) 0, (float) 0 ) ); assertEquals( Float.class, EvaluatingVisitor.resultType( (float) 0, (int) 0 ) ); } @Test public void testResultTypeLong() { // Otherwise, if either operand is of type long, the other is converted to long. assertEquals( Long.class, EvaluatingVisitor.resultType( (long) 0, (long) 0 ) ); assertEquals( Long.class, EvaluatingVisitor.resultType( (int) 0, (long) 0 ) ); assertEquals( Long.class, EvaluatingVisitor.resultType( (long) 0, (int) 0 ) ); } @Test public void testResultTypeInteger() { // Otherwise, if either operand is of type long, the other is converted to long. assertEquals( Integer.class, EvaluatingVisitor.resultType( (int) 0, (int) 0 ) ); assertEquals( Integer.class, EvaluatingVisitor.resultType( (short) 0, (int) 0 ) ); assertEquals( Integer.class, EvaluatingVisitor.resultType( (int) 0, (short) 0 ) ); } @Test public void testResultTypeVoid() { // Otherwise, if either operand is of type long, the other is converted to long. assertEquals( void.class, EvaluatingVisitor.resultType( (double) 0, new Object() ) ); assertEquals( void.class, EvaluatingVisitor.resultType( (float) 0, new Object() ) ); assertEquals( void.class, EvaluatingVisitor.resultType( (long) 0, new Object() ) ); assertEquals( void.class, EvaluatingVisitor.resultType( (int) 0, new Object() ) ); assertEquals( void.class, EvaluatingVisitor.resultType( new Object(), (double) 0 ) ); assertEquals( void.class, EvaluatingVisitor.resultType( new Object(), (float) 0 ) ); assertEquals( void.class, EvaluatingVisitor.resultType( new Object(), (long) 0 ) ); assertEquals( void.class, EvaluatingVisitor.resultType( new Object(), (int) 0 ) ); assertEquals( void.class, EvaluatingVisitor.resultType( (double) 0, null ) ); assertEquals( void.class, EvaluatingVisitor.resultType( (float) 0, null ) ); assertEquals( void.class, EvaluatingVisitor.resultType( (long) 0, null ) ); assertEquals( void.class, EvaluatingVisitor.resultType( (int) 0, null ) ); assertEquals( void.class, EvaluatingVisitor.resultType( null, (double) 0 ) ); assertEquals( void.class, EvaluatingVisitor.resultType( null, (float) 0 ) ); assertEquals( void.class, EvaluatingVisitor.resultType( null, (long) 0 ) ); assertEquals( void.class, EvaluatingVisitor.resultType( null, (int) 0 ) ); } @Test public void testVisitAdd() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Doubles when( lhs.accept( any( EvaluatingVisitor.class ) ) ).thenReturn( 7.0D ); when( rhs.accept( any( EvaluatingVisitor.class ) ) ).thenReturn( 2.0D ); assertEquals( 7.0D + 2.0D, visitor.visit( new Add( lhs, rhs ) ) ); // Floats when( lhs.accept( any( EvaluatingVisitor.class ) ) ).thenReturn( 7.0F ); when( rhs.accept( any( EvaluatingVisitor.class ) ) ).thenReturn( 2.0F ); assertEquals( 7.0F + 2.0F, visitor.visit( new Add( lhs, rhs ) ) ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L + 2L, visitor.visit( new Add( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 + 2, visitor.visit( new Add( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new Add( lhs, rhs ) ); fail( "Additive operations (+ and -) can only be performed on numeric types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitAnd() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L & 2L, visitor.visit( new And( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 & 2, visitor.visit( new And( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new And( lhs, rhs ) ); fail( "The and(&) operator can only be performed on integral types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitAnnotation() { try{ JavaAnnotation annotation = mock(JavaAnnotation.class); visitor.visit( annotation ); fail( "Visiting an annotation is not supported and should throw an UnsupportedOperationException" ); } catch (UnsupportedOperationException e) { } } @Test public void testVisitAnnotationValueList() { { List emptyList = Collections.emptyList(); List visitedResult = visitor.visit( new AnnotationValueList( emptyList ) ); assertEquals( 0, visitedResult.size() ); } { AnnotationValue annoVal = mock( AnnotationValue.class ); Object singleResult = new Object(); when( annoVal.accept( visitor ) ).thenReturn( singleResult ); List visitedResult = visitor.visit( new AnnotationValueList( Collections.singletonList( annoVal ) ) ); assertEquals( 1, visitedResult.size() ); assertSame( singleResult, visitedResult.get( 0 ) ); } } @Test public void testVisitCast() throws Exception { AnnotationValue value = mock( AnnotationValue.class ); when( value.accept( visitor ) ).thenReturn( 7 ); JavaClass primitiveClass = mock( JavaClass.class ); when( primitiveClass.isPrimitive() ).thenReturn( true ); when( primitiveClass.getFullyQualifiedName() ).thenReturn( "byte" ); assertEquals( (byte) 7, visitor.visit( new Cast( primitiveClass, value ) ) ); when( primitiveClass.getFullyQualifiedName() ).thenReturn( "char" ); assertEquals( (char) 7, visitor.visit( new Cast( primitiveClass, value ) ) ); when( primitiveClass.getFullyQualifiedName() ).thenReturn( "short" ); assertEquals( (short) 7, visitor.visit( new Cast( primitiveClass, value ) ) ); when( primitiveClass.getFullyQualifiedName() ).thenReturn( "int" ); assertEquals( (int) 7, visitor.visit( new Cast( primitiveClass, value ) ) ); when( primitiveClass.getFullyQualifiedName() ).thenReturn( "long" ); assertEquals( (long) 7, visitor.visit( new Cast( primitiveClass, value ) ) ); when( primitiveClass.getFullyQualifiedName() ).thenReturn( "float" ); assertEquals( (float) 7, visitor.visit( new Cast( primitiveClass, value ) ) ); when( primitiveClass.getFullyQualifiedName() ).thenReturn( "double" ); assertEquals( (double) 7, visitor.visit( new Cast( primitiveClass, value ) ) ); try { when( primitiveClass.getFullyQualifiedName() ).thenReturn( "void" ); visitor.visit( new Cast( primitiveClass, value ) ); fail( "Although 'void' is a primitive, you can't cast to it" ); } catch ( IllegalArgumentException iae ) { } JavaClass stringClass = mock( JavaClass.class ); when( stringClass.getFullyQualifiedName() ).thenReturn( "java.lang.String" ); when( value.accept( visitor ) ).thenReturn( "hello world" ); assertEquals( (String) "hello world", visitor.visit( new Cast( stringClass, value ) ) ); JavaClass listClass = mock( JavaClass.class ); when( listClass.getFullyQualifiedName() ).thenReturn( "java.util.List" ); Object list = Collections.EMPTY_LIST; when( value.accept( visitor ) ).thenReturn( list ); assertEquals( (List) list, visitor.visit( new Cast( listClass, value ) ) ); } @Test public void testVisitDivide() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Doubles when( lhs.accept( visitor ) ).thenReturn( 7.0D ); when( rhs.accept( visitor ) ).thenReturn( 2.0D ); assertEquals( 7.0D / 2.0D, visitor.visit( new Divide( lhs, rhs ) ) ); // Floats when( lhs.accept( visitor ) ).thenReturn( 7.0F ); when( rhs.accept( visitor ) ).thenReturn( 2.0F ); assertEquals( 7.0F / 2.0F, visitor.visit( new Divide( lhs, rhs ) ) ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L / 2L, visitor.visit( new Divide( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 / 2, visitor.visit( new Divide( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new Divide( lhs, rhs ) ); fail( "The divide(/) operator can only be performed on numeric types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitEquals() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Doubles when( lhs.accept( visitor ) ).thenReturn( 7.0D ); when( rhs.accept( visitor ) ).thenReturn( 2.0D ); assertEquals( 7.0D == 2.0D, visitor.visit( new Equals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7.0D ); assertEquals( 7.0D == 7.0D, visitor.visit( new Equals( lhs, rhs ) ) ); // Floats when( lhs.accept( visitor ) ).thenReturn( 7.0F ); when( rhs.accept( visitor ) ).thenReturn( 2.0F ); assertEquals( 7.0F == 2.0F, visitor.visit( new Equals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7.0F ); assertEquals( 7.0F == 7.0F, visitor.visit( new Equals( lhs, rhs ) ) ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L == 2L, visitor.visit( new Equals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7L ); assertEquals( 7L == 7L, visitor.visit( new Equals( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 == 2, visitor.visit( new Equals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7 ); assertEquals( 7 == 7, visitor.visit( new Equals( lhs, rhs ) ) ); // Objects Object object1 = new Object(); Object object2 = new Object(); when( lhs.accept( visitor ) ).thenReturn( object1 ); when( rhs.accept( visitor ) ).thenReturn( object2 ); assertEquals( object1 == object2, visitor.visit( new Equals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( object1 ); assertEquals( object1 == object1, visitor.visit( new Equals( lhs, rhs ) ) ); } @Test public void testVisitExlusiveOr() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L ^ 2L, visitor.visit( new ExclusiveOr( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 ^ 2, visitor.visit( new ExclusiveOr( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new ExclusiveOr( lhs, rhs ) ); fail( "The exclusive-or(^) operator can only be performed on integral types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitFieldRef() { FieldRef ref = new FieldRef( "fieldname" ); try { visitor.visit( ref ); fail( "fieldname should be a unresolvable field" ); } catch( IllegalArgumentException e ) { } JavaField nonStaticNonFinalfield = mock( JavaField.class ); JavaClass declaringClass = mock( JavaClass.class ); when( declaringClass.getFieldByName( "fieldname" ) ).thenReturn( nonStaticNonFinalfield ); JavaClass annotatedClass = mock( JavaClass.class ); ref.setDeclaringClass( declaringClass ); try { visitor.visit( ref ); fail( "fieldname should fail, because it's not-static and non-final" ); } catch( IllegalArgumentException e) { } JavaField staticFinalfield = mock( JavaField.class ); when( staticFinalfield.isStatic() ).thenReturn( true ); when( staticFinalfield.isFinal() ).thenReturn( true ); when( declaringClass.getFieldByName( "fieldname" ) ).thenReturn( staticFinalfield ); ref = new FieldRef( "fieldname" ); ref.setDeclaringClass( declaringClass ); assertSame( EvaluatingVisitorStub.fieldReferenceValue, visitor.visit( ref ) ); ref = new FieldRef( "fieldname" ); ref.setDeclaringClass( declaringClass ); assertSame( EvaluatingVisitorStub.fieldReferenceValue, visitor.visit( ref ) ); ref = new FieldRef( "a.B.fieldname" ); ref.setDeclaringClass( null ); JavaClass b = mock( JavaClass.class ); when( b.getFieldByName( "fieldname" ) ).thenReturn( staticFinalfield ); ClassLibrary classLibrary = mock( ClassLibrary.class ); when( classLibrary.hasClassReference( "a.B" ) ).thenReturn( true ); when( classLibrary.getJavaClass( "a.B" ) ).thenReturn( b ); ref.setClassLibrary( classLibrary ); assertSame( EvaluatingVisitorStub.fieldReferenceValue, visitor.visit( ref ) ); } @Test public void testVisitGreaterEquals() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Doubles when( lhs.accept( visitor ) ).thenReturn( 7.0D ); when( rhs.accept( visitor ) ).thenReturn( 2.0D ); assertEquals( 7.0D >= 2.0D, visitor.visit( new GreaterEquals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7.0D ); assertEquals( 7.0D >= 7.0D, visitor.visit( new GreaterEquals( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2.0D ); assertEquals( 2.0D >= 7.0D, visitor.visit( new GreaterEquals( lhs, rhs ) ) ); // Floats when( lhs.accept( visitor ) ).thenReturn( 7.0F ); when( rhs.accept( visitor ) ).thenReturn( 2.0F ); assertEquals( 7.0F >= 2.0F, visitor.visit( new GreaterEquals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7.0F ); assertEquals( 7.0F >= 7.0F, visitor.visit( new GreaterEquals( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2.0F ); assertEquals( 2.0F >= 7.0F, visitor.visit( new GreaterEquals( lhs, rhs ) ) ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L >= 2L, visitor.visit( new GreaterEquals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7L ); assertEquals( 7L >= 7L, visitor.visit( new GreaterEquals( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 2L >= 7L, visitor.visit( new GreaterEquals( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 >= 2, visitor.visit( new GreaterEquals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7 ); assertEquals( 7 >=7, visitor.visit( new GreaterEquals( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 2 >= 7, visitor.visit( new GreaterEquals( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new GreaterEquals( lhs, rhs ) ); fail( "The greater-equals(>=) operator can only be performed on numeric types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitGreaterThan() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Doubles when( lhs.accept( visitor ) ).thenReturn( 7.0D ); when( rhs.accept( visitor ) ).thenReturn( 2.0D ); assertEquals( 7.0D > 2.0D, visitor.visit( new GreaterThan( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7.0D ); assertEquals( 7.0D > 7.0D, visitor.visit( new GreaterThan( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2.0D ); assertEquals( 2.0D > 7.0D, visitor.visit( new GreaterThan( lhs, rhs ) ) ); // Floats when( lhs.accept( visitor ) ).thenReturn( 7.0F ); when( rhs.accept( visitor ) ).thenReturn( 2.0F ); assertEquals( 7.0F > 2.0F, visitor.visit( new GreaterThan( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7.0F ); assertEquals( 7.0F > 7.0F, visitor.visit( new GreaterThan( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2.0F ); assertEquals( 2.0F > 7.0F, visitor.visit( new GreaterThan( lhs, rhs ) ) ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L > 2L, visitor.visit( new GreaterThan( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7L ); assertEquals( 7L > 7L, visitor.visit( new GreaterThan( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 2L > 7L, visitor.visit( new GreaterThan( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 > 2, visitor.visit( new GreaterThan( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7 ); assertEquals( 7 > 7, visitor.visit( new GreaterThan( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 2 > 7, visitor.visit( new GreaterThan( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new GreaterThan( lhs, rhs ) ); fail( "The greater-than(>) operator can only be performed on numeric types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitLessEquals() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Doubles when( lhs.accept( visitor ) ).thenReturn( 7.0D ); when( rhs.accept( visitor ) ).thenReturn( 2.0D ); assertEquals( 7.0D <= 2.0D, visitor.visit( new LessEquals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7.0D ); assertEquals( 7.0D <= 7.0D, visitor.visit( new LessEquals( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2.0D ); assertEquals( 2.0D <= 7.0D, visitor.visit( new LessEquals( lhs, rhs ) ) ); // Floats when( lhs.accept( visitor ) ).thenReturn( 7.0F ); when( rhs.accept( visitor ) ).thenReturn( 2.0F ); assertEquals( 7.0F <= 2.0F, visitor.visit( new LessEquals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7.0F ); assertEquals( 7.0F <= 7.0F, visitor.visit( new LessEquals( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2.0F ); assertEquals( 2.0F <= 7.0F, visitor.visit( new LessEquals( lhs, rhs ) ) ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L <= 2L, visitor.visit( new LessEquals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7L ); assertEquals( 7L <= 7L, visitor.visit( new LessEquals( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 2L <= 7L, visitor.visit( new LessEquals( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 <= 2, visitor.visit( new LessEquals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7 ); assertEquals( 7 <= 7, visitor.visit( new LessEquals( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 2 <= 7, visitor.visit( new LessEquals( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new LessEquals( lhs, rhs ) ); fail( "The less-equals(<=) operator can only be performed on numeric types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitLessThan() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Doubles when( lhs.accept( visitor ) ).thenReturn( 7.0D ); when( rhs.accept( visitor ) ).thenReturn( 2.0D ); assertEquals( 7.0D < 2.0D, visitor.visit( new LessThan( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7.0D ); assertEquals( 7.0D < 7.0D, visitor.visit( new LessThan( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2.0D ); assertEquals( 2.0D < 7.0D, visitor.visit( new LessThan( lhs, rhs ) ) ); // Floats when( lhs.accept( visitor ) ).thenReturn( 7.0F ); when( rhs.accept( visitor ) ).thenReturn( 2.0F ); assertEquals( 7.0F < 2.0F, visitor.visit( new LessThan( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7.0F ); assertEquals( 7.0F < 7.0F, visitor.visit( new LessThan( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2.0F ); assertEquals( 2.0F < 7.0F, visitor.visit( new LessThan( lhs, rhs ) ) ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L < 2L, visitor.visit( new LessThan( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7L ); assertEquals( 7L < 7L, visitor.visit( new LessThan( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 2L < 7L, visitor.visit( new LessThan( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 < 2, visitor.visit( new LessThan( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7 ); assertEquals( 7 < 7, visitor.visit( new LessThan( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 2 < 7, visitor.visit( new LessThan( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new LessThan( lhs, rhs ) ); fail( "The less-than(<) operator can only be performed on numeric types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void visitLogicalAnd() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.accept( visitor ) ).thenReturn( true ); when( rhs.accept( visitor ) ).thenReturn( true ); assertEquals( true && true, visitor.visit( new LogicalAnd( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( false ); when( rhs.accept( visitor ) ).thenReturn( false ); assertEquals( false && false, visitor.visit( new LogicalAnd( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new LogicalAnd( lhs, rhs ) ); fail( "The logical and(&&) operator can only be performed on booleans" ); } catch ( IllegalArgumentException iae ) { } } @Test public void visitLogicalNot() { AnnotationValue value = mock( AnnotationValue.class ); when( value.accept( visitor ) ).thenReturn( true ); assertEquals( !true, visitor.visit( new LogicalNot( value ) ) ); when( value.accept( visitor ) ).thenReturn( false ); assertEquals( !false, visitor.visit( new LogicalNot( value ) ) ); // Objects when( value.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new LogicalNot( value ) ); fail( "The logical not(!) operator can only be performed on booleans" ); } catch ( IllegalArgumentException iae ) { } } @Test public void visitLogicalOr() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.accept( visitor ) ).thenReturn( true ); when( rhs.accept( visitor ) ).thenReturn( true ); assertEquals( true || true, visitor.visit( new LogicalOr( lhs, rhs ) ) ); when( lhs.accept( visitor ) ).thenReturn( false ); when( rhs.accept( visitor ) ).thenReturn( false ); assertEquals( false || false, visitor.visit( new LogicalOr( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new LogicalOr( lhs, rhs ) ); fail( "The logical or(||) operator can only be performed on booleans" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitMinusSign() { AnnotationValue value = mock( AnnotationValue.class ); // Double when( value.accept( visitor ) ).thenReturn( 7.0D ); assertEquals( -7.0D, visitor.visit( new MinusSign( value ) ) ); // Float when( value.accept( visitor ) ).thenReturn( 7.0F ); assertEquals( -7.0F, visitor.visit( new MinusSign( value ) ) ); // Long when( value.accept( visitor ) ).thenReturn( 7L ); assertEquals( -7L, visitor.visit( new MinusSign( value ) ) ); // Integer when( value.accept( visitor ) ).thenReturn( 7 ); assertEquals( -7, visitor.visit( new MinusSign( value ) ) ); when( value.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new MinusSign( value ) ); fail( "The minus(-) sign operator can only be performed on numeric types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitMultiply() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Doubles when( lhs.accept( visitor ) ).thenReturn( 7.0D ); when( rhs.accept( visitor ) ).thenReturn( 2.0D ); assertEquals( 7.0D * 2.0D, visitor.visit( new Multiply( lhs, rhs ) ) ); // Floats when( lhs.accept( visitor ) ).thenReturn( 7.0F ); when( rhs.accept( visitor ) ).thenReturn( 2.0F ); assertEquals( 7.0F * 2.0F, visitor.visit( new Multiply( lhs, rhs ) ) ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L * 2L, visitor.visit( new Multiply( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 * 2, visitor.visit( new Multiply( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new Multiply( lhs, rhs ) ); fail( "The multiply(*) operator can only be performed on numeric types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitNot() { AnnotationValue value = mock( AnnotationValue.class ); // Longs when( value.accept( visitor ) ).thenReturn( 7L ); assertEquals( ~7L, visitor.visit( new Not( value ) ) ); // Integers when( value.accept( visitor ) ).thenReturn( 7 ); assertEquals( ~7, visitor.visit( new Not( value) ) ); // Objects when( value.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new Not( value ) ); fail( "The not(~) operator can only be performed on integral types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitNotEquals() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Doubles when( lhs.accept( visitor ) ).thenReturn( 7.0D ); when( rhs.accept( visitor ) ).thenReturn( 2.0D ); assertEquals( 7.0D != 2.0D, visitor.visit( new NotEquals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7.0D ); assertEquals( 7.0D != 7.0D, visitor.visit( new NotEquals( lhs, rhs ) ) ); // Floats when( lhs.accept( visitor ) ).thenReturn( 7.0F ); when( rhs.accept( visitor ) ).thenReturn( 2.0F ); assertEquals( 7.0F != 2.0F, visitor.visit( new NotEquals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7.0F ); assertEquals( 7.0F != 7.0F, visitor.visit( new NotEquals( lhs, rhs ) ) ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L != 2L, visitor.visit( new NotEquals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7L ); assertEquals( 7L != 7L, visitor.visit( new NotEquals( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 != 2, visitor.visit( new NotEquals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( 7 ); assertEquals( 7 != 7, visitor.visit( new NotEquals( lhs, rhs ) ) ); // Objects Object object1 = new Object(); Object object2 = new Object(); when( lhs.accept( visitor ) ).thenReturn( object1 ); when( rhs.accept( visitor ) ).thenReturn( object2 ); assertEquals( object1 != object2, visitor.visit( new NotEquals( lhs, rhs ) ) ); when( rhs.accept( visitor ) ).thenReturn( object1 ); assertEquals( object1 != object1, visitor.visit( new NotEquals( lhs, rhs ) ) ); } @Test public void testVisitOr() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L | 2L, visitor.visit( new Or( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 | 2, visitor.visit( new Or( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new Or( lhs, rhs ) ); fail( "The or(|) operator can only be performed on integral types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitParenExpression() { AnnotationValue value = mock( AnnotationValue.class ); Object acceptResult = new Object(); when( value.accept( visitor ) ).thenReturn( acceptResult ); assertSame( acceptResult, visitor.visit( new ParenExpression( value ) ) ); } @Test public void testVisitPlusSign() { AnnotationValue value = mock( AnnotationValue.class ); // Double when( value.accept( visitor ) ).thenReturn( 7.0D ); assertEquals( 7.0D, visitor.visit( new PlusSign( value ) ) ); // Float when( value.accept( visitor ) ).thenReturn( 7.0F ); assertEquals( 7.0F, visitor.visit( new PlusSign( value ) ) ); // Long when( value.accept( visitor ) ).thenReturn( 7L ); assertEquals( 7L, visitor.visit( new PlusSign( value ) ) ); // Integer when( value.accept( visitor ) ).thenReturn( 7 ); assertEquals( 7, visitor.visit( new PlusSign( value ) ) ); when( value.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new PlusSign( value ) ); fail( "The plus sign operator can only be performed on numeric types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitQuery() { AnnotationValue condition = mock( AnnotationValue.class ); AnnotationValue trueExpr = mock( AnnotationValue.class ); AnnotationValue falseExpr = mock( AnnotationValue.class ); when( trueExpr.accept( visitor ) ).thenReturn( "consequent" ); when( falseExpr.accept( visitor ) ).thenReturn( "alternative" ); // true condition when( condition.accept( visitor ) ).thenReturn( Boolean.TRUE ); assertEquals( "consequent", visitor.visit( new Query( condition, trueExpr, falseExpr ) ) ); when( condition.accept( visitor ) ).thenReturn( true ); assertEquals( "consequent", visitor.visit( new Query( condition, trueExpr, falseExpr ) ) ); // false condition when( condition.accept( visitor ) ).thenReturn( Boolean.FALSE ); assertEquals( "alternative", visitor.visit( new Query( condition, trueExpr, falseExpr ) ) ); when( condition.accept( visitor ) ).thenReturn( false ); assertEquals( "alternative", visitor.visit( new Query( condition, trueExpr, falseExpr ) ) ); when( condition.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new Query( condition, trueExpr, falseExpr ) ); fail( "The condition of the query( ? : ) must be a boolean" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitRemainder() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Doubles when( lhs.accept( visitor ) ).thenReturn( 7.0D ); when( rhs.accept( visitor ) ).thenReturn( 2.0D ); assertEquals( 7.0D % 2.0D, visitor.visit( new Remainder( lhs, rhs ) ) ); // Floats when( lhs.accept( visitor ) ).thenReturn( 7.0F ); when( rhs.accept( visitor ) ).thenReturn( 2.0F ); assertEquals( 7.0F % 2.0F, visitor.visit( new Remainder( lhs, rhs ) ) ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L % 2L, visitor.visit( new Remainder( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 % 2, visitor.visit( new Remainder( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new Remainder( lhs, rhs ) ); fail( "The remainder(%) operator can only be performed on numeric types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitShiftLeft() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L << 2L, visitor.visit( new ShiftLeft( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 << 2, visitor.visit( new ShiftLeft( lhs, rhs ) ) ); // Objects when( lhs.accept( any( EvaluatingVisitor.class ) ) ).thenReturn( new Object() ); when( rhs.accept( any( EvaluatingVisitor.class ) ) ).thenReturn( new Object() ); try { visitor.visit( new ShiftLeft( lhs, rhs ) ); fail( "Bitwise and bit shift operations can only be performed on integral types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitShiftRight() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L >> 2L, visitor.visit( new ShiftRight( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 >> 2, visitor.visit( new ShiftRight( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new ShiftRight( lhs, rhs ) ); fail( "Bitwise and bit shift operations can only be performed on integral types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitSubtract() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Doubles when( lhs.accept( any( EvaluatingVisitor.class ) ) ).thenReturn( 7.0D ); when( rhs.accept( any( EvaluatingVisitor.class ) ) ).thenReturn( 2.0D ); assertEquals( 7.0D - 2.0D, visitor.visit( new Subtract( lhs, rhs ) ) ); // Floats when( lhs.accept( any( EvaluatingVisitor.class ) ) ).thenReturn( 7.0F ); when( rhs.accept( any( EvaluatingVisitor.class ) ) ).thenReturn( 2.0F ); assertEquals( 7.0F - 2.0F, visitor.visit( new Subtract( lhs, rhs ) ) ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L - 2L, visitor.visit( new Subtract( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 - 2, visitor.visit( new Subtract( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new Subtract( lhs, rhs ) ); fail( "Additive operations (+ and -) can only be performed on numeric types" ); } catch ( IllegalArgumentException iae ) { } } @Test public void testVisitTypeRef() { JavaType type = mock( JavaType.class ); assertSame( type, visitor.visit( new TypeRef( type ) ) ); } @Test public void testVisitUnsignedShiftRight() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); // Longs when( lhs.accept( visitor ) ).thenReturn( 7L ); when( rhs.accept( visitor ) ).thenReturn( 2L ); assertEquals( 7L >>> 2L, visitor.visit( new UnsignedShiftRight( lhs, rhs ) ) ); // Integers when( lhs.accept( visitor ) ).thenReturn( 7 ); when( rhs.accept( visitor ) ).thenReturn( 2 ); assertEquals( 7 >>> 2, visitor.visit( new UnsignedShiftRight( lhs, rhs ) ) ); // Objects when( lhs.accept( visitor ) ).thenReturn( new Object() ); when( rhs.accept( visitor ) ).thenReturn( new Object() ); try { visitor.visit( new UnsignedShiftRight( lhs, rhs ) ); fail( "Bitwise and bit shift operations can only be performed on integral types" ); } catch ( IllegalArgumentException iae ) { } } private static class EvaluatingVisitorStub extends EvaluatingVisitor { static final Object fieldReferenceValue = new Object(); @Override protected Object getFieldReferenceValue( JavaField javaField ) { return fieldReferenceValue; } } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/builder/impl/ModelBuilderTest.java000066400000000000000000000760461325201777200312350ustar00rootroot00000000000000package com.thoughtworks.qdox.builder.impl; import static org.mockito.Mockito.*; import java.util.List; import junit.framework.TestCase; import com.thoughtworks.qdox.library.ClassNameLibrary; import com.thoughtworks.qdox.model.DocletTagFactory; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaConstructor; import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.parser.structs.ClassDef; import com.thoughtworks.qdox.parser.structs.FieldDef; import com.thoughtworks.qdox.parser.structs.InitDef; import com.thoughtworks.qdox.parser.structs.MethodDef; import com.thoughtworks.qdox.parser.structs.PackageDef; import com.thoughtworks.qdox.parser.structs.TagDef; import com.thoughtworks.qdox.parser.structs.TypeDef; public class ModelBuilderTest extends TestCase { private ModelBuilder builder; private DocletTagFactory docletTagFactory; public ModelBuilderTest(String s) { super(s); } @Override protected void setUp() throws Exception { docletTagFactory = mock( DocletTagFactory.class ); builder = new ModelBuilder( new ClassNameLibrary(), docletTagFactory ); } public void testNumberOfClassesGrows() { assertEquals(0, builder.getSource().getClasses().size()); builder.beginClass(new ClassDef()); builder.endClass(); assertEquals(1, builder.getSource().getClasses().size()); builder.beginClass(new ClassDef()); builder.endClass(); assertEquals(2, builder.getSource().getClasses().size()); } public void testSimpleClass() { ClassDef cls = new ClassDef("Thingy"); builder.beginClass(cls); builder.endClass(); ClassDef cls2 = new ClassDef("ThingyThing"); builder.beginClass(cls2); builder.endClass(); JavaSource source = builder.getSource(); assertEquals("Thingy", source.getClasses().get(0).getName()); assertEquals("ThingyThing", source.getClasses().get(1).getName()); assertEquals(source, source.getClasses().get(0).getParentSource()); } public void testInterface() { ClassDef cls = new ClassDef(); builder.beginClass(cls); builder.endClass(); ClassDef cls2 = new ClassDef(); cls2.setType( ClassDef.INTERFACE ); builder.beginClass(cls2); builder.endClass(); JavaSource source = builder.getSource(); assertEquals(false, source.getClasses().get(0).isInterface()); assertEquals(true, source.getClasses().get(1).isInterface()); } public void testEnum() { ClassDef cls = new ClassDef(); builder.beginClass(cls); builder.endClass(); ClassDef cls2 = new ClassDef(); cls2.setType( ClassDef.ENUM ); builder.beginClass(cls2); builder.endClass(); JavaSource source = builder.getSource(); assertEquals(false, source.getClasses().get(0).isEnum()); assertEquals(true, source.getClasses().get(1).isEnum()); } public void testAnnotationType() { ClassDef cls = new ClassDef(); cls.setType( ClassDef.ANNOTATION_TYPE ); builder.beginClass(cls); builder.endClass(); JavaSource source = builder.getSource(); assertEquals(1, source.getClasses().size()); } public void testClassExtends() { ClassDef cls = new ClassDef(); builder.beginClass(cls); builder.endClass(); ClassDef cls2 = new ClassDef(); cls2.getExtends().add(new TypeDef("Another")); builder.beginClass(cls2); builder.endClass(); builder.addImport("com.thoughtworks.*"); JavaSource source = builder.getSource(); assertEquals("java.lang.Object", source.getClasses().get(0).getSuperClass().getValue()); assertEquals("Another", source.getClasses().get(1).getSuperClass().getValue()); assertEquals(0, source.getClasses().get(0).getImplements().size()); assertEquals(0, source.getClasses().get(1).getImplements().size()); // With qdox-2.0 it's not possible to inspect the source during parsing, so this has become an invalid test /* //Add another class and see if Another gets resolved builder.addPackage(new PackageDef("com.thoughtworks")); ClassDef anotherCls = new ClassDef(); anotherCls.name = "Another"; builder.beginClass(anotherCls); builder.endClass(); assertEquals("com.thoughtworks.Another", source.getClasses()[1].getSuperClass().getValue()); */ } public void testInterfaceExtends() { ClassDef cls = new ClassDef(); cls.setType( ClassDef.INTERFACE ); builder.beginClass(cls); builder.endClass(); ClassDef cls2 = new ClassDef(); cls2.setType( ClassDef.INTERFACE ); cls2.getExtends().add(new TypeDef("Another")); builder.beginClass(cls2); builder.endClass(); JavaSource source = builder.getSource(); assertEquals(0, source.getClasses().get(0).getImplements().size()); assertEquals(1, source.getClasses().get(1).getImplements().size()); assertEquals("Another", source.getClasses().get(1).getImplements().get(0).getValue()); assertNull(source.getClasses().get(0).getSuperClass()); assertNull(source.getClasses().get(1).getSuperClass()); } public void testInterfaceExtendsMultiple() { ClassDef cls = new ClassDef(); cls.setType( ClassDef.INTERFACE ); cls.getExtends().add(new TypeDef("Another")); cls.getExtends().add(new TypeDef("java.io.Serializable")); cls.getExtends().add(new TypeDef("BottleOpener")); builder.beginClass(cls); builder.endClass(); JavaSource source = builder.getSource(); assertEquals(3, source.getClasses().get(0).getImplements().size()); assertEquals("Another", source.getClasses().get(0).getImplements().get(0).getValue()); assertEquals("java.io.Serializable", source.getClasses().get(0).getImplements().get(1).getValue()); assertEquals("BottleOpener", source.getClasses().get(0).getImplements().get(2).getValue()); assertNull(source.getClasses().get(0).getSuperClass()); } public void testClassImplements() { ClassDef cls = new ClassDef(); builder.beginClass(cls); builder.endClass(); ClassDef cls2 = new ClassDef(); cls2.getImplements().add(new TypeDef("SomeInterface")); builder.beginClass(cls2); builder.endClass(); JavaSource source = builder.getSource(); assertEquals(0, source.getClasses().get(0).getImplements().size()); assertEquals(1, source.getClasses().get(1).getImplements().size()); assertEquals("SomeInterface", source.getClasses().get(1).getImplements().get(0).getValue()); assertEquals("java.lang.Object", source.getClasses().get(0).getSuperClass().getValue()); assertEquals("java.lang.Object", source.getClasses().get(1).getSuperClass().getValue()); } public void testClassImplementsMultiple() { ClassDef cls = new ClassDef(); cls.getImplements().add(new TypeDef("SomeInterface")); cls.getImplements().add(new TypeDef("XX")); builder.beginClass(cls); builder.endClass(); JavaSource source = builder.getSource(); assertEquals(2, source.getClasses().get(0).getImplements().size()); assertEquals("SomeInterface", source.getClasses().get(0).getImplements().get(0).getValue()); assertEquals("XX", source.getClasses().get(0).getImplements().get(1).getValue()); } public void testClassExtendsAndImplements() { ClassDef cls = new ClassDef(); cls.getExtends().add(new TypeDef("SubClass")); cls.getImplements().add(new TypeDef("SomeInterface")); cls.getImplements().add(new TypeDef("XX")); builder.beginClass(cls); builder.endClass(); JavaSource source = builder.getSource(); assertEquals(2, source.getClasses().get(0).getImplements().size()); assertEquals("SomeInterface", source.getClasses().get(0).getImplements().get(0).getValue()); assertEquals("XX", source.getClasses().get(0).getImplements().get(1).getValue()); assertEquals("SubClass", source.getClasses().get(0).getSuperClass().getValue()); } public void testClassModifiers() { builder.beginClass(new ClassDef()); builder.endClass(); ClassDef cls2 = new ClassDef(); cls2.getModifiers().add("public"); cls2.getModifiers().add("final"); builder.beginClass(cls2); builder.endClass(); JavaSource source = builder.getSource(); assertEquals(0, source.getClasses().get(0).getModifiers().size()); assertEquals(2, source.getClasses().get(1).getModifiers().size()); List modifiers = source.getClasses().get(1).getModifiers(); assertEquals("public", modifiers.get(0)); assertEquals("final", modifiers.get(1)); } public void testAddMethodsToCorrectClass() { builder.beginClass(new ClassDef()); builder.beginMethod(); builder.endMethod(new MethodDef()); builder.endClass(); builder.beginClass(new ClassDef()); builder.beginMethod(); builder.endMethod(new MethodDef()); builder.beginMethod(); builder.endMethod(new MethodDef()); builder.beginMethod(); builder.endMethod(new MethodDef()); builder.endClass(); builder.beginClass(new ClassDef()); builder.beginMethod(); builder.endMethod(new MethodDef()); builder.beginMethod(); builder.endMethod(new MethodDef()); builder.endClass(); JavaSource source = builder.getSource(); assertEquals(1, source.getClasses().get(0).getMethods().size()); assertEquals(3, source.getClasses().get(1).getMethods().size()); assertEquals(2, source.getClasses().get(2).getMethods().size()); } public void testInnerClass() { builder.addPackage(new PackageDef("xyz")); ClassDef outerDef = new ClassDef("Outer"); builder.beginClass(outerDef); ClassDef innerDef = new ClassDef("Inner"); builder.beginClass(innerDef); MethodDef fooDef = new MethodDef(); fooDef.setName("foo"); builder.beginMethod(); builder.endMethod(fooDef); builder.endClass(); MethodDef barDef = new MethodDef(); barDef.setName("bar"); builder.beginMethod(); builder.endMethod(barDef); builder.endClass(); JavaSource source = builder.getSource(); assertEquals(1, source.getClasses().size()); JavaClass outerClass = source.getClasses().get(0); assertEquals("xyz.Outer", outerClass.getFullyQualifiedName()); assertEquals(1, outerClass.getMethods().size()); assertEquals("bar", outerClass.getMethods().get(0).getName()); assertEquals(1, outerClass.getNestedClasses().size()); JavaClass innerClass = outerClass.getNestedClasses().get(0); assertEquals("xyz.Outer$Inner", innerClass.getBinaryName()); assertEquals("xyz.Outer.Inner", innerClass.getFullyQualifiedName()); assertEquals(1, innerClass.getMethods().size()); assertEquals("foo", innerClass.getMethods().get(0).getName()); } public void testSimpleMethod() { builder.beginClass(new ClassDef()); MethodDef mth = new MethodDef(); mth.setName("doSomething"); mth.setReturnType(new TypeDef("void")); builder.beginMethod(); builder.endMethod(mth); builder.endClass(); JavaSource source = builder.getSource(); JavaMethod doSomething = source.getClasses().get(0).getMethods().get(0); assertEquals("doSomething", doSomething.getName()); assertEquals("void", doSomething.getReturns().getValue()); assertEquals(0, doSomething.getModifiers().size()); assertEquals(0, doSomething.getParameters().size()); assertEquals(0, doSomething.getExceptions().size()); } public void testMethodNoArray() { builder.beginClass(new ClassDef()); MethodDef mth = new MethodDef(); mth.setName("doSomething"); mth.setReturnType(new TypeDef("void")); mth.setDimensions(0); builder.beginMethod(); builder.endMethod(mth); builder.endClass(); JavaSource source = builder.getSource(); JavaMethod result = source.getClasses().get(0).getMethods().get(0); assertEquals(0, result.getReturns().getDimensions()); } public void testMethod1dArray() { builder.beginClass(new ClassDef()); MethodDef mth = new MethodDef(); mth.setName("doSomething"); mth.setReturnType(new TypeDef("void")); mth.setDimensions(1); builder.beginMethod(); builder.endMethod(mth); builder.endClass(); JavaSource source = builder.getSource(); JavaMethod result = source.getClasses().get(0).getMethods().get(0); assertEquals(1, result.getReturns().getDimensions()); } public void testMethod2dArray() { builder.beginClass(new ClassDef()); MethodDef mth = new MethodDef(); mth.setName("doSomething"); mth.setReturnType(new TypeDef("void")); mth.setDimensions(2); builder.beginMethod(); builder.endMethod(mth); builder.endClass(); JavaSource source = builder.getSource(); JavaMethod result = source.getClasses().get(0).getMethods().get(0); assertEquals(2, result.getReturns().getDimensions()); } public void testMethodParameters() { builder.beginClass(new ClassDef()); builder.beginMethod(); MethodDef mth = new MethodDef(); FieldDef f1 = new FieldDef(); f1.setName( "count" ); f1.setType( new TypeDef("int") ); f1.getModifiers().add("final"); builder.addParameter( f1 ); FieldDef f2 = new FieldDef(); f2.setName( "name" ); f2.setType( new TypeDef("String") ); builder.addParameter( f2 ); builder.endMethod(mth); builder.endClass(); JavaSource source = builder.getSource(); JavaMethod result = source.getClasses().get(0).getMethods().get(0); assertEquals(2, result.getParameters().size()); assertEquals("count", result.getParameters().get(0).getName()); assertEquals("int", result.getParameters().get(0).getType().getValue()); assertEquals("name", result.getParameters().get(1).getName()); assertEquals("String", result.getParameters().get(1).getType().getValue()); } public void testMethodParametersWithArrays() { builder.beginClass(new ClassDef()); builder.beginMethod(); MethodDef mth = new MethodDef(); FieldDef f1 = new FieldDef(); f1.setName( "count" ); f1.setType( new TypeDef("int") ); f1.getModifiers().add("final"); f1.setDimensions( 1 ); builder.addParameter( f1 ); FieldDef f2 = new FieldDef(); f2.setName( "name" ); f2.setType( new TypeDef("String") ); f2.setDimensions( 2 ); builder.addParameter( f2 ); builder.endMethod(mth); builder.endClass(); JavaSource source = builder.getSource(); JavaMethod result = source.getClasses().get(0).getMethods().get(0); assertEquals(1, result.getParameters().get(0).getJavaClass().getDimensions()); assertEquals(2, result.getParameters().get(1).getJavaClass().getDimensions()); } public void testMethodExceptions() { builder.beginClass(new ClassDef()); MethodDef mth = new MethodDef(); mth.getExceptions().add(new TypeDef("RuntimeException")); mth.getExceptions().add(new TypeDef("java.io.IOException")); builder.beginMethod(); builder.endMethod(mth); builder.endClass(); JavaSource source = builder.getSource(); JavaMethod result = source.getClasses().get(0).getMethods().get(0); assertEquals(2, result.getExceptions().size()); assertEquals("RuntimeException", result.getExceptions().get(0).getValue()); assertEquals("java.io.IOException", result.getExceptions().get(1).getValue()); } public void testMethodModifiers() { builder.beginClass(new ClassDef()); MethodDef mth = new MethodDef(); mth.getModifiers().add("public"); mth.getModifiers().add("final"); mth.getModifiers().add("synchronized"); builder.beginMethod(); builder.endMethod(mth); builder.endClass(); JavaSource source = builder.getSource(); JavaMethod result = source.getClasses().get(0).getMethods().get(0); assertEquals(3, result.getModifiers().size()); List modifiers = result.getModifiers(); assertEquals("public", modifiers.get(0)); assertEquals("final", modifiers.get(1)); assertEquals("synchronized", modifiers.get(2)); } public void testSimpleField() { builder.beginClass(new ClassDef()); FieldDef fld = new FieldDef(); fld.setName( "count" ); fld.setType( new TypeDef("int") ); builder.beginField(fld); builder.endField(); builder.endClass(); JavaSource source = builder.getSource(); JavaField result = source.getClasses().get(0).getFields().get(0); assertNotNull(result); assertEquals("count", result.getName()); assertEquals("int", result.getType().getValue()); } public void testFieldWithModifiers() { builder.beginClass(new ClassDef()); FieldDef fld = new FieldDef(); fld.getModifiers().add("blah2"); fld.getModifiers().add("blah"); builder.beginField(fld); builder.endField(); builder.endClass(); JavaSource source = builder.getSource(); JavaField result = source.getClasses().get(0).getFields().get(0); assertNotNull(result); assertNotNull(result.getModifiers()); assertEquals("blah2", result.getModifiers().get(0)); assertEquals("blah", result.getModifiers().get(1)); } public void testFieldNoArray() { builder.beginClass(new ClassDef()); FieldDef fld = new FieldDef(); fld.setName( "count" ); fld.setType( new TypeDef("int") ); fld.setDimensions( 0 ); builder.beginField(fld); builder.endField(); builder.endClass(); JavaSource source = builder.getSource(); JavaField result = source.getClasses().get(0).getFields().get(0); assertEquals(0, result.getType().getDimensions()); } public void testField1dArray() { builder.beginClass(new ClassDef()); FieldDef fld = new FieldDef(); fld.setName( "count" ); fld.setType( new TypeDef("int") ); fld.setDimensions( 1 ); builder.beginField(fld); builder.endField(); builder.endClass(); JavaSource source = builder.getSource(); JavaField result = source.getClasses().get(0).getFields().get(0); assertEquals(1, result.getType().getDimensions()); } public void testField2dArray() { builder.beginClass(new ClassDef()); FieldDef fld = new FieldDef(); fld.setName( "count" ); fld.setType( new TypeDef("int") ); fld.setDimensions( 2 ); builder.beginField(fld); builder.endField(); builder.endClass(); JavaSource source = builder.getSource(); JavaField result = source.getClasses().get(0).getFields().get(0); assertEquals(2, result.getType().getDimensions()); } public void testSimpleConstructor() { builder.beginClass(new ClassDef()); MethodDef c1 = new MethodDef(); c1.setName("MyClass"); builder.beginConstructor(); builder.endConstructor(c1); MethodDef m1 = new MethodDef(); m1.setName("method"); m1.setReturnType(new TypeDef("void")); builder.beginMethod(); builder.endMethod(m1); builder.endClass(); JavaSource source = builder.getSource(); JavaConstructor result1 = source.getClasses().get(0).getConstructors().get(0); JavaMethod result2 = source.getClasses().get(0).getMethods().get(0); assertNotNull(result1); assertNotNull(result2); assertNotNull(result2.getReturns()); } public void testJavaDocOnClass() { builder.addJavaDoc("Hello"); builder.beginClass(new ClassDef()); builder.endClass(); JavaSource source = builder.getSource(); assertEquals("Hello", source.getClasses().get(0).getComment()); } public void testJavaDocSpiradiclyOnManyClasses() { builder.addJavaDoc("Hello"); builder.beginClass(new ClassDef()); builder.endClass(); builder.beginClass(new ClassDef()); builder.endClass(); builder.addJavaDoc("World"); builder.beginClass(new ClassDef()); builder.endClass(); JavaSource source = builder.getSource(); assertEquals("Hello", source.getClasses().get(0).getComment()); assertNull(source.getClasses().get(1).getComment()); assertEquals("World", source.getClasses().get(2).getComment()); } public void testJavaDocOnMethod() { builder.beginClass(new ClassDef()); builder.addJavaDoc("Hello"); builder.beginMethod(); builder.endMethod(new MethodDef()); builder.endClass(); JavaSource source = builder.getSource(); assertNull(source.getClasses().get(0).getComment()); assertEquals("Hello", source.getClasses().get(0).getMethods().get(0).getComment()); } public void testJavaDocOnField() { builder.beginClass(new ClassDef()); builder.addJavaDoc("Hello"); builder.beginField(new FieldDef()); builder.endField(); builder.endClass(); JavaSource source = builder.getSource(); assertNull(source.getClasses().get(0).getComment()); assertEquals("Hello", source.getClasses().get(0).getFields().get(0).getComment()); } public void testJavaDocOnMethodsAndFields() { builder.addJavaDoc("Thing"); builder.beginClass(new ClassDef()); builder.beginField(new FieldDef());// f0 builder.endField(); builder.addJavaDoc("Hello"); builder.beginMethod(); builder.endMethod(new MethodDef());//m0 builder.addJavaDoc("Hello field"); builder.beginField(new FieldDef());//f1 builder.endField(); builder.beginMethod(); builder.endMethod(new MethodDef());//m1 builder.addJavaDoc("World"); builder.beginMethod(); builder.endMethod(new MethodDef());//m2 builder.endClass(); JavaSource source = builder.getSource(); assertEquals("Thing", source.getClasses().get(0).getComment()); assertNull(source.getClasses().get(0).getFields().get(0).getComment()); assertEquals("Hello field", source.getClasses().get(0).getFields().get(1).getComment()); assertEquals("Hello", source.getClasses().get(0).getMethods().get(0).getComment()); assertNull(source.getClasses().get(0).getMethods().get(1).getComment()); assertEquals("World", source.getClasses().get(0).getMethods().get(2).getComment()); } public void testDocletTag() { builder.addJavaDoc("Hello"); builder.addJavaDocTag(new TagDef("cheese", "is good")); builder.beginClass(new ClassDef()); builder.endClass(); JavaSource source = builder.getSource(); assertEquals("Hello", source.getClasses().get(0).getComment()); assertEquals(1, source.getClasses().get(0).getTags().size()); verify( docletTagFactory ).createDocletTag( eq("cheese"), eq("is good"), isA( JavaClass.class ), eq(-1) ); verifyNoMoreInteractions( docletTagFactory ); // assertEquals("cheese", source.getClasses().get(0).getTags().get(0).getName()); // assertEquals("is good", source.getClasses().get(0).getTags().get(0).getValue()); } public void testDocletTagWithNoComment() { builder.addJavaDoc(""); // parser will always call this method to signify start of javadoc builder.addJavaDocTag(new TagDef("cheese", "is good")); builder.beginClass(new ClassDef()); builder.endClass(); JavaSource source = builder.getSource(); assertEquals("", source.getClasses().get(0).getComment()); assertEquals(1, source.getClasses().get(0).getTags().size()); verify( docletTagFactory ).createDocletTag( eq("cheese"), eq("is good"), isA( JavaClass.class ), eq(-1) ); verifyNoMoreInteractions( docletTagFactory ); // assertEquals("cheese", source.getClasses().get(0).getTags().get(0).getName()); // assertEquals("is good", source.getClasses().get(0).getTags().get(0).getValue()); } public void testMultipleDocletTags() { builder.addJavaDoc("Hello"); builder.addJavaDocTag(new TagDef("cheese", "is good")); builder.addJavaDocTag(new TagDef("food", "is great")); builder.addJavaDocTag(new TagDef("chairs", "are boring")); builder.beginClass(new ClassDef()); builder.endClass(); JavaSource source = builder.getSource(); assertEquals("Hello", source.getClasses().get(0).getComment()); assertEquals(3, source.getClasses().get(0).getTags().size()); verify( docletTagFactory ).createDocletTag( eq("cheese"), eq("is good"), isA( JavaClass.class ), eq(-1) ); verify( docletTagFactory ).createDocletTag( eq("food"), eq("is great"), isA( JavaClass.class ), eq(-1) ); verify( docletTagFactory ).createDocletTag( eq("chairs"), eq("are boring"), isA( JavaClass.class ), eq(-1) ); verifyNoMoreInteractions( docletTagFactory ); // assertEquals("cheese", source.getClasses().get(0).getTags().get(0).getName()); // assertEquals("is good", source.getClasses().get(0).getTags().get(0).getValue()); // assertEquals("food", source.getClasses().get(0).getTags().get(1).getName()); // assertEquals("is great", source.getClasses().get(0).getTags().get(1).getValue()); // assertEquals("chairs", source.getClasses().get(0).getTags().get(2).getName()); // assertEquals("are boring", source.getClasses().get(0).getTags().get(2).getValue()); } public void testDocletTagsOnMethodsAndFields() { builder.addJavaDoc(""); builder.addJavaDocTag(new TagDef("cheese", "is good")); builder.beginClass(new ClassDef()); builder.addJavaDoc(""); builder.addJavaDocTag(new TagDef("food", "is great")); builder.beginMethod(); builder.endMethod(new MethodDef()); builder.addJavaDoc(""); builder.addJavaDocTag(new TagDef("chairs", "are boring")); builder.beginField(new FieldDef()); builder.endField(); builder.endClass(); verify( docletTagFactory ).createDocletTag( eq("cheese"), eq("is good"), isA( JavaClass.class ), eq(-1) ); verify( docletTagFactory ).createDocletTag( eq("food"), eq("is great"), isA( JavaMethod.class ), eq(-1) ); verify( docletTagFactory ).createDocletTag( eq("chairs"), eq("are boring"), isA( JavaField.class ), eq(-1) ); verifyNoMoreInteractions( docletTagFactory ); // assertEquals("cheese", source.getClasses().get(0).getTags().get(0).getName()); // assertEquals("is good", source.getClasses().get(0).getTags().get(0).getValue()); // assertEquals("food", source.getClasses().get(0).getMethods().get(0).getTags().get(0).getName()); // assertEquals("is great", source.getClasses().get(0).getMethods().get(0).getTags().get(0).getValue()); // assertEquals("chairs", source.getClasses().get(0).getFields().get(0).getTags().get(0).getName()); // assertEquals("are boring", source.getClasses().get(0).getFields().get(0).getTags().get(0).getValue()); } public void testRetrieveJavaSource() { builder.beginClass(new ClassDef()); builder.endClass(); JavaSource source = builder.getSource(); assertNotNull(source); } public void testJavaSourceClassCount() { builder.beginClass(new ClassDef()); builder.endClass(); builder.beginClass(new ClassDef()); builder.endClass(); builder.beginClass(new ClassDef()); builder.endClass(); JavaSource result = builder.getSource(); assertEquals(3, result.getClasses().size()); } public void testJavaSourceNoPackage() { JavaSource result = builder.getSource(); assertNull(result.getPackage()); } public void testJavaSourceWithPackage() { builder.addPackage(new PackageDef("com.blah.thing")); JavaSource result = builder.getSource(); assertEquals("com.blah.thing", result.getPackage().getName()); } public void testJavaSourceNoImports() { JavaSource result = builder.getSource(); assertEquals(0, result.getImports().size()); } public void testJavaSourceOneImport() { builder.addImport("com.blah.Thing"); JavaSource result = builder.getSource(); assertEquals(1, result.getImports().size()); assertEquals("com.blah.Thing", result.getImports().get(0)); } public void testJavaSourceMultipleImports() { builder.addImport("com.blah.Thing"); builder.addImport("java.util.List"); builder.addImport("org.apache.*"); JavaSource result = builder.getSource(); assertEquals(3, result.getImports().size()); assertEquals("com.blah.Thing", result.getImports().get(0)); assertEquals("java.util.List", result.getImports().get(1)); assertEquals("org.apache.*", result.getImports().get(2)); } public void testStaticInitializers() { builder.beginClass( new ClassDef( "Foo" ) ); builder.addInitializer( new InitDef( "//test", true ) ); builder.addInitializer( new InitDef( null, true ) ); builder.endClass(); JavaClass cls = builder.getSource().getClassByName( "Foo" ); assertEquals( 2, cls.getInitializers().size() ); assertEquals( "//test", cls.getInitializers().get( 0 ).getBlockContent() ); assertTrue( cls.getInitializers().get( 0 ).isStatic() ); assertEquals( null, cls.getInitializers().get( 1 ).getBlockContent() ); assertTrue(cls.getInitializers().get( 0 ).isStatic() ); } public void testInstanceInitializers() { builder.beginClass( new ClassDef( "Foo" ) ); builder.addInitializer( new InitDef( "//test", false ) ); builder.addInitializer( new InitDef( null, false ) ); builder.endClass(); JavaClass cls = builder.getSource().getClassByName( "Foo" ); assertEquals( 2, cls.getInitializers().size() ); assertEquals( "//test", cls.getInitializers().get( 0 ).getBlockContent() ); assertFalse( cls.getInitializers().get( 0 ).isStatic() ); assertEquals( null, cls.getInitializers().get( 1 ).getBlockContent() ); assertFalse( cls.getInitializers().get( 0 ).isStatic() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/directorywalker/000077500000000000000000000000001325201777200257715ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/directorywalker/DirectoryScannerTest.java000066400000000000000000000155371325201777200327650ustar00rootroot00000000000000package com.thoughtworks.qdox.directorywalker; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.io.File; import java.util.List; import org.junit.Test; public class DirectoryScannerTest { private File newMockFile( String name ) { return newMockFile( name, false ); } private File newMockFile( String name, boolean isDirectory ) { File result = mock( File.class ); when( result.getName() ).thenReturn( name ); when( result.isDirectory() ).thenReturn( isDirectory ); return result; } @Test public void testSingleDirectory() { File rootDir = newMockFile( "root", true ); { File blahTxt = newMockFile( "blah.txt" ); File fooTxt = newMockFile( "foo.txt" ); File pigJava = newMockFile( "pig.java" ); when( rootDir.listFiles() ).thenReturn( new File[] { blahTxt, fooTxt, pigJava } ); } DirectoryScanner scanner = new DirectoryScanner( rootDir ); List files = scanner.scan(); assertEquals( 3, files.size() ); assertEquals( "blah.txt", files.get( 0 ).getName() ); assertEquals( "foo.txt", files.get( 1 ).getName() ); assertEquals( "pig.java", files.get( 2 ).getName() ); } @Test public void testDirectoryWithSubdir() { File rootDir = newMockFile( "root", true ); { File subDir = newMockFile( "subdir", true ); { File child1Txt = newMockFile( "child1.txt" ); File child2Txt = newMockFile( "child2.txt" ); when( subDir.listFiles() ).thenReturn( new File[] { child1Txt, child2Txt } ); } File fooTxt = newMockFile( "foo.txt" ); File pigJava = newMockFile( "pig.java" ); when( rootDir.listFiles() ).thenReturn( new File[] { subDir, fooTxt, pigJava } ); } DirectoryScanner scanner = new DirectoryScanner( rootDir ); List files = scanner.scan(); assertEquals( 4, files.size() ); assertEquals( "child1.txt", files.get( 0 ).getName() ); assertEquals( "child2.txt", files.get( 1 ).getName() ); assertEquals( "foo.txt", files.get( 2 ).getName() ); assertEquals( "pig.java", files.get( 3 ).getName() ); } @Test public void testDirectoryWithSubdirWithSubdir() { File rootDir = newMockFile( "root", true ); { File subDir1 = newMockFile( "subdir", true ); { File subDir2 = newMockFile( "subdir2", true ); { File grandChild1Txt = newMockFile( "grandChild1.txt" ); when( subDir2.listFiles() ).thenReturn( new File[] { grandChild1Txt } ); } File child1Txt = newMockFile( "child1.txt" ); File child2Txt = newMockFile( "child2.txt" ); when( subDir1.listFiles() ).thenReturn( new File[] { subDir2, child1Txt, child2Txt } ); } File fooTxt = newMockFile( "foo.txt" ); File pigJava = newMockFile( "pig.java" ); when( rootDir.listFiles() ).thenReturn( new File[] { subDir1, fooTxt, pigJava } ); } DirectoryScanner scanner = new DirectoryScanner( rootDir ); List files = scanner.scan(); assertEquals( 5, files.size() ); assertEquals( "grandChild1.txt", files.get( 0 ).getName() ); assertEquals( "child1.txt", files.get( 1 ).getName() ); assertEquals( "child2.txt", files.get( 2 ).getName() ); assertEquals( "foo.txt", files.get( 3 ).getName() ); assertEquals( "pig.java", files.get( 4 ).getName() ); } @Test public void testSuffixFilter() { File rootDir = newMockFile( "root", true ); { File blahTxt = newMockFile( "blah.txt" ); File fooJava = newMockFile( "foo.java" ); File pigJava = newMockFile( "pig.java" ); when( rootDir.listFiles() ).thenReturn( new File[] { blahTxt, fooJava, pigJava } ); } DirectoryScanner scanner = new DirectoryScanner( rootDir ); scanner.addFilter( new SuffixFilter( ".java" ) ); List files = scanner.scan(); assertEquals( 2, files.size() ); assertEquals( "foo.java", files.get( 0 ).getName() ); assertEquals( "pig.java", files.get( 1 ).getName() ); } @Test public void testFilterCallback() { File rootDir = newMockFile( "root", true ); { File blahTxt = newMockFile( "blah.txt" ); File fooJava = newMockFile( "foo.java" ); File pigJava = newMockFile( "pig.java" ); when( rootDir.listFiles() ).thenReturn( new File[] { blahTxt, fooJava, pigJava } ); } DirectoryScanner scanner = new DirectoryScanner( rootDir ); Filter mockFilter = new Filter() { public boolean filter( File file ) { return file.getName().equals( "foo.java" ); } }; scanner.addFilter( mockFilter ); List files = scanner.scan(); assertEquals( 1, files.size() ); assertEquals( "foo.java", files.get( 0 ).getName() ); } @Test public void testMultipleFilters() { File rootDir = newMockFile( "root", true ); { File blahTxt = newMockFile( "blah.txt" ); File fooJava = newMockFile( "foo.java" ); File pigJava = newMockFile( "pig.java" ); File fooTxt = newMockFile( "foo.txt" ); when( rootDir.listFiles() ).thenReturn( new File[] { blahTxt, fooJava, pigJava, fooTxt } ); } DirectoryScanner scanner = new DirectoryScanner( rootDir ); scanner.addFilter( new SuffixFilter( ".java" ) ); scanner.addFilter( new Filter() { public boolean filter( File file ) { return file.getName().startsWith( "foo" ); } } ); List files = scanner.scan(); assertEquals( 1, files.size() ); assertEquals( "foo.java", files.get( 0 ).getName() ); } @Test public void testFileVisitor() { File rootDir = newMockFile( "root", true ); File blahTxt = newMockFile( "blah.txt" ); File fooJava = newMockFile( "foo.java" ); File pigJava = newMockFile( "pig.java" ); when( rootDir.listFiles() ).thenReturn( new File[] { blahTxt, fooJava, pigJava } ); DirectoryScanner scanner = new DirectoryScanner( rootDir ); FileVisitor visitor = mock( FileVisitor.class ); scanner.scan( visitor ); verify( visitor ).visitFile( blahTxt ); verify( visitor ).visitFile( fooJava ); verify( visitor ).visitFile( pigJava ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/directorywalker/SuffixFilterTest.java000066400000000000000000000022261325201777200321100ustar00rootroot00000000000000package com.thoughtworks.qdox.directorywalker; import java.io.File; import org.junit.Test; import static org.junit.Assert.*; public class SuffixFilterTest { @Test public void testNullFile() { try { new SuffixFilter( ".java" ).filter( null ); fail( "Can't filter null" ); } catch ( NullPointerException e ) { } } @Test public void testNullSuffix() { try { new SuffixFilter( null ).filter( new File( "test.java" ) ); fail( "Can't filter without a suffix" ); } catch ( NullPointerException e ) { } } @Test public void testEmptySuffix() { assertTrue( new SuffixFilter( "" ).filter( new File("test.java") ) ); } @Test public void testMatchingSuffix() { assertTrue( new SuffixFilter( ".java" ).filter( new File("test.java") ) ); } @Test public void testNonMatchingSuffix() { assertFalse( new SuffixFilter( "test" ).filter( new File("test.java") ) ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/library/000077500000000000000000000000001325201777200242235ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/library/AbstractClassLibraryTest.java000066400000000000000000000125301325201777200320050ustar00rootroot00000000000000package com.thoughtworks.qdox.library; import java.util.Collection; import java.util.Iterator; import junit.framework.TestCase; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.impl.DefaultJavaClass; import com.thoughtworks.qdox.model.impl.DefaultJavaPackage; public class AbstractClassLibraryTest extends TestCase { private AbstractClassLibrary nullClassLibrary = new AbstractClassLibrary() { @Override protected JavaClass resolveJavaClass( String name ) { return null; } @Override protected JavaPackage resolveJavaPackage(String name) { return null; } @Override protected boolean containsClassReference( String name ) { return false; } }; private AbstractClassLibrary parentClassLibrary; private AbstractClassLibrary filledChildClassLibrary; private AbstractClassLibrary emptyChildClassLibrary; @Override protected void setUp() throws Exception { parentClassLibrary = new AbstractClassLibrary() { @Override protected JavaClass resolveJavaClass( String name ) { return new DefaultJavaClass(name); } @Override protected JavaPackage resolveJavaPackage(String name) { return new DefaultJavaPackage(name); } @Override protected boolean containsClassReference( String name ) { throw new RuntimeException(); } }; filledChildClassLibrary = new AbstractClassLibrary(parentClassLibrary) { @Override protected JavaClass resolveJavaClass( String name ) { return new DefaultJavaClass(name); } @Override protected JavaPackage resolveJavaPackage(String name) { return new DefaultJavaPackage(name); } @Override protected boolean containsClassReference( String name ) { throw new RuntimeException(); } }; emptyChildClassLibrary = new AbstractClassLibrary(parentClassLibrary) { @Override protected JavaClass resolveJavaClass( String name ) { return null; } @Override protected JavaPackage resolveJavaPackage(String name) { return null; } @Override protected boolean containsClassReference( String name ) { throw new RuntimeException(); } }; } /* * Never null, empty by default */ public void testGetJavaSources() { assertEquals( 0, nullClassLibrary.getJavaSources().size() ); } /* * Never null, empty by default */ public void testGetJavaClasses() { assertEquals( 0, nullClassLibrary.getJavaClasses().size() ); } public void testGetJavaClassByName() { assertEquals( null, nullClassLibrary.getJavaClass( "java.lang.String" ) ); assertEquals( null, nullClassLibrary.getJavaClass( "com.thoughtworks.qdox.JavaProjectBuilder" ) ); } public void testChainedJavaClass() { //prepare libraries parentClassLibrary.getJavaClass( "ParentClass" ); filledChildClassLibrary.getJavaClass( "ChildClass" ); Collection parentClasses = parentClassLibrary.getJavaClasses( new AbstractClassLibrary.ClassLibraryFilter(){ public boolean accept(AbstractClassLibrary classLibrary) { return true; } } ); assertEquals(1, parentClasses.size()); assertEquals( "ParentClass", parentClasses.iterator().next().getFullyQualifiedName() ); Collection filledClasses = filledChildClassLibrary.getJavaClasses(new AbstractClassLibrary.ClassLibraryFilter(){ public boolean accept(AbstractClassLibrary classLibrary) { return true; } } ); assertEquals(2, filledClasses.size() ); Iterator iter = filledClasses.iterator(); assertEquals( "ChildClass", iter.next().getFullyQualifiedName() ); assertEquals( "ParentClass", iter.next().getFullyQualifiedName() ); Collection emptyClasses = emptyChildClassLibrary.getJavaClasses(new AbstractClassLibrary.ClassLibraryFilter(){ public boolean accept(AbstractClassLibrary classLibrary) { return true; } } ); assertEquals(1, emptyClasses.size() ); assertEquals( "ParentClass", emptyClasses.iterator().next().getFullyQualifiedName() ); } /* * Never null, empty by default */ public void testGetJavaPackages() { assertEquals( 0, nullClassLibrary.getJavaPackages().size() ); } public void testGetJavaPackageByName() { assertEquals( null, nullClassLibrary.getJavaPackage( "java.lang" ) ); assertEquals( null, nullClassLibrary.getJavaPackage( "com.thoughtworks" ) ); } public void testModuleInfo() { assertNull( nullClassLibrary.getJavaModules() ); assertNull( parentClassLibrary.getJavaModules() ); assertNull( filledChildClassLibrary.getJavaModules() ); assertNull( emptyChildClassLibrary.getJavaModules() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/library/ClassLibraryBuilderTest.java000066400000000000000000000046131325201777200316330ustar00rootroot00000000000000package com.thoughtworks.qdox.library; import java.io.ByteArrayInputStream; import java.io.StringReader; import junit.framework.TestCase; public abstract class ClassLibraryBuilderTest extends TestCase { protected abstract ClassLibraryBuilder getClassLibraryBuilder(); public final void testAppendClassLoader() { ClassLibraryBuilder libraryBuilder = getClassLibraryBuilder(); ClassLibraryBuilder result = libraryBuilder.appendClassLoader( null ); assertSame( libraryBuilder, result ); } public final void testAppendDefaultClassLoaders() { ClassLibraryBuilder libraryBuilder = getClassLibraryBuilder(); ClassLibraryBuilder result = libraryBuilder.appendDefaultClassLoaders(); assertSame( libraryBuilder, result ); } public final void testAppendSourceFolder() { ClassLibraryBuilder libraryBuilder = getClassLibraryBuilder(); ClassLibraryBuilder result = libraryBuilder.appendSourceFolder( null ); assertSame( libraryBuilder, result ); } public final void testAppendSourceInputStream() throws Exception { ClassLibraryBuilder libraryBuilder = getClassLibraryBuilder(); ClassLibraryBuilder result = libraryBuilder.appendSource( new ByteArrayInputStream( "package x.y.z;".getBytes( "UTF-8" ) ) ); assertSame( libraryBuilder, result ); } public final void testAppendSourceReader() { ClassLibraryBuilder libraryBuilder = getClassLibraryBuilder(); ClassLibraryBuilder result = libraryBuilder.appendSource( new StringReader("package x.y.z;") ); assertSame( libraryBuilder, result ); } // public final void testAppendSourceURL() throws Exception // { // ClassLibraryBuilder libraryBuilder = getClassLibraryBuilder(); // ClassLibraryBuilder result = libraryBuilder.appendSource( (URL) null ); // assertSame( libraryBuilder, result ); // } // // public final void testAppendSourceFile() throws Exception // { // ClassLibraryBuilder libraryBuilder = getClassLibraryBuilder(); // ClassLibraryBuilder result = libraryBuilder.appendSource( (File) null ); // assertSame( libraryBuilder, result ); // } public final void testGetClassLibrary() { ClassLibraryBuilder libraryBuilder = getClassLibraryBuilder(); assertNotNull( libraryBuilder.getClassLibrary() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/library/ClassLoaderLibraryTest.java000066400000000000000000000024611325201777200314520ustar00rootroot00000000000000package com.thoughtworks.qdox.library; import junit.framework.TestCase; public class ClassLoaderLibraryTest extends TestCase { private ClassLoaderLibrary classLoaderLibrary; @Override protected void setUp() throws Exception { classLoaderLibrary = new ClassLoaderLibrary(null); } public void testNoClassLoaders() { assertNull( classLoaderLibrary.getJavaClass( "java.lang.String") ); } public void testWithClassLoader() { classLoaderLibrary.addClassLoader(getClass().getClassLoader()); assertNotNull(classLoaderLibrary.getJavaClass("java.lang.String")); assertNotNull(classLoaderLibrary.getJavaClass("java.util.Collection")); assertNull(classLoaderLibrary.getJavaClass("java.util.GoatCrusher")); } public void testDefaultClassLoader() { classLoaderLibrary.addDefaultLoader(); assertNotNull(classLoaderLibrary.getJavaClass( "java.lang.String")); assertNotNull(classLoaderLibrary.getJavaClass("java.util.Collection")); assertNotNull(classLoaderLibrary.getJavaClass("java.util.Map$Entry")); assertNull(classLoaderLibrary.getJavaClass("java.util.GoatCrusher")); } public void testModuleInfo() { assertNull( classLoaderLibrary.getJavaModules() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/library/JavaClassContextTest.java000066400000000000000000000125361325201777200311510ustar00rootroot00000000000000package com.thoughtworks.qdox.library; import junit.framework.TestCase; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.model.impl.DefaultJavaClass; import com.thoughtworks.qdox.model.impl.DefaultJavaPackage; import com.thoughtworks.qdox.model.impl.DefaultJavaSource; public class JavaClassContextTest extends TestCase { private JavaClassContext context; @Override protected void setUp() throws Exception { context = new JavaClassContext(); } public void testGetClassByName() { assertNull( context.getClassByName( null ) ); assertNull( "a new context should be empty, not even contain java.lang.Object", context.getClassByName( "java.lang.Object" ) ); JavaClass clazz = new DefaultJavaClass( "com.foo.Bar" ); context.add( clazz ); //check case sensitive assertNull( context.getClassByName( "com.foo.bar" ) ); assertEquals( clazz, context.getClassByName( "com.foo.Bar" ) ); } public void testRemoveClassByName() { assertNull( context.removeClassByName( null )); assertNull( context.removeClassByName( "com.foo.Bar" ) ); JavaClass clazz = new DefaultJavaClass( "com.foo.Bar" ); context.add( clazz ); //check case sensitive assertNull( context.getClassByName( "com.foo.bar" ) ); assertEquals( clazz, context.removeClassByName( "com.foo.Bar" ) ); } public void testGetClasses() { assertNotNull( context.getClasses() ); assertEquals( 0, context.getClasses().size() ); JavaClass clazz = new DefaultJavaClass( "com.foo.Bar" ); context.add( clazz ); assertEquals( 1, context.getClasses().size() ); //weird case, add same class JavaClass clazz_copy = new DefaultJavaClass( "com.foo.Bar" ); context.add( clazz_copy ); assertEquals( 1, context.getClasses().size() ); context.removeClassByName( "com.foo.Bar" ); assertNotNull( context.getClasses() ); assertEquals( 0, context.getClasses().size() ); } public void testAddJavaClass() { JavaClass clazz = new DefaultJavaClass( "com.foo.Bar" ); context.add( clazz ); //check case sensitive assertNull( context.getClassByName( "com.foo.bar" ) ); assertEquals( clazz, context.getClassByName( "com.foo.Bar" ) ); //weird case, should never happen try { context.add( (JavaClass) null ); } catch(NullPointerException npe) {} } public void testGetPackageByName() { assertNull( context.getPackageByName( null ) ); assertNull( context.getPackageByName( "java.lang" ) ); JavaPackage pckg = new DefaultJavaPackage("com.foo"); context.add( pckg ); assertEquals( pckg, context.getPackageByName( "com.foo" ) ); } public void testRemovePackageByName() { assertNull( context.removePackageByName( null ) ); assertNull( context.removePackageByName( "com.foo" ) ); JavaPackage pckg = new DefaultJavaPackage("com.foo"); context.add( pckg ); assertEquals( pckg, context.removePackageByName( "com.foo" ) ); } public void testAddJavaPackage() { JavaPackage pckg = new DefaultJavaPackage("com.foo"); context.add( pckg ); //check case sensitive assertNull( context.getClassByName( "com.bar" ) ); assertEquals( pckg, context.getPackageByName( "com.foo" ) ); //null-safe context.add( (JavaPackage) null ); } public void testGetPackages() { assertNotNull( context.getPackages() ); assertEquals( 0, context.getPackages().size() ); JavaPackage pckg = new DefaultJavaPackage("com.foo"); context.add( pckg ); assertEquals( 1, context.getPackages().size() ); //add same package JavaPackage pckg_copy = new DefaultJavaPackage("com.foo"); context.add( pckg_copy ); assertEquals( 1, context.getPackages().size() ); context.removePackageByName( "com.foo" ); assertNotNull( context.getPackages() ); assertEquals( 0, context.getPackages().size() ); } public void testAddJavaSource() { JavaSource source = new DefaultJavaSource(null); context.add( source ); //null-safe context.add( (JavaSource) null ); } public void testGetSources() { assertNotNull( context.getSources() ); assertEquals( 0, context.getSources().size() ); JavaSource source = new DefaultJavaSource(null); context.add( source ); assertEquals( 1, context.getSources().size() ); //every source is unique, just add it JavaSource source_copy = new DefaultJavaSource(null); context.add( source_copy ); assertEquals( 2, context.getSources().size() ); } public void testAdd() { context.add(new DefaultJavaClass("com.blah.Ping")); context.add(new DefaultJavaClass("com.moo.Poo")); assertTrue(context.getClassByName("com.blah.Ping") != null ); assertTrue(context.getClassByName("com.moo.Poo") != null); assertTrue(context.getClassByName("com.not.You") == null); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/library/OrderedClassLibraryBuilderTest.java000066400000000000000000000004001325201777200331260ustar00rootroot00000000000000package com.thoughtworks.qdox.library; public class OrderedClassLibraryBuilderTest extends ClassLibraryBuilderTest { @Override protected ClassLibraryBuilder getClassLibraryBuilder() { return new OrderedClassLibraryBuilder(); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/library/SortedClassLibraryBuilderTest.java000066400000000000000000000003751325201777200330150ustar00rootroot00000000000000package com.thoughtworks.qdox.library; public class SortedClassLibraryBuilderTest extends ClassLibraryBuilderTest { @Override protected ClassLibraryBuilder getClassLibraryBuilder() { return new SortedClassLibraryBuilder(); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/library/SourceFolderLibraryTest.java000066400000000000000000000120221325201777200316440ustar00rootroot00000000000000package com.thoughtworks.qdox.library; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import java.io.File; import java.io.StringReader; import java.util.Iterator; import org.junit.Test; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaModule; import com.thoughtworks.qdox.model.JavaModuleDescriptor; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaExports; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaOpens; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaProvides; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaRequires; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaUses; public class SourceFolderLibraryTest { private SourceFolderLibrary library = new SourceFolderLibrary( null ); @Test public void testClassisFolder() { JavaModule directModule = library.addSourceFolder( new File("src/test/resources/qdox-140") ); assertEquals( null, directModule); } @Test public void testModuleInfo() { library.addSource( new StringReader("package V;\n" + "public interface W {}") ); library.addSource( new StringReader("package X;\n" + "public interface Y {}") ); library.addSource( new StringReader("package Z1;\n" + "public class Z2 implements X.Y {}") ); library.addSource( new StringReader("package Z3;\n" + "public class Z4 implements X.Y {}") ); JavaModule directModule = library.addSourceFolder( new File("src/test/resources/jigsaw/example1") ); assertEquals( "M.N", directModule.getName() ); JavaModule module = library.getJavaModules().iterator().next(); assertEquals( "M.N", module.getName() ); JavaModuleDescriptor descriptor = module.getDescriptor(); assertEquals( 4, descriptor.getRequires().size() ); Iterator requiresIter = descriptor.getRequires().iterator(); JavaRequires req = requiresIter.next(); assertEquals( "A.B", req.getModule().getName() ); assertEquals( false, req.isTransitive() ); assertEquals( false, req.isStatic() ); req = requiresIter.next(); assertEquals( "C.D", req.getModule().getName() ); assertEquals( true, req.isTransitive() ); assertEquals( false, req.isStatic() ); req = requiresIter.next(); assertEquals( "E.F", req.getModule().getName() ); assertEquals( false, req.isTransitive() ); assertEquals( true, req.isStatic() ); req = requiresIter.next(); assertEquals( "G.H", req.getModule().getName() ); assertEquals( true, req.isTransitive() ); assertEquals( true, req.isStatic() ); assertEquals( 2, module.getDescriptor().getExports().size()); Iterator exportsIter = descriptor.getExports().iterator(); JavaExports exp = exportsIter.next(); assertEquals( "P.Q", exp.getSource().getName() ); assertArrayEquals( new String[0], exp.getTargets().toArray( new String[0] ) ); exp = exportsIter.next(); assertEquals( "R.S", exp.getSource().getName() ); assertEquals( 2, exp.getTargets().size()); Iterator moduleIter = exp.getTargets().iterator(); JavaModule mdl = moduleIter.next(); assertEquals( "T1.U1", mdl.getName() ); mdl = moduleIter.next(); assertEquals( "T2.U2", mdl.getName() ); assertEquals( 2, module.getDescriptor().getOpens().size() ); Iterator opensIter = descriptor.getOpens().iterator(); JavaOpens opn = opensIter.next(); assertEquals( "P.Q", opn.getSource().getName() ); assertArrayEquals( new String[0], opn.getTargets().toArray( new String[0] ) ); opn = opensIter.next(); assertEquals( "R.S", opn.getSource().getName() ); assertEquals( 2, opn.getTargets().size()); moduleIter = opn.getTargets().iterator(); mdl = moduleIter.next(); assertEquals( "T1.U1", mdl.getName() ); mdl = moduleIter.next(); assertEquals( "T2.U2", mdl.getName() ); assertEquals( 1, module.getDescriptor().getUses().size() ); Iterator usesIter = descriptor.getUses().iterator(); JavaUses uses = usesIter.next(); assertEquals( "V.W", uses.getService().getFullyQualifiedName() ); assertEquals( 1, module.getDescriptor().getProvides().size() ); Iterator providesIter = descriptor.getProvides().iterator(); JavaProvides provides = providesIter.next(); assertEquals( "X.Y", provides.getService().getFullyQualifiedName() ); Iterator classIter = provides.getProviders().iterator(); JavaClass cls = classIter.next(); assertEquals( "Z1.Z2", cls.getFullyQualifiedName() ); cls = classIter.next(); assertEquals( "Z3.Z4", cls.getFullyQualifiedName() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/library/SourceLibraryTest.java000066400000000000000000000073471325201777200305260ustar00rootroot00000000000000package com.thoughtworks.qdox.library; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import junit.framework.TestCase; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.parser.ParseException; public class SourceLibraryTest extends TestCase { private SourceLibrary sourceLibrary; @Override protected void setUp() throws Exception { sourceLibrary = new SourceLibrary( null ); } @Override protected void tearDown() throws Exception { deleteDir("target/test-source"); } private File createFile(String fileName, String packageName, String className) throws Exception { File file = new File(fileName); file.getParentFile().mkdirs(); FileWriter writer = new FileWriter(file); writer.write("// this file generated by JavaDocBuilderTest - feel free to delete it\n"); writer.write("package " + packageName + ";\n\n"); writer.write("public class " + className + " {\n\n // empty\n\n}\n"); writer.close(); return file; } private void deleteDir(String path) { File dir = new File(path); if (dir.exists()) { File[] children = dir.listFiles(); for (int i = 0; i < children.length; i++) { File file = children[i]; if (file.isDirectory()) { deleteDir(file.getAbsolutePath()); } else { file.delete(); } } dir.delete(); } } //QDOX-221 public void testClosedStream() throws Exception { File badFile = createFile("target/test-source/com/blah/Bad.java", "com.blah", "@%! BAD {}}}}"); InputStream stream = new FileInputStream( badFile ); try { sourceLibrary.addSource( stream ); } catch(ParseException ex) { try { stream.read(); fail("Stream should be closed"); } catch(IOException ioe) {} } } //QDOX-221 public void testClosedReader() throws Exception { File badFile = createFile("target/test-source/com/blah/Bad.java", "com.blah", "@%! BAD {}}}}"); Reader reader= new FileReader( badFile ); try { sourceLibrary.addSource( reader ); } catch(ParseException ex) { try { reader.read(); fail("Reader should be closed"); } catch(IOException ioe) {} } } // ensure encoding is read public void testUTF8() throws Exception { File file = new File( "src/test/resources/com/thoughtworks/qdox/testdata/UTF8.java"); sourceLibrary.setEncoding( "UTF-8" ); JavaSource src = sourceLibrary.addSource( file ); assertEquals("TEST-CHARS: \u00DF\u0131\u03A3\u042F\u05D0\u20AC", src.getClassByName( "UTF8" ).getComment()); } public void testLatin1() throws Exception { File file = new File( "src/test/resources/com/thoughtworks/qdox/testdata/Latin1.java"); sourceLibrary.setEncoding( "ISO-8859-1" ); JavaSource src = sourceLibrary.addSource( file ); assertEquals("TEST-CHARS: \u00C4\u00D6\u00DC\u00E4\u00F6\u00FC\u00DF", src.getClassByName( "Latin1" ).getComment()); } public void testModuleInfo() throws Exception { File file = new File( "src/test/resources/com/thoughtworks/qdox/testdata/module-info.java"); assertNull( "module-info.java should be ignored", sourceLibrary.addSource(file) ); assertNull( sourceLibrary.getJavaModules() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/000077500000000000000000000000001325201777200236575ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/AbstractDocletTagTest.java000066400000000000000000000062651325201777200307250ustar00rootroot00000000000000package com.thoughtworks.qdox.model; import java.util.Map; import junit.framework.TestCase; public abstract class AbstractDocletTagTest extends TestCase { public AbstractDocletTagTest(String s) { super(s); } protected abstract DocletTagFactory getDocletTagFactory(); DocletTag createDocletTag(String tag, String text) { return getDocletTagFactory().createDocletTag(tag, text); } public void testIndexedParameter() { DocletTag tag = createDocletTag("x", "one two three four"); assertEquals("one", tag.getParameters().get(0)); assertEquals("two", tag.getParameters().get(1)); assertEquals("three", tag.getParameters().get(2)); assertEquals("four", tag.getParameters().get(3)); assertEquals(4, tag.getParameters().size()); } public void testNamedParameter() { DocletTag tag = getDocletTagFactory().createDocletTag( "x", "hello=world dog=cat fork=spoon" ); assertEquals("world", tag.getNamedParameter("hello")); assertEquals("cat", tag.getNamedParameter("dog")); assertEquals("spoon", tag.getNamedParameter("fork")); assertNull(tag.getNamedParameter("goat")); } public void testNamedParameterMap() { DocletTag tag = createDocletTag( "x", "hello=world dog=cat fork=spoon" ); Map map = tag.getNamedParameterMap(); assertEquals(3, map.size()); assertEquals("world", map.get("hello")); assertEquals("cat", map.get("dog")); assertEquals("spoon", map.get("fork")); assertNull(map.get("goat")); } public void testQuotedParameters() { DocletTag tag = createDocletTag("x", "one=\"hello world bye bye\" two=hello"); assertEquals("hello world bye bye", tag.getNamedParameter("one")); assertEquals("hello", tag.getNamedParameter("two")); tag = createDocletTag("x", "one=\"hello joe's world bye bye\" two=hello"); assertEquals("hello joe's world bye bye", tag.getNamedParameter("one")); assertEquals("hello", tag.getNamedParameter("two")); tag = createDocletTag("x", "one='hello joe\"s world bye bye' two=hello"); assertEquals("hello joe\"s world bye bye", tag.getNamedParameter("one")); assertEquals("hello", tag.getNamedParameter("two")); tag = createDocletTag("x", "one=\"hello chris' world bye bye\" two=hello"); assertEquals("hello chris' world bye bye", tag.getNamedParameter("one")); assertEquals("hello", tag.getNamedParameter("two")); } public void testJiraQdox28() { DocletTag tag = createDocletTag("key", "quote'ed"); assertEquals("quote", tag.getParameters().get(0)); assertEquals(2, tag.getParameters().size()); assertEquals("ed", tag.getParameters().get(1)); } public void testJiraQdox45() { DocletTag tag = createDocletTag("key", "param = \"value\""); assertEquals("value", tag.getNamedParameter("param")); } public void testJiraQdox50() { DocletTag tag = createDocletTag("key", "param=\" value\""); assertEquals(" value", tag.getNamedParameter("param")); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/JavaClassTest.java000066400000000000000000000743421325201777200272430ustar00rootroot00000000000000package com.thoughtworks.qdox.model; import static org.junit.Assert.*; import static org.hamcrest.CoreMatchers.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; public abstract class JavaClassTest { private C cls; private JavaSource src; //contructors public abstract C newJavaClass(); public abstract C newJavaClass(String name); //setters public abstract void setClasses(C clazz, List innerClazz); public abstract void setComment(C clazz, String comment); public abstract void setDeclaringClass( C clazz, JavaClass declaringClazz ); public abstract void setEnum(C clazz, boolean isEnum); public abstract void setFields(C clazz, List fields); public abstract void setImplementz(C clazz, List implementz); public abstract void setInterface(C clazz, boolean isInterface); public abstract void setMethods(C clazz, List method); public abstract void setModifiers(C clazz, List modifiers); public abstract void setName(C clazz, String name); public abstract void setPackage(C clazz, JavaPackage pckg); public abstract void setSuperClass(C clazz, JavaType type); public abstract void setSource( C clazz, JavaSource source ); public JavaPackage newJavaPackage(String name) { JavaPackage result = mock(JavaPackage.class); when(result.getName()).thenReturn( name ); return result; } public JavaParameter newJavaParameter(JavaType type, String name) { return newJavaParameter( type, name, false ); } public JavaParameter newJavaParameter(JavaType type, String name, boolean varArgs) { JavaParameter result = mock(JavaParameter.class); when( result.getType()).thenReturn( type ); when( result.getName()).thenReturn( name ); when( result.isVarArgs()).thenReturn( varArgs ); return result; } public abstract JavaSource newJavaSource(); public JavaType newType( String fullname ) { JavaType result = mock( JavaType.class ); when( result.getFullyQualifiedName() ).thenReturn( fullname ); when( result.getValue() ).thenReturn( fullname.replace( '$', '.' ) ); when( result.getCanonicalName() ).thenReturn( fullname.replace( '$', '.' ) ); when( result.getGenericCanonicalName() ).thenReturn( fullname.replace( '$', '.' ) ); return result; } public abstract void setPackage(JavaSource source, JavaPackage pckg); public abstract void addClass(JavaSource source, JavaClass clazz); @Before public void setUp() { src = newJavaSource(); cls = newJavaClass(); addClass(src, cls); } @Test public void testGetCodeBlockSimpleClass() { setName(cls, "MyClass"); String expected = "" + "class MyClass {\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockSimpleInterface() { setName(cls, "MyClass"); setInterface(cls, true); String expected = "" + "interface MyClass {\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockSimpleEnum() { setName(cls, "MyEnum"); setEnum(cls, true); String expected = "" + "enum MyEnum {\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockClassExtends() { setName(cls, "MyClass"); setSuperClass(cls, newType("SuperClass")); String expected = "" + "class MyClass extends SuperClass {\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockInterfaceExtends() { setName(cls, "MyClass"); setImplementz(cls, type(new String[]{"SomeInterface"})); setInterface(cls, true); String expected = "" + "interface MyClass extends SomeInterface {\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockInterfaceExtendsTwo() { setName(cls, "MyClass"); setImplementz(cls, type(new String[]{"SomeInterface", "AnotherInterface"})); setInterface(cls, true); String expected = "" + "interface MyClass extends SomeInterface, AnotherInterface {\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockInterfaceExtendsThree() { setName(cls, "MyClass"); setImplementz(cls, type(new String[]{"SomeInterface", "AnotherInterface", "Thingy"})); setInterface(cls, true); String expected = "" + "interface MyClass extends SomeInterface, AnotherInterface, Thingy {\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockClassImplements() { setName(cls, "MyClass"); setImplementz(cls, type(new String[]{"SomeInterface"})); String expected = "" + "class MyClass implements SomeInterface {\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockClassImplementsTwo() { setName(cls, "MyClass"); setImplementz(cls, type(new String[]{"SomeInterface", "AnotherInterface", "Xx"})); String expected = "" + "class MyClass implements SomeInterface, AnotherInterface, Xx {\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockClassImplementsAndExtends() { setName(cls, "MyClass"); setImplementz(cls, type(new String[]{"SomeInterface", "AnotherInterface", "Xx"})); setSuperClass(cls, newType("SubMarine")); String expected = "" + "class MyClass extends SubMarine implements SomeInterface, AnotherInterface, Xx {\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockModifers() { setName(cls, "MyClass"); setModifiers(cls, Arrays.asList(new String[]{"public", "final"})); String expected = "" + "public final class MyClass {\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockModifersProtectionAlwaysFirst() { setName(cls, "MyClass"); setModifiers(cls, Arrays.asList(new String[]{"final", "public"})); String expected = "" + "public final class MyClass {\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); setModifiers(cls, Arrays.asList(new String[]{"abstract", "protected"})); expected = "" + "protected abstract class MyClass {\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockClassWithOneMethod() { setName(cls, "MyClass"); JavaMethod mth = mock(JavaMethod.class); when(mth.getName()).thenReturn( "doStuff" ); JavaType voidType = newType("void"); when(mth.getReturnType()).thenReturn( voidType ); setMethods(cls, Collections.singletonList( mth )); String expected = "" + "class MyClass {\n" + "\n" + "\tvoid doStuff();\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockClassWithThreeMethods() { setName(cls, "MyClass"); List methods = new ArrayList(); { JavaMethod mth = mock(JavaMethod.class); when(mth.getName()).thenReturn( "doStuff" ); JavaType voidType = newType( "void" ); when(mth.getReturnType()).thenReturn( voidType ); methods.add(mth); } { JavaMethod mth = mock(JavaMethod.class); when(mth.getName()).thenReturn( "somethingElse" ); JavaType gooseType = newType("Goose"); when(mth.getReturnType()).thenReturn( gooseType ); methods.add(mth); } { JavaMethod mth = mock(JavaMethod.class); when(mth.getName()).thenReturn( "eat" ); JavaType voidType = newType("void"); when(mth.getReturnType()).thenReturn( voidType ); methods.add(mth); } setMethods( cls, methods ); String expected = "" + "class MyClass {\n" + "\n" + "\tvoid doStuff();\n" + "\n" + "\tGoose somethingElse();\n" + "\n" + "\tvoid eat();\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockClassWithTwoFields() { setName(cls, "MyClass"); List fields = new ArrayList(); { JavaField fld = mock( JavaField.class ); when(fld.getName()).thenReturn( "count" ); JavaClass intType = newJavaClass("int"); when(fld.getType()).thenReturn( intType ); when(fld.getDeclaringClass()).thenReturn( cls ); fields.add( fld ); } { JavaField fld = mock( JavaField.class ); when(fld.getName()).thenReturn( "thing" ); JavaClass stringType = newJavaClass( "String" ); when(fld.getType()).thenReturn( stringType ); when(fld.getModifiers()).thenReturn( Collections.singletonList( "public" ) ); when(fld.getDeclaringClass()).thenReturn( cls ); fields.add( fld ); } setFields( cls, fields ); String expected = "" + "class MyClass {\n" + "\n" + "\tint count;\n" + "\n" + "\tpublic String thing;\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockClassWithInnerClass() { setName(cls, "Outer"); JavaClass innerClass = mock( JavaClass.class ); when( innerClass.getName() ).thenReturn( "Inner" ); setClasses(cls, Collections.singletonList( innerClass ) ); String expected = "" + "class Outer {\n" + "\n" + "\tclass Inner {\n" + "\n" + "\t}\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockClassWithInnerEnum() { setName(cls, "Outer"); JavaClass innerEnum = mock( JavaClass.class ); when( innerEnum.getName() ).thenReturn( "Inner" ); when( innerEnum.isEnum() ).thenReturn( true ); setClasses(cls, Collections.singletonList( innerEnum ) ); String expected = "" + "class Outer {\n" + "\n" + "\tenum Inner {\n" + "\n" + "\t}\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockEnumWithInnerClass() { setName(cls, "Outer"); setEnum(cls, true); JavaClass innerClass = mock( JavaClass.class ); when( innerClass.getName() ).thenReturn( "Inner" ); setClasses(cls, Collections.singletonList( innerClass ) ); String expected = "" + "enum Outer {\n" + "\n" + "\tclass Inner {\n" + "\n" + "\t}\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockClassWithComment() { setName(cls, "MyClass"); setComment(cls, "Hello World"); String expected = "" + "/**\n" + " * Hello World\n" + " */\n" + "class MyClass {\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testGetCodeBlockClassWithIndentedCommentsForFieldAndMethod() { setName(cls, "MyClass"); setComment(cls, "Hello World"); JavaMethod mth = mock(JavaMethod.class); when(mth.getName()).thenReturn( "thingy" ); JavaClass stringType = newJavaClass( "String" ); when(mth.getReturnType()).thenReturn( stringType ); when(mth.getComment()).thenReturn( "Hello Method" ); setMethods( cls, Collections.singletonList( mth ) ); JavaField fld = mock(JavaField.class); when(fld.getType()).thenReturn( stringType ); when(fld.getName()).thenReturn( "thing" ); when(fld.getComment()).thenReturn( "Hello Field" ); when(fld.getDeclaringClass()).thenReturn( cls ); setFields( cls, Collections.singletonList( fld ) ); String expected = "" + "/**\n" + " * Hello World\n" + " */\n" + "class MyClass {\n" + "\n" + "\t/**\n" + "\t * Hello Field\n" + "\t */\n" + "\tString thing;\n" + "\n" + "\t/**\n" + "\t * Hello Method\n" + "\t */\n" + "\tString thingy();\n" + "\n" + "}\n"; assertEquals(expected, cls.getCodeBlock()); } @Test public void testIsPublic() { assertTrue( !cls.isPublic() ); setModifiers( cls, Arrays.asList( new String[] { "public" } ) ); assertTrue( cls.isPublic() ); } @Test public void testIsProtected() { assertTrue( !cls.isProtected() ); setModifiers( cls, Arrays.asList( new String[] { "protected" } ) ); assertTrue( cls.isProtected() ); } @Test public void testIsPrivate() { assertTrue( !cls.isPrivate() ); setModifiers( cls, Arrays.asList( new String[] { "private" } ) ); assertTrue( cls.isPrivate() ); } @Test public void testIsAbstract() { assertTrue( !cls.isAbstract() ); setModifiers( cls, Arrays.asList( new String[] { "abstract" } ) ); assertTrue( cls.isAbstract() ); } @Test public void testIsFinal() { assertTrue( !cls.isFinal() ); setModifiers( cls, Arrays.asList( new String[] { "final" } ) ); assertTrue( cls.isFinal() ); } @Test public void testIsStatic() { assertTrue( !cls.isStatic() ); setModifiers( cls, Arrays.asList( new String[] { "static" } ) ); assertTrue( cls.isStatic() ); } @Test public void testIsVoid() { setName( cls, "void" ); assertTrue( cls.isVoid() ); setName( cls, "Void" ); assertFalse( cls.isVoid() ); } @Test public void testQualifiedType() { setPackage(src, newJavaPackage("com.thoughtworks.qdox")); setName(cls, "MyClass"); assertEquals("MyClass", cls.getName()); assertEquals("MyClass", cls.getSimpleName()); assertEquals("com.thoughtworks.qdox", cls.getPackage().getName()); assertEquals("com.thoughtworks.qdox", cls.getPackageName()); assertEquals("com.thoughtworks.qdox.MyClass", cls.getBinaryName()); assertEquals("com.thoughtworks.qdox.MyClass", cls.getCanonicalName()); assertEquals("com.thoughtworks.qdox.MyClass", cls.getFullyQualifiedName()); } @Test public void testInnerClass() { JavaPackage pkg = mock(JavaPackage.class); when(pkg.getName()).thenReturn( "foo.bar" ); JavaClass outer = mock( JavaClass.class ); when( outer.getName() ).thenReturn( "Outer" ); when( outer.getPackageName() ).thenReturn( "foo.bar" ); when( outer.getFullyQualifiedName() ).thenReturn( "foo.bar.Outer" ); when( outer.getBinaryName() ).thenReturn( "foo.bar.Outer" ); C inner = newJavaClass(); setName(inner, "Inner"); setPackage( inner, pkg ); setDeclaringClass( inner, outer ); assertEquals("Inner", inner.getName()); assertEquals("Inner", inner.getSimpleName()); assertEquals("foo.bar", inner.getPackageName()); assertEquals("foo.bar.Outer$Inner", inner.getBinaryName()); assertEquals("foo.bar.Outer.Inner", inner.getCanonicalName()); assertEquals("foo.bar.Outer.Inner", inner.getFullyQualifiedName()); } @Test public void testDefaultPackageClass() { setPackage(src, null); setName(cls, "DefaultPackageClass"); assertEquals("", src.getClasses().get(0).getPackageName()); assertEquals("DefaultPackageClass", src.getClasses().get(0).getFullyQualifiedName()); } @Test public void testDefaultClassSuperclass() { setName(cls, "MyClass"); assertEquals("java.lang.Object", cls.getSuperClass().getValue()); setSuperClass(cls, newType("x.X")); assertEquals("x.X", cls.getSuperClass().getValue()); } @Test public void testDefaultInterfaceSuperclass() { setName(cls, "MyInterface"); setInterface(cls, true); assertNull(cls.getSuperClass()); setSuperClass(cls, newType("x.X")); assertEquals("x.X", cls.getSuperClass().getValue()); } @Test public void testEnumSuperclass() { setName(cls, "MyEnum"); setEnum(cls, true); assertEquals("java.lang.Enum", cls.getSuperClass().getValue()); } @Test public void testEnumCannotExtendAnythingElse() { setName(cls, "MyEnum"); setEnum(cls, true); try { setSuperClass(cls, newType("x.X")); fail("expected an exception"); } catch (IllegalArgumentException e) { assertEquals("enums cannot extend other classes", e.getMessage()); } } @Test public void testGetEnumConstants() { setName( cls, "MyEnum" ); assertNull( cls.getEnumConstants() ); setEnum( cls, true ); assertNotNull( cls.getEnumConstants() ); assertEquals( 0, cls.getEnumConstants().size() ); List fields = new ArrayList(); JavaField nonEnumConstantField = mock(JavaField.class); fields.add( nonEnumConstantField ); setFields( cls, fields ); assertEquals( 0, cls.getEnumConstants().size() ); JavaField enumConstantField = mock(JavaField.class); when ( enumConstantField.isEnumConstant() ).thenReturn( true ); fields.add( enumConstantField ); setFields( cls, fields ); assertEquals( 1, cls.getEnumConstants().size() ); } @Test public void testGetEnumConstantByName() { setName( cls, "MyEnum" ); List fields = new ArrayList(); JavaField nonEnumConstantField = mock(JavaField.class); when ( nonEnumConstantField.getName() ).thenReturn( "nonEnumField" ); fields.add( nonEnumConstantField ); setFields( cls, fields ); assertEquals( null, cls.getEnumConstantByName( "nonEnumField" ) ); JavaField enumConstantField = mock(JavaField.class); when ( enumConstantField.isEnumConstant() ).thenReturn( true ); when ( enumConstantField.getName() ).thenReturn( "enumField" ); fields.add( enumConstantField ); setFields( cls, fields ); assertEquals( enumConstantField, cls.getEnumConstantByName( "enumField" ) ); } @Test public void testCanGetFieldByName() { JavaField fredField = mock(JavaField.class); when(fredField.getName()).thenReturn( "fred" ); JavaClass intType = newJavaClass("int"); when(fredField.getType()).thenReturn( intType ); when(fredField.getDeclaringClass()).thenReturn( cls ); setFields( cls, Collections.singletonList( fredField ) ); assertEquals(fredField, cls.getFieldByName("fred")); assertEquals(null, cls.getFieldByName("barney")); } @Test public void testCanGetMethodBySignature() { final String methodName = "doStuff"; final List parameterTypes = javaType(new String[]{"int", "double"}); JavaMethod method = mock(JavaMethod.class); when(method.getName()).thenReturn(methodName); //both signatureMatches-methods are allowed when(method.signatureMatches( "doStuff", parameterTypes )).thenReturn( true ); when(method.signatureMatches( "doStuff", parameterTypes, false )).thenReturn( true ); setMethods(cls, Collections.singletonList( method )); assertSame( method, cls.getMethodBySignature("doStuff", parameterTypes) ); assertEquals( null, cls.getMethodBySignature("doStuff", Collections.emptyList()) ); assertEquals( null, cls.getMethodBySignature("sitIdlyBy", parameterTypes) ); } @Test public void testCanGetInnerClassByName() { JavaClass innerClass = mock( JavaClass.class ); when( innerClass.getName() ).thenReturn( "Inner" ); setClasses(cls, Collections.singletonList( innerClass ) ); assertEquals(innerClass, cls.getNestedClassByName("Inner")); assertEquals(null, cls.getNestedClassByName("Bogus")); } @Test public void testGetBeanPropertiesReturnsEmptyForEmptyClass() { assertEquals(0, cls.getBeanProperties().size()); } @Test public void testGetBeanPropertiesFindsSimpleProperties() { List methods = new ArrayList(); JavaMethod setFooMethod = mock(JavaMethod.class); when(setFooMethod.getName()).thenReturn( "setFoo" ); JavaClass intType = newJavaClass("int"); List parameters = Collections.singletonList( newJavaParameter( intType, "foo" ) ); when(setFooMethod.getParameters()).thenReturn( parameters ); when(setFooMethod.isPropertyMutator()).thenReturn( true ); when(setFooMethod.getPropertyName()).thenReturn( "foo" ); when(setFooMethod.getPropertyType()).thenReturn( intType ); methods.add(setFooMethod); JavaMethod getFooMethod = mock(JavaMethod.class); when(getFooMethod.getName()).thenReturn( "getFoo" ); when(getFooMethod.getReturnType()).thenReturn( intType ); when(getFooMethod.isPropertyAccessor()).thenReturn( true ); when(getFooMethod.getPropertyName()).thenReturn( "foo" ); when(getFooMethod.getPropertyType()).thenReturn( intType ); methods.add( getFooMethod ); setMethods( cls, methods ); assertEquals(1, cls.getBeanProperties().size()); BeanProperty fooProp = cls.getBeanProperties().get(0); assertEquals("foo", fooProp.getName()); assertEquals(intType, fooProp.getType()); assertEquals(getFooMethod, fooProp.getAccessor()); assertEquals(setFooMethod, fooProp.getMutator()); } @Test public void testToStringClass() { setName(cls, "com.MyClass"); assertEquals("class com.MyClass", cls.toString()); } @Test public void testInnerClassToString() { JavaClass jOuterClass = mock(JavaClass.class); when(jOuterClass.getFullyQualifiedName()).thenReturn( "com.thoughtworks.qdox.model.OuterClass" ); C jInnerClass = newJavaClass( "InnerClass" ); setDeclaringClass( jInnerClass, jOuterClass ); assertEquals("class com.thoughtworks.qdox.model.OuterClass.InnerClass", jInnerClass.toString()); } @Test public void testInnerClassType() { JavaClass jOuterClass = mock(JavaClass.class); when(jOuterClass.getFullyQualifiedName()).thenReturn("com.thoughtworks.qdox.model.OuterClass"); C jInnerClass = newJavaClass("InnerClass"); setDeclaringClass( jInnerClass, jOuterClass ); assertEquals( "com.thoughtworks.qdox.model.OuterClass.InnerClass", jInnerClass.getFullyQualifiedName() ); } @Test public void testInnerInterfaceToString() { JavaClass jOuterClass = mock(JavaClass.class); when(jOuterClass.getFullyQualifiedName()).thenReturn( "com.thoughtworks.qdox.model.OuterClass"); C jInnerInterface = newJavaClass( "InnerInterface" ); setInterface( jInnerInterface, true ); setDeclaringClass( jInnerInterface, jOuterClass ); assertEquals("interface com.thoughtworks.qdox.model.OuterClass.InnerInterface", jInnerInterface.toString()); } @Test public void testToStringInterface() { setName(cls, "com.MyClass"); setInterface(cls, true); assertEquals("interface com.MyClass", cls.toString()); } @Test public void testEquals() { C c1 = newJavaClass( "java.util.String" ); C c2 = newJavaClass( "java.util.String" ); C c3 = newJavaClass( "org.mycompany.String" ); assertEquals( c1, c1 ); assertThat( c1, not( new Object() ) ); assertEquals( c1, c2 ); assertThat( c1, not( c3 ) ); } /** * @codehaus.jira QDOX-59 */ @Test public void testBeanPropertiesAreReturnedInOrderDeclared() { List methods = new ArrayList(); JavaMethod getFooMethod = mock(JavaMethod.class); when(getFooMethod.getName()).thenReturn( "getFoo" ); JavaClass intType = newJavaClass("int"); when(getFooMethod.getReturnType()).thenReturn( intType ); when(getFooMethod.getPropertyName()).thenReturn( "foo" ); when(getFooMethod.isPropertyAccessor()).thenReturn( true ); methods.add( getFooMethod ); JavaMethod getBarMethod = mock(JavaMethod.class); when(getBarMethod.getName()).thenReturn( "getBar" ); when(getBarMethod.getReturnType()).thenReturn( intType ); when(getBarMethod.getPropertyName()).thenReturn( "bar" ); when(getBarMethod.isPropertyAccessor()).thenReturn( true ); methods.add( getBarMethod ); JavaMethod getMcFNordMethod = mock(JavaMethod.class); when(getMcFNordMethod.getName()).thenReturn( "getMcFnord" ); JavaClass stringType = newJavaClass("String"); when(getMcFNordMethod.getReturnType()).thenReturn( stringType ); when(getMcFNordMethod.getPropertyName()).thenReturn( "mcFnord" ); when(getMcFNordMethod.isPropertyAccessor()).thenReturn( true ); methods.add( getMcFNordMethod ); setMethods( cls, methods ); List properties = cls.getBeanProperties(); assertEquals(3, properties.size()); assertEquals("foo", properties.get(0).getName()); assertEquals("bar", properties.get(1).getName()); assertEquals("mcFnord", properties.get(2).getName()); } private List type(String[] typeNames) { List result = new LinkedList(); for (int i = 0; i < typeNames.length; i++) { result.add(newJavaClass(typeNames[i])); } return result; } private List javaType(String[] typeNames) { return new LinkedList(type(typeNames)); } // QDOX-201 @Test public void testGetVarArgMethodSignature() { List methods = new ArrayList(); JavaMethod simpleMethod = mock(JavaMethod.class); JavaType stringType = newType( "String" ); //both signatureMatches-methods are allowed when(simpleMethod.signatureMatches( "doSomething", Collections.singletonList( stringType ) )).thenReturn( true ); when(simpleMethod.signatureMatches( "doSomething", Collections.singletonList( stringType ), false )).thenReturn( true ); methods.add( simpleMethod ); JavaMethod varArgMethod = mock(JavaMethod.class); when(varArgMethod.signatureMatches( "doSomething", Collections.singletonList( stringType ), true )).thenReturn( true ); methods.add( varArgMethod ); setMethods( cls, methods ); assertEquals( simpleMethod, cls.getMethodBySignature( "doSomething", Collections.singletonList( stringType ) ) ); assertEquals( simpleMethod, cls.getMethodBySignature( "doSomething", Collections.singletonList( stringType ), false ) ); assertEquals( simpleMethod, cls.getMethodBySignature( "doSomething", Collections.singletonList( stringType ), true ) ); assertEquals( simpleMethod, cls.getMethodBySignature( "doSomething", Collections.singletonList( stringType ), false, false ) ); assertEquals( varArgMethod, cls.getMethodBySignature( "doSomething", Collections.singletonList( stringType ), false, true ) ); assertEquals( simpleMethod, cls.getMethodBySignature( "doSomething", Collections.singletonList( stringType ), true, false ) ); assertEquals( varArgMethod, cls.getMethodBySignature( "doSomething", Collections.singletonList( stringType ), true, true ) ); } @Ignore public void testJavaLangObjectAsDefaultSuperClass() { //up untill now this succeeds, because other tests have already set the static value of OBJECT //running this test alone make it fail, so it's not a proper test. //should be fixed if we can get rid of the Type-visibility JavaClass clazz = newJavaClass( "a.b.Sample" ); assertEquals( "java.lang.Object", clazz.getSuperJavaClass().getFullyQualifiedName() ); assertEquals( "java.lang.Object", clazz.getSuperClass().getFullyQualifiedName() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/JavaConstructorTest.java000066400000000000000000000140511325201777200305120ustar00rootroot00000000000000package com.thoughtworks.qdox.model; import static org.hamcrest.core.IsNot.*; import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.Arrays; import java.util.Collections; import java.util.List; import org.junit.Test; public abstract class JavaConstructorTest { protected abstract D newJavaConstructor( String string ); protected abstract void setModifiers( D constructor, List asList ); protected abstract void setDeclaringClass( D constructor, JavaClass cls ); protected abstract void setParameters( D constructor, List singletonList ); private JavaType newType( String name ) { return newType( name, 0 ); } private JavaType newType( String name, int dimensions ) { JavaType result = mock(JavaType.class); when(result.getFullyQualifiedName()).thenReturn( name ); return result; } private JavaParameter newJavaParameter( JavaType type, String name ) { JavaParameter result = mock( JavaParameter.class ); when( result.getType() ).thenReturn( type ); when( result.getName() ).thenReturn( name ); return result; } @Test public void testGetCodeBlockConstructor() { D constructor = newJavaConstructor( "Blah" ); setModifiers(constructor, Arrays.asList(new String[]{"public"})); assertEquals("public Blah() {\n}\n", constructor.getCodeBlock()); } @Test public void testConstructorToString() { JavaClass cls = mock(JavaClass.class); when(cls.getFullyQualifiedName()).thenReturn( "a.b.Executor" ); D constructor = newJavaConstructor( "Executor" ); setDeclaringClass( constructor, cls ); assertEquals("a.b.Executor()", constructor.toString()); } @Test public void testConstructorParameterTypes() { JavaClass cls = mock(JavaClass.class); when(cls.getFullyQualifiedName()).thenReturn( "a.b.Executor" ); D constructor = newJavaConstructor( "Executor" ); setParameters( constructor, Collections.singletonList( newJavaParameter( newType("a.b.C"), "param" ) )); setDeclaringClass( constructor, cls ); assertEquals("a.b.C", constructor.getParameterTypes().get(0).getFullyQualifiedName()); } @Test public void testHashCode() { assertTrue( "hashCode should never resolve to 0", newJavaConstructor( "" ).hashCode() != 0 ); D c1 = newJavaConstructor( "Thong" ); D c2 = newJavaConstructor( "Thong" ); assertEquals(c1.hashCode(), c2.hashCode()); } @Test public void testEquals() { D c1 = newJavaConstructor( "thing" ); D c2 = newJavaConstructor( "Thong" ); D c3 = newJavaConstructor( "Thong" ); D c4 = newJavaConstructor( "Thong" ); setDeclaringClass( c4, mock( JavaClass.class ) ); assertEquals( c1, c1 ); assertThat( c1, not( new Object() ) ); assertThat( c1, not(c2) ); assertEquals( c2, c3 ); assertThat( c3, not(c4) ); } @Test public void testIsPublic() { D cstr = newJavaConstructor( "Constructor" ); assertTrue( !cstr.isPublic() ); setModifiers( cstr, Arrays.asList( new String[] { "public" } ) ); assertTrue( cstr.isPublic() ); } @Test public void testIsProtected() { D cstr = newJavaConstructor( "Constructor" ); assertTrue( !cstr.isProtected() ); setModifiers( cstr, Arrays.asList( new String[] { "protected" } ) ); assertTrue( cstr.isProtected() ); } @Test public void testIsPrivate() { D cstr = newJavaConstructor( "Constructor" ); assertTrue( !cstr.isPrivate() ); setModifiers( cstr, Arrays.asList( new String[] { "private" } ) ); assertTrue( cstr.isPrivate() ); } @Test public void testIsAbstract() { D cstr = newJavaConstructor( "Constructor" ); assertTrue( !cstr.isAbstract() ); setModifiers( cstr, Arrays.asList( new String[] { "abstract" } ) ); assertTrue( cstr.isAbstract() ); } @Test public void testIsFinal() { D cstr = newJavaConstructor( "Constructor" ); assertTrue( !cstr.isFinal() ); setModifiers( cstr, Arrays.asList( new String[] { "final" } ) ); assertTrue( cstr.isFinal() ); } @Test public void testIsNavite() { D cstr = newJavaConstructor( "Constructor" ); assertTrue( !cstr.isNative() ); setModifiers( cstr, Arrays.asList( new String[] { "native" } ) ); assertTrue( cstr.isNative() ); } @Test public void testIsStatic() { D cstr = newJavaConstructor( "Constructor" ); assertTrue( !cstr.isStatic() ); setModifiers( cstr, Arrays.asList( new String[] { "static" } ) ); assertTrue( cstr.isStatic() ); } @Test public void testIsStrict() { D cstr = newJavaConstructor( "Constructor" ); assertTrue( !cstr.isStrictfp() ); setModifiers( cstr, Arrays.asList( new String[] { "strictfp" } ) ); assertTrue( cstr.isStrictfp() ); } @Test public void testIsSynchronized() { D cstr = newJavaConstructor( "Constructor" ); assertTrue( !cstr.isSynchronized() ); setModifiers( cstr, Arrays.asList( new String[] { "synchronized" } ) ); assertTrue( cstr.isSynchronized() ); } @Test public void testIsTransient() { D cstr = newJavaConstructor( "Constructor" ); assertTrue( !cstr.isTransient() ); setModifiers( cstr, Arrays.asList( new String[] { "transient" } ) ); assertTrue( cstr.isTransient() ); } @Test public void testIsVolatile() { D cstr = newJavaConstructor( "Constructor" ); assertTrue( !cstr.isVolatile() ); setModifiers( cstr, Arrays.asList( new String[] { "volatile" } ) ); assertTrue( cstr.isVolatile() ); } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/JavaFieldTest.java000066400000000000000000000163071325201777200272160ustar00rootroot00000000000000package com.thoughtworks.qdox.model; import static org.mockito.Mockito.*; import java.util.Arrays; import java.util.List; import junit.framework.TestCase; public abstract class JavaFieldTest extends TestCase { public JavaFieldTest(String s) { super(s); } //constructors public abstract F newJavaField(); public abstract F newJavaField(JavaClass type, String name); //setters public abstract void setComment(F fld, String comment); public abstract void setInitializationExpression(F fld, String expression); public abstract void setModifiers(F fld, List modifiers); public abstract void setName(F fld, String name); public abstract void setType(F fld, JavaClass type); public abstract void setDeclaringClass(F fld, JavaClass cls); public JavaClass newJavaClass( String fullname ) { return newJavaClass( fullname, 0 ); } public JavaClass newJavaClass(String fullname, int dimensions) { JavaClass result = mock( JavaClass.class ); when( result.getFullyQualifiedName() ).thenReturn( fullname ); String canonicalName = fullname.replace( '$', '.' ); when( result.getValue() ).thenReturn( canonicalName ); when( result.getDimensions()).thenReturn( dimensions ); for(int i = 0; i < dimensions; i++) { canonicalName += "[]"; } when( result.getCanonicalName() ).thenReturn( canonicalName ); when( result.getGenericCanonicalName() ).thenReturn( canonicalName ); return result; } public void testHashCode() { assertTrue( "hashCode should never resolve to 0", newJavaField().hashCode() != 0 ); } public void testGetCodeBlock() { F fld = newJavaField(); setName(fld, "count"); setType(fld, newJavaClass("int")); assertEquals("int count;\n", fld.getCodeBlock()); } public void testGetCodeBlockWithModifiers() { F fld = newJavaField(); setName(fld, "count"); setType(fld, newJavaClass("int")); setModifiers(fld, Arrays.asList(new String[]{"public", "final"})); assertEquals("public final int count;\n", fld.getCodeBlock()); } public void testGetCodeBlockWithComment() { F fld = newJavaField(); setName(fld, "count"); setType(fld, newJavaClass("int")); setComment(fld, "Hello"); String expected = "" + "/**\n" + " * Hello\n" + " */\n" + "int count;\n"; assertEquals(expected, fld.getCodeBlock()); } public void testGetCodeBlock1dArray() { F fld = newJavaField(); setName(fld, "count"); setType(fld, newJavaClass("int", 1)); String expected = "int[] count;\n"; assertEquals(expected, fld.getCodeBlock()); } public void testGetCodeBlock2dArray() { F fld = newJavaField(); setName(fld, "count"); setType(fld, newJavaClass("int", 2)); String expected = "int[][] count;\n"; assertEquals(expected, fld.getCodeBlock()); } public void testGetCodeBlockWithValue() { F fld = newJavaField(); setName(fld, "stuff"); setType(fld, newJavaClass("String")); setInitializationExpression(fld, "STUFF + getThing()"); String expected = "String stuff = STUFF + getThing();\n"; assertEquals(expected, fld.getCodeBlock()); } public void testToStringThreadMIN_PRIORITY() { JavaClass cls = mock(JavaClass.class); when(cls.getFullyQualifiedName()).thenReturn( "java.lang.Thread" ); F fld = newJavaField(newJavaClass("int"), "MIN_PRIORITY"); setModifiers(fld, Arrays.asList(new String[] {"final", "static", "public"})); setDeclaringClass( fld, cls ); assertEquals("public static final int java.lang.Thread.MIN_PRIORITY", fld.toString()); } public void testToStringFieldDescriptorFd() { JavaClass cls = mock(JavaClass.class); when(cls.getFullyQualifiedName()).thenReturn("java.io.FileDescriptor"); F fld = newJavaField(newJavaClass("int"), "fd"); setModifiers(fld, Arrays.asList(new String[]{"private"})); setDeclaringClass( fld, cls ); assertEquals("private int java.io.FileDescriptor.fd", fld.toString()); } public void testIsPublic() { F fld = newJavaField(); assertTrue( !fld.isPublic() ); setModifiers( fld, Arrays.asList( new String[] { "public" } ) ); assertTrue( fld.isPublic() ); } public void testIsProtected() { F fld = newJavaField(); assertTrue( !fld.isProtected() ); setModifiers( fld, Arrays.asList( new String[] { "protected" } ) ); assertTrue( fld.isProtected() ); } public void testIsPrivate() { F fld = newJavaField(); assertTrue( !fld.isPrivate() ); setModifiers( fld, Arrays.asList( new String[] { "private" } ) ); assertTrue( fld.isPrivate() ); } public void testIsAbstract() { F fld = newJavaField(); assertTrue( !fld.isAbstract() ); setModifiers( fld, Arrays.asList( new String[] { "abstract" } ) ); assertTrue( fld.isAbstract() ); } public void testIsFinal() { F fld = newJavaField(); assertTrue( !fld.isFinal() ); setModifiers( fld, Arrays.asList( new String[] { "final" } ) ); assertTrue( fld.isFinal() ); } public void testIsNavite() { F fld = newJavaField(); assertTrue( !fld.isNative() ); setModifiers( fld, Arrays.asList( new String[] { "native" } ) ); assertTrue( fld.isNative() ); } public void testIsStatic() { F fld = newJavaField(); assertTrue( !fld.isStatic() ); setModifiers( fld, Arrays.asList( new String[] { "static" } ) ); assertTrue( fld.isStatic() ); } public void testIsStrict() { F fld = newJavaField(); assertTrue( !fld.isStrictfp() ); setModifiers( fld, Arrays.asList( new String[] { "strictfp" } ) ); assertTrue( fld.isStrictfp() ); } public void testIsSynchronized() { F fld = newJavaField(); assertTrue( !fld.isSynchronized() ); setModifiers( fld, Arrays.asList( new String[] { "synchronized" } ) ); assertTrue( fld.isSynchronized() ); } public void testIsTransient() { F fld = newJavaField(); assertTrue( !fld.isTransient() ); setModifiers( fld, Arrays.asList( new String[] { "transient" } ) ); assertTrue( fld.isTransient() ); } public void testIsVolatile() { F fld = newJavaField(); assertTrue( !fld.isVolatile() ); setModifiers( fld, Arrays.asList( new String[] { "volatile" } ) ); assertTrue( fld.isVolatile() ); } public void testEquals() { JavaClass type = mock(JavaClass.class); JavaClass declaringClass = mock(JavaClass.class); F fld1 = newJavaField( type, "field"); F fld2 = newJavaField( type, "field"); setDeclaringClass( fld1, declaringClass ); setDeclaringClass( fld2, declaringClass ); assertEquals( fld1, fld2 ); } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/JavaMethodTest.java000066400000000000000000000501011325201777200274010ustar00rootroot00000000000000package com.thoughtworks.qdox.model; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.Arrays; import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; public abstract class JavaMethodTest { private M mth; //constructors public abstract M newJavaMethod(); public abstract M newJavaMethod(JavaClass returns, String name); //setters public abstract void setExceptions(M method, List exceptions); public abstract void setComment(M method, String comment); public abstract void setName(M method, String name); public abstract void setModifiers(M method, List modifiers); public abstract void setParameters(M method, List parameters); public abstract void setDeclaringClass(M method, JavaClass clazz); public abstract void setReturns(M method, JavaClass type); public abstract void setSourceCode(M method, String code); public JavaParameter newJavaParameter(JavaClass type, String name) { return newJavaParameter( type, name, false ); } public JavaParameter newJavaParameter(JavaClass type, String name, boolean varArgs) { JavaParameter result = mock(JavaParameter.class); when( result.getType() ).thenReturn( type ); String genericCanonicalName = type.getGenericCanonicalName(); when( result.getGenericCanonicalName() ).thenReturn( genericCanonicalName ); when( result.getName() ).thenReturn( name ); when( result.isVarArgs() ).thenReturn( varArgs ); return result; } public JavaClass newType( String fullname ) { return newType( fullname, 0 ); } public JavaClass newType(String fullname, int dimensions) { JavaClass result = mock( JavaClass.class ); when( result.getFullyQualifiedName() ).thenReturn( fullname ); String canonicalName = fullname.replace( '$', '.' ); when( result.getValue() ).thenReturn( canonicalName ); when( result.getDimensions()).thenReturn( dimensions ); for(int i = 0; i < dimensions; i++) { canonicalName += "[]"; } when( result.getCanonicalName() ).thenReturn( canonicalName ); when( result.getGenericCanonicalName() ).thenReturn( canonicalName ); return result; } @Before public void setUp() { mth = newJavaMethod(); } private void createSignatureTestMethod() { setName(mth, "blah"); setModifiers(mth, Arrays.asList(new String[]{"protected", "final"})); setReturns(mth, newType("void")); setExceptions(mth, Arrays.asList( new JavaClass[] { newType("FishException"), newType("FruitException"), } )); setParameters( mth, Arrays.asList( newJavaParameter(newType("int"), "count"), newJavaParameter(newType("MyThing"), "t") ) ); } @Test public void testDeclarationSignatureWithModifiers() { createSignatureTestMethod(); String signature = mth.getDeclarationSignature(true); assertEquals("protected final void blah(int count, MyThing t) throws FishException, FruitException", signature); } @Test public void testDeclarationSignatureWithoutModifiers() { createSignatureTestMethod(); String signature = mth.getDeclarationSignature(false); assertEquals("void blah(int count, MyThing t) throws FishException, FruitException", signature); } @Test public void testCallSignature() { createSignatureTestMethod(); String signature = mth.getCallSignature(); assertEquals("blah(count, t)", signature); } // public void testSignatureWithVarArgs() throws Exception { // mth.setName( "method" ); // mth.addParameter( new JavaParameter(new Type("java.lang.String"), "param", true) ); // assertEquals( mth, clazz.getMethodBySignature( "method", new Type[] { new Type("java.lang.String", true)} ) ); // } @Test public void testGetCodeBlockSimple() { setName(mth, "doSomething"); setReturns(mth, newType("java.lang.String")); assertEquals("java.lang.String doSomething();\n", mth.getCodeBlock()); } @Test public void testGetCodeBlockOneParam() { setName(mth, "blah"); setReturns(mth, newType("void")); setParameters( mth, Collections.singletonList( newJavaParameter(newType("String"), "thingy") ) ); assertEquals("void blah(String thingy);\n", mth.getCodeBlock()); } @Test public void testGetCodeBlockTwoParams() { setName(mth, "blah"); setReturns(mth, newType("void")); setParameters(mth, Arrays.asList( newJavaParameter(newType("int"), "count"), newJavaParameter(newType("MyThing"), "t") ) ); assertEquals("void blah(int count, MyThing t);\n", mth.getCodeBlock()); } @Test public void testGetCodeBlockThreeParams() { setName(mth, "blah"); setReturns(mth, newType("void")); setParameters(mth, Arrays.asList( newJavaParameter(newType("int"), "count"), newJavaParameter(newType("MyThing"), "t"), newJavaParameter(newType("java.lang.Meat"), "beef") )); assertEquals("void blah(int count, MyThing t, java.lang.Meat beef);\n", mth.getCodeBlock()); } @Test public void testGetCodeBlockModifiersWithAccessLevelFirst() { setName(mth, "blah"); setReturns(mth, newType("void")); setModifiers(mth, Arrays.asList(new String[]{"synchronized", "public", "final"})); assertEquals("public synchronized final void blah();\n", mth.getCodeBlock()); } @Test public void testGetCodeBlockOneException() { setName(mth, "blah"); setReturns(mth, newType("void")); setExceptions( mth, Arrays.asList( new JavaClass[] { newType( "RuntimeException" ) } ) ); assertEquals("void blah() throws RuntimeException;\n", mth.getCodeBlock()); } @Test public void testGetCodeBlockTwoException() { setName(mth, "blah"); setReturns(mth, newType("void")); setExceptions(mth, Arrays.asList( new JavaClass[]{newType("RuntimeException"), newType("java.lang.SheepException")})); assertEquals("void blah() throws RuntimeException, java.lang.SheepException;\n", mth.getCodeBlock()); } @Test public void testGetCodeBlockThreeException() { setName(mth, "blah"); setReturns(mth, newType("void")); setExceptions(mth, Arrays.asList( new JavaClass[]{newType("RuntimeException"), newType("java.lang.SheepException"), newType("CowException")})); assertEquals("void blah() throws RuntimeException, java.lang.SheepException, CowException;\n", mth.getCodeBlock()); } @Test public void testGetCodeBlockWithComment() { setName(mth, "blah"); setReturns(mth, newType("void")); setComment(mth, "Hello"); String expect = "" + "/**\n" + " * Hello\n" + " */\n" + "void blah();\n"; assertEquals(expect, mth.getCodeBlock()); } @Test public void testGetCodeBlock1dArray() { setName(mth, "doSomething"); setReturns(mth, newType("java.lang.String", 1)); assertEquals("java.lang.String[] doSomething();\n", mth.getCodeBlock()); } @Test public void testGetCodeBlock2dArray() { setName(mth, "doSomething"); setReturns(mth, newType("java.lang.String", 2)); assertEquals("java.lang.String[][] doSomething();\n", mth.getCodeBlock()); } @Test public void testGetCodeBlockParamArray() { setName(mth, "blah"); setReturns(mth, newType("void")); setParameters( mth, Arrays.asList( newJavaParameter( newType("int", 2), "count"), newJavaParameter( newType("MyThing", 1), "t") ) ); assertEquals("void blah(int[][] count, MyThing[] t);\n", mth.getCodeBlock()); } @Test public void testGetCodeBlockWithBody() { setName(mth, "doStuff"); setReturns(mth, newType("java.lang.String")); setSourceCode(mth, " int x = 2;\n return STUFF;\n"); assertEquals("" + "java.lang.String doStuff() {\n" + " int x = 2;\n" + " return STUFF;\n" + "}\n", mth.getCodeBlock()); } @Test public void testEquals() { JavaClass voidType = newType("void"); setName(mth, "thing"); setReturns(mth, voidType); M m2 = newJavaMethod(); setName(m2, "thing"); setReturns(m2, voidType); M m3 = newJavaMethod(); setName(m3, "thingy"); setReturns(m3, voidType); M m4 = newJavaMethod(); setName(m4, "thing"); setReturns(m4, newType("int")); M m5 = newJavaMethod(); M m6 = newJavaMethod(); M m7 = newJavaMethod(); setReturns(m7, newType("int")); M m8 = newJavaMethod(); setReturns(m8, newType("int")); // JavaClass declaringClass = mock( JavaClass.class ); // when( declaringClass.getFullyQualifiedName() ).thenReturn( "com.foo.bar" ); setDeclaringClass( m8, mock( JavaClass.class ) ); assertEquals(mth, mth); assertThat(mth, not(new Object())); assertEquals(mth, m2); assertEquals(m2, mth); assertThat(mth, not(m3)); assertThat(mth, not(m4)); assertFalse(mth.equals(null)); assertThat( m4, not(m5) ); assertThat( m5, not(m4) ); assertEquals( m5, m6 ); assertThat( m5, not(m7) ); assertThat( m7, not(m8) ); } @Test public void testEqualsWithParameters() { JavaClass voidType = newType("void"); JavaClass intArrayType = newType("int", 1); JavaClass stringArrayType = newType("java.lang.String", 2); JavaClass xArrayType = newType("X", 3); JavaParameter intArrayParam = newJavaParameter(intArrayType, "blah"); JavaParameter stringArrayParam = newJavaParameter(stringArrayType, "thing"); JavaParameter xArrayParameter = newJavaParameter(xArrayType, "blah"); setName( mth, "thing" ); setParameters( mth, Arrays.asList( intArrayParam, stringArrayParam, xArrayParameter ) ); setReturns( mth, voidType ); M m2 = newJavaMethod(); setName( m2, "thing" ); setParameters( m2, Arrays.asList( intArrayParam, stringArrayParam, xArrayParameter ) ); setReturns( m2, voidType ); M m3 = newJavaMethod(); setName( m3, "thing" ); setParameters( m3, Arrays.asList( intArrayParam, stringArrayParam ) ); setReturns( m3, voidType ); // dimension M m5 = newJavaMethod(); setName( m5, "thing" ); setParameters( m5, Arrays.asList( intArrayParam, stringArrayParam, newJavaParameter( newType( "X", 9 ), "blah" ) ) ); setReturns( m5, voidType ); assertEquals( mth, m2 ); assertEquals( m2, mth ); assertThat( mth, not(m3) ); assertThat( mth, not(m5) ); } @Test public void testHashCode() { assertTrue( "hashCode should never resolve to 0", newJavaMethod( newType("void"), "" ).hashCode() != 0 ); JavaClass voidType = newType( "void" ); JavaClass intType = newType( "int", 1 ); JavaClass stringArrayType = newType( "java.lang.String", 2 ); JavaClass xArrayType = newType( "X", 3 ); JavaParameter intParam = newJavaParameter( intType, "blah" ); JavaParameter stringArrayParam = newJavaParameter( stringArrayType, "thing" ); JavaParameter xArrayParam = newJavaParameter( xArrayType, "blah" ); setName( mth, "thing" ); setParameters( mth, Arrays.asList( intParam, stringArrayParam, xArrayParam ) ); setReturns( mth, voidType ); M m2 = newJavaMethod(); setName( m2, "thing" ); setParameters( m2, Arrays.asList( intParam, stringArrayParam, xArrayParam ) ); setReturns( m2, voidType ); M m3 = newJavaMethod(); setName( m3, "thing" ); setParameters( m3, Arrays.asList( intParam, stringArrayParam ) ); setReturns( m3, voidType ); assertEquals( mth.hashCode(), m2.hashCode() ); assertTrue( mth.hashCode() != m3.hashCode() ); } @Test public void testSignatureMatches() { JavaClass intType = newType("int"); JavaClass longArrayType = newType("long", 2); setName(mth, "thing"); setParameters(mth, Arrays.asList( newJavaParameter(intType, "x"), newJavaParameter(longArrayType, "y") )); setReturns(mth, newType("void")); JavaType[] correctTypes = new JavaClass[]{ intType, longArrayType }; JavaType[] wrongTypes1 = new JavaClass[]{ newType("int", 2), newType("long") }; JavaType[] wrongTypes2 = new JavaClass[]{ intType, longArrayType, newType("double") }; assertTrue(mth.signatureMatches("thing", Arrays.asList( correctTypes ))); assertFalse(mth.signatureMatches("xxx", Arrays.asList( correctTypes ))); assertFalse(mth.signatureMatches("thing", Arrays.asList( wrongTypes1 ))); assertFalse(mth.signatureMatches("thing", Arrays.asList( wrongTypes2 ))); } @Test public void testVarArgSignatureMatches() { JavaClass intType = newType("int"); JavaClass longArrayType = newType("long", 2); setName(mth, "thing"); setParameters(mth, Arrays.asList( newJavaParameter(intType, "x"), newJavaParameter(longArrayType, "y", true) )); setReturns(mth, newType("void")); JavaType[] correctTypes = new JavaClass[]{ intType, longArrayType }; JavaType[] wrongTypes1 = new JavaClass[]{ newType("int", 2), newType("long") }; JavaType[] wrongTypes2 = new JavaClass[]{ intType, longArrayType, newType("double") }; assertTrue(mth.signatureMatches("thing", Arrays.asList( correctTypes ), true)); assertFalse(mth.signatureMatches("thing", Arrays.asList( correctTypes ), false)); assertFalse(mth.signatureMatches("xxx", Arrays.asList( correctTypes ), true)); assertFalse(mth.signatureMatches("thing", Arrays.asList( wrongTypes1 ), true)); assertFalse(mth.signatureMatches("thing", Arrays.asList( wrongTypes2 ), true)); } @Test public void testParentClass() { JavaClass clazz = mock(JavaClass.class); setDeclaringClass( mth, clazz ); assertSame(clazz, mth.getDeclaringClass()); } @Test public void testCanGetParameterByName() { JavaParameter paramX = newJavaParameter(newType("int"), "x"); setParameters(mth, Arrays.asList( paramX, newJavaParameter(newType("string"), "y") )); assertEquals(paramX, mth.getParameterByName("x")); assertEquals(null, mth.getParameterByName("z")); } @Test public void testToString() { JavaClass cls = mock(JavaClass.class); when(cls.getBinaryName()).thenReturn( "java.lang.Object" ); M mthd = newJavaMethod(newType("boolean"),"equals"); setDeclaringClass(mthd, cls); setModifiers(mthd, Arrays.asList(new String[]{"public"})); setParameters(mthd, Collections.singletonList( newJavaParameter(newType("java.lang.Object"), null) )); assertEquals("public boolean java.lang.Object.equals(java.lang.Object)", mthd.toString()); } @Test public void testIsPublic() { assertTrue( !mth.isPublic() ); setModifiers( mth, Arrays.asList( new String[] { "public" } ) ); assertTrue( mth.isPublic() ); } @Test public void testIsProtected() { assertTrue( !mth.isProtected() ); setModifiers( mth, Arrays.asList( new String[] { "protected" } ) ); assertTrue( mth.isProtected() ); } @Test public void testIsPrivate() { assertTrue( !mth.isPrivate() ); setModifiers( mth, Arrays.asList( new String[] { "private" } ) ); assertTrue( mth.isPrivate() ); } @Test public void testIsAbstract() { assertTrue( !mth.isAbstract() ); setModifiers( mth, Arrays.asList( new String[] { "abstract" } ) ); assertTrue( mth.isAbstract() ); } @Test public void testIsFinal() { assertTrue( !mth.isFinal() ); setModifiers( mth, Arrays.asList( new String[] { "final" } ) ); assertTrue( mth.isFinal() ); } @Test public void testIsNavite() { assertTrue( !mth.isNative() ); setModifiers( mth, Arrays.asList( new String[] { "native" } ) ); assertTrue( mth.isNative() ); } @Test public void testIsStatic() { assertTrue( !mth.isStatic() ); setModifiers( mth, Arrays.asList( new String[] { "static" } ) ); assertTrue( mth.isStatic() ); } @Test public void testIsStrict() { assertTrue( !mth.isStrictfp() ); setModifiers( mth, Arrays.asList( new String[] { "strictfp" } ) ); assertTrue( mth.isStrictfp() ); } @Test public void testIsSynchronized() { assertTrue( !mth.isSynchronized() ); setModifiers( mth, Arrays.asList( new String[] { "synchronized" } ) ); assertTrue( mth.isSynchronized() ); } @Test public void testIsTransient() { assertTrue( !mth.isTransient() ); setModifiers( mth, Arrays.asList( new String[] { "transient" } ) ); assertTrue( mth.isTransient() ); } @Test public void testIsVolatile() { assertTrue( !mth.isVolatile() ); setModifiers( mth, Arrays.asList( new String[] { "volatile" } ) ); assertTrue( mth.isVolatile() ); } @Test public void testIsPropertyAccessor() { M getNameMethod = newJavaMethod( newType( "java.lang.String" ), "getName" ); assertTrue( getNameMethod.isPropertyAccessor() ); M isValidMethod = newJavaMethod( newType( "boolean" ), "isValid" ); assertTrue( isValidMethod.isPropertyAccessor() ); M getNameWithParamMethod = newJavaMethod( newType( "boolean" ), "getName" ); setParameters( getNameWithParamMethod, Collections.singletonList( mock(JavaParameter.class) ) ); assertFalse( getNameWithParamMethod.isPropertyAccessor() ); M gettingUpMethod = newJavaMethod( newType( "java.lang.String" ), "gettingUp" ); assertFalse( gettingUpMethod.isPropertyAccessor() ); M isolatedMethod = newJavaMethod( newType( "boolean" ), "isolated" ); assertFalse( isolatedMethod.isPropertyAccessor() ); M staticGetNameMethod = newJavaMethod( newType( "java.lang.String" ), "getName" ); setModifiers( staticGetNameMethod, Collections.singletonList( "static" ) ); assertFalse( staticGetNameMethod.isPropertyAccessor() ); } @Test public void testIsPropertyMutator() { M setNameMethod = newJavaMethod( newType("void"), "setName" ); setParameters( setNameMethod, Collections.singletonList( mock(JavaParameter.class) ) ); assertTrue( setNameMethod.isPropertyMutator() ); M setUpMethod = newJavaMethod( newType("void"), "setUp" ); assertFalse( setUpMethod.isPropertyMutator() ); M settingUpMethod = newJavaMethod( newType("void"), "settingUp" ); setParameters( settingUpMethod, Collections.singletonList( mock(JavaParameter.class) ) ); assertFalse( settingUpMethod.isPropertyMutator() ); M staticSetNameMethod = newJavaMethod( newType("void"), "setName" ); setModifiers( staticSetNameMethod, Collections.singletonList( "static" ) ); setParameters( staticSetNameMethod, Collections.singletonList( mock(JavaParameter.class) ) ); assertFalse( staticSetNameMethod.isPropertyMutator() ); } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/JavaPackageTest.java000066400000000000000000000024131325201777200275170ustar00rootroot00000000000000package com.thoughtworks.qdox.model; import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public abstract class JavaPackageTest

    { public abstract P newJavaPackage( String name ); @Test public void testToStringJavaLang() { P pckg = newJavaPackage( "java.lang" ); assertEquals( "package java.lang", pckg.toString() ); } @Test public void testEquals() { P pckg = newJavaPackage( "java.lang" ); assertTrue( pckg.equals( pckg ) ); assertFalse( pckg.equals( null ) ); assertFalse( pckg.equals( new Object() ) ); JavaPackage mockPckg = mock( JavaPackage.class ); when( mockPckg.getName() ).thenReturn( "java.lang" ); assertTrue( pckg.equals( mockPckg ) ); } public void testHashCode() { assertTrue( "hashCode should never resolve to 0", newJavaPackage( "" ).hashCode() != 0 ); } @Test public void testListAccessors() { P pckg = newJavaPackage( "com.foo.bar" ); assertNotNull( pckg.getSubPackages() ); assertEquals( 0, pckg.getSubPackages().size() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/JavaParameterTest.java000066400000000000000000000036671325201777200301200ustar00rootroot00000000000000package com.thoughtworks.qdox.model; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import junit.framework.TestCase; public abstract class JavaParameterTest

    extends TestCase { private final JavaClass VOID = newType( "void" ); public JavaParameterTest( String s ) { super( s ); } // constructors protected abstract P newJavaParameter( JavaClass type, String name ); protected abstract P newJavaParameter( JavaClass type, String name, boolean varArgs ); // setters protected abstract void setJavaExecutable( P parameter, JavaExecutable executable ); protected JavaClass newType( String typeName ) { JavaClass result = mock( JavaClass.class ); when( result.getFullyQualifiedName() ).thenReturn( typeName ); return result; } public void testHashCode() { assertTrue( "hashCode should never resolve to 0", newJavaParameter( VOID, "" ).hashCode() != 0 ); P simpleParameter = newJavaParameter( VOID, "", false ); P varArgParameter = newJavaParameter( VOID, "", true ); assertTrue( simpleParameter.hashCode() != varArgParameter.hashCode() ); } public void testEquals() { P simpleParameter = newJavaParameter( VOID, "", false ); P varArgParameter = newJavaParameter( VOID, "", true ); assertTrue( !simpleParameter.equals( varArgParameter ) ); // name of parameter shouldn't matter P fooParameter = newJavaParameter( VOID, "foo" ); P barParameter = newJavaParameter( VOID, "bar" ); assertEquals( fooParameter, barParameter ); } public void testExecutableDeclarator() { P p = newJavaParameter( newType( "x" ), "x" ); assertNull( p.getExecutable() ); JavaExecutable e = mock( JavaExecutable.class ); setJavaExecutable( p, e ); assertSame( e, p.getExecutable() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/JavaSourceTest.java000066400000000000000000000120161325201777200274240ustar00rootroot00000000000000package com.thoughtworks.qdox.model; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Collections; import java.util.List; import junit.framework.TestCase; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.library.SortedClassLibraryBuilder; public abstract class JavaSourceTest extends TestCase { private S source; public JavaSourceTest(String s) { super(s); } //constructors public abstract S newJavaSource(ClassLibrary classLibrary); //setters public abstract void setClasses(S source, List classes); public abstract void setImports(S source, List imports); public abstract void setPackage(S source, JavaPackage pckg); public JavaPackage newJavaPackage(String name) { JavaPackage result = mock( JavaPackage.class ); when( result.getName() ).thenReturn( name ); return result; } @Override protected void setUp() throws Exception { super.setUp(); source = newJavaSource(new SortedClassLibraryBuilder().appendDefaultClassLoaders().getClassLibrary()); } public void testToStringOneClass() { JavaClass cls = mock(JavaClass.class); when(cls.getName()).thenReturn( "MyClass" ); setClasses( source, Collections.singletonList( cls ) ); String expected = "" + "class MyClass {\n" + "\n" + "}\n"; assertEquals(expected, source.toString()); } public void testToStringMultipleClass() { List classes = new ArrayList(); JavaClass cls1 = mock(JavaClass.class); when(cls1.getName()).thenReturn( "MyClass1" ); classes.add( cls1 ); JavaClass cls2 = mock(JavaClass.class); when(cls2.getName()).thenReturn( "MyClass2" ); classes.add( cls2 ); JavaClass cls3 = mock(JavaClass.class); when(cls3.getName()).thenReturn( "MyClass3" ); classes.add( cls3 ); setClasses( source, classes ); String expected = "" + "class MyClass1 {\n" + "\n" + "}\n" + "\n" + "class MyClass2 {\n" + "\n" + "}\n" + "\n" + "class MyClass3 {\n" + "\n" + "}\n"; assertEquals(expected, source.toString()); } public void testToStringPackage() { JavaClass cls = mock(JavaClass.class); when(cls.getName()).thenReturn("MyClass"); setClasses(source, Collections.singletonList( cls )); setPackage(source, newJavaPackage("com.thing")); String expected = "" + "package com.thing;\n" + "\n" + "class MyClass {\n" + "\n" + "}\n"; assertEquals(expected, source.toString()); } public void testToStringImport() { JavaClass cls = mock(JavaClass.class); when(cls.getName()).thenReturn("MyClass"); setClasses(source, Collections.singletonList( cls )); setImports(source, Collections.singletonList("java.util.*")); String expected = "" + "import java.util.*;\n" + "\n" + "class MyClass {\n" + "\n" + "}\n"; assertEquals(expected, source.toString()); } public void testToStringMultipleImports() { JavaClass cls = mock(JavaClass.class); when(cls.getName()).thenReturn("MyClass"); setClasses(source, Collections.singletonList( cls )); List imports = new ArrayList(); imports.add("java.util.*"); imports.add("com.blah.Thing"); imports.add("xxx"); setImports( source, imports ); String expected = "" + "import java.util.*;\n" + "import com.blah.Thing;\n" + "import xxx;\n" + "\n" + "class MyClass {\n" + "\n" + "}\n"; assertEquals(expected, source.toString()); } public void testToStringImportAndPackage() { JavaClass cls = mock(JavaClass.class); when(cls.getName()).thenReturn("MyClass"); setClasses(source, Collections.singletonList( cls )); setImports(source, Collections.singletonList( "java.util.*" )); setPackage(source, newJavaPackage("com.moo")); String expected = "" + "package com.moo;\n" + "\n" + "import java.util.*;\n" + "\n" + "class MyClass {\n" + "\n" + "}\n"; assertEquals(expected, source.toString()); } public void testGetClassNamePrefix() { assertEquals("", source.getClassNamePrefix()); setPackage(source, newJavaPackage("foo.bar")); assertEquals("foo.bar.", source.getClassNamePrefix()); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/JavaTypeTest.java000066400000000000000000000053131325201777200271070ustar00rootroot00000000000000package com.thoughtworks.qdox.model; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import org.junit.Test; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.library.OrderedClassLibraryBuilder; public abstract class JavaTypeTest { public abstract T newType( String fullname ); public abstract T newType( String fullname, int dimensions ); public abstract T newType( String fullname, int dimensions, JavaClass clazz ); public abstract JavaClass newJavaClass( ClassLibrary library ); @Test public void testToString() { assertEquals( "int", newType( "int" ).toString() ); assertEquals( "int[]", newType( "int", 1 ).toString() ); assertEquals( "long[][][]", newType( "long", 3 ).toString() ); } @Test public void testFullyQualifiedName() { assertEquals( "int", newType( "int" ).getFullyQualifiedName() ); assertEquals( "int[]", newType( "int", 1 ).getFullyQualifiedName() ); assertEquals( "long[][][]", newType( "long", 3 ).getFullyQualifiedName() ); } @Test public void testEquals() { JavaClass javaSource = newJavaClass( new OrderedClassLibraryBuilder().appendDefaultClassLoaders().getClassLibrary() ); assertEquals( newType( "long", 0, javaSource ), newType( "long", 0, javaSource ) ); assertThat( newType( "long", 0, javaSource ), not( newType( "int" ) ) ); assertThat( newType( "long", 1 ), not( newType( "long" ) ) ); assertThat( newType( "long" ), not( newType( "long", 2 ) ) ); assertFalse( newType( "int" ).equals( null ) ); } @Test public void testToStringVoid() { assertEquals( "void", newType("void").toString() ); } @Test public void testToStringBoolean() { assertEquals( "boolean", newType( "boolean" ).toString() ); } @Test public void testToStringInt() { assertEquals( "int", newType( "int" ).toString() ); } @Test public void testToStringLong() { assertEquals( "long", newType( "long" ).toString() ); } @Test public void testToStringFloat() { assertEquals( "float", newType( "float" ).toString() ); } @Test public void testToStringDouble() { assertEquals( "double", newType( "double" ).toString() ); } @Test public void testToStringChar() { assertEquals( "char", newType( "char" ).toString() ); } @Test public void testToStringByte() { assertEquals( "byte", newType( "byte" ).toString() ); } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/000077500000000000000000000000001325201777200260565ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/AddTest.java000066400000000000000000000024461325201777200302570ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class AddTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); Add expr = new Add( lhs, rhs ); assertEquals( "2 + 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); Add expr = new Add( lhs, rhs ); assertEquals( lhs + " + " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); Add expr = new Add( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/AndTest.java000066400000000000000000000024461325201777200302710ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class AndTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); And expr = new And( lhs, rhs ); assertEquals( "2 & 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); And expr = new And( lhs, rhs ); assertEquals( lhs + " & " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); And expr = new And( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/AnnotationValueListTest.java000066400000000000000000000070031325201777200335240ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.junit.Test; public class AnnotationValueListTest { @Test public void testParameterValue_emptyList() { AnnotationValueList expr = new AnnotationValueList ( Collections.emptyList() ); assertEquals( Collections.emptyList(), expr.getParameterValue() ); } @Test public void testToString_emptyList() { AnnotationValueList expr = new AnnotationValueList ( Collections.emptyList() ); assertEquals( "{}", expr.toString() ); } @Test public void testParameterValue_singletonList() { AnnotationValue value= mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "2" ); AnnotationValueList expr = new AnnotationValueList ( Collections.singletonList( value ) ); assertEquals( Collections.singletonList( "2" ), expr.getParameterValue() ); } @Test public void testToString_singletonList() { AnnotationValue value= mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "2" ); AnnotationValueList expr = new AnnotationValueList ( Collections.singletonList( value ) ); assertEquals( "{" + value+ "}", expr.toString() ); } @Test public void testParameterValue_twoElementsList() { AnnotationValue value1 = mock( AnnotationValue.class ); when( value1.getParameterValue() ).thenReturn( "2" ); AnnotationValue value2 = mock( AnnotationValue.class ); when( value2.getParameterValue() ).thenReturn( "3" ); List actualList = new LinkedList(); actualList.add( value1 ); actualList.add( value2 ); AnnotationValueList expr = new AnnotationValueList( actualList ); List expectedParameterValue = new LinkedList(); expectedParameterValue.add( "2" ); expectedParameterValue.add( "3" ); assertEquals( expectedParameterValue, expr.getParameterValue() ); } @Test public void testToString_twoElementsList() { AnnotationValue value1 = mock( AnnotationValue.class ); when( value1.getParameterValue() ).thenReturn( "2" ); AnnotationValue value2 = mock( AnnotationValue.class ); when( value2.getParameterValue() ).thenReturn( "3" ); List actualList = new LinkedList(); actualList.add( value1 ); actualList.add( value2 ); AnnotationValueList expr = new AnnotationValueList( actualList ); List expectedParameterValue = new LinkedList(); expectedParameterValue.add( "2" ); expectedParameterValue.add( "3" ); assertEquals( "{" + value1+ ", " + value2 + "}", expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); AnnotationValueList expr = new AnnotationValueList ( null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/AssignmentTest.java000066400000000000000000000025021325201777200316700ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class AssignmentTest { @Test public void testParameterValue() { Expression lhs = mock( Expression.class ); Expression rhs = mock( Expression.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); Assignment expr = new Assignment( lhs, ">>>=", rhs ); assertEquals( "2 >>>= 3", expr.getParameterValue() ); } @Test public void testToString() { Expression lhs = mock( Expression.class ); Expression rhs = mock( Expression.class ); Assignment expr = new Assignment( lhs, "+=",rhs ); assertEquals( lhs + " += " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); Assignment expr = new Assignment( null, null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/CastTest.java000066400000000000000000000025231325201777200304550ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; import com.thoughtworks.qdox.model.JavaType; public class CastTest { @Test public void testParameterValue() { JavaType type = mock(JavaType.class); AnnotationValue value = mock( AnnotationValue.class ); when( type.getCanonicalName() ).thenReturn( "int" ); when( value.getParameterValue() ).thenReturn( "3" ); Cast expr = new Cast( type, value ); assertEquals( "(int) 3", expr.getParameterValue() ); } @Test public void testToString() { JavaType type = mock(JavaType.class); AnnotationValue value = mock( AnnotationValue.class ); Cast expr = new Cast( type, value ); assertEquals( "(" +type+ ") " + value, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); Cast expr = new Cast( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/ConstantTest.java000066400000000000000000000501251325201777200313550ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.*; import org.junit.Test; public class ConstantTest { @Test public void testBinaryInteger() { assertEquals( Integer.valueOf( "0", 2 ), Constant.newIntegerLiteral( "0b0" ).getValue() ); assertEquals( Integer.valueOf( "0", 2 ), Constant.newIntegerLiteral( "0B0" ).getValue() ); assertEquals( Integer.valueOf( "0", 2 ), Constant.newIntegerLiteral( "0b00" ).getValue() ); assertEquals( Integer.valueOf( "0", 2 ), Constant.newIntegerLiteral( "0B00" ).getValue() ); assertEquals( Integer.valueOf( "10", 2 ), Constant.newIntegerLiteral( "0b10" ).getValue() ); assertEquals( Integer.valueOf( "10", 2 ), Constant.newIntegerLiteral( "0B10" ).getValue() ); } @Test public void testOctalInteger() { assertEquals( Integer.valueOf( "0", 8 ), Constant.newIntegerLiteral( "00" ).getValue() ); assertEquals( Integer.valueOf( "0", 8 ), Constant.newIntegerLiteral( "000" ).getValue() ); assertEquals( Integer.valueOf( "10", 8 ), Constant.newIntegerLiteral( "010" ).getValue() ); } @Test public void testDecimalInteger() { assertEquals( Integer.valueOf( "0" ), Constant.newIntegerLiteral( "0" ).getValue() ); assertEquals( Integer.valueOf( "10" ), Constant.newIntegerLiteral( "10" ).getValue() ); } @Test public void testHexInteger() { assertEquals( Integer.valueOf( "0", 16 ), Constant.newIntegerLiteral( "0x0" ).getValue() ); assertEquals( Integer.valueOf( "0", 16 ), Constant.newIntegerLiteral( "0X0" ).getValue() ); assertEquals( Integer.valueOf( "0", 16 ), Constant.newIntegerLiteral( "0x00" ).getValue() ); assertEquals( Integer.valueOf( "0", 16 ), Constant.newIntegerLiteral( "0X00" ).getValue() ); assertEquals( Integer.valueOf( "10", 16 ), Constant.newIntegerLiteral( "0x10" ).getValue() ); assertEquals( Integer.valueOf( "10", 16 ), Constant.newIntegerLiteral( "0X10" ).getValue() ); } @Test public void testBinaryLong() { assertEquals( Long.valueOf( "0", 2 ), Constant.newIntegerLiteral( "0b0l" ).getValue() ); assertEquals( Long.valueOf( "0", 2 ), Constant.newIntegerLiteral( "0b0L" ).getValue() ); assertEquals( Long.valueOf( "0", 2 ), Constant.newIntegerLiteral( "0B0l" ).getValue() ); assertEquals( Long.valueOf( "0", 2 ), Constant.newIntegerLiteral( "0B0L" ).getValue() ); assertEquals( Long.valueOf( "0", 2 ), Constant.newIntegerLiteral( "0b00l" ).getValue() ); assertEquals( Long.valueOf( "0", 2 ), Constant.newIntegerLiteral( "0b00L" ).getValue() ); assertEquals( Long.valueOf( "0", 2 ), Constant.newIntegerLiteral( "0B00l" ).getValue() ); assertEquals( Long.valueOf( "0", 2 ), Constant.newIntegerLiteral( "0B00L" ).getValue() ); assertEquals( Long.valueOf( "10", 2 ), Constant.newIntegerLiteral( "0b10l" ).getValue() ); assertEquals( Long.valueOf( "10", 2 ), Constant.newIntegerLiteral( "0b10L" ).getValue() ); assertEquals( Long.valueOf( "10", 2 ), Constant.newIntegerLiteral( "0B10l" ).getValue() ); assertEquals( Long.valueOf( "10", 2 ), Constant.newIntegerLiteral( "0B10L" ).getValue() ); } @Test public void testOctalLong() { assertEquals( Long.valueOf( "0", 8 ), Constant.newIntegerLiteral( "00l" ).getValue() ); assertEquals( Long.valueOf( "0", 8 ), Constant.newIntegerLiteral( "00L" ).getValue() ); assertEquals( Long.valueOf( "0", 8 ), Constant.newIntegerLiteral( "000l" ).getValue() ); assertEquals( Long.valueOf( "0", 8 ), Constant.newIntegerLiteral( "000L" ).getValue() ); assertEquals( Long.valueOf( "10", 8 ), Constant.newIntegerLiteral( "010l" ).getValue() ); assertEquals( Long.valueOf( "10", 8 ), Constant.newIntegerLiteral( "010L" ).getValue() ); } @Test public void testDecimalLong() { assertEquals( Long.valueOf( "0" ), Constant.newIntegerLiteral( "0l" ).getValue() ); assertEquals( Long.valueOf( "0" ), Constant.newIntegerLiteral( "0L" ).getValue() ); assertEquals( Long.valueOf( "10" ), Constant.newIntegerLiteral( "10l" ).getValue() ); assertEquals( Long.valueOf( "10" ), Constant.newIntegerLiteral( "10L" ).getValue() ); } @Test public void testHexLong() { assertEquals( Long.valueOf( "0", 16 ), Constant.newIntegerLiteral( "0x0l" ).getValue() ); assertEquals( Long.valueOf( "0", 16 ), Constant.newIntegerLiteral( "0X0l" ).getValue() ); assertEquals( Long.valueOf( "0", 16 ), Constant.newIntegerLiteral( "0x0L" ).getValue() ); assertEquals( Long.valueOf( "0", 16 ), Constant.newIntegerLiteral( "0X0L" ).getValue() ); assertEquals( Long.valueOf( "0", 16 ), Constant.newIntegerLiteral( "0x00l" ).getValue() ); assertEquals( Long.valueOf( "0", 16 ), Constant.newIntegerLiteral( "0X00l" ).getValue() ); assertEquals( Long.valueOf( "0", 16 ), Constant.newIntegerLiteral( "0x00L" ).getValue() ); assertEquals( Long.valueOf( "0", 16 ), Constant.newIntegerLiteral( "0X00L" ).getValue() ); assertEquals( Long.valueOf( "10", 16 ), Constant.newIntegerLiteral( "0x10l" ).getValue() ); assertEquals( Long.valueOf( "10", 16 ), Constant.newIntegerLiteral( "0X10l" ).getValue() ); assertEquals( Long.valueOf( "10", 16 ), Constant.newIntegerLiteral( "0x10L" ).getValue() ); assertEquals( Long.valueOf( "10", 16 ), Constant.newIntegerLiteral( "0X10L" ).getValue() ); } @Test public void testBoolean() { assertEquals( Boolean.TRUE, Constant.newBooleanLiteral( "true" ).getValue() ); assertEquals( Boolean.FALSE, Constant.newBooleanLiteral( "false" ).getValue() ); } @Test public void testDecimalFloatingPoint() { assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( "0.0" ).getValue() ); assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( "0.0f" ).getValue() ); assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( "0.0F" ).getValue() ); assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( "000.0" ).getValue() ); assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( "000.0f" ).getValue() ); assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( "000.0F" ).getValue() ); assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( "0.000" ).getValue() ); assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( "0.000f" ).getValue() ); assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( "0.000F" ).getValue() ); assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( ".0" ).getValue() ); assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( ".0f" ).getValue() ); assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( ".0F" ).getValue() ); assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( ".00" ).getValue() ); assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( ".00f" ).getValue() ); assertEquals( Float.valueOf( "0.0" ), Constant.newFloatingPointLiteral( ".00F" ).getValue() ); assertEquals( Float.valueOf( "0" ), Constant.newFloatingPointLiteral( "0f" ).getValue() ); assertEquals( Float.valueOf( "0" ), Constant.newFloatingPointLiteral( "0F" ).getValue() ); } @Test public void testDecimalFloatingPointWithExponent() { assertEquals( Float.valueOf( "2.0e1" ), Constant.newFloatingPointLiteral( "2.0e1" ).getValue() ); assertEquals( Float.valueOf( "2.0e1" ), Constant.newFloatingPointLiteral( "2.0E1" ).getValue() ); assertEquals( Float.valueOf( "2.0e1" ), Constant.newFloatingPointLiteral( "2.0e1f" ).getValue() ); assertEquals( Float.valueOf( "2.0e1" ), Constant.newFloatingPointLiteral( "2.0E1f" ).getValue() ); assertEquals( Float.valueOf( "2.0e1" ), Constant.newFloatingPointLiteral( "2.0e1F" ).getValue() ); assertEquals( Float.valueOf( "2.0e1" ), Constant.newFloatingPointLiteral( "2.0E1F" ).getValue() ); assertEquals( Float.valueOf( "2.0e-1" ), Constant.newFloatingPointLiteral( "2.0e-1" ).getValue() ); assertEquals( Float.valueOf( "2.0e-1" ), Constant.newFloatingPointLiteral( "2.0E-1" ).getValue() ); assertEquals( Float.valueOf( "2.0e-1" ), Constant.newFloatingPointLiteral( "2.0e-1f" ).getValue() ); assertEquals( Float.valueOf( "2.0e-1" ), Constant.newFloatingPointLiteral( "2.0E-1f" ).getValue() ); assertEquals( Float.valueOf( "2.0e-1" ), Constant.newFloatingPointLiteral( "2.0e-1F" ).getValue() ); assertEquals( Float.valueOf( "2.0e-1" ), Constant.newFloatingPointLiteral( "2.0E-1F" ).getValue() ); assertEquals( Float.valueOf( "2.0e1" ), Constant.newFloatingPointLiteral( "2.0e+1" ).getValue() ); assertEquals( Float.valueOf( "2.0e1" ), Constant.newFloatingPointLiteral( "2.0E+1" ).getValue() ); assertEquals( Float.valueOf( "2.0e1" ), Constant.newFloatingPointLiteral( "2.0e+1f" ).getValue() ); assertEquals( Float.valueOf( "2.0e1" ), Constant.newFloatingPointLiteral( "2.0E+1f" ).getValue() ); assertEquals( Float.valueOf( "2.0e1" ), Constant.newFloatingPointLiteral( "2.0e+1F" ).getValue() ); assertEquals( Float.valueOf( "2.0e1" ), Constant.newFloatingPointLiteral( "2.0E+1F" ).getValue() ); assertEquals( Float.valueOf( ".2e1" ), Constant.newFloatingPointLiteral( ".2e1" ).getValue() ); assertEquals( Float.valueOf( ".2e1" ), Constant.newFloatingPointLiteral( ".2E1" ).getValue() ); assertEquals( Float.valueOf( ".2e1" ), Constant.newFloatingPointLiteral( ".2e1f" ).getValue() ); assertEquals( Float.valueOf( ".2e1" ), Constant.newFloatingPointLiteral( ".2E1f" ).getValue() ); assertEquals( Float.valueOf( ".2e1" ), Constant.newFloatingPointLiteral( ".2e1F" ).getValue() ); assertEquals( Float.valueOf( ".2e1" ), Constant.newFloatingPointLiteral( ".2E1F" ).getValue() ); assertEquals( Float.valueOf( ".2e-1" ), Constant.newFloatingPointLiteral( ".2e-1" ).getValue() ); assertEquals( Float.valueOf( ".2e-1" ), Constant.newFloatingPointLiteral( ".2E-1" ).getValue() ); assertEquals( Float.valueOf( ".2e-1" ), Constant.newFloatingPointLiteral( ".2e-1f" ).getValue() ); assertEquals( Float.valueOf( ".2e-1" ), Constant.newFloatingPointLiteral( ".2E-1f" ).getValue() ); assertEquals( Float.valueOf( ".2e-1" ), Constant.newFloatingPointLiteral( ".2e-1F" ).getValue() ); assertEquals( Float.valueOf( ".2e-1" ), Constant.newFloatingPointLiteral( ".2E-1F" ).getValue() ); assertEquals( Float.valueOf( ".2e1" ), Constant.newFloatingPointLiteral( ".2e+1" ).getValue() ); assertEquals( Float.valueOf( ".2e1" ), Constant.newFloatingPointLiteral( ".2E+1" ).getValue() ); assertEquals( Float.valueOf( ".2e1" ), Constant.newFloatingPointLiteral( ".2e+1f" ).getValue() ); assertEquals( Float.valueOf( ".2e1" ), Constant.newFloatingPointLiteral( ".2E+1f" ).getValue() ); assertEquals( Float.valueOf( ".2e1" ), Constant.newFloatingPointLiteral( ".2e+1F" ).getValue() ); assertEquals( Float.valueOf( ".2e1" ), Constant.newFloatingPointLiteral( ".2E+1F" ).getValue() ); assertEquals( Float.valueOf( "2e1" ), Constant.newFloatingPointLiteral( "2e1" ).getValue() ); assertEquals( Float.valueOf( "2e1" ), Constant.newFloatingPointLiteral( "2E1" ).getValue() ); assertEquals( Float.valueOf( "2e-1" ), Constant.newFloatingPointLiteral( "2e-1" ).getValue() ); assertEquals( Float.valueOf( "2e-1" ), Constant.newFloatingPointLiteral( "2E-1" ).getValue() ); assertEquals( Float.valueOf( "2e1" ), Constant.newFloatingPointLiteral( "2e+1" ).getValue() ); assertEquals( Float.valueOf( "2e1" ), Constant.newFloatingPointLiteral( "2E+1" ).getValue() ); } @Test public void testHexadecimalFloatingPoint() { assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0x2p1" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0X2p1" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0x2p1f" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0X2p1f" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0x2p1F" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0X2p1F" ).getValue() ); assertEquals( Float.valueOf( "0x2p-1" ), Constant.newFloatingPointLiteral( "0x2p-1" ).getValue() ); assertEquals( Float.valueOf( "0x2p-1" ), Constant.newFloatingPointLiteral( "0X2p-1" ).getValue() ); assertEquals( Float.valueOf( "0x2p-1" ), Constant.newFloatingPointLiteral( "0x2p-1f" ).getValue() ); assertEquals( Float.valueOf( "0x2p-1" ), Constant.newFloatingPointLiteral( "0X2p-1f" ).getValue() ); assertEquals( Float.valueOf( "0x2p-1" ), Constant.newFloatingPointLiteral( "0x2p-1F" ).getValue() ); assertEquals( Float.valueOf( "0x2p-1" ), Constant.newFloatingPointLiteral( "0X2p-1F" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0x2p+1" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0X2p+1" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0x2p+1f" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0X2p+1f" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0x2p+1F" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0X2p+1F" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0x2.p1" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0X2.p1" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0x2.p1f" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0X2.p1f" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0x2.p1F" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0X2.p1F" ).getValue() ); assertEquals( Float.valueOf( "0x2p-1" ), Constant.newFloatingPointLiteral( "0x2.p-1" ).getValue() ); assertEquals( Float.valueOf( "0x2p-1" ), Constant.newFloatingPointLiteral( "0X2.p-1" ).getValue() ); assertEquals( Float.valueOf( "0x2p-1" ), Constant.newFloatingPointLiteral( "0x2.p-1f" ).getValue() ); assertEquals( Float.valueOf( "0x2p-1" ), Constant.newFloatingPointLiteral( "0X2.p-1f" ).getValue() ); assertEquals( Float.valueOf( "0x2p-1" ), Constant.newFloatingPointLiteral( "0x2.p-1F" ).getValue() ); assertEquals( Float.valueOf( "0x2p-1" ), Constant.newFloatingPointLiteral( "0X2.p-1F" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0x2.p+1" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0X2.p+1" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0x2.p+1f" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0X2.p+1f" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0x2.p+1F" ).getValue() ); assertEquals( Float.valueOf( "0x2p1" ), Constant.newFloatingPointLiteral( "0X2.p+1F" ).getValue() ); assertEquals( Float.valueOf( "0x.2p1" ), Constant.newFloatingPointLiteral( "0x.2p1" ).getValue() ); assertEquals( Float.valueOf( "0x.2p1" ), Constant.newFloatingPointLiteral( "0X.2p1" ).getValue() ); assertEquals( Float.valueOf( "0x.2p1" ), Constant.newFloatingPointLiteral( "0x.2p1f" ).getValue() ); assertEquals( Float.valueOf( "0x.2p1" ), Constant.newFloatingPointLiteral( "0X.2p1f" ).getValue() ); assertEquals( Float.valueOf( "0x.2p1" ), Constant.newFloatingPointLiteral( "0x.2p1F" ).getValue() ); assertEquals( Float.valueOf( "0x.2p1" ), Constant.newFloatingPointLiteral( "0X.2p1F" ).getValue() ); assertEquals( Float.valueOf( "0x.2p-1" ), Constant.newFloatingPointLiteral( "0x.2p-1" ).getValue() ); assertEquals( Float.valueOf( "0x.2p-1" ), Constant.newFloatingPointLiteral( "0X.2p-1" ).getValue() ); assertEquals( Float.valueOf( "0x.2p-1" ), Constant.newFloatingPointLiteral( "0x.2p-1f" ).getValue() ); assertEquals( Float.valueOf( "0x.2p-1" ), Constant.newFloatingPointLiteral( "0X.2p-1f" ).getValue() ); assertEquals( Float.valueOf( "0x.2p-1" ), Constant.newFloatingPointLiteral( "0x.2p-1F" ).getValue() ); assertEquals( Float.valueOf( "0x.2p-1" ), Constant.newFloatingPointLiteral( "0X.2p-1F" ).getValue() ); assertEquals( Float.valueOf( "0x.2p1" ), Constant.newFloatingPointLiteral( "0x.2p+1" ).getValue() ); assertEquals( Float.valueOf( "0x.2p1" ), Constant.newFloatingPointLiteral( "0X.2p+1" ).getValue() ); assertEquals( Float.valueOf( "0x.2p1" ), Constant.newFloatingPointLiteral( "0x.2p+1f" ).getValue() ); assertEquals( Float.valueOf( "0x.2p1" ), Constant.newFloatingPointLiteral( "0X.2p+1f" ).getValue() ); assertEquals( Float.valueOf( "0x.2p1" ), Constant.newFloatingPointLiteral( "0x.2p+1F" ).getValue() ); assertEquals( Float.valueOf( "0x.2p1" ), Constant.newFloatingPointLiteral( "0X.2p+1F" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p1" ), Constant.newFloatingPointLiteral( "0x3.2p1" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p1" ), Constant.newFloatingPointLiteral( "0X3.2p1" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p1" ), Constant.newFloatingPointLiteral( "0x3.2p1f" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p1" ), Constant.newFloatingPointLiteral( "0X3.2p1f" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p1" ), Constant.newFloatingPointLiteral( "0x3.2p1F" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p1" ), Constant.newFloatingPointLiteral( "0X3.2p1F" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p-1" ), Constant.newFloatingPointLiteral( "0x3.2p-1" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p-1" ), Constant.newFloatingPointLiteral( "0X3.2p-1" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p-1" ), Constant.newFloatingPointLiteral( "0x3.2p-1f" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p-1" ), Constant.newFloatingPointLiteral( "0X3.2p-1f" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p-1" ), Constant.newFloatingPointLiteral( "0x3.2p-1F" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p-1" ), Constant.newFloatingPointLiteral( "0X3.2p-1F" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p1" ), Constant.newFloatingPointLiteral( "0x3.2p+1" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p1" ), Constant.newFloatingPointLiteral( "0X3.2p+1" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p1" ), Constant.newFloatingPointLiteral( "0x3.2p+1f" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p1" ), Constant.newFloatingPointLiteral( "0X3.2p+1f" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p1" ), Constant.newFloatingPointLiteral( "0x3.2p+1F" ).getValue() ); assertEquals( Float.valueOf( "0x3.2p1" ), Constant.newFloatingPointLiteral( "0X3.2p+1F" ).getValue() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/DivideTest.java000066400000000000000000000024751325201777200307750ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class DivideTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); Divide expr = new Divide( lhs, rhs ); assertEquals( "2 / 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); Divide expr = new Divide( lhs, rhs ); assertEquals( lhs + " / " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); Divide expr = new Divide( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/EqualsTest.java000066400000000000000000000024771325201777200310250ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class EqualsTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); Equals expr = new Equals( lhs, rhs ); assertEquals( "2 == 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); Equals expr = new Equals( lhs, rhs ); assertEquals( lhs + " == " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); Equals expr = new Equals( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/ExclusiveOrTest.java000066400000000000000000000025401325201777200320320ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class ExclusiveOrTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); ExclusiveOr expr = new ExclusiveOr( lhs, rhs ); assertEquals( "2 ^ 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); ExclusiveOr expr = new ExclusiveOr( lhs, rhs ); assertEquals( lhs + " ^ " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); ExclusiveOr expr = new ExclusiveOr( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/FieldRefTest.java000066400000000000000000000017131325201777200312430ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class FieldRefTest { @Test public void testParameterValue() { FieldRef expr = new FieldRef( "aField" ); assertEquals( "aField", expr.getParameterValue() ); } @Test public void testToString() { FieldRef expr = new FieldRef( "aField" ); assertEquals( "aField", expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); FieldRef expr = new FieldRef( "" ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/GreaterEqualsTest.java000066400000000000000000000025601325201777200323300ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class GreaterEqualsTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); GreaterEquals expr = new GreaterEquals( lhs, rhs ); assertEquals( "2 >= 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); GreaterEquals expr = new GreaterEquals( lhs, rhs ); assertEquals( lhs + " >= " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); GreaterEquals expr = new GreaterEquals( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/GreaterThanTest.java000066400000000000000000000025401325201777200317660ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class GreaterThanTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); GreaterThan expr = new GreaterThan( lhs, rhs ); assertEquals( "2 > 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); GreaterThan expr = new GreaterThan( lhs, rhs ); assertEquals( lhs + " > " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); GreaterThan expr = new GreaterThan( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/LessEqualsTest.java000066400000000000000000000025331325201777200316450ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class LessEqualsTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); LessEquals expr = new LessEquals( lhs, rhs ); assertEquals( "2 <= 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); LessEquals expr = new LessEquals( lhs, rhs ); assertEquals( lhs + " <= " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); LessEquals expr = new LessEquals( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/LessThanTest.java000066400000000000000000000025131325201777200313030ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class LessThanTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); LessThan expr = new LessThan( lhs, rhs ); assertEquals( "2 < 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); LessThan expr = new LessThan( lhs, rhs ); assertEquals( lhs + " < " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); LessThan expr = new LessThan( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/LogicalAndTest.java000066400000000000000000000025311325201777200315570ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class LogicalAndTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); LogicalAnd expr = new LogicalAnd( lhs, rhs ); assertEquals( "2 && 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); LogicalAnd expr = new LogicalAnd( lhs, rhs ); assertEquals( lhs + " && " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); LogicalAnd expr = new LogicalAnd( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/LogicalNotTest.java000066400000000000000000000022321325201777200316130ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class LogicalNotTest { @Test public void testParameterValue() { AnnotationValue value = mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "valid" ); LogicalNot expr = new LogicalNot( value ); assertEquals( "!valid", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue value = mock( AnnotationValue.class ); LogicalNot expr = new LogicalNot( value ); assertEquals( "!" + value, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); LogicalNot expr = new LogicalNot( null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/LogicalOrTest.java000066400000000000000000000025241325201777200314370ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class LogicalOrTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); LogicalOr expr = new LogicalOr( lhs, rhs ); assertEquals( "2 || 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); LogicalOr expr = new LogicalOr( lhs, rhs ); assertEquals( lhs + " || " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); LogicalOr expr = new LogicalOr( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/MinusSignTest.java000066400000000000000000000022131325201777200314730ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class MinusSignTest { @Test public void testParameterValue() { AnnotationValue value = mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "2" ); MinusSign expr = new MinusSign( value ); assertEquals( "-2", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue value = mock( AnnotationValue.class ); MinusSign expr = new MinusSign( value ); assertEquals( "-" + value, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); MinusSign expr = new MinusSign( null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/MultiplyTest.java000066400000000000000000000025131325201777200314010ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class MultiplyTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); Multiply expr = new Multiply( lhs, rhs ); assertEquals( "2 * 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); Multiply expr = new Multiply( lhs, rhs ); assertEquals( lhs + " * " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); Multiply expr = new Multiply( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/NotEqualsTest.java000066400000000000000000000025241325201777200314770ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class NotEqualsTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); NotEquals expr = new NotEquals( lhs, rhs ); assertEquals( "2 != 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); NotEquals expr = new NotEquals( lhs, rhs ); assertEquals( lhs + " != " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); NotEquals expr = new NotEquals( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/NotTest.java000066400000000000000000000021511325201777200303200ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class NotTest { @Test public void testParameterValue() { AnnotationValue value = mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "valid" ); Not expr = new Not( value ); assertEquals( "~valid", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue value = mock( AnnotationValue.class ); Not expr = new Not( value ); assertEquals( "~" + value, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); Not expr = new Not( null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/OrTest.java000066400000000000000000000024411325201777200301420ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class OrTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); Or expr = new Or( lhs, rhs ); assertEquals( "2 | 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); Or expr = new Or( lhs, rhs ); assertEquals( lhs + " | " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); Or expr = new Or( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/ParenExpressionTest.java000066400000000000000000000023161325201777200327100ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class ParenExpressionTest { @Test public void testParameterValue() { AnnotationValue value = mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "expression" ); ParenExpression expr = new ParenExpression( value ); assertEquals( "(expression)", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue value = mock( AnnotationValue.class ); ParenExpression expr = new ParenExpression( value ); assertEquals( "(" + value + ")", expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); ParenExpression expr = new ParenExpression( null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/PlusSignTest.java000066400000000000000000000022041325201777200313230ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class PlusSignTest { @Test public void testParameterValue() { AnnotationValue value = mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "2" ); PlusSign expr = new PlusSign( value ); assertEquals( "+2", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue value = mock( AnnotationValue.class ); PlusSign expr = new PlusSign( value ); assertEquals( "+" + value, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); PlusSign expr = new PlusSign( null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/PostDecrementTest.java000066400000000000000000000023701325201777200323370ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class PostDecrementTest { @Test public void testParameterValue() { AnnotationValue value = mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "index" ); PostDecrement expr = new PostDecrement( value ); assertEquals( "index--", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue value = mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "index" ); PostDecrement expr = new PostDecrement( value ); assertEquals( value.toString() + "--", expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); PostDecrement expr = new PostDecrement( null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/PostIncrementTest.java000066400000000000000000000023721325201777200323570ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class PostIncrementTest { @Test public void testParameterValue() { AnnotationValue value = mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "index" ); PostIncrement expr = new PostIncrement( value ); assertEquals( "index++", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue value = mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "index" ); PostIncrement expr = new PostIncrement( value ); assertEquals( value.toString() + "++", expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); PostIncrement expr = new PostIncrement( null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/PreDecrementTest.java000066400000000000000000000023611325201777200321400ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class PreDecrementTest { @Test public void testParameterValue() { AnnotationValue value = mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "index" ); PreDecrement expr = new PreDecrement( value ); assertEquals( "--index", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue value = mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "index" ); PreDecrement expr = new PreDecrement( value ); assertEquals( "--" + value.toString(), expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); PreDecrement expr = new PreDecrement( null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/PreIncrementTest.java000066400000000000000000000023611325201777200321560ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class PreIncrementTest { @Test public void testParameterValue() { AnnotationValue value = mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "index" ); PreIncrement expr = new PreIncrement( value ); assertEquals( "++index", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue value = mock( AnnotationValue.class ); when( value.getParameterValue() ).thenReturn( "index" ); PreIncrement expr = new PreIncrement( value ); assertEquals( "++" + value.toString(), expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); PreIncrement expr = new PreIncrement( null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/QueryTest.java000066400000000000000000000032541325201777200306720ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class QueryTest { @Test public void testParameterValue() { AnnotationValue condition = mock( AnnotationValue.class ); AnnotationValue trueExpr = mock( AnnotationValue.class ); AnnotationValue falseExpr = mock( AnnotationValue.class ); when( condition.getParameterValue() ).thenReturn( "predicate" ); when( trueExpr.getParameterValue() ).thenReturn( "consequent" ); when( falseExpr.getParameterValue() ).thenReturn( "alternative" ); Query expr = new Query( condition, trueExpr, falseExpr ); assertEquals( "predicate ? consequent : alternative", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue condition = mock( AnnotationValue.class ); AnnotationValue trueExpr = mock( AnnotationValue.class ); AnnotationValue falseExpr = mock( AnnotationValue.class ); Query expr = new Query( condition, trueExpr, falseExpr ); assertEquals( condition + " ? " + trueExpr + " : " + falseExpr, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); Query expr = new Query( null, null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/RemainderTest.java000066400000000000000000000025221325201777200314700ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class RemainderTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); Remainder expr = new Remainder( lhs, rhs ); assertEquals( "2 * 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); Remainder expr = new Remainder( lhs, rhs ); assertEquals( lhs + " * " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); Remainder expr = new Remainder( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/ShiftLeftTest.java000066400000000000000000000025261325201777200314560ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class ShiftLeftTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); ShiftLeft expr = new ShiftLeft( lhs, rhs ); assertEquals( "2 << 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); ShiftLeft expr = new ShiftLeft( lhs, rhs ); assertEquals( lhs + " << " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); ShiftRight expr = new ShiftRight( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/ShiftRightTest.java000066400000000000000000000025331325201777200316370ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class ShiftRightTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); ShiftRight expr = new ShiftRight( lhs, rhs ); assertEquals( "2 >> 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); ShiftRight expr = new ShiftRight( lhs, rhs ); assertEquals( lhs + " >> " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); ShiftRight expr = new ShiftRight( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/SubtractTest.java000066400000000000000000000025111325201777200313470ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class SubtractTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); Subtract expr = new Subtract( lhs, rhs ); assertEquals( "2 - 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); Subtract expr = new Subtract( lhs, rhs ); assertEquals( lhs + " - " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); Subtract expr = new Subtract( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/expression/UnsignedShiftRightTest.java000066400000000000000000000025341325201777200333350ustar00rootroot00000000000000package com.thoughtworks.qdox.model.expression; import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; public class UnsignedShiftRightTest { @Test public void testParameterValue() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); when( lhs.getParameterValue() ).thenReturn( "2" ); when( rhs.getParameterValue() ).thenReturn( "3" ); UnsignedShiftRight expr = new UnsignedShiftRight( lhs, rhs ); assertEquals( "2 >>> 3", expr.getParameterValue() ); } @Test public void testToString() { AnnotationValue lhs = mock( AnnotationValue.class ); AnnotationValue rhs = mock( AnnotationValue.class ); UnsignedShiftRight expr = new UnsignedShiftRight( lhs, rhs ); assertEquals( lhs + " >>> " + rhs, expr.toString() ); } @Test public void testAccept() { ExpressionVisitor visitor = mock( ExpressionVisitor.class ); UnsignedShiftRight expr = new UnsignedShiftRight( null, null ); Object visitResult = new Object(); when( visitor.visit( expr ) ).thenReturn( visitResult ); assertSame( expr.accept( visitor ), visitResult ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/impl/000077500000000000000000000000001325201777200246205ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/impl/AbstractJavaEntityTest.java000066400000000000000000000110111325201777200320570ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.Arrays; import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.junit.Test; import com.thoughtworks.qdox.model.DocletTag; public class AbstractJavaEntityTest { private AbstractJavaEntity newAbstractJavaEntity() { return new AbstractJavaEntity() { public String getCodeBlock() { return null; } }; } @Test public void testGetTagsByNameMethod() { AbstractBaseJavaEntity entity = newAbstractJavaEntity(); List tags = new LinkedList(); DocletTag monkeyIsGoodTag = mock(DocletTag.class); when(monkeyIsGoodTag.getName()).thenReturn( "monkey" ); DocletTag monkeyIsFunnyTag = mock(DocletTag.class); when(monkeyIsFunnyTag.getName()).thenReturn( "monkey" ); DocletTag horseNotSoMuchTag = mock(DocletTag.class); when(horseNotSoMuchTag.getName()).thenReturn( "horse" ); tags.add(monkeyIsGoodTag); tags.add(monkeyIsFunnyTag); tags.add(horseNotSoMuchTag); entity.setTags(tags); assertEquals(2, entity.getTagsByName("monkey").size()); assertEquals(1, entity.getTagsByName("horse").size()); assertEquals(0, entity.getTagsByName("non existent tag").size()); } @Test public void testGetSingleTagByName() { AbstractBaseJavaEntity entity = newAbstractJavaEntity(); List tags = new LinkedList(); DocletTag monkeyIsGoodTag = mock(DocletTag.class); when(monkeyIsGoodTag.getName()).thenReturn( "monkey" ); when(monkeyIsGoodTag.getValue()).thenReturn( "is good" ); DocletTag monkeyIsFunnyTag = mock(DocletTag.class); when(monkeyIsFunnyTag.getName()).thenReturn( "monkey" ); when(monkeyIsFunnyTag.getValue()).thenReturn( "is funny" ); DocletTag horseNotSoMuchTag = mock(DocletTag.class); when(horseNotSoMuchTag.getName()).thenReturn( "horse" ); when(horseNotSoMuchTag.getValue()).thenReturn( "not so much" ); tags.add(monkeyIsGoodTag); tags.add(monkeyIsFunnyTag); tags.add(horseNotSoMuchTag); entity.setTags(tags); assertEquals("is good", entity.getTagByName("monkey").getValue()); assertEquals("not so much", entity.getTagByName("horse").getValue()); assertNull(entity.getTagByName("cow")); } @Test public void testPublicModifer() { AbstractJavaEntity entity = newAbstractJavaEntity(); entity.setModifiers( Collections.singletonList( "public" ) ); assertTrue( entity.isPublic() ); } @Test public void testPrivateModifer() { AbstractJavaEntity entity = newAbstractJavaEntity(); entity.setModifiers(Collections.singletonList( "private" )); assertTrue(entity.isPrivate()); } @Test public void testAbstractModifer() { AbstractJavaEntity entity = newAbstractJavaEntity(); entity.setModifiers(Arrays.asList(new String[]{"public", "abstract"})); assertTrue(entity.isAbstract()); assertTrue(!entity.isPrivate()); } @Test public void testProtectedModifer() { AbstractJavaEntity entity = newAbstractJavaEntity(); entity.setModifiers(Arrays.asList(new String[]{"protected", "abstract", "synchronized", "transient"})); assertTrue(entity.isProtected()); assertTrue(entity.isSynchronized()); assertTrue(entity.isTransient()); } @Test public void testStaticModifer() { AbstractJavaEntity entity = newAbstractJavaEntity(); entity.setModifiers(Arrays.asList(new String[]{"public", "static", "final"})); assertTrue(entity.isStatic()); assertTrue(entity.isFinal()); } @Test public void testQDOX30() { AbstractJavaEntity entity = newAbstractJavaEntity(); entity.setModifiers(Arrays.asList(new String[]{"native", "volatile", "strictfp"})); assertTrue(entity.isNative()); assertTrue(entity.isVolatile()); assertTrue(entity.isStrictfp()); } @Test public void testGetTagsReturnsEmptyArrayInsteadOfNull() { AbstractJavaEntity entity = newAbstractJavaEntity(); assertEquals(0, entity.getTags().size()); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/impl/DefaultDocletTagTest.java000066400000000000000000000020001325201777200314660ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import java.util.Map; import com.thoughtworks.qdox.model.AbstractDocletTagTest; import com.thoughtworks.qdox.model.DocletTagFactory; import com.thoughtworks.qdox.model.util.SerializationUtils; /** * * @author Aslak Hellesøy * @version $Revision$ */ public class DefaultDocletTagTest extends AbstractDocletTagTest { public DefaultDocletTagTest(String name) { super(name); } private final DocletTagFactory docletTagFactory = new DefaultDocletTagFactory(); @Override protected DocletTagFactory getDocletTagFactory() { return docletTagFactory; } public void testJiraQdox60() { DefaultDocletTag tag = new DefaultDocletTag("author", "Excalibur Development Team"); tag = (DefaultDocletTag) SerializationUtils.serializedCopy(tag); Map paramMap = tag.getNamedParameterMap(); assertEquals(0, paramMap.size()); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/impl/DefaultJavaClassIT.java000066400000000000000000000114251325201777200310770ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; import com.thoughtworks.qdox.library.ClassLoaderLibrary; import com.thoughtworks.qdox.model.BeanProperty; import com.thoughtworks.qdox.model.JavaClass; public class DefaultJavaClassIT { private ClassLoaderLibrary library; @Before public void setUp() { library = new ClassLoaderLibrary( null ); library.addDefaultLoader(); } @Test public void testSuperJavaClass() throws Exception { JavaClass hashSetClass = library.getJavaClass( "java.util.HashSet" ); assertTrue( hashSetClass instanceof DefaultJavaClass ); JavaClass superClass = hashSetClass.getSuperJavaClass(); assertEquals( "java.util.AbstractSet", superClass.getFullyQualifiedName() ); assertEquals( "java.util.AbstractSet", Class.forName( "java.util.HashSet" ).getSuperclass().getName() ); } @Test public void testIsAJavaClass() throws Exception { JavaClass hashSetClass = library.getJavaClass( "java.util.HashSet" ); assertTrue( hashSetClass instanceof DefaultJavaClass ); JavaClass setClass = library.getJavaClass( "java.util.Set" ); assertTrue( hashSetClass.isA( setClass ) ); assertTrue( hashSetClass.isA( "java.util.Set" ) ); //watch it!! isA() is the inverse of isAssignableFrom() assertTrue( Class.forName( "java.util.Set" ).isAssignableFrom( Class.forName( "java.util.HashSet" ) ) ); } @Test public void testDeclaringClass() throws Exception { JavaClass entryClass = library.getJavaClass( "java.util.Map$Entry" ); assertTrue( entryClass instanceof DefaultJavaClass ); assertEquals( "java.util.Map", entryClass.getDeclaringClass().getFullyQualifiedName() ); assertEquals( "java.util.Map", Class.forName( "java.util.Map$Entry" ).getDeclaringClass().getName() ); } @Test public void testDeclaredClasses() throws Exception { JavaClass mapClass = library.getJavaClass( "java.util.Map" ); assertTrue( mapClass instanceof DefaultJavaClass ); assertEquals( 1, mapClass.getNestedClasses().size() ); assertEquals( "java.util.Map$Entry", mapClass.getNestedClassByName( "Entry" ).getBinaryName() ); assertEquals( "java.util.Map.Entry", mapClass.getNestedClassByName( "Entry" ).getFullyQualifiedName() ); assertEquals( 1, Class.forName( "java.util.Map" ).getDeclaredClasses().length ); assertEquals( "java.util.Map$Entry", Class.forName( "java.util.Map" ).getDeclaredClasses()[0].getName() ); } @Test public void testBeanProperty() throws Exception { JavaClass entryClass = library.getJavaClass( "java.util.Map$Entry" ); BeanProperty valueBean = entryClass.getBeanProperty( "value" ); assertNotNull( valueBean ); assertEquals( "java.lang.Object", valueBean.getType().getFullyQualifiedName() ); assertNotNull( valueBean.getAccessor() ); assertEquals( "public abstract java.lang.Object java.util.Map$Entry.getValue()", Class.forName( "java.util.Map$Entry" ).getMethod("getValue").toString() ); assertEquals( "public abstract java.lang.Object java.util.Map$Entry.getValue()", valueBean.getAccessor().toString() ); assertNotNull( valueBean.getMutator() ); assertEquals( "public abstract java.lang.Object java.util.Map$Entry.setValue(java.lang.Object)", valueBean.getMutator().toString() ); BeanProperty keyBean = entryClass.getBeanProperty( "key" ); assertNotNull( keyBean.getAccessor() ); assertEquals( "public abstract java.lang.Object java.util.Map$Entry.getKey()", keyBean.getAccessor().toString() ); assertNull( keyBean.getMutator() ); } @Test public void testNames() throws Exception { //subclass JavaClass entryClass = library.getJavaClass( "java.util.Map$Entry" ); assertTrue( entryClass instanceof DefaultJavaClass ); assertEquals( "java.util.Map$Entry", entryClass.getBinaryName() ); assertEquals( "java.util.Map.Entry", entryClass.getFullyQualifiedName() ); assertEquals( "java.util.Map$Entry", Class.forName( "java.util.Map$Entry" ).getName() ); assertEquals( "java.util.Map.Entry", entryClass.getCanonicalName() ); assertEquals( "java.util.Map.Entry", Class.forName( "java.util.Map$Entry" ).getCanonicalName() ); assertEquals( "Map.Entry", entryClass.getValue() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/impl/DefaultJavaClassTest.java000066400000000000000000000063561325201777200315110ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import java.util.List; import com.thoughtworks.qdox.library.SortedClassLibraryBuilder; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaClassTest; import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaSource; import com.thoughtworks.qdox.model.JavaType; public class DefaultJavaClassTest extends JavaClassTest { @Override public DefaultJavaClass newJavaClass() { return new DefaultJavaClass(); } @Override public DefaultJavaClass newJavaClass( String name ) { return new DefaultJavaClass( name ); } @Override public JavaSource newJavaSource() { return new DefaultJavaSource(new SortedClassLibraryBuilder().getClassLibrary()); } // Add-methods @Override public void setClasses( DefaultJavaClass clazz, List innerClasses ) { for( JavaClass innerClazz : innerClasses ) { clazz.addClass( innerClazz ); } } @Override public void addClass( JavaSource source, JavaClass clazz ) { ((DefaultJavaClass) clazz).setSource( source ); ((DefaultJavaSource) source).addClass( clazz ); } // Set-methods @Override public void setComment( DefaultJavaClass clazz, String comment ) { clazz.setComment( comment ); } @Override public void setDeclaringClass( DefaultJavaClass clazz, JavaClass declaringClazz ) { clazz.setDeclaringClass( declaringClazz ); } @Override public void setEnum( DefaultJavaClass clazz, boolean isEnum ) { clazz.setEnum( isEnum ); } @Override public void setImplementz( DefaultJavaClass clazz, List implementz ) { clazz.setImplementz( implementz ); } @Override public void setInterface( DefaultJavaClass clazz, boolean isInterface ) { clazz.setInterface( isInterface ); } @Override public void setModifiers( DefaultJavaClass clazz, List modifiers ) { clazz.setModifiers( modifiers ); } @Override public void setName( DefaultJavaClass clazz, String name ) { clazz.setName( name ); } @Override public void setPackage( DefaultJavaClass clazz, JavaPackage pckg ) { clazz.setJavaPackage( pckg ); } @Override public void setPackage( JavaSource source, JavaPackage pckg ) { ((DefaultJavaSource) source).setPackage( pckg ); } @Override public void setSuperClass( DefaultJavaClass clazz, JavaType type ) { clazz.setSuperClass( type ); } @Override public void setFields( DefaultJavaClass clazz, List fields ) { for(JavaField field : fields) { clazz.addField( field ); } } @Override public void setSource( DefaultJavaClass clazz, JavaSource source ) { clazz.setSource( source ); } @Override public void setMethods( DefaultJavaClass clazz, List methods ) { for(JavaMethod method : methods) { clazz.addMethod( method ); } } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/impl/DefaultJavaConstructorTest.java000066400000000000000000000020771325201777200327650ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import java.util.List; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaConstructorTest; import com.thoughtworks.qdox.model.JavaParameter; public class DefaultJavaConstructorTest extends JavaConstructorTest { @Override protected DefaultJavaConstructor newJavaConstructor( String name ) { DefaultJavaConstructor result = new DefaultJavaConstructor(); result.setName( name ); return result; } @Override protected void setModifiers( DefaultJavaConstructor constructor, List modifiers ) { constructor.setModifiers( modifiers ); } @Override protected void setParameters( DefaultJavaConstructor constructor, List parameters ) { constructor.setParameters( parameters ); } @Override protected void setDeclaringClass( DefaultJavaConstructor constructor, JavaClass parentClass ) { constructor.setDeclaringClass( parentClass ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/impl/DefaultJavaFieldTest.java000066400000000000000000000031761325201777200314640ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import java.util.List; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaFieldTest; import com.thoughtworks.qdox.model.JavaSource; public class DefaultJavaFieldTest extends JavaFieldTest { public DefaultJavaFieldTest( String s ) { super( s ); } @Override public DefaultJavaField newJavaField() { JavaSource source = new DefaultJavaSource( null ); JavaClass javaClass = new DefaultJavaClass( source ); DefaultJavaField result = new DefaultJavaField( "NAME" ); result.setDeclaringClass( javaClass ); return result; } @Override public DefaultJavaField newJavaField( JavaClass type, String name ) { return new DefaultJavaField( type, name ); } @Override public void setComment( DefaultJavaField fld, String comment ) { fld.setComment( comment ); } @Override public void setInitializationExpression( DefaultJavaField fld, String expression ) { fld.setInitializationExpression( expression ); } @Override public void setModifiers( DefaultJavaField fld, List modifiers ) { fld.setModifiers( modifiers ); } @Override public void setName( DefaultJavaField fld, String name ) { fld.setName( name ); } @Override public void setType( DefaultJavaField fld, JavaClass type ) { fld.setType( type ); } @Override public void setDeclaringClass( DefaultJavaField fld, JavaClass cls ) { fld.setDeclaringClass( cls ); } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/impl/DefaultJavaMethodTest.java000066400000000000000000000033251325201777200316550ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import java.util.List; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaMethodTest; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.impl.DefaultJavaMethod; public class DefaultJavaMethodTest extends JavaMethodTest { @Override public DefaultJavaMethod newJavaMethod() { return new DefaultJavaMethod(); } @Override public DefaultJavaMethod newJavaMethod( JavaClass returns, String name ) { return new DefaultJavaMethod( returns, name ); } @Override public void setExceptions( DefaultJavaMethod method, List exceptions ) { method.setExceptions( exceptions ); } @Override public void setComment( DefaultJavaMethod method, String comment ) { method.setComment( comment ); } @Override public void setName( DefaultJavaMethod method, String name ) { method.setName( name ); } @Override public void setModifiers( DefaultJavaMethod method, List modifiers ) { method.setModifiers( modifiers ); } @Override public void setReturns( DefaultJavaMethod method, JavaClass type ) { method.setReturns( type ); } @Override public void setDeclaringClass( DefaultJavaMethod method, JavaClass clazz ) { method.setDeclaringClass( clazz ); } @Override public void setParameters( DefaultJavaMethod method, List parameters ) { method.setParameters( parameters ); } @Override public void setSourceCode( DefaultJavaMethod method, String code ) { method.setSourceCode( code ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/impl/DefaultJavaPackageTest.java000066400000000000000000000007711325201777200317720ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import static org.mockito.Mockito.*; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.model.JavaPackageTest; public class DefaultJavaPackageTest extends JavaPackageTest { @Override public DefaultJavaPackage newJavaPackage( String name ) { DefaultJavaPackage result = new DefaultJavaPackage( name ); result.setClassLibrary( mock(ClassLibrary.class) ); return result; } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/impl/DefaultJavaParameterTest.java000066400000000000000000000016051325201777200323540ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaExecutable; import com.thoughtworks.qdox.model.JavaParameterTest; public class DefaultJavaParameterTest extends JavaParameterTest { public DefaultJavaParameterTest( String s ) { super( s ); } @Override protected DefaultJavaParameter newJavaParameter( JavaClass type, String name ) { return new DefaultJavaParameter( type, name ); } @Override protected DefaultJavaParameter newJavaParameter( JavaClass type, String name, boolean varArgs ) { return new DefaultJavaParameter( type, name, varArgs ); } @Override protected void setJavaExecutable( DefaultJavaParameter parameter, JavaExecutable executable ) { parameter.setExecutable( executable ); } }DefaultJavaParameterizedTypeTest.java000066400000000000000000000166211325201777200340170ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/implpackage com.thoughtworks.qdox.model.impl; import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import java.lang.reflect.Field; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; import org.junit.Before; import org.junit.Test; import com.thoughtworks.qdox.library.ClassLoaderLibrary; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.type.TypeResolver; public class DefaultJavaParameterizedTypeTest { // Fields to verify if reflection acts the same public List listOfString; public List[] listOfStringArray; public List[][] listOfStringArrayArray; public Map.Entry mapEntryIntegerForString; private TypeResolver typeResolver; @Before public void initMocks() { ClassLoaderLibrary classLibrary = new ClassLoaderLibrary( null ); classLibrary.addDefaultLoader(); typeResolver = TypeResolver.byPackageName( null, classLibrary , null ); } @SuppressWarnings( "unchecked" ) @Test public void testListOfString() throws Exception { DefaultJavaParameterizedType type = new DefaultJavaParameterizedType( "java.util.List", "List", 0, typeResolver ); DefaultJavaType genType = new DefaultJavaType( "java.lang.String", "String", 0, typeResolver ); type.setActualArgumentTypes( Collections.singletonList( genType ) ); Field field = DefaultJavaParameterizedTypeTest.class.getField( "listOfString" ); assertEquals( "List", type.getValue() ); assertEquals( "List", type.getGenericValue() ); assertEquals( "java.util.List", type.getBinaryName() ); assertEquals( "java.util.List", type.getFullyQualifiedName() ); // Also compare with reflect implementations assertThat( type.getSimpleName(), allOf( equalTo("List"), equalTo(field.getType().getSimpleName()))); assertThat( type.getCanonicalName(), allOf( equalTo("java.util.List"), equalTo(field.getType().getCanonicalName()))); // Requires Java8 assertThat( type.getGenericCanonicalName(), allOf( equalTo("java.util.List")/*, equalTo(field.getGenericType().getTypeName())*/)); } @SuppressWarnings( "unchecked" ) @Test public void testListOfStringArray() throws Exception { DefaultJavaParameterizedType type = new DefaultJavaParameterizedType( "java.util.List", "List", 1, typeResolver ); DefaultJavaType genType = new DefaultJavaType( "java.lang.String", "String", 0, typeResolver ); type.setActualArgumentTypes( Collections.singletonList( genType ) ); Field field = DefaultJavaParameterizedTypeTest.class.getField( "listOfStringArray" ); assertEquals( "List[]", type.getValue() ); assertEquals( "List[]", type.getGenericValue() ); assertEquals( "java.util.List", type.getBinaryName() ); assertEquals( "java.util.List[]", type.getFullyQualifiedName() ); // Also compare with reflect implementations assertThat( type.getSimpleName(), allOf( equalTo("List[]"), equalTo(field.getType().getSimpleName()))); assertThat( type.getCanonicalName(), allOf( equalTo("java.util.List[]"), equalTo(field.getType().getCanonicalName()))); // requires java8 assertThat( type.getGenericCanonicalName(), allOf( equalTo("java.util.List[]")/*, equalTo(field.getGenericType().getTypeName())*/)); assertThat( type.getComponentType().getSimpleName(), allOf( equalTo("List"), equalTo(field.getType().getComponentType().getSimpleName()))); assertThat( type.getComponentType().getCanonicalName(), allOf( equalTo("java.util.List"), equalTo(field.getType().getComponentType().getCanonicalName()))); } @SuppressWarnings( "unchecked" ) @Test public void testListOfStringArrayArray() throws Exception { DefaultJavaParameterizedType type = new DefaultJavaParameterizedType( "java.util.List", "List", 2, typeResolver ); DefaultJavaType genType = new DefaultJavaType( "java.lang.String", "String", 0, typeResolver ); type.setActualArgumentTypes( Collections.singletonList( genType ) ); Field field = DefaultJavaParameterizedTypeTest.class.getField( "listOfStringArrayArray" ); assertEquals( "List[][]", type.getValue() ); assertEquals( "List[][]", type.getGenericValue() ); assertEquals( "java.util.List", type.getBinaryName() ); assertEquals( "java.util.List[][]", type.getFullyQualifiedName() ); // Also compare with reflect implementations assertThat( type.getSimpleName(), allOf( equalTo("List[][]"), equalTo(field.getType().getSimpleName()))); assertThat( type.getCanonicalName(), allOf( equalTo("java.util.List[][]"), equalTo(field.getType().getCanonicalName()))); // assertThat( type.getComponentType().getSimpleName(), allOf( equalTo("java.util.List"), // equalTo(field.getType().getComponentType().getSimpleName()))); } @SuppressWarnings( "unchecked" ) @Test public void testMapEntryIntegerForString() throws Exception { DefaultJavaParameterizedType type = new DefaultJavaParameterizedType( "java.util.Map$Entry", "Map.Entry", 0, typeResolver ); DefaultJavaType keyType = new DefaultJavaType( "java.lang.Integer", "Integer", 0, typeResolver ); DefaultJavaType valueType = new DefaultJavaType( "java.lang.String", "String", 0, typeResolver ); type.setActualArgumentTypes( Arrays.asList( keyType, valueType ) ); Field field = DefaultJavaParameterizedTypeTest.class.getField( "mapEntryIntegerForString" ); assertEquals( "Map.Entry", type.getValue() ); assertEquals( "Map.Entry", type.getGenericValue() ); assertEquals( "java.util.Map$Entry", type.getBinaryName() ); assertEquals( "java.util.Map.Entry", type.getFullyQualifiedName() ); // Also compare with reflect implementations assertThat( type.getSimpleName(), allOf( equalTo("Entry"), equalTo(field.getType().getSimpleName()))); assertThat( type.getCanonicalName(), allOf( equalTo("java.util.Map.Entry"), equalTo(field.getType().getCanonicalName()))); // this is buggy for multiple JDKs assertThat( type.getGenericCanonicalName(), allOf( equalTo("java.util.Map.Entry") /*, equalTo(field.getGenericType().getTypeName())*/ )); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/impl/DefaultJavaSourceTest.java000066400000000000000000000021011325201777200316640ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import java.util.List; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaSourceTest; public class DefaultJavaSourceTest extends JavaSourceTest { public DefaultJavaSourceTest( String s ) { super( s ); } @Override public DefaultJavaSource newJavaSource( ClassLibrary classLibrary ) { return new DefaultJavaSource(classLibrary); } @Override public void setPackage( DefaultJavaSource source, JavaPackage pckg ) { source.setPackage( pckg ); } @Override public void setClasses( DefaultJavaSource source, List classes ) { for(JavaClass cls: classes) { source.addClass( cls ); } } @Override public void setImports( DefaultJavaSource source, List imports ) { for(String imprt : imports) { source.addImport( imprt ); } } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/impl/DefaultJavaTypeIT.java000066400000000000000000000021231325201777200307460ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; import com.thoughtworks.qdox.library.ClassLoaderLibrary; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaType; public class DefaultJavaTypeIT { private ClassLoaderLibrary library; @Before public void setUp() { library = new ClassLoaderLibrary( null ); library.addDefaultLoader(); } @Test public void testSuperClass() { JavaClass hashSetClass = library.getJavaClass( "java.util.HashSet" ); assertTrue( hashSetClass instanceof DefaultJavaClass ); JavaType hashSetSuperClass = hashSetClass.getSuperClass(); assertEquals( "java.util.AbstractSet", hashSetSuperClass.getFullyQualifiedName() ); assertEquals( "java.util.AbstractSet", hashSetSuperClass.getCanonicalName() ); assertEquals( "java.util.AbstractSet", hashSetSuperClass.getValue() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/impl/DefaultTypeTest.java000066400000000000000000000027071325201777200305570ustar00rootroot00000000000000package com.thoughtworks.qdox.model.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.Test; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaTypeTest; public class DefaultTypeTest extends JavaTypeTest { @Override public JavaClass newJavaClass( ClassLibrary library ) { return new DefaultJavaClass(new DefaultJavaSource( library )); } @Override public DefaultJavaType newType( String fullname ) { return new DefaultJavaType( fullname ); } @Override public DefaultJavaType newType( String fullname, int dimensions ) { return new DefaultJavaType( fullname, dimensions ); } @Override public DefaultJavaType newType( String fullname, int dimensions, JavaClass clazz ) { return new DefaultJavaType( fullname, dimensions ); } @Test public void testArrayType() { DefaultJavaType type = newType( "int", 1 ); assertTrue( type.isArray() ); } @Test public void testComponentType() { assertNull( newType( "int" ).getComponentType() ); assertEquals( "int", newType( "int", 1 ).getComponentType().getFullyQualifiedName() ); assertEquals( "long", newType( "long", 3 ).getComponentType().getFullyQualifiedName() ); } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/util/000077500000000000000000000000001325201777200246345ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/util/SerializationUtils.java000066400000000000000000000024731325201777200313430ustar00rootroot00000000000000package com.thoughtworks.qdox.model.util; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; public class SerializationUtils { public static byte[] serialize(Object obj) { try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(buffer); oos.writeObject(obj); oos.close(); return buffer.toByteArray(); } catch (IOException e) { throw new RuntimeException("error writing to byte-array!", e); } } public static Object deserialize(byte[] bytes) throws ClassNotFoundException { try { ByteArrayInputStream input = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(input); return ois.readObject(); } catch (IOException e) { throw new RuntimeException("error reading from byte-array!", e); } } public static Object serializedCopy(Object obj) { try { return deserialize(serialize(obj)); } catch (ClassNotFoundException e) { throw new RuntimeException("this shouldn't happen"); } } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/model/util/TagParserTest.java000066400000000000000000000151041325201777200302300ustar00rootroot00000000000000package com.thoughtworks.qdox.model.util; import java.io.IOException; import java.io.StreamTokenizer; import java.util.Iterator; import java.util.Map; import junit.framework.TestCase; public class TagParserTest extends TestCase { public TagParserTest(String name) { super(name); } //---( Parse into named parameters )--- public void testEmptyInputContainsNoNamedParameters() { Map paramMap = TagParser.parseNamedParameters(""); assertNotNull(paramMap); assertTrue(paramMap.isEmpty()); } public void testMyUnderstandingOfStreamTokenizer() throws IOException { String input = "x=y 'foo' \" bar \" 234\t'multi\\\nline'\n" + "dotted.words hypen-ated under_scored"; StreamTokenizer tokenizer = TagParser.makeTokenizer(input); assertEquals(StreamTokenizer.TT_WORD, tokenizer.nextToken()); assertEquals("x", tokenizer.sval); assertEquals('=', tokenizer.nextToken()); assertEquals(StreamTokenizer.TT_WORD, tokenizer.nextToken()); assertEquals("y", tokenizer.sval); assertEquals('\'', tokenizer.nextToken()); assertEquals("foo", tokenizer.sval); assertEquals('"', tokenizer.nextToken()); assertEquals(" bar ", tokenizer.sval); assertEquals(StreamTokenizer.TT_WORD, tokenizer.nextToken()); assertEquals("234", tokenizer.sval); assertEquals('\'', tokenizer.nextToken()); assertEquals("multi\nline", tokenizer.sval); assertEquals(StreamTokenizer.TT_WORD, tokenizer.nextToken()); assertEquals("dotted.words", tokenizer.sval); assertEquals(StreamTokenizer.TT_WORD, tokenizer.nextToken()); assertEquals("hypen-ated", tokenizer.sval); assertEquals(StreamTokenizer.TT_WORD, tokenizer.nextToken()); assertEquals("under_scored", tokenizer.sval); } public void testCanParseSimpleNamedParameters() { Map paramMap = TagParser.parseNamedParameters("x=foo"); assertNotNull(paramMap); assertEquals(1, paramMap.size()); assertEquals("foo", paramMap.get("x")); } public void testCanParseMultipleNamedParameters() { Map paramMap = TagParser.parseNamedParameters("x=foo y=bar"); assertNotNull(paramMap); assertEquals(2, paramMap.size()); assertEquals("foo", paramMap.get("x")); assertEquals("bar", paramMap.get("y")); } public void testNamedParametersAreReturnedInOrderDeclared() { Map paramMap = TagParser.parseNamedParameters( "x=foo y=bar a=orses b=oney" ); assertEquals(4, paramMap.size()); Iterator keyIterator = paramMap.keySet().iterator(); assertEquals("x", keyIterator.next()); assertEquals("y", keyIterator.next()); assertEquals("a", keyIterator.next()); assertEquals("b", keyIterator.next()); } public void testNamedParameterValuesCanBeSingleQuoted() { Map paramMap = TagParser.parseNamedParameters("x='foo' y='bar fly'"); assertNotNull(paramMap); assertEquals(2, paramMap.size()); assertEquals("foo", paramMap.get("x")); assertEquals("bar fly", paramMap.get("y")); } public void testNamedParameterValuesCanBeDoubleQuoted() { Map paramMap = TagParser.parseNamedParameters("x=\"'foo'\" y=\"bar fly\""); assertNotNull(paramMap); assertEquals(2, paramMap.size()); assertEquals("'foo'", paramMap.get("x")); assertEquals("bar fly", paramMap.get("y")); } public void testNamedParametersCanHaveSpacesAroundEquals() { Map paramMap = TagParser.parseNamedParameters("x = foo y = 'bar'"); assertNotNull(paramMap); assertEquals(2, paramMap.size()); assertEquals("foo", paramMap.get("x")); assertEquals("bar", paramMap.get("y")); } public void testNamedParameterNamesCanContainHypensEtc() { Map paramMap = TagParser.parseNamedParameters("x.a = '1' x-b = '2' x_c = '3'"); assertNotNull(paramMap); assertEquals(3, paramMap.size()); assertEquals("1", paramMap.get("x.a")); assertEquals("2", paramMap.get("x-b")); assertEquals("3", paramMap.get("x_c")); } public void testNamedParameterValuesCanBeNumeric() { Map paramMap = TagParser.parseNamedParameters("x=1 y=2"); assertNotNull(paramMap); assertEquals(2, paramMap.size()); assertEquals("1", paramMap.get("x")); assertEquals("2", paramMap.get("y")); } public void testNamedParameterValuesCanSpanLinesIfBackslashIsUsed() { Map paramMap = TagParser.parseNamedParameters("x='multiline\\\nvalue'"); assertNotNull(paramMap); assertEquals(1, paramMap.size()); assertEquals("multiline\nvalue", paramMap.get("x")); } //---( Parse into "words": positional parameters )--- public void testEmptyInputContainsNoWords() { String[] words = TagParser.parseWords(""); assertEquals(0, words.length); } public void testCanSplitIntoWordsOnWhitespace() { String[] words = TagParser.parseWords("a b c"); assertEquals(3, words.length); assertEquals("a", words[0]); assertEquals("b", words[1]); assertEquals("c", words[2]); } public void testWordsCanContainHyphensEtc() { String[] words = TagParser.parseWords("a.b c-d e_f"); assertEquals(3, words.length); assertEquals("a.b", words[0]); assertEquals("c-d", words[1]); assertEquals("e_f", words[2]); } public void testMostPunctuationAreSeparateWords() { String[] words = TagParser.parseWords("a=c"); assertEquals(3, words.length); assertEquals("a", words[0]); assertEquals("=", words[1]); assertEquals("c", words[2]); } public void testShouldParseMultiLineParameters() { String[] words = TagParser.parseWords("\n" + "a=c\n" + "e=g\n"); assertEquals(6, words.length); assertEquals("a", words[0]); assertEquals("=", words[1]); assertEquals("c", words[2]); assertEquals("e", words[3]); assertEquals("=", words[4]); assertEquals("g", words[5]); } //for QDOX-173 public void testGenericsSupport() { String[] words = TagParser.parseWords(" The Key"); assertEquals("", words[0]); assertEquals("The", words[1]); assertEquals("Key", words[2]); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/parser/000077500000000000000000000000001325201777200240535ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/parser/LexerTest.java000066400000000000000000001166251325201777200266500ustar00rootroot00000000000000package com.thoughtworks.qdox.parser; import java.io.IOException; import java.io.StringReader; import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; import junit.framework.TestCase; import com.thoughtworks.qdox.parser.impl.JFlexLexer; import com.thoughtworks.qdox.parser.impl.Parser; public class LexerTest extends TestCase { private static Map tokens; static { tokens = new HashMap(); Field[] tokenFlds = Parser.class.getDeclaredFields(); for (int i = 0; i < tokenFlds.length; i++) { Field f = tokenFlds[i]; try { if (!f.getName().startsWith("YY")) { tokens.put(new Integer(f.getShort(Parser.class)), f.getName()); } } catch (Exception e) { // we don't care! } } } public LexerTest(String s) { super(s); } public void testEmptyInput() throws Exception { String in = ""; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(0, lexer); } public void testNewlines() throws Exception { String in = "DOS\r\nUNIX\nMAC\r"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.IDENTIFIER, "DOS", lexer); assertLex(Parser.IDENTIFIER, "UNIX", lexer); assertLex(Parser.IDENTIFIER, "MAC", lexer); assertLex(0, lexer); } public void testStaticBlock() throws Exception { String in = "" + "class X { " + " static { " + " something(); " + " } " + "} "; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.CLASS, lexer); assertLex(Parser.IDENTIFIER, "X", lexer); assertLex(Parser.BRACEOPEN, lexer); assertLex(Parser.STATIC, lexer); assertLex(Parser.CODEBLOCK, lexer); assertLex(Parser.BRACECLOSE, lexer); assertLex(0, lexer); } public void testFieldAssignment() throws Exception { checkAssignment("x"); checkAssignment("(map.isEmpty ? 1 : -1)"); checkAssignment("0"); checkAssignment("\"hello\""); checkAssignment("new Thingy()"); checkAssignment("new Thingy(\"xxx\", 3, x.getBlah())"); checkAssignment("new Thingy(\"xx;x\", 3, x.getBlah())"); checkAssignment("StaticClass.intance()"); checkAssignment("[1,2,3]"); checkAssignment("/* , ; } */"); } public void testAnonymousInnerClassAssignment() throws Exception { checkAssignment("new Thingifier() { void doThings(int x) { blah(); } }"); checkAssignment("new Thingifier() { void doThings(int x) { a = \"aaa\"; } }"); } public void testGenericTypeAssignment() throws Exception { // QDOX-77 checkAssignment("new HashMap"); } public void testFieldsContainingLessThanOrGreaterThanInAssignment() throws Exception { // QDOX-71 - this is really important as it is common to see in all versions of the JDK. // Please don't disable this test -joe. checkAssignment("x < y"); checkAssignment("x > y"); checkAssignment("x << y"); checkAssignment("x >> y"); checkAssignment("xz"); } private void checkAssignment(String assignment) throws IOException { String in = "" + "class X { " + " int x = " + assignment + "; " + "} "; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.CLASS, lexer); assertLex(Parser.IDENTIFIER, "X", lexer); assertLex(Parser.BRACEOPEN, lexer); assertLex(Parser.IDENTIFIER, "int", lexer); assertLex(Parser.IDENTIFIER, "x", lexer); assertLex(Parser.SEMI, lexer); assertLex(Parser.BRACECLOSE, lexer); assertLex(0, lexer); } public void testMultipleFields() throws Exception { String in = "" + "class X { " + " int x, y = 2; " + "} "; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.CLASS, lexer); assertLex(Parser.IDENTIFIER, "X", lexer); assertLex(Parser.BRACEOPEN, lexer); assertLex(Parser.IDENTIFIER, "int", lexer); assertLex(Parser.IDENTIFIER, "x", lexer); assertLex(Parser.COMMA, lexer); assertLex(Parser.IDENTIFIER, "y", lexer); assertLex(Parser.SEMI, lexer); assertLex(Parser.BRACECLOSE, lexer); assertLex(0, lexer); } public void testSpecialCharsInIdentifier() throws Exception { String in = "a_b x$y z80"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.IDENTIFIER, "a_b", lexer); assertLex(Parser.IDENTIFIER, "x$y", lexer); assertLex(Parser.IDENTIFIER, "z80", lexer); assertLex(0, lexer); } public void testUnicodeInTest() throws Exception { checkAssignment("\"\u0000\""); } public void testUnicodeInFile() throws Exception { Lexer lexer = new JFlexLexer( getClass().getResourceAsStream( "/com/thoughtworks/qdox/testdata/Unicode.java" ) ); assertLex(Parser.PACKAGE, lexer); assertLex(Parser.IDENTIFIER, lexer); assertLex(Parser.DOT, lexer); assertLex(Parser.IDENTIFIER, lexer); assertLex(Parser.DOT, lexer); assertLex(Parser.IDENTIFIER, lexer); assertLex(Parser.DOT, lexer); assertLex(Parser.IDENTIFIER, lexer); assertLex(Parser.SEMI, lexer); assertLex(Parser.CLASS, lexer); assertLex(Parser.IDENTIFIER, lexer); assertLex(Parser.BRACEOPEN, lexer); assertLex(Parser.IDENTIFIER, "String", lexer); assertLex(Parser.IDENTIFIER, "x", lexer); assertLex(Parser.SEMI, lexer); assertLex(Parser.BRACECLOSE, lexer); assertLex(0, lexer); } public void testUnicodeIdentifiers() throws Exception { // \u0391 == uppercase Greek "Alpha" assertSingleLex("\u0391", Parser.IDENTIFIER); // \u00f6 == lowercase o + diaeresis assertSingleLex("f\u00f6rnamn", Parser.IDENTIFIER); } public void testInnerClass() throws Exception { String in = "" + "class X { " + " class InnerClass { " + " int x = 1; " + " } " + " int y = 2; " + "} "; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.CLASS, lexer); assertLex(Parser.IDENTIFIER, lexer); assertLex(Parser.BRACEOPEN, lexer); assertLex(Parser.CLASS, lexer); assertLex(Parser.IDENTIFIER, "InnerClass", lexer); assertLex(Parser.BRACEOPEN, lexer); assertLex(Parser.IDENTIFIER, "int", lexer); assertLex(Parser.IDENTIFIER, "x", lexer); assertLex(Parser.SEMI, lexer); assertLex(Parser.BRACECLOSE, lexer); assertLex(Parser.IDENTIFIER, "int", lexer); assertLex(Parser.IDENTIFIER, "y", lexer); assertLex(Parser.SEMI, lexer); assertLex(Parser.BRACECLOSE, lexer); assertLex(0, lexer); } public void testCurliesInStringsOrChars() throws Exception { checkAssignment("\"{\""); checkAssignment("\"}\""); checkAssignment("'}'"); checkAssignment("'{'"); } public void testDoubleBackSlashesInStringsOrChars() throws Exception { checkAssignment("\"\\\\\""); // x = "\\" checkAssignment("'\\\\'"); // x = '\\' } public void testFunnyCharsInStringsOrChars() throws Exception { checkAssignment("\"???????????\""); checkAssignment("'???????????'"); } public void testQuoteInCharInCodeBlock() throws Exception { String in = "{'\"'}"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.CODEBLOCK, lexer); assertLex(0, lexer); } public void testDoubleQuotesInCharInAssignment() throws Exception { String in = "x = '\"';"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.IDENTIFIER, "x", lexer); assertLex(Parser.SEMI, lexer); assertLex(0, lexer); } public void testSingleQuoteInCharInAssignment() throws Exception { String in = "x = '\\'';"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.IDENTIFIER, "x", lexer); assertLex(Parser.SEMI, lexer); assertLex(0, lexer); } public void testStringWithDoubleQuotesIn() throws Exception { String in = "x = \"blah \\\" blah\";"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.IDENTIFIER, "x", lexer); assertLex(Parser.SEMI, lexer); assertLex(0, lexer); } public void testCommentsWithSingleQuoteInCodeBlock() throws Exception { String in = "{ /* ' */ }"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.CODEBLOCK, lexer); assertLex(0, lexer); } public void testCommentsWithDoubleQuotesInCodeBlock() throws Exception { String in = "{ /* \" */ }"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.CODEBLOCK, lexer); assertLex(0, lexer); } public void testCommentsThatEndImmediately() throws Exception { String in = "/**/ class"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.CLASS, lexer); assertLex(0, lexer); } public void testCommentsWithQuotesInAssignment() throws Exception { String in = "a x = y /* don't do stuff*/;"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.IDENTIFIER, "a", lexer); assertLex(Parser.IDENTIFIER, "x", lexer); assertLex(Parser.SEMI, lexer); assertLex(0, lexer); in = "a z = \n" + "// thing's thing \n" + "0;"; lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.IDENTIFIER, "a", lexer); assertLex(Parser.IDENTIFIER, "z", lexer); assertLex(Parser.SEMI, lexer); assertLex(0, lexer); } public void testArrayTokens() throws Exception { String in = "String[] []o[]"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.IDENTIFIER, "String", lexer); assertLex(Parser.SQUAREOPEN, lexer); assertLex(Parser.SQUARECLOSE, lexer); assertLex(Parser.SQUAREOPEN, lexer); assertLex(Parser.SQUARECLOSE, lexer); assertLex(Parser.IDENTIFIER, "o", lexer); assertLex(Parser.SQUAREOPEN, lexer); assertLex(Parser.SQUARECLOSE, lexer); assertLex(0, lexer); } public void testKeyWords() throws Exception { assertSingleLex("package", Parser.PACKAGE); assertSingleLex("import", Parser.IMPORT); assertSingleLex("public", Parser.PUBLIC); assertSingleLex("protected", Parser.PROTECTED); assertSingleLex("private", Parser.PRIVATE); assertSingleLex("static", Parser.STATIC); assertSingleLex("final", Parser.FINAL); assertSingleLex("abstract", Parser.ABSTRACT); assertSingleLex("native", Parser.NATIVE); assertSingleLex("strictfp", Parser.STRICTFP); assertSingleLex("synchronized", Parser.SYNCHRONIZED); assertSingleLex("transient", Parser.TRANSIENT); assertSingleLex("volatile", Parser.VOLATILE); assertSingleLex("class", Parser.CLASS); assertSingleLex("interface", Parser.INTERFACE); assertSingleLex("throws", Parser.THROWS); assertSingleLex("extends", Parser.EXTENDS); assertSingleLex("implements", Parser.IMPLEMENTS); assertSingleLex("super", Parser.SUPER); } public void testTypeTokens() throws Exception { String in = "Map>"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.IDENTIFIER, "Map", lexer); assertLex(Parser.LESSTHAN, lexer); assertLex(Parser.QUERY, lexer); assertLex(Parser.EXTENDS, lexer); assertLex(Parser.IDENTIFIER, "A", lexer); assertLex(Parser.AMPERSAND, lexer); assertLex(Parser.IDENTIFIER, "B", lexer); assertLex(Parser.COMMA, lexer); assertLex(Parser.IDENTIFIER, "List", lexer); assertLex(Parser.LESSTHAN, lexer); assertLex(Parser.IDENTIFIER, "String", lexer); assertLex(Parser.GREATERTHAN, lexer); assertLex(Parser.GREATERTHAN, lexer); assertLex(0, lexer); } public void testAnnotationDeclarationTokens() throws Exception { String in = "" + "public @interface Copyright {\n" + " int year();\n" + " String assignee() default \"The CodeHaus\";\n" + "}\n"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.PUBLIC, lexer); assertLex(Parser.ANNOINTERFACE, lexer); assertLex(Parser.IDENTIFIER, "Copyright", lexer); assertLex(Parser.BRACEOPEN, lexer); assertLex(Parser.IDENTIFIER, "int", lexer); assertLex(Parser.IDENTIFIER, "year", lexer); assertLex(Parser.PARENOPEN, lexer); assertLex(Parser.PARENCLOSE, lexer); assertLex(Parser.SEMI, lexer); assertLex(Parser.IDENTIFIER, "String", lexer); assertLex(Parser.IDENTIFIER, "assignee", lexer); assertLex(Parser.PARENOPEN, lexer); assertLex(Parser.PARENCLOSE, lexer); assertLex(Parser.SEMI, lexer); assertLex(Parser.BRACECLOSE, lexer); assertLex(0, lexer); } public void testAnnotationTokens() throws Exception { String in = "" + "@Copyright (year = 2004, month = \"Jan\")\n" + "@Note(\"Just ignore me\")\n" + "public class LexerTest extends TestCase {}\n"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.AT, "@", lexer); assertLex(Parser.IDENTIFIER, "Copyright", lexer); assertLex(Parser.PARENOPEN, lexer); assertLex(Parser.IDENTIFIER, "year", lexer); assertLex(Parser.EQUALS, lexer); assertLex(Parser.INTEGER_LITERAL, "2004", lexer); assertLex(Parser.COMMA, lexer); assertLex(Parser.IDENTIFIER, "month", lexer); assertLex(Parser.EQUALS, lexer); assertLex(Parser.STRING_LITERAL, "\"", lexer); assertEquals("\"Jan\"", lexer.getCodeBody()); assertLex(Parser.PARENCLOSE, lexer); assertLex(Parser.AT, "@", lexer); assertLex(Parser.IDENTIFIER, "Note", lexer); assertLex(Parser.PARENOPEN, lexer); assertLex(Parser.STRING_LITERAL, lexer); assertEquals( "\"Just ignore me\"", lexer.getCodeBody() ); assertLex(Parser.PARENCLOSE, lexer); assertLex(Parser.PUBLIC, lexer); assertLex(Parser.CLASS, lexer); assertLex(Parser.IDENTIFIER, "LexerTest", lexer); assertLex(Parser.EXTENDS, lexer); assertLex(Parser.IDENTIFIER, "TestCase", lexer); assertLex(Parser.BRACEOPEN, lexer); assertLex(Parser.BRACECLOSE, lexer); assertLex(0, lexer); } public void testQDOX134_MoreAnnotationTokens() throws Exception { String in = "" + "@myTag name=TestClass attrs=Something1,Something2,Something3\n" + "public class LexerTest extends TestCase {}\n"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.AT, "@", lexer); assertLex(Parser.IDENTIFIER, "myTag", lexer); assertLex(Parser.IDENTIFIER, "name", lexer); assertLex(Parser.COMMA, lexer); assertLex(Parser.IDENTIFIER, "Something2", lexer); assertLex(Parser.COMMA, lexer); assertLex(Parser.IDENTIFIER, "Something3", lexer); assertLex(Parser.PUBLIC, lexer); assertLex(Parser.CLASS, lexer); assertLex(Parser.IDENTIFIER, "LexerTest", lexer); assertLex(Parser.EXTENDS, lexer); assertLex(Parser.IDENTIFIER, "TestCase", lexer); assertLex(Parser.BRACEOPEN, lexer); assertLex(Parser.BRACECLOSE, lexer); assertLex(0, lexer); } public void testAnnotationElementValueArrayInitializer() throws Exception { String in = "@Endorsers({\"Children\", \"Unscrupulous dentists\"})\n" + "public class Lollipop { }"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.AT, "@", lexer); assertLex(Parser.IDENTIFIER, "Endorsers", lexer); assertLex(Parser.PARENOPEN, "(", lexer); assertLex(Parser.BRACEOPEN, "{", lexer); assertLex(Parser.STRING_LITERAL, "\"", lexer); assertEquals( "\"Children\"", lexer.getCodeBody() ); assertLex(Parser.COMMA, ",", lexer); assertLex(Parser.STRING_LITERAL, "\"", lexer); assertEquals( "\"Unscrupulous dentists\"", lexer.getCodeBody() ); assertLex(Parser.BRACECLOSE, "}", lexer); assertLex(Parser.PARENCLOSE, ")", lexer); assertLex(Parser.PUBLIC, "public", lexer); assertLex(Parser.CLASS, "class", lexer); assertLex(Parser.IDENTIFIER, "Lollipop", lexer); assertLex(Parser.BRACEOPEN, "{", lexer); assertLex(Parser.BRACECLOSE, "}", lexer); assertLex(0, lexer); } public void testEnumConstructor() throws Exception { String in = "enum Foo { a(\"hello\"); int someField; }"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.ENUM, lexer); assertLex(Parser.IDENTIFIER, "Foo", lexer); assertLex(Parser.BRACEOPEN, lexer); assertLex(Parser.IDENTIFIER, "a", lexer); assertLex(Parser.PARENOPEN, lexer); assertLex(Parser.STRING_LITERAL, "\"", lexer); assertEquals( "\"hello\"", lexer.getCodeBody() ); assertLex(Parser.PARENCLOSE, lexer); assertLex(Parser.SEMI, lexer); assertLex(Parser.IDENTIFIER, "int", lexer); assertLex(Parser.IDENTIFIER, "someField", lexer); assertLex(Parser.SEMI, lexer); assertLex(Parser.BRACECLOSE, lexer); } public void testEnumWithMethods() throws Exception { String in = "" + "enum Animal {" + " DUCK { public void speak() { System.out.println(\"quack!\"); } }" + "}"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.ENUM, lexer); assertLex(Parser.IDENTIFIER, "Animal", lexer); assertLex(Parser.BRACEOPEN, lexer); assertLex(Parser.IDENTIFIER, "DUCK", lexer); //assertLex(Parser.CODEBLOCK, lexer); assertLex( Parser.BRACEOPEN, lexer ); assertLex(Parser.PUBLIC, lexer); assertLex(Parser.IDENTIFIER, "void", lexer); assertLex( Parser.IDENTIFIER, "speak", lexer ); assertLex( Parser.PARENOPEN, lexer ); assertLex( Parser.PARENCLOSE, lexer ); assertLex( Parser.CODEBLOCK, lexer ); assertLex( Parser.BRACECLOSE, lexer ); assertLex(Parser.BRACECLOSE, lexer); assertLex( 0, lexer ); } private void assertSingleLex(String in, short expectedLex) throws Exception { Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(expectedLex, lexer); assertLex(0, lexer); } private void assertLex(int expectedToken, Lexer lexer) throws IOException { Object expected = tokens.get(new Integer(expectedToken)); Object actual = tokens.get(new Integer(lexer.lex())); assertEquals(expected, actual); } private void assertLex(int expectedToken, String expectedText, Lexer lexer) throws IOException { assertLex(expectedToken, lexer); assertEquals(expectedText, lexer.text()); } // for QDOX-140 public void testNonAsciiMethodNameDoesNotCrashLexerButChewsUpUnicodeEscapedSequencesBadly() throws Exception { String in = "" + "interface X { " + " void paramWithNonAsciis\\u00E4\\u00F6\\u00FC\\u00DF();" + "} "; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.INTERFACE, lexer); assertLex(Parser.IDENTIFIER, "X", lexer); assertLex(Parser.BRACEOPEN, lexer); assertLex(Parser.IDENTIFIER, "void", lexer); assertLex(Parser.IDENTIFIER, "paramWithNonAsciis\\u00E4\\u00F6\\u00FC\\u00DF", lexer); assertLex(Parser.PARENOPEN, lexer); assertLex(Parser.PARENCLOSE, lexer); assertLex(Parser.SEMI, lexer); assertLex(Parser.BRACECLOSE, lexer); assertLex(0, lexer); } //for QDOX-158 public void testAnnotationWithMultipleParameters() throws Exception { String in = "@MyFunction.MyInterface( prefix1 = \"abc\", prefix2 = \"abc\" )"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.AT, lexer); assertLex(Parser.IDENTIFIER, "MyFunction", lexer); assertLex(Parser.DOT, lexer); assertLex(Parser.IDENTIFIER, "MyInterface", lexer); assertLex(Parser.PARENOPEN, lexer); assertLex(Parser.IDENTIFIER, "prefix1", lexer); assertLex(Parser.EQUALS, lexer); assertLex(Parser.STRING_LITERAL, lexer); assertEquals( "\"abc\"", lexer.getCodeBody() ); assertLex(Parser.COMMA, lexer); assertLex(Parser.IDENTIFIER, "prefix2", lexer); assertLex(Parser.EQUALS, lexer); assertLex(Parser.STRING_LITERAL, lexer); assertEquals( "\"abc\"", lexer.getCodeBody() ); assertLex(Parser.PARENCLOSE, lexer); } public void testSimpleAnnotation() throws Exception { String in = "@Override\n public boolean isReadOnly(final ELContext context)"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.AT, lexer); assertLex(Parser.IDENTIFIER, "Override", lexer); assertLex(Parser.PUBLIC, lexer); assertLex(Parser.IDENTIFIER, "boolean", lexer); assertLex(Parser.IDENTIFIER, "isReadOnly", lexer); assertLex(Parser.PARENOPEN, lexer); assertLex(Parser.FINAL, lexer); assertLex(Parser.IDENTIFIER, "ELContext", lexer); assertLex(Parser.IDENTIFIER, "context", lexer); assertLex(Parser.PARENCLOSE, lexer); } public void testMultipleRowAnnotation() throws Exception { String in = "@JSFComponent\n (name = \"h:inputHidden\")"; Lexer lexer = new JFlexLexer( new StringReader( in ) ); assertLex( Parser.AT, lexer ); assertLex( Parser.IDENTIFIER, "JSFComponent", lexer ); assertLex( Parser.PARENOPEN, lexer ); assertLex( Parser.IDENTIFIER, "name", lexer ); assertLex( Parser.EQUALS, lexer ); assertLex( Parser.STRING_LITERAL, lexer ); assertEquals( "\"h:inputHidden\"", lexer.getCodeBody() ); assertLex( Parser.PARENCLOSE, lexer ); } public void testEnumWithAnnotations() throws Exception { String in = "class Foo {\n" + "public enum BasicType {\n" + "@XmlEnumValue(\"text\")\n" + "VALUE(\"value\"); }\n" + "}"; Lexer lexer = new JFlexLexer(new StringReader(in)); assertLex(Parser.CLASS, lexer); assertLex(Parser.IDENTIFIER, "Foo", lexer); assertLex(Parser.BRACEOPEN, lexer); assertLex(Parser.PUBLIC, lexer); assertLex(Parser.ENUM, lexer); assertLex(Parser.IDENTIFIER, "BasicType", lexer); assertLex(Parser.BRACEOPEN, lexer); assertLex(Parser.AT, lexer); assertLex(Parser.IDENTIFIER, "XmlEnumValue", lexer); assertLex(Parser.PARENOPEN, lexer); assertLex(Parser.STRING_LITERAL, lexer); assertEquals( "\"text\"", lexer.getCodeBody() ); assertLex(Parser.PARENCLOSE, lexer); assertLex(Parser.IDENTIFIER, "VALUE", lexer); assertLex(Parser.PARENOPEN, lexer); assertLex(Parser.STRING_LITERAL, lexer); assertEquals( "\"value\"", lexer.getCodeBody() ); assertLex(Parser.PARENCLOSE, lexer); assertLex(Parser.SEMI, lexer); } // QDOX-242 public void testDoubleValueAnnotation() throws Exception { String in = "@Rule( delta = 0.005 )"; Lexer lexer = new JFlexLexer( new StringReader( in ) ); assertLex( Parser.AT, lexer ); assertLex( Parser.IDENTIFIER, "Rule", lexer ); assertLex( Parser.PARENOPEN, lexer ); assertLex( Parser.IDENTIFIER, "delta", lexer ); assertLex( Parser.EQUALS, lexer ); assertLex( Parser.FLOAT_LITERAL, "0.005", lexer ); assertLex( Parser.PARENCLOSE, lexer ); assertLex( 0, lexer ); } // Github #31 public void testParseEnumWithConstructor() throws Exception { String in = "public enum SomeEnum {\n" + " VALUE1(\"hello\", 1, new String[]{\"hello\", \"world\"});\n" + " SomeEnum(String string, int integer, String[] stringArray) {\n" + " }\r\n" + "}"; Lexer lexer = new JFlexLexer( new StringReader( in ) ); assertLex( Parser.PUBLIC, lexer ); assertLex( Parser.ENUM, lexer ); assertLex( Parser.IDENTIFIER, "SomeEnum", lexer ); assertLex( Parser.BRACEOPEN, lexer ); assertLex( Parser.IDENTIFIER, "VALUE1", lexer ); assertLex( Parser.PARENOPEN, lexer ); assertLex( Parser.STRING_LITERAL, "\"", lexer ); //??? assertLex( Parser.COMMA, lexer ); assertLex( Parser.INTEGER_LITERAL, "1", lexer ); assertLex( Parser.COMMA, lexer ); assertLex( Parser.NEW, lexer ); assertLex( Parser.IDENTIFIER, "String", lexer ); assertLex( Parser.SQUAREOPEN, lexer ); assertLex( Parser.SQUARECLOSE, lexer ); assertLex( Parser.CODEBLOCK, lexer ); assertLex( Parser.PARENCLOSE, lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.IDENTIFIER, "SomeEnum", lexer ); assertLex( Parser.PARENOPEN, lexer ); assertLex( Parser.IDENTIFIER, "String", lexer ); assertLex( Parser.IDENTIFIER, "string", lexer ); assertLex( Parser.COMMA, lexer ); assertLex( Parser.IDENTIFIER, "int", lexer ); assertLex( Parser.IDENTIFIER, "integer", lexer ); assertLex( Parser.COMMA, lexer ); assertLex( Parser.IDENTIFIER, "String", lexer ); assertLex( Parser.SQUAREOPEN, lexer ); assertLex( Parser.SQUARECLOSE, lexer ); assertLex( Parser.IDENTIFIER, "stringArray", lexer ); assertLex( Parser.PARENCLOSE, lexer ); assertLex( Parser.CODEBLOCK, lexer ); assertLex( Parser.BRACECLOSE, lexer ); assertLex( 0, lexer ); } public void testModule() throws Exception { String in = "@Foo(1) @Foo(2) @Bar\n" + "open module M.N {\n" + " requires A.B;\n" + " requires transitive C.D;\n" + " requires static E.F;\n" + " requires transitive static G.H;\n" + " exports P.Q;\n" + " exports R.S to T1.U1, T2.U2;\n" + " opens P.Q;\n" + " opens R.S to T1.U1, T2.U2;\n" + " uses V.W;\n" + " provides X.Y with Z1.Z2, Z3.Z4;\n" + "}"; Lexer lexer = new JFlexLexer( new StringReader( in ) ); assertLex( Parser.AT, lexer ); assertLex( Parser.IDENTIFIER, "Foo", lexer ); assertLex( Parser.PARENOPEN, lexer ); assertLex( Parser.INTEGER_LITERAL, "1", lexer ); assertLex( Parser.PARENCLOSE, lexer ); assertLex( Parser.AT, lexer ); assertLex( Parser.IDENTIFIER, "Foo", lexer ); assertLex( Parser.PARENOPEN, lexer ); assertLex( Parser.INTEGER_LITERAL, "2", lexer ); assertLex( Parser.PARENCLOSE, lexer ); assertLex( Parser.AT, lexer ); assertLex( Parser.IDENTIFIER, "Bar", lexer ); assertLex( Parser.OPEN, lexer ); assertLex( Parser.MODULE, lexer ); assertLex( Parser.IDENTIFIER, "M", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "N", lexer ); assertLex( Parser.BRACEOPEN, lexer ); assertLex( Parser.REQUIRES, lexer ); assertLex( Parser.IDENTIFIER, "A", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "B", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.REQUIRES, lexer ); assertLex( Parser.TRANSITIVE, lexer ); assertLex( Parser.IDENTIFIER, "C", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "D", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.REQUIRES, lexer ); assertLex( Parser.STATIC, lexer ); assertLex( Parser.IDENTIFIER, "E", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "F", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.REQUIRES, lexer ); assertLex( Parser.TRANSITIVE, lexer ); assertLex( Parser.STATIC, lexer ); assertLex( Parser.IDENTIFIER, "G", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "H", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.EXPORTS, lexer ); assertLex( Parser.IDENTIFIER, "P", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "Q", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.EXPORTS, lexer ); assertLex( Parser.IDENTIFIER, "R", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "S", lexer ); assertLex( Parser.TO, lexer ); assertLex( Parser.IDENTIFIER, "T1", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "U1", lexer ); assertLex( Parser.COMMA, lexer ); assertLex( Parser.IDENTIFIER, "T2", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "U2", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.OPENS, lexer ); assertLex( Parser.IDENTIFIER, "P", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "Q", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.OPENS, lexer ); assertLex( Parser.IDENTIFIER, "R", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "S", lexer ); assertLex( Parser.TO, lexer ); assertLex( Parser.IDENTIFIER, "T1", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "U1", lexer ); assertLex( Parser.COMMA, lexer ); assertLex( Parser.IDENTIFIER, "T2", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "U2", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.USES, lexer ); assertLex( Parser.IDENTIFIER, "V", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "W", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.PROVIDES, lexer ); assertLex( Parser.IDENTIFIER, "X", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "Y", lexer ); assertLex( Parser.WITH, lexer ); assertLex( Parser.IDENTIFIER, "Z1", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "Z2", lexer ); assertLex( Parser.COMMA, lexer ); assertLex( Parser.IDENTIFIER, "Z3", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "Z4", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.BRACECLOSE, lexer ); assertLex( 0, lexer ); } public void testModuleAsIdentifier() throws Exception { String in = "" + "package module.module;\n" + "import static module.module;\n" + "import module.module;\n" + "@module @module.module @module(module=module)\n" + "public class module extends module implements module,module {\n" + " @module\n" + " private module module;\n" + " protected module module(module module) {}\n" + "}"; Lexer lexer = new JFlexLexer( new StringReader( in ) ); assertLex( Parser.PACKAGE, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.IMPORT, lexer ); assertLex( Parser.STATIC, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.IMPORT, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.AT, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.AT, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.AT, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.PARENOPEN, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.EQUALS, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.PARENCLOSE, lexer ); assertLex( Parser.PUBLIC, lexer ); assertLex( Parser.CLASS, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.EXTENDS, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.IMPLEMENTS, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.COMMA, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.BRACEOPEN, lexer ); assertLex( Parser.AT, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.PRIVATE, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.PROTECTED, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.PARENOPEN, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.PARENCLOSE, lexer ); assertLex( Parser.CODEBLOCK, lexer ); assertLex( Parser.BRACECLOSE, lexer ); assertLex( 0, lexer ); } public void testModuleModifiersAsIdentifier() throws Exception { String in = "open module module.module {\n" + " requires requires.requires;\n" + " requires transitive transitive.transitive;\n" + " requires static requires.transitive;\n" + " requires transitive static requires.transitive;\n" + " exports exports.exports;\n" + " exports to.to to to.to, to.to;\n" + " opens opens.opens;\n" + " opens to.to to to.to, to.to;\n" + " uses uses.uses;\n" + " provides with.with with with.with, with.with;\n" + "}"; Lexer lexer = new JFlexLexer( new StringReader( in ) ); assertLex( Parser.OPEN, lexer ); assertLex( Parser.MODULE, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "module", lexer ); assertLex( Parser.BRACEOPEN, lexer ); assertLex( Parser.REQUIRES, lexer ); assertLex( Parser.IDENTIFIER, "requires", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "requires", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.REQUIRES, lexer ); assertLex( Parser.TRANSITIVE, lexer ); assertLex( Parser.IDENTIFIER, "transitive", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "transitive", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.REQUIRES, lexer ); assertLex( Parser.STATIC, lexer ); assertLex( Parser.IDENTIFIER, "requires", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "transitive", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.REQUIRES, lexer ); assertLex( Parser.TRANSITIVE, lexer ); assertLex( Parser.STATIC, lexer ); assertLex( Parser.IDENTIFIER, "requires", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "transitive", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.EXPORTS, lexer ); assertLex( Parser.IDENTIFIER, "exports", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "exports", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.EXPORTS, lexer ); assertLex( Parser.IDENTIFIER, "to", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "to", lexer ); assertLex( Parser.TO, lexer ); assertLex( Parser.IDENTIFIER, "to", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "to", lexer ); assertLex( Parser.COMMA, lexer ); assertLex( Parser.IDENTIFIER, "to", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "to", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.OPENS, lexer ); assertLex( Parser.IDENTIFIER, "opens", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "opens", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.OPENS, lexer ); assertLex( Parser.IDENTIFIER, "to", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "to", lexer ); assertLex( Parser.TO, lexer ); assertLex( Parser.IDENTIFIER, "to", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "to", lexer ); assertLex( Parser.COMMA, lexer ); assertLex( Parser.IDENTIFIER, "to", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "to", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.USES, lexer ); assertLex( Parser.IDENTIFIER, "uses", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "uses", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.PROVIDES, lexer ); assertLex( Parser.IDENTIFIER, "with", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "with", lexer ); assertLex( Parser.WITH, lexer ); assertLex( Parser.IDENTIFIER, "with", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "with", lexer ); assertLex( Parser.COMMA, lexer ); assertLex( Parser.IDENTIFIER, "with", lexer ); assertLex( Parser.DOT, lexer ); assertLex( Parser.IDENTIFIER, "with", lexer ); assertLex( Parser.SEMI, lexer ); assertLex( Parser.BRACECLOSE, lexer ); assertLex( 0, lexer ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/parser/ParseExceptionTest.java000066400000000000000000000025171325201777200305140ustar00rootroot00000000000000package com.thoughtworks.qdox.parser; import static org.junit.Assert.*; import org.junit.Test; public class ParseExceptionTest { @Test public void testNullParseException() { ParseException pe = new ParseException( null, -1, -1 ); try { pe.getMessage(); fail( "Message should never be null" ); } catch( NullPointerException npe ) { } } @Test public void testEmptyParseException() { ParseException pe = new ParseException( "", -1, -1 ); assertEquals("", pe.getMessage()); } @Test public void testNegativeColumnParseException() { ParseException pe = new ParseException( "Failed to parse:", 5, -50 ); assertEquals("Failed to parse: @[5]", pe.getMessage()); } @Test public void testPositiveColumnParseException() { ParseException pe = new ParseException( "Failed to parse:", 5, 50 ); assertEquals("Failed to parse: @[5,50]", pe.getMessage()); } @Test public void testSurceInfoParseException() { ParseException pe = new ParseException( "Failed to parse:", 5, 50 ); pe.setSourceInfo( "com/foo/Bar.java" ); assertEquals("Failed to parse: @[5,50] in com/foo/Bar.java", pe.getMessage()); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/parser/ParserTest.java000066400000000000000000003300631325201777200270170ustar00rootroot00000000000000package com.thoughtworks.qdox.parser; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import java.util.Collection; import java.util.LinkedList; import org.junit.Assert; import org.mockito.ArgumentCaptor; import org.mockito.stubbing.answers.ReturnsElementsOf; import com.thoughtworks.qdox.builder.Builder; import com.thoughtworks.qdox.parser.expression.ExpressionDef; import com.thoughtworks.qdox.parser.impl.Parser; import com.thoughtworks.qdox.parser.structs.AnnoDef; import com.thoughtworks.qdox.parser.structs.ClassDef; import com.thoughtworks.qdox.parser.structs.FieldDef; import com.thoughtworks.qdox.parser.structs.InitDef; import com.thoughtworks.qdox.parser.structs.MethodDef; import com.thoughtworks.qdox.parser.structs.ModuleDef; import com.thoughtworks.qdox.parser.structs.PackageDef; import com.thoughtworks.qdox.parser.structs.TypeDef; import com.thoughtworks.qdox.parser.structs.WildcardTypeDef; import junit.framework.TestCase; public class ParserTest extends TestCase { private Collection lexValues = new LinkedList(); private Collection textValues = new LinkedList(); private Collection codeBodyValues = new LinkedList(); private JavaLexer lexer; private Builder builder; public ParserTest(String s) { super(s); } @Override protected void setUp() throws Exception { builder = mock(Builder.class); lexer = mock(JavaLexer.class); lexValues.clear(); textValues.clear(); } @Override protected void tearDown() throws Exception { verifyNoMoreInteractions( builder ); } public void testPackageWithOneWord() throws Exception { // setup values setupLex(Parser.PACKAGE); setupLex(Parser.IDENTIFIER, "mypackage"); setupLex(Parser.SEMI); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // verify ArgumentCaptor argument = ArgumentCaptor.forClass(PackageDef.class); verify(builder).addPackage( argument.capture() ); assertEquals( "mypackage", argument.getValue().getName() ); } public void testPackageWithMultipleWords() throws Exception { // setup values setupLex(Parser.PACKAGE); setupLex(Parser.IDENTIFIER, "com"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "blah"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "thingy"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.SEMI); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // verify ArgumentCaptor argument = ArgumentCaptor.forClass(PackageDef.class); verify(builder).addPackage( argument.capture() ); assertEquals( "com.blah.thingy.x", argument.getValue().getName() ); } public void testPackageWithAnnotation() throws Exception { // setup values setupLex(Parser.AT); setupLex(Parser.IDENTIFIER, "Bar"); setupLex(Parser.PACKAGE); setupLex(Parser.IDENTIFIER, "mypackage"); setupLex(Parser.SEMI); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // verify ArgumentCaptor annoCaptor = ArgumentCaptor.forClass( AnnoDef.class ); verify( builder ).addAnnotation( annoCaptor.capture() ); assertEquals( "Bar", annoCaptor.getValue().getTypeDef().getName() ); ArgumentCaptor argument = ArgumentCaptor.forClass( PackageDef.class ); verify( builder ).addPackage( argument.capture() ); assertEquals( "mypackage", argument.getValue().getName() ); } public void testImportWithOneWord() throws Exception { // setup values setupLex(Parser.IMPORT); setupLex(Parser.IDENTIFIER, "mypackage"); setupLex(Parser.SEMI); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // verify verify(builder).addImport( "mypackage" ); } public void testImportWithMultipleWords() throws Exception { // setup values setupLex(Parser.IMPORT); setupLex(Parser.IDENTIFIER, "com"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "blah"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "thingy"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.SEMI); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // verify verify(builder).addImport( "com.blah.thingy.x" ); } public void testImportWithOneWordAndStar() throws Exception { // setup values setupLex(Parser.IMPORT); setupLex(Parser.IDENTIFIER, "mypackage"); setupLex(Parser.DOT); setupLex(Parser.STAR); setupLex(Parser.SEMI); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // verify verify(builder).addImport( "mypackage.*" ); } public void testImportWithMultipleWordsAndStar() throws Exception { // setup values setupLex(Parser.IMPORT); setupLex(Parser.IDENTIFIER, "com"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "blah"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "thingy"); setupLex(Parser.DOT); setupLex(Parser.STAR); setupLex(Parser.SEMI); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // verify verify(builder).addImport( "com.blah.thingy.*" ); } public void testImportStaticWithOneWord() throws Exception { // setup values setupLex(Parser.IMPORT); setupLex(Parser.STATIC); setupLex(Parser.IDENTIFIER, "mypackage"); setupLex(Parser.SEMI); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // verify verify(builder).addImport( "static mypackage" ); } public void testImportStaticWithMultipleWords() throws Exception { // setup values setupLex(Parser.IMPORT); setupLex(Parser.STATIC); setupLex(Parser.IDENTIFIER, "com"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "blah"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "Thingy"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.SEMI); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // verify verify(builder).addImport( "static com.blah.Thingy.x" ); } public void testImportStaticWithOneWordAndStar() throws Exception { // setup values setupLex(Parser.IMPORT); setupLex(Parser.STATIC); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.DOT); setupLex(Parser.STAR); setupLex(Parser.SEMI); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // verify verify(builder).addImport( "static MyClass.*" ); } public void testImportStaticWithMultipleWordsAndStar() throws Exception { // setup values setupLex(Parser.IMPORT); setupLex(Parser.STATIC); setupLex(Parser.IDENTIFIER, "com"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "blah"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "Thingy"); setupLex(Parser.DOT); setupLex(Parser.STAR); setupLex(Parser.SEMI); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // verify verify( builder ).addImport( "static com.blah.Thingy.*" ); } public void testEmptyVanillaClass() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).endClass(); assertEquals( "MyClass", classCaptor.getValue().getName() ); } public void testEmptyVanillaInterface() throws Exception { // setup values setupLex(Parser.INTERFACE); setupLex(Parser.IDENTIFIER, "MyInterface"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyInterface", cls.getName() ); assertEquals( ClassDef.INTERFACE, cls.getType() ); } public void testEmptyVanillaEnum() throws Exception { // setup values setupLex(Parser.ENUM); setupLex(Parser.IDENTIFIER, "MyEnum"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyEnum", cls.getName() ); assertEquals( ClassDef.ENUM, cls.getType() ); } public void testEmptyClassExtendsAnotherClass() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MySubClass"); setupLex(Parser.EXTENDS); setupLex(Parser.IDENTIFIER, "com"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "blah"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "MyBaseClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MySubClass", cls.getName() ); Assert.assertArrayEquals( new TypeDef[] { new TypeDef( "com.blah.MyBaseClass" ) }, cls.getExtends().toArray( new TypeDef[0] ) ); } public void testEmptyInterfaceExtendsMultipleInterfaces() throws Exception { // setup values setupLex(Parser.INTERFACE); setupLex(Parser.IDENTIFIER, "MyInterface"); setupLex(Parser.EXTENDS); setupLex(Parser.IDENTIFIER, "com"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "blah"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "AnotherInterface"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "Serializable"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyInterface", cls.getName() ); assertEquals( ClassDef.INTERFACE, cls.getType() ); Assert.assertArrayEquals( new TypeDef[] { new TypeDef( "com.blah.AnotherInterface" ), new TypeDef( "Serializable" ) }, cls.getExtends().toArray( new TypeDef[0] ) ); } public void testEmptyClassImplementsOneInterface() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.IMPLEMENTS); setupLex(Parser.IDENTIFIER, "com"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "blah"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "AnInterface"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); Assert.assertArrayEquals( new TypeDef[] {new TypeDef("com.blah.AnInterface")}, cls.getImplements().toArray( new TypeDef[0] )); } public void testEmptyClassImplementsMultipleInterfaces() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.IMPLEMENTS); setupLex(Parser.IDENTIFIER, "com"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "blah"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "AnInterface"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "java"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "io"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "Serializable"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "Eatable"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); Assert.assertArrayEquals( new TypeDef[] { new TypeDef( "com.blah.AnInterface" ), new TypeDef( "java.io.Serializable" ), new TypeDef( "Eatable" ) }, cls.getImplements().toArray( new TypeDef[0] ) ); } public void testEmptyClassExtendsOneClassAndImplementsOneInterface() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.EXTENDS); setupLex(Parser.IDENTIFIER, "mypackage"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "BaseClass"); setupLex(Parser.IMPLEMENTS); setupLex(Parser.IDENTIFIER, "com"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "blah"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "AnInterface"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); Assert.assertArrayEquals( new TypeDef[] { new TypeDef( "mypackage.BaseClass" ) }, cls.getExtends().toArray( new TypeDef[0] ) ); Assert.assertArrayEquals( new TypeDef[] { new TypeDef( "com.blah.AnInterface" ) }, cls.getImplements().toArray( new TypeDef[0] ) ); } public void testEmptyClassExtendsOneClassAndImplementsMultipleInterface() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.EXTENDS); setupLex(Parser.IDENTIFIER, "mypackage"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "BaseClass"); setupLex(Parser.IMPLEMENTS); setupLex(Parser.IDENTIFIER, "com"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "blah"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "AnInterface"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "java"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "io"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "Serializable"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "Eatable"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); Assert.assertArrayEquals( new TypeDef[] { new TypeDef( "mypackage.BaseClass" ) }, cls.getExtends().toArray( new TypeDef[0] ) ); Assert.assertArrayEquals( new TypeDef[] { new TypeDef( "com.blah.AnInterface" ), new TypeDef( "java.io.Serializable" ), new TypeDef( "Eatable" ) }, cls.getImplements().toArray( new TypeDef[0] ) ); } public void testEmptyClassWithPublicFinalModifiers() throws Exception { // setup values setupLex(Parser.PUBLIC); setupLex(Parser.FINAL); setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); Assert.assertArrayEquals( new String[] { "public", "final" }, cls.getModifiers().toArray( new String[0] ) ); } public void testEmptyClassWithAllModifiers() throws Exception { // setup values setupLex(Parser.PUBLIC); setupLex(Parser.PROTECTED); setupLex(Parser.PRIVATE); setupLex(Parser.FINAL); setupLex(Parser.ABSTRACT); setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); Assert.assertArrayEquals( new String[] {"public", "protected","private", "final", "abstract" }, cls.getModifiers().toArray( new String[0] ) ); } public void testMultipleClassesInSingleFile() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "Class1"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(Parser.PUBLIC); setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "Class2"); setupLex(Parser.EXTENDS); setupLex(Parser.IDENTIFIER, "SubClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(Parser.INTERFACE); setupLex(Parser.IDENTIFIER, "Intf1"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify(builder, times(3)).beginClass( classCaptor.capture() ); verify(builder, times(3)).endClass(); ClassDef cls1 = classCaptor.getAllValues().get( 0 ); assertEquals( "Class1", cls1.getName()); assertEquals( ClassDef.CLASS, cls1.getType() ); ClassDef cls2 = classCaptor.getAllValues().get( 1 ); assertEquals( "Class2", cls2.getName() ); assertEquals( ClassDef.CLASS, cls2.getType() ); Assert.assertArrayEquals( new String[]{"public"}, cls2.getModifiers().toArray( new String[0] )); Assert.assertArrayEquals( new TypeDef[]{new TypeDef("SubClass")}, cls2.getExtends().toArray( new TypeDef[0] )); ClassDef cls3 = classCaptor.getAllValues().get( 2 ); assertEquals( "Intf1", cls3.getName() ); assertEquals( ClassDef.INTERFACE, cls3.getType() ); } public void testSemiColonBetweenClass() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "Class1"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(Parser.SEMI); // ; setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "Class2"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(Parser.SEMI); // ; setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify(builder, times(2)).beginClass( classCaptor.capture() ); verify(builder, times(2)).endClass(); ClassDef cls1 = classCaptor.getAllValues().get( 0 ); assertEquals( "Class1", cls1.getName() ); assertEquals( ClassDef.CLASS, cls1.getType() ); ClassDef cls2 = classCaptor.getAllValues().get( 1 ); assertEquals( "Class2", cls2.getName() ); assertEquals( ClassDef.CLASS, cls2.getType() ); } public void testSimpleVoidMethod() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "void"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass(MethodDef.class); // verify verify(builder).beginClass(classCaptor.capture()); verify(builder).beginMethod(); verify(builder).endMethod( methodCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef("void"), mth.getReturnType() ); } public void testSimpleVoidMethodWithNoCode() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "void"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginMethod(); verify( builder ).endMethod( methodCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef( "void" ), mth.getReturnType() ); } public void testSimpleMethodReturningSomething() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "Something"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginMethod(); verify(builder).endMethod( methodCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef("Something"), mth.getReturnType() ); } public void testSimpleMethodReturningSomethingFullyQualified() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "com"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "blah"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "Something"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginMethod(); verify(builder).endMethod( methodCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef("com.blah.Something"), mth.getReturnType() ); } public void testSimpleMethodWithAllModifiers() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.PUBLIC); setupLex(Parser.PROTECTED); setupLex(Parser.PRIVATE); setupLex(Parser.ABSTRACT); setupLex(Parser.STATIC); setupLex(Parser.FINAL); setupLex(Parser.NATIVE); setupLex(Parser.SYNCHRONIZED); setupLex(Parser.VOLATILE); setupLex(Parser.IDENTIFIER, "com"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "blah"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "Something"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor captor = ArgumentCaptor.forClass( MethodDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginMethod(); verify(builder).endMethod( captor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = captor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef("com.blah.Something"), mth.getReturnType() ); Assert.assertArrayEquals(new String[]{"public", "protected", "private", "abstract", "static", "final", "native", "synchronized", "volatile"}, mth.getModifiers().toArray(new String[0])); } public void testMethodWithOneArg() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "void"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "numberOfTimes"); setupLex(Parser.PARENCLOSE); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); ArgumentCaptor p1 = ArgumentCaptor.forClass( FieldDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginMethod(); verify(builder).endMethod( methodCaptor.capture() ); verify(builder).addParameter( p1.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef("void"), mth.getReturnType() ); FieldDef prm = p1.getValue(); assertEquals( "numberOfTimes", prm.getName() ); assertEquals( new TypeDef("int"), prm.getType() ); } public void testMethodWithOneFullyQualifiedArg() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "void"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.IDENTIFIER, "java"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "lang"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "String"); setupLex(Parser.IDENTIFIER, "numberOfTimes"); setupLex(Parser.PARENCLOSE); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); ArgumentCaptor p1 = ArgumentCaptor.forClass( FieldDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginMethod(); verify(builder).endMethod( methodCaptor.capture() ); verify(builder).addParameter( p1.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef("void"), mth.getReturnType() ); FieldDef prm = p1.getValue(); assertEquals( "numberOfTimes", prm.getName() ); assertEquals( new TypeDef("java.lang.String"), prm.getType() ); } public void testMethodWithTwoArgs() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "void"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "numberOfTimes"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "String"); setupLex(Parser.IDENTIFIER, "name"); setupLex(Parser.PARENCLOSE); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); ArgumentCaptor p = ArgumentCaptor.forClass(FieldDef.class); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginMethod(); verify(builder).endMethod( methodCaptor.capture() ); verify(builder, times(2) ).addParameter( p.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef("void"), mth.getReturnType() ); FieldDef p1 = p.getAllValues().get( 0 ); assertEquals( "numberOfTimes", p1.getName() ); assertEquals( new TypeDef( "int" ), p1.getType() ); FieldDef p2 = p.getAllValues().get( 1 ); assertEquals( "name", p2.getName() ); assertEquals( new TypeDef( "String" ), p2.getType() ); } public void testMethodWithThreeArgs() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "void"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "numberOfTimes"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "String"); setupLex(Parser.IDENTIFIER, "name"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "boolean"); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.PARENCLOSE); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass(MethodDef.class); ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(FieldDef.class); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginMethod(); verify( builder ).endMethod( methodCaptor.capture() ); verify( builder, times(3) ).addParameter( parameterCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef("void"), mth.getReturnType() ); FieldDef p1 = parameterCaptor.getAllValues().get( 0 ); assertEquals( "numberOfTimes", p1.getName() ); assertEquals( new TypeDef( "int" ), p1.getType() ); FieldDef p2 = parameterCaptor.getAllValues().get( 1 ); assertEquals( "name", p2.getName() ); assertEquals( new TypeDef( "String" ), p2.getType() ); FieldDef p3 = parameterCaptor.getAllValues().get( 2 ); assertEquals( "x", p3.getName() ); assertEquals( new TypeDef( "boolean" ), p3.getType() ); } public void testMethodWithOneArgThatHasModifier() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "void"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.FINAL); setupLex(Parser.VOLATILE); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "numberOfTimes"); setupLex(Parser.PARENCLOSE); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass(MethodDef.class); ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(FieldDef.class); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginMethod(); verify(builder).endMethod( methodCaptor.capture() ); verify(builder).addParameter( parameterCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef("void"), mth.getReturnType() ); assertEquals( "numberOfTimes", parameterCaptor.getValue().getName() ); Assert.assertArrayEquals( new String[] { "final", "volatile" }, parameterCaptor.getValue().getModifiers().toArray( new String[0] ) ); assertEquals( new TypeDef("int"), parameterCaptor.getValue().getType() ); } public void testMethodWithAnnotatedGenericReturnValue() throws Exception { setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.PUBLIC); setupLex(Parser.LESSTHAN); setupLex(Parser.IDENTIFIER, "T"); setupLex(Parser.GREATERTHAN); setupLex(Parser.AT); setupLex(Parser.IDENTIFIER, "Nullable"); setupLex(Parser.IDENTIFIER, "T"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); Parser parser = new Parser(lexer, builder); parser.parse(); ArgumentCaptor classCaptor = ArgumentCaptor.forClass(ClassDef.class); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass(MethodDef.class); ArgumentCaptor annotationCaptor = ArgumentCaptor.forClass(AnnoDef.class); verify(builder).beginClass(classCaptor.capture()); verify(builder).beginMethod(); verify(builder).endMethod(methodCaptor.capture()); verify(builder).addAnnotation(annotationCaptor.capture()); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals("MyClass", cls.getName()); MethodDef mth = methodCaptor.getValue(); assertTrue(mth.getModifiers().contains("public")); assertEquals(new TypeDef("T"), mth.getReturnType()); assertEquals("doSomething", mth.getName()); AnnoDef annotation = annotationCaptor.getValue(); assertEquals("Nullable", annotation.getTypeDef().getName()); } public void testMethodThrowingOneException() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "void"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.THROWS); setupLex(Parser.IDENTIFIER, "IOException"); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginMethod(); verify(builder).endMethod( methodCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef( "void" ), mth.getReturnType() ); Assert.assertArrayEquals( new TypeDef[] { new TypeDef("IOException")}, mth.getExceptions().toArray(new TypeDef[0])); } public void testMethodThrowingTwoExceptions() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "void"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.THROWS); setupLex(Parser.IDENTIFIER, "IOException"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "MyException"); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginMethod(); verify( builder ).endMethod( methodCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef( "void" ), mth.getReturnType() ); Assert.assertArrayEquals( new TypeDef[] { new TypeDef( "IOException" ), new TypeDef( "MyException" ) }, mth.getExceptions().toArray( new TypeDef[0] ) ); } public void testMethodThrowingThreeExceptions() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "void"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.THROWS); setupLex(Parser.IDENTIFIER, "IOException"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "MyException"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "AnotherException"); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass(MethodDef.class); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginMethod(); verify(builder).endMethod( methodCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef( "void" ), mth.getReturnType() ); Assert.assertArrayEquals( new TypeDef[] { new TypeDef( "IOException" ), new TypeDef( "MyException" ), new TypeDef( "AnotherException" ) }, mth.getExceptions().toArray( new TypeDef[0] ) ); } public void testMethodThrowingOneFullyQualifiedException() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "void"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.THROWS); setupLex(Parser.IDENTIFIER, "java"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "io"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "IOException"); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginMethod(); verify(builder).endMethod( methodCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef("void"), mth.getReturnType() ); Assert.assertArrayEquals( new TypeDef[] {new TypeDef("java.io.IOException")}, mth.getExceptions().toArray( new TypeDef[0] ) ); } public void testMethodThrowingTwoFullyQualifiedException() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "void"); setupLex(Parser.IDENTIFIER, "doSomething"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.THROWS); setupLex(Parser.IDENTIFIER, "java"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "io"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "IOException"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "java"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "lang"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "RuntimeException"); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginMethod(); verify( builder ).endMethod( methodCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doSomething", mth.getName() ); assertEquals( new TypeDef( "void" ), mth.getReturnType() ); Assert.assertArrayEquals( new TypeDef[] { new TypeDef( "java.io.IOException" ), new TypeDef( "java.lang.RuntimeException" ) }, mth.getExceptions().toArray( new TypeDef[0] ) ); } public void testDefaultConstructor() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginConstructor(); verify(builder).endConstructor( methodCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "MyClass", mth.getName() ); assertEquals(true, mth.isConstructor() ); } public void testPublicConstructorWithParam() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.PUBLIC); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.PARENOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.PARENCLOSE); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass( FieldDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginConstructor(); verify( builder ).addParameter( parameterCaptor.capture() ); verify( builder ).endConstructor( methodCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "MyClass", mth.getName() ); assertEquals( true, mth.isConstructor() ); Assert.assertArrayEquals( new String[] { "public" }, mth.getModifiers().toArray( new String[0] ) ); assertEquals( "count", parameterCaptor.getValue().getName() ); assertEquals( new TypeDef( "int" ), parameterCaptor.getValue().getType() ); } public void testConstructorWithMultipleParams() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.PUBLIC); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.PARENOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "java"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "lang"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "String"); setupLex(Parser.IDENTIFIER, "thingy"); setupLex(Parser.PARENCLOSE); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass( FieldDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginConstructor(); verify( builder, times( 2 ) ).addParameter( parameterCaptor.capture() ); verify( builder ).endConstructor( methodCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "MyClass", mth.getName() ); assertEquals( true, mth.isConstructor() ); Assert.assertArrayEquals( new String[] { "public" }, mth.getModifiers().toArray( new String[0] ) ); FieldDef p1 = parameterCaptor.getAllValues().get( 0 ); assertEquals( "count", p1.getName() ); assertEquals( new TypeDef( "int" ), p1.getType() ); FieldDef p2 = parameterCaptor.getAllValues().get( 1 ); assertEquals( "thingy", p2.getName() ); assertEquals( new TypeDef( "java.lang.String" ), p2.getType() ); } public void testConstructorWithException() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.THROWS); setupLex(Parser.IDENTIFIER, "SomeException"); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginConstructor(); verify( builder ).endConstructor( methodCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "MyClass", mth.getName() ); assertEquals( true, mth.isConstructor() ); Assert.assertArrayEquals( new TypeDef[] { new TypeDef( "SomeException" ) }, mth.getExceptions().toArray( new TypeDef[0] ) ); } public void testConstructorWithMultipleException() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.THROWS); setupLex(Parser.IDENTIFIER, "java"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "io"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "IOException"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "SomeException"); setupLex(Parser.CODEBLOCK); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginConstructor(); verify(builder).endConstructor( methodCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName()); MethodDef mth = methodCaptor.getValue(); assertEquals( "MyClass", mth.getName() ); assertEquals( true, mth.isConstructor() ); Assert.assertArrayEquals( new TypeDef[] { new TypeDef("java.io.IOException"), new TypeDef("SomeException") }, mth.getExceptions().toArray( new TypeDef[0] ) ); } public void testField() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor fieldCaptor = ArgumentCaptor.forClass(FieldDef.class); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginField( fieldCaptor.capture() ); verify(builder).endField(); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); FieldDef fld = fieldCaptor.getValue(); assertEquals( "count", fld.getName() ); assertEquals(new TypeDef("int"), fld.getType() ); } public void testFieldFullyQualified() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "java"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "lang"); setupLex(Parser.DOT); setupLex(Parser.IDENTIFIER, "String"); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor fieldCaptor = ArgumentCaptor.forClass( FieldDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginField( fieldCaptor.capture() ); verify( builder ).endField(); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); FieldDef fld = fieldCaptor.getValue(); assertEquals( "count", fld.getName() ); assertEquals( new TypeDef( "java.lang.String" ), fld.getType() ); } public void testFieldWithModifiers() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.PUBLIC); setupLex(Parser.PROTECTED); setupLex(Parser.PRIVATE); setupLex(Parser.STATIC); setupLex(Parser.FINAL); setupLex(Parser.TRANSIENT); setupLex(Parser.STRICTFP); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor fieldCaptor = ArgumentCaptor.forClass(FieldDef.class); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginField( fieldCaptor.capture() ); verify( builder ).endField(); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); FieldDef fld = fieldCaptor.getValue(); assertEquals( "count", fld.getName() ); assertEquals( new TypeDef("int"), fld.getType() ); Assert.assertArrayEquals( new String[] {"public", "protected", "private", "static", "final", "transient", "strictfp"}, fld.getModifiers().toArray(new String[0])); } public void testFieldWithMultipleDefinitionsOnOneLine() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "String"); setupLex(Parser.IDENTIFIER, "thing"); setupLex(Parser.COMMA); setupLex(Parser.IDENTIFIER, "another"); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor fieldCaptor = ArgumentCaptor.forClass(FieldDef.class); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder, times( 2 ) ).beginField( fieldCaptor.capture() ); verify( builder, times( 2 ) ).endField(); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); FieldDef fld1 = fieldCaptor.getAllValues().get( 0 ); assertEquals( "thing", fld1.getName() ); assertEquals( new TypeDef("String"), fld1.getType() ); FieldDef fld2 = fieldCaptor.getAllValues().get( 1 ); assertEquals( "another", fld2.getName() ); assertEquals( new TypeDef("String"), fld2.getType() ); } public void testFieldWithSimpleGenericType() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "List"); setupLex(Parser.LESSTHAN); setupLex(Parser.IDENTIFIER, "String"); setupLex(Parser.GREATERTHAN); setupLex(Parser.IDENTIFIER, "l"); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor fieldCaptor = ArgumentCaptor.forClass( FieldDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginField( fieldCaptor.capture() ); verify( builder ).endField(); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); FieldDef fld = fieldCaptor.getValue(); assertEquals( "l", fld.getName() ); assertEquals( "List", fld.getType().getName() ); assertEquals( 1, fld.getType().getActualArgumentTypes().size() ); assertEquals( new TypeDef( "String" ), fld.getType().getActualArgumentTypes().get( 0 ) ); } public void testFieldWithWildcardGenericType() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "List"); setupLex(Parser.LESSTHAN); setupLex(Parser.QUERY); setupLex(Parser.EXTENDS); setupLex(Parser.IDENTIFIER, "A"); setupLex(Parser.GREATERTHAN); setupLex(Parser.IDENTIFIER, "l"); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor fieldCaptor = ArgumentCaptor.forClass( FieldDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginField( fieldCaptor.capture() ); verify( builder ).endField(); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); FieldDef fld = fieldCaptor.getValue(); assertEquals( "l", fld.getName() ); assertEquals( "List", fld.getType().getName() ); assertEquals( 1, fld.getType().getActualArgumentTypes().size() ); assertEquals( new WildcardTypeDef( new TypeDef( "A" ), "extends" ), fld.getType().getActualArgumentTypes().get( 0 ) ); } public void testStaticBlock() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.STATIC); setupLex(Parser.CODEBLOCK); // a random method afterwards setupLex(Parser.IDENTIFIER, "void"); setupLex(Parser.IDENTIFIER, "doStuff"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expect no the method, and it shouldn't be static. ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor initCaptor = ArgumentCaptor.forClass( InitDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass(MethodDef.class); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).addInitializer( initCaptor.capture() ); verify(builder).beginMethod(); verify(builder).endMethod( methodCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); MethodDef method = methodCaptor.getValue(); assertEquals( "doStuff", method.getName() ); assertEquals( new TypeDef("void"), method.getReturnType() ); } public void testInnerClass() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "InnerCls"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(Parser.BRACECLOSE); setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "AnotherClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify(builder, times(3) ).beginClass( classCaptor.capture() ); verify(builder, times(3)).endClass(); assertEquals( "MyClass", classCaptor.getAllValues().get( 0 ).getName() ); assertEquals( "InnerCls", classCaptor.getAllValues().get( 1 ).getName() ); assertEquals( "AnotherClass", classCaptor.getAllValues().get( 2 ).getName() ); } public void testRogueSemiColon() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "MyClass"); setupLex(Parser.BRACEOPEN); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "MyClass", cls.getName() ); } public void testFieldNotArray() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor fieldCaptor = ArgumentCaptor.forClass(FieldDef.class); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginField( fieldCaptor.capture() ); verify( builder ).endField(); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); FieldDef fld = fieldCaptor.getValue(); assertEquals( "count", fld.getName() ); assertEquals( new TypeDef("int"), fld.getType() ); assertEquals( 0, fld.getDimensions() ); } public void testFieldArrayOnType() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor fieldCaptor = ArgumentCaptor.forClass( FieldDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginField( fieldCaptor.capture() ); verify( builder ).endField(); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); FieldDef fld = fieldCaptor.getValue(); assertEquals( "count", fld.getName() ); assertEquals( 0, fld.getDimensions() ); assertEquals( "int", fld.getType().getName() ); assertEquals( 1, fld.getType().getDimensions() ); } public void testField2dArrayOnType() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor fieldCaptor = ArgumentCaptor.forClass( FieldDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginField( fieldCaptor.capture() ); verify( builder ).endField(); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); FieldDef fld = fieldCaptor.getValue(); assertEquals( "count", fld.getName() ); assertEquals( 0, fld.getDimensions() ); assertEquals( "int", fld.getType().getName() ); assertEquals( 2, fld.getType().getDimensions() ); } public void testFieldArrayOnName() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor fieldCaptor = ArgumentCaptor.forClass( FieldDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginField( fieldCaptor.capture() ); verify( builder ).endField(); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); FieldDef fld = fieldCaptor.getValue(); assertEquals( "count", fld.getName() ); assertEquals( 1, fld.getDimensions() ); assertEquals( new TypeDef( "int", 0 ), fld.getType() ); } public void testField3dArrayOnTypeAndName() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor fieldCaptor = ArgumentCaptor.forClass(FieldDef.class); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginField( fieldCaptor.capture() ); verify( builder ).endField(); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); FieldDef fld = fieldCaptor.getValue(); assertEquals( "count", fld.getName() ); assertEquals( 1, fld.getDimensions() ); assertEquals( "int", fld.getType().getName() ); assertEquals( 2, fld.getType().getDimensions() ); } public void testFieldArrayThenAnotherNonArray() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.SEMI); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "count2"); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor fieldCaptor = ArgumentCaptor.forClass( FieldDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder, times( 2 ) ).beginField( fieldCaptor.capture() ); verify( builder, times( 2 ) ).endField(); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); FieldDef fld = fieldCaptor.getAllValues().get( 0 ); assertEquals( "count", fld.getName() ); assertEquals( 1, fld.getDimensions() ); assertEquals( new TypeDef( "int" ), fld.getType() ); FieldDef fld2 = fieldCaptor.getAllValues().get( 1 ); assertEquals( "count2", fld2.getName() ); assertEquals( 0, fld2.getDimensions() ); assertEquals( new TypeDef( "int" ), fld2.getType() ); } public void testMethodNoArray() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginMethod(); verify(builder).endMethod( methodCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "count", mth.getName() ); assertEquals( new TypeDef("int"), mth.getReturnType() ); assertEquals( 0, mth.getDimensions() ); } public void testMethodArray() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass(MethodDef.class); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginMethod(); verify(builder).endMethod( methodCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "count", mth.getName() ); assertEquals( "int", mth.getReturnType().getName() ); assertEquals( 1, mth.getReturnType().getDimensions()); } public void testMethodWithArrayDefinedAtEnd() throws Exception { // It is legal in Java to define a method like this: // String doStuff()[] { // ... which is equivalent to: // String[] doStuff() { // This is done in some places in the JDK. setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginMethod(); verify(builder).endMethod( methodCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "count", mth.getName() ); assertEquals( 1, mth.getDimensions() ); assertEquals( new TypeDef("int"), mth.getReturnType() ); } public void testMethodReturningArrayWithParamNoArray() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.PARENOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "p1"); setupLex(Parser.PARENCLOSE); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass( FieldDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginMethod(); verify( builder ).addParameter( parameterCaptor.capture() ); verify( builder ).endMethod( methodCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "count", mth.getName() ); assertEquals( new TypeDef( "int", 1 ), mth.getReturnType() ); FieldDef prm = parameterCaptor.getValue(); assertEquals( "p1", prm.getName() ); assertEquals( new TypeDef( "int" ), prm.getType() ); assertEquals( 0, prm.getDimensions() ); } public void testMethodReturningNoArrayWithParamArray() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.PARENOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.IDENTIFIER, "p1"); setupLex(Parser.PARENCLOSE); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass( FieldDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginMethod(); verify( builder ).addParameter( parameterCaptor.capture() ); verify( builder ).endMethod( methodCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "count", mth.getName() ); assertEquals( new TypeDef( "int" ), mth.getReturnType() ); assertEquals( 0, mth.getDimensions() ); FieldDef prm = parameterCaptor.getValue(); assertEquals( "p1", prm.getName() ); assertEquals( 0, prm.getDimensions() ); assertEquals( "int", prm.getType().getName() ); assertEquals( 1, prm.getType().getDimensions() ); } public void testMethodReturningArrayWithParam2dArray() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.IDENTIFIER, "count"); setupLex(Parser.PARENOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.SQUAREOPEN); setupLex(Parser.SQUARECLOSE); setupLex(Parser.IDENTIFIER, "p1"); setupLex(Parser.PARENCLOSE); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass(MethodDef.class); ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(FieldDef.class); // verify verify(builder).beginClass( classCaptor.capture() ); verify(builder).beginMethod(); verify(builder).addParameter( parameterCaptor.capture() ); verify(builder).endMethod( methodCaptor.capture() ); verify(builder).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "count", mth.getName() ); assertEquals( new TypeDef("int", 1), mth.getReturnType() ); FieldDef prm = parameterCaptor.getValue(); assertEquals( "p1", prm.getName() ); assertEquals( "int", prm.getType().getName() ); assertEquals( 2, prm.getType().getDimensions() ); } public void testMethodWithVarArgsParameter() throws Exception { // setup values setupLex(Parser.CLASS); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "void"); setupLex(Parser.IDENTIFIER, "doStuff"); setupLex(Parser.PARENOPEN); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.DOTDOTDOT); setupLex(Parser.IDENTIFIER, "stuff"); setupLex(Parser.PARENCLOSE); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor methodCaptor = ArgumentCaptor.forClass( MethodDef.class ); ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass( FieldDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginMethod(); verify( builder ).addParameter( parameterCaptor.capture() ); verify( builder ).endMethod( methodCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); MethodDef mth = methodCaptor.getValue(); assertEquals( "doStuff", mth.getName() ); assertEquals( new TypeDef( "void" ), mth.getReturnType() ); FieldDef prm = parameterCaptor.getValue(); assertEquals( "stuff", prm.getName() ); assertEquals( new TypeDef( "int" ), prm.getType() ); assertEquals( 0, prm.getDimensions() ); assertEquals( true, prm.isVarArgs() ); } public void testEnumWithConstructors() throws Exception { setupLex(Parser.ENUM); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "a"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.SEMI); setupLex(Parser.IDENTIFIER, "int"); setupLex(Parser.IDENTIFIER, "someField"); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // MethodDef mth = new MethodDef(); // mth.name = "a"; ArgumentCaptor f = ArgumentCaptor.forClass( FieldDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); // verify(mockBuilder).beginConstructor(); // verify(mockBuilder).endConstructor(mth); verify( builder, times( 2 ) ).beginField( f.capture() ); verify( builder, times( 2 ) ).endField(); verify( builder ).endClass(); verifyNoMoreInteractions( builder ); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); assertEquals( ClassDef.ENUM, cls.getType() ); FieldDef fld0 = f.getAllValues().get( 0 ); assertEquals( "a", fld0.getName() ); assertEquals( new TypeDef( "x" ), fld0.getType() ); // bug @todo fixme assertEquals( "", fld0.getBody() ); FieldDef fld1 = f.getAllValues().get( 1 ); assertEquals( "someField", fld1.getName() ); assertEquals( new TypeDef( "int" ), fld1.getType() ); assertEquals( null, fld1.getBody() ); } public void testEnumEndingWithExtraComma() throws Exception { setupLex(Parser.ENUM); setupLex(Parser.IDENTIFIER, "x"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "a"); setupLex(Parser.COMMA); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); // MethodDef mth = new MethodDef(); // mth.name = "a"; ArgumentCaptor f = ArgumentCaptor.forClass(FieldDef.class); // verify verify( builder ).beginClass( classCaptor.capture() ); // verify(mockBuilder).beginConstructor(); // verify(mockBuilder).endConstructor(mth); verify( builder ).beginField( f.capture() ); verify( builder ).endField(); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); assertEquals( ClassDef.ENUM, cls.getType() ); FieldDef fld = f.getValue(); assertEquals( "a", fld.getName() ); assertEquals( new TypeDef( "x" ), fld.getType() ); //bug @todo fixme assertEquals( "" , fld.getBody() ); } // QDOX-266 public void testEnumConstantWithClassBody() throws Exception { setupLex(Parser.PUBLIC); setupLex(Parser.ENUM); setupLex(Parser.IDENTIFIER, "MethodLocationOfEnumMethod"); setupLex(Parser.BRACEOPEN); setupLex(Parser.IDENTIFIER, "A"); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.BRACEOPEN); setupLex(Parser.AT); setupLex(Parser.IDENTIFIER, "Override"); setupLex(Parser.PUBLIC); setupLex(Parser.IDENTIFIER, "void" ); setupLex(Parser.IDENTIFIER, "method" ); setupLex(Parser.PARENOPEN); setupLex(Parser.PARENCLOSE); setupLex(Parser.CODEBLOCK); setupLex(Parser.SEMI); setupLex(Parser.BRACECLOSE); setupLex(Parser.BRACECLOSE); setupLex(0); // execute Parser parser = new Parser(lexer, builder); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor f = ArgumentCaptor.forClass(FieldDef.class); ArgumentCaptor enumConstantClassCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor annoCaptor = ArgumentCaptor.forClass( AnnoDef.class ); ArgumentCaptor methodClassCaptor = ArgumentCaptor.forClass( MethodDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginField( f.capture() ); verify( builder ).beginClass( enumConstantClassCaptor.capture() ); verify( builder ).addAnnotation( annoCaptor.capture() ); verify( builder ).beginMethod(); verify( builder ).endMethod( methodClassCaptor.capture() ); verify( builder ).endClass(); verify( builder ).endField(); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( true, cls.getModifiers().contains( "public" ) ); assertEquals( ClassDef.ENUM, cls.getType() ); assertEquals( "MethodLocationOfEnumMethod", cls.getName() ); FieldDef fld = f.getValue(); assertEquals( "A", fld.getName() ); assertEquals( new TypeDef( "MethodLocationOfEnumMethod" ), fld.getType() ); //ClassDef ecCls = enumConstantClassCaptor.getValue(); AnnoDef ann = annoCaptor.getValue(); assertEquals( "Override", ann.getTypeDef().getName() ); MethodDef mth = methodClassCaptor.getValue(); assertEquals( "method", mth.getName() ); // Class methodLocationOfEnumMethod = MethodLocationOfEnumMethod.class; // Field a = methodLocationOfEnumMethod.getField( "A" ); // assertNotNull( a ); // assertSame( methodLocationOfEnumMethod, a.getDeclaringClass() ); // assertSame( methodLocationOfEnumMethod, a.getType() ); // assertEquals( 2, methodLocationOfEnumMethod.getDeclaredMethods().length); } public void testStaticInitializer() throws Exception { // setup values setupLex( Parser.CLASS ); setupLex( Parser.IDENTIFIER, "x" ); setupLex( Parser.BRACEOPEN ); setupLex( Parser.STATIC ); setupLex( Parser.CODEBLOCK, null, "//test" ); setupLex( Parser.BRACECLOSE ); setupLex( 0 ); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor initCaptor = ArgumentCaptor.forClass( InitDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).addInitializer( initCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); InitDef init = initCaptor.getValue(); assertTrue( init.isStatic() ); assertEquals( "//test", init.getBlockContent() ); } public void testInstanceInitializer() throws Exception { // setup values setupLex( Parser.CLASS ); setupLex( Parser.IDENTIFIER, "x" ); setupLex( Parser.BRACEOPEN ); setupLex( Parser.CODEBLOCK, null, "//test" ); setupLex( Parser.BRACECLOSE ); setupLex( 0 ); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor initCaptor = ArgumentCaptor.forClass( InitDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).addInitializer( initCaptor.capture() ); verify( builder ).endClass(); ClassDef cls = classCaptor.getValue(); assertEquals( "x", cls.getName() ); InitDef init = initCaptor.getValue(); assertFalse( init.isStatic() ); assertEquals( "//test", init.getBlockContent() ); } public void testModule() throws Exception { setupLex( Parser.AT ); setupLex( Parser.IDENTIFIER, "Foo" ); setupLex( Parser.PARENOPEN ); setupLex( Parser.INTEGER_LITERAL, "1" ); setupLex( Parser.PARENCLOSE ); setupLex( Parser.AT ); setupLex( Parser.IDENTIFIER, "Foo" ); setupLex( Parser.PARENOPEN ); setupLex( Parser.INTEGER_LITERAL, "2" ); setupLex( Parser.PARENCLOSE ); setupLex( Parser.AT ); setupLex( Parser.IDENTIFIER, "Bar" ); setupLex( Parser.OPEN ); setupLex( Parser.MODULE ); setupLex( Parser.IDENTIFIER, "M" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "N" ); setupLex( Parser.BRACEOPEN ); setupLex( Parser.REQUIRES ); setupLex( Parser.IDENTIFIER, "A" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "B" ); setupLex( Parser.SEMI ); setupLex( Parser.REQUIRES ); setupLex( Parser.TRANSITIVE ); setupLex( Parser.IDENTIFIER, "C" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "D" ); setupLex( Parser.SEMI ); setupLex( Parser.REQUIRES ); setupLex( Parser.STATIC ); setupLex( Parser.IDENTIFIER, "E" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "F" ); setupLex( Parser.SEMI ); setupLex( Parser.REQUIRES ); setupLex( Parser.TRANSITIVE ); setupLex( Parser.STATIC ); setupLex( Parser.IDENTIFIER, "G" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "H" ); setupLex( Parser.SEMI ); setupLex( Parser.EXPORTS ); setupLex( Parser.IDENTIFIER, "P" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "Q" ); setupLex( Parser.SEMI ); setupLex( Parser.EXPORTS ); setupLex( Parser.IDENTIFIER, "R" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "S" ); setupLex( Parser.TO ); setupLex( Parser.IDENTIFIER, "T1" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "U1" ); setupLex( Parser.COMMA ); setupLex( Parser.IDENTIFIER, "T2" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "U2" ); setupLex( Parser.SEMI ); setupLex( Parser.OPENS ); setupLex( Parser.IDENTIFIER, "P" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "Q" ); setupLex( Parser.SEMI ); setupLex( Parser.OPENS ); setupLex( Parser.IDENTIFIER, "R" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "S" ); setupLex( Parser.TO ); setupLex( Parser.IDENTIFIER, "T1" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "U1" ); setupLex( Parser.COMMA ); setupLex( Parser.IDENTIFIER, "T2" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "U2" ); setupLex( Parser.SEMI ); setupLex( Parser.USES ); setupLex( Parser.IDENTIFIER, "V" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "W" ); setupLex( Parser.SEMI ); setupLex( Parser.PROVIDES ); setupLex( Parser.IDENTIFIER, "X" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "Y" ); setupLex( Parser.WITH ); setupLex( Parser.IDENTIFIER, "Z1" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "Z2" ); setupLex( Parser.COMMA ); setupLex( Parser.IDENTIFIER, "Z3" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "Z4" ); setupLex( Parser.SEMI ); setupLex( Parser.BRACECLOSE ); setupLex( 0 ); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); ArgumentCaptor annoCaptor = ArgumentCaptor.forClass( AnnoDef.class ); verify( builder, times(3) ).addAnnotation( annoCaptor.capture() ); assertEquals( "Foo", annoCaptor.getAllValues().get( 0 ).getTypeDef().getName() ); assertEquals( "1", annoCaptor.getAllValues().get( 0 ).getArgs().get( "value" ).toString()); assertEquals( "Foo", annoCaptor.getAllValues().get( 1 ).getTypeDef().getName() ); assertEquals( "2", annoCaptor.getAllValues().get( 1 ).getArgs().get( "value" ).toString()); assertEquals( "Bar", annoCaptor.getAllValues().get( 2 ).getTypeDef().getName() ); assertEquals( null, annoCaptor.getAllValues().get( 2 ).getArgs().get( "value" )); ArgumentCaptor moduleCaptor = ArgumentCaptor.forClass( ModuleDef.class ); verify( builder ).setModule( moduleCaptor.capture() ); assertEquals( "M.N", moduleCaptor.getValue().getName() ); assertEquals( true, moduleCaptor.getValue().isOpen() ); ArgumentCaptor requiresCaptor = ArgumentCaptor.forClass( ModuleDef.RequiresDef.class ); verify( builder, times(4) ).addRequires( requiresCaptor.capture() ); assertEquals( "A.B", requiresCaptor.getAllValues().get(0).getName() ); assertEquals( false, requiresCaptor.getAllValues().get(0).getModifiers().contains( "transitive" ) ); assertEquals( false, requiresCaptor.getAllValues().get(0).getModifiers().contains( "static" ) ); assertEquals( "C.D", requiresCaptor.getAllValues().get(1).getName() ); assertEquals( true, requiresCaptor.getAllValues().get(1).getModifiers().contains( "transitive" ) ); assertEquals( false, requiresCaptor.getAllValues().get(1).getModifiers().contains( "static" ) ); assertEquals( "E.F", requiresCaptor.getAllValues().get(2).getName() ); assertEquals( false, requiresCaptor.getAllValues().get(2).getModifiers().contains( "transitive" ) ); assertEquals( true, requiresCaptor.getAllValues().get(2).getModifiers().contains( "static" ) ); assertEquals( "G.H", requiresCaptor.getAllValues().get(3).getName() ); assertEquals( true, requiresCaptor.getAllValues().get(3).getModifiers().contains( "transitive" ) ); assertEquals( true, requiresCaptor.getAllValues().get(3).getModifiers().contains( "static" ) ); ArgumentCaptor exportsCaptor = ArgumentCaptor.forClass( ModuleDef.ExportsDef.class ); verify( builder, times(2) ).addExports( exportsCaptor.capture() ); assertEquals( "P.Q", exportsCaptor.getAllValues().get( 0 ).getSource() ); assertEquals( 0, exportsCaptor.getAllValues().get( 0 ).getTargets().size() ); assertEquals( "R.S", exportsCaptor.getAllValues().get( 1 ).getSource() ); assertEquals( 2, exportsCaptor.getAllValues().get( 1 ).getTargets().size() ); assertEquals( true, exportsCaptor.getAllValues().get( 1 ).getTargets().contains( "T1.U1" )); assertEquals( true, exportsCaptor.getAllValues().get( 1 ).getTargets().contains( "T2.U2" )); ArgumentCaptor opensCaptor = ArgumentCaptor.forClass( ModuleDef.OpensDef.class ); verify( builder, times(2) ).addOpens( opensCaptor.capture() ); assertEquals( "P.Q", opensCaptor.getAllValues().get( 0 ).getSource() ); assertEquals( 0, opensCaptor.getAllValues().get( 0 ).getTargets().size() ); assertEquals( "R.S", opensCaptor.getAllValues().get( 1 ).getSource() ); assertEquals( 2, opensCaptor.getAllValues().get( 1 ).getTargets().size() ); assertEquals( true, opensCaptor.getAllValues().get( 1 ).getTargets().contains( "T1.U1" )); assertEquals( true, opensCaptor.getAllValues().get( 1 ).getTargets().contains( "T2.U2" )); ArgumentCaptor usesCaptor = ArgumentCaptor.forClass( ModuleDef.UsesDef.class ); verify( builder ).addUses( usesCaptor.capture() ); assertEquals( "V.W", usesCaptor.getValue().getService().getName() ); ArgumentCaptor providesCaptor = ArgumentCaptor.forClass( ModuleDef.ProvidesDef.class ); verify( builder, times(1) ).addProvides( providesCaptor.capture() ); assertEquals( "X.Y", providesCaptor.getAllValues().get(0).getService().getName() ); assertEquals( "Z1.Z2", providesCaptor.getAllValues().get(0).getImplementations().get(0).getName() ); assertEquals( "Z3.Z4", providesCaptor.getAllValues().get(0).getImplementations().get(1).getName() ); } public void testCEnums() throws Exception { setupLex( Parser.PUBLIC ); setupLex( Parser.ENUM ); setupLex( Parser.IDENTIFIER, "EnumWithFields" ); setupLex( Parser.BRACEOPEN ); setupLex( Parser.IDENTIFIER, "VALUEA" ); setupLex( Parser.PARENOPEN ); setupLex( Parser.IDENTIFIER, "By" ); setupLex( Parser.DOT ); setupLex( Parser.IDENTIFIER, "linkText" ); setupLex( Parser.PARENOPEN ); setupLex( Parser.STRING_LITERAL, "\"G\""); setupLex( Parser.PARENCLOSE ); setupLex( Parser.COMMA ); setupLex( Parser.STRING_LITERAL, "\"H\""); setupLex( Parser.PARENCLOSE ); setupLex( Parser.BRACECLOSE ); setupLex( 0 ); // execute Parser parser = new Parser( lexer, builder ); parser.parse(); // expectations ArgumentCaptor classCaptor = ArgumentCaptor.forClass( ClassDef.class ); ArgumentCaptor fieldCaptor = ArgumentCaptor.forClass( FieldDef.class ); ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass( ExpressionDef.class ); // verify verify( builder ).beginClass( classCaptor.capture() ); verify( builder ).beginField( fieldCaptor.capture() ); verify( builder, times(3) ).addArgument( argumentCaptor.capture() ); verify( builder ).endField(); verify( builder ).endClass(); } private void setupLex(int token, String value) { lexValues.add( token ); textValues.add( value ); } private void setupLex(int token, String value, String codeBody ) { setupLex( token, value ); codeBodyValues.add( codeBody ); } private void setupLex( int token ) throws Exception { setupLex( token, null ); if ( token == 0 ) { when( lexer.lex() ).thenAnswer( new ReturnsElementsOf( lexValues ) ); when( lexer.text() ).thenAnswer( new ReturnsElementsOf( textValues ) ); when( lexer.getCodeBody() ).thenAnswer( new ReturnsElementsOf( codeBodyValues ) ); when( lexer.getLine() ).thenReturn( -1 ); } } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/parser/impl/000077500000000000000000000000001325201777200250145ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/parser/impl/DefaultJavaCommentLexerTest.java000066400000000000000000000241271325201777200332360ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.impl; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.io.StringReader; import org.junit.Test; public class DefaultJavaCommentLexerTest { private DefaultJavaCommentLexer lexer; @Test public void testSingleLineComment() throws Exception { lexer = new DefaultJavaCommentLexer( new StringReader("// this is a single line comment")); lexAssert( 0 ); assertEquals( "// this is a single line comment", lexer.getCodeBody() ); } @Test public void testCompactMultiLineComment() throws Exception { lexer = new DefaultJavaCommentLexer( new StringReader("/**/")); lexAssert( 0 ); assertEquals( "/**/", lexer.getCodeBody() ); } @Test public void testCompactMultiLineComment2() throws Exception { lexer = new DefaultJavaCommentLexer( new StringReader("/***/")); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/"); lexAssert( 0 ); } @Test public void testCompactMultiLineComment3() throws Exception { lexer = new DefaultJavaCommentLexer( new StringReader("/*****/")); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/****"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/"); lexAssert( 0 ); } @Test public void testSingleRowMultiLineComment() throws Exception { lexer = new DefaultJavaCommentLexer( new StringReader("/* multiline comment with one row */")); lexAssert( 0 ); assertEquals( "/* multiline comment with one row */", lexer.getCodeBody() ); } @Test public void testJavaDocComment() throws Exception { lexer = new DefaultJavaCommentLexer( new StringReader("/** multiline comment with one row */")); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "multiline comment with one row"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/"); lexAssert( 0 ); } @Test public void testSingleTagJavaDoc() throws Exception { lexer = new DefaultJavaCommentLexer( new StringReader("/** @deprecated */")); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**"); lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@deprecated"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/"); lexAssert( 0 ); } @Test public void testDeprecatedJavaDoc() throws Exception { lexer = new DefaultJavaCommentLexer( new StringReader("/** @author John Doe */")); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**"); lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@author"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "John Doe"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/"); lexAssert( 0 ); } @Test public void testMultiTagJavaDoc() throws Exception { lexer = new DefaultJavaCommentLexer( new StringReader("/** @deprecated\n" + " * @author John Doe */")); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**"); lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@deprecated"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n"); lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@author"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "John Doe"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/"); lexAssert( 0 ); } @Test public void testDocletTags() throws Exception { String in = "" + "/**\n" + " * @hello world\n" + " * @a b c d\n" + " * @bye\n" + " * @bye:bye\n" + " */"; lexer = new DefaultJavaCommentLexer(new StringReader(in)); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n"); lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@hello"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "world\n"); lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@a"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "b c d\n"); lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@bye"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n"); lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@bye:bye"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/"); lexAssert(0); } @Test public void testOneLinerDocComment() throws Exception { String in = "/** @hello world */"; lexer = new DefaultJavaCommentLexer(new StringReader(in)); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**"); lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@hello"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "world"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/"); lexAssert(0); } @Test public void testCompressedDocComment() throws Exception { String in = "/**@foo bar*/"; lexer = new DefaultJavaCommentLexer(new StringReader(in)); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**"); lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@foo"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "bar"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/"); lexAssert(0); } @Test public void testDeepJavadocTag() throws Exception { String in = " /** * *** * @m x \n" + "*/"; lexer = new DefaultJavaCommentLexer(new StringReader(in)); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "* *** * @m x \n"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/"); lexAssert(0); } @Test public void testDocCommentContainingAtSymbols() throws Exception { String in = "" + "/**\n" + " * joe@truemesh.com\n" + " * {@link here}.\n" + " * me @home\n" + " * geeks @ play\n" + " */"; lexer = new DefaultJavaCommentLexer(new StringReader(in)); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "joe@truemesh.com\n"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "{@link here}.\n"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "me @home\n"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "geeks @ play\n"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/"); lexAssert(0); } @Test public void testDocCommentContainingStars() throws Exception { String in = "" + "/**\n" + " * 5 * 4\n" + " * SELECT COUNT(*)\n" + " * **stars**everywhere** \n" + " */"; lexer = new DefaultJavaCommentLexer(new StringReader(in)); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "5 * 4\n"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "SELECT COUNT(*)\n"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "**stars**everywhere** \n"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/"); lexAssert(0); } @Test public void testExtraStarsAreIgnoredAtStartAndEnd() throws Exception { String in = "" + "/*****\n" + " * blah\n" + " *****/"; lexer = new DefaultJavaCommentLexer(new StringReader(in)); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/*****"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "blah\n"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*****/"); lexAssert(0); } @Test public void testExtraStarsCompressed() throws Exception { String in = "" + "/***blah***/"; lexer = new DefaultJavaCommentLexer(new StringReader(in)); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/***"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "blah"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "***/"); lexAssert(0); } @Test public void testIgnoreStarPrefix() throws Exception { String in = "" + "/**\n" + " * simple\n" + "\t * indented\n" + " *nospace\n" + " *** multistar\n" + " *\n" + " */"; lexer = new DefaultJavaCommentLexer(new StringReader(in)); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "simple\n"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "indented\n"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "nospace\n"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "multistar\n"); lexAssert(DefaultJavaCommentParser.JAVADOCLINE, "\n"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/"); lexAssert(0); } // QDOX-200 @Test public void testCompactJavaDocTag() throws Exception { String in = "/** @foo*/"; lexer = new DefaultJavaCommentLexer(new StringReader(in)); lexAssert(DefaultJavaCommentParser.JAVADOCSTART, "/**"); lexAssert(DefaultJavaCommentParser.JAVADOCTAG, "@foo"); lexAssert(DefaultJavaCommentParser.JAVADOCEND, "*/"); lexAssert(0); } private void lexAssert(int lex) throws IOException { lexAssert( lex, "" ); } private void lexAssert(int lex, String text) throws IOException { assertEquals(lex, lexer.lex()); assertEquals(text, lexer.text()); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/parser/impl/DefaultJavaCommentParserTest.java000066400000000000000000000163341325201777200334140ustar00rootroot00000000000000package com.thoughtworks.qdox.parser.impl; import static org.junit.Assert.*; import static org.mockito.Mockito.*; import java.io.IOException; import java.util.Collection; import java.util.LinkedList; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.stubbing.answers.ReturnsElementsOf; import com.thoughtworks.qdox.builder.Builder; import com.thoughtworks.qdox.parser.structs.TagDef; public class DefaultJavaCommentParserTest { private Collection lexValues = new LinkedList(); private Collection textValues = new LinkedList(); private DefaultJavaCommentLexer lexer; private Builder builder; @Before public void setUp() { lexer = mock(DefaultJavaCommentLexer.class); builder = mock(Builder.class); lexValues.clear(); textValues.clear(); } @After public void tearDown() { verifyNoMoreInteractions( builder ); } @Test public void testOneLineJavaDoc() throws Exception { // setup values setupLex(DefaultJavaCommentParser.JAVADOCSTART); setupLex(DefaultJavaCommentParser.JAVADOCLINE, "This is great!"); setupLex(DefaultJavaCommentParser.JAVADOCEND); setupLex(0); // execute DefaultJavaCommentParser parser = new DefaultJavaCommentParser(lexer, builder); parser.parse(); // verify verify(builder).addJavaDoc( "This is great!" ); } @Test public void testOneJavaDocTag() throws Exception { // setup values setupLex(DefaultJavaCommentParser.JAVADOCSTART); setupLex(DefaultJavaCommentParser.JAVADOCTAG, "@This"); setupLex(DefaultJavaCommentParser.JAVADOCLINE, "is great!"); setupLex(DefaultJavaCommentParser.JAVADOCEND); setupLex(0); // execute DefaultJavaCommentParser parser = new DefaultJavaCommentParser(lexer, builder); parser.parse(); ArgumentCaptor tagCaptor = ArgumentCaptor.forClass( TagDef.class ); // verify verify(builder).addJavaDocTag( tagCaptor.capture() ); TagDef tag = tagCaptor.getValue(); assertEquals( "This", tag.getName() ); assertEquals( "is great!", tag.getText() ); } @Test public void testOneJavaDocTagWithNoValue() throws Exception { // setup values setupLex(DefaultJavaCommentParser.JAVADOCSTART); setupLex(DefaultJavaCommentParser.JAVADOCTAG, "@eatme"); setupLex(DefaultJavaCommentParser.JAVADOCLINE, ""); setupLex(DefaultJavaCommentParser.JAVADOCEND); setupLex(0); // execute DefaultJavaCommentParser parser = new DefaultJavaCommentParser(lexer, builder); parser.parse(); ArgumentCaptor tagCaptor = ArgumentCaptor.forClass( TagDef.class ); // verify verify(builder).addJavaDocTag( tagCaptor.capture() ); TagDef tag = tagCaptor.getValue(); assertEquals( "eatme", tag.getName() ); assertEquals( "", tag.getText() ); } @Test public void testOneMultiLineJavaDocTag() throws Exception { // setup values setupLex(DefaultJavaCommentParser.JAVADOCSTART); setupLex(DefaultJavaCommentParser.JAVADOCTAG, "@This"); setupLex(DefaultJavaCommentParser.JAVADOCLINE, "is great! Mmmkay."); setupLex(DefaultJavaCommentParser.JAVADOCEND); setupLex(0); // execute DefaultJavaCommentParser parser = new DefaultJavaCommentParser(lexer, builder); parser.parse(); ArgumentCaptor tagCaptor = ArgumentCaptor.forClass( TagDef.class ); // verify verify( builder ).addJavaDocTag( tagCaptor.capture() ); TagDef tag = tagCaptor.getValue(); assertEquals( "This", tag.getName() ); assertEquals( "is great! Mmmkay.", tag.getText() ); } @Test public void testMultipleJavaDocTags() throws Exception { // setup values setupLex(DefaultJavaCommentParser.JAVADOCSTART); setupLex(DefaultJavaCommentParser.JAVADOCTAG, "@This"); setupLex(DefaultJavaCommentParser.JAVADOCLINE, "is great!"); setupLex(DefaultJavaCommentParser.JAVADOCTAG, "@mock"); setupLex(DefaultJavaCommentParser.JAVADOCLINE, "generate"); setupLex(DefaultJavaCommentParser.JAVADOCEND); setupLex(0); // execute DefaultJavaCommentParser parser = new DefaultJavaCommentParser(lexer, builder); parser.parse(); ArgumentCaptor tagCaptor = ArgumentCaptor.forClass( TagDef.class ); // verify verify(builder, times(2)).addJavaDocTag( tagCaptor.capture() ); TagDef tag1 = tagCaptor.getAllValues().get( 0 ); assertEquals( "This", tag1.getName() ); assertEquals( "is great!", tag1.getText() ); TagDef tag2 = tagCaptor.getAllValues().get( 1 ) ; assertEquals( "mock", tag2.getName() ); assertEquals( "generate", tag2.getText() ); } @Test public void testJavaDocTextAndMultipleJavaDocTags() throws Exception { // setup values setupLex(DefaultJavaCommentParser.JAVADOCSTART); setupLex(DefaultJavaCommentParser.JAVADOCLINE, "Welcome! Here is my class."); setupLex(DefaultJavaCommentParser.JAVADOCTAG, "@This"); setupLex(DefaultJavaCommentParser.JAVADOCLINE, "is great!"); setupLex(DefaultJavaCommentParser.JAVADOCTAG, "@mock"); setupLex(DefaultJavaCommentParser.JAVADOCLINE, "generate"); setupLex(DefaultJavaCommentParser.JAVADOCEND); setupLex(0); // execute DefaultJavaCommentParser parser = new DefaultJavaCommentParser(lexer, builder); parser.parse(); ArgumentCaptor tagCaptor = ArgumentCaptor.forClass( TagDef.class ); // verify verify(builder).addJavaDoc( "Welcome! Here is my class." ); verify(builder, times(2) ).addJavaDocTag( tagCaptor.capture() ); TagDef tag1 = tagCaptor.getAllValues().get( 0 ); assertEquals( "This", tag1.getName() ); assertEquals( "is great!", tag1.getText() ); TagDef tag2 = tagCaptor.getAllValues().get( 1 ) ; assertEquals( "mock", tag2.getName() ); assertEquals( "generate", tag2.getText() ); } @Test public void testJavaDocEmpty() throws Exception { // setup values setupLex(DefaultJavaCommentParser.JAVADOCSTART); setupLex(DefaultJavaCommentParser.JAVADOCLINE, ""); setupLex(DefaultJavaCommentParser.JAVADOCEND); setupLex(0); // execute DefaultJavaCommentParser parser = new DefaultJavaCommentParser(lexer, builder); parser.parse(); // verify verify(builder).addJavaDoc( "" ); } private void setupLex(int token, String value) { lexValues.add( token ); textValues.add( value ); } private void setupLex(int token) throws IOException { setupLex(token, null); if( token == 0) { when( lexer.lex() ).thenAnswer( new ReturnsElementsOf( lexValues ) ); when( lexer.text() ).thenAnswer( new ReturnsElementsOf( textValues ) ); when( lexer.getLine() ).thenReturn( -1 ); } } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/testdata/000077500000000000000000000000001325201777200243705ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/testdata/PropertyClass.java000066400000000000000000000021661325201777200300520ustar00rootroot00000000000000package com.thoughtworks.qdox.testdata; // used as test data for properties and binary support and other tests /** * @foo bar="zap" * @aslak.foo bar="dodgeme" */ public class PropertyClass extends Superclass { public static boolean aField; static { aField = true; } protected int protectedField; private int privateField; public PropertyClass() { } protected PropertyClass(PropertyClass other) { privateField = other.privateField; } // not a bean property, sice it's static public static String getFoo() { return "foo"; } public boolean isBar() { return aField; } // not a bean property public void set(int i) { } // not a bean property public final String get() { return null; } protected void protectedMethod() { privateField = 2; protectedField = privateMethod(); } private int privateMethod() { return privateField; } } class Superclass { public int shouldntBeInherited; public int getShouldntBeInherited() { return shouldntBeInherited; } }qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/traversal/000077500000000000000000000000001325201777200245625ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/traversal/TraversalTest.java000066400000000000000000000021151325201777200302270ustar00rootroot00000000000000package com.thoughtworks.qdox.traversal; import junit.framework.TestCase; import com.thoughtworks.qdox.JavaProjectBuilder; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.impl.DefaultJavaExecutable; import com.thoughtworks.qdox.model.impl.DefaultJavaMethod; public class TraversalTest extends TestCase { private JavaProjectBuilder builder; public TraversalTest(String name) { super(name); } @Override protected void setUp() throws Exception { builder = new JavaProjectBuilder(); //by default current classloader is already added, so QDox-classes can be found } public void testParentClassTraversal() { JavaClass javaClass = builder.getClassByName(DefaultJavaMethod.class.getName()); JavaClass parentClass = javaClass.getSuperJavaClass(); assertNotNull("Parent class not found", parentClass); assertEquals("Parent class traversal has returned the wrong parent", DefaultJavaExecutable.class.getName(), parentClass.getFullyQualifiedName()); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/type/000077500000000000000000000000001325201777200235405ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/type/TypeResolverTest.java000066400000000000000000000156331325201777200277160ustar00rootroot00000000000000package com.thoughtworks.qdox.type; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import com.thoughtworks.qdox.library.ClassLibrary; import com.thoughtworks.qdox.type.TypeResolver; public class TypeResolverTest { private TypeResolver typeResolver; @Mock private ClassLibrary classLibrary; @Before public void initMocks() { MockitoAnnotations.initMocks(this); } @Test public void testResolveTypeInnerClass() { when( classLibrary.hasClassReference( "p.X$DogFood" ) ).thenReturn( true ); typeResolver = TypeResolver.byClassName( "p.X", classLibrary, Collections.emptyList() ); assertEquals("p.X$DogFood", typeResolver.resolveType("DogFood")); assertEquals(null, typeResolver.resolveType("Food")); } @Test public void testResolving() { when( classLibrary.hasClassReference( "foo.Bar" ) ).thenReturn( true ); typeResolver = TypeResolver.byPackageName( null, classLibrary, Collections.singletonList( "foo.*" ) ); assertEquals( "foo.Bar", typeResolver.resolveType( "Bar" ) ); assertEquals( "foo.Bar", typeResolver.resolveType( "foo.Bar" ) ); } @Test public void testResolveJavaPrimitive() { List imports = new ArrayList(); imports.add("bogus.int"); imports.add("bogus.double"); String[] primitives = new String[]{ "boolean", "byte", "char", "double", "float", "int", "long", "short", "void" }; typeResolver = TypeResolver.byPackageName( null, classLibrary, imports ); for (int i = 0; i < primitives.length; i++) { assertEquals(primitives[i], typeResolver.resolveType(primitives[i])); } } @Test public void testDontResolveMissingClasses() { typeResolver = TypeResolver.byPackageName( null, classLibrary, Collections.emptyList() ); assertEquals(null, typeResolver.resolveType("not.Found")); } @Test public void testResolveFullyQualifiedName() { typeResolver = TypeResolver.byPackageName( null, classLibrary, Collections.emptyList() ); when( classLibrary.hasClassReference( "open.Bar" ) ).thenReturn( true ); assertEquals( "open.Bar", typeResolver.resolveType( "open.Bar" ) ); } @Test public void testResolveFullyQualifiedImport() { typeResolver = TypeResolver.byPackageName( null, classLibrary, Collections.singletonList( "foo.Bar" ) ); when( classLibrary.hasClassReference( "foo.Bar" ) ).thenReturn( true ); assertEquals( "foo.Bar", typeResolver.resolveType( "Bar" ) ); } @Test public void testResolveChooseFirstMatchingImport() { List imports = new ArrayList(); imports.add( "bogus.package.MyType" ); imports.add( "com.thoughtworks.qdox.model.Type" ); imports.add( "another.package.Type" ); typeResolver = TypeResolver.byPackageName( null, classLibrary, imports ); when( classLibrary.hasClassReference( "bogus.package.MyType" ) ).thenReturn( true ); when( classLibrary.hasClassReference( "com.thoughtworks.qdox.model.Type" ) ).thenReturn( true ); when( classLibrary.hasClassReference( "another.package.Type" ) ).thenReturn( true ); assertEquals( "com.thoughtworks.qdox.model.Type", typeResolver.resolveType( "Type" ) ); } @Test public void testResolveSamePackage() { typeResolver = TypeResolver.byPackageName( "foo", classLibrary, Collections.emptyList() ); when( classLibrary.hasClassReference( "foo.Bar" ) ).thenReturn( true ); assertEquals("foo.Bar", typeResolver.resolveType("Bar")); } @Test public void testResolveFullyQualifiedTrumpsSamePackage() { typeResolver = TypeResolver.byPackageName( "foo", classLibrary, Collections.emptyList() ); when( classLibrary.hasClassReference( "foo.Bar" ) ).thenReturn( true ); when( classLibrary.hasClassReference( "open.Bar" ) ).thenReturn( true ); assertEquals("open.Bar", typeResolver.resolveType("open.Bar")); } @Test public void testResolveFullyQualifiedTrumpsWildCard() { List imports = new ArrayList(); imports.add("foo.*"); imports.add("bar.Bar"); typeResolver = TypeResolver.byPackageName( null, classLibrary, imports ); when( classLibrary.hasClassReference( "foo.Bar" ) ).thenReturn( true ); when( classLibrary.hasClassReference( "bar.Bar" ) ).thenReturn( true ); assertEquals("bar.Bar", typeResolver.resolveType("Bar")); } @Test public void testResolveWildcard() { typeResolver = TypeResolver.byPackageName( null, classLibrary, Collections.singletonList("foo.*") ); when( classLibrary.hasClassReference( "foo.Bar" ) ).thenReturn( true ); assertEquals("foo.Bar", typeResolver.resolveType("Bar")); } @Test public void testResolveJavaLangClass() { typeResolver = TypeResolver.byPackageName( null, classLibrary, Collections.emptyList() ); when( classLibrary.hasClassReference( "java.lang.System" ) ).thenReturn( true ); assertEquals("java.lang.System", typeResolver.resolveType("System")); } @Test public void testResolveSamePackageTrumpsWildcard() { List imports = new ArrayList(); imports.add("com.thoughtworks.qdox.model.Type"); imports.add("foo.*"); typeResolver = TypeResolver.byPackageName( "com.thoughtworks.qdox.model", classLibrary, imports ); when( classLibrary.hasClassReference( "com.thoughtworks.qdox.model.Type" ) ).thenReturn( true ); when( classLibrary.hasClassReference( "foo.Type" ) ).thenReturn( true ); assertEquals("com.thoughtworks.qdox.model.Type", typeResolver.resolveType("Type")); } @Test public void testResolveFullyQualifiedInnerClass() { typeResolver = TypeResolver.byPackageName( "foo", classLibrary, Collections.emptyList() ); when( classLibrary.hasClassReference( "foo.Bar$Fnord" ) ).thenReturn( true ); assertEquals("foo.Bar$Fnord", typeResolver.resolveType("foo.Bar.Fnord")); } @Test public void testResolvePartiallySpecifiedInnerClass() { typeResolver = TypeResolver.byPackageName( "foo", classLibrary, Collections.singletonList("java.util.*") ); when( classLibrary.hasClassReference( "foo.Bar$Fnord" ) ).thenReturn( true ); when( classLibrary.hasClassReference( "java.util.Map$Entry" ) ).thenReturn( true ); assertEquals("foo.Bar$Fnord", typeResolver.resolveType("Bar.Fnord")); assertEquals("java.util.Map$Entry", typeResolver.resolveType("Map.Entry")); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/writer/000077500000000000000000000000001325201777200240735ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/writer/impl/000077500000000000000000000000001325201777200250345ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/writer/impl/DefaultModelWriterTest.java000066400000000000000000000465731325201777200323200ustar00rootroot00000000000000package com.thoughtworks.qdox.writer.impl; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.junit.Before; import org.junit.Test; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaAnnotatedElement; import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaInitializer; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaModule; import com.thoughtworks.qdox.model.JavaModuleDescriptor; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaExports; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaOpens; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaProvides; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaRequires; import com.thoughtworks.qdox.model.JavaModuleDescriptor.JavaUses; import com.thoughtworks.qdox.model.JavaPackage; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.expression.Expression; public class DefaultModelWriterTest { private DefaultModelWriter modelWriter; @Before public void onSetup(){ modelWriter = new DefaultModelWriter(); } @Test public void testCommentToString() { // setup JavaAnnotatedElement annotatedElement = mock(JavaAnnotatedElement.class); when(annotatedElement.getComment()).thenReturn("Hello"); // expectation String expected = "" + "/**\n" + " * Hello\n" + " */\n"; // run modelWriter.commentHeader(annotatedElement); // verify assertEquals(expected, modelWriter.toString()); } @Test public void testMultilineCommentToString() { JavaAnnotatedElement annotatedElement = mock(JavaAnnotatedElement.class); when(annotatedElement.getComment()).thenReturn("Hello\nWorld"); // expectation String expected = "" + "/**\n" + " * Hello\n" + " * World\n" + " */\n"; // run modelWriter.commentHeader(annotatedElement); // verify assertEquals(expected, modelWriter.toString()); } @Test public void testEmptyCommentToString() { // setup JavaAnnotatedElement annotatedElement = mock(JavaAnnotatedElement.class); when(annotatedElement.getComment()).thenReturn(""); // expectation String expected = "" + "/**\n" + " */\n"; // run modelWriter.commentHeader(annotatedElement); // verify assertEquals(expected, modelWriter.toString()); } @Test public void testNoCommentToString() { // setup JavaAnnotatedElement annotatedElement = mock(JavaAnnotatedElement.class); // expectation String expected = ""; // run modelWriter.commentHeader(annotatedElement); // verify assertEquals(expected, modelWriter.toString()); } @Test public void testCommentWithTagToString() { // setup JavaAnnotatedElement annotatedElement = mock(JavaAnnotatedElement.class); when(annotatedElement.getComment()).thenReturn("Hello"); DocletTag monkeyTag = mock(DocletTag.class); when(monkeyTag.getName()).thenReturn( "monkey" ); when(monkeyTag.getValue()).thenReturn( "is in the tree" ); when(annotatedElement.getTags()).thenReturn(Collections.singletonList( monkeyTag )); // expectation String expected = "" + "/**\n" + " * Hello\n" + " *\n" + " * @monkey is in the tree\n" + " */\n"; // run modelWriter.commentHeader(annotatedElement); // verify assertEquals(expected, modelWriter.toString()); } @Test public void testCommentWithMultipleTagsToString() { // setup JavaAnnotatedElement annotatedElement = mock(JavaAnnotatedElement.class); when(annotatedElement.getComment()).thenReturn("Hello"); List tags = new LinkedList(); DocletTag monkeyTag = mock(DocletTag.class); when(monkeyTag.getName()).thenReturn( "monkey" ); when(monkeyTag.getValue()).thenReturn( "is in the tree" ); tags.add( monkeyTag ); DocletTag seeTag = mock( DocletTag.class ); when(seeTag.getName()).thenReturn( "see" ); when(seeTag.getValue()).thenReturn("the doctor" ); tags.add(seeTag); when(annotatedElement.getTags()).thenReturn(tags); // expectation String expected = "" + "/**\n" + " * Hello\n" + " *\n" + " * @monkey is in the tree\n" + " * @see the doctor\n" + " */\n"; // run modelWriter.commentHeader(annotatedElement); // verify assertEquals(expected, modelWriter.toString()); } @Test public void testTagButNoCommentToString() { // setup JavaAnnotatedElement annotatedElement = mock(JavaAnnotatedElement.class); DocletTag monkeyTag = mock(DocletTag.class); when(monkeyTag.getName()).thenReturn( "monkey" ); when(monkeyTag.getValue()).thenReturn( "is in the tree" ); when(annotatedElement.getTags()).thenReturn(Collections.singletonList( monkeyTag )); // expectation String expected = "" + "/**\n" + " * @monkey is in the tree\n" + " */\n"; // run modelWriter.commentHeader(annotatedElement); // verify assertEquals(expected, modelWriter.toString()); } @Test public void testTagWithNoValueToString() { // setup JavaAnnotatedElement annotatedElement = mock(JavaAnnotatedElement.class); DocletTag monkeyTag = mock(DocletTag.class); when(monkeyTag.getName()).thenReturn( "monkey" ); when(monkeyTag.getValue()).thenReturn( "" ); when(annotatedElement.getTags()).thenReturn(Collections.singletonList( monkeyTag )); // expectation String expected = "" + "/**\n" + " * @monkey\n" + " */\n"; // run modelWriter.commentHeader(annotatedElement); // verify assertEquals(expected, modelWriter.toString()); } //enum Eon { HADEAN, ARCHAEAN, PROTEROZOIC, PHANEROZOIC } @Test public void testEnumConstant() { //setup JavaField enumConstant = mock(JavaField.class); when(enumConstant.isEnumConstant()).thenReturn( true ); when(enumConstant.getName()).thenReturn( "HADEAN" ); //expectation String expected = "HADEAN;\n"; //run modelWriter.writeField( enumConstant ); //verify assertEquals( expected, modelWriter.toString() ); } @Test public void testEnumConstantWithArgument() { // setup JavaField enumConstant = mock( JavaField.class ); when( enumConstant.isEnumConstant() ).thenReturn( true ); when( enumConstant.getName() ).thenReturn( "PENNY" ); Expression arg = mock( Expression.class ); when( arg.getParameterValue()).thenReturn( "1" ); when( enumConstant.getEnumConstantArguments() ).thenReturn( Collections.singletonList( arg ) ); //expectation String expected = "PENNY( 1 );\n"; //run modelWriter.writeField( enumConstant ); //verify assertEquals( expected, modelWriter.toString() ); } @Test public void testEnumConstantWithArguments() { // setup JavaField enumConstant = mock( JavaField.class ); when( enumConstant.isEnumConstant() ).thenReturn( true ); when( enumConstant.getName() ).thenReturn( "EARTH" ); List args = new ArrayList(); Expression mass = mock( Expression.class ); when( mass.getParameterValue()).thenReturn( "5.976e+24" ); args.add( mass ); Expression radius = mock( Expression.class ); when( radius.getParameterValue()).thenReturn( "6.37814e6" ); args.add( radius ); when( enumConstant.getEnumConstantArguments() ).thenReturn( args ); //expectation String expected = "EARTH( 5.976e+24, 6.37814e6 );\n"; //run modelWriter.writeField( enumConstant ); //verify assertEquals( expected, modelWriter.toString() ); } @Test public void testEnumConstantClass() { // setup JavaField enumConstant = mock( JavaField.class ); when( enumConstant.isEnumConstant() ).thenReturn( true ); when( enumConstant.getName() ).thenReturn( "PLUS" ); JavaClass cls = mock( JavaClass.class ); JavaMethod eval = mock( JavaMethod.class ); JavaType doubleType = mock( JavaType.class ); when( doubleType.getGenericCanonicalName() ).thenReturn( "double" ); when( eval.getReturnType() ).thenReturn( doubleType ); when( eval.getName() ).thenReturn( "eval" ); List params = new ArrayList(); JavaParameter x = mock( JavaParameter.class ); when( x.getGenericCanonicalName() ).thenReturn( "double" ); when( x.getName() ).thenReturn( "x" ); params.add( x ); JavaParameter y = mock( JavaParameter.class ); when( y.getGenericCanonicalName() ).thenReturn( "double" ); when( y.getName() ).thenReturn( "y" ); params.add( y ); when( eval.getParameters() ).thenReturn( params ); when( cls.getMethods() ).thenReturn( Collections.singletonList( eval ) ); when( enumConstant.getEnumConstantClass() ).thenReturn( cls ); //expectation String expected = "PLUS {\n" + "\n" + "\tdouble eval(double x, double y);\n" + "\n" + "}\n" + ";\n"; //run modelWriter.writeField( enumConstant ); //verify assertEquals( expected, modelWriter.toString() ); } @Test public void testJavaParameter() { JavaParameter prm = mock( JavaParameter.class ); when( prm.getGenericCanonicalName() ).thenReturn( "java.lang.String" ); when( prm.getName() ).thenReturn( "argument" ); modelWriter.writeParameter( prm ); String expected = "java.lang.String argument"; assertEquals( expected, modelWriter.toString() ); } @Test public void testJavaParameterVarArgs() { JavaParameter prm = mock( JavaParameter.class ); when( prm.getGenericCanonicalName() ).thenReturn( "java.lang.String" ); when( prm.getName() ).thenReturn( "argument" ); when( prm.isVarArgs() ).thenReturn( true ); modelWriter.writeParameter( prm ); String expected = "java.lang.String... argument"; assertEquals( expected, modelWriter.toString() ); } @Test public void testStaticInitializer() { JavaInitializer init = mock( JavaInitializer.class ); when( init.isStatic() ).thenReturn( true ); when( init.getBlockContent() ).thenReturn( "//test" ); modelWriter.writeInitializer( init ); String expected = "static {\n" + "\t//test\n" + "}\n"; assertEquals( expected, modelWriter.toString() ); } @Test public void testInstanceInitializer() { JavaInitializer init = mock( JavaInitializer.class ); when( init.isStatic() ).thenReturn( false ); when( init.getBlockContent() ).thenReturn( "//test" ); modelWriter.writeInitializer( init ); String expected = "{\n" + "\t//test\n" + "}\n"; assertEquals( expected, modelWriter.toString() ); } @Test public void testAnnotation() { JavaClass annType = mock( JavaClass.class ); when( annType.getGenericCanonicalName() ).thenReturn( "Anno" ); JavaAnnotation ann = mock( JavaAnnotation.class ); when( ann.getType() ).thenReturn( annType ); modelWriter.writeAnnotation( ann ); String expected = "@Anno\n"; assertEquals( expected, modelWriter.toString() ); } @Test public void testModuleDescriptor() { JavaModuleDescriptor descriptor = mock(JavaModuleDescriptor.class); when(descriptor.getName()).thenReturn( "M.N" ); modelWriter.writeModuleDescriptor( descriptor ); String expected = "module M.N {\n\n}\n"; assertEquals( expected, modelWriter.toString() ); } @Test public void testOpenModuleDescriptor() { JavaModuleDescriptor descriptor = mock(JavaModuleDescriptor.class); when(descriptor.getName()).thenReturn( "M.N" ); when(descriptor.isOpen()).thenReturn( true ); modelWriter.writeModuleDescriptor( descriptor ); String expected = "open module M.N {\n\n}\n"; assertEquals( expected, modelWriter.toString() ); } @Test public void testModuleRequires() { JavaRequires requires1 = mock( JavaRequires.class ); JavaModule moduleAB = mock(JavaModule.class); when( moduleAB.getName() ).thenReturn( "A.B" ); when( requires1.getModule() ).thenReturn( moduleAB ); when( requires1.getModifiers() ).thenReturn( Collections.emptyList() ); modelWriter.writeModuleRequires( requires1 ); assertEquals( "requires A.B;\n", modelWriter.toString() ); modelWriter = new DefaultModelWriter(); JavaRequires requires2 = mock( JavaRequires.class ); JavaModule moduleCD = mock(JavaModule.class); when( moduleCD.getName() ).thenReturn( "C.D" ); when( requires2.getModule() ).thenReturn( moduleCD); when( requires2.getModifiers() ).thenReturn( Collections.singleton( "public" ) ); modelWriter.writeModuleRequires( requires2 ); assertEquals( "requires public C.D;\n", modelWriter.toString() ); modelWriter = new DefaultModelWriter(); JavaRequires requires3 = mock( JavaRequires.class ); JavaModule moduleEF = mock(JavaModule.class); when( moduleEF.getName() ).thenReturn( "E.F" ); when( requires3.getModule() ).thenReturn( moduleEF ); when( requires3.getModifiers() ).thenReturn( Collections.singleton( "static" ) ); modelWriter.writeModuleRequires( requires3 ); assertEquals( "requires static E.F;\n", modelWriter.toString() ); modelWriter = new DefaultModelWriter(); JavaRequires requires4 = mock( JavaRequires.class ); JavaModule moduleGH = mock(JavaModule.class); when( moduleGH.getName() ).thenReturn( "G.H" ); when( requires4.getModule() ).thenReturn( moduleGH ); when( requires4.getModifiers() ).thenReturn( Arrays.asList( "public", "static" ) ); modelWriter.writeModuleRequires( requires4 ); assertEquals( "requires public static G.H;\n", modelWriter.toString() ); } @Test public void testModuleExports() { JavaExports exports1 = mock( JavaExports.class ); JavaPackage sourcePQ = mock(JavaPackage.class); when(sourcePQ.getName()).thenReturn( "P.Q" ); when( exports1.getSource() ).thenReturn( sourcePQ ); modelWriter.writeModuleExports( exports1 ); assertEquals( "exports P.Q;\n", modelWriter.toString() ); modelWriter = new DefaultModelWriter(); JavaExports exports2 = mock( JavaExports.class ); JavaPackage sourceRS = mock(JavaPackage.class); when(sourceRS.getName()).thenReturn( "R.S" ); when( exports2.getSource() ).thenReturn( sourceRS ); JavaModule moduleT1U1 = mock( JavaModule.class ); when( moduleT1U1.getName() ).thenReturn( "T1.U1" ); JavaModule moduleT2U2 = mock( JavaModule.class ); when( moduleT2U2.getName() ).thenReturn( "T2.U2" ); when(exports2.getTargets()).thenReturn( Arrays.asList( moduleT1U1, moduleT2U2 ) ); modelWriter.writeModuleExports( exports2 ); assertEquals( "exports R.S to T1.U1, T2.U2;\n", modelWriter.toString() ); } @Test public void testModuleOpens() { modelWriter = new DefaultModelWriter(); JavaOpens opens1 = mock( JavaOpens.class ); JavaPackage source1 = mock(JavaPackage.class); when(source1.getName()).thenReturn( "P.Q" ); when( opens1.getSource() ).thenReturn( source1 ); modelWriter.writeModuleOpens( opens1 ); assertEquals( "opens P.Q;\n", modelWriter.toString() ); modelWriter = new DefaultModelWriter(); JavaOpens opens2 = mock( JavaOpens.class ); JavaPackage source2 = mock(JavaPackage.class); when(source2.getName()).thenReturn( "R.S" ); when( opens2.getSource() ).thenReturn( source2 ); JavaModule moduleT1U1 = mock( JavaModule.class ); when( moduleT1U1.getName() ).thenReturn( "T1.U1" ); JavaModule moduleT2U2 = mock( JavaModule.class ); when( moduleT2U2.getName() ).thenReturn( "T2.U2" ); when( opens2.getTargets()).thenReturn( Arrays.asList( moduleT1U1, moduleT2U2 ) ); modelWriter.writeModuleOpens( opens2 ); assertEquals( "opens R.S to T1.U1, T2.U2;\n", modelWriter.toString() ); } @Test public void testModuleProvides() { JavaProvides provides = mock( JavaProvides.class ); JavaClass service = mock( JavaClass.class ); when( service.getName() ).thenReturn( "X.Y" ); JavaClass providerZ1Z2 = mock( JavaClass.class ); when( providerZ1Z2.getName() ).thenReturn( "Z1.Z2" ); JavaClass providerZ3Z4 = mock( JavaClass.class ); when( providerZ3Z4.getName() ).thenReturn( "Z3.Z4" ); when( provides.getService() ).thenReturn( service ); when( provides.getProviders() ).thenReturn( Arrays.asList( providerZ1Z2, providerZ3Z4 ) ); modelWriter.writeModuleProvides( provides ); assertEquals( "provides X.Y with Z1.Z2, Z3.Z4;\n", modelWriter.toString() ); } @Test public void testModuleUses() { JavaUses uses = mock( JavaUses.class ); JavaClass service = mock( JavaClass.class ); when( service.getName() ).thenReturn( "V.W" ); when( uses.getService() ).thenReturn( service ); modelWriter.writeModuleUses( uses ); assertEquals( "uses V.W;\n", modelWriter.toString() ); } } qdox-qdox-2.0-M8/src/test/java/com/thoughtworks/qdox/writer/impl/IndentBufferTest.java000066400000000000000000000023671325201777200311220ustar00rootroot00000000000000package com.thoughtworks.qdox.writer.impl; import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; import com.thoughtworks.qdox.writer.impl.IndentBuffer; public class IndentBufferTest { private IndentBuffer buffer; @Before public void setUp() { buffer = new IndentBuffer(); } @Test public void testNoIndentation() { buffer.write("A string"); buffer.newline(); buffer.write("more string"); buffer.write('s'); buffer.newline(); String expected = "" + "A string\n" + "more strings\n"; assertEquals(expected, buffer.toString()); } @Test public void testIndentation() { buffer.write("Line1"); buffer.newline(); buffer.indent(); buffer.write("Indent1"); buffer.newline(); buffer.write("Indent2"); buffer.write(" more"); buffer.newline(); buffer.deindent(); buffer.write("Line2"); buffer.newline(); String expected = "" + "Line1\n" + "\tIndent1\n" + "\tIndent2 more\n" + "Line2\n"; assertEquals(expected, buffer.toString()); } } qdox-qdox-2.0-M8/src/test/resources/000077500000000000000000000000001325201777200173475ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/resources/com/000077500000000000000000000000001325201777200201255ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/resources/com/thoughtworks/000077500000000000000000000000001325201777200226755ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/resources/com/thoughtworks/qdox/000077500000000000000000000000001325201777200236505ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/resources/com/thoughtworks/qdox/testdata/000077500000000000000000000000001325201777200254615ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/resources/com/thoughtworks/qdox/testdata/DefaultCtor.java000066400000000000000000000004421325201777200305400ustar00rootroot00000000000000/* ---------------------------------------------------------------------------- * (c) Volantis Systems Ltd 2007. All Rights Reserved. * ---------------------------------------------------------------------------- */ package com.thoughtworks.qdox.testdata; public class DefaultCtor { } qdox-qdox-2.0-M8/src/test/resources/com/thoughtworks/qdox/testdata/Latin1.java000066400000000000000000000001501325201777200274500ustar00rootroot00000000000000package com.thoughtworks.qdox.testdata; /** * TEST-CHARS: */ public class Latin1 { } qdox-qdox-2.0-M8/src/test/resources/com/thoughtworks/qdox/testdata/PropertyClass.java000066400000000000000000000021661325201777200311430ustar00rootroot00000000000000package com.thoughtworks.qdox.testdata; // used as test data for properties and binary support and other tests /** * @foo bar="zap" * @aslak.foo bar="dodgeme" */ public class PropertyClass extends Superclass { public static boolean aField; static { aField = true; } protected int protectedField; private int privateField; public PropertyClass() { } protected PropertyClass(PropertyClass other) { privateField = other.privateField; } // not a bean property, sice it's static public static String getFoo() { return "foo"; } public boolean isBar() { return aField; } // not a bean property public void set(int i) { } // not a bean property public final String get() { return null; } protected void protectedMethod() { privateField = 2; protectedField = privateMethod(); } private int privateMethod() { return privateField; } } class Superclass { public int shouldntBeInherited; public int getShouldntBeInherited() { return shouldntBeInherited; } }qdox-qdox-2.0-M8/src/test/resources/com/thoughtworks/qdox/testdata/UTF8.java000066400000000000000000000001651325201777200270540ustar00rootroot00000000000000package com.thoughtworks.qdox.testdata; /** * TEST-CHARS: ßıΣЯא€ */ public class UTF8 { }qdox-qdox-2.0-M8/src/test/resources/com/thoughtworks/qdox/testdata/Unicode.java000066400000000000000000000001241325201777200277070ustar00rootroot00000000000000package com.thoughtworks.qdox.testdata; class Unicode { String x = "\u0000"; } qdox-qdox-2.0-M8/src/test/resources/com/thoughtworks/qdox/testdata/module-info.java000066400000000000000000000000641325201777200305420ustar00rootroot00000000000000module qdoxtest { exports com.thoughtworks.qdox; }qdox-qdox-2.0-M8/src/test/resources/jigsaw/000077500000000000000000000000001325201777200206335ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/resources/jigsaw/example1/000077500000000000000000000000001325201777200223475ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/resources/jigsaw/example1/module-info.java000066400000000000000000000004001325201777200254220ustar00rootroot00000000000000@Bar module M.N { requires A.B; requires transitive C.D; requires static E.F; requires transitive static G.H; exports P.Q; exports R.S to T1.U1, T2.U2; opens P.Q; opens R.S to T1.U1, T2.U2; uses V.W; provides X.Y with Z1.Z2, Z3.Z4; }qdox-qdox-2.0-M8/src/test/resources/jigsaw/example2/000077500000000000000000000000001325201777200223505ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/resources/jigsaw/example2/module-info.java000066400000000000000000000003521325201777200254310ustar00rootroot00000000000000@Foo(1) @Foo(2) @Bar open module M.N { requires A.B; requires transitive C.D; requires static E.F; requires transitive static G.H; exports P.Q; exports R.S to T1.U1, T2.U2; uses V.W; provides X.Y with Z1.Z2, Z3.Z4; }qdox-qdox-2.0-M8/src/test/resources/qdox-140/000077500000000000000000000000001325201777200206245ustar00rootroot00000000000000qdox-qdox-2.0-M8/src/test/resources/qdox-140/X.jav000066400000000000000000000001101325201777200215250ustar00rootroot00000000000000interface X { void paramWithNonAsciis\u00E4\u00F6\u00FC\u00DF(); }qdox-qdox-2.0-M8/src/test/resources/readme.txt000066400000000000000000000000761325201777200213500ustar00rootroot00000000000000this folder is introduces to have a solid way to test qdox-148