Skip to content

Commit

Permalink
Minor: Cleanup, proper method name, @nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianSchuette committed Jul 16, 2020
1 parent 458867c commit 90d6675
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main/java/de/fraunhofer/aisec/cpg/graph/type/TypeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Class responsible for parsing the type definition and create the same Type as described by the
Expand Down Expand Up @@ -227,7 +229,8 @@ private static int findMatching(char openBracket, char closeBracket, String stri
* @param type separated type string
* @return true if function pointer structure is found in typeString, false if not
*/
private static Matcher isFunctionPointer(List<String> type) {
@Nullable
private static Matcher getFunctionPtrMatcher(@NonNull List<String> type) {

StringBuilder typeStringBuilder = new StringBuilder();
for (String typePart : type) {
Expand Down Expand Up @@ -313,7 +316,8 @@ private static void processBlockUntilLastSplit(
* @param type string with the entire type definition
* @return list of strings in which every piece of type information is one element of the list
*/
public static List<String> separate(String type) {
@NonNull
public static List<String> separate(@NonNull String type) {

// Remove :: CPP operator, use . instead
type = type.replace("::", ".");
Expand Down Expand Up @@ -661,7 +665,7 @@ private static ObjectType.Modifier determineModifier(
* @param resolveAlias should replace with original type in typedefs
* @return new type representing the type string
*/
public static Type createFrom(String type, boolean resolveAlias) {
public static Type createFrom(@NonNull String type, boolean resolveAlias) {
// Check if Problems during Parsing
if (type.contains("?")
|| type.contains("org.eclipse.cdt.internal.core.dom.parser.ProblemType@")
Expand Down Expand Up @@ -713,8 +717,7 @@ public static Type createFrom(String type, boolean resolveAlias) {

// Once all preceding known keywords (if any) are handled the next word must be the TypeName
if (counter >= typeBlocks.size()) {
// TODO Note that "const auto bla = ..." will end here with typeName="const" as "auto" is not
// supported.
// Note that "const auto ..." will end here with typeName="const" as auto is not supported.
return UnknownType.getUnknownType();
}
assert counter < typeBlocks.size();
Expand All @@ -725,7 +728,7 @@ public static Type createFrom(String type, boolean resolveAlias) {
TypeManager typeManager = TypeManager.getInstance();

// Check if type is FunctionPointer
Matcher funcptr = isFunctionPointer(typeBlocks.subList(counter, typeBlocks.size()));
Matcher funcptr = getFunctionPtrMatcher(typeBlocks.subList(counter, typeBlocks.size()));

if (funcptr != null) {
Type returnType = createFrom(typeName, false);
Expand Down

0 comments on commit 90d6675

Please sign in to comment.