use custom exception class to represent the "no descriptor for declaration" case
This commit is contained in:
+1
-2
@@ -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;
|
||||
}
|
||||
|
||||
+23
@@ -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()}")
|
||||
+2
-5
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-6
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user