-
-
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.
Merge pull request #1163 from soot-oss/streamify/AnalysisInputLocation
Streamify AnalysisInputLocation getClasses
- Loading branch information
Showing
39 changed files
with
565 additions
and
476 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
113 changes: 113 additions & 0 deletions
113
...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,113 @@ | ||
package sootup.java.bytecode.frontend.inputlocation; | ||
|
||
/*- | ||
* #%L | ||
* SootUp | ||
* %% | ||
* Copyright (C) 1997 - 2024 Raja Vallée-Rai and others | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 2.1 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Lesser Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Lesser Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
* #L% | ||
*/ | ||
|
||
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
70 changes: 70 additions & 0 deletions
70
...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,70 @@ | ||
package sootup.java.bytecode.frontend.inputlocation; | ||
|
||
/*- | ||
* #%L | ||
* Soot | ||
* %% | ||
* Copyright (C) 2018-2020 Manuel Benz, Christian Brüggemann, Markus Schmidt and others | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 2.1 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Lesser Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Lesser Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
* #L% | ||
*/ | ||
|
||
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)); | ||
} | ||
} |
Oops, something went wrong.