Field names pushed into Diagnostic factories

This commit is contained in:
Andrey Breslav
2011-09-15 15:45:47 +04:00
parent 911d6e7fa1
commit fec625b434
5 changed files with 55 additions and 55 deletions
@@ -8,6 +8,18 @@ import org.jetbrains.annotations.NotNull;
* @author abreslav
*/
public class AbstractDiagnosticFactory implements DiagnosticFactory {
private String name = null;
/*package*/ void setName(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
@NotNull
@Override
public TextRange getTextRange(@NotNull Diagnostic diagnostic) {
@@ -18,6 +30,10 @@ public class AbstractDiagnosticFactory implements DiagnosticFactory {
@Override
public PsiFile getPsiFile(@NotNull Diagnostic diagnostic) {
return ((DiagnosticWithTextRange) diagnostic).getPsiFile();
}
@Override
public String toString() {
return getName();
}
}
@@ -13,4 +13,7 @@ public interface DiagnosticFactory {
@NotNull
PsiFile getPsiFile(@NotNull Diagnostic diagnostic);
@NotNull
String getName();
}
@@ -6,6 +6,8 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.resolve.DescriptorRenderer;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Iterator;
@@ -282,5 +284,27 @@ public interface Errors {
};
// This field is needed to make the Initializer class load (interfaces cannot have static initializers)
@SuppressWarnings("UnusedDeclaration")
Initializer __initializer = Initializer.INSTANCE;
class Initializer {
static {
for (Field field : Errors.class.getFields()) {
if ((field.getModifiers() & Modifier.STATIC) != 0) {
try {
Object value = field.get(null);
if (value instanceof AbstractDiagnosticFactory) {
AbstractDiagnosticFactory factory = (AbstractDiagnosticFactory) value;
factory.setName(field.getName());
}
}
catch (IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
}
}
private static final Initializer INSTANCE = new Initializer();
private Initializer() {};
}
}
@@ -29,4 +29,15 @@ public class RedeclarationDiagnosticFactory implements DiagnosticFactory {
public PsiFile getPsiFile(@NotNull Diagnostic diagnostic) {
throw new UnsupportedOperationException(); // TODO
}
@NotNull
@Override
public String getName() {
return "REDECLARATION";
}
@Override
public String toString() {
return getName();
}
}