Skip to content

Commit

Permalink
Minor fixes and prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
amitdev committed Oct 15, 2023
1 parent f920dfd commit a91fdbd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# PMDPlugin Changelog

## [Unreleased]
### Added
- Support for running PMD task in background

## [1.8.27]
### Added
- Support for idea 2022.x and 2023.x
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# pluginGroup = com.intellij.plugins.bodhi.pmd
pluginName = PMDPlugin
pluginVersion = 1.8.27
pluginVersion = 1.8.28

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public String defaultFileExtension() {
return null;
}

@Override
public void start() throws IOException {
}

@Override
public void startFileAnalysis(DataSource dataSource) {
processedFiles++;
Expand All @@ -36,12 +32,19 @@ public void startFileAnalysis(DataSource dataSource) {
}

@Override
public void renderFileReport(Report report) throws IOException {
public void flush() {
}

@Override
public void start() throws IOException {
}

@Override
public void renderFileReport(Report report) throws IOException {
}

@Override
public void end() throws IOException {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public static Report getReport() {
*
* @param files The files to run PMD on
* @param ruleSetPath The path of the ruleSet to run
* @param progressRenderer
* @return list of results
*/
public List<PMDRuleSetEntryNode> runPMDAndGetResults(List<File> files, String ruleSetPath, PMDProjectComponent comp) {
Expand All @@ -69,7 +68,6 @@ public List<PMDRuleSetEntryNode> runPMDAndGetResults(List<File> files, String ru
*
* @param files The files to run PMD on
* @param ruleSetPath The path of the ruleSet to run
* @param progress Object to report progress to
* @return list of results
*/
public List<PMDRuleSetEntryNode> runPMDAndGetResults(List<File> files, String ruleSetPath, PMDProjectComponent comp, PMDProgressRenderer progressRenderer) {
Expand All @@ -92,7 +90,7 @@ public List<PMDRuleSetEntryNode> runPMDAndGetResults(List<File> files, String ru

PMDJsonExportingRenderer exportingRenderer = addExportRenderer(options);
if (exportingRenderer != null) renderers.add(exportingRenderer);
if (progressRenderer != null) renderers.add(progressRenderer );
if (progressRenderer != null) renderers.add(progressRenderer);

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

try {
RuleSet rs = new RuleSetLoader().loadFromResource(path);
if (rs.getRules().size() != 0) {
if (!rs.getRules().isEmpty()) {
pathToRuleSet.put(path, rs);
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
* @author jborgers
*/
public class UselessSuppressionsHelper {
static final Pattern NEXT_METHOD_NAME_PATTERN = Pattern.compile("\\R*^\\s*[\\w\\s<>]+\\s+([\\w]+)\\(");
static final Pattern NEXT_FIELD_NAME_PATTERN = Pattern.compile("\\R*\\s*[\\w\\s<>,?]+\\s+([\\w]+)\\s*[=;]");
static final Pattern COMMENT_PATTERN = Pattern.compile("(\\/\\/.*|\\/\\*(?s:.)*?\\*\\/)"); // Matches single-line and multi-line comments
static final Pattern NEXT_METHOD_NAME_PATTERN = Pattern.compile("\\R*^\\s*[\\w\\s<>]+\\s+(\\w+)\\(");
static final Pattern NEXT_FIELD_NAME_PATTERN = Pattern.compile("\\R*\\s*[\\w\\s<>,?]+\\s+(\\w+)\\s*[=;]");
static final Pattern COMMENT_PATTERN = Pattern.compile("(//.*|/\\*(?s:.)*?\\*/)"); // Matches single-line and multi-line comments
static final String NO_METHOD = "<nom>";
final Map<String, Set<String>> classMethodToRuleNameOfSuppressedViolationsMap = new HashMap<>();
final Map<String, Set<String>> classMethodToRuleNameOfViolationsMap = new HashMap<>();
Expand All @@ -55,7 +55,7 @@ public class UselessSuppressionsHelper {

void storeRuleNameForMethod(Report.SuppressedViolation suppressed) {
RuleViolation violation = suppressed.getRuleViolation();
if (!violation.getMethodName().isEmpty()) {
if (violation.getMethodName() != null && !violation.getMethodName().isEmpty()) {
// store for method
String methodKey = violation.getPackageName() + "-" + violation.getClassName() + "-" + violation.getMethodName();
Set<String> suppressedMethodRuleNames = classMethodToRuleNameOfSuppressedViolationsMap.get(methodKey);
Expand Down Expand Up @@ -136,8 +136,6 @@ private void addNodeIfUseless(List<PMDUselessSuppression> uselessSuppressions, P
uselessSuppressions.add(new PMDUselessSuppression(pmdViolation, annotatedRuleName));
}
}
} else {
// cannot deal with other, non-pmd suppressions
}
}
}
Expand Down Expand Up @@ -179,18 +177,20 @@ ViolatingAnnotationHolder getAnnotationContext(PMDViolation annotationViolation)
if (virtualFile != null) {
ApplicationManager.getApplication().runReadAction(() -> {
Document doc = FileDocumentManager.getInstance().getDocument(virtualFile);
int startOffset = doc.getLineStartOffset(annotationViolation.getBeginLine() - 1) + annotationViolation.getBeginColumn();
int endOffset = doc.getLineStartOffset(annotationViolation.getEndLine() - 1) + annotationViolation.getEndColumn() - 1;
String violatingAnnotation = doc.getText(new TextRange(startOffset, endOffset));
String methodName;
if (!annotationViolation.getMethodName().isEmpty()) { // an annotation inside a method
methodName = annotationViolation.getMethodName();
} else {
int startAfter = doc.getLineStartOffset(annotationViolation.getEndLine());
String after = doc.getText(new TextRange(startAfter, doc.getTextLength() - 1));
methodName = findMethodName(after);
if (doc != null) {
int startOffset = doc.getLineStartOffset(annotationViolation.getBeginLine() - 1) + annotationViolation.getBeginColumn();
int endOffset = doc.getLineStartOffset(annotationViolation.getEndLine() - 1) + annotationViolation.getEndColumn() - 1;
String violatingAnnotation = doc.getText(new TextRange(startOffset, endOffset));
String methodName;
if (!annotationViolation.getMethodName().isEmpty()) { // an annotation inside a method
methodName = annotationViolation.getMethodName();
} else {
int startAfter = doc.getLineStartOffset(annotationViolation.getEndLine());
String after = doc.getText(new TextRange(startAfter, doc.getTextLength() - 1));
methodName = findMethodName(after);
}
annotationContextResult = new ViolatingAnnotationHolder(violatingAnnotation, methodName);
}
annotationContextResult = new ViolatingAnnotationHolder(violatingAnnotation, methodName);
});
}
return annotationContextResult;
Expand Down

0 comments on commit a91fdbd

Please sign in to comment.