Skip to content

Commit

Permalink
Fix Regex
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmaisch committed Mar 23, 2024
1 parent 9c25f9f commit b2fc2f1
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -22,7 +23,6 @@
* This class contains methods to put a call graph oriented order on methods.
*/
public class MethodOrderStrategy {
private static final String START_OF_GENERIC_CLASS = ".*class\\s*\\w+\\s*<.*";
private static final Logger logger = LoggerFactory.getLogger(MethodOrderStrategy.class);
private final NodeOrderStrategy nodeOrderStrategy;
private int index;
Expand Down Expand Up @@ -126,8 +126,13 @@ private static boolean isGeneric(Type type) {
String code = recordDeclaration.getCode();
if (Objects.isNull(code))
return false;
String firstLine = code.split("\\{")[0];
return firstLine.matches(START_OF_GENERIC_CLASS);
OptionalInt cutOffIndex = Stream.of("{", "implements", "extends").mapToInt(code::indexOf).filter(i -> i > 0).min();
if (cutOffIndex.isEmpty()) {
return false;
}
String firstLine = code.substring(0, cutOffIndex.getAsInt());
// does it contain an angle bracket as a start for type parameters?
return firstLine.contains("<");
}

private static List<MethodDeclaration> getSuperConstructorCandidates(MethodDeclaration methodDeclaration, CallExpression call) {
Expand Down

0 comments on commit b2fc2f1

Please sign in to comment.