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();
}
public static List<String> getClassNamesFromJar(File jarFile) throws IOException {
List<String> result = new ArrayList<>();
try (
- JarInputStream jarInputStream = new JarInputStream(new FileInputStream(jarFile));
+ JarInputStream jarInputStream = new JarInputStream(new FileInputStream(jarFile))
) {
while (true) {
JarEntry jarEntry = jarInputStream.getNextJarEntry();
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() {
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();
graph.generateGraph("JavaInspect");
}
- public static void main(final String[] args) throws FileNotFoundException {
+ public static void main(final String[] args) {
handpickClassesExample();
/*
* 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.
/*
* 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.
public class ClassReference {
+ final List<ClassReference> typeParameters = new ArrayList<>();
public String name;
- List<ClassReference> typeParameters = new ArrayList<ClassReference>();
-
public ClassReference(final Tokenizer tokenizer)
throws InvalidSyntaxException {
name = tokenizer.getNextToken().token;
/*
* 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.
public class Clazz {
+ public final List<ClassReference> implementedInterfaces = new ArrayList<>();
private final String packageName;
private final String className;
private final boolean isInterface;
-
public ClassReference superClass;
- public List<ClassReference> implementedInterfaces = new ArrayList<ClassReference>();
public Clazz(final String packageName, final String className,
final Tokenizer tokenizer, final boolean isInterface)
/*
* 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.
/*
* 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.
/*
* 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.
public class JavaFile {
public static final String UTF_8 = "UTF-8";
- private final List<Import> imports = new ArrayList<Import>();
+ public final List<Clazz> classes = new ArrayList<>();
+ final StringBuffer contents = new StringBuffer();
+ private final List<Import> imports = new ArrayList<>();
private final File file;
- public List<Clazz> classes = new ArrayList<Clazz>();
- StringBuffer contents = new StringBuffer();
private String packageName;
public JavaFile(final File file) throws IOException, InvalidSyntaxException {
final Tokenizer tokenizer = new Tokenizer(contents.toString());
// empty space
- tokenizer.addTerminator(" ", DROP);
+ tokenizer.addTerminator(" ", DROP);
tokenizer.addTerminator("\t", DROP);
tokenizer.addTerminator("\n", DROP);
/*
* 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.
@Override
public String toString() {
- final StringBuffer result = new StringBuffer();
+ final StringBuilder result = new StringBuilder();
result.append(access.name);
/*
* 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.
public class Package {
- Map<String, Clazz> classes = new HashMap<String, Clazz>();
+ Map<String, Clazz> classes = new HashMap<>();
}
/*
* 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.
public class Project {
- Map<String, Package> packages = new HashMap<String, Package>();
+ Map<String, Package> packages = new HashMap<>();
}
/*
* 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.
public class ProjectScanner {
+ public final List<JavaFile> javaFiles = new ArrayList<>();
private final File scanPath;
- public List<JavaFile> javaFiles = new ArrayList<JavaFile>();
- Map<File, Project> projects = new HashMap<File, Project>();
+ Map<File, Project> projects = new HashMap<>();
public ProjectScanner(final File projectPath) {
scanPath = projectPath;
}
public List<Clazz> getAllClasses() {
- final List<Clazz> result = new ArrayList<Clazz>();
+ final List<Clazz> result = new ArrayList<>();
for (final JavaFile file : javaFiles)
- for (final Clazz clazz : file.classes)
- result.add(clazz);
+ result.addAll(file.classes);
return result;
}
/*
* 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.
public class ClassDescriptor implements GraphElement, Comparable<ClassDescriptor> {
private static final int MAX_REFERECNES_COUNT = 10;
+ final List<ClassDescriptor> interfaces = new ArrayList<>();
private final Map<String, FieldDescriptor> nameToFieldMap = new TreeMap<>();
- private final SortedSet<MethodDescriptor> methods = new TreeSet<MethodDescriptor>();
+ private final SortedSet<MethodDescriptor> methods = new TreeSet<>();
private final ClassGraph classGraph;
boolean isEnum;
boolean isInterface;
boolean isArray;
- List<ClassDescriptor> interfaces = new ArrayList<ClassDescriptor>();
ClassDescriptor superClass;
private String fullyQualifiedName;
/**
this.classGraph = classGraph;
}
- protected void analyzeClass(final Class<? extends Object> clazz) {
+ protected void analyzeClass(final Class<?> clazz) {
fullyQualifiedName = clazz.getName();
try {
indexFields(clazz.getDeclaredFields());
indexFields(clazz.getFields());
- } catch (NoClassDefFoundError error){
+ } catch (NoClassDefFoundError error) {
// TODO: better logging of this error
System.out.println(error.toString());
}
@Override
public String getGraphId() {
- final String result = "class_"
+
+ return "class_"
+ fullyQualifiedName
.replace('.', '_')
.replace(";", "")
.replace("[[L", "") // array of arrays
.replace("[[[L", "") // array of arrays of arrays
.replace('$', '_');
-
- return result;
}
private String getInterfaceColor() {
return;
}
- return;
}
private void indexFields(final Field[] fields) {
getOrCreateFieldDescriptor(field);
}
- private void indexMethods(final Class<? extends Object> clazz) {
+ private void indexMethods(final Class<?> clazz) {
for (final Method method : clazz.getMethods()) {
final MethodDescriptor methodDescriptor = new MethodDescriptor(
this, method.getName());
/**
* Maps class fully qualified names to class descriptors.
*/
- private final Map<String, ClassDescriptor> fullyQualifiedNameToClassMap = new HashMap<String, ClassDescriptor>();
+ private final Map<String, ClassDescriptor> fullyQualifiedNameToClassMap = new HashMap<>();
- private final List<String> blacklistClassGlobs = new ArrayList<String>();
+ private final List<String> blacklistClassGlobs = new ArrayList<>();
private final List<String> whitelistClassGlobs = new ArrayList<>();
-
+ TargetImageType targetImageType = TargetImageType.SVG;
private String targetDirectoryPath = CommonPathResolver.getDesktopDirectory()
.getAbsolutePath() + separator;
-
private boolean keepDotFile;
- TargetImageType targetImageType = TargetImageType.SVG;
-
public 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: "
}
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");
result.append("}\n");
- final String resultStr = result.toString();
- return resultStr;
+ return result.toString();
}
/**
public class FieldDescriptor implements GraphElement {
private final ClassDescriptor parentClassDescriptor;
- private final List<ClassDescriptor> typeArguments = new ArrayList<ClassDescriptor>();
+ private final List<ClassDescriptor> typeArguments = new ArrayList<>();
private String name;
private ClassDescriptor type;
private boolean isInherited;
if (!isVisible())
return "";
- final StringBuffer result = new StringBuffer();
+ final StringBuilder result = new StringBuilder();
// describe associated types
for (final ClassDescriptor classDescriptor : typeArguments)
if (!isVisible())
return "";
- final StringBuffer result = new StringBuffer();
+ final StringBuilder result = new StringBuilder();
result.append(" // " + name + "\n");
if (parentClassDescriptor.isEnum && (type == parentClassDescriptor)) {
private final String methodName;
private final ClassDescriptor parentClass;
- private final List<ClassDescriptor> argumentTypes = new ArrayList<ClassDescriptor>();
+ private final List<ClassDescriptor> argumentTypes = new ArrayList<>();
private ClassDescriptor returnType;
private boolean isInherited;
if (!isVisible())
return "";
- final StringBuffer result = new StringBuffer();
+ final StringBuilder result = new StringBuilder();
// describe associated types
for (final ClassDescriptor classDescriptor : argumentTypes)
if (!isVisible())
return "";
- final StringBuffer result = new StringBuffer();
+ final StringBuilder result = new StringBuilder();
result.append(" // " + methodName + "\n");
public final String fileExtension;
- TargetImageType(String fileExtension){
+ TargetImageType(String fileExtension) {
this.fileExtension = fileExtension;
}
}
public class Utils {
- private static final List<String> systemDataTypes = new ArrayList<String>();
- private static final List<String> commonObjectMethods = new ArrayList<String>();
- private static final List<String> systemPackages = new ArrayList<String>();
- private static final List<String> darkColors = new ArrayList<String>();
- private static final List<String> lightColors = new ArrayList<String>();
- private static final List<String> enumMethods = new ArrayList<String>();
+ private static final List<String> systemDataTypes = new ArrayList<>();
+ private static final List<String> commonObjectMethods = new ArrayList<>();
+ private static final List<String> systemPackages = new ArrayList<>();
+ private static final List<String> darkColors = new ArrayList<>();
+ private static final List<String> lightColors = new ArrayList<>();
+ private static final List<String> enumMethods = new ArrayList<>();
private static int lastChosenDarkColor = -1;
private static int lastChosenLightColor = -1;
/*
* 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.