3

I want to create a plugin for intellij idea and in that I want to get the inspections or code analysis errors.By default intellij will show those code inspections like errors, dead code, or unused components.So I want to get those inspections pro grammatically to my plugin.I am able to create an tool button from my plugin and getting the code. Process is,

  1. created plugin for intellij Idea with some actions and tools menu.
  2. running the plugin, created separate instace in intellijIdea
  3. wrote some java code in new instance of intellij in editor

-->in that it will show inspections or errors

so I want get those inspection to my plugin.How can I do that?

2 Answers 2

1

The simplest API for getting the inspection errors in a given set of files is CodeSmellDetector:

CodeSmellDetector.getInstance(project).findCodeSmells(files);
0
1

If you know what exact inspection you need, you can get it this way:

PhpUnusedAliasInspection inspection = new PhpUnusedAliasInspection();
InspectionManager manager = InspectionManager.getInstance(psiFile.getProject());
List<ProblemDescriptor> checked = inspection.processFile(psiFile, manager);
System.out.println("checked " + checked);

Outputs:

checked [Import 'Illuminate\Database\Eloquent\Model' is never used]

Where PhpUnusedAliasInspection may be any class that extends the LocalInspectionTool (you can list them all by opening the decompilled LocalInspectionTool class and clicking the Subclasses circle near the name).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.