Kapt: Add DUMP_DEFAULT_PARAMETER_VALUES flag (KT-29355)
Put initializers on fields when corresponding primary constructor parameters have a default value specified. The new behavior is available under the new 'DUMP_DEFAULT_PARAMETER_VALUES' flag. Note that this doesn't affect regular functions with default parameter values, as well as primary constructor parameters without a 'val' or 'var' keyword.
This commit is contained in:
+18
-16
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isAnnotationConstructor
|
||||
import org.jetbrains.kotlin.resolve.lazy.DeclarationScopeProvider
|
||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
@@ -35,6 +36,9 @@ open class PartialAnalysisHandlerExtension : AnalysisHandlerExtension {
|
||||
open val analyzePartially: Boolean
|
||||
get() = true
|
||||
|
||||
open val analyzeDefaultParameterValues: Boolean
|
||||
get() = false
|
||||
|
||||
override fun doAnalysis(
|
||||
project: Project,
|
||||
module: ModuleDescriptor,
|
||||
@@ -83,20 +87,17 @@ open class PartialAnalysisHandlerExtension : AnalysisHandlerExtension {
|
||||
* val a: Runnable = object : Runnable { ... } */
|
||||
bodyResolver.resolveProperty(topDownAnalysisContext, declaration, descriptor)
|
||||
}
|
||||
else if (declaration is KtParameter) { // Annotation parameter
|
||||
val ownerElement = declaration.ownerFunction
|
||||
val ownerDescriptor = bindingTrace[BindingContext.VALUE_PARAMETER, declaration]?.containingDeclaration
|
||||
val containingScope = ownerDescriptor?.containingScope
|
||||
|
||||
if (ownerElement is KtPrimaryConstructor && ownerDescriptor is ConstructorDescriptor && containingScope != null) {
|
||||
bodyResolver.resolveConstructorParameterDefaultValues(
|
||||
topDownAnalysisContext.outerDataFlowInfo, bindingTrace, ownerElement, ownerDescriptor, containingScope)
|
||||
}
|
||||
}
|
||||
}
|
||||
is FunctionDescriptor -> {
|
||||
// is body expression (not unit)
|
||||
if (declaration is KtFunction && !declaration.hasDeclaredReturnType() && !declaration.hasBlockBody()) {
|
||||
if (declaration is KtPrimaryConstructor && (analyzeDefaultParameterValues || descriptor.isAnnotationConstructor())) {
|
||||
val containingScope = descriptor.containingScope
|
||||
if (containingScope != null) {
|
||||
bodyResolver.resolveConstructorParameterDefaultValues(
|
||||
topDownAnalysisContext.outerDataFlowInfo, bindingTrace,
|
||||
declaration, descriptor as ConstructorDescriptor, containingScope
|
||||
)
|
||||
}
|
||||
} else if (declaration is KtFunction && !declaration.hasDeclaredReturnType() && !declaration.hasBlockBody()) {
|
||||
ForceResolveUtil.forceResolveAllContents(descriptor)
|
||||
}
|
||||
}
|
||||
@@ -122,11 +123,12 @@ open class PartialAnalysisHandlerExtension : AnalysisHandlerExtension {
|
||||
}
|
||||
|
||||
if (declaration is KtClassOrObject) {
|
||||
declaration.declarations.forEach { doForEachDeclaration(it, f) }
|
||||
}
|
||||
val primaryConstructor = declaration.primaryConstructor
|
||||
if (primaryConstructor != null) {
|
||||
f(primaryConstructor)
|
||||
}
|
||||
|
||||
if (declaration is KtClass && declaration.isAnnotation()) {
|
||||
declaration.primaryConstructorParameters.forEach { doForEachDeclaration(it, f) }
|
||||
declaration.declarations.forEach { doForEachDeclaration(it, f) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user