Skip to content

Commit

Permalink
Add option to disable on-the-fly inspections
Browse files Browse the repository at this point in the history
  • Loading branch information
ybroeker committed Dec 2, 2020
1 parent f7fe590 commit 520f9b5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class PmdConfigurationPanel extends JPanel {

private final JCheckBox scanTestSources;

private final JCheckBox runOnTheFlyInspection;

private final ComboBox<PmdVersion> versionComboBox;

private final ComboBox<JavaVersion> jdkComboBox;
Expand All @@ -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);
Expand All @@ -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<JavaVersion> buildJdkComboBox(final PmdConfigurationService.@NotNull State stateBuilder) {
final Box horizontalBox = Box.createHorizontalBox();
horizontalBox.setAlignmentX(Component.LEFT_ALIGNMENT);
Expand Down Expand Up @@ -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()
);
}

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -86,6 +90,10 @@ public JavaVersion getJdkVersion() {
return jdkVersion;
}

public boolean isRunOnTheFlyInspection() {
return runOnTheFlyInspection;
}

@Override
public boolean equals(final Object other) {
if (this == other) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path> rulesPath = getRules(project);
if (!rulesPath.isPresent()) {
Expand Down

0 comments on commit 520f9b5

Please sign in to comment.