From f0253606ed92cc13aa4e49e28a44ee41cf3d3251 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Tue, 26 Dec 2017 04:13:45 +0200 Subject: [PATCH] Code cleanup. --- .../inspector/java/CommandlineConfiguration.java | 5 ++--- .../java/eu/svjatoslav/inspector/java/Main.java | 2 +- .../inspector/java/RenderJavaInspect.java | 8 +++----- .../inspector/java/methods/Annotation.java | 2 +- .../inspector/java/methods/ClassReference.java | 5 ++--- .../svjatoslav/inspector/java/methods/Clazz.java | 5 ++--- .../java/methods/EnumerationBuffer.java | 2 +- .../inspector/java/methods/Import.java | 2 +- .../inspector/java/methods/JavaFile.java | 10 +++++----- .../inspector/java/methods/Modifiers.java | 4 ++-- .../inspector/java/methods/Package.java | 4 ++-- .../inspector/java/methods/Project.java | 4 ++-- .../inspector/java/methods/ProjectScanner.java | 11 +++++------ .../inspector/java/methods/package-info.java | 2 +- .../java/structure/ClassDescriptor.java | 16 +++++++--------- .../inspector/java/structure/ClassGraph.java | 16 ++++++---------- .../java/structure/FieldDescriptor.java | 6 +++--- .../java/structure/MethodDescriptor.java | 6 +++--- .../java/structure/TargetImageType.java | 2 +- .../inspector/java/structure/Utils.java | 12 ++++++------ .../inspector/java/structure/package-info.java | 2 +- 21 files changed, 57 insertions(+), 69 deletions(-) diff --git a/src/main/java/eu/svjatoslav/inspector/java/CommandlineConfiguration.java b/src/main/java/eu/svjatoslav/inspector/java/CommandlineConfiguration.java index bbb57b2..cb9e4fc 100644 --- a/src/main/java/eu/svjatoslav/inspector/java/CommandlineConfiguration.java +++ b/src/main/java/eu/svjatoslav/inspector/java/CommandlineConfiguration.java @@ -12,16 +12,15 @@ public class CommandlineConfiguration { public StringParameter graphName; private NullParameter showDebug; - public CommandlineConfiguration (String args[]){ + public CommandlineConfiguration(String args[]) { Parser parser = buildCommandlineParameterParser(); if (!parser.parse(args)) { parser.showHelp(); - return; } } - public boolean isDebug(){ + public boolean isDebug() { return showDebug.isSpecified(); } diff --git a/src/main/java/eu/svjatoslav/inspector/java/Main.java b/src/main/java/eu/svjatoslav/inspector/java/Main.java index 58963ff..4f6bfbf 100644 --- a/src/main/java/eu/svjatoslav/inspector/java/Main.java +++ b/src/main/java/eu/svjatoslav/inspector/java/Main.java @@ -74,7 +74,7 @@ public class Main { public static List getClassNamesFromJar(File jarFile) throws IOException { List result = new ArrayList<>(); try ( - JarInputStream jarInputStream = new JarInputStream(new FileInputStream(jarFile)); + JarInputStream jarInputStream = new JarInputStream(new FileInputStream(jarFile)) ) { while (true) { JarEntry jarEntry = jarInputStream.getNextJarEntry(); diff --git a/src/main/java/eu/svjatoslav/inspector/java/RenderJavaInspect.java b/src/main/java/eu/svjatoslav/inspector/java/RenderJavaInspect.java index a616a63..6776e0a 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/RenderJavaInspect.java +++ b/src/main/java/eu/svjatoslav/inspector/java/RenderJavaInspect.java @@ -12,8 +12,6 @@ package eu.svjatoslav.inspector.java; import eu.svjatoslav.inspector.java.structure.ClassGraph; import eu.svjatoslav.inspector.java.structure.Utils; -import java.io.FileNotFoundException; - public class RenderJavaInspect { private static void fullProjectExample() { @@ -35,8 +33,8 @@ public class RenderJavaInspect { private static void handpickClassesExample() { /* * This example demonstrates generating of class graph from hand picked - * classes and visualizing GraphViz itself. - */ + * classes and visualizing GraphViz itself. + */ // Create graph final ClassGraph graph = new ClassGraph(); @@ -56,7 +54,7 @@ public class RenderJavaInspect { graph.generateGraph("JavaInspect"); } - public static void main(final String[] args) throws FileNotFoundException { + public static void main(final String[] args) { handpickClassesExample(); diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/Annotation.java b/src/main/java/eu/svjatoslav/inspector/java/methods/Annotation.java index 94b320c..da1653e 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/Annotation.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/Annotation.java @@ -1,7 +1,7 @@ /* * JavaInspect - Utility to visualize java software * Copyright (C) 2013-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/ClassReference.java b/src/main/java/eu/svjatoslav/inspector/java/methods/ClassReference.java index bac017d..e006296 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/ClassReference.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/ClassReference.java @@ -1,7 +1,7 @@ /* * JavaInspect - Utility to visualize java software * Copyright (C) 2013-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. @@ -17,10 +17,9 @@ import java.util.List; public class ClassReference { + final List typeParameters = new ArrayList<>(); public String name; - List typeParameters = new ArrayList(); - public ClassReference(final Tokenizer tokenizer) throws InvalidSyntaxException { name = tokenizer.getNextToken().token; diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/Clazz.java b/src/main/java/eu/svjatoslav/inspector/java/methods/Clazz.java index 49f3d5e..93aee08 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/Clazz.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/Clazz.java @@ -1,7 +1,7 @@ /* * JavaInspect - Utility to visualize java software * Copyright (C) 2013-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. @@ -18,12 +18,11 @@ import java.util.List; public class Clazz { + public final List implementedInterfaces = new ArrayList<>(); private final String packageName; private final String className; private final boolean isInterface; - public ClassReference superClass; - public List implementedInterfaces = new ArrayList(); public Clazz(final String packageName, final String className, final Tokenizer tokenizer, final boolean isInterface) diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/EnumerationBuffer.java b/src/main/java/eu/svjatoslav/inspector/java/methods/EnumerationBuffer.java index cc2691e..864a339 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/EnumerationBuffer.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/EnumerationBuffer.java @@ -1,7 +1,7 @@ /* * JavaInspect - Utility to visualize java software * Copyright (C) 2013-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/Import.java b/src/main/java/eu/svjatoslav/inspector/java/methods/Import.java index 9c8b8c3..87b5abc 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/Import.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/Import.java @@ -1,7 +1,7 @@ /* * JavaInspect - Utility to visualize java software * Copyright (C) 2013-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/JavaFile.java b/src/main/java/eu/svjatoslav/inspector/java/methods/JavaFile.java index 9ec86c3..c1404c8 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/JavaFile.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/JavaFile.java @@ -1,7 +1,7 @@ /* * JavaInspect - Utility to visualize java software * Copyright (C) 2013-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. @@ -23,10 +23,10 @@ import static eu.svjatoslav.commons.string.tokenizer.Terminator.TerminationStrat public class JavaFile { public static final String UTF_8 = "UTF-8"; - private final List imports = new ArrayList(); + public final List classes = new ArrayList<>(); + final StringBuffer contents = new StringBuffer(); + private final List imports = new ArrayList<>(); private final File file; - public List classes = new ArrayList(); - StringBuffer contents = new StringBuffer(); private String packageName; public JavaFile(final File file) throws IOException, InvalidSyntaxException { @@ -42,7 +42,7 @@ public class JavaFile { final Tokenizer tokenizer = new Tokenizer(contents.toString()); // empty space - tokenizer.addTerminator(" ", DROP); + tokenizer.addTerminator(" ", DROP); tokenizer.addTerminator("\t", DROP); tokenizer.addTerminator("\n", DROP); diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/Modifiers.java b/src/main/java/eu/svjatoslav/inspector/java/methods/Modifiers.java index 65626ef..f68a810 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/Modifiers.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/Modifiers.java @@ -1,7 +1,7 @@ /* * JavaInspect - Utility to visualize java software * Copyright (C) 2013-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. @@ -49,7 +49,7 @@ public class Modifiers { @Override public String toString() { - final StringBuffer result = new StringBuffer(); + final StringBuilder result = new StringBuilder(); result.append(access.name); diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/Package.java b/src/main/java/eu/svjatoslav/inspector/java/methods/Package.java index 5412a8d..2844a56 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/Package.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/Package.java @@ -1,7 +1,7 @@ /* * JavaInspect - Utility to visualize java software * Copyright (C) 2013-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. @@ -14,6 +14,6 @@ import java.util.Map; public class Package { - Map classes = new HashMap(); + Map classes = new HashMap<>(); } diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/Project.java b/src/main/java/eu/svjatoslav/inspector/java/methods/Project.java index 66c4e72..157388e 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/Project.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/Project.java @@ -1,7 +1,7 @@ /* * JavaInspect - Utility to visualize java software * Copyright (C) 2013-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. @@ -14,6 +14,6 @@ import java.util.Map; public class Project { - Map packages = new HashMap(); + Map packages = new HashMap<>(); } diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/ProjectScanner.java b/src/main/java/eu/svjatoslav/inspector/java/methods/ProjectScanner.java index cf776c4..b90c0e0 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/ProjectScanner.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/ProjectScanner.java @@ -1,7 +1,7 @@ /* * JavaInspect - Utility to visualize java software * Copyright (C) 2013-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. @@ -21,9 +21,9 @@ import java.util.Map; public class ProjectScanner { + public final List javaFiles = new ArrayList<>(); private final File scanPath; - public List javaFiles = new ArrayList(); - Map projects = new HashMap(); + Map projects = new HashMap<>(); public ProjectScanner(final File projectPath) { scanPath = projectPath; @@ -31,11 +31,10 @@ public class ProjectScanner { } public List getAllClasses() { - final List result = new ArrayList(); + final List result = new ArrayList<>(); for (final JavaFile file : javaFiles) - for (final Clazz clazz : file.classes) - result.add(clazz); + result.addAll(file.classes); return result; } diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/package-info.java b/src/main/java/eu/svjatoslav/inspector/java/methods/package-info.java index 35ee51d..d94ef50 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/package-info.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/package-info.java @@ -1,7 +1,7 @@ /* * JavaInspect - Utility to visualize java software * Copyright (C) 2013-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassDescriptor.java b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassDescriptor.java index 5bfeb25..b38794d 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassDescriptor.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassDescriptor.java @@ -19,13 +19,13 @@ import java.util.*; public class ClassDescriptor implements GraphElement, Comparable { private static final int MAX_REFERECNES_COUNT = 10; + final List interfaces = new ArrayList<>(); private final Map nameToFieldMap = new TreeMap<>(); - private final SortedSet methods = new TreeSet(); + private final SortedSet methods = new TreeSet<>(); private final ClassGraph classGraph; boolean isEnum; boolean isInterface; boolean isArray; - List interfaces = new ArrayList(); ClassDescriptor superClass; private String fullyQualifiedName; /** @@ -52,7 +52,7 @@ public class ClassDescriptor implements GraphElement, Comparable clazz) { + protected void analyzeClass(final Class clazz) { fullyQualifiedName = clazz.getName(); @@ -76,7 +76,7 @@ public class ClassDescriptor implements GraphElement, Comparable clazz) { + private void indexMethods(final Class clazz) { for (final Method method : clazz.getMethods()) { final MethodDescriptor methodDescriptor = new MethodDescriptor( this, method.getName()); diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java index 51fa04a..1747614 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java @@ -30,19 +30,16 @@ public class ClassGraph { /** * Maps class fully qualified names to class descriptors. */ - private final Map fullyQualifiedNameToClassMap = new HashMap(); + private final Map fullyQualifiedNameToClassMap = new HashMap<>(); - private final List blacklistClassGlobs = new ArrayList(); + private final List blacklistClassGlobs = new ArrayList<>(); private final List whitelistClassGlobs = new ArrayList<>(); - + TargetImageType targetImageType = TargetImageType.SVG; private String targetDirectoryPath = CommonPathResolver.getDesktopDirectory() .getAbsolutePath() + separator; - private boolean keepDotFile; - TargetImageType targetImageType = TargetImageType.SVG; - public ClassGraph() { } @@ -75,7 +72,7 @@ public class ClassGraph { for (final Clazz clazz : projectScanner.getAllClasses()) try { System.out.println("Class full name: " + clazz.getFullName()); - final Class c = this.getClass().forName(clazz.getFullName()); + final Class c = Class.forName(clazz.getFullName()); addObject(c); } catch (final Exception exception) { System.out.println("cannot add class: " @@ -128,7 +125,7 @@ public class ClassGraph { } private String getDot() { - final StringBuffer result = new StringBuffer(); + final StringBuilder result = new StringBuilder(); result.append("digraph Java {\n"); result.append("graph [rankdir=LR, overlap = false, concentrate=true];\n"); @@ -139,8 +136,7 @@ public class ClassGraph { result.append("}\n"); - final String resultStr = result.toString(); - return resultStr; + return result.toString(); } /** diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/FieldDescriptor.java b/src/main/java/eu/svjatoslav/inspector/java/structure/FieldDescriptor.java index 11959da..36532e2 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/FieldDescriptor.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/FieldDescriptor.java @@ -22,7 +22,7 @@ import java.util.List; public class FieldDescriptor implements GraphElement { private final ClassDescriptor parentClassDescriptor; - private final List typeArguments = new ArrayList(); + private final List typeArguments = new ArrayList<>(); private String name; private ClassDescriptor type; private boolean isInherited; @@ -63,7 +63,7 @@ public class FieldDescriptor implements GraphElement { if (!isVisible()) return ""; - final StringBuffer result = new StringBuffer(); + final StringBuilder result = new StringBuilder(); // describe associated types for (final ClassDescriptor classDescriptor : typeArguments) @@ -101,7 +101,7 @@ public class FieldDescriptor implements GraphElement { if (!isVisible()) return ""; - final StringBuffer result = new StringBuffer(); + final StringBuilder result = new StringBuilder(); result.append(" // " + name + "\n"); if (parentClassDescriptor.isEnum && (type == parentClassDescriptor)) { diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/MethodDescriptor.java b/src/main/java/eu/svjatoslav/inspector/java/structure/MethodDescriptor.java index 3f7acef..72ce997 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/MethodDescriptor.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/MethodDescriptor.java @@ -23,7 +23,7 @@ public class MethodDescriptor implements GraphElement, private final String methodName; private final ClassDescriptor parentClass; - private final List argumentTypes = new ArrayList(); + private final List argumentTypes = new ArrayList<>(); private ClassDescriptor returnType; private boolean isInherited; @@ -86,7 +86,7 @@ public class MethodDescriptor implements GraphElement, if (!isVisible()) return ""; - final StringBuffer result = new StringBuffer(); + final StringBuilder result = new StringBuilder(); // describe associated types for (final ClassDescriptor classDescriptor : argumentTypes) @@ -116,7 +116,7 @@ public class MethodDescriptor implements GraphElement, if (!isVisible()) return ""; - final StringBuffer result = new StringBuffer(); + final StringBuilder result = new StringBuilder(); result.append(" // " + methodName + "\n"); diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/TargetImageType.java b/src/main/java/eu/svjatoslav/inspector/java/structure/TargetImageType.java index 637724a..c1baf93 100644 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/TargetImageType.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/TargetImageType.java @@ -6,7 +6,7 @@ public enum TargetImageType { public final String fileExtension; - TargetImageType(String fileExtension){ + TargetImageType(String fileExtension) { this.fileExtension = fileExtension; } } diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/Utils.java b/src/main/java/eu/svjatoslav/inspector/java/structure/Utils.java index 435a3eb..c4caca8 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/Utils.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/Utils.java @@ -14,12 +14,12 @@ import java.util.List; public class Utils { - private static final List systemDataTypes = new ArrayList(); - private static final List commonObjectMethods = new ArrayList(); - private static final List systemPackages = new ArrayList(); - private static final List darkColors = new ArrayList(); - private static final List lightColors = new ArrayList(); - private static final List enumMethods = new ArrayList(); + private static final List systemDataTypes = new ArrayList<>(); + private static final List commonObjectMethods = new ArrayList<>(); + private static final List systemPackages = new ArrayList<>(); + private static final List darkColors = new ArrayList<>(); + private static final List lightColors = new ArrayList<>(); + private static final List enumMethods = new ArrayList<>(); private static int lastChosenDarkColor = -1; private static int lastChosenLightColor = -1; diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/package-info.java b/src/main/java/eu/svjatoslav/inspector/java/structure/package-info.java index 9c71850..582c795 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/package-info.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/package-info.java @@ -1,7 +1,7 @@ /* * JavaInspect - Utility to visualize java software * Copyright (C) 2013-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. -- 2.20.1