diff options
8 files changed, 25 insertions, 18 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/ClassComplexityDistributionBuilder.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/ClassComplexityDistributionBuilder.java index 2b8eb53be18..2ff7b38cf9f 100644 --- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/ClassComplexityDistributionBuilder.java +++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/ClassComplexityDistributionBuilder.java @@ -50,7 +50,7 @@ public final class ClassComplexityDistributionBuilder implements Decorator { if (shouldExecuteOn(resource, context)) { RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, LIMITS); for (DecoratorContext childContext : context.getChildren()) { - if (Scopes.isType(childContext.getResource())) { + if (Scopes.isProgramUnit(childContext.getResource())) { Measure complexity = childContext.getMeasure(CoreMetrics.COMPLEXITY); if (complexity != null) { builder.add(complexity.getValue()); diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/ClassesDecorator.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/ClassesDecorator.java index 5e87d950cb4..11501ba7a6b 100644 --- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/ClassesDecorator.java +++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/ClassesDecorator.java @@ -34,7 +34,7 @@ public final class ClassesDecorator implements Decorator { if (Scopes.isFile(resource)) { int classes = 0; for (DecoratorContext child : context.getChildren()) { - if (Scopes.isType(child.getResource())) { + if (Scopes.isProgramUnit(child.getResource())) { classes++; } } diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/FunctionComplexityDistributionBuilder.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/FunctionComplexityDistributionBuilder.java index 66570870c6f..6b9477ba720 100644 --- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/FunctionComplexityDistributionBuilder.java +++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/FunctionComplexityDistributionBuilder.java @@ -66,7 +66,7 @@ public final class FunctionComplexityDistributionBuilder implements Decorator { } boolean shouldExecuteOn(Resource resource, DecoratorContext context) { - return Scopes.isType(resource) && context.getMeasure(CoreMetrics.COMPLEXITY) != null; + return Scopes.isProgramUnit(resource) && context.getMeasure(CoreMetrics.COMPLEXITY) != null; } public boolean shouldExecuteOnProject(Project project) { diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/FunctionsDecorator.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/FunctionsDecorator.java index 0f15bf37fa5..dddc3c6efca 100644 --- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/FunctionsDecorator.java +++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/decorators/FunctionsDecorator.java @@ -32,7 +32,7 @@ import org.sonar.java.api.JavaMethod; public final class FunctionsDecorator implements Decorator { public void decorate(Resource resource, DecoratorContext context) { - if (Scopes.isType(resource)) { + if (Scopes.isProgramUnit(resource)) { int methods=0, accessors=0; for (DecoratorContext child : context.getChildren()) { if (child.getResource() instanceof JavaMethod) { diff --git a/sonar-java-api/src/main/java/org/sonar/java/api/JavaClass.java b/sonar-java-api/src/main/java/org/sonar/java/api/JavaClass.java index 59f046bf6ff..724be07867b 100644 --- a/sonar-java-api/src/main/java/org/sonar/java/api/JavaClass.java +++ b/sonar-java-api/src/main/java/org/sonar/java/api/JavaClass.java @@ -27,7 +27,7 @@ import org.sonar.api.resources.*; */ public final class JavaClass extends Resource { - public static final String SCOPE = Scopes.TYPE; + public static final String SCOPE = Scopes.PROGRAM_UNIT; public static final String QUALIFIER = Qualifiers.CLASS; public static final int UNKNOWN_LINE = -1; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Scopes.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Scopes.java index 2f4677ed366..c992cb36e1f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Scopes.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Scopes.java @@ -25,9 +25,9 @@ import org.apache.commons.lang.StringUtils; /** * Resource scopes are used to group some types of resources. For example Java methods, Flex methods, C functions * and Cobol paragraphs are grouped in the scope "block unit". - * + * <p/> * Scopes are generally used in UI to display/hide some services or in web services. - * + * <p/> * Scopes are not extensible by plugins. * * @since 2.6 @@ -37,6 +37,7 @@ public final class Scopes { private Scopes() { // only static methods } + /** * For example view, subview, project, module or library. Persisted in database. */ @@ -57,14 +58,14 @@ public final class Scopes { /** * Types like Java classes/interfaces. Not persisted in database. */ - public static final String TYPE = "TYP"; + public static final String PROGRAM_UNIT = "PGU"; /** * Block units like methods, functions or Cobol paragraphs. */ public static final String BLOCK_UNIT = "BLU"; - public static final String[] SORTED_SCOPES = {PROJECT, DIRECTORY, FILE, TYPE, BLOCK_UNIT}; + public static final String[] SORTED_SCOPES = {PROJECT, DIRECTORY, FILE, PROGRAM_UNIT, BLOCK_UNIT}; public static boolean isProject(final Resource resource) { @@ -75,12 +76,18 @@ public final class Scopes { return StringUtils.equals(DIRECTORY, resource.getScope()); } + /** + * This scope is sometimes called a "compilation unit". + */ public static boolean isFile(final Resource resource) { return StringUtils.equals(FILE, resource.getScope()); } - public static boolean isType(final Resource resource) { - return StringUtils.equals(TYPE, resource.getScope()); + /** + * A program unit can be a Java class. + */ + public static boolean isProgramUnit(final Resource resource) { + return StringUtils.equals(PROGRAM_UNIT, resource.getScope()); } public static boolean isBlockUnit(final Resource resource) { @@ -94,7 +101,7 @@ public final class Scopes { public static boolean isHigherThan(final String scope, final String than) { int index = ArrayUtils.indexOf(SORTED_SCOPES, scope); int thanIndex = ArrayUtils.indexOf(SORTED_SCOPES, than); - return index<thanIndex; + return index < thanIndex; } public static boolean isHigherThanOrEquals(final Resource resource, final String than) { @@ -104,6 +111,6 @@ public final class Scopes { public static boolean isHigherThanOrEquals(final String scope, final String than) { int index = ArrayUtils.indexOf(SORTED_SCOPES, scope); int thanIndex = ArrayUtils.indexOf(SORTED_SCOPES, than); - return index<=thanIndex; + return index <= thanIndex; } }
\ No newline at end of file diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java index a5240345f6d..f6cad4d31de 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java @@ -78,7 +78,7 @@ public class ResourceUtilsTest { @Test public void shouldNotBePersistable() { Resource javaClass = mock(Resource.class); - when(javaClass.getScope()).thenReturn(Scopes.TYPE); + when(javaClass.getScope()).thenReturn(Scopes.PROGRAM_UNIT); Resource javaMethod = mock(Resource.class); when(javaMethod.getScope()).thenReturn(Scopes.BLOCK_UNIT); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java index 1cd288c5543..5674f5dd8f4 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java @@ -33,7 +33,7 @@ public class ScopesTest { assertThat(Scopes.isDirectory(resource), is(false)); assertThat(Scopes.isFile(resource), is(false)); assertThat(Scopes.isBlockUnit(resource), is(false)); - assertThat(Scopes.isType(resource), is(false)); + assertThat(Scopes.isProgramUnit(resource), is(false)); } @Test @@ -43,7 +43,7 @@ public class ScopesTest { assertThat(Scopes.isDirectory(resource), is(false)); assertThat(Scopes.isFile(resource), is(false)); assertThat(Scopes.isBlockUnit(resource), is(false)); - assertThat(Scopes.isType(resource), is(false)); + assertThat(Scopes.isProgramUnit(resource), is(false)); } @Test @@ -53,7 +53,7 @@ public class ScopesTest { assertThat(Scopes.isDirectory(resource), is(true)); assertThat(Scopes.isFile(resource), is(false)); assertThat(Scopes.isBlockUnit(resource), is(false)); - assertThat(Scopes.isType(resource), is(false)); + assertThat(Scopes.isProgramUnit(resource), is(false)); } @Test @@ -63,7 +63,7 @@ public class ScopesTest { assertThat(Scopes.isDirectory(resource), is(false)); assertThat(Scopes.isFile(resource), is(true)); assertThat(Scopes.isBlockUnit(resource), is(false)); - assertThat(Scopes.isType(resource), is(false)); + assertThat(Scopes.isProgramUnit(resource), is(false)); } @Test |