issue warning instead of error in case of finite bound or non-expansive inheritance violation in java code

This commit is contained in:
Michael Nedzelsky
2015-10-28 15:31:59 +03:00
parent d2c65a5336
commit c123af75fd
6 changed files with 16 additions and 12 deletions
@@ -99,8 +99,10 @@ public interface Errors {
DiagnosticFactory1<KtTypeProjection, ClassifierDescriptor> REDUNDANT_PROJECTION = DiagnosticFactory1.create(WARNING, VARIANCE_IN_PROJECTION);
DiagnosticFactory1<PsiElement, VarianceConflictDiagnosticData> TYPE_VARIANCE_CONFLICT =
DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
DiagnosticFactory1<PsiElement, String> FINITE_BOUNDS_VIOLATION = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, String> EXPANSIVE_INHERITANCE = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<PsiElement> FINITE_BOUNDS_VIOLATION = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<PsiElement, String> FINITE_BOUNDS_VIOLATION_IN_JAVA = DiagnosticFactory1.create(WARNING);
DiagnosticFactory0<PsiElement> EXPANSIVE_INHERITANCE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<PsiElement, String> EXPANSIVE_INHERITANCE_IN_JAVA = DiagnosticFactory1.create(WARNING);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -501,8 +501,10 @@ public class DefaultErrorMessages {
}
});
MAP.put(FINITE_BOUNDS_VIOLATION, "{0}", STRING);
MAP.put(EXPANSIVE_INHERITANCE, "{0}", STRING);
MAP.put(FINITE_BOUNDS_VIOLATION, "Type argument is not within its bounds (violation of Finite Bound Restriction)");
MAP.put(FINITE_BOUNDS_VIOLATION_IN_JAVA, "Violation of Finite Bound Restriction for {0}", STRING);
MAP.put(EXPANSIVE_INHERITANCE, "Type argument is not within its bounds (violation of Non-Expansive Inheritance Restriction)");
MAP.put(EXPANSIVE_INHERITANCE_IN_JAVA, "Violation of Non-Expansive Inheritance Restriction for {0}", STRING);
MAP.put(REDUNDANT_PROJECTION, "Projection is redundant: the corresponding type parameter of {0} has the same variance", NAME);
MAP.put(CONFLICTING_PROJECTION, "Projection is conflicting with variance of the corresponding type parameter of {0}. Remove the projection or replace it with ''*''", NAME);
@@ -51,15 +51,15 @@ public object FiniteBoundRestrictionChecker {
for (typeParameter in typeConstructor.parameters) {
if (typeParameter in problemNodes) {
val element = DescriptorToSourceUtils.descriptorToDeclaration(typeParameter) ?: declaration
diagnosticHolder.report(Errors.FINITE_BOUNDS_VIOLATION.on(element, "Type argument is not within its bounds (violation of Finite Bound Restriction)"))
diagnosticHolder.report(Errors.FINITE_BOUNDS_VIOLATION.on(element))
return
}
}
if (problemNodes.any { it.source != SourceElement.NO_SOURCE }) return
val superTypeFqNames = problemNodes.map { it.containingDeclaration }.map { it.fqNameUnsafe.asString() }.toSortedSet()
diagnosticHolder.report(Errors.FINITE_BOUNDS_VIOLATION.on(declaration, "Violation of Finite Bound Restriction for supertypes: " + superTypeFqNames.joinToString(", ")))
val typeFqNames = problemNodes.map { it.containingDeclaration }.map { it.fqNameUnsafe.asString() }.toSortedSet()
diagnosticHolder.report(Errors.FINITE_BOUNDS_VIOLATION_IN_JAVA.on(declaration, typeFqNames.joinToString(", ")))
}
private class GraphBuilder(val typeConstructor: TypeConstructor) {
@@ -52,15 +52,15 @@ public object NonExpansiveInheritanceRestrictionChecker {
for (typeParameter in typeConstructor.parameters) {
if (typeParameter in problemNodes) {
val element = DescriptorToSourceUtils.descriptorToDeclaration(typeParameter) ?: declaration
diagnosticHolder.report(Errors.EXPANSIVE_INHERITANCE.on(element, "Type argument is not within its bounds (violation of Non-Expansive Inheritance Restriction"))
diagnosticHolder.report(Errors.EXPANSIVE_INHERITANCE.on(element))
return
}
}
if (problemNodes.any { it.source != SourceElement.NO_SOURCE }) return
val superTypeFqNames = problemNodes.map { it.containingDeclaration }.map { it.fqNameUnsafe.asString() }.toSortedSet()
diagnosticHolder.report(Errors.EXPANSIVE_INHERITANCE.on(declaration, "Violation of Non-Expansive Inheritance Restriction for supertypes: " + superTypeFqNames.joinToString(", ")))
val typeFqNames = problemNodes.map { it.containingDeclaration }.map { it.fqNameUnsafe.asString() }.toSortedSet()
diagnosticHolder.report(Errors.EXPANSIVE_INHERITANCE_IN_JAVA.on(declaration, typeFqNames.joinToString(", ")))
}
private class GraphBuilder(val typeConstructor: TypeConstructor) {
@@ -2,4 +2,4 @@
public class A<T extends A> {}
// FILE: 1.kt
<!FINITE_BOUNDS_VIOLATION!>class B<S: A<*>><!>
<!FINITE_BOUNDS_VIOLATION_IN_JAVA!>class B<S: A<*>><!>
@@ -13,4 +13,4 @@ public interface C<X> extends D<P<X,X>> {}
public interface P<Y1, Y2> extends Q<C<Y1>, C<D<Y2>>> {}
// FILE: 1.kt
<!EXPANSIVE_INHERITANCE!>interface P1<YY1, YY2> : P<YY1, YY2><!>
<!EXPANSIVE_INHERITANCE_IN_JAVA!>interface P1<YY1, YY2> : P<YY1, YY2><!>