aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-squid-java-plugin
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-11-29 22:12:51 +0000
committerGodin <mandrikov@gmail.com>2010-11-29 22:12:51 +0000
commit65c771783cc8a7d8512f3eb57650ebd426ffb975 (patch)
tree57071e1f13a7344988eaf295c32ccc9108d5d5fb /plugins/sonar-squid-java-plugin
parent6143ab3cce790a5083669f355bfee16db07ffb41 (diff)
downloadsonarqube-65c771783cc8a7d8512f3eb57650ebd426ffb975.tar.gz
sonarqube-65c771783cc8a7d8512f3eb57650ebd426ffb975.zip
SONAR-1760: Improve performance of NoSonarFilterLoader
Diffstat (limited to 'plugins/sonar-squid-java-plugin')
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidScanner.java3
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidVisitorNotifier.java5
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/NoSonarFilterLoader.java49
3 files changed, 36 insertions, 21 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidScanner.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidScanner.java
index f3ecbc425e2..519d4fcd041 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidScanner.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidScanner.java
@@ -48,8 +48,7 @@ public class SquidScanner extends CodeScanner<CodeVisitor> {
private void notifySquidVisitors(Collection<SourceCode> files) {
SquidVisitor[] visitorArray = getVisitors().toArray(new SquidVisitor[getVisitors().size()]);
for (SourceCode sourceFile : files) {
- SquidVisitorNotifier visitorNotifier = new SquidVisitorNotifier((SourceFile) sourceFile, visitorArray);
- visitorNotifier.notifyVisitors(indexer);
+ new SquidVisitorNotifier((SourceFile) sourceFile, visitorArray).notifyVisitors();
}
}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidVisitorNotifier.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidVisitorNotifier.java
index 306bb428441..8b56509b2f6 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidVisitorNotifier.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidVisitorNotifier.java
@@ -5,20 +5,19 @@ import org.sonar.squid.api.SourceClass;
import org.sonar.squid.api.SourceCode;
import org.sonar.squid.api.SourceFile;
import org.sonar.squid.api.SourceMethod;
-import org.sonar.squid.indexer.SquidIndex;
public class SquidVisitorNotifier {
private final SourceFile sourceFile;
private final SquidVisitor[] squidVisitors;
- public SquidVisitorNotifier(SourceFile sourceFile, SquidVisitor[] squidVisitors) {
+ public SquidVisitorNotifier(SourceFile sourceFile, SquidVisitor... squidVisitors) {
this.sourceFile = sourceFile;
this.squidVisitors = new SquidVisitor[squidVisitors.length];
System.arraycopy(squidVisitors, 0, this.squidVisitors, 0, squidVisitors.length);
}
- public void notifyVisitors(SquidIndex indexer) {
+ public void notifyVisitors() {
callVisitFile();
}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/NoSonarFilterLoader.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/NoSonarFilterLoader.java
index 1fd831fc4c2..b5826ffd186 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/NoSonarFilterLoader.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/NoSonarFilterLoader.java
@@ -19,16 +19,17 @@
*/
package org.sonar.plugins.squid.bridges;
-import java.util.HashSet;
-import java.util.Set;
-
import org.sonar.api.checks.NoSonarFilter;
import org.sonar.api.resources.Resource;
+import org.sonar.java.squid.SquidVisitorNotifier;
+import org.sonar.java.squid.visitor.SquidVisitor;
import org.sonar.squid.api.SourceClass;
import org.sonar.squid.api.SourceCode;
import org.sonar.squid.api.SourceFile;
import org.sonar.squid.api.SourceMethod;
-import org.sonar.squid.indexer.QueryByParent;
+
+import java.util.HashSet;
+import java.util.Set;
public class NoSonarFilterLoader extends Bridge {
private NoSonarFilter noSonarFilter;
@@ -43,23 +44,39 @@ public class NoSonarFilterLoader extends Bridge {
if (noSonarFilter != null) {
// lines with NOSONAR tag
Set<Integer> ignoredLines = new HashSet<Integer>(squidFile.getNoSonarTagLines());
- // classes and methods with annotaion SuppressWarnings
- for (SourceCode sourceCode : squid.search(new QueryByParent(squidFile))) {
- if (sourceCode instanceof SourceMethod && ((SourceMethod) sourceCode).isSuppressWarnings()) {
- visitLines(sourceCode, ignoredLines);
- }
- if (sourceCode instanceof SourceClass && ((SourceClass) sourceCode).isSuppressWarnings()) {
- visitLines(sourceCode, ignoredLines);
- }
- }
+ // classes and methods with annotation SuppressWarnings
+ new SquidVisitorNotifier(squidFile, new SuppressWarningsVisitor(ignoredLines)).notifyVisitors();
noSonarFilter.addResource(sonarFile, ignoredLines);
}
}
- private static void visitLines(SourceCode sourceCode, Set<Integer> ignoredLines) {
- for (int line = sourceCode.getStartAtLine(); line <= sourceCode.getEndAtLine(); line++) {
- ignoredLines.add(line);
+ private static class SuppressWarningsVisitor implements SquidVisitor {
+ private Set<Integer> ignoredLines;
+
+ public SuppressWarningsVisitor(Set<Integer> ignoredLines) {
+ this.ignoredLines = ignoredLines;
+ }
+
+ public void visitFile(SourceFile sourceFile) {
+ }
+
+ public void visitClass(SourceClass sourceClass) {
+ if (sourceClass.isSuppressWarnings()) {
+ }
+ }
+
+ public void visitMethod(SourceMethod sourceMethod) {
+ if (sourceMethod.isSuppressWarnings()) {
+ visitLines(sourceMethod);
+ }
+ }
+
+ private void visitLines(SourceCode sourceCode) {
+ for (int line = sourceCode.getStartAtLine(); line <= sourceCode.getEndAtLine(); line++) {
+ ignoredLines.add(line);
+ }
}
}
+
}