-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve subclass exploration do not include generic interfaces add ja…
…vadoc
- Loading branch information
1 parent
7ff0b65
commit 50c2f40
Showing
4 changed files
with
52 additions
and
42 deletions.
There are no files selected for viewing
25 changes: 16 additions & 9 deletions
25
...n/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/CustomClassResolver.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 |
---|---|---|
@@ -1,34 +1,41 @@ | ||
package de.tum.cit.ase.ares.api.architecturetest.java.postcompile; | ||
|
||
import com.tngtech.archunit.core.domain.JavaClass; | ||
import com.tngtech.archunit.core.domain.JavaClasses; | ||
import com.tngtech.archunit.core.importer.ClassFileImporter; | ||
import com.tngtech.archunit.core.importer.ImportOption; | ||
|
||
import java.net.URL; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Custom class resolver to resolve classes that are outside classpath to be able to analyze them transitively. | ||
*/ | ||
public class CustomClassResolver { | ||
|
||
private CustomClassResolver() { | ||
throw new IllegalStateException("Utility class"); | ||
} | ||
|
||
/** | ||
* Class file importer to import the class files. | ||
* This is used to import the class files from the URL. | ||
*/ | ||
private static final ClassFileImporter classFileImporter = new ClassFileImporter(); | ||
private final JavaClasses allClasses; | ||
|
||
public CustomClassResolver() { | ||
allClasses = new ClassFileImporter() | ||
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS) | ||
.withImportOption(location -> location.toString().contains("jrt:/")) | ||
.importClasspath(); | ||
} | ||
|
||
/** | ||
* Try to resolve the class by the given type name. | ||
* | ||
* @param typeName The type name of the class to resolve. | ||
* @return The resolved class if it exists. | ||
*/ | ||
public static Optional<JavaClass> tryResolve(String typeName) { | ||
URL url = CustomClassResolver.class.getResource("/" + typeName.replace(".", "/") + ".class"); | ||
return url != null ? Optional.of(classFileImporter.importUrl(url).get(typeName)) : Optional.empty(); | ||
public Optional<JavaClass> tryResolve(String typeName) { | ||
try { | ||
return Optional.ofNullable(allClasses.get(typeName)); | ||
} catch (IllegalArgumentException e) { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
# Set to false to ignore missing dependencies in the classpath, as they are resolved manually by the de.tum.cit.ase.ares.api.architecturetest.java.postcompile.CustomClassResolver | ||
resolveMissingDependenciesFromClassPath=false |