-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor
AnalysisInputLocation
s Collection getClassSources(...)
t…
…o `Stream getClassSources(...) -> passing the Autoclosable object to the callers to avoid collecting streams and re-stream() them in the meantime
- Loading branch information
Showing
37 changed files
with
492 additions
and
472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...java/sootup/java/bytecode/frontend/inputlocation/ClassFileBasedAnalysisInputLocation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package sootup.java.bytecode.frontend.inputlocation; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
import javax.annotation.Nonnull; | ||
import org.apache.commons.io.FilenameUtils; | ||
import sootup.core.IdentifierFactory; | ||
import sootup.core.model.SourceType; | ||
import sootup.core.transform.BodyInterceptor; | ||
import sootup.core.types.ClassType; | ||
import sootup.core.views.View; | ||
import sootup.interceptors.BytecodeBodyInterceptors; | ||
import sootup.java.bytecode.frontend.conversion.AsmJavaClassProvider; | ||
import sootup.java.core.JavaSootClassSource; | ||
import sootup.java.core.types.JavaClassType; | ||
|
||
public class ClassFileBasedAnalysisInputLocation extends PathBasedAnalysisInputLocation { | ||
|
||
@Nonnull private final String omittedPackageName; | ||
|
||
public ClassFileBasedAnalysisInputLocation( | ||
@Nonnull Path classFilePath, | ||
@Nonnull String omittedPackageName, | ||
@Nonnull SourceType srcType) { | ||
this( | ||
classFilePath, | ||
omittedPackageName, | ||
srcType, | ||
BytecodeBodyInterceptors.Default.getBodyInterceptors()); | ||
} | ||
|
||
public ClassFileBasedAnalysisInputLocation( | ||
@Nonnull Path classFilePath, | ||
@Nonnull String omittedPackageName, | ||
@Nonnull SourceType srcType, | ||
@Nonnull List<BodyInterceptor> bodyInterceptors) { | ||
super(classFilePath, srcType, bodyInterceptors); | ||
this.omittedPackageName = omittedPackageName; | ||
|
||
if (!Files.isRegularFile(classFilePath)) { | ||
throw new IllegalArgumentException("Needs to point to a regular file!"); | ||
} | ||
|
||
if (Files.isDirectory(classFilePath)) { | ||
throw new IllegalArgumentException("Needs to point to a regular file - not to a directory."); | ||
} | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public Optional<JavaSootClassSource> getClassSource(@Nonnull ClassType type, @Nonnull View view) { | ||
|
||
if (!type.getPackageName().getName().startsWith(omittedPackageName)) { | ||
return Optional.empty(); | ||
} | ||
|
||
return getSingleClass((JavaClassType) type, path, new AsmJavaClassProvider(view)); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public Stream<JavaSootClassSource> getClassSources(@Nonnull View view) { | ||
AsmJavaClassProvider classProvider = new AsmJavaClassProvider(view); | ||
IdentifierFactory factory = view.getIdentifierFactory(); | ||
Path dirPath = this.path.getParent(); | ||
|
||
final String fullyQualifiedName = fromPath(dirPath, path); | ||
|
||
Optional<JavaSootClassSource> javaSootClassSource = | ||
classProvider | ||
.createClassSource(this, path, factory.getClassType(fullyQualifiedName)) | ||
.map(src -> (JavaSootClassSource) src); | ||
|
||
return Stream.of(javaSootClassSource.get()); | ||
} | ||
|
||
@Nonnull | ||
protected String fromPath(@Nonnull Path baseDirPath, Path packageNamePathAndClass) { | ||
String str = | ||
FilenameUtils.removeExtension( | ||
packageNamePathAndClass | ||
.subpath(baseDirPath.getNameCount(), packageNamePathAndClass.getNameCount()) | ||
.toString() | ||
.replace(packageNamePathAndClass.getFileSystem().getSeparator(), ".")); | ||
|
||
return omittedPackageName.isEmpty() ? str : omittedPackageName + "." + str; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...java/sootup/java/bytecode/frontend/inputlocation/DirectoryBasedAnalysisInputLocation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package sootup.java.bytecode.frontend.inputlocation; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
import javax.annotation.Nonnull; | ||
import sootup.core.model.SourceType; | ||
import sootup.core.transform.BodyInterceptor; | ||
import sootup.core.types.ClassType; | ||
import sootup.core.views.View; | ||
import sootup.java.bytecode.frontend.conversion.AsmJavaClassProvider; | ||
import sootup.java.core.JavaSootClassSource; | ||
import sootup.java.core.types.JavaClassType; | ||
|
||
class DirectoryBasedAnalysisInputLocation extends PathBasedAnalysisInputLocation { | ||
|
||
protected DirectoryBasedAnalysisInputLocation( | ||
@Nonnull Path path, | ||
@Nonnull SourceType srcType, | ||
@Nonnull List<BodyInterceptor> bodyInterceptors) { | ||
this(path, srcType, bodyInterceptors, Collections.emptyList()); | ||
} | ||
|
||
protected DirectoryBasedAnalysisInputLocation( | ||
@Nonnull Path path, | ||
@Nonnull SourceType srcType, | ||
@Nonnull List<BodyInterceptor> bodyInterceptors, | ||
@Nonnull Collection<Path> ignoredPaths) { | ||
super(path, srcType, bodyInterceptors, ignoredPaths); | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public Stream<JavaSootClassSource> getClassSources(@Nonnull View view) { | ||
// FIXME: 1) store the classprovider reference as a field; 2) and above too; and 3) move view | ||
// which is only used in SootNode to be just there? | ||
return walkDirectory(path, view.getIdentifierFactory(), new AsmJavaClassProvider(view)); | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public Optional<JavaSootClassSource> getClassSource(@Nonnull ClassType type, @Nonnull View view) { | ||
return getClassSourceInternal((JavaClassType) type, path, new AsmJavaClassProvider(view)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.