Skip to content

Commit

Permalink
Merge pull request #1145 from Liyw979/improve/buildClassFrom
Browse files Browse the repository at this point in the history
remove Optional since buildClassFrom always finds a class
  • Loading branch information
swissiety authored Jan 6, 2025
2 parents ec86625 + 45420f5 commit f55a0ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 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 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;
}
}

0 comments on commit f55a0ca

Please sign in to comment.