package com.googlecode.jslint4java;

import org.mozilla.javascript.Scriptable;

/**
 * A single issue with the code that is being checked for problems.
 *
 * @author dom
 */
public class Issue {

    /**
     * Allow creating an issue in a couple of different ways.
     */
    public static class IssueBuilder {

        /** Build from a JavaScript context */
        public static Issue fromJavaScript(String systemId, Scriptable err) {
            // These used to be zero-based, but now _appear_ to be one-based.
            int line = Util.intValue("line", err);
            int col = Util.intValue("character", err);
            return new IssueBuilder(systemId, line, col, Util.stringValue("reason", err))
                    .evidence(Util.stringValue("evidence", err))
                    .raw(Util.stringValue("raw", err))
                    .a(Util.stringValue("a", err))
                    .b(Util.stringValue("b", err))
                    .c(Util.stringValue("c", err))
                    .d(Util.stringValue("d", err))
                    .build();
        }

        private String a;
        private String b;
        private String c;
        private final int character;
        private String d;
        private String evidence;
        private final int line;
        private String raw;
        private final String reason;
        private final String systemId;

        public IssueBuilder(String systemId, int line, int character, String reason) {
            this.character = character;
            this.line = line;
            this.reason = reason;
            this.systemId = systemId;
        }

        public Issue build() {
            return new Issue(this);
        }

        public IssueBuilder a(String a) {
            this.a = a;
            return this;
        }

        public IssueBuilder b(String b) {
            this.b = b;
            return this;
        }

        public IssueBuilder c(String c) {
            this.c = c;
            return this;
        }

        public IssueBuilder d(String d) {
            this.d = d;
            return this;
        }

        public IssueBuilder evidence(String evidence) {
            this.evidence = evidence;
            return this;
        }

        public IssueBuilder raw(String raw) {
            this.raw = raw;
            return this;
        }
    }

    private final String a;
    private final String b;
    private final String c;
    private final int character;
    private final String d;
    private final String evidence;
    private final int line;
    private final String raw;
    private final String reason;
    private final String systemId;

    private Issue(IssueBuilder ib) {
        systemId = ib.systemId;
        reason = ib.reason;
        line = ib.line;
        character = ib.character;
        evidence = ib.evidence;
        raw = ib.raw;
        a = ib.a;
        b = ib.b;
        c = ib.c;
        d = ib.d;
    }

    /**
     * @return A string of auxiliary information.
     */
    public String getA() {
        return a;
    }

    /**
     * @return A string of auxiliary information.
     */
    public String getB() {
        return b;
    }

    /**
     * @return A string of auxiliary information.
     */
    public String getC() {
        return c;
    }

    /**
     * @return the position of the issue within the line. Starts at 0.
     */
    public int getCharacter() {
        return character;
    }

    /**
     * @return a string of auxiliary information.
     */
    public String getD() {
        return d;
    }

    /**
     * @return the contents of the line in which this issue occurs.
     */
    public String getEvidence() {
        return evidence;
    }

    /**
     * @return the number of the line on which this issue occurs.
     */
    public int getLine() {
        return line;
    }

    /**
     * @return a copy of the evidence, but before substitution has occurred.
     */
    public String getRaw() {
        return raw;
    }

    /**
     * @return a textual description of this issue.
     */
    public String getReason() {
        return reason;
    }

    /**
     * @return the name of the file this issue occurred in.
     */
    public String getSystemId() {
        return systemId;
    }

    /**
     * Provide four fields from this issue, separated by colons: systemId, line,
     * character, reason.
     */
    @Override
    public String toString() {
        return getSystemId() + ":" + getLine() + ":" + getCharacter() + ":" + getReason();
    }
}

@@ -851,309 +851,27 @@
    .
-a(Util.stringValue(%22a%22, err))%0A                    .b(Util.stringValue(%22b%22, err))%0A                    .c(Util.stringValue(%22c%22, err))%0A                    .d(Util.stringValue(%22d%22, err))%0A                    .build();%0A        %7D%0A%0A        private String a;%0A        private String b;%0A        private String c;
+build();%0A        %7D%0A
 %0A   
@@ -908,34 +908,8 @@
 er;%0A
-        private String d;%0A
     
@@ -1396,416 +1396,8 @@
  %7D%0A%0A
-        public IssueBuilder a(String a) %7B%0A            this.a = a;%0A            return this;%0A        %7D%0A%0A        public IssueBuilder b(String b) %7B%0A            this.b = b;%0A            return this;%0A        %7D%0A%0A        public IssueBuilder c(String c) %7B%0A            this.c = c;%0A            return this;%0A        %7D%0A%0A        public IssueBuilder d(String d) %7B%0A            this.d = d;%0A            return this;%0A        %7D%0A%0A
     
@@ -1642,92 +1642,8 @@
  %7D%0A%0A
-    private final String a;%0A    private final String b;%0A    private final String c;%0A
     
@@ -1675,36 +1675,8 @@
 er;%0A
-    private final String d;%0A
     
@@ -2046,434 +2046,8 @@
 aw;%0A
-        a = ib.a;%0A        b = ib.b;%0A        c = ib.c;%0A        d = ib.d;%0A    %7D%0A%0A    /**%0A     * @return A string of auxiliary information.%0A     */%0A    public String getA() %7B%0A        return a;%0A    %7D%0A%0A    /**%0A     * @return A string of auxiliary information.%0A     */%0A    public String getB() %7B%0A        return b;%0A    %7D%0A%0A    /**%0A     * @return A string of auxiliary information.%0A     */%0A    public String getC() %7B%0A        return c;%0A
     
@@ -2205,126 +2205,8 @@
  %7D%0A%0A
-    /**%0A     * @return a string of auxiliary information.%0A     */%0A    public String getD() %7B%0A        return d;%0A    %7D%0A%0A
     

Remove unused Issue fields.