Removed redundant variable types

This commit is contained in:
Erik C. Thauvin 2023-08-20 13:40:33 -07:00
parent 65fb61daf4
commit 9ddf470e40
10 changed files with 29 additions and 29 deletions

View file

@ -4,5 +4,6 @@
<inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ADDITIONAL_TAGS" value="created,created.on" />
</inspection_tool>
<inspection_tool class="RedundantExplicitVariableType" enabled="true" level="INFORMATION" enabled_by_default="true" editorAttributes="INFORMATION_ATTRIBUTES" />
</profile>
</component>

View file

@ -13,7 +13,7 @@ public final class App {
* @param args The command line parameters.
*/
public static void main(final String... args) {
final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z", Locale.US);
final var sdf = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z", Locale.US);
System.out.println("-----------------------------------------------------");

View file

@ -9,7 +9,7 @@ import java.util.Locale;
keysPrefix = "example.")
public class Example {
public static void main(final String... args) {
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
final var sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
System.out.println("-- From Example -------------------------------------");

View file

@ -9,7 +9,7 @@ import java.util.Date;
public final class ExampleVersion {
public static final String PROJECT = "Java Example";
public static final Date BUILDDATE = new Date(1692423608415L);
public static final Date BUILDDATE = new Date(1692564205424L);
public static final String VERSION = "8.4.97-alpha+T800";
/**

View file

@ -14,7 +14,7 @@ import java.util.Date;
*/
public final class GeneratedVersion {
public static final String PROJECT = "Java App";
public static final Date BUILDDATE = new Date(1692423608452L);
public static final Date BUILDDATE = new Date(1692564205452L);
public static final int MAJOR = 11;
public static final int MINOR = 11;
public static final int PATCH = 20;

View file

@ -13,7 +13,7 @@ public final class App {
* @param args The command line parameters.
*/
public static void main(final String... args) {
final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z", Locale.US);
final var sdf = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z", Locale.US);
System.out.println("-----------------------------------------------------");

View file

@ -14,7 +14,7 @@ public final class Example {
* @param args The command line parameters.
*/
public static void main(final String... args) {
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
final var sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
System.out.println("-- From Example -------------------------------------");

View file

@ -93,16 +93,16 @@ public class VersionProcessor extends AbstractProcessor {
}
private VersionInfo findValues(final Version version) throws IOException {
final VersionInfo versionInfo = new VersionInfo(version);
final var versionInfo = new VersionInfo(version);
if (!version.properties().isEmpty()) {
final File propsFile = getLocalFile(version.properties());
final var propsFile = getLocalFile(version.properties());
if (propsFile.isFile() && propsFile.canRead()) {
note("Found properties: " + propsFile.getName() + " (" + propsFile.getAbsoluteFile().getParent() + ')');
final Properties p = new Properties();
final var p = new Properties();
try (InputStreamReader reader = new InputStreamReader(
try (var reader = new InputStreamReader(
Files.newInputStream(propsFile.toPath()), StandardCharsets.UTF_8)) {
p.load(reader);
@ -143,7 +143,7 @@ public class VersionProcessor extends AbstractProcessor {
private File getLocalFile(final String fileName) {
if (processingEnv != null) { // null when testing.
final String prop = processingEnv.getOptions().get(Constants.SEMVER_PROJECT_DIR_ARG);
final var prop = processingEnv.getOptions().get(Constants.SEMVER_PROJECT_DIR_ARG);
if (prop != null) {
return new File(prop, fileName);
}
@ -185,20 +185,20 @@ public class VersionProcessor extends AbstractProcessor {
*/
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
final boolean isLocalTemplate = getLocalFile(Constants.DEFAULT_TEMPLATE_NAME).exists();
final var isLocalTemplate = getLocalFile(Constants.DEFAULT_TEMPLATE_NAME).exists();
for (final Element element : roundEnv.getElementsAnnotatedWith(Version.class)) {
final Version version = element.getAnnotation(Version.class);
final var version = element.getAnnotation(Version.class);
if (element.getKind() == ElementKind.CLASS) {
final Element enclosingElement = element.getEnclosingElement();
final var enclosingElement = element.getEnclosingElement();
if (enclosingElement.getKind() == ElementKind.PACKAGE) {
final PackageElement packageElement = (PackageElement) enclosingElement;
final var packageElement = (PackageElement) enclosingElement;
try {
final VersionInfo versionInfo = findValues(version);
final var versionInfo = findValues(version);
if (Constants.EMPTY.equals(version.packageName())) {
versionInfo.setPackageName(packageElement.getQualifiedName().toString());
}
note("Found version: " + versionInfo.getVersion());
final String template = getTemplate(isLocalTemplate, version);
final var template = getTemplate(isLocalTemplate, version);
writeTemplate(version.type(), versionInfo, template);
} catch (IOException | MustacheNotFoundException e) {
@ -239,7 +239,7 @@ public class VersionProcessor extends AbstractProcessor {
final var dir = getLocalFile("");
final var mustache = compileTemplate(dir, template);
final String templateName = switch (mustache.getName()) {
final var templateName = switch (mustache.getName()) {
case Constants.DEFAULT_JAVA_TEMPLATE -> "default (Java)";
case Constants.DEFAULT_KOTLIN_TEMPLATE -> "default (Kotlin)";
default -> mustache.getName() + " (" + dir.getAbsolutePath() + ')';
@ -248,15 +248,15 @@ public class VersionProcessor extends AbstractProcessor {
final var fileName = versionInfo.getClassName() + '.' + type;
if (Constants.KOTLIN_TYPE.equalsIgnoreCase(type)) {
final String kaptGenDir = processingEnv.getOptions().get(Constants.KAPT_KOTLIN_GENERATED_OPTION_NAME);
final var kaptGenDir = processingEnv.getOptions().get(Constants.KAPT_KOTLIN_GENERATED_OPTION_NAME);
if (kaptGenDir == null) {
throw new IOException("Could not find the target directory for generated Kotlin files.");
}
final File ktFile = new File(kaptGenDir, fileName);
final var ktFile = new File(kaptGenDir, fileName);
if (!ktFile.getParentFile().exists() && !ktFile.getParentFile().mkdirs()) {
note("Could not create target directory: " + ktFile.getParentFile().getAbsolutePath());
}
try (OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(ktFile.toPath()),
try (var osw = new OutputStreamWriter(Files.newOutputStream(ktFile.toPath()),
StandardCharsets.UTF_8)) {
mustache.execute(osw, versionInfo).flush();
}
@ -264,7 +264,7 @@ public class VersionProcessor extends AbstractProcessor {
} else {
final FileObject jfo = filer.createSourceFile(
versionInfo.getPackageName() + '.' + versionInfo.getClassName());
try (Writer writer = jfo.openWriter()) {
try (var writer = jfo.openWriter()) {
mustache.execute(writer, versionInfo).flush();
}
note("Generated source: " + fileName + " (" + new File(jfo.getName()).getAbsoluteFile().getParent() + ')');

View file

@ -66,7 +66,7 @@ class ConstantsTest {
templates.add(Constants.DEFAULT_KOTLIN_TEMPLATE);
templates.add(Constants.DEFAULT_TEMPLATE_NAME);
for (final String tp : templates) {
for (final var tp : templates) {
assertTrue(tp.endsWith(".mustache"), tp);
}
}

View file

@ -39,7 +39,6 @@ import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;
import static org.junit.jupiter.api.Assertions.*;
@ -114,9 +113,9 @@ class VersionProcessorTest {
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
@Test
void testFindValues() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
final Method method = processor.getClass().getDeclaredMethod("findValues", Version.class);
final var method = processor.getClass().getDeclaredMethod("findValues", Version.class);
method.setAccessible(true);
final VersionInfo versionInfo = (VersionInfo) method.invoke(processor, version);
final var versionInfo = (VersionInfo) method.invoke(processor, version);
assertEquals("0-0-7:vodka++martini", versionInfo.getVersion(), "getVersion(0-0-7:vodka++martin)");
assertEquals("James Bond", versionInfo.getProject(), "getProject(James Bond)");
@ -125,7 +124,7 @@ class VersionProcessorTest {
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
@Test
void testGetTemplate() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
final Method method = processor.getClass().getDeclaredMethod("getTemplate", boolean.class, Version.class);
final var method = processor.getClass().getDeclaredMethod("getTemplate", boolean.class, Version.class);
method.setAccessible(true);
assertEquals(version.template(), method.invoke(processor, true, version), version.template);
@ -139,13 +138,13 @@ class VersionProcessorTest {
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
@Test
void testParseIntProperty() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
final Properties p = new Properties();
final var p = new Properties();
p.setProperty("1", "1");
p.setProperty("2", "2.1");
p.setProperty("3", "zero");
p.setProperty("4", " 4 ");
final Method method = processor.getClass().getDeclaredMethod("parseIntProperty", Properties.class, String.class,
final var method = processor.getClass().getDeclaredMethod("parseIntProperty", Properties.class, String.class,
int.class);
method.setAccessible(true);