Throw ISE earlier on passing certain types of declaration to ResolveSession#resolveToDescriptor()
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -294,12 +294,22 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
@Override
|
||||
@NotNull
|
||||
public DeclarationDescriptor resolveToDescriptor(@NotNull KtDeclaration declaration) {
|
||||
if (!areDescriptorsCreatedForDeclaration(declaration)) {
|
||||
throw new IllegalStateException(
|
||||
"No descriptors are created for declarations of type " + declaration.getClass().getSimpleName()
|
||||
+ "\n. Change the caller accordingly"
|
||||
);
|
||||
}
|
||||
if (!KtPsiUtil.isLocal(declaration)) {
|
||||
return lazyDeclarationResolver.resolveToDescriptor(declaration);
|
||||
}
|
||||
return localDescriptorResolver.resolveLocalDeclaration(declaration);
|
||||
}
|
||||
|
||||
public static boolean areDescriptorsCreatedForDeclaration(@NotNull KtDeclaration declaration) {
|
||||
return !(declaration instanceof KtAnonymousInitializer || declaration instanceof KtDestructuringDeclaration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Annotations getFileAnnotations(@NotNull KtFile file) {
|
||||
return fileAnnotations.invoke(file);
|
||||
|
||||
Reference in New Issue
Block a user