diff --git a/CHANGELOG.md b/CHANGELOG.md index fc07975..3c6e456 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## [Unreleased] ### Added - Quick Fix to suppress warnings for members and class +- Add option to disable on-the-fly inspections ### Changed - Run inspection only on java files diff --git a/src/main/java/com/github/ybroeker/pmdidea/config/PmdConfigurationPanel.java b/src/main/java/com/github/ybroeker/pmdidea/config/PmdConfigurationPanel.java index ed85121..c2695b9 100644 --- a/src/main/java/com/github/ybroeker/pmdidea/config/PmdConfigurationPanel.java +++ b/src/main/java/com/github/ybroeker/pmdidea/config/PmdConfigurationPanel.java @@ -21,6 +21,8 @@ public class PmdConfigurationPanel extends JPanel { private final JCheckBox scanTestSources; + private final JCheckBox runOnTheFlyInspection; + private final ComboBox versionComboBox; private final ComboBox jdkComboBox; @@ -34,6 +36,7 @@ public PmdConfigurationPanel(final Project project) { PmdConfigurationService.State originalState = project.getService(PmdConfigurationService.class).getState(); this.scanTestSources = buildScanTestSources(originalState); + this.runOnTheFlyInspection = buildRunOnTheFlyInspection(originalState); this.versionComboBox = buildVersionComboBox(originalState); this.jdkComboBox = buildJdkComboBox(originalState); this.rulesFile = buildRulesField(project, originalState); @@ -49,6 +52,16 @@ private JCheckBox buildScanTestSources(final PmdConfigurationService.@NotNull St return scanTestSources; } + private JCheckBox buildRunOnTheFlyInspection(final PmdConfigurationService.@NotNull State stateBuilder) { + final JCheckBox onTheFlyInspection = new JCheckBox(); + onTheFlyInspection.setText("Run inspection on the fly"); + onTheFlyInspection.setSelected(stateBuilder.isCheckTests()); + this.add(onTheFlyInspection); + onTheFlyInspection.setAlignmentX(Component.LEFT_ALIGNMENT); + + return onTheFlyInspection; + } + private ComboBox buildJdkComboBox(final PmdConfigurationService.@NotNull State stateBuilder) { final Box horizontalBox = Box.createHorizontalBox(); horizontalBox.setAlignmentX(Component.LEFT_ALIGNMENT); @@ -103,7 +116,8 @@ private TextFieldWithBrowseButton buildRulesField(final Project project, final P return new PmdConfigurationService.@NotNull State(rulesFile.getText(), scanTestSources.isSelected(), (PmdVersion) versionComboBox.getSelectedItem(), - (JavaVersion) jdkComboBox.getSelectedItem() + (JavaVersion) jdkComboBox.getSelectedItem(), + runOnTheFlyInspection.isSelected() ); } @@ -118,6 +132,7 @@ public void reset() { scanTestSources.setSelected(originalState.isCheckTests()); versionComboBox.setSelectedItem(originalState.getPmdVersion()); jdkComboBox.setSelectedItem(originalState.getJdkVersion()); + runOnTheFlyInspection.setSelected(originalState.isRunOnTheFlyInspection()); } public void apply() { diff --git a/src/main/java/com/github/ybroeker/pmdidea/config/PmdConfigurationService.java b/src/main/java/com/github/ybroeker/pmdidea/config/PmdConfigurationService.java index c828fb3..4731c02 100644 --- a/src/main/java/com/github/ybroeker/pmdidea/config/PmdConfigurationService.java +++ b/src/main/java/com/github/ybroeker/pmdidea/config/PmdConfigurationService.java @@ -60,14 +60,18 @@ public static class State { @OptionTag(converter = JavaVersionConverter.class) private JavaVersion jdkVersion; + @OptionTag + private boolean runOnTheFlyInspection = true; + public State() { } - public State(final String rulesPath, final boolean checkTests, final PmdVersion pmdVersion, final JavaVersion jdkVersion) { + public State(final String rulesPath, final boolean checkTests, final PmdVersion pmdVersion, final JavaVersion jdkVersion, final boolean runOnTheFlyInspection) { this.rulesPath = rulesPath; this.checkTests = checkTests; this.pmdVersion = pmdVersion; this.jdkVersion = jdkVersion; + this.runOnTheFlyInspection = runOnTheFlyInspection; } public String getRulesPath() { @@ -86,6 +90,10 @@ public JavaVersion getJdkVersion() { return jdkVersion; } + public boolean isRunOnTheFlyInspection() { + return runOnTheFlyInspection; + } + @Override public boolean equals(final Object other) { if (this == other) { @@ -96,6 +104,7 @@ public boolean equals(final Object other) { } final State state = (State) other; return checkTests == state.checkTests + && runOnTheFlyInspection == state.runOnTheFlyInspection && Objects.equals(rulesPath, state.rulesPath) && Objects.equals(pmdVersion, state.pmdVersion) && Objects.equals(jdkVersion, state.jdkVersion); diff --git a/src/main/java/com/github/ybroeker/pmdidea/inspection/PmdInspection.java b/src/main/java/com/github/ybroeker/pmdidea/inspection/PmdInspection.java index c16b06e..510f9c1 100644 --- a/src/main/java/com/github/ybroeker/pmdidea/inspection/PmdInspection.java +++ b/src/main/java/com/github/ybroeker/pmdidea/inspection/PmdInspection.java @@ -42,6 +42,11 @@ public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, } final Project project = manager.getProject(); + final PmdConfigurationService service = project.getService(PmdConfigurationService.class); + if (isOnTheFly && !service.getState().isRunOnTheFlyInspection()) { + LOGGER.trace("Skip inspection, on the fly inspections disabled"); + return ProblemDescriptor.EMPTY_ARRAY; + } final Optional rulesPath = getRules(project); if (!rulesPath.isPresent()) {