diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..e45ece5 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..1c24f9a --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..71cdfea --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + Android + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8eaf43d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..8145cf4 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,795 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + modifier + getModifi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1506723083617 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.8 + + + + + + + + class_assembly_generator + + + + + + + + 1.8 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/class_assembly_generator.iml b/class_assembly_generator.iml new file mode 100644 index 0000000..c035f0b --- /dev/null +++ b/class_assembly_generator.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..9dd41da --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + com.github.git-leon + class-assembly-generator + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.7 + 1.7 + + + + + + + \ No newline at end of file diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..20bb8a5 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,27 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ + +### OSX Files ### +.DS_Store \ No newline at end of file diff --git a/src/main/java/com/github/git_leon/class_assembly_generator/DemoApplication.java b/src/main/java/com/github/git_leon/class_assembly_generator/DemoApplication.java new file mode 100644 index 0000000..621afa7 --- /dev/null +++ b/src/main/java/com/github/git_leon/class_assembly_generator/DemoApplication.java @@ -0,0 +1,16 @@ +package com.github.git_leon.class_assembly_generator; + +import com.github.git_leon.class_assembly_generator.utils.Describer; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.sql.Date; + +/** + * Created by leon on 9/29/17. + */ +public class DemoApplication { + public static void main(String[] args) { + System.out.println(Describer.getFullDescription(Date.class)); + } +} diff --git a/src/main/java/com/github/git_leon/class_assembly_generator/utils/ClassDescriber.java b/src/main/java/com/github/git_leon/class_assembly_generator/utils/ClassDescriber.java new file mode 100644 index 0000000..adf9d8f --- /dev/null +++ b/src/main/java/com/github/git_leon/class_assembly_generator/utils/ClassDescriber.java @@ -0,0 +1,25 @@ +package com.github.git_leon.class_assembly_generator.utils; + +/** + * Created by leon on 9/29/17. + */ +public class ClassDescriber { + private final Class cls; + private final Modifiers modifiers; + private String description; + + public ClassDescriber(Class cls) { + this.cls = cls; + this.modifiers = new Modifiers(cls); + } + + public String toString() { + String description = "%s class in the `%s` package named `%s.`"; + return String.format(description, + modifiers.getAbstractness(), + cls.getPackage().getName(), + cls.getCanonicalName()); + } + + +} diff --git a/src/main/java/com/github/git_leon/class_assembly_generator/utils/Describer.java b/src/main/java/com/github/git_leon/class_assembly_generator/utils/Describer.java new file mode 100644 index 0000000..e0aad4d --- /dev/null +++ b/src/main/java/com/github/git_leon/class_assembly_generator/utils/Describer.java @@ -0,0 +1,41 @@ +package com.github.git_leon.class_assembly_generator.utils; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.sql.Date; + +/** + * Created by leon on 9/29/17. + */ +public class Describer { + public static String getFullDescription(Class cls) { + StringBuilder sb = new StringBuilder(); + sb.append("\n" + Describer.getClassDescription(Date.class)); + + for (Method m : Date.class.getDeclaredMethods()) { + sb.append("\n" + Describer.getMethodDescription(m)); + } + + for (Field field : Date.class.getDeclaredFields()) { + sb.append("\n" + Describer.getFieldDescription(field)); + } + return sb.toString(); + } + + public static String getMethodDescription(Method m) { + return new MethodDescriber(m).toString(); + } + + public static String getParameterDescription(Parameter[] parameters) { + return new ParameterDescriber(parameters).toString(); + } + + public static String getClassDescription(Class cls) { + return new ClassDescriber(cls).toString(); + } + + public static String getFieldDescription(Field f) { + return new FieldDescriber(f).toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/github/git_leon/class_assembly_generator/utils/FieldDescriber.java b/src/main/java/com/github/git_leon/class_assembly_generator/utils/FieldDescriber.java new file mode 100644 index 0000000..5b71ecc --- /dev/null +++ b/src/main/java/com/github/git_leon/class_assembly_generator/utils/FieldDescriber.java @@ -0,0 +1,24 @@ +package com.github.git_leon.class_assembly_generator.utils; + +import java.lang.reflect.Field; + +/** + * Created by leon on 9/29/17. + */ +public class FieldDescriber { + private final Field field; + + public FieldDescriber(Field field) { + this.field = field; + } + public String toString() { + Modifiers modifiers = new Modifiers(field); + String description = "declare %s %s field named `%s` of type `%s`. The field has `%s` accessibility."; + return String.format(description, + modifiers.getStaticism(), + modifiers.getAbstractness(), + field.getName(), + field.getType().getCanonicalName(), + modifiers.getAccessibility()); + } +} diff --git a/src/main/java/com/github/git_leon/class_assembly_generator/utils/MethodDescriber.java b/src/main/java/com/github/git_leon/class_assembly_generator/utils/MethodDescriber.java new file mode 100644 index 0000000..ea724d2 --- /dev/null +++ b/src/main/java/com/github/git_leon/class_assembly_generator/utils/MethodDescriber.java @@ -0,0 +1,24 @@ +package com.github.git_leon.class_assembly_generator.utils; + +import java.lang.reflect.Method; + +/** + * Created by leon on 9/29/17. + */ +public class MethodDescriber { + private final Method method; + private String description; + + public MethodDescriber(Method method) { + this.method = method; + this.description = new Modifiers(method).isAbstract() ? "Declare " : "Define "; + } + + public String toString() { + description += "method named `%s`, which has a return type of `%s` and %s"; + return String.format(description, + method.getName(), + method.getGenericReturnType().getTypeName(), + Describer.getParameterDescription(method.getParameters())); + } +} diff --git a/src/main/java/com/github/git_leon/class_assembly_generator/utils/Modifiers.java b/src/main/java/com/github/git_leon/class_assembly_generator/utils/Modifiers.java new file mode 100644 index 0000000..2cf5ed1 --- /dev/null +++ b/src/main/java/com/github/git_leon/class_assembly_generator/utils/Modifiers.java @@ -0,0 +1,67 @@ +package com.github.git_leon.class_assembly_generator.utils; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.lang.reflect.Parameter; + +/** + * Created by leon on 9/29/17. + */ +public class Modifiers { + private final String modifiers; + private String staticism; + private String finalism; + + public Modifiers(int modifiers) { + this.modifiers = Modifier.toString(modifiers); + } + + public Modifiers(Class c) { + this(c.getModifiers()); + } + + public Modifiers(Field f) { + this(f.getModifiers()); + } + + public Modifiers(Method m) { + this(m.getModifiers()); + } + + public Modifiers(Parameter p) { + this(p.getModifiers()); + } + + public boolean isAbstract() { + return getAbstractness().equalsIgnoreCase("abstract"); + } + + + public String getAccessibility() { + String modifier = modifierPresumption("private", "protected", "public"); + return "".equals(modifier) ? "default" : modifier; + } + + public String getStaticism() { + return modifierPresumption("static"); + } + + public String getAbstractness() { + String modifier = modifierPresumption("abstract"); + return "".equals(modifier) ? "concrete" : modifier; + + } + + private String modifierPresumption(String... strings) { + for (String s : strings) { + if (modifiers.contains(s)) + return s; + } + return ""; + } + + public String getFinalism() { + return modifierPresumption("final"); + } +} diff --git a/src/main/java/com/github/git_leon/class_assembly_generator/utils/ParameterDescriber.java b/src/main/java/com/github/git_leon/class_assembly_generator/utils/ParameterDescriber.java new file mode 100644 index 0000000..0cb21bd --- /dev/null +++ b/src/main/java/com/github/git_leon/class_assembly_generator/utils/ParameterDescriber.java @@ -0,0 +1,43 @@ +package com.github.git_leon.class_assembly_generator.utils; + +import java.lang.reflect.Parameter; + +/** + * Created by leon on 9/29/17. + */ +public class ParameterDescriber { + private final Parameter[] parameters; + private String description; + + public ParameterDescriber(Parameter[] parameters) { + this.parameters = parameters; + this.description = null; + switch (parameters.length) { // get description prefix + case 0: + description = "nullary parameters"; + break; + + case 1: + description = "a parameter of type "; + break; + + default: + description = "parameters of type "; + break; + } + } + + @Override + public String toString() { + String description = null; + int parameterCount = parameters.length; + for (int i = 0; i < parameterCount; i++) { + Parameter parameter = parameters[i]; + if (i + 1 < parameterCount) { + description += ", "; + } + description += "`" + parameter.getType().getCanonicalName() + "`"; + } + return description; + } +} diff --git a/target/classes/com/github/git_leon/class_assembly_generator/DemoApplication.class b/target/classes/com/github/git_leon/class_assembly_generator/DemoApplication.class new file mode 100644 index 0000000..a175b59 Binary files /dev/null and b/target/classes/com/github/git_leon/class_assembly_generator/DemoApplication.class differ diff --git a/target/classes/com/github/git_leon/class_assembly_generator/utils/ClassDescriber.class b/target/classes/com/github/git_leon/class_assembly_generator/utils/ClassDescriber.class new file mode 100644 index 0000000..5e1b196 Binary files /dev/null and b/target/classes/com/github/git_leon/class_assembly_generator/utils/ClassDescriber.class differ diff --git a/target/classes/com/github/git_leon/class_assembly_generator/utils/Describer.class b/target/classes/com/github/git_leon/class_assembly_generator/utils/Describer.class new file mode 100644 index 0000000..a50a2bc Binary files /dev/null and b/target/classes/com/github/git_leon/class_assembly_generator/utils/Describer.class differ diff --git a/target/classes/com/github/git_leon/class_assembly_generator/utils/FieldDescriber.class b/target/classes/com/github/git_leon/class_assembly_generator/utils/FieldDescriber.class new file mode 100644 index 0000000..39ec490 Binary files /dev/null and b/target/classes/com/github/git_leon/class_assembly_generator/utils/FieldDescriber.class differ diff --git a/target/classes/com/github/git_leon/class_assembly_generator/utils/MethodDescriber.class b/target/classes/com/github/git_leon/class_assembly_generator/utils/MethodDescriber.class new file mode 100644 index 0000000..fb2d22a Binary files /dev/null and b/target/classes/com/github/git_leon/class_assembly_generator/utils/MethodDescriber.class differ diff --git a/target/classes/com/github/git_leon/class_assembly_generator/utils/Modifiers.class b/target/classes/com/github/git_leon/class_assembly_generator/utils/Modifiers.class new file mode 100644 index 0000000..8409724 Binary files /dev/null and b/target/classes/com/github/git_leon/class_assembly_generator/utils/Modifiers.class differ diff --git a/target/classes/com/github/git_leon/class_assembly_generator/utils/ParameterDescriber.class b/target/classes/com/github/git_leon/class_assembly_generator/utils/ParameterDescriber.class new file mode 100644 index 0000000..6608f0f Binary files /dev/null and b/target/classes/com/github/git_leon/class_assembly_generator/utils/ParameterDescriber.class differ diff --git a/target/classes/com/github/git_leon/class_assembly_generator/utils/Parameters.class b/target/classes/com/github/git_leon/class_assembly_generator/utils/Parameters.class new file mode 100644 index 0000000..2e9a491 Binary files /dev/null and b/target/classes/com/github/git_leon/class_assembly_generator/utils/Parameters.class differ