-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve Index[View].getKnownUsers()
#354
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
110 changes: 110 additions & 0 deletions
110
core/src/test/java/org/jboss/jandex/test/KnownUsersTest.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,110 @@ | ||
package org.jboss.jandex.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Queue; | ||
import java.util.Set; | ||
|
||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.Index; | ||
import org.jboss.jandex.test.util.IndexingUtil; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class KnownUsersTest { | ||
static class SuperClass<T> { | ||
} | ||
|
||
interface ImplementedInterface1<T> { | ||
} | ||
|
||
interface ImplementedInterface2<T> { | ||
} | ||
|
||
static class TestClass<T extends Number> extends SuperClass<CharSequence> | ||
implements ImplementedInterface1<T>, ImplementedInterface2<RuntimeException> { | ||
int i; | ||
|
||
Map<String, List<Integer>> m; | ||
|
||
TestClass(StringBuilder str) { | ||
m = new HashMap<>(); | ||
m.put("foo", new ArrayList<>()); | ||
} | ||
|
||
<U extends T, V extends Collection<?>, W extends Exception> U bar(Set<? extends Long> s, Queue<? super Double> q) | ||
throws IllegalArgumentException, IllegalStateException, W { | ||
// `toString()` to force a class reference to `File` into the constant pool | ||
Paths.get("").toFile().toString(); | ||
return null; | ||
} | ||
|
||
static class NestedClass { | ||
} | ||
|
||
class InnerClass { | ||
} | ||
} | ||
|
||
@Test | ||
public void test() throws IOException { | ||
Index index = Index.of(SuperClass.class, ImplementedInterface1.class, ImplementedInterface2.class, TestClass.class); | ||
doTest(index); | ||
doTest(IndexingUtil.roundtrip(index)); | ||
} | ||
|
||
private void doTest(Index index) { | ||
// from class signature | ||
assertKnownUsers(index, SuperClass.class); | ||
assertKnownUsers(index, ImplementedInterface1.class); | ||
assertKnownUsers(index, ImplementedInterface2.class); | ||
assertKnownUsers(index, Number.class); | ||
assertKnownUsers(index, CharSequence.class); | ||
assertKnownUsers(index, RuntimeException.class); | ||
// from field types | ||
assertKnownUsers(index, String.class); | ||
assertKnownUsers(index, Integer.class); | ||
// from method signatures | ||
assertKnownUsers(index, StringBuilder.class); | ||
assertKnownUsers(index, Collection.class); | ||
assertKnownUsers(index, Exception.class); | ||
assertKnownUsers(index, Set.class); | ||
assertKnownUsers(index, Long.class); | ||
assertKnownUsers(index, Queue.class); | ||
assertKnownUsers(index, Double.class); | ||
assertKnownUsers(index, IllegalArgumentException.class); | ||
assertKnownUsers(index, IllegalStateException.class); | ||
// from method bodies (class references in the constant pool) | ||
assertKnownUsers(index, HashMap.class); | ||
assertKnownUsers(index, ArrayList.class); | ||
assertKnownUsers(index, Paths.class); | ||
assertKnownUsers(index, Path.class); | ||
assertKnownUsers(index, File.class); | ||
// member classes (class references in the constant pool) | ||
assertKnownUsers(index, TestClass.NestedClass.class); | ||
assertKnownUsers(index, TestClass.InnerClass.class); | ||
} | ||
|
||
private void assertKnownUsers(Index index, Class<?> clazz) { | ||
Collection<ClassInfo> knownUsers = index.getKnownUsers(clazz); | ||
|
||
assertNotNull(knownUsers); | ||
assertFalse(knownUsers.isEmpty()); | ||
for (ClassInfo knownUser : knownUsers) { | ||
if (TestClass.class.getName().equals(knownUser.name().toString())) { | ||
return; | ||
} | ||
} | ||
fail("Expected " + TestClass.class.getName() + " to be a known user of " + clazz.getName()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if
List#copyOf()
could be a little bit more efficient here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly, but Jandex is still on Java 8 :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry. I forgot about it 🤦