From 03fb2e2294dfee57f43cc0e43ba70d3765ca33ad Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Wed, 15 Jan 2020 14:58:11 -0500 Subject: Add the java javaparser https://github.com/javaparser/javaparser/ Invisible tag: javaparser-1.0.6 --- .../java/javaparser/test/ignore/TestRunner.java | 127 ++++ .../test/japa/parser/ast/test/AllTests.java | 25 + .../test/japa/parser/ast/test/TestAdapters.java | 80 +++ .../test/japa/parser/ast/test/TestDumper.java | 86 +++ .../test/japa/parser/ast/test/TestHelper.java | 61 ++ .../japa/parser/ast/test/TestNodePositions.java | 639 +++++++++++++++++++++ .../parser/ast/test/classes/DumperTestClass.java | 364 ++++++++++++ .../parser/ast/test/classes/JavadocTestClass.java | 127 ++++ 8 files changed, 1509 insertions(+) create mode 100644 parser/html/java/javaparser/test/ignore/TestRunner.java create mode 100644 parser/html/java/javaparser/test/japa/parser/ast/test/AllTests.java create mode 100644 parser/html/java/javaparser/test/japa/parser/ast/test/TestAdapters.java create mode 100644 parser/html/java/javaparser/test/japa/parser/ast/test/TestDumper.java create mode 100644 parser/html/java/javaparser/test/japa/parser/ast/test/TestHelper.java create mode 100644 parser/html/java/javaparser/test/japa/parser/ast/test/TestNodePositions.java create mode 100644 parser/html/java/javaparser/test/japa/parser/ast/test/classes/DumperTestClass.java create mode 100644 parser/html/java/javaparser/test/japa/parser/ast/test/classes/JavadocTestClass.java (limited to 'parser/html/java/javaparser/test') diff --git a/parser/html/java/javaparser/test/ignore/TestRunner.java b/parser/html/java/javaparser/test/ignore/TestRunner.java new file mode 100644 index 000000000..574da0b2e --- /dev/null +++ b/parser/html/java/javaparser/test/ignore/TestRunner.java @@ -0,0 +1,127 @@ +package ignore; + +import japa.parser.JavaParser; +import japa.parser.ParseException; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.IOException; + +/* + * Created on 14/10/2007 + */ + +/** + * @author Julio Vilmar Gesser + */ +public class TestRunner { + + private static final File ROOT = // + new File("D:/Downloads/openjdk-7-ea-src-b27-22_may_2008/openjdk/langtools/test/tools/javac" // + //"C:/Documents and Settings/jgesser/Desktop/openjdk-7-ea-src-b27-22_may_2008/openjdk" // + //"C:/Documents and Settings/jgesser/Desktop/openjdk-6-src-b09-11_apr_2008/jdk" // + ); + + public static void main(String[] args) { + new TestRunner().run(); + } + + private void visitAllJavaFiles(FileFilter callback, File dir) { + File[] listFiles = dir.listFiles(new FileFilter() { + + public boolean accept(File file) { + return file.isDirectory() || file.getName().endsWith(".java"); + } + + }); + if (listFiles != null) { + for (File element : listFiles) { + if (element.isDirectory()) { + visitAllJavaFiles(callback, element); + } else { + callback.accept(element); + } + } + } + } + + int runCount = 0; + + long runTime = 0; + + public void run() { + visitAllJavaFiles(new FileFilter() { + + public boolean accept(File javaFile) { + //System.out.println("Visiting file: " + javaFile.getPath()); + try { + runTest(javaFile); + } catch (IOException e) { + throw new RuntimeException(e); + } + return false; + } + + }, ROOT); + + System.out.println("Compiled " + runCount + " in " + runTime + " ms, avarage of " + (((double) runTime) / runCount)); + } + + private void runTest(File javaFile) throws IOException { + + // try { + // JavaParser.parse(javaFile); + // } catch (ParseException e) { + // System.out.println("<> " + e.getMessage()); + // } + + StringBuilder buf = new StringBuilder(); + try { + FileInputStream in = new FileInputStream(javaFile); + try { + int i; + while ((i = in.read()) >= 0) { + buf.append((char) i); + } + } finally { + in.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + + if (buf.indexOf("@test") < 0) { + return; + // System.out.println("Skiping file: " + javaFile.getPath()); + } + boolean fail = false; + // if (buf.indexOf("@compile ") == -1) { + // fail = buf.indexOf("compile/fail") >= 0; + // } + if (!(buf.indexOf("@compile ") >= 0 && buf.indexOf("compile/fail") < 0)) { + return; + } + + try { + //System.out.println("Parsing file: " + javaFile.getPath()); + + runCount++; + long time = System.currentTimeMillis(); + JavaParser.parse(javaFile); + runTime += System.currentTimeMillis() - time; + if (fail) { + System.out.println("Testing file: " + javaFile.getPath()); + System.out.println(" >>Parser error expected but not ocurred"); + } + } catch (ParseException e) { + if (!fail) { + System.out.println("Testing file: " + javaFile.getPath()); + System.out.println(" >>Parser error not expected: " + e.getMessage()); + } + } catch (Error e) { + System.out.println("Testing file: " + javaFile.getPath()); + System.out.println(" >>Unknow error: " + e.getMessage()); + } + } +} \ No newline at end of file diff --git a/parser/html/java/javaparser/test/japa/parser/ast/test/AllTests.java b/parser/html/java/javaparser/test/japa/parser/ast/test/AllTests.java new file mode 100644 index 000000000..f0a236833 --- /dev/null +++ b/parser/html/java/javaparser/test/japa/parser/ast/test/AllTests.java @@ -0,0 +1,25 @@ +/* + * Created on 11/01/2009 + */ +package japa.parser.ast.test; + +import junit.framework.Test; +import junit.framework.TestSuite; + + +/** + * @author Julio Vilmar Gesser + */ +public class AllTests { + + public static Test suite() { + TestSuite suite = new TestSuite("Test for japa.parser.ast.test"); + //$JUnit-BEGIN$ + suite.addTestSuite(TestAdapters.class); + suite.addTestSuite(TestNodePositions.class); + suite.addTestSuite(TestDumper.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/parser/html/java/javaparser/test/japa/parser/ast/test/TestAdapters.java b/parser/html/java/javaparser/test/japa/parser/ast/test/TestAdapters.java new file mode 100644 index 000000000..7876a970b --- /dev/null +++ b/parser/html/java/javaparser/test/japa/parser/ast/test/TestAdapters.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2008 Júlio Vilmar Gesser. + * + * This file is part of Java 1.5 parser and Abstract Syntax Tree. + * + * Java 1.5 parser and Abstract Syntax Tree is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Java 1.5 parser and Abstract Syntax Tree is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Java 1.5 parser and Abstract Syntax Tree. If not, see . + */ +/* + * Created on 11/06/2008 + */ +package japa.parser.ast.test; + +import japa.parser.ParseException; +import japa.parser.ast.CompilationUnit; +import japa.parser.ast.test.classes.DumperTestClass; +import japa.parser.ast.test.classes.JavadocTestClass; +import japa.parser.ast.visitor.GenericVisitor; +import japa.parser.ast.visitor.GenericVisitorAdapter; +import japa.parser.ast.visitor.ModifierVisitorAdapter; +import japa.parser.ast.visitor.VoidVisitor; +import japa.parser.ast.visitor.VoidVisitorAdapter; +import junit.framework.TestCase; + +/** + * @author Julio Vilmar Gesser + */ +public class TestAdapters extends TestCase { + + class ConcreteVoidVisitorAdapter extends VoidVisitorAdapter { + + } + + class ConcreteGenericVisitorAdapter extends GenericVisitorAdapter { + + } + + class ConcreteModifierVisitorAdapter extends ModifierVisitorAdapter { + + } + + private void doTest(VoidVisitor< ? > visitor) throws ParseException { + CompilationUnit cu = TestHelper.parserClass("./test", DumperTestClass.class); + cu.accept(visitor, null); + + cu = TestHelper.parserClass("./test", JavadocTestClass.class); + cu.accept(visitor, null); + } + + private void doTest(GenericVisitor< ? , ? > visitor) throws ParseException { + CompilationUnit cu = TestHelper.parserClass("./test", DumperTestClass.class); + cu.accept(visitor, null); + + cu = TestHelper.parserClass("./test", JavadocTestClass.class); + cu.accept(visitor, null); + } + + public void testVoidVisitorAdapter() throws Exception { + doTest(new ConcreteVoidVisitorAdapter()); + } + + public void testGenericVisitorAdapter() throws Exception { + doTest(new ConcreteGenericVisitorAdapter()); + } + + public void testModifierVisitorAdapter() throws Exception { + doTest(new ConcreteModifierVisitorAdapter()); + } + +} diff --git a/parser/html/java/javaparser/test/japa/parser/ast/test/TestDumper.java b/parser/html/java/javaparser/test/japa/parser/ast/test/TestDumper.java new file mode 100644 index 000000000..f6fefe187 --- /dev/null +++ b/parser/html/java/javaparser/test/japa/parser/ast/test/TestDumper.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2007 Júlio Vilmar Gesser. + * + * This file is part of Java 1.5 parser and Abstract Syntax Tree. + * + * Java 1.5 parser and Abstract Syntax Tree is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Java 1.5 parser and Abstract Syntax Tree is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Java 1.5 parser and Abstract Syntax Tree. If not, see . + */ +/* + * Created on 22/11/2006 + */ +package japa.parser.ast.test; + +import japa.parser.ast.CompilationUnit; +import japa.parser.ast.test.classes.DumperTestClass; +import japa.parser.ast.test.classes.JavadocTestClass; +import junit.framework.TestCase; + +/** + * @author Julio Vilmar Gesser + */ +public class TestDumper extends TestCase { + + public void testDumpVisitor() throws Exception { + String source = TestHelper.readClass("./test", DumperTestClass.class); + CompilationUnit cu = TestHelper.parserString(source); + assertEquals(source, cu.toString()); + } + + public void testJavadoc() throws Exception { + String source = TestHelper.readClass("./test", JavadocTestClass.class); + CompilationUnit cu = TestHelper.parserString(source); + assertEquals(source, cu.toString()); + assertEquals(19, cu.getComments().size()); + } + + public void testComments() throws Exception { + final String source_with_comment = // + "package japa.parser.javacc;\n" + // + "public class Teste {\n" + // + "//line comment\n" + // + "int a = 0;" + // + "//line comment\r\n" + // + "int b = 0;" + // + "//line comment\r" + // + "int c = 0;" + // + "/* multi-line\n comment\n*/" + // + "int d = 0;" + // + "/** multi-line\r\n javadoc\n*/" + // + "int e = 0;" + // + "}\n" + // + "//final comment" + // + ""; + final String source_without_comment = // + "package japa.parser.javacc;\n" + // + "\n" + // + "public class Teste {\n" + // + "\n" + // + " int a = 0;\n" + // + "\n" + // + " int b = 0;\n" + // + "\n" + // + " int c = 0;\n" + // + "\n" + // + " int d = 0;\n" + // + "\n" + // + " /** multi-line\r\n javadoc\n*/\n" + // + " int e = 0;\n" + // + "}\n" + // + ""; + + CompilationUnit cu = TestHelper.parserString(source_with_comment); + assertEquals(source_without_comment, cu.toString()); + assertEquals(6, cu.getComments().size()); + } +} \ No newline at end of file diff --git a/parser/html/java/javaparser/test/japa/parser/ast/test/TestHelper.java b/parser/html/java/javaparser/test/japa/parser/ast/test/TestHelper.java new file mode 100644 index 000000000..a6098633a --- /dev/null +++ b/parser/html/java/javaparser/test/japa/parser/ast/test/TestHelper.java @@ -0,0 +1,61 @@ +/* + * Created on 30/06/2008 + */ +package japa.parser.ast.test; + +import japa.parser.JavaParser; +import japa.parser.ParseException; +import japa.parser.ast.CompilationUnit; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.StringBufferInputStream; + +/** + * @author Julio Vilmar Gesser + */ +final class TestHelper { + + private TestHelper() { + // hide the constructor + } + + private static File getFile(String sourceFolder, Class clazz) { + return new File(sourceFolder, clazz.getName().replace('.', '/') + ".java"); + } + + public static CompilationUnit parserClass(String sourceFolder, Class clazz) throws ParseException { + try { + return JavaParser.parse(getFile(sourceFolder, clazz)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static CompilationUnit parserString(String source) throws ParseException { + return JavaParser.parse(new StringBufferInputStream(source)); + } + + public static String readFile(File file) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); + try { + StringBuilder ret = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + ret.append(line); + ret.append("\n"); + } + return ret.toString(); + } finally { + reader.close(); + } + } + + public static String readClass(String sourceFolder, Class clazz) throws IOException { + return readFile(getFile(sourceFolder, clazz)); + } + +} diff --git a/parser/html/java/javaparser/test/japa/parser/ast/test/TestNodePositions.java b/parser/html/java/javaparser/test/japa/parser/ast/test/TestNodePositions.java new file mode 100644 index 000000000..70087a89c --- /dev/null +++ b/parser/html/java/javaparser/test/japa/parser/ast/test/TestNodePositions.java @@ -0,0 +1,639 @@ +/* + * Created on 30/06/2008 + */ +package japa.parser.ast.test; + +import japa.parser.ast.BlockComment; +import japa.parser.ast.CompilationUnit; +import japa.parser.ast.ImportDeclaration; +import japa.parser.ast.LineComment; +import japa.parser.ast.Node; +import japa.parser.ast.PackageDeclaration; +import japa.parser.ast.TypeParameter; +import japa.parser.ast.body.AnnotationDeclaration; +import japa.parser.ast.body.AnnotationMemberDeclaration; +import japa.parser.ast.body.ClassOrInterfaceDeclaration; +import japa.parser.ast.body.ConstructorDeclaration; +import japa.parser.ast.body.EmptyMemberDeclaration; +import japa.parser.ast.body.EmptyTypeDeclaration; +import japa.parser.ast.body.EnumConstantDeclaration; +import japa.parser.ast.body.EnumDeclaration; +import japa.parser.ast.body.FieldDeclaration; +import japa.parser.ast.body.InitializerDeclaration; +import japa.parser.ast.body.JavadocComment; +import japa.parser.ast.body.MethodDeclaration; +import japa.parser.ast.body.Parameter; +import japa.parser.ast.body.VariableDeclarator; +import japa.parser.ast.body.VariableDeclaratorId; +import japa.parser.ast.expr.ArrayAccessExpr; +import japa.parser.ast.expr.ArrayCreationExpr; +import japa.parser.ast.expr.ArrayInitializerExpr; +import japa.parser.ast.expr.AssignExpr; +import japa.parser.ast.expr.BinaryExpr; +import japa.parser.ast.expr.BooleanLiteralExpr; +import japa.parser.ast.expr.CastExpr; +import japa.parser.ast.expr.CharLiteralExpr; +import japa.parser.ast.expr.ClassExpr; +import japa.parser.ast.expr.ConditionalExpr; +import japa.parser.ast.expr.DoubleLiteralExpr; +import japa.parser.ast.expr.EnclosedExpr; +import japa.parser.ast.expr.FieldAccessExpr; +import japa.parser.ast.expr.InstanceOfExpr; +import japa.parser.ast.expr.IntegerLiteralExpr; +import japa.parser.ast.expr.IntegerLiteralMinValueExpr; +import japa.parser.ast.expr.LongLiteralExpr; +import japa.parser.ast.expr.LongLiteralMinValueExpr; +import japa.parser.ast.expr.MarkerAnnotationExpr; +import japa.parser.ast.expr.MemberValuePair; +import japa.parser.ast.expr.MethodCallExpr; +import japa.parser.ast.expr.NameExpr; +import japa.parser.ast.expr.NormalAnnotationExpr; +import japa.parser.ast.expr.NullLiteralExpr; +import japa.parser.ast.expr.ObjectCreationExpr; +import japa.parser.ast.expr.QualifiedNameExpr; +import japa.parser.ast.expr.SingleMemberAnnotationExpr; +import japa.parser.ast.expr.StringLiteralExpr; +import japa.parser.ast.expr.SuperExpr; +import japa.parser.ast.expr.ThisExpr; +import japa.parser.ast.expr.UnaryExpr; +import japa.parser.ast.expr.VariableDeclarationExpr; +import japa.parser.ast.stmt.AssertStmt; +import japa.parser.ast.stmt.BlockStmt; +import japa.parser.ast.stmt.BreakStmt; +import japa.parser.ast.stmt.CatchClause; +import japa.parser.ast.stmt.ContinueStmt; +import japa.parser.ast.stmt.DoStmt; +import japa.parser.ast.stmt.EmptyStmt; +import japa.parser.ast.stmt.ExplicitConstructorInvocationStmt; +import japa.parser.ast.stmt.ExpressionStmt; +import japa.parser.ast.stmt.ForStmt; +import japa.parser.ast.stmt.ForeachStmt; +import japa.parser.ast.stmt.IfStmt; +import japa.parser.ast.stmt.LabeledStmt; +import japa.parser.ast.stmt.ReturnStmt; +import japa.parser.ast.stmt.SwitchEntryStmt; +import japa.parser.ast.stmt.SwitchStmt; +import japa.parser.ast.stmt.SynchronizedStmt; +import japa.parser.ast.stmt.ThrowStmt; +import japa.parser.ast.stmt.TryStmt; +import japa.parser.ast.stmt.TypeDeclarationStmt; +import japa.parser.ast.stmt.WhileStmt; +import japa.parser.ast.test.classes.DumperTestClass; +import japa.parser.ast.type.ClassOrInterfaceType; +import japa.parser.ast.type.PrimitiveType; +import japa.parser.ast.type.ReferenceType; +import japa.parser.ast.type.VoidType; +import japa.parser.ast.type.WildcardType; +import japa.parser.ast.visitor.VoidVisitorAdapter; +import junit.framework.TestCase; + +/** + * @author Julio Vilmar Gesser + */ +public class TestNodePositions extends TestCase { + + public void testNodePositions() throws Exception { + String source = TestHelper.readClass("./test", DumperTestClass.class); + CompilationUnit cu = TestHelper.parserString(source); + + cu.accept(new TestVisitor(source), null); + } + + void doTest(String source, Node node) { + String parsed = node.toString(); + + assertTrue(node.getClass().getName() + ": " + parsed, node.getBeginLine() >= 0); + assertTrue(node.getClass().getName() + ": " + parsed, node.getBeginColumn() >= 0); + assertTrue(node.getClass().getName() + ": " + parsed, node.getEndLine() >= 0); + assertTrue(node.getClass().getName() + ": " + parsed, node.getEndColumn() >= 0); + + if (node.getBeginLine() == node.getEndLine()) { + assertTrue(node.getClass().getName() + ": " + parsed, node.getBeginColumn() <= node.getEndColumn()); + } else { + assertTrue(node.getClass().getName() + ": " + parsed, node.getBeginLine() <= node.getEndLine()); + } + + String substr = substring(source, node.getBeginLine(), node.getBeginColumn(), node.getEndLine(), node.getEndColumn()); + assertEquals(node.getClass().getName(), trimLines(parsed), trimLines(substr)); + } + + private String trimLines(String str) { + String[] split = str.split("\n"); + StringBuilder ret = new StringBuilder(); + for (int i = 0; i < split.length; i++) { + ret.append(split[i].trim()); + if (i < split.length - 1) { + ret.append("\n"); + } + } + + return ret.toString(); + } + + private String substring(String source, int beginLine, int beginColumn, int endLine, int endColumn) { + int pos = 0; + while (beginLine > 1) { + if (source.charAt(pos) == '\n') { + beginLine--; + endLine--; + } + pos++; + } + int start = pos + beginColumn - 1; + + while (endLine > 1) { + if (source.charAt(pos) == '\n') { + endLine--; + } + pos++; + } + int end = pos + endColumn; + + return source.substring(start, end); + } + + class TestVisitor extends VoidVisitorAdapter { + + private final String source; + + public TestVisitor(String source) { + this.source = source; + } + + @Override + public void visit(AnnotationDeclaration n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(AnnotationMemberDeclaration n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ArrayAccessExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ArrayCreationExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ArrayInitializerExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(AssertStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(AssignExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(BinaryExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(BlockComment n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(BlockStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(BooleanLiteralExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(BreakStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(CastExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(CatchClause n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(CharLiteralExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ClassExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ClassOrInterfaceDeclaration n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ClassOrInterfaceType n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(CompilationUnit n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ConditionalExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ConstructorDeclaration n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ContinueStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(DoStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(DoubleLiteralExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(EmptyMemberDeclaration n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(EmptyStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(EmptyTypeDeclaration n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(EnclosedExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(EnumConstantDeclaration n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(EnumDeclaration n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ExplicitConstructorInvocationStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ExpressionStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(FieldAccessExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(FieldDeclaration n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ForeachStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ForStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(IfStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ImportDeclaration n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(InitializerDeclaration n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(InstanceOfExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(IntegerLiteralExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(IntegerLiteralMinValueExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(JavadocComment n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(LabeledStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(LineComment n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(LongLiteralExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(LongLiteralMinValueExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(MarkerAnnotationExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(MemberValuePair n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(MethodCallExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(MethodDeclaration n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(NameExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(NormalAnnotationExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(NullLiteralExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ObjectCreationExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(PackageDeclaration n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(Parameter n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(PrimitiveType n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(QualifiedNameExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ReferenceType n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ReturnStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(SingleMemberAnnotationExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(StringLiteralExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(SuperExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(SwitchEntryStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(SwitchStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(SynchronizedStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ThisExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(ThrowStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(TryStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(TypeDeclarationStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(TypeParameter n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(UnaryExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(VariableDeclarationExpr n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(VariableDeclarator n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(VariableDeclaratorId n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(VoidType n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(WhileStmt n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + @Override + public void visit(WildcardType n, Object arg) { + doTest(source, n); + super.visit(n, arg); + } + + } + +} diff --git a/parser/html/java/javaparser/test/japa/parser/ast/test/classes/DumperTestClass.java b/parser/html/java/javaparser/test/japa/parser/ast/test/classes/DumperTestClass.java new file mode 100644 index 000000000..390f77a51 --- /dev/null +++ b/parser/html/java/javaparser/test/japa/parser/ast/test/classes/DumperTestClass.java @@ -0,0 +1,364 @@ +package japa.parser.ast.test.classes; + +import japa.parser.JavaParser; +import japa.parser.ParseException; +import japa.parser.ast.CompilationUnit; +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.lang.annotation.Documented; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import static java.util.Map.Entry; +import java.applet.*; + +@Deprecated +public class DumperTestClass, X> extends Base implements Serializable { + + static Class clz1 = String.class; + + protected Class clz2 = (String.class); + + Class clz3 = int.class; + + Class clz4 = (int.class); + + int[] arr = new int[10]; + + byte bye = 0; + + short sh1, sh2 = 1; + + List[][] arrLS = (List[][]) new List[10][]; + + ; + + @Deprecated() + static class Ugly { + + static int x = 0; + + public static void main(String[] args) { + x = +x; + x = ~x; + --x; + boolean b = !false; + x &= 2; + x |= 2; + x ^= 2; + x -= 2; + x %= 2; + x /= 2; + x *= 2; + x <<= 2; + x >>= 2; + x >>>= 2; + b = b || false; + b = b | false; + b = b & false; + b = b ^ false; + b = b != false; + b = x > 1; + b = x < 1; + b = x >= 1; + b = x <= 1; + x = x << 1; + x = x >> 1; + x = x >>> 1; + x = x - 1; + x = x * 1; + x = x % 1; + x = x / 1; + } + } + + ; + + @Deprecated() + int[][][][] arr2 = new int[10][2][1][0]; + + volatile float fff = 0x1.fffeP+127f; + + char cc = 'a'; + + int[][] arr3 = { { 1, 2 }, { 3, 4 } }; + + static int[] arr4[] = {}; + + public static DumperTestClass t; + + static { + arr4 = new int[][] { { 2 }, { 1 } }; + } + + { + arr3 = new int[][] { { 2 }, { 1 } }; + } + + public enum Teste { + + asc, def + } + + public static enum Sexo { + + m, @Deprecated + f; + + public static enum Sexo_ implements Serializable, Cloneable { + } + + private Sexo() { + } + } + + @Deprecated + public static enum Enum { + + m(1) { + + @Override + void mm() { + } + } + , f(2) { + + void mm() { + } + } + ; + + native void nnn(); + + transient int x; + + private Enum(int x) { + this.x = x; + } + + abstract void mm(); + } + + strictfp double ddd() { + return 0.0; + } + + public DumperTestClass(int x) { + this.arr[0] = x; + T val1 = null; + E val2 = null; + super.check2(val1, val2); + boolean b = true, y = false; + abstract class X { + + int i = 0; + + public X() { + } + + public void m() { + } + } + @Deprecated + final class Y extends X { + + public Y() { + super(); + DumperTestClass.this.cc = 'c'; + super.i = 1; + Y.super.m(); + } + + public Y(int y) { + t.super(); + } + + public Y(long x) { + this(); + } + } + } + + public DumperTestClass(String str) { + } + + private class QWE extends DumperTestClass, String> { + + @Deprecated + final int z = 0; + + int i = (int) -1; + + public QWE(String... x) { + super(x[0]); + } + + public QWE(int... x) { + super(x[0]); + i = x[0]; + assert true; + assert 1 == 1 : 2; + { + int iii = 3; + iii += 3; + } + label: { + int iii = 1; + } + ; + ; + int min = -2147483648; + long sl = 123123123123l; + long minl = -9223372036854775808L; + switch(i) { + } + ll: switch(i) { + case 1: + System.out.println(1); + break ll; + default: + { + System.out.println("default"); + break; + } + case 2: + if (t instanceof Base) { + System.out.println(1); + } + i++; + ++i; + } + } + + private synchronized int doSomething()[] { + List x = new ArrayList(); + return new int[] { 1 }; + } + } + + public static void main(String[] args) throws ParseException, IOException { + int x = 2; + CompilationUnit cu = parse(new File("src/japa/parser/javacc/Parser.java")); + System.out.println(cu); + DumperTestClass teste = new DumperTestClass(2); + DumperTestClass.QWE qwe = teste.new QWE(1); + if (1 + 1 == 2) { + teste = null; + teste = new DumperTestClass(1); + } else { + x = 3; + teste = new DumperTestClass(1); + x = x == 0 ? 2 : 4; + } + if (true) x = 1; else x = 3; + while (true) { + xxx: while (x == 3) continue xxx; + break; + } + do { + x++; + } while (x < 100); + do x++; while (x < 100); + for (@Deprecated int i : arr4[0]) { + x--; + } + for (@Deprecated final int i = 0, j = 1; i < 10; x++) { + break; + } + int i, j; + for (i = 0, j = 1; i < 10 && j < 2; i++, j--) { + break; + } + } + + @AnnotationTest(value = "x") + public static CompilationUnit parse(@Deprecated File file) throws ParseException, IOException { + String a = ((String) "qwe"); + String x = ((String) clz1.getName()); + int y = ((Integer) (Object) x).intValue(); + synchronized (file) { + file = null; + file = new File(""); + } + try { + if (file == null) { + throw new NullPointerException("blah"); + } + } catch (final NullPointerException e) { + System.out.println("catch"); + } catch (RuntimeException e) { + System.out.println("catch"); + } finally { + System.out.println("finally"); + } + try { + if (file == null) { + throw new NullPointerException("blah"); + } + } finally { + System.out.println("finally"); + } + try { + if (file == null) { + throw new NullPointerException("blah"); + } + } catch (RuntimeException e) { + System.out.println("catch"); + } + return JavaParser.parse(file); + } + + class A implements XXX, Serializable { + + @AnnotationTest + public A(Integer integer, ABC string) throws Exception, IOException { + } + } + + private void x(Map x) { + @Deprecated Comparator c = new Comparator() { + + public int compare(Object o1, Object o2) { + try { + A a = new A(new Integer(11), "foo") { + }; + } catch (Exception e) { + } + return 0; + } + + @Override + public boolean equals(Object obj) { + return super.equals(obj); + } + }; + } + + @Documented + public @interface AnnotationTest { + + String value() default "asd"; + + @Deprecated + int[] valueI() default { 1, 2 }; + + AnnotationTest valueA1() default @AnnotationTest; + + AnnotationTest valueA2() default @AnnotationTest("qwe"); + + AnnotationTest valueA3() default @AnnotationTest(value = "qwe", valueI = { 1 }); + } + + ; +} + +class Base { + + public void check2(A val1, B val2) { + } +} + +interface XXX extends Serializable, Cloneable { +} \ No newline at end of file diff --git a/parser/html/java/javaparser/test/japa/parser/ast/test/classes/JavadocTestClass.java b/parser/html/java/javaparser/test/japa/parser/ast/test/classes/JavadocTestClass.java new file mode 100644 index 000000000..e8b96179c --- /dev/null +++ b/parser/html/java/javaparser/test/japa/parser/ast/test/classes/JavadocTestClass.java @@ -0,0 +1,127 @@ +package japa.parser.ast.test.classes; + +/** + * Javadoc 1 + * @author Julio Vilmar Gesser + */ +public abstract class JavadocTestClass { + + ; + + /** + * 1.1 + */ + ; + + private static int x; + + /** + * 1.2 + */ + private int y[]; + + /** + * 1.3 + */ + @Annotation(x = 10) + private int z; + + private static final int m(int x) { + return 0; + } + + /** + * 1.4 + * @param x + * @return + */ + private static final int m2(int x) { + x = 10; + /** + * 1.4.1 + * @author jgesser + */ + class Teste { + + /** + * 1.4.1.1 + */ + int x; + } + return 0; + } + + /** + * 1.5 + */ + public JavadocTestClass() { + } + + /** + * 1.5 + */ + public JavadocTestClass(int x) { + } + + /** + * 1.6 + * init + */ + { + z = 10; + } + + /** + * 1.6 + * init + */ + static { + x = 10; + } +} + +/** + * Javadoc 2 + */ +@Deprecated +@SuppressWarnings(value = "") +abstract class Class2 { +} + +/** + * Javadoc 3 + */ +; + +/** + * Javadoc 4 + */ +enum Enum { + + /** + * 4.1 + */ + item1, item2, item3, /** + * 4.2 + */ + item4 +} + +/** + * Javadoc 5 + */ +@interface Annotation { + + ; + + /** + * Javadoc 5.1 + * @return + */ + int x(); + + /** + * Javadoc 5.2 + */ + ; +} \ No newline at end of file -- cgit v1.2.3