Bläddra i källkod

Tidy/lombok

Change-Id: Ie312f385f4e72c599c9d5357f46e38f80cd45f98
Reviewed-on: http://gerrit.dmdirc.com/2430
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.7rc1
Chris Smith 12 år sedan
förälder
incheckning
f1f1c557f6

+ 3
- 11
src/com/dmdirc/addons/calc/Evaluator.java Visa fil

@@ -22,26 +22,18 @@
22 22
 
23 23
 package com.dmdirc.addons.calc;
24 24
 
25
+import lombok.RequiredArgsConstructor;
26
+
25 27
 /**
26 28
  * A simple evaluator which just requests that the {@link TreeToken} evaluates
27 29
  * itself.
28
- *
29
- * @author chris
30 30
  */
31
+@RequiredArgsConstructor
31 32
 public class Evaluator {
32 33
 
33 34
     /** The token to be evaluated. */
34 35
     private final TreeToken node;
35 36
 
36
-    /**
37
-     * Creates a new evaluator for the specified token.
38
-     *
39
-     * @param node The token to be evaluated
40
-     */
41
-    public Evaluator(final TreeToken node) {
42
-        this.node = node;
43
-    }
44
-
45 37
     /**
46 38
      * Evaluates the token and returns the numeric result.
47 39
      *

+ 1
- 3
src/com/dmdirc/addons/calc/Lexer.java Visa fil

@@ -30,13 +30,11 @@ import java.util.List;
30 30
 /**
31 31
  * The lexer takes a String input and produces an ordered list of {@link Token}s
32 32
  * corresponding to the input.
33
- *
34
- * @author chris
35 33
  */
36 34
 public class Lexer {
37 35
 
38 36
     /** The input string. */
39
-    final String input;
37
+    private final String input;
40 38
 
41 39
     /**
42 40
      * Creates a new lexer for the specified input string.

+ 6
- 13
src/com/dmdirc/addons/calc/Parser.java Visa fil

@@ -29,19 +29,21 @@ import java.util.Collections;
29 29
 import java.util.Comparator;
30 30
 import java.util.List;
31 31
 
32
+import lombok.RequiredArgsConstructor;
33
+
32 34
 /**
33 35
  * The parser takes the output from a {@link Lexer} and applies precdence rules
34 36
  * to build the tokens into a tree.
35
- *
36
- * @author chris
37 37
  */
38
+@RequiredArgsConstructor
38 39
 public class Parser {
39 40
 
40
-    /** The lexer whose output will be parsed. */
41
-    protected final Lexer lexer;
42 41
     /** A list of token types sorted by their precendece. */
43 42
     protected static final List<TokenType> TOKENS_BY_PRECEDENCE;
44 43
 
44
+    /** The lexer whose output will be parsed. */
45
+    protected final Lexer lexer;
46
+
45 47
     static {
46 48
         TOKENS_BY_PRECEDENCE = new ArrayList<TokenType>(Arrays.asList(
47 49
                 TokenType.values()));
@@ -49,15 +51,6 @@ public class Parser {
49 51
                 new TokenTypePrecedenceComparator());
50 52
     }
51 53
 
52
-    /**
53
-     * Creates a new parser for the specified lexer.
54
-     *
55
-     * @param lexer The lexer whose output should be parsed
56
-     */
57
-    public Parser(final Lexer lexer) {
58
-        this.lexer = lexer;
59
-    }
60
-
61 54
     /**
62 55
      * Parses the output of this parser's lexer, and returns a {@link TreeToken}
63 56
      * representing the parsed formula.

+ 8
- 37
src/com/dmdirc/addons/calc/Token.java Visa fil

@@ -22,12 +22,18 @@
22 22
 
23 23
 package com.dmdirc.addons.calc;
24 24
 
25
+import lombok.Getter;
26
+import lombok.RequiredArgsConstructor;
27
+import lombok.ToString;
28
+
25 29
 /**
26 30
  * Describes a distinct piece of a mathematical formula, as tokenised by a
27 31
  * {@link Lexer}.
28
- *
29
- * @author chris
30 32
  */
33
+@Getter
34
+@ToString
35
+@RequiredArgsConstructor
36
+@SuppressWarnings("PMD.UnusedPrivateField")
31 37
 public class Token {
32 38
 
33 39
     /** The type of this token. */
@@ -36,39 +42,4 @@ public class Token {
36 42
     /** The content of this token, if any. */
37 43
     private final String content;
38 44
 
39
-    /**
40
-     * Creates a new token.
41
-     *
42
-     * @param type The type of the token
43
-     * @param content The content of the token
44
-     */
45
-    public Token(final TokenType type, final String content) {
46
-        this.type = type;
47
-        this.content = content;
48
-    }
49
-
50
-    /**
51
-     * Retrieves the content of this token.
52
-     *
53
-     * @return This token's content
54
-     */
55
-    public String getContent() {
56
-        return content;
57
-    }
58
-
59
-    /**
60
-     * Retrieves the type of this token.
61
-     *
62
-     * @return This token's type
63
-     */
64
-    public TokenType getType() {
65
-        return type;
66
-    }
67
-
68
-    /** {@inheritDoc} */
69
-    @Override
70
-    public String toString() {
71
-        return "[type: " + type + "; content: " + content + "]";
72
-    }
73
-
74 45
 }

+ 5
- 20
src/com/dmdirc/addons/calc/TokenType.java Visa fil

@@ -27,12 +27,13 @@ import java.util.List;
27 27
 import java.util.regex.Matcher;
28 28
 import java.util.regex.Pattern;
29 29
 
30
+import lombok.Getter;
31
+
30 32
 /**
31 33
  * Describes the different types of possible token, their arities, precedence,
32 34
  * and the types of token that may follow them.
33
- *
34
- * @author chris
35 35
  */
36
+@SuppressWarnings("PMD.UnusedPrivateField")
36 37
 public enum TokenType {
37 38
 
38 39
     /** The start of an input string. */
@@ -150,12 +151,14 @@ public enum TokenType {
150 151
     /** The string representation of tokens that may follow this one. */
151 152
     private final String[] strfollows;
152 153
     /** The precedence of this token. */
154
+    @Getter
153 155
     private final int precedence;
154 156
     /** The list of tokens that may follow this one. */
155 157
     private List<TokenType> follows;
156 158
     /** The regular expression used to match this token. */
157 159
     private final Pattern regex;
158 160
     /** The arity of this token. */
161
+    @Getter
159 162
     private final TokenTypeArity arity;
160 163
 
161 164
     /**
@@ -191,24 +194,6 @@ public enum TokenType {
191 194
         return follows;
192 195
     }
193 196
 
194
-    /**
195
-     * Retrieves the arity of this token type.
196
-     *
197
-     * @return This token type's arity
198
-     */
199
-    public TokenTypeArity getArity() {
200
-        return arity;
201
-    }
202
-
203
-    /**
204
-     * Retrieves the precedence of this token type.
205
-     *
206
-     * @return This token type's precedence
207
-     */
208
-    public int getPrecedence() {
209
-        return precedence;
210
-    }
211
-
212 197
     /**
213 198
      * Attempts to match this token type against the specified input string
214 199
      * (starting at the specified offset).

+ 0
- 2
src/com/dmdirc/addons/calc/TokenTypeArity.java Visa fil

@@ -24,8 +24,6 @@ package com.dmdirc.addons.calc;
24 24
 
25 25
 /**
26 26
  * Describes the arity (number of operands) of a token type.
27
- *
28
- * @author chris
29 27
  */
30 28
 public enum TokenTypeArity {
31 29
 

+ 10
- 45
src/com/dmdirc/addons/calc/TreeToken.java Visa fil

@@ -25,49 +25,30 @@ package com.dmdirc.addons.calc;
25 25
 import java.util.ArrayList;
26 26
 import java.util.List;
27 27
 
28
+import lombok.Getter;
29
+import lombok.RequiredArgsConstructor;
30
+import lombok.ToString;
31
+
28 32
 /**
29 33
  * Describes a tree of {@link Token}s.
30
- *
31
- * @author chris
32 34
  */
35
+@ToString
36
+@RequiredArgsConstructor
37
+@SuppressWarnings("PMD.UnusedPrivateField")
33 38
 public class TreeToken {
34 39
 
35 40
     /** The children of this node. */
41
+    @Getter
36 42
     private final List<TreeToken> children = new ArrayList<TreeToken>();
37 43
 
38 44
     /** The token at the root of the tree. */
45
+    @Getter
39 46
     private final Token token;
40 47
 
41 48
     /** Whether or not this tree has been processed. */
49
+    @Getter
42 50
     private boolean processed = false;
43 51
 
44
-    /**
45
-     * Creates a new tree with the specified token at the root.
46
-     *
47
-     * @param token The root token
48
-     */
49
-    public TreeToken(final Token token) {
50
-        this.token = token;
51
-    }
52
-
53
-    /**
54
-     * Retrieves the (direct) children of this tree.
55
-     *
56
-     * @return This tree's children
57
-     */
58
-    public List<TreeToken> getChildren() {
59
-        return children;
60
-    }
61
-
62
-    /**
63
-     * Retrieves the root token of this tree.
64
-     *
65
-     * @return This tree's token
66
-     */
67
-    public Token getToken() {
68
-        return token;
69
-    }
70
-
71 52
     /**
72 53
      * Adds the specified child to this tree.
73 54
      *
@@ -77,15 +58,6 @@ public class TreeToken {
77 58
         children.add(token);
78 59
     }
79 60
 
80
-    /**
81
-     * Determines if this tree has been processed.
82
-     *
83
-     * @return True if the tree has been processed, false otherwise
84
-     */
85
-    public boolean isProcessed() {
86
-        return processed;
87
-    }
88
-
89 61
     /**
90 62
      * Sets the processed flag of this tree to true.
91 63
      */
@@ -102,11 +74,4 @@ public class TreeToken {
102 74
         return token.getType().evaluate(this);
103 75
     }
104 76
 
105
-    /** {@inheritDoc} */
106
-    @Override
107
-    public String toString() {
108
-        return "[token: " + token + "; children: " + children + "; processed: "
109
-                + processed + "]";
110
-    }
111
-
112 77
 }

Laddar…
Avbryt
Spara