From b1f137ca79da8dcee79ff258cd39d439fad80820 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Wed, 12 Aug 2015 17:55:34 +0200 Subject: [PATCH] add Component.Type#VIEW, SUBVIEW and PROJECT_VIEW --- .../computation/component/Component.java | 15 ++++++- .../DepthTraversalTypeAwareCrawler.java | 33 +++++----------- .../component/PathAwareCrawler.java | 9 +++++ .../component/PathAwareVisitor.java | 39 +++++++++++++++++++ .../component/PathAwareVisitorAdapter.java | 30 ++++++++++++++ .../component/PathAwareVisitorWrapper.java | 15 +++++++ .../component/TypeAwareVisitor.java | 15 +++++++ .../component/TypeAwareVisitorAdapter.java | 24 ++++++++++++ .../component/TypeAwareVisitorWrapper.java | 15 +++++++ 9 files changed, 170 insertions(+), 25 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java index 5658daf4aa3..a70ca336884 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java @@ -19,12 +19,17 @@ */ package org.sonar.server.computation.component; +import java.util.EnumSet; import java.util.List; +import java.util.Set; import org.sonar.server.computation.step.FillComponentsStep; public interface Component { enum Type { - PROJECT(0), MODULE(1), DIRECTORY(2), FILE(3); + PROJECT(0), MODULE(1), DIRECTORY(2), FILE(3), VIEW(0), SUBVIEW(1), PROJECT_VIEW(2); + + private static final Set REPORT_TYPES = EnumSet.of(PROJECT, MODULE, DIRECTORY, FILE); + private static final Set VIEWS_TYPES = EnumSet.of(VIEW, SUBVIEW, PROJECT_VIEW); private final int depth; @@ -43,6 +48,14 @@ public interface Component { public boolean isHigherThan(Type otherType) { return this.getDepth() < otherType.getDepth(); } + + public boolean isReportType() { + return REPORT_TYPES.contains(this); + } + + public boolean isViewsType() { + return VIEWS_TYPES.contains(this); + } } Type getType(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/DepthTraversalTypeAwareCrawler.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/DepthTraversalTypeAwareCrawler.java index 779f9816764..d2f07f0d7d8 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/DepthTraversalTypeAwareCrawler.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/DepthTraversalTypeAwareCrawler.java @@ -63,6 +63,15 @@ public abstract class DepthTraversalTypeAwareCrawler extends TypeAwareVisitorAda case FILE: visitFile(component); break; + case VIEW: + visitView(component); + break; + case SUBVIEW: + visitSubView(component); + break; + case PROJECT_VIEW: + visitProjectView(component); + break; default: visitUnknown(component); } @@ -76,33 +85,9 @@ public abstract class DepthTraversalTypeAwareCrawler extends TypeAwareVisitorAda } } - @Override - public void visitProject(Component project) { - // empty implementation, meant to be override at will by subclasses - } - - @Override - public void visitModule(Component module) { - // empty implementation, meant to be override at will by subclasses - } - - @Override - public void visitDirectory(Component directory) { - // empty implementation, meant to be override at will by subclasses - } - - @Override - public void visitFile(Component file) { - // empty implementation, meant to be override at will by subclasses - } - @Override public void visitUnknown(Component unknownComponent) { // 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 - } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareCrawler.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareCrawler.java index cc669661ca4..b1e89489706 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareCrawler.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareCrawler.java @@ -80,6 +80,15 @@ public abstract class PathAwareCrawler extends PathAwareVisitorAdapter imp case FILE: visitFile(component, stack); break; + case VIEW: + visitView(component, stack); + break; + case SUBVIEW: + visitSubView(component, stack); + break; + case PROJECT_VIEW: + visitProjectView(component, stack); + break; default: visitUnknown(component, stack); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareVisitor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareVisitor.java index 1dd23d7b6ac..8144eeb98cd 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareVisitor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareVisitor.java @@ -31,16 +31,49 @@ public interface PathAwareVisitor extends ComponentVisitor { StackElementFactory getFactory(); + /** + * Called when encountering a Component of type {@link Component.Type#PROJECT} + */ void visitProject(Component project, Path path); + /** + * Called when encountering a Component of type {@link Component.Type#MODULE} + */ void visitModule(Component module, Path path); + /** + * Called when encountering a Component of type {@link Component.Type#DIRECTORY} + */ void visitDirectory(Component directory, Path path); + /** + * Called when encountering a Component of type {@link Component.Type#FILE} + */ void visitFile(Component file, Path path); + /** + * Called when encountering a Component of type {@link Component.Type#VIEW} + */ + void visitView(Component view, Path path); + + /** + * Called when encountering a Component of type {@link Component.Type#SUBVIEW} + */ + void visitSubView(Component subView, Path path); + + /** + * Called when encountering a Component of type {@link Component.Type#PROJECT_VIEW} + */ + void visitProjectView(Component projectView, Path path); + + /** + * Called when encountering a Component which type has no visit method in this interface. + */ void visitUnknown(Component unknownComponent, Path path); + /** + * Called for any component, in addition to the methods specific to each type + */ void visitAny(Component component, Path path); interface StackElementFactory { @@ -52,6 +85,12 @@ public interface PathAwareVisitor extends ComponentVisitor { T createForFile(Component file); + T createForView(Component view); + + T createForSubView(Component subView); + + T createForProjectView(Component projectView); + T createForUnknown(Component file); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareVisitorAdapter.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareVisitorAdapter.java index 775e7b60d57..630074a5a65 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareVisitorAdapter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareVisitorAdapter.java @@ -71,6 +71,21 @@ public abstract class PathAwareVisitorAdapter implements PathAwareVisitor // empty implementation, meant to be override at will by subclasses } + @Override + public void visitView(Component view, Path path) { + // empty implementation, meant to be override at will by subclasses + } + + @Override + public void visitSubView(Component subView, Path path) { + // empty implementation, meant to be override at will by subclasses + } + + @Override + public void visitProjectView(Component projectView, Path path) { + // empty implementation, meant to be override at will by subclasses + } + @Override public void visitUnknown(Component unknownComponent, Path path) { // empty implementation, meant to be override at will by subclasses @@ -109,6 +124,21 @@ public abstract class PathAwareVisitorAdapter implements PathAwareVisitor return createForAny(file); } + @Override + public T createForView(Component view) { + return createForAny(view); + } + + @Override + public T createForSubView(Component subView) { + return createForAny(subView); + } + + @Override + public T createForProjectView(Component projectView) { + return createForAny(projectView); + } + @Override public T createForUnknown(Component file) { return createForAny(file); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareVisitorWrapper.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareVisitorWrapper.java index ca4e12853f2..f6df44655c6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareVisitorWrapper.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/PathAwareVisitorWrapper.java @@ -60,6 +60,21 @@ public class PathAwareVisitorWrapper implements VisitorWrapper { delegate.visitFile(tree, stack); } + @Override + public void visitView(Component view) { + delegate.visitView(view, stack); + } + + @Override + public void visitSubView(Component subView) { + delegate.visitSubView(subView, stack); + } + + @Override + public void visitProjectView(Component projectView) { + delegate.visitProjectView(projectView, stack); + } + @Override public void visitAny(Component component) { delegate.visitAny(component, stack); 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 d49db4b8f89..2431ec0fdee 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 @@ -44,6 +44,21 @@ public interface TypeAwareVisitor extends ComponentVisitor { */ void visitFile(Component file); + /** + * Called when encountering a Component of type {@link Component.Type#VIEW} + */ + void visitView(Component view); + + /** + * Called when encountering a Component of type {@link Component.Type#SUBVIEW} + */ + void visitSubView(Component subView); + + /** + * Called when encountering a Component of type {@link Component.Type#PROJECT_VIEW} + */ + void visitProjectView(Component projectView); + /** * Called for any component, in addition to the methods specific to each type */ diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/TypeAwareVisitorAdapter.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/TypeAwareVisitorAdapter.java index a8e469275f2..29d7c3babe5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/TypeAwareVisitorAdapter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/TypeAwareVisitorAdapter.java @@ -77,6 +77,30 @@ public abstract class TypeAwareVisitorAdapter implements TypeAwareVisitor { // empty implementation, meant to be override at will by subclasses } + /** + * Called when encountering a Component of type {@link Component.Type#VIEW} + */ + @Override + public void visitView(Component view) { + // empty implementation, meant to be override at will by subclasses + } + + /** + * Called when encountering a Component of type {@link Component.Type#SUBVIEW} + */ + @Override + public void visitSubView(Component subView) { + // empty implementation, meant to be override at will by subclasses + } + + /** + * Called when encountering a Component of type {@link Component.Type#PROJECT_VIEW} + */ + @Override + public void visitProjectView(Component projectView) { + // empty implementation, meant to be override at will by subclasses + } + /** * Called for any component, in addition to the methods specific to each type */ diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/TypeAwareVisitorWrapper.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/TypeAwareVisitorWrapper.java index 814cb8a0370..8540ec26bb2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/TypeAwareVisitorWrapper.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/TypeAwareVisitorWrapper.java @@ -58,6 +58,21 @@ public class TypeAwareVisitorWrapper implements VisitorWrapper { delegate.visitFile(tree); } + @Override + public void visitView(Component view) { + delegate.visitView(view); + } + + @Override + public void visitSubView(Component subView) { + delegate.visitSubView(subView); + } + + @Override + public void visitProjectView(Component projectView) { + delegate.visitProjectView(projectView); + } + @Override public void visitAny(Component component) { delegate.visitAny(component); -- 2.39.5