updated copyright notice
[javainspect.git] / src / main / java / eu / svjatoslav / inspector / java / methods / Modifiers.java
1 /*
2  * JavaInspect - Utility to visualize java software
3  * Copyright (C) 2013-2015, 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 public class Modifiers {
13
14         public enum Access {
15                 PUBLIC("public"), PROTECTED("protected"), DEFAULT(""), PRIVATE(
16                                 "private");
17
18                 public final String name;
19
20                 Access(final String name) {
21                         this.name = name;
22                 };
23         }
24
25         Access access = Access.DEFAULT;
26
27         boolean isStatic = false;;
28
29         boolean isFinal = false;
30
31         boolean isAbstract = false;
32
33         public boolean parseModifier(final String string) {
34                 for (final Access access : Access.values())
35                         if (access.name.equals(string)) {
36                                 this.access = access;
37                                 return true;
38                         }
39
40                 if ("static".equals(string)) {
41                         isStatic = true;
42                         return true;
43                 }
44
45                 if ("final".equals(string)) {
46                         isFinal = true;
47                         return true;
48                 }
49
50                 if ("abstract".equals(string)) {
51                         isAbstract = true;
52                         return true;
53                 }
54
55                 return false;
56         }
57
58         public void reset() {
59                 isStatic = false;
60                 isFinal = false;
61                 access = Access.DEFAULT;
62         }
63
64         @Override
65         public String toString() {
66                 final StringBuffer result = new StringBuffer();
67
68                 result.append(access.name);
69
70                 if (isStatic) {
71                         if (result.length() > 0)
72                                 result.append(" ");
73                         result.append("static");
74                 }
75
76                 if (isFinal) {
77                         if (result.length() > 0)
78                                 result.append(" ");
79                         result.append("final");
80                 }
81
82                 return result.toString();
83         }
84 }