aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjean pierre Lerbscher <jean-pierre.lerbscher@jperf.com>2020-10-03 10:14:09 +0200
committerGitHub <noreply@github.com>2020-10-03 10:14:09 +0200
commite9af3e337100645141534e3a73004f2b45c2f572 (patch)
tree6a24fc269c22b31502a0e76b0c1902a0afc4d9ed
parenta5011a1502abef71b648da04506ab6229076fde3 (diff)
parent4d238129c268b3e670a354c12840b0009445c769 (diff)
downloadplatform_external_javaparser-e9af3e337100645141534e3a73004f2b45c2f572.tar.gz
platform_external_javaparser-e9af3e337100645141534e3a73004f2b45c2f572.tar.bz2
platform_external_javaparser-e9af3e337100645141534e3a73004f2b45c2f572.zip
Merge pull request #2818 from jlerbsc/issue-1467upstream-master
Issue 1467
-rwxr-xr-xjavaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java74
1 files changed, 74 insertions, 0 deletions
diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java
new file mode 100755
index 000000000..1e62bfce6
--- /dev/null
+++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue1467Test.java
@@ -0,0 +1,74 @@
+package com.github.javaparser.printer.lexicalpreservation;
+
+/*
+ * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2019 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) 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.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser 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.
+ */
+
+import org.junit.jupiter.api.Test;
+
+import com.github.javaparser.StaticJavaParser;
+import com.github.javaparser.ast.CompilationUnit;
+import com.github.javaparser.ast.Modifier.Keyword;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
+import com.github.javaparser.ast.body.MethodDeclaration;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.expr.ObjectCreationExpr;
+import com.github.javaparser.ast.expr.StringLiteralExpr;
+import com.github.javaparser.ast.stmt.BlockStmt;
+import com.github.javaparser.ast.stmt.Statement;
+import com.github.javaparser.ast.stmt.ThrowStmt;
+import com.github.javaparser.utils.TestUtils;
+
+public class Issue1467Test {
+
+ @Test
+ public void test() {
+ String before =
+ "public class Bar {\n" +
+ " public void foo() {\n" +
+ " System.out.print(\"Hello\");\n" +
+ " }\n" +
+ "}";
+ String expected =
+ "public void f() {\n" +
+ " throw new UnsupportedOperationException(\"Not supported yet.\");\n" +
+ " }" ;
+ CompilationUnit cu = StaticJavaParser.parse(before);
+ LexicalPreservingPrinter.setup(cu);
+ // add method method declaration
+ MethodDeclaration decl = cu.getChildNodesByType(ClassOrInterfaceDeclaration.class).get(0).addMethod("f", Keyword.PUBLIC);
+ // create body
+ BlockStmt body = new BlockStmt();
+ NodeList<Statement> statements = new NodeList<>();
+ ObjectCreationExpr exception = new ObjectCreationExpr();
+ exception.setType("UnsupportedOperationException");
+ NodeList<Expression> arguments = new NodeList<>();
+ arguments.add(new StringLiteralExpr("Not supported yet."));
+ exception.setArguments(arguments);
+ statements.add(new ThrowStmt(exception));
+ body.setStatements(statements);
+ // set body to the method declaration
+ decl.setBody(body);
+ // print the result from LexicalPreservingPrinter
+ String actual = LexicalPreservingPrinter.print(decl);
+ TestUtils.assertEqualsStringIgnoringEol(expected, actual);
+ }
+}