Skip to content

Commit d412d65

Browse files
committed
add JavaClass.isImported()
Signed-off-by: Manfred Hanke <[email protected]>
1 parent 582d50b commit d412d65

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

archunit/src/main/java/com/tngtech/archunit/core/domain/JavaClass.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public Set<JavaMember> get() {
9999
}
100100
});
101101
private JavaClassDependencies javaClassDependencies = new JavaClassDependencies(this); // just for stubs; will be overwritten for imported classes
102+
private boolean imported = false;
102103

103104
JavaClass(JavaClassBuilder builder) {
104105
source = checkNotNull(builder.getSource());
@@ -1082,6 +1083,14 @@ public Set<JavaAnnotation<?>> getAnnotationsWithTypeOfSelf() {
10821083
return javaClassDependencies.getAnnotationsWithTypeOfClass();
10831084
}
10841085

1086+
/**
1087+
* @return Whether this class has actually been imported (or is just a stub).
1088+
*/
1089+
@PublicAPI(usage = ACCESS)
1090+
public boolean isImported() {
1091+
return imported;
1092+
}
1093+
10851094
/**
10861095
* @param clazz An arbitrary type
10871096
* @return true, if this {@link JavaClass} represents the same class as the supplied {@link Class}, otherwise false
@@ -1221,6 +1230,7 @@ CompletionProcess completeFrom(ImportContext context) {
12211230
completeComponentType(context);
12221231
enclosingClass = context.createEnclosingClass(this);
12231232
javaClassDependencies = new JavaClassDependencies(this, context);
1233+
imported = true;
12241234
return new CompletionProcess();
12251235
}
12261236

archunit/src/test/java/com/tngtech/archunit/core/domain/JavaClassTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ private Set<JavaClass> getOriginsOfDependenciesTo(JavaClass withType) {
625625
}
626626

627627
@Test
628-
public void stubs_have_empty_dependencies() {
628+
public void stubs_have_empty_dependencies_and_are_not_imported() {
629629
class Element {
630630
}
631631
class DependsOnArray {
@@ -644,6 +644,9 @@ class DependsOnArray {
644644
assertThat(stub.getConstructorsWithParameterTypeOfSelf()).isEmpty();
645645
assertThat(stub.getConstructorsWithThrowsDeclarationTypeOfSelf()).isEmpty();
646646
assertThat(stub.getAnnotationsWithTypeOfSelf()).isEmpty();
647+
assertThat(directlyImportedClass.isImported()).isTrue();
648+
assertThat(additionallyImportedClass.isImported()).isTrue();
649+
assertThat(stub.isImported()).isFalse();
647650
}
648651

649652
@Test

0 commit comments

Comments
 (0)