Extract superclass from AnnotationResolver
This commit is contained in:
@@ -62,6 +62,7 @@ private fun StorageComponentContainer.configureJavaTopDownAnalysis(
|
||||
useInstance(VirtualFileFinderFactory.getInstance(project).create(moduleContentScope))
|
||||
|
||||
useImpl<FileScopeProviderImpl>()
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
|
||||
useImpl<JavaClassFinderImpl>()
|
||||
useImpl<SignaturePropagatorImpl>()
|
||||
|
||||
@@ -134,6 +134,7 @@ object DefaultAnalyzerFacade : AnalyzerFacade<PlatformAnalysisParameters>() {
|
||||
useImpl<LazyTopDownAnalyzer>()
|
||||
useImpl<FileScopeProviderImpl>()
|
||||
useInstance(languageVersionSettings)
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
useImpl<CompilerDeserializationConfiguration>()
|
||||
useInstance(packagePartProvider)
|
||||
useInstance(declarationProviderFactory)
|
||||
|
||||
@@ -88,6 +88,7 @@ fun createContainerForBodyResolve(
|
||||
useInstance(LookupTracker.DO_NOTHING)
|
||||
useInstance(BodyResolveCache.ThrowException)
|
||||
useInstance(languageVersionSettings)
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
|
||||
useImpl<BodyResolver>()
|
||||
}
|
||||
@@ -108,6 +109,7 @@ fun createContainerForLazyBodyResolve(
|
||||
useInstance(kotlinCodeAnalyzer.fileScopeProvider)
|
||||
useInstance(bodyResolveCache)
|
||||
useInstance(languageVersionSettings)
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
useImpl<LazyTopDownAnalyzer>()
|
||||
useImpl<BasicAbsentDescriptorHandler>()
|
||||
}
|
||||
@@ -134,6 +136,7 @@ fun createContainerForLazyLocalClassifierAnalyzer(
|
||||
CompilerEnvironment.configure(this)
|
||||
|
||||
useInstance(FileScopeProvider.ThrowException)
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
|
||||
useImpl<DeclarationScopeProviderForLocalClassifierAnalyzer>()
|
||||
useImpl<LocalLazyDeclarationResolver>()
|
||||
@@ -158,6 +161,7 @@ fun createContainerForLazyResolve(
|
||||
useInstance(languageVersionSettings)
|
||||
|
||||
useImpl<FileScopeProviderImpl>()
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
useImpl<CompilerDeserializationConfiguration>()
|
||||
targetEnvironment.configure(this)
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||
import org.jetbrains.kotlin.psi.KtModifierList
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
abstract class AnnotationResolver {
|
||||
fun resolveAnnotationsWithoutArguments(
|
||||
scope: LexicalScope,
|
||||
modifierList: KtModifierList?,
|
||||
trace: BindingTrace
|
||||
): Annotations = resolveAnnotationsFromModifierList(scope, modifierList, trace, false)
|
||||
|
||||
fun resolveAnnotationsWithArguments(
|
||||
scope: LexicalScope,
|
||||
modifierList: KtModifierList?,
|
||||
trace: BindingTrace
|
||||
): Annotations = resolveAnnotationsFromModifierList(scope, modifierList, trace, true)
|
||||
|
||||
|
||||
private fun resolveAnnotationsFromModifierList(
|
||||
scope: LexicalScope,
|
||||
modifierList: KtModifierList?,
|
||||
trace: BindingTrace,
|
||||
shouldResolveArguments: Boolean
|
||||
): Annotations {
|
||||
if (modifierList == null) {
|
||||
return Annotations.EMPTY
|
||||
}
|
||||
|
||||
return resolveAnnotationEntries(scope, modifierList.annotationEntries, trace, shouldResolveArguments)
|
||||
}
|
||||
|
||||
fun resolveAnnotationsWithoutArguments(
|
||||
scope: LexicalScope,
|
||||
annotationEntries: @JvmSuppressWildcards List<KtAnnotationEntry>,
|
||||
trace: BindingTrace
|
||||
): Annotations = resolveAnnotationEntries(scope, annotationEntries, trace, false)
|
||||
|
||||
fun resolveAnnotationsWithArguments(
|
||||
scope: LexicalScope,
|
||||
annotationEntries: @JvmSuppressWildcards List<KtAnnotationEntry>,
|
||||
trace: BindingTrace
|
||||
): Annotations = resolveAnnotationEntries(scope, annotationEntries, trace, true)
|
||||
|
||||
protected abstract fun resolveAnnotationEntries(
|
||||
scope: LexicalScope,
|
||||
annotationEntries: @JvmSuppressWildcards List<KtAnnotationEntry>,
|
||||
trace: BindingTrace,
|
||||
shouldResolveArguments: Boolean
|
||||
): Annotations
|
||||
|
||||
|
||||
abstract fun resolveAnnotationType(scope: LexicalScope, entryElement: KtAnnotationEntry, trace: BindingTrace): KotlinType
|
||||
|
||||
abstract fun resolveAnnotationCall(
|
||||
annotationEntry: KtAnnotationEntry,
|
||||
scope: LexicalScope,
|
||||
trace: BindingTrace
|
||||
): OverloadResolutionResults<FunctionDescriptor>
|
||||
|
||||
abstract fun getAnnotationArgumentValue(
|
||||
trace: BindingTrace,
|
||||
valueParameter: ValueParameterDescriptor,
|
||||
resolvedArgument: ResolvedValueArgument
|
||||
): ConstantValue<*>?
|
||||
}
|
||||
+15
-54
@@ -44,13 +44,13 @@ import java.util.List;
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.NOT_AN_ANNOTATION_CLASS;
|
||||
import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
|
||||
public class AnnotationResolver {
|
||||
public class AnnotationResolverImpl extends AnnotationResolver {
|
||||
@NotNull private final CallResolver callResolver;
|
||||
@NotNull private final StorageManager storageManager;
|
||||
@NotNull private TypeResolver typeResolver;
|
||||
@NotNull private final ConstantExpressionEvaluator constantExpressionEvaluator;
|
||||
|
||||
public AnnotationResolver(
|
||||
public AnnotationResolverImpl(
|
||||
@NotNull CallResolver callResolver,
|
||||
@NotNull ConstantExpressionEvaluator constantExpressionEvaluator,
|
||||
@NotNull StorageManager storageManager
|
||||
@@ -67,56 +67,10 @@ public class AnnotationResolver {
|
||||
this.typeResolver = typeResolver;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Annotations resolveAnnotationsWithoutArguments(
|
||||
@NotNull LexicalScope scope,
|
||||
@Nullable KtModifierList modifierList,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
return resolveAnnotations(scope, modifierList, trace, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Annotations resolveAnnotationsWithArguments(
|
||||
@NotNull LexicalScope scope,
|
||||
@Nullable KtModifierList modifierList,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
return resolveAnnotations(scope, modifierList, trace, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Annotations resolveAnnotationsWithoutArguments(
|
||||
@NotNull LexicalScope scope,
|
||||
@NotNull List<KtAnnotationEntry> annotationEntries,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
return resolveAnnotationEntries(scope, annotationEntries, trace, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Annotations resolveAnnotationsWithArguments(
|
||||
@NotNull LexicalScope scope,
|
||||
@NotNull List<KtAnnotationEntry> annotationEntries,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
return resolveAnnotationEntries(scope, annotationEntries, trace, true);
|
||||
}
|
||||
|
||||
private Annotations resolveAnnotations(
|
||||
@NotNull LexicalScope scope,
|
||||
@Nullable KtModifierList modifierList,
|
||||
@NotNull BindingTrace trace,
|
||||
boolean shouldResolveArguments
|
||||
) {
|
||||
if (modifierList == null) {
|
||||
return Annotations.Companion.getEMPTY();
|
||||
}
|
||||
|
||||
return resolveAnnotationEntries(scope, modifierList.getAnnotationEntries(), trace, shouldResolveArguments);
|
||||
}
|
||||
|
||||
private Annotations resolveAnnotationEntries(
|
||||
@Override
|
||||
public Annotations resolveAnnotationEntries(
|
||||
@NotNull LexicalScope scope,
|
||||
@NotNull List<KtAnnotationEntry> annotationEntryElements,
|
||||
@NotNull BindingTrace trace,
|
||||
@@ -145,8 +99,13 @@ public class AnnotationResolver {
|
||||
return AnnotationsImpl.create(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public KotlinType resolveAnnotationType(@NotNull LexicalScope scope, @NotNull KtAnnotationEntry entryElement, @NotNull BindingTrace trace) {
|
||||
public KotlinType resolveAnnotationType(
|
||||
@NotNull LexicalScope scope,
|
||||
@NotNull KtAnnotationEntry entryElement,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
KtTypeReference typeReference = entryElement.getTypeReference();
|
||||
if (typeReference == null) {
|
||||
return ErrorUtils.createErrorType("No type reference: " + entryElement.getText());
|
||||
@@ -180,11 +139,12 @@ public class AnnotationResolver {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public OverloadResolutionResults<FunctionDescriptor> resolveAnnotationCall(
|
||||
KtAnnotationEntry annotationEntry,
|
||||
LexicalScope scope,
|
||||
BindingTrace trace
|
||||
@NotNull KtAnnotationEntry annotationEntry,
|
||||
@NotNull LexicalScope scope,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
return callResolver.resolveFunctionCall(
|
||||
trace, scope,
|
||||
@@ -204,6 +164,7 @@ public class AnnotationResolver {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ConstantValue<?> getAnnotationArgumentValue(
|
||||
@NotNull BindingTrace trace,
|
||||
@@ -448,7 +448,7 @@ class DeclarationsChecker(
|
||||
private fun checkTypeParameters(typeParameterListOwner: KtTypeParameterListOwner) {
|
||||
// TODO: Support annotation for type parameters
|
||||
for (jetTypeParameter in typeParameterListOwner.typeParameters) {
|
||||
AnnotationResolver.reportUnsupportedAnnotationForTypeParameter(jetTypeParameter, trace)
|
||||
AnnotationResolverImpl.reportUnsupportedAnnotationForTypeParameter(jetTypeParameter, trace)
|
||||
|
||||
trace.get(TYPE_PARAMETER, jetTypeParameter)?.let { DescriptorResolver.checkConflictingUpperBounds(trace, it, jetTypeParameter) }
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@
|
||||
package org.jetbrains.kotlin.resolve
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.builtins.*
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationsImpl
|
||||
@@ -44,12 +47,10 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.TraceBasedLocalRedeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionExpression
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral
|
||||
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
|
||||
@@ -59,8 +60,6 @@ class FunctionDescriptorResolver(
|
||||
private val typeResolver: TypeResolver,
|
||||
private val descriptorResolver: DescriptorResolver,
|
||||
private val annotationResolver: AnnotationResolver,
|
||||
private val storageManager: StorageManager,
|
||||
private val expressionTypingServices: ExpressionTypingServices,
|
||||
private val builtIns: KotlinBuiltIns,
|
||||
private val modifiersChecker: ModifiersChecker,
|
||||
private val overloadChecker: OverloadChecker
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.psi.KtPsiUtil
|
||||
import org.jetbrains.kotlin.psi.KtVariableDeclaration
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore
|
||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
private final MemoizedFunctionToNotNull<KtFile, LazyAnnotations> danglingAnnotations;
|
||||
|
||||
private KtImportsFactory jetImportFactory;
|
||||
private AnnotationResolver annotationResolve;
|
||||
private AnnotationResolver annotationResolver;
|
||||
private DescriptorResolver descriptorResolver;
|
||||
private FunctionDescriptorResolver functionDescriptorResolver;
|
||||
private TypeResolver typeResolver;
|
||||
@@ -93,8 +93,8 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setAnnotationResolve(AnnotationResolver annotationResolve) {
|
||||
this.annotationResolve = annotationResolve;
|
||||
public void setAnnotationResolve(AnnotationResolver annotationResolver) {
|
||||
this.annotationResolver = annotationResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@@ -216,7 +216,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
private LazyAnnotations createAnnotations(KtFile file, List<KtAnnotationEntry> annotationEntries) {
|
||||
LexicalScope scope = fileScopeProvider.getFileResolutionScope(file);
|
||||
LazyAnnotationsContextImpl lazyAnnotationContext =
|
||||
new LazyAnnotationsContextImpl(annotationResolve, storageManager, trace, scope);
|
||||
new LazyAnnotationsContextImpl(annotationResolver, storageManager, trace, scope);
|
||||
return new LazyAnnotations(lazyAnnotationContext, annotationEntries);
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
@Override
|
||||
@NotNull
|
||||
public AnnotationResolver getAnnotationResolver() {
|
||||
return annotationResolve;
|
||||
return annotationResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-5
@@ -23,10 +23,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||
import org.jetbrains.kotlin.resolve.AnnotationResolver
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyEntity
|
||||
@@ -144,7 +141,7 @@ class LazyAnnotationDescriptor(
|
||||
|
||||
private fun computeValueArguments(): Map<ValueParameterDescriptor, ConstantValue<*>> {
|
||||
val resolutionResults = c.annotationResolver.resolveAnnotationCall(annotationEntry, scope, c.trace)
|
||||
AnnotationResolver.checkAnnotationType(annotationEntry, c.trace, resolutionResults)
|
||||
AnnotationResolverImpl.checkAnnotationType(annotationEntry, c.trace, resolutionResults)
|
||||
|
||||
if (!resolutionResults.isSingleResult) return mapOf()
|
||||
|
||||
|
||||
@@ -27,10 +27,7 @@ import org.jetbrains.kotlin.context.ModuleContext
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.frontend.di.configureModule
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.resolve.DescriptorResolver
|
||||
import org.jetbrains.kotlin.resolve.FunctionDescriptorResolver
|
||||
import org.jetbrains.kotlin.resolve.TypeResolver
|
||||
import org.jetbrains.kotlin.resolve.createContainer
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.types.expressions.FakeCallResolver
|
||||
@@ -40,6 +37,7 @@ fun createContainerForTests(project: Project, module: ModuleDescriptor): Contain
|
||||
configureModule(ModuleContext(module, project), JvmPlatform, JvmTarget.JVM_1_6)
|
||||
useInstance(LookupTracker.DO_NOTHING)
|
||||
useInstance(LanguageVersionSettingsImpl.DEFAULT)
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
useImpl<ExpressionTypingServices>()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -26,10 +26,7 @@ import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.frontend.di.configureModule
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.CompilerEnvironment
|
||||
import org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.createContainer
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.lazy.FileScopeProviderImpl
|
||||
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
@@ -46,6 +43,7 @@ fun createTopDownAnalyzerForJs(
|
||||
|
||||
useInstance(declarationProviderFactory)
|
||||
useImpl<FileScopeProviderImpl>()
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
|
||||
CompilerEnvironment.configure(this)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user