diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyDeclarationResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyDeclarationResolver.java index 982f2df9149..0658ba9d8ee 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyDeclarationResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyDeclarationResolver.java @@ -220,8 +220,7 @@ public class LazyDeclarationResolver { } }, null); if (result == null) { - throw new IllegalStateException("No descriptor resolved for " + declaration + ":\n" + - PsiUtilPackage.getElementTextWithContext(declaration)); + throw new NoDescriptorForDeclarationException(declaration); } return result; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/NoDescriptorForDeclarationException.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/NoDescriptorForDeclarationException.kt new file mode 100644 index 00000000000..38400591983 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/NoDescriptorForDeclarationException.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2015 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.resolve.lazy + +import org.jetbrains.kotlin.psi.JetDeclaration +import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext + +class NoDescriptorForDeclarationException(declaration: JetDeclaration) : + IllegalStateException("Descriptor wasn't found for declaration $declaration\n${declaration.getElementTextWithContext()}") diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.java index 7515d016bf0..d6562051d9c 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.java @@ -54,10 +54,7 @@ import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.psi.psiUtil.PsiUtilPackage; import org.jetbrains.kotlin.resolve.BindingContext; -import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode; -import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil; -import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer; -import org.jetbrains.kotlin.resolve.lazy.ResolveSession; +import org.jetbrains.kotlin.resolve.lazy.*; import org.jetbrains.kotlin.resolve.scopes.JetScope; import java.io.IOException; @@ -310,7 +307,7 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport try { return (ClassDescriptor) ResolvePackage.resolveToDescriptor(classOrObject); } - catch (IllegalStateException e) { + catch (NoDescriptorForDeclarationException e) { return null; } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/IdeaLocalDescriptorResolver.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/IdeaLocalDescriptorResolver.kt index 50f198a907d..8c6442edb1d 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/IdeaLocalDescriptorResolver.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/IdeaLocalDescriptorResolver.kt @@ -18,20 +18,17 @@ package org.jetbrains.kotlin.idea.project import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.psi.JetDeclaration -import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.resolve.BindingContextUtils import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.lazy.LocalDescriptorResolver +import org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException public class IdeaLocalDescriptorResolver( private val resolveElementCache: ResolveElementCache ): LocalDescriptorResolver { override fun resolveLocalDeclaration(declaration: JetDeclaration): DeclarationDescriptor { val context = resolveElementCache.resolveToElement(declaration, BodyResolveMode.FULL) - return BindingContextUtils.getNotNull( - context, BindingContext.DECLARATION_TO_DESCRIPTOR, declaration, - "Descriptor wasn't found for declaration $declaration\n${declaration.getElementTextWithContext()}" - ) + return context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration) + ?: throw NoDescriptorForDeclarationException(declaration) } } \ No newline at end of file