2 * JavaInspect - Utility to visualize java software
3 * Copyright (C) 2013-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 3 of the GNU Lesser General Public License
7 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.inspector.java.methods;
12 import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException;
13 import eu.svjatoslav.commons.string.tokenizer.Tokenizer;
14 import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch;
16 import java.util.ArrayList;
17 import java.util.List;
21 public final List<ClassReference> implementedInterfaces = new ArrayList<>();
22 private final String packageName;
23 private final String className;
24 private final boolean isInterface;
25 public ClassReference superClass;
27 public Clazz(final String packageName, final String className,
28 final Tokenizer tokenizer, final boolean isInterface)
29 throws InvalidSyntaxException {
31 this.packageName = packageName;
32 this.className = className;
33 this.isInterface = isInterface;
36 final TokenizerMatch match = tokenizer.getNextToken();
38 if ("extends".equals(match.token)) {
39 superClass = new ClassReference(tokenizer);
43 if ("implements".equals(match.token)) {
45 implementedInterfaces.add(new ClassReference(tokenizer));
47 if (tokenizer.consumeIfNextToken(","))
55 if ("{".equals(match.token)) {
56 parseClassBody(tokenizer);
63 public String getFullName() {
64 return packageName + "." + className;
67 public void parseClassBody(final Tokenizer tokenizer) {
68 tokenizer.skipUntilDataEnd();
72 public String toString() {
73 final EnumerationBuffer result = new EnumerationBuffer();
75 result.append(packageName + " -> " + className + " ");
78 result.append("(interface)");
80 result.append("(class)");
83 if (superClass != null)
84 result.append(" super: " + superClass.toString() + "\n");
86 if (implementedInterfaces.size() > 0) {
87 result.append(" implements: ");
88 for (final ClassReference classReference : implementedInterfaces)
89 result.appendEnumeration(classReference.toString());
93 return result.toString();