summaryrefslogtreecommitdiff
path: root/src/main/java/org/javacs/Warning.java
blob: a173d40d32d743d80726b7e34a0dccf30b6a7abf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package org.javacs;

import com.sun.source.tree.LineMap;
import com.sun.source.util.*;
import java.util.Locale;
import javax.tools.*;
import javax.tools.JavaFileObject;

class Warning implements Diagnostic<JavaFileObject> {

    private final JavaFileObject source;
    private final LineMap lines;
    private final long start, end;
    private final String code, message;

    Warning(JavacTask task, TreePath path, String code, String message) {
        this.source = path.getCompilationUnit().getSourceFile();
        this.lines = path.getCompilationUnit().getLineMap();
        var pos = Trees.instance(task).getSourcePositions();
        this.start = pos.getStartPosition(path.getCompilationUnit(), path.getLeaf());
        this.end = pos.getEndPosition(path.getCompilationUnit(), path.getLeaf());
        this.code = code;
        this.message = message;
    }

    @Override
    public Kind getKind() {
        return Kind.WARNING;
    }

    @Override
    public JavaFileObject getSource() {
        return source;
    }

    @Override
    public long getPosition() {
        return start;
    }

    @Override
    public long getStartPosition() {
        return start;
    }

    @Override
    public long getEndPosition() {
        return end;
    }

    @Override
    public long getLineNumber() {
        return lines.getLineNumber(start);
    }

    @Override
    public long getColumnNumber() {
        return lines.getColumnNumber(start);
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMessage(Locale locale) {
        return message;
    }
}