KT-2641 Warn on using j.l.Iterable in Kotlin code
#KT-2641 fixed
This commit is contained in:
@@ -80,8 +80,9 @@ public interface Errors {
|
|||||||
|
|
||||||
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> CANNOT_IMPORT_FROM_ELEMENT = DiagnosticFactory1.create(ERROR);
|
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> CANNOT_IMPORT_FROM_ELEMENT = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> CANNOT_BE_IMPORTED = DiagnosticFactory1.create(ERROR);
|
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> CANNOT_BE_IMPORTED = DiagnosticFactory1.create(ERROR);
|
||||||
SimpleDiagnosticFactory<JetExpression>USELESS_HIDDEN_IMPORT = SimpleDiagnosticFactory.create(WARNING);
|
SimpleDiagnosticFactory<JetExpression> USELESS_HIDDEN_IMPORT = SimpleDiagnosticFactory.create(WARNING);
|
||||||
SimpleDiagnosticFactory<JetExpression> USELESS_SIMPLE_IMPORT = SimpleDiagnosticFactory.create(WARNING);
|
SimpleDiagnosticFactory<JetExpression> USELESS_SIMPLE_IMPORT = SimpleDiagnosticFactory.create(WARNING);
|
||||||
|
DiagnosticFactory1<JetElement, Collection<ClassDescriptor>> CLASS_HAS_KOTLIN_ANALOG = DiagnosticFactory1.create(WARNING);
|
||||||
|
|
||||||
SimpleDiagnosticFactory<JetParameter> CANNOT_INFER_PARAMETER_TYPE = SimpleDiagnosticFactory.create(ERROR);
|
SimpleDiagnosticFactory<JetParameter> CANNOT_INFER_PARAMETER_TYPE = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|
||||||
|
|||||||
+1
@@ -94,6 +94,7 @@ public class DefaultErrorMessages {
|
|||||||
MAP.put(CANNOT_BE_IMPORTED, "Cannot import ''{0}'', functions and properties can be imported only from packages", NAME);
|
MAP.put(CANNOT_BE_IMPORTED, "Cannot import ''{0}'', functions and properties can be imported only from packages", NAME);
|
||||||
MAP.put(USELESS_HIDDEN_IMPORT, "Useless import, it is hidden further");
|
MAP.put(USELESS_HIDDEN_IMPORT, "Useless import, it is hidden further");
|
||||||
MAP.put(USELESS_SIMPLE_IMPORT, "Useless import, does nothing");
|
MAP.put(USELESS_SIMPLE_IMPORT, "Useless import, does nothing");
|
||||||
|
MAP.put(CLASS_HAS_KOTLIN_ANALOG, "This class has Kotlin analog(s) {0} that should be used instead.", CLASS_DESCRIPTOR_LIST);
|
||||||
|
|
||||||
MAP.put(CANNOT_INFER_PARAMETER_TYPE,
|
MAP.put(CANNOT_INFER_PARAMETER_TYPE,
|
||||||
"Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) => ...} notation");
|
"Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) => ...} notation");
|
||||||
|
|||||||
@@ -22,12 +22,10 @@ import com.google.common.collect.Sets;
|
|||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.Named;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetClass;
|
import org.jetbrains.jet.lang.psi.JetClass;
|
||||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||||
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
|
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintsUtil;
|
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintsUtil;
|
||||||
@@ -290,6 +288,24 @@ public class Renderers {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final Renderer<Collection<ClassDescriptor>> CLASS_DESCRIPTOR_LIST = new Renderer<Collection<ClassDescriptor>>() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String render(@NotNull Collection<ClassDescriptor> descriptors) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("(");
|
||||||
|
for (Iterator<ClassDescriptor> iterator = descriptors.iterator(); iterator.hasNext(); ) {
|
||||||
|
ClassDescriptor descriptor = iterator.next();
|
||||||
|
sb.append(DescriptorUtils.getFQName(descriptor).getFqName());
|
||||||
|
if (iterator.hasNext()) {
|
||||||
|
sb.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.append(")");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private Renderers() {
|
private Renderers() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
@@ -31,6 +32,7 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.lang.diagnostics.Errors.CLASS_HAS_KOTLIN_ANALOG;
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.USELESS_HIDDEN_IMPORT;
|
import static org.jetbrains.jet.lang.diagnostics.Errors.USELESS_HIDDEN_IMPORT;
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.USELESS_SIMPLE_IMPORT;
|
import static org.jetbrains.jet.lang.diagnostics.Errors.USELESS_SIMPLE_IMPORT;
|
||||||
|
|
||||||
@@ -119,6 +121,16 @@ public class ImportsResolver {
|
|||||||
if (descriptors.size() == 1) {
|
if (descriptors.size() == 1) {
|
||||||
resolvedDirectives.put(importDirective, descriptors.iterator().next());
|
resolvedDirectives.put(importDirective, descriptors.iterator().next());
|
||||||
}
|
}
|
||||||
|
for (DeclarationDescriptor descriptor : descriptors) {
|
||||||
|
if (descriptor instanceof ClassDescriptor && !onlyClasses) {
|
||||||
|
FqNameUnsafe fqName = DescriptorUtils.getFQName(descriptor);
|
||||||
|
Collection<ClassDescriptor> kotlinAnalogs = configuration.getKotlinAnalogs(fqName);
|
||||||
|
JetExpression importedReference = importDirective.getImportedReference();
|
||||||
|
if (importedReference != null && !kotlinAnalogs.isEmpty()) {
|
||||||
|
trace.report(CLASS_HAS_KOTLIN_ANALOG.on(importedReference, kotlinAnalogs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
delayedImporter.processImports();
|
delayedImporter.processImports();
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.lang.diagnostics.Errors.CLASS_HAS_KOTLIN_ANALOG;
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.UNSUPPORTED;
|
import static org.jetbrains.jet.lang.diagnostics.Errors.UNSUPPORTED;
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.WRONG_NUMBER_OF_TYPE_ARGUMENTS;
|
import static org.jetbrains.jet.lang.diagnostics.Errors.WRONG_NUMBER_OF_TYPE_ARGUMENTS;
|
||||||
|
|
||||||
@@ -288,6 +289,10 @@ public class TypeResolver {
|
|||||||
Collection<? extends DeclarationDescriptor> descriptors = qualifiedExpressionResolver.lookupDescriptorsForUserType(userType, scope, trace);
|
Collection<? extends DeclarationDescriptor> descriptors = qualifiedExpressionResolver.lookupDescriptorsForUserType(userType, scope, trace);
|
||||||
for (DeclarationDescriptor descriptor : descriptors) {
|
for (DeclarationDescriptor descriptor : descriptors) {
|
||||||
if (descriptor instanceof ClassifierDescriptor) {
|
if (descriptor instanceof ClassifierDescriptor) {
|
||||||
|
Collection<ClassDescriptor> kotlinAnalogs = moduleConfiguration.getKotlinAnalogs(DescriptorUtils.getFQName(descriptor));
|
||||||
|
if (!kotlinAnalogs.isEmpty()) {
|
||||||
|
trace.report(CLASS_HAS_KOTLIN_ANALOG.on(userType, kotlinAnalogs));
|
||||||
|
}
|
||||||
return (ClassifierDescriptor) descriptor;
|
return (ClassifierDescriptor) descriptor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
//KT-2641 Warn on using j.l.Iterable in Kotlin code
|
||||||
|
package n
|
||||||
|
|
||||||
|
import <!CLASS_HAS_KOTLIN_ANALOG!>java.util.Iterator<!>
|
||||||
|
import <!CLASS_HAS_KOTLIN_ANALOG!>java.lang.Comparable<!> as Comp
|
||||||
|
|
||||||
|
fun bar() : <!CLASS_HAS_KOTLIN_ANALOG!>java.lang.Iterable<Int><!>? {
|
||||||
|
val <!UNUSED_VARIABLE!>a<!> : <!CLASS_HAS_KOTLIN_ANALOG!>java.lang.Comparable<String><!>? = null
|
||||||
|
val <!UNUSED_VARIABLE!>b<!> : Iterable<<!CLASS_HAS_KOTLIN_ANALOG!>Integer<!>>
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -15,13 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.jetbrains.jet.checkers;
|
package org.jetbrains.jet.checkers;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.test.InnerTestClasses;
|
import org.jetbrains.jet.test.InnerTestClasses;
|
||||||
import org.jetbrains.jet.test.TestMetadata;
|
import org.jetbrains.jet.test.TestMetadata;
|
||||||
|
|
||||||
import java.io.File;
|
import org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve;
|
||||||
|
|
||||||
/** This class is generated by {@link org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve}. DO NOT MODIFY MANUALLY */
|
/** This class is generated by {@link org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve}. DO NOT MODIFY MANUALLY */
|
||||||
@InnerTestClasses({JetDiagnosticsTestGenerated.Tests.class, JetDiagnosticsTestGenerated.Script.class})
|
@InnerTestClasses({JetDiagnosticsTestGenerated.Tests.class, JetDiagnosticsTestGenerated.Script.class})
|
||||||
@@ -1739,6 +1742,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/j+k/kt2394.kt");
|
doTest("compiler/testData/diagnostics/tests/j+k/kt2394.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt2641.kt")
|
||||||
|
public void testKt2641() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/j+k/kt2641.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("mutableIterator.kt")
|
@TestMetadata("mutableIterator.kt")
|
||||||
public void testMutableIterator() throws Exception {
|
public void testMutableIterator() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/j+k/mutableIterator.kt");
|
doTest("compiler/testData/diagnostics/tests/j+k/mutableIterator.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user