Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove Optional since buildClassFrom always finds a class #1145

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public synchronized Optional<JavaSootClass> getClass(

if (!foundClassSources.isEmpty()) {

return buildClassFrom(foundClassSources.get(0));
return Optional.of(buildClassFrom(foundClassSources.get(0)));
} else {
PackageName packageName = type.getPackageName();
if (packageName instanceof ModulePackageName
Expand All @@ -189,7 +189,7 @@ public synchronized Optional<JavaSootClass> getClass(
.collect(Collectors.toList());

if (!foundClassSources.isEmpty()) {
return buildClassFrom(foundClassSources.get(0));
return Optional.of(buildClassFrom(foundClassSources.get(0)));
} else {
// automatic module can access the unnamed module -> try to find in classpath (as if
// modules do not exist)
Expand Down Expand Up @@ -231,7 +231,7 @@ public synchronized Optional<JavaSootClass> getClass(
})
.findAny();

return foundClassSources.flatMap(this::buildClassFrom);
return foundClassSources.map(this::buildClassFrom);
}
}

Expand Down Expand Up @@ -333,11 +333,7 @@ public synchronized Collection<JavaSootClass> getModuleClasses(
.map(src -> (JavaSootClassSource) src));
}
}
return stream
.map(this::buildClassFrom)
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
return stream.map(this::buildClassFrom).collect(Collectors.toList());
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ public synchronized Stream<JavaSootClass> getClasses() {
Stream<JavaSootClass> resolvedClasses =
inputLocations.stream()
.flatMap(location -> location.getClassSources(this).stream())
.map(this::buildClassFrom)
.filter(Optional::isPresent)
.map(Optional::get);
.map(this::buildClassFrom);

isFullyResolved = true;

Expand All @@ -107,7 +105,7 @@ public synchronized Optional<JavaSootClass> getClass(@Nonnull ClassType type) {
}

Optional<JavaSootClassSource> abstractClass = getClassSource(type);
return abstractClass.flatMap(this::buildClassFrom);
return abstractClass.map(this::buildClassFrom);
}

@Nonnull
Expand Down Expand Up @@ -155,7 +153,7 @@ protected Optional<JavaSootClassSource> getClassSource(@Nonnull ClassType type)
}

@Nonnull
protected synchronized Optional<JavaSootClass> buildClassFrom(AbstractClassSource classSource) {
protected synchronized JavaSootClass buildClassFrom(AbstractClassSource classSource) {

ClassType classType = classSource.getClassType();
JavaSootClass theClass;
Expand All @@ -167,6 +165,6 @@ protected synchronized Optional<JavaSootClass> buildClassFrom(AbstractClassSourc
classSource.buildClass(classSource.getAnalysisInputLocation().getSourceType());
cache.putClass(classType, theClass);
}
return Optional.of(theClass);
return theClass;
}
}
Loading