Package init
This commit is contained in:
parent
42df814b8f
commit
e22da5366f
61
0001-Fix-build-failure-because-of-freemarker.patch
Normal file
61
0001-Fix-build-failure-because-of-freemarker.patch
Normal file
@ -0,0 +1,61 @@
|
||||
From e5732c989267457c65eb8ef585520fdda4a8e0bd Mon Sep 17 00:00:00 2001
|
||||
From: lei_ju <lj3074194431@163.com>
|
||||
Date: Mon, 24 Aug 2020 15:15:48 +0800
|
||||
Subject: [PATCH] Fix build failure because of freemarker
|
||||
|
||||
|
||||
diff --git a/src/freemarker/core/ActionCodeBI.java b/src/freemarker/core/ActionCodeBI.java
|
||||
index 4cbc9f7..2808c59 100644
|
||||
--- a/src/freemarker/core/ActionCodeBI.java
|
||||
+++ b/src/freemarker/core/ActionCodeBI.java
|
||||
@@ -45,7 +45,7 @@ public class ActionCodeBI extends BuiltIn
|
||||
{
|
||||
public static void init ()
|
||||
{
|
||||
- BuiltIn.builtins.put ("actioncode", new ActionCodeBI ());
|
||||
+ BuiltIn.BUILT_INS_BY_NAME.put ("actioncode", new ActionCodeBI ());
|
||||
}
|
||||
|
||||
TemplateModel _eval (Environment env) throws TemplateException
|
||||
diff --git a/src/freemarker/core/HexBI.java b/src/freemarker/core/HexBI.java
|
||||
index cd04fc3..840c95a 100644
|
||||
--- a/src/freemarker/core/HexBI.java
|
||||
+++ b/src/freemarker/core/HexBI.java
|
||||
@@ -41,7 +41,7 @@ public class HexBI extends BuiltIn
|
||||
{
|
||||
public static void init ()
|
||||
{
|
||||
- BuiltIn.builtins.put ("hex", new HexBI ());
|
||||
+ BuiltIn.BUILT_INS_BY_NAME.put ("hex", new HexBI ());
|
||||
}
|
||||
|
||||
TemplateModel _eval (Environment env) throws TemplateException
|
||||
diff --git a/src/freemarker/core/JavaStringBI.java b/src/freemarker/core/JavaStringBI.java
|
||||
index 4bac9df..088efb6 100644
|
||||
--- a/src/freemarker/core/JavaStringBI.java
|
||||
+++ b/src/freemarker/core/JavaStringBI.java
|
||||
@@ -47,7 +47,7 @@ public class JavaStringBI extends BuiltIn
|
||||
|
||||
public static void init ()
|
||||
{
|
||||
- BuiltIn.builtins.put ("javastring", new JavaStringBI ());
|
||||
+ BuiltIn.BUILT_INS_BY_NAME.put ("javastring", new JavaStringBI ());
|
||||
}
|
||||
|
||||
TemplateModel _eval (Environment env) throws TemplateException
|
||||
diff --git a/src/freemarker/core/TypeBI.java b/src/freemarker/core/TypeBI.java
|
||||
index 9346f6d..a8a4a30 100644
|
||||
--- a/src/freemarker/core/TypeBI.java
|
||||
+++ b/src/freemarker/core/TypeBI.java
|
||||
@@ -48,7 +48,7 @@ public class TypeBI extends BuiltIn
|
||||
{
|
||||
public static void init ()
|
||||
{
|
||||
- BuiltIn.builtins.put ("type", new TypeBI ());
|
||||
+ BuiltIn.BUILT_INS_BY_NAME.put ("type", new TypeBI ());
|
||||
}
|
||||
|
||||
TemplateModel _eval (Environment env) throws TemplateException
|
||||
--
|
||||
2.23.0
|
||||
|
||||
35
cookcc-0.3.3-buildxml.patch
Normal file
35
cookcc-0.3.3-buildxml.patch
Normal file
@ -0,0 +1,35 @@
|
||||
diff -Naur cookcc-0.3.3/build.xml cookcc-0.3.3-work/build.xml
|
||||
--- cookcc-0.3.3/build.xml 2009-07-22 01:13:31.000000000 -0400
|
||||
+++ cookcc-0.3.3-work/build.xml 2011-09-22 07:48:03.609525998 -0400
|
||||
@@ -2,6 +2,7 @@
|
||||
<project name="cookcc" basedir="." default="all">
|
||||
<property name="src" location="${basedir}/src"/>
|
||||
<property name="lib" location="${basedir}/lib"/>
|
||||
+ <property name="javadocdir" location="${basedir}/javadocs"/>
|
||||
<property name="dist" value="${basedir}/dist"/>
|
||||
<property name="tool" value="${basedir}/tool"/>
|
||||
<property name="build" value="${basedir}/cookcc_classes"/>
|
||||
@@ -63,10 +64,6 @@
|
||||
</manifest>
|
||||
<fileset dir="${build}" includes="**/**.class"/>
|
||||
<fileset dir="${src}" excludes="**/**.java"/>
|
||||
- <!-- freemarker jar files -->
|
||||
- <zipfileset src="${lib}/freemarker.jar"/>
|
||||
- <!-- cookxml jar files -->
|
||||
- <zipfileset src="${lib}/cookxml-3.0.1.jar" excludes="LICENSE"/>
|
||||
<fileset dir="${basedir}">
|
||||
<patternset>
|
||||
<include name="${license}"/>
|
||||
@@ -99,4 +96,12 @@
|
||||
</cookcc>
|
||||
</target>
|
||||
|
||||
+ <target name="javadocs">
|
||||
+ <delete dir="${javadocdir}"/>
|
||||
+ <mkdir dir="${javadocdir}"/>
|
||||
+ <javadoc packagenames="org.yuanheng.cookcc" destdir="${javadocdir}" private="true">
|
||||
+ <fileset dir="${src}/org" includes="**/*.java"/>
|
||||
+ </javadoc>
|
||||
+ </target>
|
||||
+
|
||||
</project>
|
||||
95
cookcc-0.3.3-freemarker2.3.2+.patch
Normal file
95
cookcc-0.3.3-freemarker2.3.2+.patch
Normal file
@ -0,0 +1,95 @@
|
||||
diff -Nru cookcc-0.3.3/src/freemarker/core/ActionCodeBI.java cookcc-0.3.3.freemarker/src/freemarker/core/ActionCodeBI.java
|
||||
--- cookcc-0.3.3/src/freemarker/core/ActionCodeBI.java 2008-10-29 00:13:18.000000000 +0100
|
||||
+++ cookcc-0.3.3.freemarker/src/freemarker/core/ActionCodeBI.java 2016-03-12 17:10:12.401069670 +0100
|
||||
@@ -48,11 +48,11 @@
|
||||
BuiltIn.builtins.put ("actioncode", new ActionCodeBI ());
|
||||
}
|
||||
|
||||
- TemplateModel _getAsTemplateModel (Environment env) throws TemplateException
|
||||
+ TemplateModel _eval (Environment env) throws TemplateException
|
||||
{
|
||||
- TemplateModel model = target.getAsTemplateModel (env);
|
||||
- if (!(model instanceof StringModel))
|
||||
- throw invalidTypeException (model, target, env, "string");
|
||||
+ TemplateModel model = target.eval (env);
|
||||
+ //if (!(model instanceof StringModel))
|
||||
+ // throw invalidTypeException (model, target, env, "string");
|
||||
StringModel seq = (StringModel)model;
|
||||
return new ActionCodeBuilder (seq);
|
||||
}
|
||||
@@ -124,3 +124,4 @@
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
+
|
||||
diff -Nru cookcc-0.3.3/src/freemarker/core/HexBI.java cookcc-0.3.3.freemarker/src/freemarker/core/HexBI.java
|
||||
--- cookcc-0.3.3/src/freemarker/core/HexBI.java 2008-10-15 19:10:55.000000000 +0200
|
||||
+++ cookcc-0.3.3.freemarker/src/freemarker/core/HexBI.java 2016-03-12 16:41:22.184418305 +0100
|
||||
@@ -44,11 +44,11 @@
|
||||
BuiltIn.builtins.put ("hex", new HexBI ());
|
||||
}
|
||||
|
||||
- TemplateModel _getAsTemplateModel (Environment env) throws TemplateException
|
||||
+ TemplateModel _eval (Environment env) throws TemplateException
|
||||
{
|
||||
- TemplateModel model = target.getAsTemplateModel (env);
|
||||
- if (!(model instanceof TemplateNumberModel))
|
||||
- throw invalidTypeException (model, target, env, "number");
|
||||
+ TemplateModel model = target.eval (env);
|
||||
+ //if (!(model instanceof TemplateNumberModel))
|
||||
+ // throw invalidTypeException (model, target, env, "number");
|
||||
TemplateNumberModel nModel = (TemplateNumberModel)model;
|
||||
return new Hexanizer (nModel.getAsNumber ().intValue ());
|
||||
}
|
||||
diff -Nru cookcc-0.3.3/src/freemarker/core/JavaStringBI.java cookcc-0.3.3.freemarker/src/freemarker/core/JavaStringBI.java
|
||||
--- cookcc-0.3.3/src/freemarker/core/JavaStringBI.java 2008-10-27 22:57:00.000000000 +0100
|
||||
+++ cookcc-0.3.3.freemarker/src/freemarker/core/JavaStringBI.java 2016-03-12 17:25:44.632644922 +0100
|
||||
@@ -50,11 +50,11 @@
|
||||
BuiltIn.builtins.put ("javastring", new JavaStringBI ());
|
||||
}
|
||||
|
||||
- TemplateModel _getAsTemplateModel (Environment env) throws TemplateException
|
||||
+ TemplateModel _eval (Environment env) throws TemplateException
|
||||
{
|
||||
- TemplateModel model = target.getAsTemplateModel (env);
|
||||
- if (!(model instanceof ArrayModel))
|
||||
- throw invalidTypeException (model, target, env, "array");
|
||||
+ TemplateModel model = target.eval (env);
|
||||
+ //if (!(model instanceof ArrayModel))
|
||||
+ // throw invalidTypeException (model, target, env, "array");
|
||||
ArrayModel seq = (ArrayModel)model;
|
||||
return new JavaStringBuilder (seq);
|
||||
}
|
||||
@@ -105,4 +105,4 @@
|
||||
return new SimpleScalar (buffer.toString ());
|
||||
}
|
||||
}
|
||||
-}
|
||||
\ Manca newline alla fine del file
|
||||
+}
|
||||
diff -Nru cookcc-0.3.3/src/freemarker/core/TypeBI.java cookcc-0.3.3.freemarker/src/freemarker/core/TypeBI.java
|
||||
--- cookcc-0.3.3/src/freemarker/core/TypeBI.java 2008-10-29 00:13:18.000000000 +0100
|
||||
+++ cookcc-0.3.3.freemarker/src/freemarker/core/TypeBI.java 2016-03-12 17:11:36.163541746 +0100
|
||||
@@ -51,11 +51,11 @@
|
||||
BuiltIn.builtins.put ("type", new TypeBI ());
|
||||
}
|
||||
|
||||
- TemplateModel _getAsTemplateModel (Environment env) throws TemplateException
|
||||
+ TemplateModel _eval (Environment env) throws TemplateException
|
||||
{
|
||||
- TemplateModel model = target.getAsTemplateModel (env);
|
||||
- if (!(model instanceof BeanModel))
|
||||
- throw invalidTypeException (model, target, env, "bean");
|
||||
+ TemplateModel model = target.eval (env);
|
||||
+ //if (!(model instanceof BeanModel))
|
||||
+ // throw invalidTypeException (model, target, env, "bean");
|
||||
BeanModel seq = (BeanModel)model;
|
||||
return new TypeBuilder (seq);
|
||||
}
|
||||
@@ -139,4 +139,4 @@
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
-}
|
||||
\ Manca newline alla fine del file
|
||||
+}
|
||||
17
cookcc-0.3.3-pom.xml
Normal file
17
cookcc-0.3.3-pom.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.google.code.cookcc</groupId>
|
||||
<artifactId>cookcc</artifactId>
|
||||
<version>0.3.3</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<version>2.3.13</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
941
cookcc-0.3.3-port-to-jsr-269.patch
Normal file
941
cookcc-0.3.3-port-to-jsr-269.patch
Normal file
@ -0,0 +1,941 @@
|
||||
From a5ad3bdbf48e3d893f3e871682d7548f17b85f8e Mon Sep 17 00:00:00 2001
|
||||
From: Michal Srb <msrb@redhat.com>
|
||||
Date: Wed, 25 Jun 2014 18:53:52 +0200
|
||||
Subject: [PATCH] Port to JSR-269
|
||||
|
||||
Initial attempt
|
||||
---
|
||||
.../com.sun.mirror.apt.AnnotationProcessorFactory | 1 -
|
||||
.../services/javax.annotation.processing.Processor | 1 +
|
||||
.../yuanheng/cookcc/input/javaap/ClassVisitor.java | 190 ++++++++++-----------
|
||||
.../cookcc/input/javaap/CookCCAptFactory.java | 97 -----------
|
||||
.../cookcc/input/javaap/CookCCProcessor.java | 83 +++++++--
|
||||
.../cookcc/input/javaap/CookCCVisitor.java | 145 ++++++----------
|
||||
.../yuanheng/cookcc/input/javaap/EnumVisitor.java | 82 +++------
|
||||
7 files changed, 228 insertions(+), 371 deletions(-)
|
||||
delete mode 100644 javaap_src/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
|
||||
create mode 100644 javaap_src/META-INF/services/javax.annotation.processing.Processor
|
||||
delete mode 100644 javaap_src/org/yuanheng/cookcc/input/javaap/CookCCAptFactory.java
|
||||
|
||||
diff --git a/javaap_src/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory b/javaap_src/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
|
||||
deleted file mode 100644
|
||||
index c3a572f..0000000
|
||||
--- a/javaap_src/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
|
||||
+++ /dev/null
|
||||
@@ -1 +0,0 @@
|
||||
-org.yuanheng.cookcc.input.javaap.CookCCAptFactory
|
||||
\ No newline at end of file
|
||||
diff --git a/javaap_src/META-INF/services/javax.annotation.processing.Processor b/javaap_src/META-INF/services/javax.annotation.processing.Processor
|
||||
new file mode 100644
|
||||
index 0000000..3f398d6
|
||||
--- /dev/null
|
||||
+++ b/javaap_src/META-INF/services/javax.annotation.processing.Processor
|
||||
@@ -0,0 +1 @@
|
||||
+org.yuanheng.cookcc.input.javaap.CookCCProcessor
|
||||
diff --git a/javaap_src/org/yuanheng/cookcc/input/javaap/ClassVisitor.java b/javaap_src/org/yuanheng/cookcc/input/javaap/ClassVisitor.java
|
||||
index a885852..48ca76a 100644
|
||||
--- a/javaap_src/org/yuanheng/cookcc/input/javaap/ClassVisitor.java
|
||||
+++ b/javaap_src/org/yuanheng/cookcc/input/javaap/ClassVisitor.java
|
||||
@@ -27,24 +27,41 @@
|
||||
|
||||
package org.yuanheng.cookcc.input.javaap;
|
||||
|
||||
+import java.io.File;
|
||||
+import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
+import javax.annotation.processing.ProcessingEnvironment;
|
||||
+import javax.lang.model.element.AnnotationMirror;
|
||||
+import javax.lang.model.element.AnnotationValue;
|
||||
+import javax.lang.model.element.Element;
|
||||
+import javax.lang.model.element.ExecutableElement;
|
||||
+import javax.lang.model.element.TypeElement;
|
||||
+import javax.lang.model.element.VariableElement;
|
||||
+import javax.lang.model.type.DeclaredType;
|
||||
+import javax.lang.model.type.TypeKind;
|
||||
+import javax.lang.model.type.TypeMirror;
|
||||
+import javax.lang.model.type.NoType;
|
||||
+import javax.lang.model.util.SimpleElementVisitor6;
|
||||
+import javax.lang.model.util.Types;
|
||||
+
|
||||
+import com.sun.source.tree.CompilationUnitTree;
|
||||
+import com.sun.source.tree.LineMap;
|
||||
+import com.sun.source.tree.Tree;
|
||||
+import com.sun.source.util.SourcePositions;
|
||||
+import com.sun.source.util.TreePath;
|
||||
+import com.sun.source.util.Trees;
|
||||
+
|
||||
import org.yuanheng.cookcc.*;
|
||||
import org.yuanheng.cookcc.doc.*;
|
||||
|
||||
-import com.sun.mirror.declaration.*;
|
||||
-import com.sun.mirror.type.ClassType;
|
||||
-import com.sun.mirror.type.DeclaredType;
|
||||
-import com.sun.mirror.util.DeclarationVisitor;
|
||||
-import com.sun.mirror.util.SourcePosition;
|
||||
-
|
||||
/**
|
||||
* @author Heng Yuan
|
||||
* @version $Id: ClassVisitor.java 674 2009-07-22 03:18:36Z superduperhengyuan $
|
||||
*/
|
||||
-class ClassVisitor implements DeclarationVisitor
|
||||
+class ClassVisitor<R, P> extends SimpleElementVisitor6<R, P>
|
||||
{
|
||||
private final static String PROP_OUTPUT = "outputClass";
|
||||
private final static String PROP_INPUT = "inputClass";
|
||||
@@ -124,26 +141,47 @@ class ClassVisitor implements DeclarationVisitor
|
||||
return buffer.toString ();
|
||||
}
|
||||
|
||||
- static int getAnnotationLineNumber (MethodDeclaration method, String className)
|
||||
+ private static File getFile(Element element, ProcessingEnvironment env) {
|
||||
+ Trees trees = Trees.instance(env);
|
||||
+ SourcePositions sourcePositions = trees.getSourcePositions();
|
||||
+ TreePath treePath = trees.getPath(element);
|
||||
+ CompilationUnitTree compUnitTree = treePath.getCompilationUnit();
|
||||
+
|
||||
+ return new File(compUnitTree.getSourceFile().toUri().getPath());
|
||||
+ }
|
||||
+
|
||||
+ private static int getLineNumber(Element element, ProcessingEnvironment env) {
|
||||
+ Trees trees = Trees.instance(env);
|
||||
+ SourcePositions sourcePositions = trees.getSourcePositions();
|
||||
+ TreePath treePath = trees.getPath(element);
|
||||
+ CompilationUnitTree compUnitTree = treePath.getCompilationUnit();
|
||||
+ Tree leaf = treePath.getLeaf();
|
||||
+ long startPos = sourcePositions.getStartPosition(compUnitTree, leaf);
|
||||
+ long endPos = sourcePositions.getEndPosition(compUnitTree, leaf);
|
||||
+ LineMap lineMap = compUnitTree.getLineMap();
|
||||
+
|
||||
+ return (int) lineMap.getLineNumber(startPos);
|
||||
+ }
|
||||
+
|
||||
+ static int getAnnotationLineNumber (ExecutableElement method, String className, ProcessingEnvironment env)
|
||||
{
|
||||
for (AnnotationMirror mirror : method.getAnnotationMirrors ())
|
||||
{
|
||||
- if (!className.equals (mirror.getAnnotationType ().getDeclaration ().getQualifiedName ()))
|
||||
+ if (!className.equals (((TypeElement) mirror.getAnnotationType ().asElement()).getQualifiedName ()))
|
||||
continue;
|
||||
- SourcePosition pos = mirror.getPosition ();
|
||||
- return pos == null ? 0 : pos.line ();
|
||||
+ return getLineNumber(mirror.getAnnotationType().asElement(), env);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
- static int[] getAnnotationArrayLineNumbers (MethodDeclaration method, String className, String attr)
|
||||
+ static int[] getAnnotationArrayLineNumbers (ExecutableElement method, String className, String attr, ProcessingEnvironment env)
|
||||
{
|
||||
for (AnnotationMirror mirror : method.getAnnotationMirrors ())
|
||||
{
|
||||
- if (!className.equals (mirror.getAnnotationType ().getDeclaration ().getQualifiedName ()))
|
||||
+ if (!className.equals (((TypeElement) mirror.getAnnotationType().asElement()).getQualifiedName ()))
|
||||
continue;
|
||||
- Map<AnnotationTypeElementDeclaration, AnnotationValue> map = mirror.getElementValues ();
|
||||
- for (AnnotationTypeElementDeclaration key : map.keySet ())
|
||||
+ Map<? extends ExecutableElement, ? extends AnnotationValue> map = mirror.getElementValues ();
|
||||
+ for (ExecutableElement key : map.keySet ())
|
||||
{
|
||||
if (!attr.equals (key.getSimpleName ()))
|
||||
continue;
|
||||
@@ -155,11 +193,7 @@ class ClassVisitor implements DeclarationVisitor
|
||||
for (Object o : c)
|
||||
{
|
||||
AnnotationValue v = (AnnotationValue)o;
|
||||
- SourcePosition pos = v.getPosition ();
|
||||
- if (pos == null)
|
||||
- returnVal[i++] = 0;
|
||||
- else
|
||||
- returnVal[i++] = pos.line ();
|
||||
+ returnVal[i++] = getLineNumber((Element) v.getValue(), env);
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
@@ -167,11 +201,10 @@ class ClassVisitor implements DeclarationVisitor
|
||||
return null;
|
||||
}
|
||||
|
||||
- private static String computeOutputClass (ClassType classType)
|
||||
+ private static String computeOutputClass (DeclaredType classType, ProcessingEnvironment env)
|
||||
{
|
||||
- DeclaredType containingType = classType.getContainingType ();
|
||||
- if (containingType == null)
|
||||
- return classType.getDeclaration ().getQualifiedName ();
|
||||
+ if (classType.getEnclosingType() == env.getTypeUtils().getNoType(TypeKind.NONE))
|
||||
+ return ((TypeElement) classType.asElement()).getQualifiedName().toString();
|
||||
throw new IllegalArgumentException ("The generated class cannot be a nested class.");
|
||||
}
|
||||
|
||||
@@ -231,34 +264,32 @@ class ClassVisitor implements DeclarationVisitor
|
||||
getLexer ().addShortcut (shortcutDoc);
|
||||
}
|
||||
|
||||
- private void parseLexs (Lexs lexs, MethodDeclaration method)
|
||||
+ private void parseLexs (Lexs lexs, ExecutableElement method)
|
||||
{
|
||||
if (lexs == null)
|
||||
return;
|
||||
|
||||
- int[] pos = getAnnotationArrayLineNumbers (method, Lexs.class.getName (), "patterns");
|
||||
+ int[] pos = getAnnotationArrayLineNumbers (method, Lexs.class.getName (), "patterns", m_parent.getEnv());
|
||||
int i = 0;
|
||||
for (Lex lex : lexs.patterns ())
|
||||
parseLex (lex, method, pos == null ? 0 : pos[i++]);
|
||||
}
|
||||
|
||||
- private void parseLex (Lex lex, MethodDeclaration method, int lineNumber)
|
||||
+ private void parseLex (Lex lex, ExecutableElement method, int lineNumber)
|
||||
{
|
||||
if (lex == null)
|
||||
return;
|
||||
|
||||
RuleDoc rule = new RuleDoc (getLexer ());
|
||||
|
||||
- SourcePosition pos = method.getPosition ();
|
||||
- if (pos != null)
|
||||
- rule.setLineNumber (pos.line ());
|
||||
+ rule.setLineNumber (getLineNumber(method, m_parent.getEnv()));
|
||||
|
||||
rule.setAction (getLexAction (method, lex.token ()));
|
||||
|
||||
PatternDoc pattern = new PatternDoc ();
|
||||
pattern.setPattern (lex.pattern ());
|
||||
if (lineNumber < 0)
|
||||
- pattern.setLineNumber (getAnnotationLineNumber (method, Lex.class.getName ()));
|
||||
+ pattern.setLineNumber (getAnnotationLineNumber (method, Lex.class.getName (), m_parent.getEnv()));
|
||||
else
|
||||
pattern.setLineNumber (lineNumber);
|
||||
|
||||
@@ -266,18 +297,18 @@ class ClassVisitor implements DeclarationVisitor
|
||||
rule.addStates (lex.state ());
|
||||
}
|
||||
|
||||
- private void parseRules (Rules rules, MethodDeclaration method)
|
||||
+ private void parseRules (Rules rules, ExecutableElement method)
|
||||
{
|
||||
if (rules == null)
|
||||
return;
|
||||
|
||||
- int[] pos = getAnnotationArrayLineNumbers (method, Rules.class.getName (), "rules");
|
||||
+ int[] pos = getAnnotationArrayLineNumbers (method, Rules.class.getName (), "rules", m_parent.getEnv());
|
||||
int i = 0;
|
||||
for (Rule rule : rules.rules ())
|
||||
parseRule (rule, method, pos == null ? 0 : pos[i++]);
|
||||
}
|
||||
|
||||
- private void parseRule (Rule rule, MethodDeclaration method, int lineNumber)
|
||||
+ private void parseRule (Rule rule, ExecutableElement method, int lineNumber)
|
||||
{
|
||||
if (rule == null)
|
||||
return;
|
||||
@@ -286,7 +317,7 @@ class ClassVisitor implements DeclarationVisitor
|
||||
RhsDoc rhs = new RhsDoc ();
|
||||
rhs.setTerms (rule.rhs ());
|
||||
if (lineNumber < 0)
|
||||
- rhs.setLineNumber (getAnnotationLineNumber (method, Rule.class.getName ()));
|
||||
+ rhs.setLineNumber (getAnnotationLineNumber (method, Rule.class.getName (), m_parent.getEnv()));
|
||||
else
|
||||
rhs.setLineNumber (lineNumber);
|
||||
String precedence = rule.precedence ().trim ();
|
||||
@@ -297,7 +328,7 @@ class ClassVisitor implements DeclarationVisitor
|
||||
grammar.addRhs (rhs);
|
||||
}
|
||||
|
||||
- private String getLexAction (MethodDeclaration method, String token)
|
||||
+ private String getLexAction (ExecutableElement method, String token)
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer ();
|
||||
|
||||
@@ -323,7 +354,7 @@ class ClassVisitor implements DeclarationVisitor
|
||||
return buffer.toString ();
|
||||
}
|
||||
|
||||
- private String getParseAction (MethodDeclaration method, String args)
|
||||
+ private String getParseAction (ExecutableElement method, String args)
|
||||
{
|
||||
if (args == null)
|
||||
args = "";
|
||||
@@ -337,7 +368,7 @@ class ClassVisitor implements DeclarationVisitor
|
||||
|
||||
buffer.append (THIS_STR).append (method.getSimpleName ()).append (" (");
|
||||
|
||||
- ParameterDeclaration[] params = method.getParameters ().toArray (new ParameterDeclaration[method.getParameters ().size ()]);
|
||||
+ VariableElement[] params = method.getParameters ().toArray (new VariableElement[method.getParameters ().size ()]);
|
||||
|
||||
int[] argv = getArgs (args);
|
||||
|
||||
@@ -349,7 +380,7 @@ class ClassVisitor implements DeclarationVisitor
|
||||
if (i > 0)
|
||||
buffer.append (", ");
|
||||
int v = argv[i];
|
||||
- String cl = params[i].getType ().toString ();
|
||||
+ String cl = params[i].asType().toString();
|
||||
if ("java.lang.Object" != cl)
|
||||
buffer.append ("(").append (cl).append (")");
|
||||
buffer.append ("yyGetValue (").append (v).append (")");
|
||||
@@ -360,35 +391,23 @@ class ClassVisitor implements DeclarationVisitor
|
||||
return buffer.toString ();
|
||||
}
|
||||
|
||||
- public void visitDeclaration (Declaration declaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitPackageDeclaration (PackageDeclaration packageDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitMemberDeclaration (MemberDeclaration memberDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitTypeDeclaration (TypeDeclaration typeDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitClassDeclaration (ClassDeclaration classDeclaration)
|
||||
+ @Override
|
||||
+ public R visitType(TypeElement classDeclaration, P p)
|
||||
{
|
||||
CookCCOption option = classDeclaration.getAnnotation (CookCCOption.class);
|
||||
if (option == null)
|
||||
- return;
|
||||
+ return DEFAULT_VALUE;
|
||||
m_option = option;
|
||||
|
||||
+ ProcessingEnvironment env = (ProcessingEnvironment) p;
|
||||
+
|
||||
m_doc.setMain (false);
|
||||
- String inputClass = classDeclaration.getQualifiedName ();
|
||||
+ String inputClass = classDeclaration.getQualifiedName().toString();
|
||||
m_doc.setProperty (PROP_INPUT, inputClass);
|
||||
- ClassType superClassType = classDeclaration.getSuperclass ();
|
||||
- ClassDeclaration superClass = superClassType.getDeclaration ();
|
||||
- m_doc.setProperty (PROP_OUTPUT, computeOutputClass (superClassType));
|
||||
+ DeclaredType superClassType = (DeclaredType) classDeclaration.getSuperclass();
|
||||
+ TypeElement superClass = (TypeElement) superClassType.asElement();
|
||||
+
|
||||
+ m_doc.setProperty (PROP_OUTPUT, computeOutputClass (superClassType, m_parent.getEnv()));
|
||||
|
||||
if (superClass.getModifiers ().contains (Modifier.PUBLIC))
|
||||
m_doc.setProperty (PROP_PUBLIC, Boolean.TRUE);
|
||||
@@ -402,46 +421,21 @@ class ClassVisitor implements DeclarationVisitor
|
||||
// try to get the file header
|
||||
try
|
||||
{
|
||||
- m_doc.addCode ("fileheader", generateFileHeader (FileHeaderScanner.getFileHeader (superClass.getPosition ().file ())));
|
||||
+ File file = getFile(superClass, env);
|
||||
+ m_doc.addCode ("fileheader", generateFileHeader (FileHeaderScanner.getFileHeader (file)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
// try to get the class header
|
||||
- m_doc.addCode ("classheader", generateClassHeader (superClass.getDocComment ()));
|
||||
-
|
||||
- m_parent.addDocument (classDeclaration.getQualifiedName (), m_doc);
|
||||
- }
|
||||
-
|
||||
- public void visitEnumDeclaration (EnumDeclaration enumDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitInterfaceDeclaration (InterfaceDeclaration interfaceDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitAnnotationTypeDeclaration (AnnotationTypeDeclaration annotationTypeDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitFieldDeclaration (FieldDeclaration fieldDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitEnumConstantDeclaration (EnumConstantDeclaration enumConstantDeclaration)
|
||||
- {
|
||||
- }
|
||||
+ m_doc.addCode ("classheader", generateClassHeader (m_parent.getEnv().getElementUtils().getDocComment(superClass)));
|
||||
|
||||
- public void visitExecutableDeclaration (ExecutableDeclaration executableDeclaration)
|
||||
- {
|
||||
- }
|
||||
+ m_parent.addDocument (classDeclaration.getQualifiedName().toString(), m_doc);
|
||||
|
||||
- public void visitConstructorDeclaration (ConstructorDeclaration constructorDeclaration)
|
||||
- {
|
||||
+ return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
- public void visitMethodDeclaration (MethodDeclaration method)
|
||||
+ public void visitExecutableElement (ExecutableElement method)
|
||||
{
|
||||
parseLexs (method.getAnnotation (Lexs.class), method);
|
||||
parseLex (method.getAnnotation (Lex.class), method, -1);
|
||||
@@ -450,16 +444,4 @@ class ClassVisitor implements DeclarationVisitor
|
||||
parseRules (method.getAnnotation (Rules.class), method);
|
||||
parseRule (method.getAnnotation (Rule.class), method, -1);
|
||||
}
|
||||
-
|
||||
- public void visitAnnotationTypeElementDeclaration (AnnotationTypeElementDeclaration annotationTypeElementDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitParameterDeclaration (ParameterDeclaration parameterDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitTypeParameterDeclaration (TypeParameterDeclaration typeParameterDeclaration)
|
||||
- {
|
||||
- }
|
||||
}
|
||||
\ No newline at end of file
|
||||
diff --git a/javaap_src/org/yuanheng/cookcc/input/javaap/CookCCAptFactory.java b/javaap_src/org/yuanheng/cookcc/input/javaap/CookCCAptFactory.java
|
||||
deleted file mode 100644
|
||||
index 3d3957c..0000000
|
||||
--- a/javaap_src/org/yuanheng/cookcc/input/javaap/CookCCAptFactory.java
|
||||
+++ /dev/null
|
||||
@@ -1,97 +0,0 @@
|
||||
-/*
|
||||
- * Copyright (c) 2008, Heng Yuan
|
||||
- * All rights reserved.
|
||||
- *
|
||||
- * Redistribution and use in source and binary forms, with or without
|
||||
- * modification, are permitted provided that the following conditions are met:
|
||||
- * * Redistributions of source code must retain the above copyright
|
||||
- * notice, this list of conditions and the following disclaimer.
|
||||
- * * Redistributions in binary form must reproduce the above copyright
|
||||
- * notice, this list of conditions and the following disclaimer in the
|
||||
- * documentation and/or other materials provided with the distribution.
|
||||
- * * Neither the name of the Heng Yuan nor the
|
||||
- * names of its contributors may be used to endorse or promote products
|
||||
- * derived from this software without specific prior written permission.
|
||||
- *
|
||||
- * THIS SOFTWARE IS PROVIDED BY Heng Yuan ''AS IS'' AND ANY
|
||||
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
- * DISCLAIMED. IN NO EVENT SHALL Heng Yuan BE LIABLE FOR ANY
|
||||
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
- */
|
||||
-package org.yuanheng.cookcc.input.javaap;
|
||||
-
|
||||
-import java.util.Arrays;
|
||||
-import java.util.Collection;
|
||||
-import java.util.Collections;
|
||||
-import java.util.Set;
|
||||
-
|
||||
-import com.sun.mirror.apt.AnnotationProcessor;
|
||||
-import com.sun.mirror.apt.AnnotationProcessorEnvironment;
|
||||
-import com.sun.mirror.apt.AnnotationProcessorFactory;
|
||||
-import com.sun.mirror.declaration.AnnotationTypeDeclaration;
|
||||
-
|
||||
-/**
|
||||
- * @author Heng Yuan
|
||||
- * @version $Id: CookCCAptFactory.java 486 2008-11-09 15:09:57Z superduperhengyuan $
|
||||
- */
|
||||
-public class CookCCAptFactory implements AnnotationProcessorFactory
|
||||
-{
|
||||
- private final static Collection<String> s_supportedOptions = Collections.emptySet ();
|
||||
- private final static Collection<String> s_supportedAnnotationTypes = Collections.unmodifiableCollection (Arrays.asList ("org.yuanheng.cookcc.*"));
|
||||
-
|
||||
-// static
|
||||
-// {
|
||||
-// // compute all possible options across all output languages
|
||||
-//
|
||||
-// HashSet<String> options = new HashSet<String> ();
|
||||
-//
|
||||
-// addOptions (options, Main.getOptions ());
|
||||
-//
|
||||
-// for (String lang : Main.getLanguages ())
|
||||
-// {
|
||||
-// try
|
||||
-// {
|
||||
-// CodeGen codeGen = Main.getCodeGen (lang);
|
||||
-// addOptions (options, codeGen.getOptions ());
|
||||
-// }
|
||||
-// catch (Throwable t)
|
||||
-// {
|
||||
-// }
|
||||
-// }
|
||||
-// s_supportedOptions = options;
|
||||
-// }
|
||||
-//
|
||||
-// private static void addOptions (HashSet<String> optionSet, OptionMap optionMap)
|
||||
-// {
|
||||
-// for (String option : optionMap.getAvailableOptions ())
|
||||
-// optionSet.add ("-A" + option.substring (1));
|
||||
-// }
|
||||
-
|
||||
- public Collection<String> supportedOptions ()
|
||||
- {
|
||||
- return s_supportedOptions;
|
||||
- }
|
||||
-
|
||||
- public Collection<String> supportedAnnotationTypes ()
|
||||
- {
|
||||
- return s_supportedAnnotationTypes;
|
||||
- }
|
||||
-
|
||||
- public AnnotationProcessor getProcessorFor (Set<AnnotationTypeDeclaration> annotationTypeDeclarations, AnnotationProcessorEnvironment env)
|
||||
- {
|
||||
- try
|
||||
- {
|
||||
- return new CookCCProcessor (env);
|
||||
- }
|
||||
- catch (Exception ex)
|
||||
- {
|
||||
- throw new IllegalArgumentException ("Invalid CookCC options");
|
||||
- }
|
||||
- }
|
||||
-}
|
||||
diff --git a/javaap_src/org/yuanheng/cookcc/input/javaap/CookCCProcessor.java b/javaap_src/org/yuanheng/cookcc/input/javaap/CookCCProcessor.java
|
||||
index 5753fb2..6b6b478 100644
|
||||
--- a/javaap_src/org/yuanheng/cookcc/input/javaap/CookCCProcessor.java
|
||||
+++ b/javaap_src/org/yuanheng/cookcc/input/javaap/CookCCProcessor.java
|
||||
@@ -26,8 +26,13 @@
|
||||
*/
|
||||
package org.yuanheng.cookcc.input.javaap;
|
||||
|
||||
+import java.lang.annotation.Annotation;
|
||||
+import java.util.Arrays;
|
||||
+import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
+import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
+import java.util.Set;
|
||||
|
||||
import org.yuanheng.cookcc.Main;
|
||||
import org.yuanheng.cookcc.OptionMap;
|
||||
@@ -37,18 +42,31 @@ import org.yuanheng.cookcc.codegen.options.ClassOption;
|
||||
import org.yuanheng.cookcc.doc.Document;
|
||||
import org.yuanheng.cookcc.interfaces.CodeGen;
|
||||
|
||||
-import com.sun.mirror.apt.AnnotationProcessor;
|
||||
-import com.sun.mirror.apt.AnnotationProcessorEnvironment;
|
||||
-import com.sun.mirror.declaration.TypeDeclaration;
|
||||
-import com.sun.mirror.util.DeclarationVisitors;
|
||||
+import javax.annotation.processing.AbstractProcessor;
|
||||
+import javax.annotation.processing.ProcessingEnvironment;
|
||||
+import javax.annotation.processing.RoundEnvironment;
|
||||
+import javax.lang.model.SourceVersion;
|
||||
+import javax.lang.model.element.Element;
|
||||
+import javax.lang.model.element.TypeElement;
|
||||
+
|
||||
|
||||
/**
|
||||
* @author Heng Yuan
|
||||
* @version $Id: CookCCProcessor.java 486 2008-11-09 15:09:57Z superduperhengyuan $
|
||||
*/
|
||||
-class CookCCProcessor implements AnnotationProcessor
|
||||
+public class CookCCProcessor extends AbstractProcessor
|
||||
{
|
||||
- static Map<String, String> convertOptions (Map<String, String> aptOptions)
|
||||
+
|
||||
+ private Set<String> s_supportedOptions = Collections.emptySet();
|
||||
+ private Set<String> s_supportedAnnotationTypes = new HashSet<String> (Arrays.asList(
|
||||
+ "org.yuanheng.cookcc.CookCCOption",
|
||||
+ "org.yuanheng.cookcc.CookCCToken",
|
||||
+ "org.yuanheng.cookcc.TokenGroup",
|
||||
+ "org.yuanheng.cookcc.Lex",
|
||||
+ "org.yuanheng.cookcc.Lexs",
|
||||
+ "org.yuanheng.cookcc.Rule"));
|
||||
+
|
||||
+ private static Map<String, String> convertOptions (Map<String, String> aptOptions)
|
||||
{
|
||||
HashMap<String, String> ccOptions = new HashMap<String, String> ();
|
||||
for (String option : aptOptions.keySet ())
|
||||
@@ -68,22 +86,50 @@ class CookCCProcessor implements AnnotationProcessor
|
||||
return ccOptions;
|
||||
}
|
||||
|
||||
- private final AnnotationProcessorEnvironment m_env;
|
||||
- private final CodeGen m_codeGen;
|
||||
+ private CodeGen m_codeGen;
|
||||
|
||||
- CookCCProcessor (AnnotationProcessorEnvironment env) throws Exception
|
||||
- {
|
||||
- m_env = env;
|
||||
- Map<String, String> ccOptions = convertOptions (env.getOptions ());
|
||||
- Main.parseOptions (ccOptions);
|
||||
- m_codeGen = Main.getCodeGen ();
|
||||
- }
|
||||
+ @Override
|
||||
+ public synchronized void init(ProcessingEnvironment processingEnv) {
|
||||
+ super.init(processingEnv);
|
||||
+ Map<String, String> ccOptions = convertOptions (processingEnv.getOptions ());
|
||||
+ try {
|
||||
+ Main.parseOptions (ccOptions);
|
||||
+ m_codeGen = Main.getCodeGen ();
|
||||
+ } catch (Exception e) {
|
||||
+ throw new RuntimeException(e);
|
||||
+ }
|
||||
+ }
|
||||
|
||||
- public void process ()
|
||||
+ @Override
|
||||
+ public Set<String> getSupportedAnnotationTypes() {
|
||||
+ return s_supportedAnnotationTypes;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Set<String> getSupportedOptions() {
|
||||
+ return s_supportedOptions;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public SourceVersion getSupportedSourceVersion() {
|
||||
+ return SourceVersion.RELEASE_8;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
|
||||
{
|
||||
CookCCVisitor visitor = new CookCCVisitor ();
|
||||
- for (TypeDeclaration typeDecl : m_env.getSpecifiedTypeDeclarations ())
|
||||
- typeDecl.accept (DeclarationVisitors.getDeclarationScanner (visitor, DeclarationVisitors.NO_OP));
|
||||
+ visitor.setEnv(this.processingEnv);
|
||||
+ Set<Element> allElements = new HashSet<Element>();
|
||||
+ for (String annotation: getSupportedAnnotationTypes()) {
|
||||
+ try {
|
||||
+ allElements.addAll(roundEnv.getElementsAnnotatedWith((Class<? extends Annotation>) Class.forName(annotation)));
|
||||
+ } catch (ClassNotFoundException e) {
|
||||
+ throw new RuntimeException("Unknown annotation " + annotation, e);
|
||||
+ }
|
||||
+ }
|
||||
+ for (Element typeDecl : allElements)
|
||||
+ typeDecl.accept (visitor, null);
|
||||
visitor.process ();
|
||||
Document[] docs = visitor.getDocuments ();
|
||||
OptionMap options = m_codeGen.getOptions ();
|
||||
@@ -109,5 +155,6 @@ class CookCCProcessor implements AnnotationProcessor
|
||||
ex.printStackTrace ();
|
||||
}
|
||||
}
|
||||
+ return true;
|
||||
}
|
||||
}
|
||||
diff --git a/javaap_src/org/yuanheng/cookcc/input/javaap/CookCCVisitor.java b/javaap_src/org/yuanheng/cookcc/input/javaap/CookCCVisitor.java
|
||||
index b69be72..164f59f 100644
|
||||
--- a/javaap_src/org/yuanheng/cookcc/input/javaap/CookCCVisitor.java
|
||||
+++ b/javaap_src/org/yuanheng/cookcc/input/javaap/CookCCVisitor.java
|
||||
@@ -32,22 +32,37 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
+import javax.annotation.processing.ProcessingEnvironment;
|
||||
+import javax.lang.model.element.ElementKind;
|
||||
+import javax.lang.model.element.ExecutableElement;
|
||||
+import javax.lang.model.element.PackageElement;
|
||||
+import javax.lang.model.element.TypeElement;
|
||||
+import javax.lang.model.element.TypeParameterElement;
|
||||
+import javax.lang.model.element.VariableElement;
|
||||
+import javax.lang.model.util.SimpleElementVisitor6;
|
||||
+
|
||||
import org.yuanheng.cookcc.codegen.TemplatedCodeGen;
|
||||
import org.yuanheng.cookcc.doc.Document;
|
||||
import org.yuanheng.cookcc.doc.TokensDoc;
|
||||
|
||||
-import com.sun.mirror.declaration.*;
|
||||
-import com.sun.mirror.util.DeclarationVisitor;
|
||||
-
|
||||
import freemarker.template.Template;
|
||||
|
||||
/**
|
||||
* @author Heng Yuan
|
||||
* @version $Id: CookCCVisitor.java 486 2008-11-09 15:09:57Z superduperhengyuan $
|
||||
*/
|
||||
-class CookCCVisitor implements DeclarationVisitor
|
||||
+class CookCCVisitor<R, P> extends SimpleElementVisitor6<R, P>
|
||||
{
|
||||
public final static String TEMPLATE_URI = "resources/templates/javaap/javaap.ftl";
|
||||
+ private ProcessingEnvironment env;
|
||||
+
|
||||
+ public ProcessingEnvironment getEnv() {
|
||||
+ return this.env;
|
||||
+ }
|
||||
+
|
||||
+ public void setEnv(ProcessingEnvironment env) {
|
||||
+ this.env = env;
|
||||
+ }
|
||||
|
||||
private static class Resources
|
||||
{
|
||||
@@ -76,7 +91,7 @@ class CookCCVisitor implements DeclarationVisitor
|
||||
|
||||
private final Map<String, Document> m_docs = new HashMap<String, Document> ();
|
||||
private final Map<String, Collection<TokensDoc>> m_tokens = new HashMap<String, Collection<TokensDoc>> ();
|
||||
- private DeclarationVisitor m_visitor;
|
||||
+ private SimpleElementVisitor6 m_visitor;
|
||||
|
||||
void addDocument (String className, Document document)
|
||||
{
|
||||
@@ -166,99 +181,47 @@ class CookCCVisitor implements DeclarationVisitor
|
||||
addDefaultCode ();
|
||||
}
|
||||
|
||||
- public void visitDeclaration (Declaration declaration)
|
||||
- {
|
||||
- if (m_visitor != null)
|
||||
- m_visitor.visitDeclaration (declaration);
|
||||
- }
|
||||
-
|
||||
- public void visitPackageDeclaration (PackageDeclaration packageDeclaration)
|
||||
- {
|
||||
- if (m_visitor != null)
|
||||
- m_visitor.visitPackageDeclaration (packageDeclaration);
|
||||
- }
|
||||
-
|
||||
- public void visitMemberDeclaration (MemberDeclaration memberDeclaration)
|
||||
- {
|
||||
- if (m_visitor != null)
|
||||
- m_visitor.visitMemberDeclaration (memberDeclaration);
|
||||
- }
|
||||
-
|
||||
- public void visitTypeDeclaration (TypeDeclaration typeDeclaration)
|
||||
- {
|
||||
- if (m_visitor != null)
|
||||
- m_visitor.visitTypeDeclaration (typeDeclaration);
|
||||
- }
|
||||
-
|
||||
- public void visitClassDeclaration (ClassDeclaration classDeclaration)
|
||||
- {
|
||||
- m_visitor = new ClassVisitor (this);
|
||||
- m_visitor.visitClassDeclaration (classDeclaration);
|
||||
- }
|
||||
-
|
||||
- public void visitEnumDeclaration (EnumDeclaration enumDeclaration)
|
||||
- {
|
||||
- m_visitor = new EnumVisitor (this);
|
||||
- m_visitor.visitEnumDeclaration (enumDeclaration);
|
||||
- }
|
||||
-
|
||||
- public void visitInterfaceDeclaration (InterfaceDeclaration interfaceDeclaration)
|
||||
- {
|
||||
- if (m_visitor != null)
|
||||
- m_visitor.visitInterfaceDeclaration (interfaceDeclaration);
|
||||
- }
|
||||
-
|
||||
- public void visitAnnotationTypeDeclaration (AnnotationTypeDeclaration annotationTypeDeclaration)
|
||||
- {
|
||||
- if (m_visitor != null)
|
||||
- m_visitor.visitAnnotationTypeDeclaration (annotationTypeDeclaration);
|
||||
- }
|
||||
-
|
||||
- public void visitFieldDeclaration (FieldDeclaration fieldDeclaration)
|
||||
- {
|
||||
- if (m_visitor != null)
|
||||
- m_visitor.visitFieldDeclaration (fieldDeclaration);
|
||||
- }
|
||||
-
|
||||
- public void visitEnumConstantDeclaration (EnumConstantDeclaration enumConstantDeclaration)
|
||||
- {
|
||||
- if (m_visitor != null)
|
||||
- m_visitor.visitEnumConstantDeclaration (enumConstantDeclaration);
|
||||
- }
|
||||
-
|
||||
- public void visitExecutableDeclaration (ExecutableDeclaration executableDeclaration)
|
||||
- {
|
||||
- if (m_visitor != null)
|
||||
- m_visitor.visitExecutableDeclaration (executableDeclaration);
|
||||
- }
|
||||
-
|
||||
- public void visitConstructorDeclaration (ConstructorDeclaration constructorDeclaration)
|
||||
- {
|
||||
- if (m_visitor != null)
|
||||
- m_visitor.visitConstructorDeclaration (constructorDeclaration);
|
||||
+ @Override
|
||||
+ public R visitPackage(PackageElement e, P p) {
|
||||
+ if (m_visitor != null) {
|
||||
+ return (R) m_visitor.visitPackage(e, p);
|
||||
+ }
|
||||
+ return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
- public void visitMethodDeclaration (MethodDeclaration methodDeclaration)
|
||||
- {
|
||||
- if (m_visitor != null)
|
||||
- m_visitor.visitMethodDeclaration (methodDeclaration);
|
||||
+ @Override
|
||||
+ public R visitVariable(VariableElement e, P p) {
|
||||
+ if (m_visitor != null) {
|
||||
+ return (R) m_visitor.visitVariable(e, p);
|
||||
+ }
|
||||
+ return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
- public void visitAnnotationTypeElementDeclaration (AnnotationTypeElementDeclaration annotationTypeElementDeclaration)
|
||||
- {
|
||||
- if (m_visitor != null)
|
||||
- m_visitor.visitAnnotationTypeElementDeclaration (annotationTypeElementDeclaration);
|
||||
+ @Override
|
||||
+ public R visitExecutable(ExecutableElement e, P p) {
|
||||
+ if (m_visitor != null) {
|
||||
+ return (R) m_visitor.visitExecutable(e, p);
|
||||
+ }
|
||||
+ return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
- public void visitParameterDeclaration (ParameterDeclaration parameterDeclaration)
|
||||
- {
|
||||
- if (m_visitor != null)
|
||||
- m_visitor.visitParameterDeclaration (parameterDeclaration);
|
||||
+ @Override
|
||||
+ public R visitTypeParameter(TypeParameterElement e, P p) {
|
||||
+ if (m_visitor != null) {
|
||||
+ return (R) m_visitor.visitTypeParameter(e, p);
|
||||
+ }
|
||||
+ return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
- public void visitTypeParameterDeclaration (TypeParameterDeclaration typeParameterDeclaration)
|
||||
- {
|
||||
- if (m_visitor != null)
|
||||
- m_visitor.visitTypeParameterDeclaration (typeParameterDeclaration);
|
||||
+ public R visitType(TypeElement classDeclaration, P p) {
|
||||
+ if (classDeclaration.getKind() == ElementKind.CLASS) {
|
||||
+ m_visitor = new ClassVisitor(this);
|
||||
+ m_visitor.visitType(classDeclaration, p);
|
||||
+ }
|
||||
+ if (classDeclaration.getKind() == ElementKind.ENUM) {
|
||||
+ m_visitor = new EnumVisitor(this);
|
||||
+ m_visitor.visitType(classDeclaration, p);
|
||||
+ }
|
||||
+ return DEFAULT_VALUE;
|
||||
}
|
||||
}
|
||||
\ No newline at end of file
|
||||
diff --git a/javaap_src/org/yuanheng/cookcc/input/javaap/EnumVisitor.java b/javaap_src/org/yuanheng/cookcc/input/javaap/EnumVisitor.java
|
||||
index 4e846bc..4bc7a3b 100644
|
||||
--- a/javaap_src/org/yuanheng/cookcc/input/javaap/EnumVisitor.java
|
||||
+++ b/javaap_src/org/yuanheng/cookcc/input/javaap/EnumVisitor.java
|
||||
@@ -29,18 +29,20 @@ package org.yuanheng.cookcc.input.javaap;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
+import javax.lang.model.element.ElementKind;
|
||||
+import javax.lang.model.element.TypeElement;
|
||||
+import javax.lang.model.element.VariableElement;
|
||||
+import javax.lang.model.util.SimpleElementVisitor6;
|
||||
+
|
||||
import org.yuanheng.cookcc.CookCCToken;
|
||||
import org.yuanheng.cookcc.TokenGroup;
|
||||
import org.yuanheng.cookcc.doc.TokensDoc;
|
||||
|
||||
-import com.sun.mirror.declaration.*;
|
||||
-import com.sun.mirror.util.DeclarationVisitor;
|
||||
-
|
||||
/**
|
||||
* @author Heng Yuan
|
||||
* @version $Id: EnumVisitor.java 486 2008-11-09 15:09:57Z superduperhengyuan $
|
||||
*/
|
||||
-class EnumVisitor implements DeclarationVisitor
|
||||
+class EnumVisitor<R, P> extends SimpleElementVisitor6<R, P>
|
||||
{
|
||||
private final CookCCVisitor m_parent;
|
||||
private final Collection<TokensDoc> m_tokens = new LinkedList<TokensDoc> ();
|
||||
@@ -52,46 +54,14 @@ class EnumVisitor implements DeclarationVisitor
|
||||
m_parent = parent;
|
||||
}
|
||||
|
||||
- public void visitDeclaration (Declaration declaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitPackageDeclaration (PackageDeclaration packageDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitMemberDeclaration (MemberDeclaration memberDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitTypeDeclaration (TypeDeclaration typeDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitClassDeclaration (ClassDeclaration classDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitEnumDeclaration (EnumDeclaration enumDeclaration)
|
||||
+ public void visitEnumDeclaration (TypeElement enumDeclaration)
|
||||
{
|
||||
if (enumDeclaration.getAnnotation (CookCCToken.class) == null)
|
||||
return;
|
||||
- m_parent.addTokenEnum (enumDeclaration.getQualifiedName (), m_tokens);
|
||||
- }
|
||||
-
|
||||
- public void visitInterfaceDeclaration (InterfaceDeclaration interfaceDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitAnnotationTypeDeclaration (AnnotationTypeDeclaration annotationTypeDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitFieldDeclaration (FieldDeclaration fieldDeclaration)
|
||||
- {
|
||||
+ m_parent.addTokenEnum (enumDeclaration.getQualifiedName().toString(), m_tokens);
|
||||
}
|
||||
|
||||
- public void visitEnumConstantDeclaration (EnumConstantDeclaration enumConstantDeclaration)
|
||||
+ private void visitEnumConstantDeclaration (VariableElement enumConstantDeclaration)
|
||||
{
|
||||
TokenGroup tg = null;
|
||||
if (m_doc == null || (tg = enumConstantDeclaration.getAnnotation (TokenGroup.class)) != null)
|
||||
@@ -101,30 +71,22 @@ class EnumVisitor implements DeclarationVisitor
|
||||
m_doc.setType (tg.type ().toString ());
|
||||
m_tokens.add (m_doc);
|
||||
}
|
||||
- m_doc.addTokens (enumConstantDeclaration.getSimpleName ());
|
||||
- }
|
||||
-
|
||||
- public void visitExecutableDeclaration (ExecutableDeclaration executableDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitConstructorDeclaration (ConstructorDeclaration constructorDeclaration)
|
||||
- {
|
||||
+ m_doc.addTokens (enumConstantDeclaration.getSimpleName().toString());
|
||||
}
|
||||
|
||||
- public void visitMethodDeclaration (MethodDeclaration methodDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitAnnotationTypeElementDeclaration (AnnotationTypeElementDeclaration annotationTypeElementDeclaration)
|
||||
- {
|
||||
- }
|
||||
-
|
||||
- public void visitParameterDeclaration (ParameterDeclaration parameterDeclaration)
|
||||
- {
|
||||
+ @Override
|
||||
+ public R visitVariable(VariableElement e, P p) {
|
||||
+ if (e.getKind() == ElementKind.ENUM_CONSTANT) {
|
||||
+ visitEnumConstantDeclaration(e);
|
||||
+ }
|
||||
+ return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
- public void visitTypeParameterDeclaration (TypeParameterDeclaration typeParameterDeclaration)
|
||||
- {
|
||||
+ @Override
|
||||
+ public R visitType(TypeElement e, P p) {
|
||||
+ if (e.getKind() == ElementKind.ENUM) {
|
||||
+ visitEnumDeclaration(e);
|
||||
+ }
|
||||
+ return DEFAULT_VALUE;
|
||||
}
|
||||
}
|
||||
\ No newline at end of file
|
||||
--
|
||||
1.9.3
|
||||
|
||||
14
cookcc-0.3.3-xerces.patch
Normal file
14
cookcc-0.3.3-xerces.patch
Normal file
@ -0,0 +1,14 @@
|
||||
diff -Naur cookcc-0.3.3/src/org/yuanheng/cookcc/input/xml/XmlParser.java cookcc-0.3.3-work/src/org/yuanheng/cookcc/input/xml/XmlParser.java
|
||||
--- cookcc-0.3.3/src/org/yuanheng/cookcc/input/xml/XmlParser.java 2008-12-01 06:39:30.000000000 -0500
|
||||
+++ cookcc-0.3.3-work/src/org/yuanheng/cookcc/input/xml/XmlParser.java 2011-07-08 05:08:33.226920421 -0400
|
||||
@@ -36,8 +36,8 @@
|
||||
import org.xml.sax.SAXException;
|
||||
import org.yuanheng.cookcc.doc.*;
|
||||
|
||||
-import com.sun.org.apache.xerces.internal.parsers.DOMParser;
|
||||
-import com.sun.org.apache.xerces.internal.xni.*;
|
||||
+import org.apache.xerces.parsers.DOMParser;
|
||||
+import org.apache.xerces.xni.*;
|
||||
|
||||
import cookxml.core.CookXml;
|
||||
import cookxml.core.adder.CallFunctionAdder;
|
||||
BIN
cookcc-0.3.3.tar.xz
Normal file
BIN
cookcc-0.3.3.tar.xz
Normal file
Binary file not shown.
56
cookcc.spec
Normal file
56
cookcc.spec
Normal file
@ -0,0 +1,56 @@
|
||||
Name: cookcc
|
||||
Version: 0.3.3
|
||||
Release: 1
|
||||
Summary: Lexer and Parser Generator
|
||||
License: BSD
|
||||
URL: https://github.com/coconut2015/cookcc
|
||||
# svn export -r 678 http://cookcc.googlecode.com/svn/trunk/ cookcc-0.3.3
|
||||
# tar -J -cf cookcc-0.3.3.tar.xz cookcc-0.3.3
|
||||
Source0: %{name}-%{version}.tar.xz
|
||||
Source1: %{name}-%{version}-pom.xml
|
||||
Patch0: %{name}-%{version}-xerces.patch
|
||||
Patch1: %{name}-%{version}-buildxml.patch
|
||||
Patch2: %{name}-%{version}-port-to-jsr-269.patch
|
||||
Patch3: %{name}-0.3.3-freemarker2.3.2+.patch
|
||||
Patch4: 0001-Fix-build-failure-because-of-freemarker.patch
|
||||
BuildRequires: ant cookxml freemarker javapackages-local xerces-j2
|
||||
Requires: freemarker cookxml xerces-j2
|
||||
BuildArch: noarch
|
||||
|
||||
%description
|
||||
CookCC is a lexer and parser (LALR (1)) generator project, combined.
|
||||
It is written in Java, but the target languages can vary.
|
||||
|
||||
%package help
|
||||
Summary: Documents for %{name}
|
||||
Provides: %{name}-javadoc = %{version}-%{release}
|
||||
Obsoletes: %{name}-javadoc < %{version}-%{release}
|
||||
|
||||
%description help
|
||||
This package contains man pages and other related documents for %{name}.
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
%patch0 -p1
|
||||
%patch1 -p1
|
||||
%patch2 -p1
|
||||
%patch3 -p1
|
||||
%patch4 -p1
|
||||
find . -name '*.jar' -delete
|
||||
|
||||
%build
|
||||
CLASSPATH=$(build-classpath xerces-j2 freemarker cookxml) ant cookcc_jar javadocs
|
||||
|
||||
%install
|
||||
%mvn_artifact %{SOURCE1} dist/%{name}-%{version}.jar
|
||||
%mvn_install -J javadocs
|
||||
|
||||
%files -f .mfiles
|
||||
%license LICENSE_cookcc.txt
|
||||
|
||||
%files help -f .mfiles-javadoc
|
||||
%license LICENSE_cookcc.txt
|
||||
|
||||
%changelog
|
||||
* Fri Aug 14 2020 leiju <leiju4@huawei.com> - 0.3.3-1
|
||||
- Package init
|
||||
4
cookcc.yaml
Normal file
4
cookcc.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
version_control: github
|
||||
src_repo: coconut2015/cookcc
|
||||
tag_prefix: "^v"
|
||||
seperator: "."
|
||||
Loading…
x
Reference in New Issue
Block a user