Skip to content

Commit

Permalink
add JavaClass.isImported()
Browse files Browse the repository at this point in the history
Signed-off-by: Manfred Hanke <[email protected]>
  • Loading branch information
hankem committed Dec 15, 2020
1 parent 5ec2428 commit 883ef99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public Set<JavaMember> get() {
});
private JavaClassDependencies javaClassDependencies = new JavaClassDependencies(this); // just for stubs; will be overwritten for imported classes
private ReverseDependencies reverseDependencies = ReverseDependencies.EMPTY; // just for stubs; will be overwritten for imported classes
private boolean imported = false;

JavaClass(JavaClassBuilder builder) {
source = checkNotNull(builder.getSource());
Expand Down Expand Up @@ -1149,6 +1150,14 @@ public Set<InstanceofCheck> getInstanceofChecksWithTypeOfSelf() {
return reverseDependencies.getInstanceofChecksWithTypeOf(this);
}

/**
* @return Whether this class has actually been imported (or is just a stub).
*/
@PublicAPI(usage = ACCESS)
public boolean isImported() {
return imported;
}

/**
* @param clazz An arbitrary type
* @return true, if this {@link JavaClass} represents the same class as the supplied {@link Class}, otherwise false
Expand Down Expand Up @@ -1301,6 +1310,7 @@ JavaClassDependencies completeFrom(ImportContext context) {
codeUnit.completeFrom(context);
}
javaClassDependencies = new JavaClassDependencies(this);
imported = true;
return javaClassDependencies;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ private Set<JavaClass> getOriginsOfDependenciesTo(JavaClass withType) {
}

@Test
public void stubs_have_empty_dependencies() {
public void stubs_have_empty_dependencies_and_are_not_imported() {
class Element {
}
class DependsOnArray {
Expand All @@ -868,6 +868,9 @@ class DependsOnArray {
JavaClass additionallyImportedClass = directlyImportedClass.getField("array").getRawType(); // Element[]
JavaClass stub = additionallyImportedClass.getComponentType(); // Element

assertThat(directlyImportedClass.isImported()).isTrue();
assertThat(additionallyImportedClass.isImported()).isTrue();
assertThat(stub.isImported()).isFalse();
assertThat(stub.getDirectDependenciesFromSelf()).isEmpty();
assertThat(stub.getDirectDependenciesToSelf()).isEmpty();
assertThat(stub.getFieldAccessesToSelf()).isEmpty();
Expand Down

0 comments on commit 883ef99

Please sign in to comment.