Added quick fixes binding to error codes
This commit is contained in:
+7
-1
@@ -1,6 +1,8 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -10,7 +12,11 @@ public class DiagnosticWithPsiElement<T extends PsiElement> extends GenericDiagn
|
||||
private final T psiElement;
|
||||
|
||||
public DiagnosticWithPsiElement(DiagnosticFactory factory, Severity severity, String message, T psiElement) {
|
||||
super(factory, severity, message, psiElement.getContainingFile(), psiElement.getTextRange());
|
||||
this(factory, severity, message, psiElement, psiElement.getTextRange());
|
||||
}
|
||||
|
||||
public DiagnosticWithPsiElement(DiagnosticFactory factory, Severity severity, String message, T psiElement, @NotNull TextRange textRange) {
|
||||
super(factory, severity, message, psiElement.getContainingFile(), textRange);
|
||||
this.psiElement = psiElement;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public interface Errors {
|
||||
SimpleDiagnosticFactory PROPERTY_INITIALIZER_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR, "Property initializers are not allowed in traits");
|
||||
SimpleDiagnosticFactory PROPERTY_INITIALIZER_NO_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR, "Initializer is not allowed here because this property has no backing field");
|
||||
SimpleDiagnosticFactory PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR, "Property initializers are not allowed when no primary constructor is present");
|
||||
SimpleDiagnosticFactory REDUNDANT_ABSTRACT = SimpleDiagnosticFactory.create(WARNING, "Abstract modifier is redundant in traits");
|
||||
SimplePsiElementOnlyDiagnosticFactory<JetDeclaration> REDUNDANT_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "Abstract modifier is redundant in traits");
|
||||
ParameterizedDiagnosticFactory2<String, ClassDescriptor> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = ParameterizedDiagnosticFactory2.create(ERROR, "Abstract property {0} in non-abstract class {1}");
|
||||
ParameterizedDiagnosticFactory2<String, ClassDescriptor> ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = ParameterizedDiagnosticFactory2.create(ERROR, "Abstract function {0} in non-abstract class {1}");
|
||||
ParameterizedDiagnosticFactory1<FunctionDescriptor> ABSTRACT_FUNCTION_WITH_BODY = ParameterizedDiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract");
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public interface PsiElementOnlyDiagnosticFactory<T extends PsiElement> extends DiagnosticFactory {
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class SimplePsiElementOnlyDiagnosticFactory<T extends PsiElement> extends DiagnosticFactoryWithSeverity implements PsiElementOnlyDiagnosticFactory<T> {
|
||||
|
||||
public static <T extends PsiElement> SimplePsiElementOnlyDiagnosticFactory<T> create(Severity severity, String message) {
|
||||
return new SimplePsiElementOnlyDiagnosticFactory<T>(severity, message);
|
||||
}
|
||||
|
||||
protected final String message;
|
||||
|
||||
public SimplePsiElementOnlyDiagnosticFactory(Severity severity, String message) {
|
||||
super(severity);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull ASTNode node) {
|
||||
return new DiagnosticWithPsiElement<T>(this, severity, message, element, node.getTextRange());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element) {
|
||||
return on(element, element.getNode());
|
||||
}
|
||||
}
|
||||
@@ -621,7 +621,7 @@ public class BodyResolver {
|
||||
}
|
||||
if (classDescriptor.getKind() == ClassKind.TRAIT) {
|
||||
// context.getTrace().getErrorHandler().genericWarning(abstractNode, "Abstract modifier is redundant in traits");
|
||||
context.getTrace().report(REDUNDANT_ABSTRACT.on(abstractNode));
|
||||
context.getTrace().report(REDUNDANT_ABSTRACT.on(property, abstractNode));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -799,7 +799,7 @@ public class BodyResolver {
|
||||
}
|
||||
if (hasAbstractModifier && inTrait && !isPropertyAccessor) {
|
||||
// context.getTrace().getErrorHandler().genericWarning(abstractNode, "Abstract modifier is redundant in trait");
|
||||
context.getTrace().report(REDUNDANT_ABSTRACT.on(abstractNode));
|
||||
context.getTrace().report(REDUNDANT_ABSTRACT.on((JetDeclaration)function, abstractNode)); //TODO
|
||||
}
|
||||
if (function.getBodyExpression() != null && hasAbstractModifier) {
|
||||
// context.getTrace().getErrorHandler().genericError(abstractNode, "Method " + methodName + "with body cannot be abstract");
|
||||
|
||||
Reference in New Issue
Block a user