aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-06-12 09:40:12 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-06-15 13:07:53 +0200
commit1043c094fa04f2f577581519f7c139d4fb28a88a (patch)
tree3918bcf3002cc02ee801e7b28e658636dd7f98e6
parenta8d025a142cc6d9497546e12db9e733b74b116ca (diff)
downloadsonarqube-1043c094fa04f2f577581519f7c139d4fb28a88a.tar.gz
sonarqube-1043c094fa04f2f577581519f7c139d4fb28a88a.zip
impl. of DepthTraversalTypeAwareVisitor should not have to visit internal method
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/component/DepthTraversalTypeAwareVisitor.java12
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/component/TypeAwareVisitor.java20
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/component/PostOrderDepthTraversalTypeAwareVisitorTest.java33
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/component/PreOrderDepthTraversalTypeAwareVisitorTest.java31
5 files changed, 81 insertions, 17 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/DepthTraversalTypeAwareVisitor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/DepthTraversalTypeAwareVisitor.java
index 4f4dc144870..c43c9cbd4ee 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/DepthTraversalTypeAwareVisitor.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/DepthTraversalTypeAwareVisitor.java
@@ -43,17 +43,18 @@ public abstract class DepthTraversalTypeAwareVisitor implements TypeAwareVisitor
}
if (order == Order.PRE_ORDER) {
- visitAny(component);
+ visitNode(component);
}
visitChildren(component);
if (order == Order.POST_ORDER) {
- visitAny(component);
+ visitNode(component);
}
}
- protected void visitAny(Component component) {
+ protected void visitNode(Component component) {
+ visitAny(component);
switch (component.getType()) {
case PROJECT:
visitProject(component);
@@ -105,6 +106,11 @@ public abstract class DepthTraversalTypeAwareVisitor implements TypeAwareVisitor
// empty implementation, meant to be override at will by subclasses
}
+ @Override
+ public void visitAny(Component component) {
+ // empty implementation, meant to be override at will by subclasses
+ }
+
public enum Order {
PRE_ORDER, POST_ORDER
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/TypeAwareVisitor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/TypeAwareVisitor.java
index 9e59e178935..dec025a09d9 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/TypeAwareVisitor.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/TypeAwareVisitor.java
@@ -23,13 +23,33 @@ package org.sonar.server.computation.component;
* A {@link ComponentVisitor} which can exposes methods which ensure the type of the visited Component.
*/
public interface TypeAwareVisitor extends ComponentVisitor {
+ /**
+ * Called when encountering a Component of type {@link Component.Type#PROJECT}
+ */
void visitProject(Component tree);
+ /**
+ * Called when encountering a Component of type {@link Component.Type#MODULE}
+ */
void visitModule(Component tree);
+ /**
+ * Called when encountering a Component of type {@link Component.Type#DIRECTORY}
+ */
void visitDirectory(Component tree);
+ /**
+ * Called when encountering a Component of type {@link Component.Type#FILE}
+ */
void visitFile(Component tree);
+ /**
+ * Called when encountering a Component of an unknown type
+ */
void visitUnknown(Component tree);
+
+ /**
+ * Called for any component, <strong>in addition</strong> to the methods specific to each type
+ */
+ void visitAny(Component component);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java
index 56130f97f1c..4f40bcb46f6 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java
@@ -90,7 +90,7 @@ public class PersistMeasuresStep implements ComputationStep {
}
@Override
- protected void visitAny(Component component) {
+ public void visitAny(Component component) {
int componentRef = component.getRef();
List<BatchReport.Measure> measures = reportReader.readComponentMeasures(componentRef);
persistMeasures(measures, dbIdsRepository.getComponentId(component), dbIdsRepository.getSnapshotId(component));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/component/PostOrderDepthTraversalTypeAwareVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/component/PostOrderDepthTraversalTypeAwareVisitorTest.java
index f2be283b461..48e57e23f76 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/component/PostOrderDepthTraversalTypeAwareVisitorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/component/PostOrderDepthTraversalTypeAwareVisitorTest.java
@@ -66,6 +66,7 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
spyFileVisitor.visit(component);
inOrder.verify(spyFileVisitor).visit(component);
+ inOrder.verify(spyFileVisitor).visitAny(component);
inOrder.verify(spyFileVisitor).visitFile(component);
inOrder.verifyNoMoreInteractions();
}
@@ -76,6 +77,7 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
spyFileVisitor.visit(component);
inOrder.verify(spyFileVisitor).visit(component);
+ inOrder.verify(spyFileVisitor).visitAny(component);
inOrder.verify(spyFileVisitor).visitModule(component);
inOrder.verifyNoMoreInteractions();
}
@@ -86,6 +88,7 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
spyFileVisitor.visit(component);
inOrder.verify(spyFileVisitor).visit(component);
+ inOrder.verify(spyFileVisitor).visitAny(component);
inOrder.verify(spyFileVisitor).visitDirectory(component);
inOrder.verifyNoMoreInteractions();
}
@@ -96,12 +99,13 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
spyFileVisitor.visit(component);
inOrder.verify(spyFileVisitor).visit(component);
+ inOrder.verify(spyFileVisitor).visitAny(component);
inOrder.verify(spyFileVisitor).visitProject(component);
inOrder.verifyNoMoreInteractions();
}
@Test
- public void visit_file_with_depth_DIRECTORY_does_not_call_visit_file() {
+ public void visit_file_with_depth_DIRECTORY_does_not_call_visit_file_nor_visitAny() {
Component component = component(FILE, 1);
spyDirectoryVisitor.visit(component);
@@ -115,6 +119,7 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
spyDirectoryVisitor.visit(component);
inOrder.verify(spyDirectoryVisitor).visit(component);
+ inOrder.verify(spyDirectoryVisitor).visitAny(component);
inOrder.verify(spyDirectoryVisitor).visitDirectory(component);
inOrder.verifyNoMoreInteractions();
}
@@ -125,6 +130,7 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
spyDirectoryVisitor.visit(component);
inOrder.verify(spyDirectoryVisitor).visit(component);
+ inOrder.verify(spyDirectoryVisitor).visitAny(component);
inOrder.verify(spyDirectoryVisitor).visitModule(component);
inOrder.verifyNoMoreInteractions();
}
@@ -135,12 +141,13 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
spyDirectoryVisitor.visit(component);
inOrder.verify(spyDirectoryVisitor).visit(component);
+ inOrder.verify(spyDirectoryVisitor).visitAny(component);
inOrder.verify(spyDirectoryVisitor).visitProject(component);
inOrder.verifyNoMoreInteractions();
}
@Test
- public void visit_file_with_depth_MODULE_does_not_call_visit_file() {
+ public void visit_file_with_depth_MODULE_does_not_call_visit_file_nor_visitAny() {
Component component = component(FILE, 1);
spyModuleVisitor.visit(component);
@@ -149,7 +156,7 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
}
@Test
- public void visit_directory_with_depth_MODULE_does_not_call_visit_directory() {
+ public void visit_directory_with_depth_MODULE_does_not_call_visit_directory_nor_visitAny() {
Component component = component(DIRECTORY, 1);
spyModuleVisitor.visit(component);
@@ -163,6 +170,7 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
spyModuleVisitor.visit(component);
inOrder.verify(spyModuleVisitor).visit(component);
+ inOrder.verify(spyModuleVisitor).visitAny(component);
inOrder.verify(spyModuleVisitor).visitModule(component);
inOrder.verifyNoMoreInteractions();
}
@@ -173,12 +181,13 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
spyModuleVisitor.visit(component);
inOrder.verify(spyModuleVisitor).visit(component);
+ inOrder.verify(spyModuleVisitor).visitAny(component);
inOrder.verify(spyModuleVisitor).visitModule(component);
inOrder.verifyNoMoreInteractions();
}
@Test
- public void visit_file_with_depth_PROJECT_does_not_call_visit_file() {
+ public void visit_file_with_depth_PROJECT_does_not_call_visit_file_nor_visitAny() {
Component component = component(FILE, 1);
spyProjectVisitor.visit(component);
@@ -187,7 +196,7 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
}
@Test
- public void visit_directory_with_depth_PROJECT_does_not_call_visit_directory() {
+ public void visit_directory_with_depth_PROJECT_does_not_call_visit_directory_nor_visitAny() {
Component component = component(DIRECTORY, 1);
spyProjectVisitor.visit(component);
@@ -196,7 +205,7 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
}
@Test
- public void visit_module_with_depth_PROJECT_does_not_call_visit_module() {
+ public void visit_module_with_depth_PROJECT_does_not_call_visit_module_nor_visitAny() {
Component component = component(MODULE, 1);
spyProjectVisitor.visit(component);
@@ -210,6 +219,7 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
spyProjectVisitor.visit(component);
inOrder.verify(spyProjectVisitor).visit(component);
+ inOrder.verify(spyProjectVisitor).visitAny(component);
inOrder.verify(spyProjectVisitor).visitProject(component);
inOrder.verifyNoMoreInteractions();
}
@@ -222,11 +232,16 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
inOrder.verify(spyFileVisitor).visit(MODULE_2);
inOrder.verify(spyFileVisitor).visit(DIRECTORY_3);
inOrder.verify(spyFileVisitor).visit(FILE_4);
+ inOrder.verify(spyFileVisitor).visitAny(FILE_4);
inOrder.verify(spyFileVisitor).visitFile(FILE_4);
inOrder.verify(spyFileVisitor).visit(FILE_5);
+ inOrder.verify(spyFileVisitor).visitAny(FILE_5);
inOrder.verify(spyFileVisitor).visitFile(FILE_5);
+ inOrder.verify(spyFileVisitor).visitAny(DIRECTORY_3);
inOrder.verify(spyFileVisitor).visitDirectory(DIRECTORY_3);
+ inOrder.verify(spyFileVisitor).visitAny(MODULE_2);
inOrder.verify(spyFileVisitor).visitModule(MODULE_2);
+ inOrder.verify(spyFileVisitor).visitAny(COMPONENT_TREE);
inOrder.verify(spyFileVisitor).visitProject(COMPONENT_TREE);
inOrder.verifyNoMoreInteractions();
}
@@ -238,8 +253,11 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
inOrder.verify(spyDirectoryVisitor).visit(COMPONENT_TREE);
inOrder.verify(spyDirectoryVisitor).visit(MODULE_2);
inOrder.verify(spyDirectoryVisitor).visit(DIRECTORY_3);
+ inOrder.verify(spyDirectoryVisitor).visitAny(DIRECTORY_3);
inOrder.verify(spyDirectoryVisitor).visitDirectory(DIRECTORY_3);
+ inOrder.verify(spyDirectoryVisitor).visitAny(MODULE_2);
inOrder.verify(spyDirectoryVisitor).visitModule(MODULE_2);
+ inOrder.verify(spyDirectoryVisitor).visitAny(COMPONENT_TREE);
inOrder.verify(spyDirectoryVisitor).visitProject(COMPONENT_TREE);
inOrder.verifyNoMoreInteractions();
}
@@ -250,7 +268,9 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
inOrder.verify(spyModuleVisitor).visit(COMPONENT_TREE);
inOrder.verify(spyModuleVisitor).visit(MODULE_2);
+ inOrder.verify(spyModuleVisitor).visitAny(MODULE_2);
inOrder.verify(spyModuleVisitor).visitModule(MODULE_2);
+ inOrder.verify(spyModuleVisitor).visitAny(COMPONENT_TREE);
inOrder.verify(spyModuleVisitor).visitProject(COMPONENT_TREE);
inOrder.verifyNoMoreInteractions();
}
@@ -260,6 +280,7 @@ public class PostOrderDepthTraversalTypeAwareVisitorTest {
spyProjectVisitor.visit(COMPONENT_TREE);
inOrder.verify(spyProjectVisitor).visit(COMPONENT_TREE);
+ inOrder.verify(spyProjectVisitor).visitAny(COMPONENT_TREE);
inOrder.verify(spyProjectVisitor).visitProject(COMPONENT_TREE);
inOrder.verifyNoMoreInteractions();
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/component/PreOrderDepthTraversalTypeAwareVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/component/PreOrderDepthTraversalTypeAwareVisitorTest.java
index 2c54c8621d8..c471d2341fc 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/component/PreOrderDepthTraversalTypeAwareVisitorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/component/PreOrderDepthTraversalTypeAwareVisitorTest.java
@@ -66,6 +66,7 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
spyFileVisitor.visit(component);
inOrder.verify(spyFileVisitor).visit(component);
+ inOrder.verify(spyFileVisitor).visitAny(component);
inOrder.verify(spyFileVisitor).visitFile(component);
inOrder.verifyNoMoreInteractions();
}
@@ -76,6 +77,7 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
spyFileVisitor.visit(component);
inOrder.verify(spyFileVisitor).visit(component);
+ inOrder.verify(spyFileVisitor).visitAny(component);
inOrder.verify(spyFileVisitor).visitModule(component);
inOrder.verifyNoMoreInteractions();
}
@@ -86,6 +88,7 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
spyFileVisitor.visit(component);
inOrder.verify(spyFileVisitor).visit(component);
+ inOrder.verify(spyFileVisitor).visitAny(component);
inOrder.verify(spyFileVisitor).visitDirectory(component);
inOrder.verifyNoMoreInteractions();
}
@@ -101,7 +104,7 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
}
@Test
- public void visit_file_with_depth_DIRECTORY_does_not_call_visit_file() {
+ public void visit_file_with_depth_DIRECTORY_does_not_call_visit_file_nor_visitAny() {
Component component = component(FILE, 1);
spyDirectoryVisitor.visit(component);
@@ -115,6 +118,7 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
spyDirectoryVisitor.visit(component);
inOrder.verify(spyDirectoryVisitor).visit(component);
+ inOrder.verify(spyDirectoryVisitor).visitAny(component);
inOrder.verify(spyDirectoryVisitor).visitDirectory(component);
inOrder.verifyNoMoreInteractions();
}
@@ -125,6 +129,7 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
spyDirectoryVisitor.visit(component);
inOrder.verify(spyDirectoryVisitor).visit(component);
+ inOrder.verify(spyDirectoryVisitor).visitAny(component);
inOrder.verify(spyDirectoryVisitor).visitModule(component);
inOrder.verifyNoMoreInteractions();
}
@@ -135,12 +140,13 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
spyDirectoryVisitor.visit(component);
inOrder.verify(spyDirectoryVisitor).visit(component);
+ inOrder.verify(spyDirectoryVisitor).visitAny(component);
inOrder.verify(spyDirectoryVisitor).visitProject(component);
inOrder.verifyNoMoreInteractions();
}
@Test
- public void visit_file_with_depth_MODULE_does_not_call_visit_file() {
+ public void visit_file_with_depth_MODULE_does_not_call_visit_file_nor_visit_any() {
Component component = component(FILE, 1);
spyModuleVisitor.visit(component);
@@ -149,7 +155,7 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
}
@Test
- public void visit_directory_with_depth_MODULE_does_not_call_visit_directory() {
+ public void visit_directory_with_depth_MODULE_does_not_call_visit_directory_not_visit_any() {
Component component = component(DIRECTORY, 1);
spyModuleVisitor.visit(component);
@@ -163,6 +169,7 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
spyModuleVisitor.visit(component);
inOrder.verify(spyModuleVisitor).visit(component);
+ inOrder.verify(spyModuleVisitor).visitAny(component);
inOrder.verify(spyModuleVisitor).visitModule(component);
inOrder.verifyNoMoreInteractions();
}
@@ -173,12 +180,13 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
spyModuleVisitor.visit(component);
inOrder.verify(spyModuleVisitor).visit(component);
+ inOrder.verify(spyModuleVisitor).visitAny(component);
inOrder.verify(spyModuleVisitor).visitModule(component);
inOrder.verifyNoMoreInteractions();
}
@Test
- public void visit_file_with_depth_PROJECT_does_not_call_visit_file() {
+ public void visit_file_with_depth_PROJECT_does_not_call_visit_file_nor_visitAny() {
Component component = component(FILE, 1);
spyProjectVisitor.visit(component);
@@ -187,7 +195,7 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
}
@Test
- public void visit_directory_with_depth_PROJECT_does_not_call_visit_directory() {
+ public void visit_directory_with_depth_PROJECT_does_not_call_visit_directory_nor_visitAny() {
Component component = component(DIRECTORY, 1);
spyProjectVisitor.visit(component);
@@ -196,7 +204,7 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
}
@Test
- public void visit_module_with_depth_PROJECT_does_not_call_visit_module() {
+ public void visit_module_with_depth_PROJECT_does_not_call_visit_module_nor_visitAny() {
Component component = component(MODULE, 1);
spyProjectVisitor.visit(component);
@@ -205,11 +213,12 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
}
@Test
- public void visit_project_with_depth_PROJECT_calls_visit_project() {
+ public void visit_project_with_depth_PROJECT_calls_visit_project_nor_visitAny() {
Component component = component(PROJECT, 1);
spyProjectVisitor.visit(component);
inOrder.verify(spyProjectVisitor).visit(component);
+ inOrder.verify(spyProjectVisitor).visitAny(component);
inOrder.verify(spyProjectVisitor).visitProject(component);
inOrder.verifyNoMoreInteractions();
}
@@ -219,14 +228,19 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
spyFileVisitor.visit(COMPONENT_TREE);
inOrder.verify(spyFileVisitor).visit(COMPONENT_TREE);
+ inOrder.verify(spyFileVisitor).visitAny(COMPONENT_TREE);
inOrder.verify(spyFileVisitor).visitProject(COMPONENT_TREE);
inOrder.verify(spyFileVisitor).visit(MODULE_2);
+ inOrder.verify(spyFileVisitor).visitAny(MODULE_2);
inOrder.verify(spyFileVisitor).visitModule(MODULE_2);
inOrder.verify(spyFileVisitor).visit(DIRECTORY_3);
+ inOrder.verify(spyFileVisitor).visitAny(DIRECTORY_3);
inOrder.verify(spyFileVisitor).visitDirectory(DIRECTORY_3);
inOrder.verify(spyFileVisitor).visit(FILE_4);
+ inOrder.verify(spyFileVisitor).visitAny(FILE_4);
inOrder.verify(spyFileVisitor).visitFile(FILE_4);
inOrder.verify(spyFileVisitor).visit(FILE_5);
+ inOrder.verify(spyFileVisitor).visitAny(FILE_5);
inOrder.verify(spyFileVisitor).visitFile(FILE_5);
inOrder.verifyNoMoreInteractions();
}
@@ -249,8 +263,10 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
spyModuleVisitor.visit(COMPONENT_TREE);
inOrder.verify(spyModuleVisitor).visit(COMPONENT_TREE);
+ inOrder.verify(spyModuleVisitor).visitAny(COMPONENT_TREE);
inOrder.verify(spyModuleVisitor).visitProject(COMPONENT_TREE);
inOrder.verify(spyModuleVisitor).visit(MODULE_2);
+ inOrder.verify(spyModuleVisitor).visitAny(MODULE_2);
inOrder.verify(spyModuleVisitor).visitModule(MODULE_2);
inOrder.verifyNoMoreInteractions();
}
@@ -260,6 +276,7 @@ public class PreOrderDepthTraversalTypeAwareVisitorTest {
spyProjectVisitor.visit(COMPONENT_TREE);
inOrder.verify(spyProjectVisitor).visit(COMPONENT_TREE);
+ inOrder.verify(spyProjectVisitor).visitAny(COMPONENT_TREE);
inOrder.verify(spyProjectVisitor).visitProject(COMPONENT_TREE);
inOrder.verifyNoMoreInteractions();
}