From 0ed2a4bad27f1a8dc065548d3c7063325d7287e4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:57:51 +0000 Subject: [PATCH 1/5] chore(deps): update actions/checkout action to v4.1.1 --- .github/workflows/create_github_release.yml | 2 +- .github/workflows/maven_tests.yml | 4 ++-- .github/workflows/prepare_release_changelog.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/create_github_release.yml b/.github/workflows/create_github_release.yml index 84345779c7..80ed0e35cf 100644 --- a/.github/workflows/create_github_release.yml +++ b/.github/workflows/create_github_release.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 - name: Create Release id: create_release diff --git a/.github/workflows/maven_tests.yml b/.github/workflows/maven_tests.yml index 64e43d228a..7822dc4d08 100644 --- a/.github/workflows/maven_tests.yml +++ b/.github/workflows/maven_tests.yml @@ -45,7 +45,7 @@ jobs: steps: ## Checkout the current version of the code from the repo. - name: Checkout latest code - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 with: fetch-depth: "0" @@ -109,7 +109,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout latest code - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 with: fetch-depth: "0" - name: Set up JDK 11 diff --git a/.github/workflows/prepare_release_changelog.yml b/.github/workflows/prepare_release_changelog.yml index 1c4519902a..1a233d631d 100644 --- a/.github/workflows/prepare_release_changelog.yml +++ b/.github/workflows/prepare_release_changelog.yml @@ -15,7 +15,7 @@ jobs: # Check out current repository - name: Fetch Sources - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 # Setup Java 11 environment for the next steps - name: Setup Java From 687abcdc88b20b7e7c1e94f565b85ee66abf33c6 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 19 Oct 2023 17:38:20 +0200 Subject: [PATCH 2/5] Fix: issue 4163 Calling MethodDeclaration.getDeclarationAsString leads to MethodDelaration.getComment returning no comment --- .../lexicalpreservation/Issue4163Test.java | 75 +++++++++++++++++++ .../java/com/github/javaparser/ast/Node.java | 2 - .../ast/body/CallableDeclaration.java | 48 +++++++----- .../body/CompactConstructorDeclaration.java | 42 +++++++---- .../ast/body/ConstructorDeclaration.java | 20 ++--- .../ast/body/MethodDeclaration.java | 31 ++++---- 6 files changed, 159 insertions(+), 59 deletions(-) create mode 100755 javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue4163Test.java diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue4163Test.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue4163Test.java new file mode 100755 index 0000000000..55785a4ee9 --- /dev/null +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue4163Test.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2023 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. + */ + +package com.github.javaparser.printer.lexicalpreservation; + +import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol; + +import org.junit.jupiter.api.Test; + +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.visitor.VoidVisitorAdapter; +import com.github.javaparser.printer.DefaultPrettyPrinter; +import com.github.javaparser.printer.Printer; +import com.github.javaparser.printer.configuration.DefaultConfigurationOption; +import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration; +import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption; +import com.github.javaparser.printer.configuration.PrinterConfiguration; + +public class Issue4163Test extends AbstractLexicalPreservingTest { + + @Test + void test() { + VoidVisitorAdapter visitor = new VoidVisitorAdapter() { + @Override + public void visit(MethodDeclaration n, Object arg) { + System.out.println(n.getDeclarationAsString(true, true, true)); + System.out.println(n.getComment()); + } + }; + String code = + "class Foo {\n" + + " /*\n" + + " * comment\n" + + " */\n" + + " void m() {}\n" + + " }"; + + // setup pretty printer to print comments + PrinterConfiguration config = new DefaultPrinterConfiguration() + .addOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)); + Printer printer = new DefaultPrettyPrinter(config); + CompilationUnit cu = StaticJavaParser.parse(code); + MethodDeclaration md = cu.findFirst(MethodDeclaration.class).get(); + + // expected result is + String expected = md.getComment().get().asString()+"\n"; + + // set the new pretty printer in the compilation unit + cu.printer(printer); + // visit the MethodDeclaration node + visitor.visit(cu, null); + // checks that the comment is printed after executing the getDeclarationAsString method + assertEqualsStringIgnoringEol(expected, md.getComment().get().toString()); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java b/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java index b4fdaa020f..1f35979da5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java @@ -153,8 +153,6 @@ public enum Parsedness { // usefull to find if the node is a phantom node private static final int LEVELS_TO_EXPLORE = 3; - protected static final PrinterConfiguration prettyPrinterNoCommentsConfiguration = new DefaultPrinterConfiguration().removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)); - @InternalProperty private Range range; diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java index 4ee92a5b10..328dbd3b97 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java @@ -20,6 +20,14 @@ */ package com.github.javaparser.ast.body; +import static com.github.javaparser.utils.Utils.assertNotNull; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; + +import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; + import com.github.javaparser.TokenRange; import com.github.javaparser.ast.*; import com.github.javaparser.ast.expr.AnnotationExpr; @@ -36,14 +44,6 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; -import java.util.List; -import java.util.Optional; -import java.util.function.Consumer; - -import static com.github.javaparser.utils.Utils.assertNotNull; -import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toList; - /** * Represents a declaration which is callable eg. a method or a constructor. */ @@ -88,12 +88,14 @@ public CallableDeclaration(TokenRange tokenRange, NodeList modifiers, * @return modifiers * @see Modifier */ - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public NodeList getModifiers() { return modifiers; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") @SuppressWarnings("unchecked") public T setModifiers(final NodeList modifiers) { assertNotNull(modifiers); @@ -108,12 +110,14 @@ public T setModifiers(final NodeList modifiers) { return (T) this; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public SimpleName getName() { return name; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") @SuppressWarnings("unchecked") public T setName(final SimpleName name) { assertNotNull(name); @@ -128,12 +132,14 @@ public T setName(final SimpleName name) { return (T) this; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public NodeList getParameters() { return parameters; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") @SuppressWarnings("unchecked") public T setParameters(final NodeList parameters) { assertNotNull(parameters); @@ -148,12 +154,14 @@ public T setParameters(final NodeList parameters) { return (T) this; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public NodeList getThrownExceptions() { return thrownExceptions; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") @SuppressWarnings("unchecked") public T setThrownExceptions(final NodeList thrownExceptions) { assertNotNull(thrownExceptions); @@ -168,12 +176,14 @@ public T setThrownExceptions(final NodeList thrownExceptions) { return (T) this; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public NodeList getTypeParameters() { return typeParameters; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") @SuppressWarnings("unchecked") public T setTypeParameters(final NodeList typeParameters) { assertNotNull(typeParameters); @@ -199,7 +209,7 @@ protected String appendThrowsIfRequested(boolean includingThrows) { } else { sb.append(", "); } - sb.append(thr.toString(prettyPrinterNoCommentsConfiguration)); + sb.append(thr); } } return sb.toString(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/CompactConstructorDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CompactConstructorDeclaration.java index cffaf44929..e710ddfd59 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/CompactConstructorDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CompactConstructorDeclaration.java @@ -20,6 +20,11 @@ */ package com.github.javaparser.ast.body; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; +import java.util.function.Consumer; + import com.github.javaparser.TokenRange; import com.github.javaparser.ast.*; import com.github.javaparser.ast.expr.AnnotationExpr; @@ -38,11 +43,6 @@ import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; -import java.util.Optional; -import java.util.function.Consumer; - -import static com.github.javaparser.utils.Utils.assertNotNull; - /** *

The record declaration's constructor

* WARNING: This implementation is subject to change. @@ -121,7 +121,8 @@ public void accept(final VoidVisitor v, final A arg) { v.visit(this, arg); } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public BlockStmt getBody() { return body; } @@ -132,7 +133,8 @@ public BlockStmt getBody() { * @param body the body, can not be null * @return this, the ConstructorDeclaration */ - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public CompactConstructorDeclaration setBody(final BlockStmt body) { assertNotNull(body); if (body == this.body) { @@ -146,12 +148,14 @@ public CompactConstructorDeclaration setBody(final BlockStmt body) { return this; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public NodeList getModifiers() { return modifiers; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public CompactConstructorDeclaration setModifiers(final NodeList modifiers) { assertNotNull(modifiers); if (modifiers == this.modifiers) { @@ -165,12 +169,14 @@ public CompactConstructorDeclaration setModifiers(final NodeList modif return this; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public SimpleName getName() { return name; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public CompactConstructorDeclaration setName(final SimpleName name) { assertNotNull(name); if (name == this.name) { @@ -184,12 +190,14 @@ public CompactConstructorDeclaration setName(final SimpleName name) { return this; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public NodeList getThrownExceptions() { return thrownExceptions; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public CompactConstructorDeclaration setThrownExceptions(final NodeList thrownExceptions) { assertNotNull(thrownExceptions); if (thrownExceptions == this.thrownExceptions) { @@ -203,12 +211,14 @@ public CompactConstructorDeclaration setThrownExceptions(final NodeList getTypeParameters() { return typeParameters; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public CompactConstructorDeclaration setTypeParameters(final NodeList typeParameters) { assertNotNull(typeParameters); if (typeParameters == this.typeParameters) { @@ -252,7 +262,7 @@ protected String appendThrowsIfRequested(boolean includingThrows) { } else { sb.append(", "); } - sb.append(thr.toString(prettyPrinterNoCommentsConfiguration)); + sb.append(thr); } } return sb.toString(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java index c16619a80a..f8d8d96c4b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java @@ -20,6 +20,11 @@ */ package com.github.javaparser.ast.body; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; +import java.util.function.Consumer; + import com.github.javaparser.TokenRange; import com.github.javaparser.ast.*; import com.github.javaparser.ast.expr.AnnotationExpr; @@ -38,11 +43,6 @@ import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration; -import java.util.Optional; -import java.util.function.Consumer; - -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * A constructor declaration: {@code class X { X() { } }} where X(){} is the constructor declaration. *

@@ -98,7 +98,8 @@ public void accept(final VoidVisitor v, final A arg) { v.visit(this, arg); } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public BlockStmt getBody() { return body; } @@ -109,7 +110,8 @@ public BlockStmt getBody() { * @param body the body, can not be null * @return this, the ConstructorDeclaration */ - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public ConstructorDeclaration setBody(final BlockStmt body) { assertNotNull(body); if (body == this.body) { @@ -171,9 +173,9 @@ public String getDeclarationAsString(boolean includingModifiers, boolean includi sb.append(", "); } if (includingParameterName) { - sb.append(param.toString(prettyPrinterNoCommentsConfiguration)); + sb.append(param); } else { - sb.append(param.getType().toString(prettyPrinterNoCommentsConfiguration)); + sb.append(param.getType()); } } sb.append(")"); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java index 4587fc898d..cf30305052 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java @@ -20,6 +20,11 @@ */ package com.github.javaparser.ast.body; +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; +import java.util.function.Consumer; + import com.github.javaparser.TokenRange; import com.github.javaparser.ast.*; import com.github.javaparser.ast.expr.AnnotationExpr; @@ -41,11 +46,6 @@ import com.github.javaparser.resolution.Resolvable; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; -import java.util.Optional; -import java.util.function.Consumer; - -import static com.github.javaparser.utils.Utils.assertNotNull; - /** * A method declaration. "public int abc() {return 1;}" in this example: {@code class X { public int abc() {return 1;} * }} @@ -106,7 +106,8 @@ public void accept(final VoidVisitor v, final A arg) { v.visit(this, arg); } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public Optional getBody() { return Optional.ofNullable(body); } @@ -117,7 +118,8 @@ public Optional getBody() { * @param body the body, can be null * @return this, the MethodDeclaration */ - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public MethodDeclaration setBody(final BlockStmt body) { if (body == this.body) { return this; @@ -130,12 +132,14 @@ public MethodDeclaration setBody(final BlockStmt body) { return this; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public Type getType() { return type; } - @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public MethodDeclaration setType(final Type type) { assertNotNull(type); if (type == this.type) { @@ -205,7 +209,7 @@ public String getDeclarationAsString(boolean includingModifiers, boolean includi sb.append("synchronized "); } } - sb.append(getType().toString(prettyPrinterNoCommentsConfiguration)); + sb.append(getType()); sb.append(" "); sb.append(getName()); sb.append("("); @@ -217,9 +221,9 @@ public String getDeclarationAsString(boolean includingModifiers, boolean includi sb.append(", "); } if (includingParameterName) { - sb.append(param.toString(prettyPrinterNoCommentsConfiguration)); + sb.append(param); } else { - sb.append(param.getType().toString(prettyPrinterNoCommentsConfiguration)); + sb.append(param.getType()); if (param.isVarArgs()) { sb.append("..."); } @@ -286,7 +290,8 @@ public boolean remove(Node node) { return super.remove(node); } - @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") public MethodDeclaration removeBody() { return setBody((BlockStmt) null); } From 0d909d718d7b11e3081e14aecf28d32976700760 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 19 Oct 2023 19:30:35 +0200 Subject: [PATCH 3/5] revert previous commit and add new behaviour in Node.toString() --- .../src/main/java/com/github/javaparser/ast/Node.java | 11 ++++++++++- .../javaparser/ast/body/CallableDeclaration.java | 2 +- .../ast/body/CompactConstructorDeclaration.java | 2 +- .../javaparser/ast/body/ConstructorDeclaration.java | 4 ++-- .../github/javaparser/ast/body/MethodDeclaration.java | 6 +++--- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java b/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java index 1f35979da5..1205643567 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java @@ -153,6 +153,9 @@ public enum Parsedness { // usefull to find if the node is a phantom node private static final int LEVELS_TO_EXPLORE = 3; + protected static final PrinterConfiguration prettyPrinterNoCommentsConfiguration = new DefaultPrinterConfiguration() + .removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS)); + @InternalProperty private Range range; @@ -332,7 +335,13 @@ public final String toString() { * Formatting can be configured with parameter PrinterConfiguration. */ public final String toString(PrinterConfiguration configuration) { - return getPrinter(configuration).print(this); + // save the current configuration + PrinterConfiguration previousConfiguration = getPrinter().getConfiguration(); + // print with the new configuration + String result = getPrinter(configuration).print(this); + // restore the previous printer configuration (issue 4163) + getPrinter().setConfiguration(previousConfiguration); + return result; } @Override diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java index 328dbd3b97..9d5d5c6815 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java @@ -209,7 +209,7 @@ protected String appendThrowsIfRequested(boolean includingThrows) { } else { sb.append(", "); } - sb.append(thr); + sb.append(thr.toString(prettyPrinterNoCommentsConfiguration)); } } return sb.toString(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/CompactConstructorDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CompactConstructorDeclaration.java index e710ddfd59..7610dab804 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/CompactConstructorDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CompactConstructorDeclaration.java @@ -262,7 +262,7 @@ protected String appendThrowsIfRequested(boolean includingThrows) { } else { sb.append(", "); } - sb.append(thr); + sb.append(thr.toString(prettyPrinterNoCommentsConfiguration)); } } return sb.toString(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java index f8d8d96c4b..a9dbd6e90d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java @@ -173,9 +173,9 @@ public String getDeclarationAsString(boolean includingModifiers, boolean includi sb.append(", "); } if (includingParameterName) { - sb.append(param); + sb.append(param.toString(prettyPrinterNoCommentsConfiguration)); } else { - sb.append(param.getType()); + sb.append(param.getType().toString(prettyPrinterNoCommentsConfiguration)); } } sb.append(")"); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java index cf30305052..eb68950cbf 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java @@ -209,7 +209,7 @@ public String getDeclarationAsString(boolean includingModifiers, boolean includi sb.append("synchronized "); } } - sb.append(getType()); + sb.append(getType().toString(prettyPrinterNoCommentsConfiguration)); sb.append(" "); sb.append(getName()); sb.append("("); @@ -221,9 +221,9 @@ public String getDeclarationAsString(boolean includingModifiers, boolean includi sb.append(", "); } if (includingParameterName) { - sb.append(param); + sb.append(param.toString(prettyPrinterNoCommentsConfiguration)); } else { - sb.append(param.getType()); + sb.append(param.getType().toString(prettyPrinterNoCommentsConfiguration)); if (param.isVarArgs()) { sb.append("..."); } From 485665a32a1703e97723a94a422eb0f11e731a57 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Thu, 19 Oct 2023 19:53:12 +0200 Subject: [PATCH 4/5] Remove printing of comments on method name --- .../java/com/github/javaparser/ast/body/MethodDeclaration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java index eb68950cbf..8502ac3a68 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java @@ -211,7 +211,7 @@ public String getDeclarationAsString(boolean includingModifiers, boolean includi } sb.append(getType().toString(prettyPrinterNoCommentsConfiguration)); sb.append(" "); - sb.append(getName()); + sb.append(getName().toString(prettyPrinterNoCommentsConfiguration)); sb.append("("); boolean firstParam = true; for (Parameter param : getParameters()) { From 2f5b010e5b1421f75c5b86fade578386c257cb59 Mon Sep 17 00:00:00 2001 From: u7461674 Date: Fri, 20 Oct 2023 12:35:00 +1100 Subject: [PATCH 5/5] reformat javaconcept take 2 --- .../ConcreteSyntaxModelAcceptanceTest.java | 14 +- .../printer/JavaConceptsBase_prettyprinted | 83 ++++ .../printer/JavaConceptsEnums_prettyprinted | 70 +++ .../JavaConceptsInnerClasses_prettyprinted | 135 ++++++ .../printer/JavaConceptsMethods_prettyprinted | 164 ++++++++ .../printer/JavaConceptsUgly_prettyprinted | 60 +++ .../printer/JavaConcepts_prettyprinted | 398 ------------------ .../javaparser/printer/JavaConcepts.java | 393 ----------------- .../javaparser/printer/JavaConceptsBase.java | 83 ++++ .../javaparser/printer/JavaConceptsEnums.java | 70 +++ .../printer/JavaConceptsInnerClasses.java | 135 ++++++ .../printer/JavaConceptsMethods.java | 164 ++++++++ .../javaparser/printer/JavaConceptsUgly.java | 60 +++ 13 files changed, 1035 insertions(+), 794 deletions(-) create mode 100644 javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsBase_prettyprinted create mode 100644 javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsEnums_prettyprinted create mode 100644 javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsInnerClasses_prettyprinted create mode 100644 javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsMethods_prettyprinted create mode 100644 javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsUgly_prettyprinted delete mode 100644 javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConcepts_prettyprinted delete mode 100644 javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConcepts.java create mode 100644 javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsBase.java create mode 100644 javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsEnums.java create mode 100644 javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsInnerClasses.java create mode 100644 javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsMethods.java create mode 100644 javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsUgly.java diff --git a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/ConcreteSyntaxModelAcceptanceTest.java b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/ConcreteSyntaxModelAcceptanceTest.java index a2d4d689f0..1f81eeacfa 100644 --- a/javaparser-core-testing/src/test/java/com/github/javaparser/printer/ConcreteSyntaxModelAcceptanceTest.java +++ b/javaparser-core-testing/src/test/java/com/github/javaparser/printer/ConcreteSyntaxModelAcceptanceTest.java @@ -51,8 +51,16 @@ void printingExamplePrettyPrintVisitor() throws IOException { @Test void printingExampleJavaConcepts() throws IOException { - CompilationUnit cu = parse(rootDir.resolve("com/github/javaparser/printer/JavaConcepts.java")); - TestUtils.assertEqualsStringIgnoringEol(prettyPrintedExpectation("JavaConcepts"), prettyPrint(cu)); - } + CompilationUnit base = parse(rootDir.resolve("com/github/javaparser/printer/JavaConceptsBase.java")); + CompilationUnit enums = parse(rootDir.resolve("com/github/javaparser/printer/JavaConceptsEnums.java")); + CompilationUnit innerClass = parse(rootDir.resolve("com/github/javaparser/printer/JavaConceptsInnerClasses.java")); + CompilationUnit methods = parse(rootDir.resolve("com/github/javaparser/printer/JavaConceptsMethods.java")); + CompilationUnit ugly = parse(rootDir.resolve("com/github/javaparser/printer/JavaConceptsUgly.java")); + TestUtils.assertEqualsStringIgnoringEol(prettyPrintedExpectation("JavaConceptsBase"), prettyPrint(base)); + TestUtils.assertEqualsStringIgnoringEol(prettyPrintedExpectation("JavaConceptsEnums"), prettyPrint(enums)); + TestUtils.assertEqualsStringIgnoringEol(prettyPrintedExpectation("JavaConceptsInnerClasses"), prettyPrint(innerClass)); + TestUtils.assertEqualsStringIgnoringEol(prettyPrintedExpectation("JavaConceptsMethods"), prettyPrint(methods)); + TestUtils.assertEqualsStringIgnoringEol(prettyPrintedExpectation("JavaConceptsUgly"), prettyPrint(ugly)); + } } diff --git a/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsBase_prettyprinted b/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsBase_prettyprinted new file mode 100644 index 0000000000..0740244055 --- /dev/null +++ b/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsBase_prettyprinted @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 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. + */ +package japa.bdd.samples; + +import com.github.javaparser.JavaParser; +import japa.parser.ParseException; +import com.github.javaparser.ast.CompilationUnit; +import java.io.*; +import java.util.*; + +@Deprecated +public class JavaConceptsBase, 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; + + byte[] byebye = null; + + short sh1, sh2 = 1; + + int intWithUnderscore = 1234_5678; + + long longWithUnderscore = 1234_5678L; + + float floatWithUnderscore = 1_234.5_678f; + + float floatWithUnderscoreAndExponent = 1_234e1_0f; + + double doubleWithUnderscore = 1_234.5_678; + + double doubleWithUnderscoreAndExponent = 1_234e1_0; + + int binaryLiteral = 0b101101; + + List[][] arrLS = (List[][]) new List[10][]; + + 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 = {}; + + static { + arr4 = new int[][] { { 2 }, { 1 } }; + } + + { + arr3 = new int[][] { { 2 }, { 1 } }; + } + + public static JavaConceptsBase t; +} diff --git a/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsEnums_prettyprinted b/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsEnums_prettyprinted new file mode 100644 index 0000000000..734faabedf --- /dev/null +++ b/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsEnums_prettyprinted @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 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. + */ +package japa.bdd.samples; + +@Deprecated +public class JavaConceptsEnums { + + public enum Teste { + + asc, + def + } + + public enum Sexo { + + m, + @Deprecated + f; + + public enum Sexo_ implements Serializable, Cloneable { + + } + } + + @Deprecated + public 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(); + } +} diff --git a/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsInnerClasses_prettyprinted b/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsInnerClasses_prettyprinted new file mode 100644 index 0000000000..e1eb83c6ca --- /dev/null +++ b/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsInnerClasses_prettyprinted @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 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. + */ +package japa.bdd.samples; + +import com.github.javaparser.JavaParser; +import japa.parser.ParseException; +import com.github.javaparser.ast.CompilationUnit; +import org.junit.Ignore; +import java.io.*; +import java.util.*; + +@Ignore +@Deprecated +public class JavaConceptsInnerClasses, X> extends Base implements Serializable { + + public JavaConceptsInnerClasses(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(); + JavaConceptsInnerClasses.this.cc = 'c'; + super.i = 1; + Y.super.m(); + } + + public Y(int y) { + super(); + } + + public Y(long x) { + this(); + } + } + } + + public JavaConceptsInnerClasses(String str) { + } + + private class QWE extends JavaConceptsInnerClasses, 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 }; + } + } +} + +class Base { + + public void check2(A val1, B val2) { + } +} + +interface XXX extends Serializable, Cloneable { +} diff --git a/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsMethods_prettyprinted b/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsMethods_prettyprinted new file mode 100644 index 0000000000..122fc5b7e4 --- /dev/null +++ b/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsMethods_prettyprinted @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 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. + */ +package japa.bdd.samples; + +import com.github.javaparser.JavaParser; +import japa.parser.ParseException; +import com.github.javaparser.ast.CompilationUnit; +import java.io.*; +import java.util.*; + +public class JavaConceptsMethods { + + strictfp double ddd() { + return 0.0; + } + + 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); + JavaConcepts teste = new JavaConcepts(2); + JavaConcepts.QWE qwe = teste.new QWE(1); + if (1 + 1 == 2) { + teste = null; + teste = new JavaConcepts(1); + } else { + x = 3; + teste = new JavaConcepts(1); + x = x == 0 ? 2 : 4; + } + if (true) + x = 1; + else + x = 3; + if (true) + x = 1; + else if (false) + x = 3; + else + x = 2; + 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; + } + } + + 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"); + } + try (InputStream in = createInputStream()) { + System.out.println(in); + } catch (IOException e) { + System.out.println("catch"); + } + try (InputStream in = createInputStream(); + InputStream in2 = createInputStream()) { + System.out.println(in); + } catch (IOException e) { + System.out.println("catch"); + } + try (InputStream in = createInputStream()) { + System.out.println(in); + } + try { + System.out.println("whatever"); + } catch (RuntimeException e) { + System.out.println(e); + } catch (final Exception | Error e) { + System.out.println(e); + } + return JavaParser.parse(file); + } + + class A implements XXX, Serializable { + + 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); + } + }; + } + + private static InputStream createInputStream() { + return new ByteArrayInputStream(null); + } +} diff --git a/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsUgly_prettyprinted b/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsUgly_prettyprinted new file mode 100644 index 0000000000..b34d8f0790 --- /dev/null +++ b/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConceptsUgly_prettyprinted @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 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. + */ +package japa.bdd.samples; + +@Deprecated +public class JavaConceptsUgly { + + 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; + } +} diff --git a/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConcepts_prettyprinted b/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConcepts_prettyprinted deleted file mode 100644 index 014fd9cb8c..0000000000 --- a/javaparser-core-testing/src/test/resources/com/github/javaparser/printer/JavaConcepts_prettyprinted +++ /dev/null @@ -1,398 +0,0 @@ -package japa.bdd.samples; - -import com.github.javaparser.JavaParser; -import japa.parser.ParseException; -import com.github.javaparser.ast.CompilationUnit; -import org.junit.Ignore; -import java.io.*; -import java.util.*; - -@Ignore -@Deprecated -public class JavaConcepts, 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; - - byte[] byebye = null; - - short sh1, sh2 = 1; - - int intWithUnderscore = 1234_5678; - - long longWithUnderscore = 1234_5678L; - - float floatWithUnderscore = 1_234.5_678f; - - float floatWithUnderscoreAndExponent = 1_234e1_0f; - - double doubleWithUnderscore = 1_234.5_678; - - double doubleWithUnderscoreAndExponent = 1_234e1_0; - - int binaryLiteral = 0b101101; - - List[][] arrLS = (List[][]) new List[10][]; - - { - int z = 0, y = 0; - int a = (z) + y; - a = (+z) + y; - byte b = (byte) +y; - } - - List diamond1 = new LinkedList<>(); - - @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 JavaConcepts t; - - static { - arr4 = new int[][] { { 2 }, { 1 } }; - } - - { - arr3 = new int[][] { { 2 }, { 1 } }; - } - - public enum Teste { - - asc, - def - } - - public enum Sexo { - - m, - @Deprecated - f; - - public enum Sexo_ implements Serializable, Cloneable { - - } - - private Sexo() { - } - } - - @Deprecated - public 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 JavaConcepts(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(); - JavaConcepts.this.cc = 'c'; - super.i = 1; - Y.super.m(); - } - - public Y(int y) { - super(); - } - - public Y(long x) { - this(); - } - } - } - - public JavaConcepts(String str) { - } - - private class QWE extends JavaConcepts, 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); - JavaConcepts teste = new JavaConcepts(2); - JavaConcepts.QWE qwe = teste.new QWE(1); - if (1 + 1 == 2) { - teste = null; - teste = new JavaConcepts(1); - } else { - x = 3; - teste = new JavaConcepts(1); - x = x == 0 ? 2 : 4; - } - if (true) - x = 1; - else - x = 3; - if (true) - x = 1; - else if (false) - x = 3; - else - x = 2; - 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; - } - } - - 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"); - } - try (InputStream in = createInputStream()) { - System.out.println(in); - } catch (IOException e) { - System.out.println("catch"); - } - try (InputStream in = createInputStream(); - InputStream in2 = createInputStream()) { - System.out.println(in); - } catch (IOException e) { - System.out.println("catch"); - } - try (InputStream in = createInputStream()) { - System.out.println(in); - } - try { - System.out.println("whatever"); - } catch (RuntimeException e) { - System.out.println(e); - } catch (final Exception | Error e) { - System.out.println(e); - } - return JavaParser.parse(file); - } - - class A implements XXX, Serializable { - - 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); - } - }; - } - - private static InputStream createInputStream() { - return new ByteArrayInputStream(null); - } -} - -class Base { - - public void check2(A val1, B val2) { - } -} - -interface XXX extends Serializable, Cloneable { -} diff --git a/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConcepts.java b/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConcepts.java deleted file mode 100644 index 2a53e5f5b6..0000000000 --- a/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConcepts.java +++ /dev/null @@ -1,393 +0,0 @@ -package japa.bdd.samples; - -import com.github.javaparser.JavaParser; -import japa.parser.ParseException; -import com.github.javaparser.ast.CompilationUnit; -import org.junit.Ignore; - -import java.io.*; -import java.util.*; - -@Ignore -@Deprecated -public class JavaConcepts, 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; - - byte byebye[] = null; - - short sh1, sh2 = 1; - - int intWithUnderscore = 1234_5678; - - long longWithUnderscore = 1234_5678L; - - float floatWithUnderscore = 1_234.5_678f; - - float floatWithUnderscoreAndExponent = 1_234e1_0f; - - double doubleWithUnderscore = 1_234.5_678; - - double doubleWithUnderscoreAndExponent = 1_234e1_0; - - int binaryLiteral = 0b101101; - - List[][] arrLS = (List[][]) new List[10][]; - - { - int z = 0, y = 0; - int a = (z) + y; - a = (+z) + y; - byte b = (byte) +y; - } - - List diamond1 = new LinkedList<>(); - - @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 JavaConcepts t; - - static { - arr4 = new int[][]{{2}, {1}}; - } - - { - arr3 = new int[][]{{2}, {1}}; - } - - public enum Teste { - - asc, def - } - - public enum Sexo { - - m, @Deprecated - f; - - public enum Sexo_ implements Serializable, Cloneable { - } - - private Sexo() { - } - } - - @Deprecated - public 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 JavaConcepts(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(); - JavaConcepts.this.cc = 'c'; - super.i = 1; - Y.super.m(); - } - - public Y(int y) { - super(); - } - - public Y(long x) { - this(); - } - } - } - - public JavaConcepts(String str) { - } - - private class QWE extends JavaConcepts, 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); - JavaConcepts teste = new JavaConcepts(2); - JavaConcepts.QWE qwe = teste.new QWE(1); - if (1 + 1 == 2) { - teste = null; - teste = new JavaConcepts(1); - } else { - x = 3; - teste = new JavaConcepts(1); - x = x == 0 ? 2 : 4; - } - if (true) - x = 1; - else - x = 3; - if (true) - x = 1; - else if (false) - x = 3; - else - x = 2; - 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; - } - } - - 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"); - } - try (InputStream in = createInputStream()) { - System.out.println(in); - } catch (IOException e) { - System.out.println("catch"); - } - try (InputStream in = createInputStream(); - InputStream in2 = createInputStream()) { - System.out.println(in); - } catch (IOException e) { - System.out.println("catch"); - } - try (InputStream in = createInputStream()) { - System.out.println(in); - } - try { - System.out.println("whatever"); - } catch (RuntimeException e) { - System.out.println(e); - } catch (final Exception | Error e) { - System.out.println(e); - } - return JavaParser.parse(file); - } - - class A implements XXX, Serializable { - - 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); - } - }; - } - - private static InputStream createInputStream() { - return new ByteArrayInputStream(null); - } -} - -class Base { - - public void check2(A val1, B val2) { - } -} - -interface XXX extends Serializable, Cloneable { -} diff --git a/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsBase.java b/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsBase.java new file mode 100644 index 0000000000..0740244055 --- /dev/null +++ b/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsBase.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 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. + */ +package japa.bdd.samples; + +import com.github.javaparser.JavaParser; +import japa.parser.ParseException; +import com.github.javaparser.ast.CompilationUnit; +import java.io.*; +import java.util.*; + +@Deprecated +public class JavaConceptsBase, 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; + + byte[] byebye = null; + + short sh1, sh2 = 1; + + int intWithUnderscore = 1234_5678; + + long longWithUnderscore = 1234_5678L; + + float floatWithUnderscore = 1_234.5_678f; + + float floatWithUnderscoreAndExponent = 1_234e1_0f; + + double doubleWithUnderscore = 1_234.5_678; + + double doubleWithUnderscoreAndExponent = 1_234e1_0; + + int binaryLiteral = 0b101101; + + List[][] arrLS = (List[][]) new List[10][]; + + 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 = {}; + + static { + arr4 = new int[][] { { 2 }, { 1 } }; + } + + { + arr3 = new int[][] { { 2 }, { 1 } }; + } + + public static JavaConceptsBase t; +} diff --git a/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsEnums.java b/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsEnums.java new file mode 100644 index 0000000000..734faabedf --- /dev/null +++ b/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsEnums.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 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. + */ +package japa.bdd.samples; + +@Deprecated +public class JavaConceptsEnums { + + public enum Teste { + + asc, + def + } + + public enum Sexo { + + m, + @Deprecated + f; + + public enum Sexo_ implements Serializable, Cloneable { + + } + } + + @Deprecated + public 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(); + } +} diff --git a/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsInnerClasses.java b/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsInnerClasses.java new file mode 100644 index 0000000000..e1eb83c6ca --- /dev/null +++ b/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsInnerClasses.java @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 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. + */ +package japa.bdd.samples; + +import com.github.javaparser.JavaParser; +import japa.parser.ParseException; +import com.github.javaparser.ast.CompilationUnit; +import org.junit.Ignore; +import java.io.*; +import java.util.*; + +@Ignore +@Deprecated +public class JavaConceptsInnerClasses, X> extends Base implements Serializable { + + public JavaConceptsInnerClasses(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(); + JavaConceptsInnerClasses.this.cc = 'c'; + super.i = 1; + Y.super.m(); + } + + public Y(int y) { + super(); + } + + public Y(long x) { + this(); + } + } + } + + public JavaConceptsInnerClasses(String str) { + } + + private class QWE extends JavaConceptsInnerClasses, 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 }; + } + } +} + +class Base { + + public void check2(A val1, B val2) { + } +} + +interface XXX extends Serializable, Cloneable { +} diff --git a/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsMethods.java b/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsMethods.java new file mode 100644 index 0000000000..122fc5b7e4 --- /dev/null +++ b/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsMethods.java @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 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. + */ +package japa.bdd.samples; + +import com.github.javaparser.JavaParser; +import japa.parser.ParseException; +import com.github.javaparser.ast.CompilationUnit; +import java.io.*; +import java.util.*; + +public class JavaConceptsMethods { + + strictfp double ddd() { + return 0.0; + } + + 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); + JavaConcepts teste = new JavaConcepts(2); + JavaConcepts.QWE qwe = teste.new QWE(1); + if (1 + 1 == 2) { + teste = null; + teste = new JavaConcepts(1); + } else { + x = 3; + teste = new JavaConcepts(1); + x = x == 0 ? 2 : 4; + } + if (true) + x = 1; + else + x = 3; + if (true) + x = 1; + else if (false) + x = 3; + else + x = 2; + 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; + } + } + + 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"); + } + try (InputStream in = createInputStream()) { + System.out.println(in); + } catch (IOException e) { + System.out.println("catch"); + } + try (InputStream in = createInputStream(); + InputStream in2 = createInputStream()) { + System.out.println(in); + } catch (IOException e) { + System.out.println("catch"); + } + try (InputStream in = createInputStream()) { + System.out.println(in); + } + try { + System.out.println("whatever"); + } catch (RuntimeException e) { + System.out.println(e); + } catch (final Exception | Error e) { + System.out.println(e); + } + return JavaParser.parse(file); + } + + class A implements XXX, Serializable { + + 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); + } + }; + } + + private static InputStream createInputStream() { + return new ByteArrayInputStream(null); + } +} diff --git a/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsUgly.java b/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsUgly.java new file mode 100644 index 0000000000..b34d8f0790 --- /dev/null +++ b/javaparser-core-testing/src/test/test_sourcecode/com/github/javaparser/printer/JavaConceptsUgly.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2016 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. + */ +package japa.bdd.samples; + +@Deprecated +public class JavaConceptsUgly { + + 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; + } +}