Skip to content

Commit

Permalink
remove Optional since buildClassFrom always builds a class
Browse files Browse the repository at this point in the history
  • Loading branch information
Liyw979 committed Dec 7, 2024
1 parent dec694a commit 6080645
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
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
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;
}
}

0 comments on commit 6080645

Please sign in to comment.