Removed redundant variable types
This commit is contained in:
parent
65fb61daf4
commit
9ddf470e40
10 changed files with 29 additions and 29 deletions
1
.idea/inspectionProfiles/Project_Default.xml
generated
1
.idea/inspectionProfiles/Project_Default.xml
generated
|
@ -4,5 +4,6 @@
|
||||||
<inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true">
|
<inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
<option name="ADDITIONAL_TAGS" value="created,created.on" />
|
<option name="ADDITIONAL_TAGS" value="created,created.on" />
|
||||||
</inspection_tool>
|
</inspection_tool>
|
||||||
|
<inspection_tool class="RedundantExplicitVariableType" enabled="true" level="INFORMATION" enabled_by_default="true" editorAttributes="INFORMATION_ATTRIBUTES" />
|
||||||
</profile>
|
</profile>
|
||||||
</component>
|
</component>
|
|
@ -13,7 +13,7 @@ public final class App {
|
||||||
* @param args The command line parameters.
|
* @param args The command line parameters.
|
||||||
*/
|
*/
|
||||||
public static void main(final String... args) {
|
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("-----------------------------------------------------");
|
System.out.println("-----------------------------------------------------");
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.util.Locale;
|
||||||
keysPrefix = "example.")
|
keysPrefix = "example.")
|
||||||
public class Example {
|
public class Example {
|
||||||
public static void main(final String... args) {
|
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 -------------------------------------");
|
System.out.println("-- From Example -------------------------------------");
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.util.Date;
|
||||||
|
|
||||||
public final class ExampleVersion {
|
public final class ExampleVersion {
|
||||||
public static final String PROJECT = "Java Example";
|
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";
|
public static final String VERSION = "8.4.97-alpha+T800";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,7 +14,7 @@ import java.util.Date;
|
||||||
*/
|
*/
|
||||||
public final class GeneratedVersion {
|
public final class GeneratedVersion {
|
||||||
public static final String PROJECT = "Java App";
|
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 MAJOR = 11;
|
||||||
public static final int MINOR = 11;
|
public static final int MINOR = 11;
|
||||||
public static final int PATCH = 20;
|
public static final int PATCH = 20;
|
||||||
|
|
|
@ -13,7 +13,7 @@ public final class App {
|
||||||
* @param args The command line parameters.
|
* @param args The command line parameters.
|
||||||
*/
|
*/
|
||||||
public static void main(final String... args) {
|
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("-----------------------------------------------------");
|
System.out.println("-----------------------------------------------------");
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ public final class Example {
|
||||||
* @param args The command line parameters.
|
* @param args The command line parameters.
|
||||||
*/
|
*/
|
||||||
public static void main(final String... args) {
|
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 -------------------------------------");
|
System.out.println("-- From Example -------------------------------------");
|
||||||
|
|
||||||
|
|
|
@ -93,16 +93,16 @@ public class VersionProcessor extends AbstractProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private VersionInfo findValues(final Version version) throws IOException {
|
private VersionInfo findValues(final Version version) throws IOException {
|
||||||
final VersionInfo versionInfo = new VersionInfo(version);
|
final var versionInfo = new VersionInfo(version);
|
||||||
|
|
||||||
if (!version.properties().isEmpty()) {
|
if (!version.properties().isEmpty()) {
|
||||||
final File propsFile = getLocalFile(version.properties());
|
final var propsFile = getLocalFile(version.properties());
|
||||||
if (propsFile.isFile() && propsFile.canRead()) {
|
if (propsFile.isFile() && propsFile.canRead()) {
|
||||||
note("Found properties: " + propsFile.getName() + " (" + propsFile.getAbsoluteFile().getParent() + ')');
|
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)) {
|
Files.newInputStream(propsFile.toPath()), StandardCharsets.UTF_8)) {
|
||||||
p.load(reader);
|
p.load(reader);
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ public class VersionProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private File getLocalFile(final String fileName) {
|
private File getLocalFile(final String fileName) {
|
||||||
if (processingEnv != null) { // null when testing.
|
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) {
|
if (prop != null) {
|
||||||
return new File(prop, fileName);
|
return new File(prop, fileName);
|
||||||
}
|
}
|
||||||
|
@ -185,20 +185,20 @@ public class VersionProcessor extends AbstractProcessor {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
|
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)) {
|
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) {
|
if (element.getKind() == ElementKind.CLASS) {
|
||||||
final Element enclosingElement = element.getEnclosingElement();
|
final var enclosingElement = element.getEnclosingElement();
|
||||||
if (enclosingElement.getKind() == ElementKind.PACKAGE) {
|
if (enclosingElement.getKind() == ElementKind.PACKAGE) {
|
||||||
final PackageElement packageElement = (PackageElement) enclosingElement;
|
final var packageElement = (PackageElement) enclosingElement;
|
||||||
try {
|
try {
|
||||||
final VersionInfo versionInfo = findValues(version);
|
final var versionInfo = findValues(version);
|
||||||
if (Constants.EMPTY.equals(version.packageName())) {
|
if (Constants.EMPTY.equals(version.packageName())) {
|
||||||
versionInfo.setPackageName(packageElement.getQualifiedName().toString());
|
versionInfo.setPackageName(packageElement.getQualifiedName().toString());
|
||||||
}
|
}
|
||||||
note("Found version: " + versionInfo.getVersion());
|
note("Found version: " + versionInfo.getVersion());
|
||||||
final String template = getTemplate(isLocalTemplate, version);
|
final var template = getTemplate(isLocalTemplate, version);
|
||||||
|
|
||||||
writeTemplate(version.type(), versionInfo, template);
|
writeTemplate(version.type(), versionInfo, template);
|
||||||
} catch (IOException | MustacheNotFoundException e) {
|
} catch (IOException | MustacheNotFoundException e) {
|
||||||
|
@ -239,7 +239,7 @@ public class VersionProcessor extends AbstractProcessor {
|
||||||
final var dir = getLocalFile("");
|
final var dir = getLocalFile("");
|
||||||
final var mustache = compileTemplate(dir, template);
|
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_JAVA_TEMPLATE -> "default (Java)";
|
||||||
case Constants.DEFAULT_KOTLIN_TEMPLATE -> "default (Kotlin)";
|
case Constants.DEFAULT_KOTLIN_TEMPLATE -> "default (Kotlin)";
|
||||||
default -> mustache.getName() + " (" + dir.getAbsolutePath() + ')';
|
default -> mustache.getName() + " (" + dir.getAbsolutePath() + ')';
|
||||||
|
@ -248,15 +248,15 @@ public class VersionProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
final var fileName = versionInfo.getClassName() + '.' + type;
|
final var fileName = versionInfo.getClassName() + '.' + type;
|
||||||
if (Constants.KOTLIN_TYPE.equalsIgnoreCase(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) {
|
if (kaptGenDir == null) {
|
||||||
throw new IOException("Could not find the target directory for generated Kotlin files.");
|
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()) {
|
if (!ktFile.getParentFile().exists() && !ktFile.getParentFile().mkdirs()) {
|
||||||
note("Could not create target directory: " + ktFile.getParentFile().getAbsolutePath());
|
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)) {
|
StandardCharsets.UTF_8)) {
|
||||||
mustache.execute(osw, versionInfo).flush();
|
mustache.execute(osw, versionInfo).flush();
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ public class VersionProcessor extends AbstractProcessor {
|
||||||
} else {
|
} else {
|
||||||
final FileObject jfo = filer.createSourceFile(
|
final FileObject jfo = filer.createSourceFile(
|
||||||
versionInfo.getPackageName() + '.' + versionInfo.getClassName());
|
versionInfo.getPackageName() + '.' + versionInfo.getClassName());
|
||||||
try (Writer writer = jfo.openWriter()) {
|
try (var writer = jfo.openWriter()) {
|
||||||
mustache.execute(writer, versionInfo).flush();
|
mustache.execute(writer, versionInfo).flush();
|
||||||
}
|
}
|
||||||
note("Generated source: " + fileName + " (" + new File(jfo.getName()).getAbsoluteFile().getParent() + ')');
|
note("Generated source: " + fileName + " (" + new File(jfo.getName()).getAbsoluteFile().getParent() + ')');
|
||||||
|
|
|
@ -66,7 +66,7 @@ class ConstantsTest {
|
||||||
templates.add(Constants.DEFAULT_KOTLIN_TEMPLATE);
|
templates.add(Constants.DEFAULT_KOTLIN_TEMPLATE);
|
||||||
templates.add(Constants.DEFAULT_TEMPLATE_NAME);
|
templates.add(Constants.DEFAULT_TEMPLATE_NAME);
|
||||||
|
|
||||||
for (final String tp : templates) {
|
for (final var tp : templates) {
|
||||||
assertTrue(tp.endsWith(".mustache"), tp);
|
assertTrue(tp.endsWith(".mustache"), tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,6 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
@ -114,9 +113,9 @@ class VersionProcessorTest {
|
||||||
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
|
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
|
||||||
@Test
|
@Test
|
||||||
void testFindValues() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
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);
|
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("0-0-7:vodka++martini", versionInfo.getVersion(), "getVersion(0-0-7:vodka++martin)");
|
||||||
assertEquals("James Bond", versionInfo.getProject(), "getProject(James Bond)");
|
assertEquals("James Bond", versionInfo.getProject(), "getProject(James Bond)");
|
||||||
|
@ -125,7 +124,7 @@ class VersionProcessorTest {
|
||||||
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
|
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
|
||||||
@Test
|
@Test
|
||||||
void testGetTemplate() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
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);
|
method.setAccessible(true);
|
||||||
|
|
||||||
assertEquals(version.template(), method.invoke(processor, true, version), version.template);
|
assertEquals(version.template(), method.invoke(processor, true, version), version.template);
|
||||||
|
@ -139,13 +138,13 @@ class VersionProcessorTest {
|
||||||
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
|
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
|
||||||
@Test
|
@Test
|
||||||
void testParseIntProperty() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
void testParseIntProperty() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||||
final Properties p = new Properties();
|
final var p = new Properties();
|
||||||
p.setProperty("1", "1");
|
p.setProperty("1", "1");
|
||||||
p.setProperty("2", "2.1");
|
p.setProperty("2", "2.1");
|
||||||
p.setProperty("3", "zero");
|
p.setProperty("3", "zero");
|
||||||
p.setProperty("4", " 4 ");
|
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);
|
int.class);
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue