diff --git a/.run/CoreGenerator.run.xml b/.run/CoreGenerator.run.xml
index 00b8188d5a..f73c99fd7b 100644
--- a/.run/CoreGenerator.run.xml
+++ b/.run/CoreGenerator.run.xml
@@ -3,8 +3,8 @@
nameIsGenerated="true">
-
-
+
+
diff --git a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/CoreGenerator.java b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/CoreGenerator.java
index fcb3d135a0..c80a9478a6 100644
--- a/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/CoreGenerator.java
+++ b/javaparser-core-generators/src/main/java/com/github/javaparser/generator/core/CoreGenerator.java
@@ -54,13 +54,14 @@ public static void main(String[] args) throws Exception {
throw new RuntimeException("Need 1 parameter: the JavaParser source checkout root directory.");
}
Log.setAdapter(new Log.StandardOutStandardErrorAdapter());
- final Path root = Paths.get(args[0], "..", "javaparser-core", "src", "main", "java");
+ final var project = Paths.get(args[0]).getParent();
+ final Path root = project.resolve(Paths.get("javaparser-core", "src", "main", "java"));
final SourceRoot sourceRoot = new SourceRoot(root, parserConfiguration)
// .setPrinter(LexicalPreservingPrinter::print)
;
StaticJavaParser.setConfiguration(parserConfiguration);
- final Path generatedJavaCcRoot = Paths.get(args[0], "..", "javaparser-core", "target", "generated-sources", "javacc");
+ final Path generatedJavaCcRoot = project.resolve(Paths.get("javaparser-core", "target", "generated-sources", "javacc"));
final SourceRoot generatedJavaCcSourceRoot = new SourceRoot(generatedJavaCcRoot, parserConfiguration)
// .setPrinter(LexicalPreservingPrinter::print)
;
diff --git a/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java
index 8b5b07450a..31f4403670 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java
@@ -22,7 +22,6 @@
import java.util.Optional;
import java.util.function.Predicate;
-
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.observer.Observable;
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java
index 1ac76db62a..ff0a6e484b 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java
@@ -42,11 +42,9 @@
import com.github.javaparser.metamodel.OptionalProperty;
import com.github.javaparser.resolution.Resolvable;
import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
-
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Consumer;
-
import static com.github.javaparser.ast.Modifier.DefaultKeyword.*;
import static com.github.javaparser.utils.Utils.assertNotNull;
@@ -266,10 +264,7 @@ public boolean isPublic() {
}
private boolean isImplicitlyPublic() {
- return getAccessSpecifier() == AccessSpecifier.NONE
- && hasParentNode()
- && getParentNode().get() instanceof ClassOrInterfaceDeclaration
- && ((ClassOrInterfaceDeclaration) getParentNode().get()).isInterface();
+ return getAccessSpecifier() == AccessSpecifier.NONE && hasParentNode() && getParentNode().get() instanceof ClassOrInterfaceDeclaration && ((ClassOrInterfaceDeclaration) getParentNode().get()).isInterface();
}
/*
@@ -282,13 +277,9 @@ public boolean isAbstract() {
}
private boolean isImplicitlyAbstract() {
- return hasParentNode() && getParentNode().get() instanceof ClassOrInterfaceDeclaration
- && ((ClassOrInterfaceDeclaration) getParentNode().get()).isInterface()
- && Arrays.asList(STATIC, DEFAULT, PRIVATE).stream()
- .noneMatch(modifier -> hasModifier(modifier));
+ return hasParentNode() && getParentNode().get() instanceof ClassOrInterfaceDeclaration && ((ClassOrInterfaceDeclaration) getParentNode().get()).isInterface() && Arrays.asList(STATIC, DEFAULT, PRIVATE).stream().noneMatch(modifier -> hasModifier(modifier));
}
-
public boolean isNative() {
return hasModifier(Modifier.DefaultKeyword.NATIVE);
}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java
index 2f83755c74..fd7dc51030 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java
@@ -21,10 +21,8 @@
package com.github.javaparser.ast.expr;
import static com.github.javaparser.utils.Utils.assertNotNull;
-
import java.util.Optional;
import java.util.function.Consumer;
-
import com.github.javaparser.TokenRange;
import com.github.javaparser.ast.AllFieldsConstructor;
import com.github.javaparser.ast.Generated;
@@ -117,13 +115,11 @@ public LambdaExpr(TokenRange tokenRange, NodeList parameters, Stateme
customInitialization();
}
- @Override
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
public NodeList getParameters() {
return parameters;
}
- @Override
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
public LambdaExpr setParameters(final NodeList parameters) {
assertNotNull(parameters);
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java
index bbb519dbfb..849ab8a851 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java
@@ -161,7 +161,7 @@ default boolean hasParametersOfType(String... paramTypes) {
*/
default boolean hasParametersOfType(Class>... paramTypes) {
return // if p.getType() is a class or interface type, we want to consider its erasure, i.e., if the parameter
- getParameters().stream().// is "List", we want to consider it as "List", so we need to call getName()
- map(p -> p.getType().toClassOrInterfaceType().map(NodeWithSimpleName::getNameAsString).orElseGet(() -> p.getType().asString())).collect(toList()).equals(Stream.of(paramTypes).map(Class::getSimpleName).collect(toList()));
+ // is "List", we want to consider it as "List", so we need to call getName()
+ getParameters().stream().map(p -> p.getType().toClassOrInterfaceType().map(NodeWithSimpleName::getNameAsString).orElseGet(() -> p.getType().asString())).collect(toList()).equals(Stream.of(paramTypes).map(Class::getSimpleName).collect(toList()));
}
}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java
index c33a109eae..8edbc4b843 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/postprocessors/Java10PostProcessor.java
@@ -27,7 +27,6 @@
import com.github.javaparser.ast.expr.ClassExpr;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import com.github.javaparser.ast.type.VarType;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -40,6 +39,7 @@ public class Java10PostProcessor extends PostProcessors {
// List of parent contexts in which a var type must not be detected.
// for example: in this statement var.class.getCanonicalName(), var must not be considered as a VarType
private static List FORBIDEN_PARENT_CONTEXT_TO_DETECT_POTENTIAL_VAR_TYPE = new ArrayList<>();
+
static {
FORBIDEN_PARENT_CONTEXT_TO_DETECT_POTENTIAL_VAR_TYPE.addAll(Arrays.asList(ClassExpr.class));
}
@@ -49,23 +49,19 @@ public class Java10PostProcessor extends PostProcessors {
@Override
public void postProcess(ParseResult extends Node> result, ParserConfiguration configuration) {
result.getResult().ifPresent(node -> {
- node.findAll(ClassOrInterfaceType.class)
- .forEach(n -> {
- if ("var".equals(n.getNameAsString())
- && !matchForbiddenContext(n)) {
- n.replace(new VarType(n.getTokenRange().orElse(null)));
- }
+ node.findAll(ClassOrInterfaceType.class).forEach(n -> {
+ if ("var".equals(n.getNameAsString()) && !matchForbiddenContext(n)) {
+ n.replace(new VarType(n.getTokenRange().orElse(null)));
+ }
});
});
}
private boolean matchForbiddenContext(ClassOrInterfaceType cit) {
- return cit.getParentNode().isPresent()
- && FORBIDEN_PARENT_CONTEXT_TO_DETECT_POTENTIAL_VAR_TYPE.stream().anyMatch(cl -> cl.isInstance(cit.getParentNode().get()));
+ return cit.getParentNode().isPresent() && FORBIDEN_PARENT_CONTEXT_TO_DETECT_POTENTIAL_VAR_TYPE.stream().anyMatch(cl -> cl.isInstance(cit.getParentNode().get()));
}
};
-
public Java10PostProcessor() {
add(varNodeCreator);
}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java
index 05fdb31c50..2bb012d982 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java
@@ -21,7 +21,6 @@
package com.github.javaparser.ast.visitor;
import java.util.Optional;
-
import com.github.javaparser.ast.*;
import com.github.javaparser.ast.body.*;
import com.github.javaparser.ast.comments.BlockComment;
@@ -41,6 +40,7 @@
import com.github.javaparser.ast.modules.*;
import com.github.javaparser.ast.stmt.*;
import com.github.javaparser.ast.type.*;
+
/**
* A visitor that clones (copies) a node and all its children.
*/
@@ -268,6 +268,7 @@ public Visitable visit(final Parameter n, final Object arg) {
@Override
public Visitable visit(final InitializerDeclaration n, final Object arg) {
BlockStmt body = cloneNode(n.getBody(), arg);
+ NodeList annotations = cloneList(n.getAnnotations(), arg);
Comment comment = cloneNode(n.getComment(), arg);
InitializerDeclaration r = new InitializerDeclaration(n.getTokenRange().orElse(null), n.isStatic(), body);
r.setComment(comment);
@@ -338,6 +339,7 @@ public Visitable visit(final ArrayCreationLevel n, final Object arg) {
@Override
public Visitable visit(final IntersectionType n, final Object arg) {
NodeList elements = cloneList(n.getElements(), arg);
+ NodeList annotations = cloneList(n.getAnnotations(), arg);
Comment comment = cloneNode(n.getComment(), arg);
IntersectionType r = new IntersectionType(n.getTokenRange().orElse(null), elements);
r.setComment(comment);
@@ -349,6 +351,7 @@ public Visitable visit(final IntersectionType n, final Object arg) {
@Override
public Visitable visit(final UnionType n, final Object arg) {
NodeList elements = cloneList(n.getElements(), arg);
+ NodeList annotations = cloneList(n.getAnnotations(), arg);
Comment comment = cloneNode(n.getComment(), arg);
UnionType r = new UnionType(n.getTokenRange().orElse(null), elements);
r.setComment(comment);
@@ -359,6 +362,7 @@ public Visitable visit(final UnionType n, final Object arg) {
@Override
public Visitable visit(final VoidType n, final Object arg) {
+ NodeList annotations = cloneList(n.getAnnotations(), arg);
Comment comment = cloneNode(n.getComment(), arg);
VoidType r = new VoidType(n.getTokenRange().orElse(null));
r.setComment(comment);
@@ -382,6 +386,7 @@ public Visitable visit(final WildcardType n, final Object arg) {
@Override
public Visitable visit(final UnknownType n, final Object arg) {
+ NodeList annotations = cloneList(n.getAnnotations(), arg);
Comment comment = cloneNode(n.getComment(), arg);
UnknownType r = new UnknownType(n.getTokenRange().orElse(null));
r.setComment(comment);
@@ -1199,6 +1204,7 @@ public Visitable visit(final ReceiverParameter n, final Object arg) {
@Override
public Visitable visit(final VarType n, final Object arg) {
+ NodeList annotations = cloneList(n.getAnnotations(), arg);
Comment comment = cloneNode(n.getComment(), arg);
VarType r = new VarType(n.getTokenRange().orElse(null));
r.setComment(comment);
diff --git a/javaparser-core/src/main/java/com/github/javaparser/jml/JmlProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/jml/JmlProcessor.java
index c24a4d39e1..ed1e8e217a 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/jml/JmlProcessor.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/jml/JmlProcessor.java
@@ -144,9 +144,7 @@ public JmlDocDeclaration visit(JmlDocDeclaration n, Void arg) {
setJmlTags(t);
TypeDeclaration> parent = (TypeDeclaration>) n.getParentNode().get();
NodeList> members = parent.getMembers();
- int pos = IntStream.range(0, members.size())
- .filter(i -> members.get(i) == n)
- .findFirst().orElse(-1);
+ int pos = IntStream.range(0, members.size()).filter(i -> members.get(i) == n).findFirst().orElse(-1);
assert pos >= 0;
if (pos + 1 >= members.size()) {
//JML Documentation is last element, therefore it can only refer to upper element.
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java b/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java
index 7137871eaf..9db35b00b9 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java
@@ -103,10 +103,10 @@ private static CsmElement typeArguments() {
// FIXME: we should introduce a derived property
// FIXME: we should introduce a derived property
// FIXME: we should introduce a derived property
+ // FIXME: we should introduce a derived property
concreteSyntaxModelByClass.// FIXME: we should introduce a derived property
- put(// FIXME: we should introduce a derived property
- VariableDeclarator.class, // list(ObservableProperty.EXTRA_ARRAY_LEVELS),
- sequence(comment(), child(ObservableProperty.NAME), conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.ASSIGN), space(), child(ObservableProperty.INITIALIZER)))));
+ put(// list(ObservableProperty.EXTRA_ARRAY_LEVELS),
+ VariableDeclarator.class, sequence(comment(), child(ObservableProperty.NAME), conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.ASSIGN), space(), child(ObservableProperty.INITIALIZER)))));
// /
// / Expressions
// /
@@ -211,12 +211,12 @@ private static CsmElement typeArguments() {
concreteSyntaxModelByClass.put(JmlMultiExprClause.class, sequence(child(ObservableProperty.KIND), child(HEAPS), space(), child(EXPRESSION), semicolon(), newline()));
concreteSyntaxModelByClass.put(JmlClauseLabel.class, sequence(child(ObservableProperty.KIND), token(LPAREN), child(LABEL), token(RPAREN), space(), child(EXPRESSION), semicolon(), newline()));
//space(),
+ //space(),
concreteSyntaxModelByClass.//space(),
put(//space(),
JmlCallableClause.class, //space(),
- sequence(//space(),
- child(MODIFIERS), //child(EXPRESSION),
- token(CALLABLE), semicolon()));
+ sequence(//child(EXPRESSION),
+ child(MODIFIERS), token(CALLABLE), semicolon()));
concreteSyntaxModelByClass.put(JmlClassExprDeclaration.class, sequence(child(MODIFIERS), attribute(KIND), space(), attribute(NAME), token(COLON), child(EXPRESSION), semicolon()));
concreteSyntaxModelByClass.put(JmlBodyDeclaration.class, sequence());
concreteSyntaxModelByClass.put(JmlClassAccessibleDeclaration.class, sequence());
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 bdb92b5fb5..2333400e4d 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
@@ -23,11 +23,9 @@
import static com.github.javaparser.GeneratedJavaParserConstants.LBRACE;
import static com.github.javaparser.GeneratedJavaParserConstants.RBRACE;
import static com.github.javaparser.GeneratedJavaParserConstants.SPACE;
-
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.IntStream;
-
import com.github.javaparser.GeneratedJavaParserConstants;
import com.github.javaparser.JavaToken;
import com.github.javaparser.JavaToken.Kind;
@@ -111,13 +109,8 @@ List takeWhile(List prevElements, Predicate source) {
- return IntStream.range(0, source.size())
- .map(i -> source.size() - i - 1)
- .filter(i -> source.get(i).isNewline())
- .findFirst()
- .orElse(-1);
+ return IntStream.range(0, source.size()).map(i -> source.size() - i - 1).filter(i -> source.get(i).isNewline()).findFirst().orElse(-1);
}
/*
@@ -244,15 +237,11 @@ private int considerIndentation(NodeText nodeText, int nodeTextIndex, int number
}
private boolean isEnforcingIndentationActivable(RemovedGroup removedGroup) {
- return (isLastElement(diffElements, diffIndex) || !(nextDiffElement(diffElements, diffIndex).isAdded()))
- && originalIndex < originalElements.size()
- && !removedGroup.isACompleteLine();
+ return (isLastElement(diffElements, diffIndex) || !(nextDiffElement(diffElements, diffIndex).isAdded())) && originalIndex < originalElements.size() && !removedGroup.isACompleteLine();
}
private boolean isRemovingIndentationActivable(RemovedGroup removedGroup) {
- return (isLastElement(diffElements, diffIndex) || !(nextDiffElement(diffElements, diffIndex).isAdded()))
- && originalIndex < originalElements.size()
- && removedGroup.isACompleteLine();
+ return (isLastElement(diffElements, diffIndex) || !(nextDiffElement(diffElements, diffIndex).isAdded())) && originalIndex < originalElements.size() && removedGroup.isACompleteLine();
}
private boolean isLastElement(List> list, int index) {
@@ -268,7 +257,9 @@ private DifferenceElement nextDiffElement(List list, int inde
* and the number of consecutive whitespace (or tab) characters
*/
private class EnforcingIndentationContext {
+
int start;
+
int extraCharacters;
public EnforcingIndentationContext(int start) {
@@ -323,7 +314,7 @@ private EnforcingIndentationContext defineEnforcingIndentationContext(NodeText n
}
// compute space after the deleted element
if (startIndex < nodeText.numberOfElements() && isSpaceOrTabElement(nodeText, startIndex)) {
-// int startingFromIndex = startIndex == 0 ? startIndex : startIndex + 1;
+ // int startingFromIndex = startIndex == 0 ? startIndex : startIndex + 1;
for (int i = startIndex; i >= 0 && i < nodeText.numberOfElements(); i++) {
if (nodeText.getTextElement(i).isNewline()) {
break;
@@ -334,7 +325,6 @@ private EnforcingIndentationContext defineEnforcingIndentationContext(NodeText n
ctx.extraCharacters++;
}
}
-
return ctx;
}
@@ -500,9 +490,7 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed,
// The token corresponding to the annotation is the first element of the annotation node
// and it is also the first element of the parent node (MethodDeclaration),
// so the previous indentation is defined in the parent node of the method declaration.
- if (!parentNodeText.getElements().isEmpty()
- && parentNode.getParentNode().isPresent()
- && parentNodeText.getTextElement(0).equals(nodeText.getTextElement(originalIndex))) {
+ if (!parentNodeText.getElements().isEmpty() && parentNode.getParentNode().isPresent() && parentNodeText.getTextElement(0).equals(nodeText.getTextElement(originalIndex))) {
startingNodeForFindingIndentation = parentNode;
parentNodeText = LexicalPreservingPrinter.getOrCreateNodeText(parentNode.getParentNode().get());
}
@@ -547,8 +535,7 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed,
// the same line as a method declaration.
if (originalIndex == 0 && !indentationTokens.isEmpty() && !isInlined(nodeText, originalIndex)) {
for (TextElement indentationToken : indentationTokens) {
- parentNodeText.removeElement(
- parentNodeText.findElement(indentationToken.and(indentationToken.matchByRange())));
+ parentNodeText.removeElement(parentNodeText.findElement(indentationToken.and(indentationToken.matchByRange())));
}
}
}
@@ -560,13 +547,12 @@ private void applyRemovedDiffElement(RemovedGroup removedGroup, Removed removed,
if (isRemovingIndentationActivable(removedGroup)) {
originalIndex = considerRemovingIndentation(nodeText, originalIndex);
}
- } else if (removed.isToken() && originalElementIsToken && (removed.getTokenType() == ((TokenTextElement) originalElement).getTokenKind() || // handle EOLs separately as their token kind might not be equal. This is because the 'removed'
- // element always has the current operating system's EOL as type
- (((TokenTextElement) originalElement).getToken().getCategory().isEndOfLine() && removed.isNewLine()))) {
+ } else if (removed.isToken() && originalElementIsToken && (// handle EOLs separately as their token kind might not be equal. This is because the 'removed'
+ removed.getTokenType() == ((TokenTextElement) originalElement).getTokenKind() || // element always has the current operating system's EOL as type
+ (((TokenTextElement) originalElement).getToken().getCategory().isEndOfLine() && removed.isNewLine()))) {
nodeText.removeElement(originalIndex);
diffIndex++;
- } else if ((removed.isWhiteSpaceNotEol() || removed.getElement() instanceof CsmIndent || removed.getElement() instanceof CsmUnindent)
- && originalElement.isSpaceOrTab()) {
+ } else if ((removed.isWhiteSpaceNotEol() || removed.getElement() instanceof CsmIndent || removed.getElement() instanceof CsmUnindent) && originalElement.isSpaceOrTab()) {
// remove the current space
nodeText.removeElement(originalIndex);
} else if (originalElementIsToken && originalElement.isWhiteSpaceOrComment()) {
@@ -609,10 +595,7 @@ private void cleanTheLineOfLeftOverSpace(RemovedGroup removedGroup, Removed remo
}
// we dont want to remove the indentation if the last removed element is a newline
// because in this case we are trying to remove the indentation of the next child element
- if (!removedGroup.isProcessed()
- && removedGroup.isLastElement(removed)
- && removedGroup.isACompleteLine()
- && !removed.isNewLine()) {
+ if (!removedGroup.isProcessed() && removedGroup.isLastElement(removed) && removedGroup.isACompleteLine() && !removed.isNewLine()) {
Integer lastElementIndex = removedGroup.getLastElementIndex();
Optional indentation = removedGroup.getIndentation();
if (indentation.isPresent() && !isReplaced(lastElementIndex)) {
@@ -956,9 +939,7 @@ private void applyAddedDiffElement(Added added) {
boolean currentIsNewline = nodeText.getTextElement(originalIndex).isNewline();
boolean isFirstElement = originalIndex == 0;
boolean previousIsWhiteSpace = originalIndex > 0 && nodeText.getTextElement(originalIndex - 1).isWhiteSpace();
- boolean commentIsBeforeAddedElement = currentIsAComment && addedTextElement.getRange().isPresent()
- && nodeText.getTextElement(originalIndex).getRange()
- .map(range -> range.isBefore(addedTextElement.getRange().get())).orElse(false);
+ boolean commentIsBeforeAddedElement = currentIsAComment && addedTextElement.getRange().isPresent() && nodeText.getTextElement(originalIndex).getRange().map(range -> range.isBefore(addedTextElement.getRange().get())).orElse(false);
if (sufficientTokensRemainToSkip && currentIsAComment && commentIsBeforeAddedElement) {
// Need to get behind the comment:
// FIXME: Why 2? This comment and the next newline?
@@ -1020,6 +1001,7 @@ private void applyAddedDiffElement(Added added) {
* A list iterator which provides a method to know the current positioning
*/
public static class ArrayIterator implements ListIterator {
+
ListIterator iterator;
public ArrayIterator(List elements) {
@@ -1083,7 +1065,6 @@ public void add(T e) {
iterator.add(e);
;
}
-
}
/*
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 d6c5a5b82e..cff3d132fc 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
@@ -26,12 +26,10 @@
import static com.github.javaparser.utils.Utils.decapitalize;
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toList;
-
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.*;
-
import com.github.javaparser.JavaToken;
import com.github.javaparser.Range;
import com.github.javaparser.ast.DataKey;
@@ -134,10 +132,11 @@ public void concretePropertyChange(Node observedNode, ObservableProperty propert
if (property == ObservableProperty.COMMENT) {
Optional parentNode = observedNode.getParentNode();
NodeText nodeText = parentNode.map(parent -> getOrCreateNodeText(parentNode.get())).orElseGet(() -> getOrCreateNodeText(observedNode));
- if (oldValue == null) { // this case corresponds to the addition of a comment
- int index = parentNode.isPresent() ? // Find the position of the comment node and put in front of it the [...]
- nodeText.findChild(observedNode) : //
- 0;
+ if (oldValue == null) {
+ // this case corresponds to the addition of a comment
+ int index = // Find the position of the comment node and put in front of it the [...]
+ parentNode.isPresent() ? //
+ nodeText.findChild(observedNode) : 0;
/* Add the same indentation to the comment as the previous node
* for example if we want to add a comment on the body of the method declaration :
* Actual code
@@ -163,7 +162,8 @@ public void concretePropertyChange(Node observedNode, ObservableProperty propert
nodeText.addElement(index++, makeCommentToken((Comment) newValue));
nodeText.addToken(index, eolTokenKind(lineSeparator), lineSeparator.asRawString());
// code indentation after inserting an eol token may be wrong
- } else if (newValue == null) { // this case corresponds to a deletion of a comment
+ } else if (newValue == null) {
+ // this case corresponds to a deletion of a comment
if (oldValue instanceof Comment) {
if (((Comment) oldValue).isOrphan()) {
nodeText = getOrCreateNodeText(observedNode);
@@ -197,14 +197,17 @@ public void concretePropertyChange(Node observedNode, ObservableProperty propert
}
private boolean isCompleteLine(List elements, int index) {
- if (index <= 0 || index >= elements.size()) return false;
+ if (index <= 0 || index >= elements.size())
+ return false;
boolean isCompleteLine = true;
ListIterator iterator = elements.listIterator(index);
// verify if elements after the index are only spaces or tabs
while (iterator.hasNext()) {
TextElement textElement = iterator.next();
- if (textElement.isNewline()) break;
- if (textElement.isSpaceOrTab()) continue;
+ if (textElement.isNewline())
+ break;
+ if (textElement.isSpaceOrTab())
+ continue;
isCompleteLine = false;
break;
}
@@ -212,16 +215,18 @@ private boolean isCompleteLine(List elements, int index) {
iterator = elements.listIterator(index);
while (iterator.hasPrevious() && isCompleteLine) {
TextElement textElement = iterator.previous();
- if (textElement.isNewline()) break;
- if (textElement.isSpaceOrTab()) continue;
+ if (textElement.isNewline())
+ break;
+ if (textElement.isSpaceOrTab())
+ continue;
isCompleteLine = false;
}
-
return isCompleteLine;
}
private void removeAllExtraCharacters(List elements, int index) {
- if (index < 0 || index >= elements.size()) return;
+ if (index < 0 || index >= elements.size())
+ return;
removeAllExtraCharactersStartingFrom(elements.listIterator(index));
removeAllExtraCharactersBeforePosition(elements.listIterator(index));
}
@@ -290,13 +295,7 @@ private List findChildTextElementForComment(Comment oldValue,
matchingChildElements = selectMatchingChildElements(oldValue, nodeText);
if (matchingChildElements.size() > 1) {
// Duplicate child nodes found, refine the result
- matchingChildElements = matchingChildElements.stream()
- .filter(t -> t.getChild().hasRange() && oldValue.hasRange())
- .filter(t -> t.getChild().getRange().get().equals(oldValue.getRange().get())
- || (t.getChild().getComment().isPresent()
- && t.getChild().getComment().get().hasRange()
- && t.getChild().getComment().get().getRange().get().equals(oldValue.getRange().get())))
- .collect(toList());
+ matchingChildElements = matchingChildElements.stream().filter(t -> t.getChild().hasRange() && oldValue.hasRange()).filter(t -> t.getChild().getRange().get().equals(oldValue.getRange().get()) || (t.getChild().getComment().isPresent() && t.getChild().getComment().get().hasRange() && t.getChild().getComment().get().getRange().get().equals(oldValue.getRange().get()))).collect(toList());
}
if (matchingChildElements.size() != 1) {
throw new IllegalStateException("The matching child text element for the comment to be removed could not be found.");
@@ -306,8 +305,7 @@ private List findChildTextElementForComment(Comment oldValue,
private List selectMatchingChildElements(Comment oldValue, NodeText nodeText) {
List result = new ArrayList<>();
- List childTextElements = nodeText.getElements().stream().filter(e -> e.isChild())
- .map(c -> (ChildTextElement) c).collect(toList());
+ List childTextElements = nodeText.getElements().stream().filter(e -> e.isChild()).map(c -> (ChildTextElement) c).collect(toList());
ListIterator iterator = childTextElements.listIterator();
while (iterator.hasNext()) {
ChildTextElement textElement = iterator.next();
@@ -331,31 +329,15 @@ private boolean isSameComment(Comment childValue, Comment oldValue) {
private List findTokenTextElementForComment(Comment oldValue, NodeText nodeText) {
List matchingTokens;
if (oldValue instanceof JavadocComment) {
- matchingTokens = nodeText.getElements().stream()
- .filter(e -> e.isToken(JAVADOC_COMMENT))
- .map(e -> (TokenTextElement) e)
- .filter(t -> t.getText().equals(oldValue.asString()))
- .collect(toList());
+ matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(JAVADOC_COMMENT)).map(e -> (TokenTextElement) e).filter(t -> t.getText().equals(oldValue.asString())).collect(toList());
} else if (oldValue instanceof BlockComment) {
- matchingTokens = nodeText.getElements().stream()
- .filter(e -> e.isToken(MULTI_LINE_COMMENT))
- .map(e -> (TokenTextElement) e)
- .filter(t -> t.getText().equals(oldValue.asString()))
- .collect(toList());
+ matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(MULTI_LINE_COMMENT)).map(e -> (TokenTextElement) e).filter(t -> t.getText().equals(oldValue.asString())).collect(toList());
} else {
- matchingTokens = nodeText.getElements().stream()
- .filter(e -> e.isToken(SINGLE_LINE_COMMENT))
- .map(e -> (TokenTextElement) e)
- .filter(t -> t.getText().trim().equals((oldValue.asString()).trim()))
- .collect(toList());
+ matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(SINGLE_LINE_COMMENT)).map(e -> (TokenTextElement) e).filter(t -> t.getText().trim().equals((oldValue.asString()).trim())).collect(toList());
}
// To check that a comment matches in the list of tokens, if exists the range must be always checked,
// as comments with the same content may exist on different lines.
- return matchingTokens.stream()
- .filter(t -> (!t.getToken().hasRange() && !oldValue.hasRange())
- || (t.getToken().hasRange() && oldValue.hasRange()
- && t.getToken().getRange().get().equals(oldValue.getRange().get())))
- .collect(toList());
+ return matchingTokens.stream().filter(t -> (!t.getToken().hasRange() && !oldValue.hasRange()) || (t.getToken().hasRange() && oldValue.hasRange() && t.getToken().getRange().get().equals(oldValue.getRange().get()))).collect(toList());
}
/**
@@ -516,7 +498,6 @@ public static String print(Node node) {
final NodeText nodeText = getOrCreateNodeText(node);
nodeText.getElements().forEach(element -> element.accept(visitor));
return visitor.toString();
-
}
//
@@ -591,8 +572,8 @@ private static NodeText interpret(Node node, CsmElement csm, NodeText nodeText)
if (!comment.hasRange()) {
LineSeparator lineSeparator = node.getLineEndingStyleOrDefault(LineSeparator.SYSTEM);
calculatedSyntaxModel.elements.add(0, new CsmToken(eolTokenKind(lineSeparator), lineSeparator.asRawString()));
- calculatedSyntaxModel.elements.add(0,new CsmChild(comment));
- }
+ calculatedSyntaxModel.elements.add(0, new CsmChild(comment));
+ }
});
for (CsmElement element : calculatedSyntaxModel.elements) {
if (element instanceof CsmIndent) {
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java
index 5e19065d8c..74b015e036 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java
@@ -21,7 +21,6 @@
package com.github.javaparser.printer.lexicalpreservation.changes;
import java.util.Optional;
-
import com.github.javaparser.Range;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.NodeList;
@@ -64,8 +63,7 @@ public Object getValue(ObservableProperty property, Node node) {
// which deletes the relationship between a node and its parent node.
// This relationship is necessary to reinforce indentation, for example when
// deleting a node, as indentation can be carried by the parent node.
- currentNodeList.stream().filter(n -> !isSameNode(currentNodeList.get(index), n))
- .forEach(selectedNode -> newNodeList.add(selectedNode));
+ currentNodeList.stream().filter(n -> !isSameNode(currentNodeList.get(index), n)).forEach(selectedNode -> newNodeList.add(selectedNode));
return newNodeList;
}
return new NoChange().getValue(property, node);
@@ -76,8 +74,7 @@ private boolean isSameNode(Node n1, Node n2) {
}
private boolean isSameRange(Node n1, Node n2) {
- return (!n1.hasRange() && !n2.hasRange())
- || (n1.hasRange() && n2.hasRange() && isSameRange(n1.getRange().get(), n2.getRange().get()));
+ return (!n1.hasRange() && !n2.hasRange()) || (n1.hasRange() && n2.hasRange() && isSameRange(n1.getRange().get(), n2.getRange().get()));
}
private boolean isSameRange(Range r1, Range r2) {
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java
index 112414bc6e..61dfa847b3 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java
@@ -24,7 +24,6 @@
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
-
import com.github.javaparser.ast.AccessSpecifier;
import com.github.javaparser.resolution.MethodUsage;
import com.github.javaparser.resolution.UnsolvedSymbolException;
@@ -37,8 +36,11 @@
public interface ResolvedReferenceTypeDeclaration extends ResolvedTypeDeclaration, ResolvedTypeParametrizable {
String JAVA_LANG_ENUM = java.lang.Enum.class.getCanonicalName();
+
String JAVA_LANG_COMPARABLE = java.lang.Comparable.class.getCanonicalName();
+
String JAVA_IO_SERIALIZABLE = Serializable.class.getCanonicalName();
+
String JAVA_LANG_OBJECT = java.lang.Object.class.getCanonicalName();
@Override
@@ -293,12 +295,7 @@ default boolean hasAnnotation(String qualifiedName) {
if (hasDirectlyAnnotation(qualifiedName)) {
return true;
}
- return isClass() && getAllAncestors().stream()
- .filter(it -> it.asReferenceType().getTypeDeclaration().isPresent())
- .filter(it -> it.asReferenceType().getTypeDeclaration().get().isClass())
- .map(it -> it.asReferenceType().getTypeDeclaration().get())
- .anyMatch(rrtd -> rrtd.hasDirectlyAnnotation(qualifiedName)
- && rrtd.isInheritedAnnotation(qualifiedName));
+ return isClass() && getAllAncestors().stream().filter(it -> it.asReferenceType().getTypeDeclaration().isPresent()).filter(it -> it.asReferenceType().getTypeDeclaration().get().isClass()).map(it -> it.asReferenceType().getTypeDeclaration().get()).anyMatch(rrtd -> rrtd.hasDirectlyAnnotation(qualifiedName) && rrtd.isInheritedAnnotation(qualifiedName));
}
/**
@@ -313,9 +310,7 @@ default boolean isInheritedAnnotation(String name) {
* Returns the resolved annotation corresponding to the specified name and declared in this type declaration.
*/
default Optional getDeclaredAnnotation(String name) {
- return getDeclaredAnnotations().stream()
- .filter(annotation -> annotation.getQualifiedName().endsWith(name))
- .findFirst();
+ return getDeclaredAnnotations().stream().filter(annotation -> annotation.getQualifiedName().endsWith(name)).findFirst();
}
/**
@@ -325,7 +320,6 @@ default Set getDeclaredAnnotations() {
throw new UnsupportedOperationException("Getting declared annotation is not supproted on this type " + this.getName());
}
-
/**
* This means that the type has a functional method. Conceptually, a functional interface has exactly one abstract method.
* Typically these classes has the FunctionInterface annotation but this is not mandatory.
@@ -359,8 +353,8 @@ default Optional findTypeParameter(String name
* @see https://github.com/javaparser/javaparser/issues/2044
*/
default boolean isJavaLangObject() {
- return this.isClass() && !isAnonymousClass() && // Consider anonymous classes
- hasName() && JAVA_LANG_OBJECT.equals(getQualifiedName());
+ return // Consider anonymous classes
+ this.isClass() && !isAnonymousClass() && hasName() && JAVA_LANG_OBJECT.equals(getQualifiedName());
}
/**
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/FunctionalInterfaceLogic.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/FunctionalInterfaceLogic.java
index 23eb88a9f9..25fafe5058 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/FunctionalInterfaceLogic.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/FunctionalInterfaceLogic.java
@@ -63,10 +63,10 @@ public static Optional getFunctionalMethod(ResolvedReferenceTypeDec
// Remove methods inherited by Object:
Set // Remove methods inherited by Object:
// Consider the case of Comparator which define equals. It would be considered a functional method.
+ // TODO a functional interface can have multiple subsignature method with a return-type-substitutable
methods = // TODO a functional interface can have multiple subsignature method with a return-type-substitutable
typeDeclaration.getAllMethods().stream().filter(m -> m.getDeclaration().isAbstract()).// TODO a functional interface can have multiple subsignature method with a return-type-substitutable
- filter(// TODO a functional interface can have multiple subsignature method with a return-type-substitutable
- m -> !isPublicMemberOfObject(m)).collect(Collectors.toSet());
+ filter(m -> !isPublicMemberOfObject(m)).collect(Collectors.toSet());
// see https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.8
if (methods.size() == 0) {
return Optional.empty();
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java
index e7d9431388..14a58b97f3 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java
@@ -509,10 +509,10 @@ public static SymbolReference findMostApplicable(List
// Only consider methods with a matching name
List // Only consider methods with a matching name
// Filters out duplicate ResolvedMethodDeclaration by their signature.
- applicableMethods = // Filters out duplicate ResolvedMethodDeclaration by their signature.
+ // Filters out duplicate ResolvedMethodDeclaration by their signature.
+ applicableMethods = // Checks if ResolvedMethodDeclaration is applicable to argumentsTypes.
methods.stream().// Checks if ResolvedMethodDeclaration is applicable to argumentsTypes.
- filter(// Checks if ResolvedMethodDeclaration is applicable to argumentsTypes.
- m -> m.getName().equals(name)).filter(distinctByKey(ResolvedMethodDeclaration::getQualifiedSignature)).filter((m) -> isApplicable(m, name, argumentsTypes, typeSolver, wildcardTolerance)).collect(Collectors.toList());
+ filter(m -> m.getName().equals(name)).filter(distinctByKey(ResolvedMethodDeclaration::getQualifiedSignature)).filter((m) -> isApplicable(m, name, argumentsTypes, typeSolver, wildcardTolerance)).collect(Collectors.toList());
// If no applicable methods found, return as unsolved.
if (applicableMethods.isEmpty()) {
return SymbolReference.unsolved();
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java
index ceb44a564a..7c1d8fbb85 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java
@@ -23,7 +23,6 @@
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
-
import com.github.javaparser.ast.AccessSpecifier;
import com.github.javaparser.resolution.MethodUsage;
import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration;
@@ -90,17 +89,14 @@ public boolean equals(Object o) {
return true;
if (o == null)
return false;
-
if (o instanceof LazyType) {
final LazyType lazyType = (LazyType) o;
if (!lazyType.isReferenceType())
return false;
return this.equals(lazyType.asReferenceType());
}
-
if (getClass() != o.getClass())
return false;
-
ResolvedReferenceType that = (ResolvedReferenceType) o;
if (!typeDeclaration.equals(that.typeDeclaration))
return false;
@@ -524,8 +520,8 @@ private static List deriveParams(ResolvedReferenceTypeDeclaration
* @see https://github.com/javaparser/javaparser/issues/2044
*/
public boolean isJavaLangObject() {
- return this.isReferenceType() && // Consider anonymous classes
- hasName() && getQualifiedName().equals(JAVA_LANG_OBJECT);
+ return // Consider anonymous classes
+ this.isReferenceType() && hasName() && getQualifiedName().equals(JAVA_LANG_OBJECT);
}
/**
@@ -533,8 +529,8 @@ public boolean isJavaLangObject() {
* @see ResolvedReferenceTypeDeclaration#isJavaLangEnum()
*/
public boolean isJavaLangEnum() {
- return this.isReferenceType() && // Consider anonymous classes
- hasName() && getQualifiedName().equals(JAVA_LANG_ENUM);
+ return // Consider anonymous classes
+ this.isReferenceType() && hasName() && getQualifiedName().equals(JAVA_LANG_ENUM);
}
// /
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java
index 24fa37ae15..534a9b337b 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java
@@ -25,7 +25,6 @@
import java.io.Reader;
import java.util.*;
import java.util.function.Function;
-
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.expr.UnaryExpr;
@@ -224,15 +223,15 @@ public static boolean valueIsNullOrEmptyStringOrOptional(Object value) {
if (value == null) {
return true;
}
-// // is not Optional?
-// if (!(value instanceof Optional)) {
-// return false;
-// }
-// // is an empty Optional?
-// if (!((Optional) value).isPresent()) {
-// return true;
-// }
-// return false;
+ // // is not Optional?
+ // if (!(value instanceof Optional)) {
+ // return false;
+ // }
+ // // is an empty Optional?
+ // if (!((Optional) value).isPresent()) {
+ // return true;
+ // }
+ // return false;
return value instanceof Optional ? !((Optional) value).isPresent() : false;
}