qdox-qdox-2.0-M8/ 0000775 0000000 0000000 00000000000 13252017772 0013567 5 ustar 00root root 0000000 0000000 qdox-qdox-2.0-M8/.gitignore 0000664 0000000 0000000 00000000062 13252017772 0015555 0 ustar 00root root 0000000 0000000 /target/
/.project
/target
/.classpath
/.settings
qdox-qdox-2.0-M8/.travis.yml 0000664 0000000 0000000 00000000111 13252017772 0015671 0 ustar 00root root 0000000 0000000 language: java
jdk:
- openjdk7
- oraclejdk8
script: mvn clean verify
qdox-qdox-2.0-M8/LICENSE.txt 0000664 0000000 0000000 00000001101 13252017772 0015403 0 ustar 00root root 0000000 0000000 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/README.md 0000664 0000000 0000000 00000050020 13252017772 0015043 0 ustar 00root root 0000000 0000000 # QDox
### Status
[](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/ 0000775 0000000 0000000 00000000000 13252017772 0015604 5 ustar 00root root 0000000 0000000 qdox-qdox-2.0-M8/pom.xml 0000664 0000000 0000000 00000035766 13252017772 0015125 0 ustar 00root root 0000000 0000000
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/ 0000775 0000000 0000000 00000000000 13252017772 0014356 5 ustar 00root root 0000000 0000000 qdox-qdox-2.0-M8/src/grammar/ 0000775 0000000 0000000 00000000000 13252017772 0016004 5 ustar 00root root 0000000 0000000 qdox-qdox-2.0-M8/src/grammar/commentlexer.flex 0000664 0000000 0000000 00000013767 13252017772 0021404 0 ustar 00root root 0000000 0000000 package 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.y 0000664 0000000 0000000 00000006705 13252017772 0021065 0 ustar 00root root 0000000 0000000 %{
/*
* 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.flex 0000664 0000000 0000000 00000054325 13252017772 0020014 0 ustar 00root root 0000000 0000000 package 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.y 0000664 0000000 0000000 00000172425 13252017772 0017505 0 ustar 00root root 0000000 0000000 %{
/*
* 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/ 0000775 0000000 0000000 00000000000 13252017772 0014772 5 ustar 00root root 0000000 0000000 qdox-qdox-2.0-M8/src/it/lambda-examples/ 0000775 0000000 0000000 00000000000 13252017772 0020026 5 ustar 00root root 0000000 0000000 qdox-qdox-2.0-M8/src/it/lambda-examples/LambdaExamples01.zip 0000664 0000000 0000000 00000047231 13252017772 0023601 0 ustar 00root root 0000000 0000000 PK
zC LambdaExamples01/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`T u>c19~*jʥpHݹN(n`BDh