Kapt: Write annotations with the "SOURCE" retention if kapt2 is enabled

(cherry picked from commit 6177b2b)
This commit is contained in:
Yan Zhulanow
2016-09-02 18:37:25 +03:00
committed by Yan Zhulanow
parent 00355f3c52
commit 471ddc5a93
32 changed files with 317 additions and 107 deletions
@@ -129,7 +129,7 @@ object KotlinToJVMBytecodeCompiler {
val targetDescription = "in targets [" + chunk.joinToString { input -> input.getModuleName() + "-" + input.getModuleType() } + "]"
var result = analyze(environment, targetDescription)
if (result is AnalysisResult.RetryWithAdditionalJavaRoots) {
val oldReadOnlyValue = projectConfiguration.isReadOnly
projectConfiguration.isReadOnly = false
@@ -142,14 +142,14 @@ object KotlinToJVMBytecodeCompiler {
// Clear package caches (see KotlinJavaPsiFacade)
(PsiManager.getInstance(environment.project).modificationTracker as? PsiModificationTrackerImpl)?.incCounter()
// Clear all diagnostic messages
projectConfiguration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY]?.clear()
// Repeat analysis with additional Java roots (kapt generated sources)
result = analyze(environment, targetDescription)
}
if (result == null || !result.shouldGenerateCode) return false
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
@@ -249,7 +249,7 @@ object KotlinToJVMBytecodeCompiler {
try {
try {
tryConstructClass(scriptClass, scriptArgs)
?: throw RuntimeException("unable to find appropriate constructor for class ${scriptClass.name} accepting arguments $scriptArgs\n")
?: throw RuntimeException("unable to find appropriate constructor for class ${scriptClass.name} accepting arguments $scriptArgs\n")
}
finally {
// NB: these lines are required (see KT-9546) but aren't covered by tests
@@ -428,7 +428,7 @@ object KotlinToJVMBytecodeCompiler {
K2JVMCompiler.reportPerf(environment.configuration, message)
val analysisResult = analyzerWithCompilerReport.analysisResult
return if (!analyzerWithCompilerReport.hasErrors() || analysisResult is AnalysisResult.RetryWithAdditionalJavaRoots)
analysisResult
else
@@ -442,9 +442,10 @@ object KotlinToJVMBytecodeCompiler {
sourceFiles: List<KtFile>,
module: Module?
): GenerationState {
val isKapt2Enabled = environment.project.getUserData(IS_KAPT2_ENABLED_KEY) ?: false
val generationState = GenerationState(
environment.project,
ClassBuilderFactories.BINARIES,
ClassBuilderFactories.binaries(isKapt2Enabled),
result.moduleDescriptor,
result.bindingContext,
sourceFiles,
@@ -0,0 +1,21 @@
/*
* 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.
* 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.cli.jvm.config
import com.intellij.openapi.util.Key
val IS_KAPT2_ENABLED_KEY = Key<Boolean>("IsKapt2EnabledKey")
@@ -113,9 +113,12 @@ class ReplInterpreter(
}
val state = GenerationState(
psiFile.project, ClassBuilderFactories.BINARIES, analyzerEngine.module,
analyzerEngine.trace.bindingContext, listOf(psiFile), configuration
)
psiFile.project,
ClassBuilderFactories.binaries(false),
analyzerEngine.module,
analyzerEngine.trace.bindingContext,
listOf(psiFile),
configuration)
compileScript(psiFile.script!!, earlierLines.map(EarlierLine::getScriptDescriptor), state, CompilationErrorHandler.THROW_EXCEPTION)