From 07be33658cd768818cf2c6ddbd1f05bad14eaf97 Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Wed, 31 Jan 2018 16:37:35 +0300 Subject: [PATCH] Added enum javadocing --- .gitignore | 3 +- build.gradle | 18 +++++++++++- src/main/java/ru/noties/enhance/Enhance.java | 2 ++ .../ru/noties/enhance/EnhanceWriterImpl.java | 28 ++++++++++++++++++- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index e6924e8..39ea55c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /.gradle /.idea **/build -**/out \ No newline at end of file +**/out +**/gen \ No newline at end of file diff --git a/build.gradle b/build.gradle index e27dfbf..43c4c26 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { } group 'ru.noties' -version '1.0.0' +version '1.0.1' apply plugin: 'java' apply plugin: 'application' @@ -40,3 +40,19 @@ task wrapper(type: Wrapper) { gradleVersion '4.5' distributionType 'all' } + +afterEvaluate { + final def folder = new File(rootDir, '/gen/ru/noties/enhance') + if (!folder.exists()) { + folder.mkdirs() + } + final def file = new File(folder, 'EnhanceVersion.java') + file.write(""" +package ru.noties.enhance; +class EnhanceVersion { static final String NAME = \"${version}\"; } + """) +} + +sourceSets { + main.java.srcDirs += new File(rootDir, 'gen') +} diff --git a/src/main/java/ru/noties/enhance/Enhance.java b/src/main/java/ru/noties/enhance/Enhance.java index c28b786..76423ea 100644 --- a/src/main/java/ru/noties/enhance/Enhance.java +++ b/src/main/java/ru/noties/enhance/Enhance.java @@ -15,6 +15,8 @@ public class Enhance { public static void main(String[] args) { + log("[Enhance] version: %s", EnhanceVersion.NAME); + final long start = System.currentTimeMillis(); final EnhanceOptions options = EnhanceOptions.create(args); diff --git a/src/main/java/ru/noties/enhance/EnhanceWriterImpl.java b/src/main/java/ru/noties/enhance/EnhanceWriterImpl.java index e01117d..7f677f2 100644 --- a/src/main/java/ru/noties/enhance/EnhanceWriterImpl.java +++ b/src/main/java/ru/noties/enhance/EnhanceWriterImpl.java @@ -2,6 +2,7 @@ import com.github.javaparser.JavaParser; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.PackageDeclaration; import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.nodeTypes.NodeWithJavadoc; @@ -128,12 +129,38 @@ public void visit(PackageDeclaration n, ApiInfoStore arg) { super.visit(n, arg); } + @Override + public void visit(EnumDeclaration n, ApiInfoStore arg) { + super.visit(n, arg); + + final String type = typeName(n); + + final NodeList constants = n.getEntries(); + if (constants != null) { + for (EnumConstantDeclaration declaration : constants) { + setApiInfo(declaration, arg.field(type, declaration.getNameAsString())); + } + } + + visit(type, n, arg, n.getConstructors()); + } + @Override public void visit(ClassOrInterfaceDeclaration n, ApiInfoStore api) { super.visit(n, api); final String type = typeName(n); + visit(type, n, api, n.getConstructors()); + } + + private void visit( + @Nonnull String type, + @Nonnull TypeDeclaration n, + @Nonnull ApiInfoStore api, + @Nullable List constructors + ) { + final List fields = n.getFields(); if (fields != null) { @@ -154,7 +181,6 @@ public void visit(ClassOrInterfaceDeclaration n, ApiInfoStore api) { callableDeclarations.addAll(methods); } - final List constructors = n.getConstructors(); if (constructors != null) { callableDeclarations.addAll(constructors); }