Code from ImportsResolver moved, the class renamed to PlatformTypesMappedToKotlinChecker
This commit is contained in:
+1
-35
@@ -17,25 +17,19 @@
|
|||||||
package org.jetbrains.kotlin.resolve;
|
package org.jetbrains.kotlin.resolve;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor;
|
|
||||||
import org.jetbrains.kotlin.name.Name;
|
|
||||||
import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap;
|
import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap;
|
||||||
import org.jetbrains.kotlin.psi.JetElement;
|
import org.jetbrains.kotlin.psi.JetElement;
|
||||||
import org.jetbrains.kotlin.psi.JetExpression;
|
import org.jetbrains.kotlin.psi.JetExpression;
|
||||||
import org.jetbrains.kotlin.psi.JetImportDirective;
|
import org.jetbrains.kotlin.psi.JetImportDirective;
|
||||||
import org.jetbrains.kotlin.psi.JetPsiUtil;
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.diagnostics.Errors.CONFLICTING_IMPORT;
|
|
||||||
import static org.jetbrains.kotlin.diagnostics.Errors.PLATFORM_CLASS_MAPPED_TO_KOTLIN;
|
import static org.jetbrains.kotlin.diagnostics.Errors.PLATFORM_CLASS_MAPPED_TO_KOTLIN;
|
||||||
|
|
||||||
public class ImportsResolver {
|
public class PlatformTypesMappedToKotlinChecker {
|
||||||
|
|
||||||
public static void checkPlatformTypesMappedToKotlin(
|
public static void checkPlatformTypesMappedToKotlin(
|
||||||
@NotNull ModuleDescriptor module,
|
@NotNull ModuleDescriptor module,
|
||||||
@@ -65,32 +59,4 @@ public class ImportsResolver {
|
|||||||
trace.report(PLATFORM_CLASS_MAPPED_TO_KOTLIN.on(element, kotlinAnalogsForClass));
|
trace.report(PLATFORM_CLASS_MAPPED_TO_KOTLIN.on(element, kotlinAnalogsForClass));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reportConflictingImport(
|
|
||||||
@NotNull JetImportDirective importDirective,
|
|
||||||
@NotNull JetScope fileScope,
|
|
||||||
@Nullable Collection<? extends DeclarationDescriptor> resolvedTo,
|
|
||||||
@NotNull BindingTrace trace
|
|
||||||
) {
|
|
||||||
|
|
||||||
JetExpression importedReference = importDirective.getImportedReference();
|
|
||||||
if (importedReference == null || resolvedTo == null) return;
|
|
||||||
|
|
||||||
Name aliasName = JetPsiUtil.getAliasName(importDirective);
|
|
||||||
if (aliasName == null) return;
|
|
||||||
|
|
||||||
if (resolvedTo.size() != 1) return;
|
|
||||||
|
|
||||||
DeclarationDescriptor target = resolvedTo.iterator().next();
|
|
||||||
if (target instanceof ClassDescriptor) {
|
|
||||||
if (fileScope.getClassifier(aliasName) == null) {
|
|
||||||
trace.report(CONFLICTING_IMPORT.on(importedReference, aliasName.asString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (target instanceof PackageViewDescriptor) {
|
|
||||||
if (fileScope.getPackage(aliasName) == null) {
|
|
||||||
trace.report(CONFLICTING_IMPORT.on(importedReference, aliasName.asString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -292,7 +292,7 @@ public class TypeResolver(
|
|||||||
val classifierDescriptor = qualifiedExpressionResolver.lookupDescriptorsForUserType(userType, scope, trace, true)
|
val classifierDescriptor = qualifiedExpressionResolver.lookupDescriptorsForUserType(userType, scope, trace, true)
|
||||||
.firstIsInstanceOrNull<ClassifierDescriptor>()
|
.firstIsInstanceOrNull<ClassifierDescriptor>()
|
||||||
if (classifierDescriptor != null) {
|
if (classifierDescriptor != null) {
|
||||||
ImportsResolver.reportPlatformClassMappedToKotlin(moduleDescriptor, trace, userType, classifierDescriptor)
|
PlatformTypesMappedToKotlinChecker.reportPlatformClassMappedToKotlin(moduleDescriptor, trace, userType, classifierDescriptor)
|
||||||
}
|
}
|
||||||
return classifierDescriptor
|
return classifierDescriptor
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.psi.JetImportDirective
|
|||||||
import org.jetbrains.kotlin.psi.debugText.*
|
import org.jetbrains.kotlin.psi.debugText.*
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
import org.jetbrains.kotlin.resolve.Importer
|
import org.jetbrains.kotlin.resolve.Importer
|
||||||
import org.jetbrains.kotlin.resolve.ImportsResolver
|
|
||||||
import org.jetbrains.kotlin.resolve.JetModuleUtil
|
import org.jetbrains.kotlin.resolve.JetModuleUtil
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.scopes.*
|
import org.jetbrains.kotlin.resolve.scopes.*
|
||||||
@@ -35,6 +34,8 @@ import kotlin.properties.Delegates
|
|||||||
import com.google.common.collect.ImmutableListMultimap
|
import com.google.common.collect.ImmutableListMultimap
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScopeSelectorUtil.ScopeByNameSelector
|
import org.jetbrains.kotlin.resolve.scopes.JetScopeSelectorUtil.ScopeByNameSelector
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScopeSelectorUtil.ScopeByNameMultiSelector
|
import org.jetbrains.kotlin.resolve.scopes.JetScopeSelectorUtil.ScopeByNameMultiSelector
|
||||||
|
import org.jetbrains.kotlin.psi.JetPsiUtil
|
||||||
|
import org.jetbrains.kotlin.diagnostics.Errors
|
||||||
|
|
||||||
trait IndexedImports {
|
trait IndexedImports {
|
||||||
val imports: List<JetImportDirective>
|
val imports: List<JetImportDirective>
|
||||||
@@ -108,7 +109,7 @@ class LazyImportResolver(
|
|||||||
importer, traceForImportResolve, mode)
|
importer, traceForImportResolve, mode)
|
||||||
importer.doImport(directiveImportScope)
|
importer.doImport(directiveImportScope)
|
||||||
if (mode == LookupMode.EVERYTHING) {
|
if (mode == LookupMode.EVERYTHING) {
|
||||||
ImportsResolver.checkPlatformTypesMappedToKotlin(packageView.getModule(), traceForImportResolve, directive, descriptors)
|
org.jetbrains.kotlin.resolve.PlatformTypesMappedToKotlinChecker.checkPlatformTypesMappedToKotlin(packageView.getModule(), traceForImportResolve, directive, descriptors)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -135,10 +136,40 @@ class LazyImportResolver(
|
|||||||
val status = importedScopesProvider(importDirective).importResolveStatus
|
val status = importedScopesProvider(importDirective).importResolveStatus
|
||||||
if (status != null && !status.descriptors.isEmpty()) {
|
if (status != null && !status.descriptors.isEmpty()) {
|
||||||
val fileScope = resolveSession.getScopeProvider().getFileScope(importDirective.getContainingJetFile())
|
val fileScope = resolveSession.getScopeProvider().getFileScope(importDirective.getContainingJetFile())
|
||||||
ImportsResolver.reportConflictingImport(importDirective, fileScope, status.descriptors, traceForImportResolve)
|
reportConflictingImport(importDirective, fileScope, status.descriptors, traceForImportResolve)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun reportConflictingImport(
|
||||||
|
importDirective: JetImportDirective,
|
||||||
|
fileScope: JetScope,
|
||||||
|
resolvedTo: Collection<DeclarationDescriptor>?,
|
||||||
|
trace: BindingTrace
|
||||||
|
) {
|
||||||
|
|
||||||
|
val importedReference = importDirective.getImportedReference()
|
||||||
|
if (importedReference == null || resolvedTo == null) return
|
||||||
|
|
||||||
|
val aliasName = JetPsiUtil.getAliasName(importDirective)
|
||||||
|
if (aliasName == null) return
|
||||||
|
|
||||||
|
if (resolvedTo.size() != 1) return
|
||||||
|
|
||||||
|
when (resolvedTo.single()) {
|
||||||
|
is ClassDescriptor -> {
|
||||||
|
if (fileScope.getClassifier(aliasName) == null) {
|
||||||
|
trace.report(Errors.CONFLICTING_IMPORT.on(importedReference, aliasName.asString()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is PackageViewDescriptor -> {
|
||||||
|
if (fileScope.getPackage(aliasName) == null) {
|
||||||
|
trace.report(Errors.CONFLICTING_IMPORT.on(importedReference, aliasName.asString()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public fun <D : DeclarationDescriptor> selectSingleFromImports(
|
public fun <D : DeclarationDescriptor> selectSingleFromImports(
|
||||||
name: Name,
|
name: Name,
|
||||||
lookupMode: LookupMode,
|
lookupMode: LookupMode,
|
||||||
|
|||||||
Reference in New Issue
Block a user