001 package org.extendj.ast; 002 003 import java.util.HashSet; 004 import java.io.File; 005 import java.util.Set; 006 import java.util.Collections; 007 import java.util.Collection; 008 import java.util.ArrayList; 009 import beaver.*; 010 import java.util.*; 011 import java.io.ByteArrayOutputStream; 012 import java.io.PrintStream; 013 import java.lang.reflect.InvocationTargetException; 014 import java.lang.reflect.Method; 015 import org.jastadd.util.*; 016 import java.util.zip.*; 017 import java.io.*; 018 import org.jastadd.util.PrettyPrintable; 019 import org.jastadd.util.PrettyPrinter; 020 import java.io.FileNotFoundException; 021 import java.io.BufferedInputStream; 022 import java.io.DataInputStream; 023 /** 024 * @ast class 025 * @aspect ErrorCheck 026 * @declaredat /home/jesper/git/extendj/java4/frontend/ErrorCheck.jrag:95 027 */ 028 public class Problem extends java.lang.Object implements Comparable { 029 030 public int compareTo(Object o) { 031 if (o instanceof Problem) { 032 Problem other = (Problem) o; 033 if (!fileName.equals(other.fileName)) { 034 return fileName.compareTo(other.fileName); 035 } 036 if (line != other.line) { 037 return line - other.line; 038 } 039 return message.compareTo(other.message); 040 } 041 return 0; 042 } 043 044 045 public static class Severity { 046 public static final Severity ERROR = new Severity(); 047 public static final Severity WARNING = new Severity(); 048 private Severity() { } 049 } 050 051 052 public static class Kind { 053 public static final Kind OTHER = new Kind(); 054 public static final Kind LEXICAL = new Kind(); 055 public static final Kind SYNTACTIC = new Kind(); 056 public static final Kind SEMANTIC = new Kind(); 057 private Kind() { } 058 } 059 060 061 protected int line = -1; 062 063 064 public int line() { return line; } 065 066 067 protected int column = -1; 068 069 070 public int column() { return column; } 071 072 073 protected int endLine = -1; 074 075 076 public int endLine() { return endLine; } 077 078 079 protected int endColumn = -1; 080 081 082 public int endColumn() { return endColumn; } 083 084 085 protected String fileName; 086 087 088 public String fileName() { return fileName; } 089 090 091 public void setFileName(String fileName) { this.fileName = fileName; } 092 093 094 protected String message; 095 096 097 public String message() { return message; } 098 099 100 protected Severity severity = Severity.ERROR; 101 102 103 public Severity severity() { return severity; } 104 105 106 protected Kind kind = Kind.OTHER; 107 108 109 public Kind kind() { return kind; } 110 111 112 public Problem(String fileName, String message) { 113 this.fileName = fileName; 114 this.message = message; 115 } 116 117 118 public Problem(String fileName, String message, int line) { 119 this(fileName, message); 120 this.line = line; 121 } 122 123 124 public Problem(String fileName, String message, int line, Severity severity) { 125 this(fileName, message); 126 this.line = line; 127 this.severity = severity; 128 } 129 130 131 public Problem(String fileName, String message, int line, int column, Severity severity) { 132 this(fileName, message); 133 this.line = line; 134 this.column = column; 135 this.severity = severity; 136 } 137 138 139 public Problem(String fileName, String message, int line, Severity severity, Kind kind) { 140 this(fileName, message); 141 this.line = line; 142 this.kind = kind; 143 this.severity = severity; 144 } 145 146 147 public Problem(String fileName, String message, int line, int column, Severity severity, Kind kind) { 148 this(fileName, message); 149 this.line = line; 150 this.column = column; 151 this.kind = kind; 152 this.severity = severity; 153 } 154 155 156 public Problem(String fileName, String message, int line, int column, int endLine, int endColumn, Severity severity, Kind kind) { 157 this(fileName, message); 158 this.line = line; 159 this.column = column; 160 this.endLine = endLine; 161 this.endColumn = endColumn; 162 this.kind = kind; 163 this.severity = severity; 164 } 165 166 167 public String toString() { 168 String location = ""; 169 if (line != -1 && column != -1) { 170 location = line + "," + column + ":"; 171 } else if (line != -1) { 172 location = line + ":"; 173 } 174 String s = ""; 175 if (this.kind == Kind.LEXICAL) { 176 s = "Lexical Error: "; 177 } else if (this.kind == Kind.SYNTACTIC) { 178 s = "Syntactic Error: "; 179 } else if (this.kind == Kind.SEMANTIC) { 180 s = "Semantic Error: "; 181 } 182 return fileName + ":" + location + "\n" + " " + s + message; 183 } 184 185 186 }