"This helps in maintenance by decreasing the maintained code size, " +
"making it easier to understand the program and preventing bugs from being introduced.</p>" +
"<p>In the following two cases, private methods are not considered as dead code by Sonar :</p>" +
- "<ul><li>Private empty constructors that are intentionally used to prevent any direct instanciation of a class.</li>" +
+ "<ul><li>Private empty constructors that are intentionally used to prevent any direct instantiation of a class.</li>" +
"<li>Private methods : readObject(...), writeObject(...), writeReplace(...), readResolve(...) " +
"which can contractually be used when implementing the Serializable interface.</li></ul>")
public class UnusedPrivateMethodCheck extends BytecodeCheck {
import org.sonar.api.ExtensionProvider;
import org.sonar.api.Plugin;
import org.sonar.api.batch.CoverageExtension;
-import org.sonar.api.batch.InstanciationStrategy;
+import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
import java.util.List;
void installExtension(Module module, Object extension) {
if (ExtensionUtils.isBatchExtension(extension) &&
ExtensionUtils.isSupportedEnvironment(extension, environment) &&
- ExtensionUtils.isInstantiationStrategy(extension, InstanciationStrategy.PER_BATCH)) {
+ ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_BATCH)) {
if (ExtensionUtils.isType(extension, CoverageExtension.class)) {
- throw new IllegalArgumentException("Instantiation strategy " + InstanciationStrategy.PER_BATCH + " is not supported on CoverageExtension components: " + extension);
+ throw new IllegalArgumentException("Instantiation strategy " + InstantiationStrategy.PER_BATCH + " is not supported on CoverageExtension components: " + extension);
}
module.addComponent(extension);
}
import org.apache.commons.lang.StringUtils;
import org.sonar.api.BatchExtension;
import org.sonar.api.Extension;
-import org.sonar.api.batch.InstanciationStrategy;
+import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.SupportedEnvironment;
import org.sonar.api.utils.AnnotationUtils;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
static boolean isInstantiationStrategy(Object extension, String strategy) {
Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass());
- InstanciationStrategy extStrategy = AnnotationUtils.getClassAnnotation(clazz, InstanciationStrategy.class);
+ InstantiationStrategy extStrategy = AnnotationUtils.getClassAnnotation(clazz, InstantiationStrategy.class);
if (extStrategy != null) {
return strategy.equals(extStrategy.value());
}
- return InstanciationStrategy.PER_PROJECT.equals(strategy);
+ return InstantiationStrategy.PER_PROJECT.equals(strategy);
}
static boolean isBatchExtension(Object extension) {
import org.sonar.api.Plugin;
import org.sonar.api.batch.AbstractCoverageExtension;
import org.sonar.api.batch.CoverageExtension;
-import org.sonar.api.batch.InstanciationStrategy;
+import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
private Object installExtension(Module module, Object extension, Project project, String pluginKey) {
if (ExtensionUtils.isBatchExtension(extension) &&
ExtensionUtils.isSupportedEnvironment(extension, environment) &&
- ExtensionUtils.isInstantiationStrategy(extension, InstanciationStrategy.PER_PROJECT) &&
+ ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_PROJECT) &&
!isDeactivatedCoverageExtension(extension, project, pluginKey)) {
module.addComponent(extension);
import org.junit.Test;
import org.sonar.api.*;
import org.sonar.api.batch.CoverageExtension;
-import org.sonar.api.batch.InstanciationStrategy;
+import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
import java.util.Arrays;
}
}
- @InstanciationStrategy(InstanciationStrategy.PER_BATCH)
+ @InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public static class BatchService implements BatchExtension {
}
}
- @InstanciationStrategy(InstanciationStrategy.PER_BATCH)
+ @InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public static class BatchServiceProvider extends ExtensionProvider implements BatchExtension {
@Override
}
}
- @InstanciationStrategy(InstanciationStrategy.PER_BATCH)
+ @InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public static class InvalidCoverageExtension implements CoverageExtension {
// strategy PER_BATCH is not allowed
}
import org.junit.Test;
import org.sonar.api.BatchExtension;
import org.sonar.api.ServerExtension;
-import org.sonar.api.batch.InstanciationStrategy;
+import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.SupportedEnvironment;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
@Test
public void shouldBeBatchInstantiationStrategy() {
- assertThat(ExtensionUtils.isInstantiationStrategy(BatchService.class, InstanciationStrategy.PER_BATCH), is(true));
- assertThat(ExtensionUtils.isInstantiationStrategy(new BatchService(), InstanciationStrategy.PER_BATCH), is(true));
- assertThat(ExtensionUtils.isInstantiationStrategy(ProjectService.class, InstanciationStrategy.PER_BATCH), is(false));
- assertThat(ExtensionUtils.isInstantiationStrategy(new ProjectService(), InstanciationStrategy.PER_BATCH), is(false));
- assertThat(ExtensionUtils.isInstantiationStrategy(DefaultService.class, InstanciationStrategy.PER_BATCH), is(false));
- assertThat(ExtensionUtils.isInstantiationStrategy(new DefaultService(), InstanciationStrategy.PER_BATCH), is(false));
+ assertThat(ExtensionUtils.isInstantiationStrategy(BatchService.class, InstantiationStrategy.PER_BATCH), is(true));
+ assertThat(ExtensionUtils.isInstantiationStrategy(new BatchService(), InstantiationStrategy.PER_BATCH), is(true));
+ assertThat(ExtensionUtils.isInstantiationStrategy(ProjectService.class, InstantiationStrategy.PER_BATCH), is(false));
+ assertThat(ExtensionUtils.isInstantiationStrategy(new ProjectService(), InstantiationStrategy.PER_BATCH), is(false));
+ assertThat(ExtensionUtils.isInstantiationStrategy(DefaultService.class, InstantiationStrategy.PER_BATCH), is(false));
+ assertThat(ExtensionUtils.isInstantiationStrategy(new DefaultService(), InstantiationStrategy.PER_BATCH), is(false));
}
@Test
public void shouldBeProjectInstantiationStrategy() {
- assertThat(ExtensionUtils.isInstantiationStrategy(BatchService.class, InstanciationStrategy.PER_PROJECT), is(false));
- assertThat(ExtensionUtils.isInstantiationStrategy(new BatchService(), InstanciationStrategy.PER_PROJECT), is(false));
- assertThat(ExtensionUtils.isInstantiationStrategy(ProjectService.class, InstanciationStrategy.PER_PROJECT), is(true));
- assertThat(ExtensionUtils.isInstantiationStrategy(new ProjectService(), InstanciationStrategy.PER_PROJECT), is(true));
- assertThat(ExtensionUtils.isInstantiationStrategy(DefaultService.class, InstanciationStrategy.PER_PROJECT), is(true));
- assertThat(ExtensionUtils.isInstantiationStrategy(new DefaultService(), InstanciationStrategy.PER_PROJECT), is(true));
+ assertThat(ExtensionUtils.isInstantiationStrategy(BatchService.class, InstantiationStrategy.PER_PROJECT), is(false));
+ assertThat(ExtensionUtils.isInstantiationStrategy(new BatchService(), InstantiationStrategy.PER_PROJECT), is(false));
+ assertThat(ExtensionUtils.isInstantiationStrategy(ProjectService.class, InstantiationStrategy.PER_PROJECT), is(true));
+ assertThat(ExtensionUtils.isInstantiationStrategy(new ProjectService(), InstantiationStrategy.PER_PROJECT), is(true));
+ assertThat(ExtensionUtils.isInstantiationStrategy(DefaultService.class, InstantiationStrategy.PER_PROJECT), is(true));
+ assertThat(ExtensionUtils.isInstantiationStrategy(new DefaultService(), InstantiationStrategy.PER_PROJECT), is(true));
}
@Test
assertThat(ExtensionUtils.isSupportedEnvironment(new BuildToolService(), new EnvironmentInformation("eclipse", "0.1")), is(false));
}
- @InstanciationStrategy(InstanciationStrategy.PER_BATCH)
+ @InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public static class BatchService implements BatchExtension {
}
- @InstanciationStrategy(InstanciationStrategy.PER_PROJECT)
+ @InstantiationStrategy(InstantiationStrategy.PER_PROJECT)
public static class ProjectService implements BatchExtension {
}
} catch (ClassNotFoundException e) {
// dialectId was not a class name :)
} catch (Exception e) {
- throw new SonarException("Unable to instanciate dialect class", e);
+ throw new SonarException("Unable to instantiate dialect class", e);
}
return null;
}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.batch;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Define instanciation strategy of batch extensions. If an extension is not annotated, then default value
- * is {@link org.sonar.api.batch.InstanciationStrategy#PER_PROJECT}.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-public @interface InstanciationStrategy {
-
- /**
- * Shared extension. Lifecycle is the full analysis.
- */
- public static final String PER_BATCH = "PER_BATCH";
-
- /**
- * Created and initialized for each project and sub-project (a project is a module in Maven terminology).
- */
- public static final String PER_PROJECT = "PER_PROJECT";
-
- String value();
-}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.batch;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Define instantiation strategy of batch extensions. If an extension is not annotated, then default value
+ * is {@link org.sonar.api.batch.InstantiationStrategy#PER_PROJECT}.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface InstantiationStrategy {
+
+ /**
+ * Shared extension. Lifecycle is the full analysis.
+ */
+ public static final String PER_BATCH = "PER_BATCH";
+
+ /**
+ * Created and initialized for each project and sub-project (a project is a module in Maven terminology).
+ */
+ public static final String PER_PROJECT = "PER_PROJECT";
+
+ String value();
+}