Skip to content

Commit

Permalink
Apply spotless checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sarpsahinalp committed May 1, 2024
1 parent 6519fde commit a3a9288
Show file tree
Hide file tree
Showing 6 changed files with 452 additions and 455 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public class UnwantedNodesAssert extends AbstractAssert<UnwantedNodesAssert, Pat
private final LanguageLevel level;

/**
* Whether to enable the main method for the Java parser
* Default is set to false
* Whether to enable the main method for the Java parser Default is set to false
*/
private final boolean excludeMainMethod;

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/de/tum/in/test/api/ast/model/JavaFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import java.util.*;
import java.util.stream.*;

import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.MethodDeclaration;
import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;
import org.slf4j.*;

import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.MethodDeclaration;

/**
* Stores all required information about a Java file to be analyzed
Expand All @@ -37,11 +37,11 @@ public JavaFile(Path javaFilePath, CompilationUnit javaFileAST, boolean excludeM
}

private static void excludeMainMethod(CompilationUnit javaFileAST) {
javaFileAST.findAll(MethodDeclaration.class)
.stream()
.filter(method -> method.isStatic() && method.getNameAsString().equals("main") && method.getParameters().size() == 1 && method.getType().isVoidType() && method.getParameter(0).getTypeAsString().equals("String[]"))
.findAny()
.ifPresent(Node::remove);
javaFileAST.findAll(MethodDeclaration.class).stream()
.filter(method -> method.isStatic() && method.getNameAsString().equals("main")
&& method.getParameters().size() == 1 && method.getType().isVoidType()
&& method.getParameter(0).getTypeAsString().equals("String[]"))
.findAny().ifPresent(Node::remove);
}

public Path getJavaFilePath() {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/de/tum/in/test/api/ast/model/UnwantedNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public List<NodePosition> getUnwantedNodePositions() {
* UnwantedNode objects)
*/
public static List<UnwantedNode> getUnwantedNodesInJavaFile(JavaFile javaFile,
Map<String, Class<? extends Node>> nodesDefinedAsUnwanted) {
Map<String, Class<? extends Node>> nodesDefinedAsUnwanted) {
return nodesDefinedAsUnwanted.keySet().stream()
.map(unwantedNodeName -> new UnwantedNode(javaFile, unwantedNodeName,
nodesDefinedAsUnwanted.get(unwantedNodeName)))
Expand All @@ -62,7 +62,7 @@ public static List<UnwantedNode> getUnwantedNodesInJavaFile(JavaFile javaFile,
* information (packed into UnwantedNode objects)
*/
public static Map<Path, List<UnwantedNode>> getUnwantedNodesForFileAt(Path pathOfJavaFile,
Map<String, Class<? extends Node>> nodesDefinedAsUnwanted, boolean excludeMainMethod) {
Map<String, Class<? extends Node>> nodesDefinedAsUnwanted, boolean excludeMainMethod) {
JavaFile javaFile = JavaFile.convertFromFile(pathOfJavaFile, excludeMainMethod);
if (javaFile == null) {
return Map.of();
Expand Down Expand Up @@ -113,9 +113,9 @@ public static String getFormattedFileString(Path filePath, Map<Path, List<Unwant
* @return Error message
*/
public static Optional<String> getMessageForUnwantedNodesForFileAt(Path pathOfJavaFile,
Map<String, Class<? extends Node>> nodeNameUnwantedNodeMap, boolean excludeMainMethod) {
Map<Path, List<UnwantedNode>> unwantedNodes = getUnwantedNodesForFileAt(pathOfJavaFile,
nodeNameUnwantedNodeMap, excludeMainMethod);
Map<String, Class<? extends Node>> nodeNameUnwantedNodeMap, boolean excludeMainMethod) {
Map<Path, List<UnwantedNode>> unwantedNodes = getUnwantedNodesForFileAt(pathOfJavaFile, nodeNameUnwantedNodeMap,
excludeMainMethod);
if (unwantedNodes.isEmpty()) {
return Optional.empty();
}
Expand All @@ -132,7 +132,7 @@ public static Optional<String> getMessageForUnwantedNodesForFileAt(Path pathOfJa
* @return Error message
*/
public static Optional<String> getMessageForUnwantedNodesForAllFilesBelow(Path pathOfDirectory,
Map<String, Class<? extends Node>> nodeNameUnwantedNodeMap, boolean excludeMainMethod) {
Map<String, Class<? extends Node>> nodeNameUnwantedNodeMap, boolean excludeMainMethod) {
return JavaFile.readFromDirectory(pathOfDirectory, excludeMainMethod).stream()
.sorted(Comparator.comparing(JavaFile::getJavaFilePath))
.map(javaFile -> getMessageForUnwantedNodesForFileAt(javaFile.getJavaFilePath(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ void test_testExcludeMain_Fail() {
testFailedWith(testExcludeMain_Fail, AssertionError.class,
"Unwanted statement found:" + System.lineSeparator() + " - In "
+ Path.of("src", "test", "java", "de", "tum", "in", "test", "integration",
"testuser", "subject", "structural", "astTestFiles", "excludeMain", "yes",
"ClassWithLoopOutsideMainMethod.java")
"testuser", "subject", "structural", "astTestFiles", "excludeMain", "yes",
"ClassWithLoopOutsideMainMethod.java")
+ ":" + System.lineSeparator() + " - For-Statement was found:"
+ System.lineSeparator() + " - Between line 6 (column 3) and line 8 (column 3)"));
}
Expand Down
Loading

0 comments on commit a3a9288

Please sign in to comment.