package notpure.antlr4.macro.model.lexer.token;

/**
 * A token.
 */
public final class Token {

    private final String name;
    private final String value;
    private int lineNo;
    private int colNo;

    public Token(TokenDefinition def) {
        if (def.getValueType() == TokenDefinition.ValueType.REGEX) {
            throw new IllegalArgumentException("TokenDefinition has ValueType.REGEX and hence is invalid.");
        }
        this.name = def.name();
        this.value = def.getValue();
        lineNo = colNo = -1;
    }

    public Token(String name, String value) {
        this(name, value, -1, -1);
    }

    public Token(String name, String value, int lineNo, int colNo) {
        this.name = name;
        this.value = value;
        this.lineNo = lineNo;
        this.colNo = colNo;
    }

    public String getName() {
        return name;
    }

    public String getValue() {
        return value;
    }

    public int getLineNo() {
        return lineNo;
    }

    public int getColNo() {
        return colNo;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Token) {
            Token other = (Token) obj;
            return other.getName().equals(name)
                    && (value == null && other.getValue() == null
                    || value != null && other.getValue() != null && other.getValue().equals(value));
        }
        return false;
    }

    public boolean nameEquals(TokenDefinition def) {
        return def.name().equals(name);
    }

    @Override
    public String toString() {
        return "Token(" + name + "='" + value.trim() + "')";
    }
}

@@ -42,16 +42,127 @@
 token;%0A%0A
+import notpure.antlr4.macro.model.lang.ExpressionValue;%0A%0Aimport java.util.Objects;%0Aimport java.util.Optional;%0A%0A
 /**%0A * A
@@ -1163,73 +1163,203 @@
     
-@Override%0A    public boolean equals(Object obj) %7B%0A        if (obj
+/**%0A     * Checks Token equality based on name and value only.%0A     */%0A    @Override%0A    public boolean equals(Object obj) %7B%0A        return Optional.ofNullable(obj)%0A                .filter($ -%3E $
  ins
@@ -1372,19 +1372,18 @@
 f Token)
- %7B
 %0A
+ 
         
@@ -1390,29 +1390,28 @@
     
-Token other =
+   .map($ -%3E
  (Token)
  obj
@@ -1410,14 +1410,13 @@
 ken)
- obj;%0A
+$)%0A  
     
@@ -1427,20 +1427,24 @@
     
-return other
+  .filter($ -%3E $
 .get
@@ -1462,16 +1462,17 @@
 ls(name)
+)
 %0A       
@@ -1484,131 +1484,37 @@
     
-    && (value == null && other.getValue() == null%0A                    %7C%7C value != null && other.getValue() != null && other
+.filter($ -%3E Objects.equals($
 .get
@@ -1524,24 +1524,17 @@
 ue()
-.equals(
+, 
 value))
-;
 %0A   
@@ -1538,26 +1538,24 @@
         
-%7D%0A
         
 return f
@@ -1550,20 +1550,20 @@
     
-return false
+.isPresent()
 ;%0A  

Refactor and document Token#equals