Library reflection in plugin Follow
I'm trying to develop a plugin for IntelliJ but I need to reflect over included Libraries (also gradle libraries).
How I get these Libraries (jars, classes, or something like that)? I need to inspect some annotations at classes in these libraries but I can't reference these in my plugin.
Does anyone know how to do that?
Thanks
Edit: I'm only have PsiClass and a Project in my methods available. Here is my debug-code
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
List<OrderEntry> orderEntriesForFile = fileIndex.getOrderEntriesForFile(psiClass.getContainingFile().getVirtualFile());
System.out.println("OrderEntries: " + orderEntriesForFile.size());
for(OrderEntry entry : orderEntriesForFile) {
System.out.print("EntryType: " + entry.getClass());
System.out.println(" " + entry.getPresentableName());
if(entry instanceof LibraryOrderEntry) {
VirtualFile[] files = ((LibraryOrderEntry) entry).getLibrary().getFiles(OrderRootType.CLASSES);
System.out.println("Library files: " + files.length);
for(VirtualFile jar : files) {
System.out.println("Library found: " + jar.getName());
}
}
}
for (PsiField psiField : PsiClassUtil.collectClassFieldsIntern(psiClass)) {
PsiAnnotation[] annotations = psiField.getModifierList().getAnnotations();
for(PsiAnnotation annotation : annotations) {
System.out.println("Annotation found: " + annotation.getQualifiedName());
try {
System.out.println("Annotation class: " + Class.forName(annotation.getQualifiedName()));
} catch (ClassNotFoundException e) {
System.out.println("Annotation class not found");
}
}
}
Please sign in to leave a comment.
META-INF/plugin.xml -> idea-plugin -> <depends>com.jetbrains.twig</depends>
Project Structure -> SDKs -> Classpath -> Add foreign plugin jar for builds (JetBrains/../Plugins/twig/...)
Thank you @Daniel Espendiller
The problem is that i don't know the libraries on which i have to depend. I'm building a generic library which can be extended and I don't know the Extensions directly. Is there a opportunity to reflect over all dependencies and libraries of the project and find all classes in them? (only one time at initialization and every time on rsync)
Thank you.
just the same for external libs. every plugin is a sandbox, so just let them compile in: Project Structure -> Modules -> Dependencies -> Scope.
You can also see https://github.com/nicoulaj/idea-markdown. this one includes external libs, too.
The problem is, that i don't know these external libs. My lib is used in some project and my project (an Annotation Prozessor) is expandable with third party libs. I have to tell IntelliJ which mehtods would be created by an Annotation but I don't know which Extensions would someone build upon my library and don't know at compile time which mehtods would be created by these libraries, so I have to find and reflect them at runtime.
@Daniel Espendiller had the dazzling idea. What i've searched for is
Thank you Daniel