f6051c9ca10081a378ce3a04eb2bceb70b67922f
[javainspect.git] / src / main / java / eu / svjatoslav / inspector / java / methods / Clazz.java
1 /*
2  * JavaInspect - Utility to visualize java software
3  * Copyright (C) 2013-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
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.
8  */
9
10 package eu.svjatoslav.inspector.java.methods;
11
12 import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException;
13 import eu.svjatoslav.commons.string.tokenizer.Tokenizer;
14 import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 public class Clazz {
20
21     private final String packageName;
22     private final String className;
23     private final boolean isInterface;
24
25     public ClassReference superClass;
26     public List<ClassReference> implementedInterfaces = new ArrayList<ClassReference>();
27
28     public Clazz(final String packageName, final String className,
29                  final Tokenizer tokenizer, final boolean isInterface)
30             throws InvalidSyntaxException {
31
32         this.packageName = packageName;
33         this.className = className;
34         this.isInterface = isInterface;
35
36         while (true) {
37             final TokenizerMatch match = tokenizer.getNextToken();
38
39             if ("extends".equals(match.token)) {
40                 superClass = new ClassReference(tokenizer);
41                 continue;
42             }
43
44             if ("implements".equals(match.token)) {
45                 while (true) {
46                     implementedInterfaces.add(new ClassReference(tokenizer));
47
48                     if (tokenizer.probeNextToken(","))
49                         continue;
50
51                     break;
52                 }
53                 continue;
54             }
55
56             if ("{".equals(match.token)) {
57                 parseClassBody(tokenizer);
58                 break;
59             }
60
61         }
62     }
63
64     public String getFullName() {
65         return packageName + "." + className;
66     }
67
68     public void parseClassBody(final Tokenizer tokenizer) {
69         tokenizer.skipUntilDataEnd();
70     }
71
72     @Override
73     public String toString() {
74         final EnumerationBuffer result = new EnumerationBuffer();
75
76         result.append(packageName + " -> " + className + " ");
77
78         if (isInterface)
79             result.append("(interface)");
80         else
81             result.append("(class)");
82         result.append("\n");
83
84         if (superClass != null)
85             result.append("    super: " + superClass.toString() + "\n");
86
87         if (implementedInterfaces.size() > 0) {
88             result.append("    implements: ");
89             for (final ClassReference classReference : implementedInterfaces)
90                 result.appendEnumeration(classReference.toString());
91             result.append("\n");
92         }
93
94         return result.toString();
95     }
96
97 }