Skip to content

Commit a91fdbd

Browse files
committed
Minor fixes and prepare for release
1 parent f920dfd commit a91fdbd

File tree

5 files changed

+32
-28
lines changed

5 files changed

+32
-28
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# PMDPlugin Changelog
44

55
## [Unreleased]
6+
### Added
7+
- Support for running PMD task in background
8+
69
## [1.8.27]
710
### Added
811
- Support for idea 2022.x and 2023.x

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# pluginGroup = com.intellij.plugins.bodhi.pmd
55
pluginName = PMDPlugin
6-
pluginVersion = 1.8.27
6+
pluginVersion = 1.8.28
77

88
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
99
# for insight into build numbers and IntelliJ Platform versions.

src/main/java/com/intellij/plugins/bodhi/pmd/core/PMDProgressRenderer.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ public String defaultFileExtension() {
2424
return null;
2525
}
2626

27-
@Override
28-
public void start() throws IOException {
29-
}
30-
3127
@Override
3228
public void startFileAnalysis(DataSource dataSource) {
3329
processedFiles++;
@@ -36,12 +32,19 @@ public void startFileAnalysis(DataSource dataSource) {
3632
}
3733

3834
@Override
39-
public void renderFileReport(Report report) throws IOException {
35+
public void flush() {
36+
}
37+
38+
@Override
39+
public void start() throws IOException {
40+
}
4041

42+
@Override
43+
public void renderFileReport(Report report) throws IOException {
4144
}
4245

4346
@Override
4447
public void end() throws IOException {
45-
4648
}
49+
4750
}

src/main/java/com/intellij/plugins/bodhi/pmd/core/PMDResultCollector.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public static Report getReport() {
5757
*
5858
* @param files The files to run PMD on
5959
* @param ruleSetPath The path of the ruleSet to run
60-
* @param progressRenderer
6160
* @return list of results
6261
*/
6362
public List<PMDRuleSetEntryNode> runPMDAndGetResults(List<File> files, String ruleSetPath, PMDProjectComponent comp) {
@@ -69,7 +68,6 @@ public List<PMDRuleSetEntryNode> runPMDAndGetResults(List<File> files, String ru
6968
*
7069
* @param files The files to run PMD on
7170
* @param ruleSetPath The path of the ruleSet to run
72-
* @param progress Object to report progress to
7371
* @return list of results
7472
*/
7573
public List<PMDRuleSetEntryNode> runPMDAndGetResults(List<File> files, String ruleSetPath, PMDProjectComponent comp, PMDProgressRenderer progressRenderer) {
@@ -92,7 +90,7 @@ public List<PMDRuleSetEntryNode> runPMDAndGetResults(List<File> files, String ru
9290

9391
PMDJsonExportingRenderer exportingRenderer = addExportRenderer(options);
9492
if (exportingRenderer != null) renderers.add(exportingRenderer);
95-
if (progressRenderer != null) renderers.add(progressRenderer );
93+
if (progressRenderer != null) renderers.add(progressRenderer);
9694

9795
try (PmdAnalysis pmd = PmdAnalysis.create(pmdConfig)) {
9896
files.forEach(file -> pmd.files().addFile(file.toPath()));
@@ -161,7 +159,7 @@ public static String isValidRuleSet(String path) {
161159

162160
try {
163161
RuleSet rs = new RuleSetLoader().loadFromResource(path);
164-
if (rs.getRules().size() != 0) {
162+
if (!rs.getRules().isEmpty()) {
165163
pathToRuleSet.put(path, rs);
166164
return "";
167165
}

src/main/java/com/intellij/plugins/bodhi/pmd/core/UselessSuppressionsHelper.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
* @author jborgers
3535
*/
3636
public class UselessSuppressionsHelper {
37-
static final Pattern NEXT_METHOD_NAME_PATTERN = Pattern.compile("\\R*^\\s*[\\w\\s<>]+\\s+([\\w]+)\\(");
38-
static final Pattern NEXT_FIELD_NAME_PATTERN = Pattern.compile("\\R*\\s*[\\w\\s<>,?]+\\s+([\\w]+)\\s*[=;]");
39-
static final Pattern COMMENT_PATTERN = Pattern.compile("(\\/\\/.*|\\/\\*(?s:.)*?\\*\\/)"); // Matches single-line and multi-line comments
37+
static final Pattern NEXT_METHOD_NAME_PATTERN = Pattern.compile("\\R*^\\s*[\\w\\s<>]+\\s+(\\w+)\\(");
38+
static final Pattern NEXT_FIELD_NAME_PATTERN = Pattern.compile("\\R*\\s*[\\w\\s<>,?]+\\s+(\\w+)\\s*[=;]");
39+
static final Pattern COMMENT_PATTERN = Pattern.compile("(//.*|/\\*(?s:.)*?\\*/)"); // Matches single-line and multi-line comments
4040
static final String NO_METHOD = "<nom>";
4141
final Map<String, Set<String>> classMethodToRuleNameOfSuppressedViolationsMap = new HashMap<>();
4242
final Map<String, Set<String>> classMethodToRuleNameOfViolationsMap = new HashMap<>();
@@ -55,7 +55,7 @@ public class UselessSuppressionsHelper {
5555

5656
void storeRuleNameForMethod(Report.SuppressedViolation suppressed) {
5757
RuleViolation violation = suppressed.getRuleViolation();
58-
if (!violation.getMethodName().isEmpty()) {
58+
if (violation.getMethodName() != null && !violation.getMethodName().isEmpty()) {
5959
// store for method
6060
String methodKey = violation.getPackageName() + "-" + violation.getClassName() + "-" + violation.getMethodName();
6161
Set<String> suppressedMethodRuleNames = classMethodToRuleNameOfSuppressedViolationsMap.get(methodKey);
@@ -136,8 +136,6 @@ private void addNodeIfUseless(List<PMDUselessSuppression> uselessSuppressions, P
136136
uselessSuppressions.add(new PMDUselessSuppression(pmdViolation, annotatedRuleName));
137137
}
138138
}
139-
} else {
140-
// cannot deal with other, non-pmd suppressions
141139
}
142140
}
143141
}
@@ -179,18 +177,20 @@ ViolatingAnnotationHolder getAnnotationContext(PMDViolation annotationViolation)
179177
if (virtualFile != null) {
180178
ApplicationManager.getApplication().runReadAction(() -> {
181179
Document doc = FileDocumentManager.getInstance().getDocument(virtualFile);
182-
int startOffset = doc.getLineStartOffset(annotationViolation.getBeginLine() - 1) + annotationViolation.getBeginColumn();
183-
int endOffset = doc.getLineStartOffset(annotationViolation.getEndLine() - 1) + annotationViolation.getEndColumn() - 1;
184-
String violatingAnnotation = doc.getText(new TextRange(startOffset, endOffset));
185-
String methodName;
186-
if (!annotationViolation.getMethodName().isEmpty()) { // an annotation inside a method
187-
methodName = annotationViolation.getMethodName();
188-
} else {
189-
int startAfter = doc.getLineStartOffset(annotationViolation.getEndLine());
190-
String after = doc.getText(new TextRange(startAfter, doc.getTextLength() - 1));
191-
methodName = findMethodName(after);
180+
if (doc != null) {
181+
int startOffset = doc.getLineStartOffset(annotationViolation.getBeginLine() - 1) + annotationViolation.getBeginColumn();
182+
int endOffset = doc.getLineStartOffset(annotationViolation.getEndLine() - 1) + annotationViolation.getEndColumn() - 1;
183+
String violatingAnnotation = doc.getText(new TextRange(startOffset, endOffset));
184+
String methodName;
185+
if (!annotationViolation.getMethodName().isEmpty()) { // an annotation inside a method
186+
methodName = annotationViolation.getMethodName();
187+
} else {
188+
int startAfter = doc.getLineStartOffset(annotationViolation.getEndLine());
189+
String after = doc.getText(new TextRange(startAfter, doc.getTextLength() - 1));
190+
methodName = findMethodName(after);
191+
}
192+
annotationContextResult = new ViolatingAnnotationHolder(violatingAnnotation, methodName);
192193
}
193-
annotationContextResult = new ViolatingAnnotationHolder(violatingAnnotation, methodName);
194194
});
195195
}
196196
return annotationContextResult;

0 commit comments

Comments
 (0)