How to know what imports are used in each line?
Hi all,
I'm making a pluing which needs to know what imports(for now it's java only) are being used in each line. Can someone show what's the best way to do so?
Ex: Take this code
1. import java.io.File;
2. import java.io.FileReader;
3. import java.io.IOException;
4.
5. public class Exp {
6. private int from;
7. private int to;
8.
9. public static void main(String args[]) throws IOException {
10. FileReader fileReader = new FileReader(new File("test.java"));
11.
12. if (fileReader.ready()) {
13. System.out.print("File Reader is ready");
14. } else {
15. System.out.print("File Reader is not ready");
16. }
17. }
18. }
Here:
Line 9 -> java.io.IOException
Line 10 -> java.io.File, java.io.FileReader
Line 12-> java.io.FileReader
All others no imports are used.
Is it possible through psi file??
Thanks in advance.
Please sign in to leave a comment.
Hi all,
Any update on this?
Check out the code at https://github.com/JetBrains/intellij-community/blob/master/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/imports/ImportsAreUsedVisitor.java for an implementation that checks which import statement is used by each reference in a Java class.
Is there any way to get which import statement is used by each reference in languages other than Java?