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