diff options
28 files changed, 782 insertions, 753 deletions
diff --git a/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java b/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java new file mode 100644 index 000000000..284556bd7 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java @@ -0,0 +1,87 @@ +package com.github.javaparser; + +import static com.github.javaparser.GeneratedJavaParserConstants.*; +import static com.github.javaparser.utils.Utils.EOL; + +/** + * Complements GeneratedJavaParserConstants + */ +public class TokenTypes { + public static boolean isWhitespace(int tokenType) { + return tokenType >= EOF && tokenType <= ZERO_WIDTH_NO_BREAK_SPACE; + } + + public static boolean isEndOfLineCharacter(int tokenType) { + switch (tokenType) { + case WINDOWS_EOL: + case OLD_MAC_EOL: + case UNIX_EOL: + return true; + default: + return false; + } + } + + public static boolean isWhitespaceOrComment(int tokenType) { + return isWhitespace(tokenType) || isComment(tokenType); + } + + public static boolean isSpaceOrTab(int tokenType) { + switch (tokenType) { + case SPACE: + case TAB: + case FORM_FEED: + case NEXT_LINE: + case NON_BREAKING_SPACE: + case OGHAM_SPACE: + case MONGOLIAN_VOWEL_SEPARATOR: + case EN_QUAD: + case EM_QUAD: + case EN_SPACE: + case EM_SPACE: + case THREE_PER_EM_SPACE: + case FOUR_PER_EM_SPACE: + case SIX_PER_EM_SPACE: + case FIGURE_SPACE: + case PUNCTUATION_SPACE: + case THIN_SPACE: + case HAIR_SPACE: + case ZERO_WIDTH_SPACE: + case ZERO_WIDTH_NON_JOINER: + case ZERO_WIDTH_JOINER: + case LINE_SEPARATOR: + case PARAGRAPH_SEPARATOR: + case NARROW_NO_BREAK_SPACE: + case MEDIUM_MATHEMATICAL_SPACE: + case WORD_JOINER: + case IDEOGRAPHIC_SPACE: + case ZERO_WIDTH_NO_BREAK_SPACE: + return true; + default: + return false; + } + } + + public static boolean isComment(int tokenType) { + return tokenType == SINGLE_LINE_COMMENT + || tokenType == MULTI_LINE_COMMENT + || tokenType == JAVA_DOC_COMMENT; + } + + public static int eolToken() { + if (EOL.equals("\n")) { + return UNIX_EOL; + } + if (EOL.equals("\r\n")) { + return WINDOWS_EOL; + } + if (EOL.equals("\r")) { + return OLD_MAC_EOL; + } + throw new AssertionError("Unknown EOL character sequence"); + } + + public static int spaceToken() { + return SPACE; + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java b/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java index 0248da30a..57aa3dea3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java @@ -289,7 +289,7 @@ public final class CompilationUnit extends Node { } i.append(";"); ImportDeclaration importDeclaration = JavaParser.parseImport(i.toString()); - if (getImports().stream().anyMatch( im -> im.toString().equals(importDeclaration.toString()))) + if (getImports().stream().anyMatch(im -> im.toString().equals(importDeclaration.toString()))) return this; else { getImports().add(importDeclaration); @@ -395,7 +395,7 @@ public final class CompilationUnit extends Node { * @param className the class name (case-sensitive) */ public Optional<ClassOrInterfaceDeclaration> getClassByName(String className) { - return getTypes().stream().filter( type -> type.getNameAsString().equals(className) && type instanceof ClassOrInterfaceDeclaration && !((ClassOrInterfaceDeclaration) type).isInterface()).findFirst().map( t -> (ClassOrInterfaceDeclaration) t); + return getTypes().stream().filter(type -> type.getNameAsString().equals(className) && type instanceof ClassOrInterfaceDeclaration && !((ClassOrInterfaceDeclaration) type).isInterface()).findFirst().map(t -> (ClassOrInterfaceDeclaration) t); } /** @@ -404,7 +404,7 @@ public final class CompilationUnit extends Node { * @param interfaceName the interface name (case-sensitive) */ public Optional<ClassOrInterfaceDeclaration> getInterfaceByName(String interfaceName) { - return getTypes().stream().filter( type -> type.getNameAsString().equals(interfaceName) && type instanceof ClassOrInterfaceDeclaration && ((ClassOrInterfaceDeclaration) type).isInterface()).findFirst().map( t -> (ClassOrInterfaceDeclaration) t); + return getTypes().stream().filter(type -> type.getNameAsString().equals(interfaceName) && type instanceof ClassOrInterfaceDeclaration && ((ClassOrInterfaceDeclaration) type).isInterface()).findFirst().map(t -> (ClassOrInterfaceDeclaration) t); } /** @@ -413,7 +413,7 @@ public final class CompilationUnit extends Node { * @param enumName the enum name (case-sensitive) */ public Optional<EnumDeclaration> getEnumByName(String enumName) { - return getTypes().stream().filter( type -> type.getNameAsString().equals(enumName) && type instanceof EnumDeclaration).findFirst().map( t -> (EnumDeclaration) t); + return getTypes().stream().filter(type -> type.getNameAsString().equals(enumName) && type instanceof EnumDeclaration).findFirst().map(t -> (EnumDeclaration) t); } /** @@ -422,7 +422,7 @@ public final class CompilationUnit extends Node { * @param annotationName the annotation name (case-sensitive) */ public Optional<AnnotationDeclaration> getAnnotationDeclarationByName(String annotationName) { - return getTypes().stream().filter( type -> type.getNameAsString().equals(annotationName) && type instanceof AnnotationDeclaration).findFirst().map( t -> (AnnotationDeclaration) t); + return getTypes().stream().filter(type -> type.getNameAsString().equals(annotationName) && type instanceof AnnotationDeclaration).findFirst().map(t -> (AnnotationDeclaration) t); } @Override 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 cf4508daf..ed77d3a35 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 @@ -113,7 +113,7 @@ public abstract class Node implements Cloneable, HasParentNode<Node>, Visitable /** * This can be used to sort nodes on position. */ - public static Comparator<Node> NODE_BY_BEGIN_POSITION = ( a, b) -> { + public static Comparator<Node> NODE_BY_BEGIN_POSITION = (a, b) -> { if (a.getRange().isPresent() && b.getRange().isPresent()) { return a.getRange().get().begin.compareTo(b.getRange().get().begin); } @@ -338,7 +338,7 @@ public abstract class Node implements Cloneable, HasParentNode<Node>, Visitable */ @Override public Node setParentNode(Node parentNode) { - observers.forEach( o -> o.parentChange(this, this.parentNode, parentNode)); + observers.forEach(o -> o.parentChange(this, this.parentNode, parentNode)); // remove from old parent, if any if (this.parentNode != null) { this.parentNode.childNodes.remove(this); @@ -380,7 +380,7 @@ public abstract class Node implements Cloneable, HasParentNode<Node>, Visitable } public void tryAddImportToParentCompilationUnit(Class<?> clazz) { - getAncestorOfType(CompilationUnit.class).ifPresent( p -> p.addImport(clazz)); + getAncestorOfType(CompilationUnit.class).ifPresent(p -> p.addImport(clazz)); } /** @@ -456,7 +456,7 @@ public abstract class Node implements Cloneable, HasParentNode<Node>, Visitable } public <P> void notifyPropertyChange(ObservableProperty property, P oldValue, P newValue) { - this.observers.forEach( o -> o.propertyChange(this, property, oldValue, newValue)); + this.observers.forEach(o -> o.propertyChange(this, property, oldValue, newValue)); } @Override @@ -497,8 +497,8 @@ public abstract class Node implements Cloneable, HasParentNode<Node>, Visitable */ public void registerForSubtree(AstObserver observer) { register(observer); - this.getChildNodes().forEach( c -> c.registerForSubtree(observer)); - this.getNodeLists().forEach( nl -> { + this.getChildNodes().forEach(c -> c.registerForSubtree(observer)); + this.getNodeLists().forEach(nl -> { if (nl != null) nl.register(observer); }); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java index bb4833bb1..30fcf7a48 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java @@ -151,7 +151,7 @@ public final class ClassOrInterfaceDeclaration extends TypeDeclaration<ClassOrIn * @return the methods found (multiple in case of polymorphism) */ public Optional<ConstructorDeclaration> getDefaultConstructor() { - return getMembers().stream().filter( bd -> bd instanceof ConstructorDeclaration).map( bd -> (ConstructorDeclaration) bd).filter( cd -> cd.getParameters().isEmpty()).findFirst(); + return getMembers().stream().filter(bd -> bd instanceof ConstructorDeclaration).map(bd -> (ConstructorDeclaration) bd).filter(cd -> cd.getParameters().isEmpty()).findFirst(); } @Override diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/FieldDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/FieldDeclaration.java index dbd862884..e97f8ed3d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/FieldDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/FieldDeclaration.java @@ -158,7 +158,7 @@ public final class FieldDeclaration extends BodyDeclaration<FieldDeclaration> im String fieldName = variable.getNameAsString(); String fieldNameUpper = fieldName.toUpperCase().substring(0, 1) + fieldName.substring(1, fieldName.length()); final MethodDeclaration getter; - getter = parentClass.map( clazz -> clazz.addMethod("get" + fieldNameUpper, PUBLIC)).orElseGet(() -> parentEnum.get().addMethod("get" + fieldNameUpper, PUBLIC)); + getter = parentClass.map(clazz -> clazz.addMethod("get" + fieldNameUpper, PUBLIC)).orElseGet(() -> parentEnum.get().addMethod("get" + fieldNameUpper, PUBLIC)); getter.setType(variable.getType()); BlockStmt blockStmt = new BlockStmt(); getter.setBody(blockStmt); @@ -185,7 +185,7 @@ public final class FieldDeclaration extends BodyDeclaration<FieldDeclaration> im String fieldName = variable.getNameAsString(); String fieldNameUpper = fieldName.toUpperCase().substring(0, 1) + fieldName.substring(1, fieldName.length()); final MethodDeclaration setter; - setter = parentClass.map( clazz -> clazz.addMethod("set" + fieldNameUpper, PUBLIC)).orElseGet(() -> parentEnum.get().addMethod("set" + fieldNameUpper, PUBLIC)); + setter = parentClass.map(clazz -> clazz.addMethod("set" + fieldNameUpper, PUBLIC)).orElseGet(() -> parentEnum.get().addMethod("set" + fieldNameUpper, PUBLIC)); setter.setType(new VoidType()); setter.getParameters().add(new Parameter(variable.getType(), fieldName)); BlockStmt blockStmt2 = new BlockStmt(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/observer/ObservableProperty.java b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/ObservableProperty.java index f37058e4c..a3a26148d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/observer/ObservableProperty.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/ObservableProperty.java @@ -54,7 +54,7 @@ public enum ObservableProperty { private boolean derived; public static ObservableProperty fromCamelCaseName(String camelCaseName) { - Optional<ObservableProperty> observableProperty = Arrays.stream(values()).filter( v -> v.camelCaseName().equals(camelCaseName)).findFirst(); + Optional<ObservableProperty> observableProperty = Arrays.stream(values()).filter(v -> v.camelCaseName().equals(camelCaseName)).findFirst(); if (observableProperty.isPresent()) { return observableProperty.get(); } else { diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java index 643d6a49c..9ec21a604 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java @@ -1865,7 +1865,7 @@ public abstract class GenericListVisitorAdapter<R, A> implements GenericVisitor< @Override public List<R> visit(NodeList n, A arg) { - return ((NodeList<? extends Node>) n).stream().filter(Objects::nonNull).flatMap( v -> v.accept(this, arg).stream()).collect(Collectors.toList()); + return ((NodeList<? extends Node>) n).stream().filter(Objects::nonNull).flatMap(v -> v.accept(this, arg).stream()).collect(Collectors.toList()); } @Override diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitor.java index c1dd3c996..f7c05c3a5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitor.java @@ -50,7 +50,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { NodeList<BodyDeclaration<?>> members = modifyList(n.getMembers(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setMembers(members); @@ -62,11 +62,11 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final AnnotationMemberDeclaration n, final A arg) { - Expression defaultValue = n.getDefaultValue().map( s -> (Expression) s.accept(this, arg)).orElse(null); + Expression defaultValue = n.getDefaultValue().map(s -> (Expression) s.accept(this, arg)).orElse(null); SimpleName name = (SimpleName) n.getName().accept(this, arg); Type type = (Type) n.getType().accept(this, arg); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null || type == null) return null; n.setDefaultValue(defaultValue); @@ -81,7 +81,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final ArrayAccessExpr n, final A arg) { Expression index = (Expression) n.getIndex().accept(this, arg); Expression name = (Expression) n.getName().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (index == null || name == null) return null; n.setIndex(index); @@ -93,9 +93,9 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final ArrayCreationExpr n, final A arg) { Type elementType = (Type) n.getElementType().accept(this, arg); - ArrayInitializerExpr initializer = n.getInitializer().map( s -> (ArrayInitializerExpr) s.accept(this, arg)).orElse(null); + ArrayInitializerExpr initializer = n.getInitializer().map(s -> (ArrayInitializerExpr) s.accept(this, arg)).orElse(null); NodeList<ArrayCreationLevel> levels = modifyList(n.getLevels(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (elementType == null || levels.isEmpty()) return null; n.setElementType(elementType); @@ -108,7 +108,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final ArrayInitializerExpr n, final A arg) { NodeList<Expression> values = modifyList(n.getValues(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setValues(values); n.setComment(comment); return n; @@ -117,8 +117,8 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final AssertStmt n, final A arg) { Expression check = (Expression) n.getCheck().accept(this, arg); - Expression message = n.getMessage().map( s -> (Expression) s.accept(this, arg)).orElse(null); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Expression message = n.getMessage().map(s -> (Expression) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (check == null) return null; n.setCheck(check); @@ -131,7 +131,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final AssignExpr n, final A arg) { Expression target = (Expression) n.getTarget().accept(this, arg); Expression value = (Expression) n.getValue().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (target == null || value == null) return null; n.setTarget(target); @@ -144,7 +144,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final BinaryExpr n, final A arg) { Expression left = (Expression) n.getLeft().accept(this, arg); Expression right = (Expression) n.getRight().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (left == null) return right; if (right == null) @@ -158,7 +158,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final BlockStmt n, final A arg) { NodeList<Statement> statements = modifyList(n.getStatements(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setStatements(statements); n.setComment(comment); return n; @@ -166,15 +166,15 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final BooleanLiteralExpr n, final A arg) { - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setComment(comment); return n; } @Override public Visitable visit(final BreakStmt n, final A arg) { - SimpleName label = n.getLabel().map( s -> (SimpleName) s.accept(this, arg)).orElse(null); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + SimpleName label = n.getLabel().map(s -> (SimpleName) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setLabel(label); n.setComment(comment); return n; @@ -184,7 +184,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final CastExpr n, final A arg) { Expression expression = (Expression) n.getExpression().accept(this, arg); Type type = (Type) n.getType().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (expression == null || type == null) return null; n.setExpression(expression); @@ -197,7 +197,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final CatchClause n, final A arg) { BlockStmt body = (BlockStmt) n.getBody().accept(this, arg); Parameter parameter = (Parameter) n.getParameter().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (body == null || parameter == null) return null; n.setBody(body); @@ -208,7 +208,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final CharLiteralExpr n, final A arg) { - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setComment(comment); return n; } @@ -216,7 +216,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final ClassExpr n, final A arg) { Type type = (Type) n.getType().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (type == null) return null; n.setType(type); @@ -232,7 +232,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { NodeList<BodyDeclaration<?>> members = modifyList(n.getMembers(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setExtendedTypes(extendedTypes); @@ -248,10 +248,10 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final ClassOrInterfaceType n, final A arg) { SimpleName name = (SimpleName) n.getName().accept(this, arg); - ClassOrInterfaceType scope = n.getScope().map( s -> (ClassOrInterfaceType) s.accept(this, arg)).orElse(null); + ClassOrInterfaceType scope = n.getScope().map(s -> (ClassOrInterfaceType) s.accept(this, arg)).orElse(null); NodeList<Type> typeArguments = modifyList(n.getTypeArguments(), arg); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setName(name); @@ -265,10 +265,10 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final CompilationUnit n, final A arg) { NodeList<ImportDeclaration> imports = modifyList(n.getImports(), arg); - ModuleDeclaration module = n.getModule().map( s -> (ModuleDeclaration) s.accept(this, arg)).orElse(null); - PackageDeclaration packageDeclaration = n.getPackageDeclaration().map( s -> (PackageDeclaration) s.accept(this, arg)).orElse(null); + ModuleDeclaration module = n.getModule().map(s -> (ModuleDeclaration) s.accept(this, arg)).orElse(null); + PackageDeclaration packageDeclaration = n.getPackageDeclaration().map(s -> (PackageDeclaration) s.accept(this, arg)).orElse(null); NodeList<TypeDeclaration<?>> types = modifyList(n.getTypes(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setImports(imports); n.setModule(module); n.setPackageDeclaration(packageDeclaration); @@ -282,7 +282,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { Expression condition = (Expression) n.getCondition().accept(this, arg); Expression elseExpr = (Expression) n.getElseExpr().accept(this, arg); Expression thenExpr = (Expression) n.getThenExpr().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (condition == null || elseExpr == null || thenExpr == null) return null; n.setCondition(condition); @@ -300,7 +300,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { NodeList<ReferenceType> thrownExceptions = modifyList(n.getThrownExceptions(), arg); NodeList<TypeParameter> typeParameters = modifyList(n.getTypeParameters(), arg); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (body == null || name == null) return null; n.setBody(body); @@ -315,8 +315,8 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final ContinueStmt n, final A arg) { - SimpleName label = n.getLabel().map( s -> (SimpleName) s.accept(this, arg)).orElse(null); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + SimpleName label = n.getLabel().map(s -> (SimpleName) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setLabel(label); n.setComment(comment); return n; @@ -326,7 +326,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final DoStmt n, final A arg) { Statement body = (Statement) n.getBody().accept(this, arg); Expression condition = (Expression) n.getCondition().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (body == null || condition == null) return null; n.setBody(body); @@ -337,7 +337,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final DoubleLiteralExpr n, final A arg) { - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setComment(comment); return n; } @@ -345,7 +345,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final EmptyMemberDeclaration n, final A arg) { NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setAnnotations(annotations); n.setComment(comment); return n; @@ -353,15 +353,15 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final EmptyStmt n, final A arg) { - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setComment(comment); return n; } @Override public Visitable visit(final EnclosedExpr n, final A arg) { - Expression inner = n.getInner().map( s -> (Expression) s.accept(this, arg)).orElse(null); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Expression inner = n.getInner().map(s -> (Expression) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setInner(inner); n.setComment(comment); return n; @@ -373,7 +373,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { NodeList<BodyDeclaration<?>> classBody = modifyList(n.getClassBody(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setArguments(arguments); @@ -391,7 +391,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { NodeList<BodyDeclaration<?>> members = modifyList(n.getMembers(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setEntries(entries); @@ -406,9 +406,9 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final ExplicitConstructorInvocationStmt n, final A arg) { NodeList<Expression> arguments = modifyList(n.getArguments(), arg); - Expression expression = n.getExpression().map( s -> (Expression) s.accept(this, arg)).orElse(null); + Expression expression = n.getExpression().map(s -> (Expression) s.accept(this, arg)).orElse(null); NodeList<Type> typeArguments = modifyList(n.getTypeArguments(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setArguments(arguments); n.setExpression(expression); n.setTypeArguments(typeArguments); @@ -419,7 +419,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final ExpressionStmt n, final A arg) { Expression expression = (Expression) n.getExpression().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (expression == null) return null; n.setExpression(expression); @@ -430,9 +430,9 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final FieldAccessExpr n, final A arg) { SimpleName name = (SimpleName) n.getName().accept(this, arg); - Expression scope = n.getScope().map( s -> (Expression) s.accept(this, arg)).orElse(null); + Expression scope = n.getScope().map(s -> (Expression) s.accept(this, arg)).orElse(null); NodeList<Type> typeArguments = modifyList(n.getTypeArguments(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setName(name); @@ -446,7 +446,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final FieldDeclaration n, final A arg) { NodeList<VariableDeclarator> variables = modifyList(n.getVariables(), arg); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (variables.isEmpty()) return null; n.setVariables(variables); @@ -460,7 +460,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { Statement body = (Statement) n.getBody().accept(this, arg); Expression iterable = (Expression) n.getIterable().accept(this, arg); VariableDeclarationExpr variable = (VariableDeclarationExpr) n.getVariable().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (body == null || iterable == null || variable == null) return null; n.setBody(body); @@ -473,10 +473,10 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final ForStmt n, final A arg) { Statement body = (Statement) n.getBody().accept(this, arg); - Expression compare = n.getCompare().map( s -> (Expression) s.accept(this, arg)).orElse(null); + Expression compare = n.getCompare().map(s -> (Expression) s.accept(this, arg)).orElse(null); NodeList<Expression> initialization = modifyList(n.getInitialization(), arg); NodeList<Expression> update = modifyList(n.getUpdate(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (body == null) return null; n.setBody(body); @@ -490,9 +490,9 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final IfStmt n, final A arg) { Expression condition = (Expression) n.getCondition().accept(this, arg); - Statement elseStmt = n.getElseStmt().map( s -> (Statement) s.accept(this, arg)).orElse(null); + Statement elseStmt = n.getElseStmt().map(s -> (Statement) s.accept(this, arg)).orElse(null); Statement thenStmt = (Statement) n.getThenStmt().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (condition == null || thenStmt == null) return null; n.setCondition(condition); @@ -506,7 +506,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final InitializerDeclaration n, final A arg) { BlockStmt body = (BlockStmt) n.getBody().accept(this, arg); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (body == null) return null; n.setBody(body); @@ -519,7 +519,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final InstanceOfExpr n, final A arg) { Expression expression = (Expression) n.getExpression().accept(this, arg); ReferenceType<?> type = (ReferenceType<?>) n.getType().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (expression == null || type == null) return null; n.setExpression(expression); @@ -530,14 +530,14 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final IntegerLiteralExpr n, final A arg) { - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setComment(comment); return n; } @Override public Visitable visit(final JavadocComment n, final A arg) { - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setComment(comment); return n; } @@ -546,7 +546,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final LabeledStmt n, final A arg) { SimpleName label = (SimpleName) n.getLabel().accept(this, arg); Statement statement = (Statement) n.getStatement().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (label == null || statement == null) return null; n.setLabel(label); @@ -557,7 +557,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final LongLiteralExpr n, final A arg) { - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setComment(comment); return n; } @@ -565,7 +565,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final MarkerAnnotationExpr n, final A arg) { Name name = (Name) n.getName().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setName(name); @@ -577,7 +577,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final MemberValuePair n, final A arg) { SimpleName name = (SimpleName) n.getName().accept(this, arg); Expression value = (Expression) n.getValue().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null || value == null) return null; n.setName(name); @@ -590,9 +590,9 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final MethodCallExpr n, final A arg) { NodeList<Expression> arguments = modifyList(n.getArguments(), arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); - Expression scope = n.getScope().map( s -> (Expression) s.accept(this, arg)).orElse(null); + Expression scope = n.getScope().map(s -> (Expression) s.accept(this, arg)).orElse(null); NodeList<Type> typeArguments = modifyList(n.getTypeArguments(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setArguments(arguments); @@ -605,14 +605,14 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final MethodDeclaration n, final A arg) { - BlockStmt body = n.getBody().map( s -> (BlockStmt) s.accept(this, arg)).orElse(null); + BlockStmt body = n.getBody().map(s -> (BlockStmt) s.accept(this, arg)).orElse(null); Type type = (Type) n.getType().accept(this, arg); SimpleName name = (SimpleName) n.getName().accept(this, arg); NodeList<Parameter> parameters = modifyList(n.getParameters(), arg); NodeList<ReferenceType> thrownExceptions = modifyList(n.getThrownExceptions(), arg); NodeList<TypeParameter> typeParameters = modifyList(n.getTypeParameters(), arg); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (type == null || name == null) return null; n.setBody(body); @@ -629,7 +629,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final NameExpr n, final A arg) { SimpleName name = (SimpleName) n.getName().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setName(name); @@ -641,7 +641,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final NormalAnnotationExpr n, final A arg) { NodeList<MemberValuePair> pairs = modifyList(n.getPairs(), arg); Name name = (Name) n.getName().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setPairs(pairs); @@ -652,7 +652,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final NullLiteralExpr n, final A arg) { - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setComment(comment); return n; } @@ -661,10 +661,10 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final ObjectCreationExpr n, final A arg) { NodeList<BodyDeclaration<?>> anonymousClassBody = modifyList(n.getAnonymousClassBody(), arg); NodeList<Expression> arguments = modifyList(n.getArguments(), arg); - Expression scope = n.getScope().map( s -> (Expression) s.accept(this, arg)).orElse(null); + Expression scope = n.getScope().map(s -> (Expression) s.accept(this, arg)).orElse(null); ClassOrInterfaceType type = (ClassOrInterfaceType) n.getType().accept(this, arg); NodeList<Type> typeArguments = modifyList(n.getTypeArguments(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (type == null) return null; n.setAnonymousClassBody(anonymousClassBody); @@ -680,7 +680,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final PackageDeclaration n, final A arg) { NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); Name name = (Name) n.getName().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setAnnotations(annotations); @@ -695,7 +695,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { SimpleName name = (SimpleName) n.getName().accept(this, arg); Type type = (Type) n.getType().accept(this, arg); NodeList<AnnotationExpr> varArgsAnnotations = modifyList(n.getVarArgsAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null || type == null) return null; n.setAnnotations(annotations); @@ -709,8 +709,8 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final Name n, final A arg) { NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Name qualifier = n.getQualifier().map( s -> (Name) s.accept(this, arg)).orElse(null); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Name qualifier = n.getQualifier().map(s -> (Name) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setAnnotations(annotations); n.setQualifier(qualifier); n.setComment(comment); @@ -720,7 +720,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final PrimitiveType n, final A arg) { NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setAnnotations(annotations); n.setComment(comment); return n; @@ -728,7 +728,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(SimpleName n, A arg) { - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setComment(comment); return n; } @@ -737,7 +737,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(ArrayType n, A arg) { Type componentType = (Type) n.getComponentType().accept(this, arg); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (componentType == null) return null; n.setComponentType(componentType); @@ -749,8 +749,8 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(ArrayCreationLevel n, A arg) { NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Expression dimension = n.getDimension().map( s -> (Expression) s.accept(this, arg)).orElse(null); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Expression dimension = n.getDimension().map(s -> (Expression) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setAnnotations(annotations); n.setDimension(dimension); n.setComment(comment); @@ -761,7 +761,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final IntersectionType n, final A arg) { NodeList<ReferenceType> elements = modifyList(n.getElements(), arg); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (elements.isEmpty()) return null; n.setElements(elements); @@ -774,7 +774,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final UnionType n, final A arg) { NodeList<ReferenceType> elements = modifyList(n.getElements(), arg); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (elements.isEmpty()) return null; n.setElements(elements); @@ -785,8 +785,8 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final ReturnStmt n, final A arg) { - Expression expression = n.getExpression().map( s -> (Expression) s.accept(this, arg)).orElse(null); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Expression expression = n.getExpression().map(s -> (Expression) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setExpression(expression); n.setComment(comment); return n; @@ -796,7 +796,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final SingleMemberAnnotationExpr n, final A arg) { Expression memberValue = (Expression) n.getMemberValue().accept(this, arg); Name name = (Name) n.getName().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (memberValue == null || name == null) return null; n.setMemberValue(memberValue); @@ -807,15 +807,15 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final StringLiteralExpr n, final A arg) { - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setComment(comment); return n; } @Override public Visitable visit(final SuperExpr n, final A arg) { - Expression classExpr = n.getClassExpr().map( s -> (Expression) s.accept(this, arg)).orElse(null); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Expression classExpr = n.getClassExpr().map(s -> (Expression) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setClassExpr(classExpr); n.setComment(comment); return n; @@ -823,9 +823,9 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final SwitchEntryStmt n, final A arg) { - Expression label = n.getLabel().map( s -> (Expression) s.accept(this, arg)).orElse(null); + Expression label = n.getLabel().map(s -> (Expression) s.accept(this, arg)).orElse(null); NodeList<Statement> statements = modifyList(n.getStatements(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setLabel(label); n.setStatements(statements); n.setComment(comment); @@ -836,7 +836,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final SwitchStmt n, final A arg) { NodeList<SwitchEntryStmt> entries = modifyList(n.getEntries(), arg); Expression selector = (Expression) n.getSelector().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (selector == null) return null; n.setEntries(entries); @@ -849,7 +849,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final SynchronizedStmt n, final A arg) { BlockStmt body = (BlockStmt) n.getBody().accept(this, arg); Expression expression = (Expression) n.getExpression().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (body == null || expression == null) return null; n.setBody(body); @@ -860,8 +860,8 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final ThisExpr n, final A arg) { - Expression classExpr = n.getClassExpr().map( s -> (Expression) s.accept(this, arg)).orElse(null); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Expression classExpr = n.getClassExpr().map(s -> (Expression) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setClassExpr(classExpr); n.setComment(comment); return n; @@ -870,7 +870,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final ThrowStmt n, final A arg) { Expression expression = (Expression) n.getExpression().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (expression == null) return null; n.setExpression(expression); @@ -881,10 +881,10 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final TryStmt n, final A arg) { NodeList<CatchClause> catchClauses = modifyList(n.getCatchClauses(), arg); - BlockStmt finallyBlock = n.getFinallyBlock().map( s -> (BlockStmt) s.accept(this, arg)).orElse(null); + BlockStmt finallyBlock = n.getFinallyBlock().map(s -> (BlockStmt) s.accept(this, arg)).orElse(null); NodeList<VariableDeclarationExpr> resources = modifyList(n.getResources(), arg); - BlockStmt tryBlock = n.getTryBlock().map( s -> (BlockStmt) s.accept(this, arg)).orElse(null); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + BlockStmt tryBlock = n.getTryBlock().map(s -> (BlockStmt) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setCatchClauses(catchClauses); n.setFinallyBlock(finallyBlock); n.setResources(resources); @@ -896,7 +896,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final LocalClassDeclarationStmt n, final A arg) { ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) n.getClassDeclaration().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (classDeclaration == null) return null; n.setClassDeclaration(classDeclaration); @@ -909,7 +909,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { SimpleName name = (SimpleName) n.getName().accept(this, arg); NodeList<ClassOrInterfaceType> typeBound = modifyList(n.getTypeBound(), arg); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setName(name); @@ -922,7 +922,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final UnaryExpr n, final A arg) { Expression expression = (Expression) n.getExpression().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (expression == null) return null; n.setExpression(expression); @@ -933,7 +933,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final UnknownType n, final A arg) { NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setAnnotations(annotations); n.setComment(comment); return n; @@ -943,7 +943,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final VariableDeclarationExpr n, final A arg) { NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); NodeList<VariableDeclarator> variables = modifyList(n.getVariables(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (variables.isEmpty()) return null; n.setAnnotations(annotations); @@ -954,10 +954,10 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final VariableDeclarator n, final A arg) { - Expression initializer = n.getInitializer().map( s -> (Expression) s.accept(this, arg)).orElse(null); + Expression initializer = n.getInitializer().map(s -> (Expression) s.accept(this, arg)).orElse(null); SimpleName name = (SimpleName) n.getName().accept(this, arg); Type type = (Type) n.getType().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null || type == null) return null; n.setInitializer(initializer); @@ -970,7 +970,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final VoidType n, final A arg) { NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setAnnotations(annotations); n.setComment(comment); return n; @@ -980,7 +980,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final WhileStmt n, final A arg) { Statement body = (Statement) n.getBody().accept(this, arg); Expression condition = (Expression) n.getCondition().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (body == null || condition == null) return null; n.setBody(body); @@ -991,10 +991,10 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final WildcardType n, final A arg) { - ReferenceType extendedType = n.getExtendedType().map( s -> (ReferenceType) s.accept(this, arg)).orElse(null); - ReferenceType superType = n.getSuperType().map( s -> (ReferenceType) s.accept(this, arg)).orElse(null); + ReferenceType extendedType = n.getExtendedType().map(s -> (ReferenceType) s.accept(this, arg)).orElse(null); + ReferenceType superType = n.getSuperType().map(s -> (ReferenceType) s.accept(this, arg)).orElse(null); NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setExtendedType(extendedType); n.setSuperType(superType); n.setAnnotations(annotations); @@ -1006,7 +1006,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final LambdaExpr n, final A arg) { Statement body = (Statement) n.getBody().accept(this, arg); NodeList<Parameter> parameters = modifyList(n.getParameters(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (body == null) return null; n.setBody(body); @@ -1019,7 +1019,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(final MethodReferenceExpr n, final A arg) { Expression scope = (Expression) n.getScope().accept(this, arg); NodeList<Type> typeArguments = modifyList(n.getTypeArguments(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (scope == null) return null; n.setScope(scope); @@ -1031,7 +1031,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final TypeExpr n, final A arg) { Type type = (Type) n.getType().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (type == null) return null; n.setType(type); @@ -1067,7 +1067,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Node visit(final ImportDeclaration n, final A arg) { Name name = (Name) n.getName().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setName(name); @@ -1077,14 +1077,14 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override public Visitable visit(final BlockComment n, final A arg) { - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setComment(comment); return n; } @Override public Visitable visit(final LineComment n, final A arg) { - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); n.setComment(comment); return n; } @@ -1094,14 +1094,14 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { } private <N extends Node> NodeList<N> modifyList(Optional<NodeList<N>> list, A arg) { - return list.map( ns -> modifyList(ns, arg)).orElse(null); + return list.map(ns -> modifyList(ns, arg)).orElse(null); } public Visitable visit(ModuleDeclaration n, A arg) { NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg); NodeList<ModuleStmt> moduleStmts = modifyList(n.getModuleStmts(), arg); Name name = (Name) n.getName().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setAnnotations(annotations); @@ -1113,7 +1113,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(ModuleRequiresStmt n, A arg) { Name name = (Name) n.getName().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setName(name); @@ -1125,7 +1125,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(ModuleExportsStmt n, A arg) { NodeList<Name> moduleNames = modifyList(n.getModuleNames(), arg); Name name = (Name) n.getName().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setModuleNames(moduleNames); @@ -1138,7 +1138,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(ModuleProvidesStmt n, A arg) { Type type = (Type) n.getType().accept(this, arg); NodeList<Type> withTypes = modifyList(n.getWithTypes(), arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (type == null) return null; n.setType(type); @@ -1150,7 +1150,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { @Override() public Visitable visit(ModuleUsesStmt n, A arg) { Type type = (Type) n.getType().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (type == null) return null; n.setType(type); @@ -1162,7 +1162,7 @@ public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> { public Visitable visit(ModuleOpensStmt n, A arg) { NodeList<Name> moduleNames = modifyList(n.getModuleNames(), arg); Name name = (Name) n.getName().accept(this, arg); - Comment comment = n.getComment().map( s -> (Comment) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (name == null) return null; n.setModuleNames(moduleNames); diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/TreeStructureVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/TreeStructureVisitor.java index 1bc7a7cd1..1f940fe83 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/TreeStructureVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/TreeStructureVisitor.java @@ -68,7 +68,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { @Override public void visit(NodeList n, Integer arg) { - ((NodeList<Node>) n).forEach( x -> x.accept(this, arg)); + ((NodeList<Node>) n).forEach(x -> x.accept(this, arg)); } public void visit(AnnotationDeclaration n, Integer arg) { @@ -77,18 +77,18 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { n.getMembers().accept(this, arg + 1); n.getName().accept(this, arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(AnnotationMemberDeclaration n, Integer arg) { enterNode(n, arg); outputProperty(n, "modifiers", n.getModifiers(), arg + 1); - n.getDefaultValue().ifPresent( c -> c.accept(this, arg + 1)); + n.getDefaultValue().ifPresent(c -> c.accept(this, arg + 1)); n.getName().accept(this, arg + 1); n.getType().accept(this, arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -96,31 +96,31 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getIndex().accept(this, arg + 1); n.getName().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(ArrayCreationExpr n, Integer arg) { enterNode(n, arg); n.getElementType().accept(this, arg + 1); - n.getInitializer().ifPresent( c -> c.accept(this, arg + 1)); + n.getInitializer().ifPresent(c -> c.accept(this, arg + 1)); n.getLevels().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(ArrayCreationLevel n, Integer arg) { enterNode(n, arg); n.getAnnotations().accept(this, arg + 1); - n.getDimension().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getDimension().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(ArrayInitializerExpr n, Integer arg) { enterNode(n, arg); n.getValues().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -128,15 +128,15 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getComponentType().accept(this, arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(AssertStmt n, Integer arg) { enterNode(n, arg); n.getCheck().accept(this, arg + 1); - n.getMessage().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getMessage().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -145,7 +145,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { outputProperty(n, "operator", n.getOperator(), arg + 1); n.getTarget().accept(this, arg + 1); n.getValue().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -154,35 +154,35 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { outputProperty(n, "operator", n.getOperator(), arg + 1); n.getLeft().accept(this, arg + 1); n.getRight().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(BlockComment n, Integer arg) { enterNode(n, arg); outputProperty(n, "content", n.getContent(), arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(BlockStmt n, Integer arg) { enterNode(n, arg); n.getStatements().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(BooleanLiteralExpr n, Integer arg) { enterNode(n, arg); outputProperty(n, "value", n.getValue(), arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(BreakStmt n, Integer arg) { enterNode(n, arg); - n.getLabel().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getLabel().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -190,7 +190,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getExpression().accept(this, arg + 1); n.getType().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -198,21 +198,21 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getBody().accept(this, arg + 1); n.getParameter().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(CharLiteralExpr n, Integer arg) { enterNode(n, arg); outputProperty(n, "value", n.getValue(), arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(ClassExpr n, Integer arg) { enterNode(n, arg); n.getType().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -226,27 +226,27 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { n.getMembers().accept(this, arg + 1); n.getName().accept(this, arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(ClassOrInterfaceType n, Integer arg) { enterNode(n, arg); n.getName().accept(this, arg + 1); - n.getScope().ifPresent( c -> c.accept(this, arg + 1)); - n.getTypeArguments().ifPresent( c -> c.accept(this, arg + 1)); + n.getScope().ifPresent(c -> c.accept(this, arg + 1)); + n.getTypeArguments().ifPresent(c -> c.accept(this, arg + 1)); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(CompilationUnit n, Integer arg) { enterNode(n, arg); n.getImports().accept(this, arg + 1); - n.getModule().ifPresent( c -> c.accept(this, arg + 1)); - n.getPackageDeclaration().ifPresent( c -> c.accept(this, arg + 1)); + n.getModule().ifPresent(c -> c.accept(this, arg + 1)); + n.getPackageDeclaration().ifPresent(c -> c.accept(this, arg + 1)); n.getTypes().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -255,7 +255,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { n.getCondition().accept(this, arg + 1); n.getElseExpr().accept(this, arg + 1); n.getThenExpr().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -268,14 +268,14 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { n.getThrownExceptions().accept(this, arg + 1); n.getTypeParameters().accept(this, arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(ContinueStmt n, Integer arg) { enterNode(n, arg); - n.getLabel().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getLabel().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -283,34 +283,34 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getBody().accept(this, arg + 1); n.getCondition().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(DoubleLiteralExpr n, Integer arg) { enterNode(n, arg); outputProperty(n, "value", n.getValue(), arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(EmptyMemberDeclaration n, Integer arg) { enterNode(n, arg); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(EmptyStmt n, Integer arg) { enterNode(n, arg); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(EnclosedExpr n, Integer arg) { enterNode(n, arg); - n.getInner().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getInner().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -320,7 +320,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { n.getClassBody().accept(this, arg + 1); n.getName().accept(this, arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -332,7 +332,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { n.getMembers().accept(this, arg + 1); n.getName().accept(this, arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -340,25 +340,25 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); outputProperty(n, "isThis", n.isThis(), arg + 1); n.getArguments().accept(this, arg + 1); - n.getExpression().ifPresent( c -> c.accept(this, arg + 1)); - n.getTypeArguments().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getExpression().ifPresent(c -> c.accept(this, arg + 1)); + n.getTypeArguments().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(ExpressionStmt n, Integer arg) { enterNode(n, arg); n.getExpression().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(FieldAccessExpr n, Integer arg) { enterNode(n, arg); n.getName().accept(this, arg + 1); - n.getScope().ifPresent( c -> c.accept(this, arg + 1)); - n.getTypeArguments().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getScope().ifPresent(c -> c.accept(this, arg + 1)); + n.getTypeArguments().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -367,17 +367,17 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { outputProperty(n, "modifiers", n.getModifiers(), arg + 1); n.getVariables().accept(this, arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(ForStmt n, Integer arg) { enterNode(n, arg); n.getBody().accept(this, arg + 1); - n.getCompare().ifPresent( c -> c.accept(this, arg + 1)); + n.getCompare().ifPresent(c -> c.accept(this, arg + 1)); n.getInitialization().accept(this, arg + 1); n.getUpdate().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -386,16 +386,16 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { n.getBody().accept(this, arg + 1); n.getIterable().accept(this, arg + 1); n.getVariable().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(IfStmt n, Integer arg) { enterNode(n, arg); n.getCondition().accept(this, arg + 1); - n.getElseStmt().ifPresent( c -> c.accept(this, arg + 1)); + n.getElseStmt().ifPresent(c -> c.accept(this, arg + 1)); n.getThenStmt().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -404,7 +404,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { outputProperty(n, "isAsterisk", n.isAsterisk(), arg + 1); outputProperty(n, "isStatic", n.isStatic(), arg + 1); n.getName().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -413,7 +413,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { outputProperty(n, "isStatic", n.isStatic(), arg + 1); n.getBody().accept(this, arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -421,14 +421,14 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getExpression().accept(this, arg + 1); n.getType().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(IntegerLiteralExpr n, Integer arg) { enterNode(n, arg); outputProperty(n, "value", n.getValue(), arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -436,14 +436,14 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getElements().accept(this, arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(JavadocComment n, Integer arg) { enterNode(n, arg); outputProperty(n, "content", n.getContent(), arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -451,7 +451,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getLabel().accept(this, arg + 1); n.getStatement().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -460,35 +460,35 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { outputProperty(n, "isEnclosingParameters", n.isEnclosingParameters(), arg + 1); n.getBody().accept(this, arg + 1); n.getParameters().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(LineComment n, Integer arg) { enterNode(n, arg); outputProperty(n, "content", n.getContent(), arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(LocalClassDeclarationStmt n, Integer arg) { enterNode(n, arg); n.getClassDeclaration().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(LongLiteralExpr n, Integer arg) { enterNode(n, arg); outputProperty(n, "value", n.getValue(), arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(MarkerAnnotationExpr n, Integer arg) { enterNode(n, arg); n.getName().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -496,7 +496,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getName().accept(this, arg + 1); n.getValue().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -504,9 +504,9 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getArguments().accept(this, arg + 1); n.getName().accept(this, arg + 1); - n.getScope().ifPresent( c -> c.accept(this, arg + 1)); - n.getTypeArguments().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getScope().ifPresent(c -> c.accept(this, arg + 1)); + n.getTypeArguments().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -514,14 +514,14 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); outputProperty(n, "isDefault", n.isDefault(), arg + 1); outputProperty(n, "modifiers", n.getModifiers(), arg + 1); - n.getBody().ifPresent( c -> c.accept(this, arg + 1)); + n.getBody().ifPresent(c -> c.accept(this, arg + 1)); n.getType().accept(this, arg + 1); n.getName().accept(this, arg + 1); n.getParameters().accept(this, arg + 1); n.getThrownExceptions().accept(this, arg + 1); n.getTypeParameters().accept(this, arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -529,15 +529,15 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); outputProperty(n, "identifier", n.getIdentifier(), arg + 1); n.getScope().accept(this, arg + 1); - n.getTypeArguments().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getTypeArguments().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(NameExpr n, Integer arg) { enterNode(n, arg); n.getName().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -545,8 +545,8 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); outputProperty(n, "identifier", n.getIdentifier(), arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getQualifier().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getQualifier().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -554,24 +554,24 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getPairs().accept(this, arg + 1); n.getName().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(NullLiteralExpr n, Integer arg) { enterNode(n, arg); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(ObjectCreationExpr n, Integer arg) { enterNode(n, arg); - n.getAnonymousClassBody().ifPresent( c -> c.accept(this, arg + 1)); + n.getAnonymousClassBody().ifPresent(c -> c.accept(this, arg + 1)); n.getArguments().accept(this, arg + 1); - n.getScope().ifPresent( c -> c.accept(this, arg + 1)); + n.getScope().ifPresent(c -> c.accept(this, arg + 1)); n.getType().accept(this, arg + 1); - n.getTypeArguments().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getTypeArguments().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -579,7 +579,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getAnnotations().accept(this, arg + 1); n.getName().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -591,7 +591,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { n.getName().accept(this, arg + 1); n.getType().accept(this, arg + 1); n.getVarArgsAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -599,21 +599,21 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); outputProperty(n, "type", n.getType(), arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(ReturnStmt n, Integer arg) { enterNode(n, arg); - n.getExpression().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getExpression().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(SimpleName n, Integer arg) { enterNode(n, arg); outputProperty(n, "identifier", n.getIdentifier(), arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -621,29 +621,29 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getMemberValue().accept(this, arg + 1); n.getName().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(StringLiteralExpr n, Integer arg) { enterNode(n, arg); outputProperty(n, "value", n.getValue(), arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(SuperExpr n, Integer arg) { enterNode(n, arg); - n.getClassExpr().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getClassExpr().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(SwitchEntryStmt n, Integer arg) { enterNode(n, arg); - n.getLabel().ifPresent( c -> c.accept(this, arg + 1)); + n.getLabel().ifPresent(c -> c.accept(this, arg + 1)); n.getStatements().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -651,7 +651,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getEntries().accept(this, arg + 1); n.getSelector().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -659,38 +659,38 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getBody().accept(this, arg + 1); n.getExpression().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(ThisExpr n, Integer arg) { enterNode(n, arg); - n.getClassExpr().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getClassExpr().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(ThrowStmt n, Integer arg) { enterNode(n, arg); n.getExpression().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(TryStmt n, Integer arg) { enterNode(n, arg); n.getCatchClauses().accept(this, arg + 1); - n.getFinallyBlock().ifPresent( c -> c.accept(this, arg + 1)); + n.getFinallyBlock().ifPresent(c -> c.accept(this, arg + 1)); n.getResources().accept(this, arg + 1); - n.getTryBlock().ifPresent( c -> c.accept(this, arg + 1)); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getTryBlock().ifPresent(c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(TypeExpr n, Integer arg) { enterNode(n, arg); n.getType().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -699,7 +699,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { n.getName().accept(this, arg + 1); n.getTypeBound().accept(this, arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -707,7 +707,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); outputProperty(n, "operator", n.getOperator(), arg + 1); n.getExpression().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -715,14 +715,14 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getElements().accept(this, arg + 1); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(UnknownType n, Integer arg) { enterNode(n, arg); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -731,23 +731,23 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { outputProperty(n, "modifiers", n.getModifiers(), arg + 1); n.getAnnotations().accept(this, arg + 1); n.getVariables().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(VariableDeclarator n, Integer arg) { enterNode(n, arg); - n.getInitializer().ifPresent( c -> c.accept(this, arg + 1)); + n.getInitializer().ifPresent(c -> c.accept(this, arg + 1)); n.getName().accept(this, arg + 1); n.getType().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(VoidType n, Integer arg) { enterNode(n, arg); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -755,16 +755,16 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getBody().accept(this, arg + 1); n.getCondition().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } public void visit(WildcardType n, Integer arg) { enterNode(n, arg); - n.getExtendedType().ifPresent( c -> c.accept(this, arg + 1)); - n.getSuperType().ifPresent( c -> c.accept(this, arg + 1)); + n.getExtendedType().ifPresent(c -> c.accept(this, arg + 1)); + n.getSuperType().ifPresent(c -> c.accept(this, arg + 1)); n.getAnnotations().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -774,7 +774,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { n.getAnnotations().accept(this, arg + 1); n.getModuleStmts().accept(this, arg + 1); n.getName().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -782,7 +782,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); outputProperty(n, "modifiers", n.getModifiers(), arg + 1); n.getName().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -791,7 +791,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getModuleNames().accept(this, arg + 1); n.getName().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -800,7 +800,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getType().accept(this, arg + 1); n.getWithTypes().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -808,7 +808,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { public void visit(ModuleUsesStmt n, Integer arg) { enterNode(n, arg); n.getType().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } @@ -817,7 +817,7 @@ public class TreeStructureVisitor extends VoidVisitorAdapter<Integer> { enterNode(n, arg); n.getModuleNames().accept(this, arg + 1); n.getName().accept(this, arg + 1); - n.getComment().ifPresent( c -> c.accept(this, arg + 1)); + n.getComment().ifPresent(c -> c.accept(this, arg + 1)); exitNode(n, arg); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java index 9fa8b52a9..290f57598 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java @@ -38,137 +38,137 @@ public abstract class VoidVisitorAdapter<A> implements VoidVisitor<A> { @Override public void visit(final AnnotationDeclaration n, final A arg) { - n.getMembers().forEach( p -> p.accept(this, arg)); + n.getMembers().forEach(p -> p.accept(this, arg)); n.getName().accept(this, arg); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final AnnotationMemberDeclaration n, final A arg) { - n.getDefaultValue().ifPresent( l -> l.accept(this, arg)); + n.getDefaultValue().ifPresent(l -> l.accept(this, arg)); n.getName().accept(this, arg); n.getType().accept(this, arg); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ArrayAccessExpr n, final A arg) { n.getIndex().accept(this, arg); n.getName().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ArrayCreationExpr n, final A arg) { n.getElementType().accept(this, arg); - n.getInitializer().ifPresent( l -> l.accept(this, arg)); - n.getLevels().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getInitializer().ifPresent(l -> l.accept(this, arg)); + n.getLevels().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ArrayInitializerExpr n, final A arg) { - n.getValues().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getValues().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final AssertStmt n, final A arg) { n.getCheck().accept(this, arg); - n.getMessage().ifPresent( l -> l.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getMessage().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final AssignExpr n, final A arg) { n.getTarget().accept(this, arg); n.getValue().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final BinaryExpr n, final A arg) { n.getLeft().accept(this, arg); n.getRight().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final BlockComment n, final A arg) { - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final BlockStmt n, final A arg) { - n.getStatements().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getStatements().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final BooleanLiteralExpr n, final A arg) { - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final BreakStmt n, final A arg) { - n.getLabel().ifPresent( l -> l.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getLabel().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final CastExpr n, final A arg) { n.getExpression().accept(this, arg); n.getType().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final CatchClause n, final A arg) { n.getBody().accept(this, arg); n.getParameter().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final CharLiteralExpr n, final A arg) { - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ClassExpr n, final A arg) { n.getType().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ClassOrInterfaceDeclaration n, final A arg) { - n.getExtendedTypes().forEach( p -> p.accept(this, arg)); - n.getImplementedTypes().forEach( p -> p.accept(this, arg)); - n.getTypeParameters().forEach( p -> p.accept(this, arg)); - n.getMembers().forEach( p -> p.accept(this, arg)); + n.getExtendedTypes().forEach(p -> p.accept(this, arg)); + n.getImplementedTypes().forEach(p -> p.accept(this, arg)); + n.getTypeParameters().forEach(p -> p.accept(this, arg)); + n.getMembers().forEach(p -> p.accept(this, arg)); n.getName().accept(this, arg); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ClassOrInterfaceType n, final A arg) { n.getName().accept(this, arg); - n.getScope().ifPresent( l -> l.accept(this, arg)); - n.getTypeArguments().ifPresent( l -> l.forEach( v -> v.accept(this, arg))); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getScope().ifPresent(l -> l.accept(this, arg)); + n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg))); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final CompilationUnit n, final A arg) { - n.getImports().forEach( p -> p.accept(this, arg)); - n.getModule().ifPresent( l -> l.accept(this, arg)); - n.getPackageDeclaration().ifPresent( l -> l.accept(this, arg)); - n.getTypes().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getImports().forEach(p -> p.accept(this, arg)); + n.getModule().ifPresent(l -> l.accept(this, arg)); + n.getPackageDeclaration().ifPresent(l -> l.accept(this, arg)); + n.getTypes().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override @@ -176,101 +176,101 @@ public abstract class VoidVisitorAdapter<A> implements VoidVisitor<A> { n.getCondition().accept(this, arg); n.getElseExpr().accept(this, arg); n.getThenExpr().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ConstructorDeclaration n, final A arg) { n.getBody().accept(this, arg); n.getName().accept(this, arg); - n.getParameters().forEach( p -> p.accept(this, arg)); - n.getThrownExceptions().forEach( p -> p.accept(this, arg)); - n.getTypeParameters().forEach( p -> p.accept(this, arg)); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getParameters().forEach(p -> p.accept(this, arg)); + n.getThrownExceptions().forEach(p -> p.accept(this, arg)); + n.getTypeParameters().forEach(p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ContinueStmt n, final A arg) { - n.getLabel().ifPresent( l -> l.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getLabel().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final DoStmt n, final A arg) { n.getBody().accept(this, arg); n.getCondition().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final DoubleLiteralExpr n, final A arg) { - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final EmptyMemberDeclaration n, final A arg) { - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final EmptyStmt n, final A arg) { - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final EnclosedExpr n, final A arg) { - n.getInner().ifPresent( l -> l.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getInner().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final EnumConstantDeclaration n, final A arg) { - n.getArguments().forEach( p -> p.accept(this, arg)); - n.getClassBody().forEach( p -> p.accept(this, arg)); + n.getArguments().forEach(p -> p.accept(this, arg)); + n.getClassBody().forEach(p -> p.accept(this, arg)); n.getName().accept(this, arg); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final EnumDeclaration n, final A arg) { - n.getEntries().forEach( p -> p.accept(this, arg)); - n.getImplementedTypes().forEach( p -> p.accept(this, arg)); - n.getMembers().forEach( p -> p.accept(this, arg)); + n.getEntries().forEach(p -> p.accept(this, arg)); + n.getImplementedTypes().forEach(p -> p.accept(this, arg)); + n.getMembers().forEach(p -> p.accept(this, arg)); n.getName().accept(this, arg); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ExplicitConstructorInvocationStmt n, final A arg) { - n.getArguments().forEach( p -> p.accept(this, arg)); - n.getExpression().ifPresent( l -> l.accept(this, arg)); - n.getTypeArguments().ifPresent( l -> l.forEach( v -> v.accept(this, arg))); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getArguments().forEach(p -> p.accept(this, arg)); + n.getExpression().ifPresent(l -> l.accept(this, arg)); + n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg))); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ExpressionStmt n, final A arg) { n.getExpression().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final FieldAccessExpr n, final A arg) { n.getName().accept(this, arg); - n.getScope().ifPresent( l -> l.accept(this, arg)); - n.getTypeArguments().ifPresent( l -> l.forEach( v -> v.accept(this, arg))); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getScope().ifPresent(l -> l.accept(this, arg)); + n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg))); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final FieldDeclaration n, final A arg) { - n.getVariables().forEach( p -> p.accept(this, arg)); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getVariables().forEach(p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override @@ -278,337 +278,337 @@ public abstract class VoidVisitorAdapter<A> implements VoidVisitor<A> { n.getBody().accept(this, arg); n.getIterable().accept(this, arg); n.getVariable().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ForStmt n, final A arg) { n.getBody().accept(this, arg); - n.getCompare().ifPresent( l -> l.accept(this, arg)); - n.getInitialization().forEach( p -> p.accept(this, arg)); - n.getUpdate().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getCompare().ifPresent(l -> l.accept(this, arg)); + n.getInitialization().forEach(p -> p.accept(this, arg)); + n.getUpdate().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final IfStmt n, final A arg) { n.getCondition().accept(this, arg); - n.getElseStmt().ifPresent( l -> l.accept(this, arg)); + n.getElseStmt().ifPresent(l -> l.accept(this, arg)); n.getThenStmt().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final InitializerDeclaration n, final A arg) { n.getBody().accept(this, arg); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final InstanceOfExpr n, final A arg) { n.getExpression().accept(this, arg); n.getType().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final IntegerLiteralExpr n, final A arg) { - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final JavadocComment n, final A arg) { - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final LabeledStmt n, final A arg) { n.getLabel().accept(this, arg); n.getStatement().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final LineComment n, final A arg) { - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final LongLiteralExpr n, final A arg) { - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final MarkerAnnotationExpr n, final A arg) { n.getName().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final MemberValuePair n, final A arg) { n.getName().accept(this, arg); n.getValue().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final MethodCallExpr n, final A arg) { - n.getArguments().forEach( p -> p.accept(this, arg)); + n.getArguments().forEach(p -> p.accept(this, arg)); n.getName().accept(this, arg); - n.getScope().ifPresent( l -> l.accept(this, arg)); - n.getTypeArguments().ifPresent( l -> l.forEach( v -> v.accept(this, arg))); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getScope().ifPresent(l -> l.accept(this, arg)); + n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg))); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final MethodDeclaration n, final A arg) { - n.getBody().ifPresent( l -> l.accept(this, arg)); + n.getBody().ifPresent(l -> l.accept(this, arg)); n.getType().accept(this, arg); n.getName().accept(this, arg); - n.getParameters().forEach( p -> p.accept(this, arg)); - n.getThrownExceptions().forEach( p -> p.accept(this, arg)); - n.getTypeParameters().forEach( p -> p.accept(this, arg)); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getParameters().forEach(p -> p.accept(this, arg)); + n.getThrownExceptions().forEach(p -> p.accept(this, arg)); + n.getTypeParameters().forEach(p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final NameExpr n, final A arg) { n.getName().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final NormalAnnotationExpr n, final A arg) { - n.getPairs().forEach( p -> p.accept(this, arg)); + n.getPairs().forEach(p -> p.accept(this, arg)); n.getName().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final NullLiteralExpr n, final A arg) { - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ObjectCreationExpr n, final A arg) { - n.getAnonymousClassBody().ifPresent( l -> l.forEach( v -> v.accept(this, arg))); - n.getArguments().forEach( p -> p.accept(this, arg)); - n.getScope().ifPresent( l -> l.accept(this, arg)); + n.getAnonymousClassBody().ifPresent(l -> l.forEach(v -> v.accept(this, arg))); + n.getArguments().forEach(p -> p.accept(this, arg)); + n.getScope().ifPresent(l -> l.accept(this, arg)); n.getType().accept(this, arg); - n.getTypeArguments().ifPresent( l -> l.forEach( v -> v.accept(this, arg))); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg))); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final PackageDeclaration n, final A arg) { - n.getAnnotations().forEach( p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); n.getName().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final Parameter n, final A arg) { - n.getAnnotations().forEach( p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); n.getName().accept(this, arg); n.getType().accept(this, arg); - n.getVarArgsAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getVarArgsAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final PrimitiveType n, final A arg) { - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final Name n, final A arg) { - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getQualifier().ifPresent( l -> l.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getQualifier().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(SimpleName n, A arg) { - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(ArrayType n, A arg) { n.getComponentType().accept(this, arg); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(ArrayCreationLevel n, A arg) { - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getDimension().ifPresent( l -> l.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getDimension().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final IntersectionType n, final A arg) { - n.getElements().forEach( p -> p.accept(this, arg)); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getElements().forEach(p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final UnionType n, final A arg) { - n.getElements().forEach( p -> p.accept(this, arg)); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getElements().forEach(p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ReturnStmt n, final A arg) { - n.getExpression().ifPresent( l -> l.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getExpression().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final SingleMemberAnnotationExpr n, final A arg) { n.getMemberValue().accept(this, arg); n.getName().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final StringLiteralExpr n, final A arg) { - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final SuperExpr n, final A arg) { - n.getClassExpr().ifPresent( l -> l.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getClassExpr().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final SwitchEntryStmt n, final A arg) { - n.getLabel().ifPresent( l -> l.accept(this, arg)); - n.getStatements().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getLabel().ifPresent(l -> l.accept(this, arg)); + n.getStatements().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final SwitchStmt n, final A arg) { - n.getEntries().forEach( p -> p.accept(this, arg)); + n.getEntries().forEach(p -> p.accept(this, arg)); n.getSelector().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final SynchronizedStmt n, final A arg) { n.getBody().accept(this, arg); n.getExpression().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ThisExpr n, final A arg) { - n.getClassExpr().ifPresent( l -> l.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getClassExpr().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final ThrowStmt n, final A arg) { n.getExpression().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final TryStmt n, final A arg) { - n.getCatchClauses().forEach( p -> p.accept(this, arg)); - n.getFinallyBlock().ifPresent( l -> l.accept(this, arg)); - n.getResources().forEach( p -> p.accept(this, arg)); - n.getTryBlock().ifPresent( l -> l.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getCatchClauses().forEach(p -> p.accept(this, arg)); + n.getFinallyBlock().ifPresent(l -> l.accept(this, arg)); + n.getResources().forEach(p -> p.accept(this, arg)); + n.getTryBlock().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final LocalClassDeclarationStmt n, final A arg) { n.getClassDeclaration().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final TypeParameter n, final A arg) { n.getName().accept(this, arg); - n.getTypeBound().forEach( p -> p.accept(this, arg)); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getTypeBound().forEach(p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final UnaryExpr n, final A arg) { n.getExpression().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final UnknownType n, final A arg) { - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final VariableDeclarationExpr n, final A arg) { - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getVariables().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getVariables().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final VariableDeclarator n, final A arg) { - n.getInitializer().ifPresent( l -> l.accept(this, arg)); + n.getInitializer().ifPresent(l -> l.accept(this, arg)); n.getName().accept(this, arg); n.getType().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final VoidType n, final A arg) { - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final WhileStmt n, final A arg) { n.getBody().accept(this, arg); n.getCondition().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(final WildcardType n, final A arg) { - n.getExtendedType().ifPresent( l -> l.accept(this, arg)); - n.getSuperType().ifPresent( l -> l.accept(this, arg)); - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getExtendedType().ifPresent(l -> l.accept(this, arg)); + n.getSuperType().ifPresent(l -> l.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(LambdaExpr n, final A arg) { n.getBody().accept(this, arg); - n.getParameters().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getParameters().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(MethodReferenceExpr n, final A arg) { n.getScope().accept(this, arg); - n.getTypeArguments().ifPresent( l -> l.forEach( v -> v.accept(this, arg))); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg))); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(TypeExpr n, final A arg) { n.getType().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override @@ -621,46 +621,46 @@ public abstract class VoidVisitorAdapter<A> implements VoidVisitor<A> { @Override public void visit(final ImportDeclaration n, final A arg) { n.getName().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } public void visit(ModuleDeclaration n, A arg) { - n.getAnnotations().forEach( p -> p.accept(this, arg)); - n.getModuleStmts().forEach( p -> p.accept(this, arg)); + n.getAnnotations().forEach(p -> p.accept(this, arg)); + n.getModuleStmts().forEach(p -> p.accept(this, arg)); n.getName().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } public void visit(ModuleRequiresStmt n, A arg) { n.getName().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(ModuleExportsStmt n, A arg) { - n.getModuleNames().forEach( p -> p.accept(this, arg)); + n.getModuleNames().forEach(p -> p.accept(this, arg)); n.getName().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(ModuleProvidesStmt n, A arg) { n.getType().accept(this, arg); - n.getWithTypes().forEach( p -> p.accept(this, arg)); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getWithTypes().forEach(p -> p.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(ModuleUsesStmt n, A arg) { n.getType().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } @Override public void visit(ModuleOpensStmt n, A arg) { - n.getModuleNames().forEach( p -> p.accept(this, arg)); + n.getModuleNames().forEach(p -> p.accept(this, arg)); n.getName().accept(this, arg); - n.getComment().ifPresent( l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/TokenConstants.java b/javaparser-core/src/main/java/com/github/javaparser/printer/TokenConstants.java deleted file mode 100644 index 58a304a21..000000000 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/TokenConstants.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.javaparser.printer; - -import com.github.javaparser.GeneratedJavaParserConstants; - -/** - * It complements GeneratedJavaParserConstants - */ -public class TokenConstants { - public static int EOF_TOKEN = 0; - public static int SPACE_TOKEN = 1; - public static int TAB_TOKEN = 2; - public static int NEWLINE_TOKEN = 3; - - public static boolean isWhitespace(int tokenType) { - return tokenType == EOF_TOKEN - || tokenType == NEWLINE_TOKEN - || tokenType == SPACE_TOKEN - || tokenType == TAB_TOKEN; - } - - public static boolean isWhitespaceOrComment(int tokenType) { - return isWhitespace(tokenType) || isComment(tokenType); - } - - public static boolean isSpaceOrTab(int tokenType) { - return tokenType == SPACE_TOKEN || tokenType == TAB_TOKEN; - } - - public static boolean isComment(int tokenType) { - return tokenType == GeneratedJavaParserConstants.SINGLE_LINE_COMMENT - || tokenType == GeneratedJavaParserConstants.MULTI_LINE_COMMENT - || tokenType == GeneratedJavaParserConstants.JAVA_DOC_COMMENT; - } -} diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java index fb993b5b2..1d5e25f34 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java @@ -28,6 +28,8 @@ import com.github.javaparser.printer.SourcePrinter; import java.util.Arrays; +import static com.github.javaparser.TokenTypes.eolToken; +import static com.github.javaparser.TokenTypes.spaceToken; import static com.github.javaparser.utils.Utils.EOL; @@ -80,7 +82,7 @@ public interface CsmElement { } static CsmElement space() { - return new CsmToken(1, " "); + return new CsmToken(spaceToken(), " "); } static CsmElement semicolon() { @@ -90,7 +92,7 @@ public interface CsmElement { static CsmElement comment() { return new CsmComment(); } static CsmElement newline() { - return new CsmToken(3, EOL); + return new CsmToken(eolToken(), EOL); } static CsmElement none() { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java index bbd955662..0aff276f0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java @@ -24,20 +24,18 @@ package com.github.javaparser.printer.concretesyntaxmodel; import com.github.javaparser.GeneratedJavaParserConstants; import com.github.javaparser.ast.Node; import com.github.javaparser.printer.SourcePrinter; +import com.github.javaparser.TokenTypes; import com.github.javaparser.utils.Utils; +import static com.github.javaparser.TokenTypes.isEndOfLineCharacter; +import static com.github.javaparser.TokenTypes.isSpaceOrTab; + public class CsmToken implements CsmElement { private int tokenType; private String content; private TokenContentCalculator tokenContentCalculator; - public static int NEWLINE_TOKEN = 3; - public static int SPACE_TOKEN = 1; - public static int SPACE_TOKEN_ALT = 32; - public static int TAB_TOKEN = 2; - public static int EOF_TOKEN = 0; - public interface TokenContentCalculator { String calculate(Node node); } @@ -59,9 +57,9 @@ public class CsmToken implements CsmElement { if (content.startsWith("\"")) { content = content.substring(1, content.length() - 1); } - if (tokenType == NEWLINE_TOKEN) { + if (isEndOfLineCharacter(tokenType)) { content = Utils.EOL; - } else if (tokenType == SPACE_TOKEN) { + } else if (isSpaceOrTab(tokenType)) { content = " "; } } @@ -78,7 +76,7 @@ public class CsmToken implements CsmElement { @Override public void prettyPrint(Node node, SourcePrinter printer) { - if (tokenType == 3) { + if (isEndOfLineCharacter(tokenType)) { printer.println(); } else { printer.print(getContent(node)); @@ -111,7 +109,6 @@ public class CsmToken implements CsmElement { } public boolean isWhiteSpace() { - return tokenType == NEWLINE_TOKEN || tokenType == SPACE_TOKEN || tokenType == EOF_TOKEN - || tokenType == TAB_TOKEN || tokenType == SPACE_TOKEN_ALT; + return TokenTypes.isWhitespace(tokenType); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java index 27652833f..5eba4e214 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java @@ -1,18 +1,15 @@ package com.github.javaparser.printer.lexicalpreservation; -import com.github.javaparser.GeneratedJavaParserConstants; -import com.github.javaparser.GeneratedJavaParserConstants; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.type.PrimitiveType; -import com.github.javaparser.printer.TokenConstants; +import com.github.javaparser.TokenTypes; import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; import com.github.javaparser.printer.concretesyntaxmodel.CsmIndent; import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; import java.util.*; -import static com.github.javaparser.printer.TokenConstants.NEWLINE_TOKEN; -import static com.github.javaparser.printer.TokenConstants.SPACE_TOKEN; +import static com.github.javaparser.GeneratedJavaParserConstants.*; /** * A Difference should give me a sequence of elements I should find (to indicate the context) followed by a list of elements @@ -22,7 +19,7 @@ import static com.github.javaparser.printer.TokenConstants.SPACE_TOKEN; */ public class Difference { - private int STANDARD_INDENTANTION_SIZE = 4; + private int STANDARD_INDENTATION_SIZE = 4; private List<DifferenceElement> elements; @@ -302,11 +299,11 @@ public class Difference { res.addAll(indentation); boolean afterNl = false; for (TextElement e : prevElements) { - if (e.isToken(NEWLINE_TOKEN) || e.isToken(GeneratedJavaParserConstants.SINGLE_LINE_COMMENT)) { + if (e.isNewline() || e.isToken(SINGLE_LINE_COMMENT)) { res.clear(); afterNl = true; } else { - if (afterNl && e instanceof TokenTextElement && TokenConstants.isWhitespace(((TokenTextElement)e).getTokenKind())) { + if (afterNl && e instanceof TokenTextElement && TokenTypes.isWhitespace(((TokenTextElement)e).getTokenKind())) { res.add(e); } else { afterNl = false; @@ -318,15 +315,15 @@ public class Difference { private List<TextElement> indentationBlock() { List<TextElement> res = new LinkedList<>(); - res.add(new TokenTextElement(SPACE_TOKEN)); - res.add(new TokenTextElement(SPACE_TOKEN)); - res.add(new TokenTextElement(SPACE_TOKEN)); - res.add(new TokenTextElement(SPACE_TOKEN)); + res.add(new TokenTextElement(SPACE)); + res.add(new TokenTextElement(SPACE)); + res.add(new TokenTextElement(SPACE)); + res.add(new TokenTextElement(SPACE)); return res; } private int considerCleaningTheLine(NodeText nodeText, int nodeTextIndex) { - while (nodeTextIndex >=1 && nodeText.getElements().get(nodeTextIndex - 1).isWhiteSpace() && !nodeText.getElements().get(nodeTextIndex - 1).isToken(3)) { + while (nodeTextIndex >=1 && nodeText.getElements().get(nodeTextIndex - 1).isWhiteSpace() && !nodeText.getElements().get(nodeTextIndex - 1).isNewline()) { nodeText.removeElement(nodeTextIndex - 1); nodeTextIndex--; } @@ -334,10 +331,10 @@ public class Difference { } private boolean isAfterLBrace(NodeText nodeText, int nodeTextIndex) { - if (nodeTextIndex > 0 && nodeText.getElements().get(nodeTextIndex - 1).isToken(GeneratedJavaParserConstants.LBRACE)) { + if (nodeTextIndex > 0 && nodeText.getElements().get(nodeTextIndex - 1).isToken(LBRACE)) { return true; } - if (nodeTextIndex > 0 && nodeText.getElements().get(nodeTextIndex - 1).isWhiteSpace() && !nodeText.getElements().get(nodeTextIndex - 1).isToken(3)) { + if (nodeTextIndex > 0 && nodeText.getElements().get(nodeTextIndex - 1).isWhiteSpace() && !nodeText.getElements().get(nodeTextIndex - 1).isNewline()) { return isAfterLBrace(nodeText, nodeTextIndex - 1); } return false; @@ -389,7 +386,7 @@ public class Difference { Kept kept = (Kept) diffEl; if (kept.element instanceof CsmToken) { CsmToken csmToken = (CsmToken) kept.element; - if (TokenConstants.isWhitespaceOrComment(csmToken.getTokenType())) { + if (TokenTypes.isWhitespaceOrComment(csmToken.getTokenType())) { diffIndex++; } else { throw new IllegalStateException("Cannot keep element because we reached the end of nodetext: " @@ -420,15 +417,15 @@ public class Difference { if (diffEl instanceof Added) { TextElement textElement = toTextElement(nodeText.getLexicalPreservingPrinter(), ((Added) diffEl).element); boolean used = false; - if (nodeTextIndex > 0 && nodeText.getElements().get(nodeTextIndex - 1).isToken(NEWLINE_TOKEN)) { + if (nodeTextIndex > 0 && nodeText.getElements().get(nodeTextIndex - 1).isNewline()) { for (TextElement e : processIndentation(indentation, nodeText.getElements().subList(0, nodeTextIndex - 1))) { nodeText.addElement(nodeTextIndex++, e); } } else if (isAfterLBrace(nodeText, nodeTextIndex) && !isAReplacement(diffIndex)) { - if (textElement.isToken(NEWLINE_TOKEN)) { + if (textElement.isNewline()) { used = true; } - nodeText.addElement(nodeTextIndex++, new TokenTextElement(NEWLINE_TOKEN)); + nodeText.addElement(nodeTextIndex++, new TokenTextElement(TokenTypes.eolToken())); while (nodeText.getElements().get(nodeTextIndex).isSpaceOrTab()) { nodeText.getElements().remove(nodeTextIndex); } @@ -476,7 +473,7 @@ public class Difference { if (csmToken.getTokenType() == nodeTextToken.getTokenKind()) { nodeTextIndex++; diffIndex++; - } else if (TokenConstants.isWhitespaceOrComment(csmToken.getTokenType())) { + } else if (TokenTypes.isWhitespaceOrComment(csmToken.getTokenType())) { diffIndex++; } else if (nodeTextToken.isWhiteSpaceOrComment()) { nodeTextIndex++; @@ -492,7 +489,7 @@ public class Difference { Removed removed = (Removed)diffEl; if ((removed.element instanceof LexicalDifferenceCalculator.CsmChild) && nodeTextEl instanceof ChildTextElement) { nodeText.removeElement(nodeTextIndex); - if (nodeTextIndex < nodeText.getElements().size() && nodeText.getElements().get(nodeTextIndex).isToken(TokenConstants.NEWLINE_TOKEN)) { + if (nodeTextIndex < nodeText.getElements().size() && nodeText.getElements().get(nodeTextIndex).isNewline()) { nodeTextIndex = considerCleaningTheLine(nodeText, nodeTextIndex); } else { if (diffIndex + 1 >= this.getElements().size() || !(this.getElements().get(diffIndex + 1) instanceof Added)) { @@ -531,8 +528,8 @@ public class Difference { private int adjustIndentation(List<TokenTextElement> indentation, NodeText nodeText, int nodeTextIndex) { List<TextElement> indentationAdj = processIndentation(indentation, nodeText.getElements().subList(0, nodeTextIndex - 1)); - if (nodeTextIndex < nodeText.getElements().size() && nodeText.getElements().get(nodeTextIndex).isToken(GeneratedJavaParserConstants.RBRACE)) { - indentationAdj = indentationAdj.subList(0, indentationAdj.size() - Math.min(STANDARD_INDENTANTION_SIZE, indentationAdj.size())); + if (nodeTextIndex < nodeText.getElements().size() && nodeText.getElements().get(nodeTextIndex).isToken(RBRACE)) { + indentationAdj = indentationAdj.subList(0, indentationAdj.size() - Math.min(STANDARD_INDENTATION_SIZE, indentationAdj.size())); } for (TextElement e : indentationAdj) { nodeText.getElements().add(nodeTextIndex++, e); @@ -548,13 +545,13 @@ public class Difference { if (textElement instanceof TokenTextElement) { TokenTextElement tokenTextElement = (TokenTextElement)textElement; int tokenKind = tokenTextElement.getTokenKind(); - return tokenKind == GeneratedJavaParserConstants.BYTE - || tokenKind == GeneratedJavaParserConstants.CHAR - || tokenKind == GeneratedJavaParserConstants.SHORT - || tokenKind == GeneratedJavaParserConstants.INT - || tokenKind == GeneratedJavaParserConstants.LONG - || tokenKind == GeneratedJavaParserConstants.FLOAT - || tokenKind == GeneratedJavaParserConstants.DOUBLE; + return tokenKind == BYTE + || tokenKind == CHAR + || tokenKind == SHORT + || tokenKind == INT + || tokenKind == LONG + || tokenKind == FLOAT + || tokenKind == DOUBLE; } else { return false; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java index 8bfec6646..b68ed542f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java @@ -32,7 +32,6 @@ import com.github.javaparser.ast.observer.PropagatingAstObserver; import com.github.javaparser.ast.type.PrimitiveType; import com.github.javaparser.ast.visitor.TreeVisitor; import com.github.javaparser.printer.ConcreteSyntaxModel; -import com.github.javaparser.printer.TokenConstants; import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; import com.github.javaparser.utils.Pair; @@ -47,7 +46,7 @@ import java.util.*; import java.util.stream.Collectors; import static com.github.javaparser.GeneratedJavaParserConstants.JAVA_DOC_COMMENT; -import static com.github.javaparser.printer.TokenConstants.NEWLINE_TOKEN; +import static com.github.javaparser.TokenTypes.eolToken; import static com.github.javaparser.utils.Utils.decapitalize; /** @@ -117,7 +116,7 @@ public class LexicalPreservingPrinter { // Find the position of the comment node and put in front of it the comment and a newline int index = nodeText.findChild(observedNode); nodeText.addChild(index, (Comment)newValue); - nodeText.addToken(index + 1, NEWLINE_TOKEN, Utils.EOL); + nodeText.addToken(index + 1, eolToken(), Utils.EOL); } else if (oldValue != null && newValue == null) { if (oldValue instanceof JavadocComment) { JavadocComment javadocComment = (JavadocComment)oldValue; @@ -128,7 +127,7 @@ public class LexicalPreservingPrinter { } int index = nodeText.findElement(matchingTokens.get(0)); nodeText.removeElement(index); - if (nodeText.getElements().get(index).isToken(NEWLINE_TOKEN)) { + if (nodeText.getElements().get(index).isNewline()) { nodeText.removeElement(index); } } else { @@ -334,7 +333,7 @@ public class LexicalPreservingPrinter { while (it.hasNext()) { TokenTextElement tte = it.next(); if (tte.getTokenKind() == GeneratedJavaParserConstants.SINGLE_LINE_COMMENT - || tte.getTokenKind() == TokenConstants.NEWLINE_TOKEN) { + || tte.isNewline()) { break; } else { followingNewlines.add(tte); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java index 6ea5f1337..9a2063749 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java @@ -22,7 +22,6 @@ package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.ast.Node; -import com.github.javaparser.printer.TokenConstants; import java.util.LinkedList; import java.util.List; @@ -126,7 +125,7 @@ class NodeText { // void remove(TextElementMatcher matcher) { - elements.removeIf(e -> matcher.match(e)); + elements.removeIf(matcher::match); } public void remove(TextElementMatcher matcher, boolean potentiallyFollowingWhitespace) { @@ -136,7 +135,7 @@ class NodeText { elements.remove(e); if (potentiallyFollowingWhitespace) { if (i < elements.size()) { - if (elements.get(i).isToken(TokenConstants.SPACE_TOKEN)) { + if (elements.get(i).isWhiteSpace()) { elements.remove(i); } } else { diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java index 177fa65ff..0c12f0eb8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java @@ -24,8 +24,9 @@ package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.GeneratedJavaParserConstants; import com.github.javaparser.JavaToken; import com.github.javaparser.ast.Node; -import com.github.javaparser.printer.TokenConstants; -import com.github.javaparser.utils.Utils; +import com.github.javaparser.TokenTypes; + +import static com.github.javaparser.utils.Utils.EOL; class TokenTextElement extends TextElement { @@ -33,7 +34,7 @@ class TokenTextElement extends TextElement { private String text; public static TokenTextElement newLine() { - return new TokenTextElement(TokenConstants.NEWLINE_TOKEN, Utils.EOL); + return new TokenTextElement(TokenTypes.eolToken(), EOL); } TokenTextElement(JavaToken token) { @@ -50,9 +51,9 @@ class TokenTextElement extends TextElement { if (content.startsWith("\"")) { content = content.substring(1, content.length() - 1); } - if (tokenKind == TokenConstants.NEWLINE_TOKEN) { - content = Utils.EOL; - } else if (tokenKind == TokenConstants.SPACE_TOKEN) { + if (TokenTypes.isEndOfLineCharacter(tokenKind)) { + content = EOL; + } else if (TokenTypes.isWhitespace(tokenKind)) { content = " "; } this.tokenKind = tokenKind; @@ -110,21 +111,21 @@ class TokenTextElement extends TextElement { @Override public boolean isWhiteSpace() { - return TokenConstants.isWhitespace(tokenKind); + return TokenTypes.isWhitespace(tokenKind); } @Override public boolean isSpaceOrTab() { - return TokenConstants.isSpaceOrTab(tokenKind); + return TokenTypes.isSpaceOrTab(tokenKind); } @Override public boolean isComment() { - return TokenConstants.isComment(tokenKind); + return TokenTypes.isComment(tokenKind); } @Override public boolean isNewline() { - return tokenKind == TokenConstants.NEWLINE_TOKEN; + return TokenTypes.isEndOfLineCharacter(tokenKind); } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java index c32a08fda..e4535c60b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java @@ -1,6 +1,7 @@ package com.github.javaparser.utils; import java.io.File; +import java.net.URISyntaxException; import java.nio.file.Path; import java.nio.file.Paths; @@ -104,7 +105,11 @@ public final class CodeGenerationUtils { * @return the root directory of the classloader for class c. */ public static Path classLoaderRoot(Class<?> c) { - return Paths.get(c.getProtectionDomain().getCodeSource().getLocation().getPath()); + try { + return Paths.get(c.getProtectionDomain().getCodeSource().getLocation().toURI()); + } catch (URISyntaxException e) { + throw new AssertionError("Bug in JavaParser, please report.", e); + } } /** @@ -114,13 +119,4 @@ public final class CodeGenerationUtils { public static Path mavenModuleRoot(Class<?> c) { return classLoaderRoot(c).resolve(Paths.get("..", "..")).normalize(); } - - /** - * Useful for locating source code in your Maven project. - * Finds the classpath for the JavaParser code (which is probably the classpath for your code too,) - * then backs up out of "target/(test-)classes", giving the directory containing the pom.xml. - */ - public static Path mavenModuleRoot() { - return mavenModuleRoot(CodeGenerationUtils.class); - } } diff --git a/javaparser-core/src/main/javacc/java.jj b/javaparser-core/src/main/javacc/java.jj index b5c3312cd..785792d02 100644 --- a/javaparser-core/src/main/javacc/java.jj +++ b/javaparser-core/src/main/javacc/java.jj @@ -278,36 +278,37 @@ PARSER_END(GeneratedJavaParser) SPECIAL_TOKEN : { - " " -| "\t" -| "\n" -| "\r" -| "\f" -| "\u0085" -| "\u00A0" -| "\u1680" -| "\u180e" -| "\u2000" -| "\u2001" -| "\u2002" -| "\u2003" -| "\u2004" -| "\u2005" -| "\u2006" -| "\u2007" -| "\u2008" -| "\u2009" -| "\u200a" -| "\u200b" -| "\u200c" -| "\u200d" -| "\u2028" -| "\u2029" -| "\u202f" -| "\u205f" -| "\u2060" -| "\u3000" -| "\ufeff" + <SPACE: " "> +| <WINDOWS_EOL : "\r\n"> +| <TAB: "\t"> +| <UNIX_EOL: "\n"> +| <OLD_MAC_EOL: "\r"> +| <FORM_FEED: "\f"> +| <NEXT_LINE: "\u0085"> +| <NON_BREAKING_SPACE: "\u00A0"> +| <OGHAM_SPACE: "\u1680"> +| <MONGOLIAN_VOWEL_SEPARATOR: "\u180e"> +| <EN_QUAD: "\u2000"> +| <EM_QUAD: "\u2001"> +| <EN_SPACE: "\u2002"> +| <EM_SPACE: "\u2003"> +| <THREE_PER_EM_SPACE: "\u2004"> +| <FOUR_PER_EM_SPACE: "\u2005"> +| <SIX_PER_EM_SPACE: "\u2006"> +| <FIGURE_SPACE: "\u2007"> +| <PUNCTUATION_SPACE: "\u2008"> +| <THIN_SPACE: "\u2009"> +| <HAIR_SPACE: "\u200a"> +| <ZERO_WIDTH_SPACE: "\u200b"> +| <ZERO_WIDTH_NON_JOINER: "\u200c"> +| <ZERO_WIDTH_JOINER: "\u200d"> +| <LINE_SEPARATOR: "\u2028"> +| <PARAGRAPH_SEPARATOR: "\u2029"> +| <NARROW_NO_BREAK_SPACE: "\u202f"> +| <MEDIUM_MATHEMATICAL_SPACE: "\u205f"> +| <WORD_JOINER: "\u2060"> +| <IDEOGRAPHIC_SPACE: "\u3000"> +| <ZERO_WIDTH_NO_BREAK_SPACE: "\ufeff"> } TOKEN_MGR_DECLS : diff --git a/javaparser-testing/src/test/java/com/github/javaparser/ast/ParseResultTest.java b/javaparser-testing/src/test/java/com/github/javaparser/ast/ParseResultTest.java index 8c9ebe06f..98f5c9ac2 100644 --- a/javaparser-testing/src/test/java/com/github/javaparser/ast/ParseResultTest.java +++ b/javaparser-testing/src/test/java/com/github/javaparser/ast/ParseResultTest.java @@ -29,6 +29,7 @@ import org.junit.Test; import static com.github.javaparser.ParseStart.COMPILATION_UNIT; import static com.github.javaparser.Providers.provider; +import static com.github.javaparser.utils.Utils.EOL; import static org.assertj.core.api.Assertions.assertThat; public class ParseResultTest { @@ -56,6 +57,6 @@ public class ParseResultTest { assertThat(problem.getMessage()).isEqualTo("Parse error. Found \"{\", expected one of \"exports\" \"module\" \"open\" \"opens\" \"provides\" \"requires\" \"to\" \"transitive\" \"uses\" \"with\" <IDENTIFIER>"); assertThat(result.getTokens().isPresent()).isTrue(); - assertThat(result.toString()).startsWith("Parsing failed:\n(line 1,col 1) Parse error."); + assertThat(result.toString()).startsWith("Parsing failed:" + EOL + "(line 1,col 1) Parse error."); } } diff --git a/javaparser-testing/src/test/java/com/github/javaparser/manual/BulkParseTest.java b/javaparser-testing/src/test/java/com/github/javaparser/manual/BulkParseTest.java index 0becf9e2e..cc135550b 100644 --- a/javaparser-testing/src/test/java/com/github/javaparser/manual/BulkParseTest.java +++ b/javaparser-testing/src/test/java/com/github/javaparser/manual/BulkParseTest.java @@ -15,9 +15,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import static com.github.javaparser.utils.SourceRoot.Callback.Result.DONT_SAVE; -import static com.github.javaparser.utils.TestUtils.download; -import static com.github.javaparser.utils.TestUtils.temporaryDirectory; -import static com.github.javaparser.utils.TestUtils.unzip; +import static com.github.javaparser.utils.TestUtils.*; public class BulkParseTest { /** @@ -29,7 +27,7 @@ public class BulkParseTest { } private void parseOpenJdk() throws IOException { - Path workdir = CodeGenerationUtils.mavenModuleRoot().resolve(Paths.get(temporaryDirectory(), "javaparser_openjdk_download")); + Path workdir = CodeGenerationUtils.mavenModuleRoot(BulkParseTest.class).resolve(Paths.get(temporaryDirectory(), "javaparser_openjdk_download")); workdir.toFile().mkdirs(); Path openJdkZipPath = workdir.resolve("openjdk.zip"); if (Files.notExists(openJdkZipPath)) { @@ -46,21 +44,23 @@ public class BulkParseTest { @Test public void parseOwnSourceCode() throws IOException { - bulkTest(new SourceRoot(CodeGenerationUtils.mavenModuleRoot().resolve("..")), "javaparser_test_results.txt"); + bulkTest(new SourceRoot(CodeGenerationUtils.mavenModuleRoot(BulkParseTest.class).resolve("..")), "javaparser_test_results.txt"); } public void bulkTest(SourceRoot sourceRoot, String testResultsFileName) throws IOException { - Path testResults = CodeGenerationUtils.mavenModuleRoot().resolve(Paths.get("..", "javaparser-testing", "src", "test", "resources", "com", "github", "javaparser", "bulk_test_results")).normalize(); + Path testResults = CodeGenerationUtils.mavenModuleRoot(BulkParseTest.class).resolve(Paths.get("..", "javaparser-testing", "src", "test", "resources", "com", "github", "javaparser", "bulk_test_results")).normalize(); testResults.toFile().mkdirs(); testResults = testResults.resolve(testResultsFileName); try (BufferedWriter writer = Files.newBufferedWriter(testResults)) { sourceRoot.parse("", new JavaParser(), (localPath, absolutePath, result) -> { - if (!result.isSuccessful()) { - writer.write(localPath.toString()); - writer.newLine(); - for (Problem problem : result.getProblems()) { - writer.write(problem.getVerboseMessage()); + if (!localPath.toString().contains("target")) { + if (!result.isSuccessful()) { + writer.write(localPath.toString().replace("\\", "/")); writer.newLine(); + for (Problem problem : result.getProblems()) { + writer.write(problem.getVerboseMessage()); + writer.newLine(); + } } } return DONT_SAVE; diff --git a/javaparser-testing/src/test/java/com/github/javaparser/printer/ConcreteSyntaxModelAcceptanceTest.java b/javaparser-testing/src/test/java/com/github/javaparser/printer/ConcreteSyntaxModelAcceptanceTest.java index a114fbbbc..9f27bb4dd 100644 --- a/javaparser-testing/src/test/java/com/github/javaparser/printer/ConcreteSyntaxModelAcceptanceTest.java +++ b/javaparser-testing/src/test/java/com/github/javaparser/printer/ConcreteSyntaxModelAcceptanceTest.java @@ -38,7 +38,7 @@ public class ConcreteSyntaxModelAcceptanceTest { } private String prettyPrintedExpectation(String name) throws IOException { - return TestUtils.readFileWith("com/github/javaparser/printer/" + name + "_prettyprinted"); + return TestUtils.readResource("com/github/javaparser/printer/" + name + "_prettyprinted"); } @Test diff --git a/javaparser-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AbstractLexicalPreservingTest.java b/javaparser-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AbstractLexicalPreservingTest.java index fc9cab205..431f62656 100644 --- a/javaparser-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AbstractLexicalPreservingTest.java +++ b/javaparser-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/AbstractLexicalPreservingTest.java @@ -26,15 +26,13 @@ import com.github.javaparser.ParseStart; import com.github.javaparser.Providers; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.utils.Pair; import org.junit.Before; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.InputStream; +import static com.github.javaparser.utils.TestUtils.readResource; import static org.junit.Assert.assertEquals; public abstract class AbstractLexicalPreservingTest { @@ -70,21 +68,7 @@ public abstract class AbstractLexicalPreservingTest { } protected String readExample(String resourceName) throws IOException { - InputStream is = this.getClass().getResourceAsStream("/com/github/javaparser/lexical_preservation_samples/" + resourceName + ".java.txt"); - if (is == null) { - throw new IllegalArgumentException("Example not found: " + resourceName); - } - return read(is); - } - - protected String read(InputStream inputStream) throws IOException { - ByteArrayOutputStream result = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int length; - while ((length = inputStream.read(buffer)) != -1) { - result.write(buffer, 0, length); - } - return result.toString("UTF-8"); + return readResource("com/github/javaparser/lexical_preservation_samples/" + resourceName + ".java.txt"); } protected void assertTransformed(String exampleName, Node node) throws IOException { diff --git a/javaparser-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/DifferenceTest.java b/javaparser-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/DifferenceTest.java index d5147d84a..93db4ca22 100644 --- a/javaparser-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/DifferenceTest.java +++ b/javaparser-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/DifferenceTest.java @@ -1,10 +1,8 @@ package com.github.javaparser.printer.lexicalpreservation; import com.github.javaparser.GeneratedJavaParserConstants; -import com.github.javaparser.Range; import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.PackageDeclaration; import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.comments.JavadocComment; @@ -14,15 +12,10 @@ import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.type.ArrayType; import com.github.javaparser.ast.type.PrimitiveType; -import com.github.javaparser.ast.visitor.GenericVisitor; -import com.github.javaparser.ast.visitor.HashCodeVisitor; -import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.printer.ConcreteSyntaxModel; import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; import com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CsmChild; -import com.sun.org.apache.xpath.internal.operations.Mod; -import org.assertj.core.internal.Diff; import org.junit.Test; import java.io.IOException; @@ -30,12 +23,9 @@ import java.util.Arrays; import java.util.Collections; import java.util.EnumSet; -import static com.github.javaparser.printer.concretesyntaxmodel.CsmElement.*; -import static com.github.javaparser.printer.concretesyntaxmodel.CsmElement.newline; -import static com.github.javaparser.printer.concretesyntaxmodel.CsmElement.unindent; -import static com.github.javaparser.printer.lexicalpreservation.Difference.DifferenceElement.added; -import static com.github.javaparser.printer.lexicalpreservation.Difference.DifferenceElement.kept; -import static com.github.javaparser.printer.lexicalpreservation.Difference.DifferenceElement.removed; +import static com.github.javaparser.TokenTypes.eolToken; +import static com.github.javaparser.TokenTypes.spaceToken; +import static com.github.javaparser.printer.lexicalpreservation.Difference.DifferenceElement.*; import static org.junit.Assert.assertEquals; public class DifferenceTest extends AbstractLexicalPreservingTest { @@ -103,7 +93,7 @@ public class DifferenceTest extends AbstractLexicalPreservingTest { assertEquals(3, diff.getElements().size()); assertEquals(added(new CsmChild(packageDeclaration)), diff.getElements().get(0)); assertEquals(kept(new CsmChild(cu.getType(0))), diff.getElements().get(1)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(2)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(2)); } @Test @@ -116,26 +106,26 @@ public class DifferenceTest extends AbstractLexicalPreservingTest { Difference diff = Difference.calculate(csmOriginal, csmChanged); int i = 0; assertEquals(added(new CsmToken(GeneratedJavaParserConstants.PUBLIC)), diff.getElements().get(i++)); - assertEquals(added(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(added(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.AT)), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.INTERFACE)), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getName())), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.LBRACE)), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(0))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(1))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(2))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(3))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(4))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(5))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.RBRACE)), diff.getElements().get(i++)); assertEquals(i, diff.getElements().size()); } @@ -153,24 +143,24 @@ public class DifferenceTest extends AbstractLexicalPreservingTest { int i = 0; assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.AT)), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.INTERFACE)), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(removed(new CsmChild(annotationDeclaration.getName())), diff.getElements().get(i++)); assertEquals(added(new CsmChild(newName)), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.LBRACE)), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(0))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(1))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(2))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(3))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(4))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(5))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.RBRACE)), diff.getElements().get(i++)); assertEquals(i, diff.getElements().size()); } @@ -186,26 +176,26 @@ public class DifferenceTest extends AbstractLexicalPreservingTest { Difference diff = Difference.calculate(csmOriginal, csmChanged); int i = 0; assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.PUBLIC)), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.AT)), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.INTERFACE)), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getName())), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.LBRACE)), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(0))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(1))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(2))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(3))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(4))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(5))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.RBRACE)), diff.getElements().get(i++)); assertEquals(i, diff.getElements().size()); } @@ -220,26 +210,26 @@ public class DifferenceTest extends AbstractLexicalPreservingTest { Difference diff = Difference.calculate(csmOriginal, csmChanged); int i = 0; assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.PUBLIC)), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.AT)), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.INTERFACE)), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getName())), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.LBRACE)), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(0))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(1))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(2))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(3))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(4))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(5))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.RBRACE)), diff.getElements().get(i++)); assertEquals(i, diff.getElements().size()); } @@ -254,26 +244,26 @@ public class DifferenceTest extends AbstractLexicalPreservingTest { Difference diff = Difference.calculate(csmOriginal, csmChanged); int i = 0; assertEquals(removed(new CsmToken(GeneratedJavaParserConstants.PUBLIC)), diff.getElements().get(i++)); - assertEquals(removed(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(removed(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.AT)), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.INTERFACE)), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getName())), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.LBRACE)), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(0))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(1))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(2))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(3))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(4))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(annotationDeclaration.getMember(5))), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.RBRACE)), diff.getElements().get(i++)); assertEquals(i, diff.getElements().size()); } @@ -286,13 +276,13 @@ public class DifferenceTest extends AbstractLexicalPreservingTest { Difference diff = Difference.calculate(csmOriginal, csmChanged); int i = 0; assertEquals(kept(new CsmChild(md.getType())), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(md.getName())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.LPAREN)), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.RPAREN)), diff.getElements().get(i++)); - assertEquals(removed(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(removed(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(removed(new CsmToken(GeneratedJavaParserConstants._DEFAULT)), diff.getElements().get(i++)); - assertEquals(removed(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(removed(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(removed(new CsmChild(md.getDefaultValue().get())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.SEMICOLON)), diff.getElements().get(i++)); assertEquals(i, diff.getElements().size()); @@ -307,13 +297,13 @@ public class DifferenceTest extends AbstractLexicalPreservingTest { Difference diff = Difference.calculate(csmOriginal, csmChanged); int i = 0; assertEquals(kept(new CsmChild(md.getType())), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(md.getName())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.LPAREN)), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.RPAREN)), diff.getElements().get(i++)); - assertEquals(added(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(added(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(added(new CsmToken(GeneratedJavaParserConstants._DEFAULT)), diff.getElements().get(i++)); - assertEquals(added(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(added(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(added(new CsmChild(defaultValue)), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.SEMICOLON)), diff.getElements().get(i++)); assertEquals(i, diff.getElements().size()); @@ -328,11 +318,11 @@ public class DifferenceTest extends AbstractLexicalPreservingTest { Difference diff = Difference.calculate(csmOriginal, csmChanged); int i = 0; assertEquals(added(new CsmToken(GeneratedJavaParserConstants.PUBLIC)), diff.getElements().get(i++)); - assertEquals(added(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(added(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(cd.getName())), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.LPAREN)), diff.getElements().get(i++)); assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.RPAREN)), diff.getElements().get(i++)); - assertEquals(kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(kept(new CsmChild(cd.getBody())), diff.getElements().get(i++)); assertEquals(i, diff.getElements().size()); } @@ -365,9 +355,9 @@ public class DifferenceTest extends AbstractLexicalPreservingTest { Difference diff = Difference.calculate(csmOriginal, csmChanged); int i = 0; assertEquals(Difference.DifferenceElement.kept(new CsmToken(GeneratedJavaParserConstants.LBRACE)), diff.getElements().get(i++)); - assertEquals(Difference.DifferenceElement.kept(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(Difference.DifferenceElement.kept(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(Difference.DifferenceElement.added(new CsmChild(s)), diff.getElements().get(i++)); - assertEquals(Difference.DifferenceElement.added(new CsmToken(3)), diff.getElements().get(i++)); + assertEquals(Difference.DifferenceElement.added(new CsmToken(eolToken())), diff.getElements().get(i++)); assertEquals(Difference.DifferenceElement.kept(new CsmToken(GeneratedJavaParserConstants.RBRACE)), diff.getElements().get(i++)); assertEquals(i, diff.getElements().size()); } @@ -380,14 +370,14 @@ public class DifferenceTest extends AbstractLexicalPreservingTest { Difference diff = Difference.calculate(csmOriginal, csmChanged); int i = 0; assertEquals(Difference.DifferenceElement.kept(new CsmToken(GeneratedJavaParserConstants.PUBLIC)), diff.getElements().get(i++)); - assertEquals(Difference.DifferenceElement.kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(Difference.DifferenceElement.kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(Difference.DifferenceElement.kept(new CsmChild(md.getType())), diff.getElements().get(i++)); - assertEquals(Difference.DifferenceElement.kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(Difference.DifferenceElement.kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(Difference.DifferenceElement.kept(new CsmChild(md.getName())), diff.getElements().get(i++)); assertEquals(Difference.DifferenceElement.kept(new CsmToken(GeneratedJavaParserConstants.LPAREN)), diff.getElements().get(i++)); assertEquals(Difference.DifferenceElement.removed(new CsmChild(md.getParameter(0))), diff.getElements().get(i++)); assertEquals(Difference.DifferenceElement.kept(new CsmToken(GeneratedJavaParserConstants.RPAREN)), diff.getElements().get(i++)); - assertEquals(Difference.DifferenceElement.kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(Difference.DifferenceElement.kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(Difference.DifferenceElement.kept(new CsmChild(md.getBody().get())), diff.getElements().get(i++)); assertEquals(i, diff.getElements().size()); } @@ -401,14 +391,14 @@ public class DifferenceTest extends AbstractLexicalPreservingTest { Difference diff = Difference.calculate(csmOriginal, csmChanged); int i = 0; assertEquals(Difference.DifferenceElement.kept(new CsmToken(GeneratedJavaParserConstants.PUBLIC)), diff.getElements().get(i++)); - assertEquals(Difference.DifferenceElement.kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(Difference.DifferenceElement.kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(Difference.DifferenceElement.kept(new CsmChild(md.getType())), diff.getElements().get(i++)); - assertEquals(Difference.DifferenceElement.kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(Difference.DifferenceElement.kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(Difference.DifferenceElement.kept(new CsmChild(md.getName())), diff.getElements().get(i++)); assertEquals(Difference.DifferenceElement.kept(new CsmToken(GeneratedJavaParserConstants.LPAREN)), diff.getElements().get(i++)); assertEquals(Difference.DifferenceElement.added(new CsmChild(newParameter)), diff.getElements().get(i++)); assertEquals(Difference.DifferenceElement.kept(new CsmToken(GeneratedJavaParserConstants.RPAREN)), diff.getElements().get(i++)); - assertEquals(Difference.DifferenceElement.kept(new CsmToken(1)), diff.getElements().get(i++)); + assertEquals(Difference.DifferenceElement.kept(new CsmToken(spaceToken())), diff.getElements().get(i++)); assertEquals(Difference.DifferenceElement.kept(new CsmChild(md.getBody().get())), diff.getElements().get(i++)); assertEquals(i, diff.getElements().size()); } diff --git a/javaparser-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculatorTest.java b/javaparser-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculatorTest.java index d5a6e58c8..2016ce73d 100644 --- a/javaparser-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculatorTest.java +++ b/javaparser-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculatorTest.java @@ -18,6 +18,8 @@ import org.junit.Test; import java.io.IOException; import java.util.EnumSet; +import static com.github.javaparser.TokenTypes.eolToken; +import static com.github.javaparser.TokenTypes.spaceToken; import static org.junit.Assert.assertEquals; public class LexicalDifferenceCalculatorTest extends AbstractLexicalPreservingTest { @@ -29,7 +31,7 @@ public class LexicalDifferenceCalculatorTest extends AbstractLexicalPreservingTe LexicalDifferenceCalculator.CalculatedSyntaxModel csmOriginal = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(element, cu); assertEquals(2, csmOriginal.elements.size()); assertEquals(new LexicalDifferenceCalculator.CsmChild(cu.getType(0)), csmOriginal.elements.get(0)); - assertEquals(new CsmToken(3), csmOriginal.elements.get(1)); + assertEquals(new CsmToken(eolToken()), csmOriginal.elements.get(1)); } @Test @@ -41,7 +43,7 @@ public class LexicalDifferenceCalculatorTest extends AbstractLexicalPreservingTe assertEquals(3, csmChanged.elements.size()); assertEquals(new LexicalDifferenceCalculator.CsmChild(packageDeclaration), csmChanged.elements.get(0)); assertEquals(new LexicalDifferenceCalculator.CsmChild(cu.getType(0)), csmChanged.elements.get(1)); - assertEquals(new CsmToken(3), csmChanged.elements.get(2)); + assertEquals(new CsmToken(eolToken()), csmChanged.elements.get(2)); } @Test @@ -53,23 +55,23 @@ public class LexicalDifferenceCalculatorTest extends AbstractLexicalPreservingTe int i = 0; assertEquals(new CsmToken(GeneratedJavaParserConstants.AT), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.INTERFACE), csm.elements.get(i++)); - assertEquals(new CsmToken(1), csm.elements.get(i++)); + assertEquals(new CsmToken(spaceToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getName()), csm.elements.get(i++)); - assertEquals(new CsmToken(1), csm.elements.get(i++)); + assertEquals(new CsmToken(spaceToken()), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.LBRACE), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(0)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(1)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(2)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(3)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(4)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(5)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.RBRACE), csm.elements.get(i++)); assertEquals(i, csm.elements.size()); } @@ -82,26 +84,26 @@ public class LexicalDifferenceCalculatorTest extends AbstractLexicalPreservingTe LexicalDifferenceCalculator.CalculatedSyntaxModel csm = new LexicalDifferenceCalculator().calculatedSyntaxModelAfterPropertyChange(element, annotationDeclaration, ObservableProperty.MODIFIERS, EnumSet.noneOf(Modifier.class), EnumSet.of(Modifier.PUBLIC)); int i = 0; assertEquals(new CsmToken(GeneratedJavaParserConstants.PUBLIC), csm.elements.get(i++)); - assertEquals(new CsmToken(1), csm.elements.get(i++)); + assertEquals(new CsmToken(spaceToken()), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.AT), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.INTERFACE), csm.elements.get(i++)); - assertEquals(new CsmToken(1), csm.elements.get(i++)); + assertEquals(new CsmToken(spaceToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getName()), csm.elements.get(i++)); - assertEquals(new CsmToken(1), csm.elements.get(i++)); + assertEquals(new CsmToken(spaceToken()), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.LBRACE), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(0)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(1)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(2)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(3)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(4)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(5)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.RBRACE), csm.elements.get(i++)); assertEquals(i, csm.elements.size()); } @@ -117,23 +119,23 @@ public class LexicalDifferenceCalculatorTest extends AbstractLexicalPreservingTe int i = 0; assertEquals(new CsmToken(GeneratedJavaParserConstants.AT), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.INTERFACE), csm.elements.get(i++)); - assertEquals(new CsmToken(1), csm.elements.get(i++)); + assertEquals(new CsmToken(spaceToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(newName), csm.elements.get(i++)); - assertEquals(new CsmToken(1), csm.elements.get(i++)); + assertEquals(new CsmToken(spaceToken()), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.LBRACE), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(0)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(1)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(2)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(3)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(4)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(5)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.RBRACE), csm.elements.get(i++)); assertEquals(i, csm.elements.size()); } @@ -146,26 +148,26 @@ public class LexicalDifferenceCalculatorTest extends AbstractLexicalPreservingTe LexicalDifferenceCalculator.CalculatedSyntaxModel csm = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(element, annotationDeclaration); int i = 0; assertEquals(new CsmToken(GeneratedJavaParserConstants.PUBLIC), csm.elements.get(i++)); - assertEquals(new CsmToken(1), csm.elements.get(i++)); + assertEquals(new CsmToken(spaceToken()), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.AT), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.INTERFACE), csm.elements.get(i++)); - assertEquals(new CsmToken(1), csm.elements.get(i++)); + assertEquals(new CsmToken(spaceToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getName()), csm.elements.get(i++)); - assertEquals(new CsmToken(1), csm.elements.get(i++)); + assertEquals(new CsmToken(spaceToken()), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.LBRACE), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(0)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(1)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(2)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(3)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(4)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(5)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.RBRACE), csm.elements.get(i++)); assertEquals(i, csm.elements.size()); } @@ -179,26 +181,26 @@ public class LexicalDifferenceCalculatorTest extends AbstractLexicalPreservingTe LexicalDifferenceCalculator.CalculatedSyntaxModel csm = new LexicalDifferenceCalculator().calculatedSyntaxModelAfterPropertyChange(element, annotationDeclaration, ObservableProperty.COMMENT, null, comment); int i = 0; assertEquals(new CsmToken(GeneratedJavaParserConstants.PUBLIC), csm.elements.get(i++)); - assertEquals(new CsmToken(1), csm.elements.get(i++)); + assertEquals(new CsmToken(spaceToken()), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.AT), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.INTERFACE), csm.elements.get(i++)); - assertEquals(new CsmToken(1), csm.elements.get(i++)); + assertEquals(new CsmToken(spaceToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getName()), csm.elements.get(i++)); - assertEquals(new CsmToken(1), csm.elements.get(i++)); + assertEquals(new CsmToken(spaceToken()), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.LBRACE), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(0)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(1)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(2)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(3)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(4)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(5)), csm.elements.get(i++)); - assertEquals(new CsmToken(3), csm.elements.get(i++)); + assertEquals(new CsmToken(eolToken()), csm.elements.get(i++)); assertEquals(new CsmToken(GeneratedJavaParserConstants.RBRACE), csm.elements.get(i++)); assertEquals(i, csm.elements.size()); } diff --git a/javaparser-testing/src/test/java/com/github/javaparser/utils/SourceRootTest.java b/javaparser-testing/src/test/java/com/github/javaparser/utils/SourceRootTest.java index 643ee30cc..4814d4afc 100644 --- a/javaparser-testing/src/test/java/com/github/javaparser/utils/SourceRootTest.java +++ b/javaparser-testing/src/test/java/com/github/javaparser/utils/SourceRootTest.java @@ -16,7 +16,7 @@ import static org.junit.Assert.fail; public class SourceRootTest { @Test public void parseTestDirectory() throws URISyntaxException, IOException { - SourceRoot sourceRoot = new SourceRoot(Paths.get(getClass().getProtectionDomain().getCodeSource().getLocation().toURI()).resolve(Paths.get("..", "..", "src", "test", "resources", "com", "github", "javaparser", "utils"))); + SourceRoot sourceRoot = new SourceRoot(CodeGenerationUtils.mavenModuleRoot(SourceRootTest.class).resolve(Paths.get("src", "test", "resources", "com", "github", "javaparser", "utils"))); Map<Path, ParseResult<CompilationUnit>> results = sourceRoot.tryToParse(); assertEquals(2, results.size()); diff --git a/javaparser-testing/src/test/java/com/github/javaparser/utils/TestUtils.java b/javaparser-testing/src/test/java/com/github/javaparser/utils/TestUtils.java index cbcf07c77..5daa93e46 100644 --- a/javaparser-testing/src/test/java/com/github/javaparser/utils/TestUtils.java +++ b/javaparser-testing/src/test/java/com/github/javaparser/utils/TestUtils.java @@ -12,20 +12,29 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public class TestUtils { /** * Takes care of setting all the end of line character to platform specific ones. */ - public static String readFileWith(String resourceName) throws IOException { - try (final InputStream inputStream = TestUtils.class.getClassLoader().getResourceAsStream(resourceName); - final BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "utf-8"))) { - final StringBuilder builder = new StringBuilder(); - String line; - while ((line = br.readLine()) != null) { - builder.append(line).append(Utils.EOL); + public static String readResource(String resourceName) throws IOException { + if (resourceName.startsWith("/")) { + resourceName = resourceName.substring(1); + } + try (final InputStream resourceAsStream = TestUtils.class.getClassLoader().getResourceAsStream(resourceName)) { + if (resourceAsStream == null) { + fail("not found: " + resourceName); + } + try (final InputStreamReader reader = new InputStreamReader(resourceAsStream, "utf-8"); + final BufferedReader br = new BufferedReader(reader)) { + final StringBuilder builder = new StringBuilder(); + String line; + while ((line = br.readLine()) != null) { + builder.append(line).append(Utils.EOL); + } + return builder.toString(); } - return builder.toString(); } } diff --git a/javaparser-testing/src/test/resources/com/github/javaparser/bulk_test_results/javaparser_test_results.txt b/javaparser-testing/src/test/resources/com/github/javaparser/bulk_test_results/javaparser_test_results.txt index a7b0c6939..b0212f41d 100644 --- a/javaparser-testing/src/test/resources/com/github/javaparser/bulk_test_results/javaparser_test_results.txt +++ b/javaparser-testing/src/test/resources/com/github/javaparser/bulk_test_results/javaparser_test_results.txt @@ -1,4 +1,2 @@ -javaparser-testing/target/test-classes/com/github/javaparser/TestFileIso88591.java -Lexical error at line 5, column 22. Encountered: "\ufffd" (65533), after : "" javaparser-testing/src/test/resources/com/github/javaparser/TestFileIso88591.java Lexical error at line 5, column 22. Encountered: "\ufffd" (65533), after : "" |