diff --git a/.idea/modules.xml b/.idea/modules.xml
index d6670b3ae98..336bbaefd71 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -14,7 +14,6 @@
-
@@ -64,7 +63,6 @@
-
diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt
index f600ebe20eb..85d38c839f1 100755
--- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt
+++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt
@@ -30,9 +30,6 @@ import org.jetbrains.kotlin.android.intention.AbstractAndroidResourceIntentionTe
import org.jetbrains.kotlin.android.lint.AbstractKotlinLintTest
import org.jetbrains.kotlin.android.quickfix.AbstractAndroidLintQuickfixTest
import org.jetbrains.kotlin.android.quickfix.AbstractAndroidQuickFixMultiFileTest
-import org.jetbrains.kotlin.annotation.AbstractAnnotationProcessorBoxTest
-import org.jetbrains.kotlin.annotation.processing.test.sourceRetention.AbstractBytecodeListingTestForSourceRetention
-import org.jetbrains.kotlin.annotation.processing.test.wrappers.AbstractAnnotationProcessingTest
import org.jetbrains.kotlin.asJava.AbstractCompilerLightClassTest
import org.jetbrains.kotlin.cfg.AbstractControlFlowTest
import org.jetbrains.kotlin.cfg.AbstractDataFlowTest
@@ -160,6 +157,7 @@ import org.jetbrains.kotlin.kdoc.AbstractKDocLexerTest
import org.jetbrains.kotlin.android.synthetic.test.AbstractAndroidBoxTest
import org.jetbrains.kotlin.android.synthetic.test.AbstractAndroidBytecodeShapeTest
import org.jetbrains.kotlin.android.synthetic.test.AbstractAndroidSyntheticPropertyDescriptorTest
+import org.jetbrains.kotlin.annotation.AbstractAnnotationProcessorBoxTest
import org.jetbrains.kotlin.modules.xml.AbstractModuleXmlParserTest
import org.jetbrains.kotlin.multiplatform.AbstractMultiPlatformIntegrationTest
import org.jetbrains.kotlin.noarg.AbstractBlackBoxCodegenTestForNoArg
@@ -1258,16 +1256,6 @@ fun main(args: Array) {
}
}
- testGroup("plugins/plugins-tests/tests", "plugins/annotation-processing/testData") {
- testClass {
- model("wrappers", recursive = true, extension = "kt")
- }
-
- testClass {
- model("sourceRetention", extension = "kt")
- }
- }
-
testGroup("plugins/kapt3/test", "plugins/kapt3/testData") {
testClass {
model("converter")
diff --git a/plugins/annotation-processing/annotation-processing.iml b/plugins/annotation-processing/annotation-processing.iml
deleted file mode 100644
index e351929b013..00000000000
--- a/plugins/annotation-processing/annotation-processing.iml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/plugins/annotation-processing/src/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor b/plugins/annotation-processing/src/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
deleted file mode 100644
index 769c1967d51..00000000000
--- a/plugins/annotation-processing/src/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
+++ /dev/null
@@ -1 +0,0 @@
-org.jetbrains.kotlin.annotation.processing.AnnotationProcessingCommandLineProcessor
\ No newline at end of file
diff --git a/plugins/annotation-processing/src/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar b/plugins/annotation-processing/src/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
deleted file mode 100644
index 4af1a3bcc17..00000000000
--- a/plugins/annotation-processing/src/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
+++ /dev/null
@@ -1 +0,0 @@
-org.jetbrains.kotlin.annotation.processing.AnnotationProcessingComponentRegistrar
\ No newline at end of file
diff --git a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/AnnotationProcessingExtension.kt b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/AnnotationProcessingExtension.kt
deleted file mode 100755
index 1f124435f7d..00000000000
--- a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/AnnotationProcessingExtension.kt
+++ /dev/null
@@ -1,361 +0,0 @@
-/*
- * 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.annotation
-
-import com.intellij.openapi.application.ApplicationManager
-import com.intellij.openapi.project.Project
-import com.intellij.openapi.vfs.StandardFileSystems
-import com.intellij.psi.JavaPsiFacade
-import com.intellij.psi.PsiJavaFile
-import com.intellij.psi.PsiManager
-import com.intellij.psi.impl.PsiModificationTrackerImpl
-import com.intellij.psi.search.GlobalSearchScope
-import org.jetbrains.kotlin.analyzer.AnalysisResult
-import org.jetbrains.kotlin.annotation.processing.RoundAnnotations
-import org.jetbrains.kotlin.annotation.processing.diagnostic.ErrorsAnnotationProcessing
-import org.jetbrains.kotlin.annotation.processing.impl.*
-import org.jetbrains.kotlin.cli.common.messages.*
-import org.jetbrains.kotlin.codegen.ClassBuilderMode
-import org.jetbrains.kotlin.codegen.state.IncompatibleClassTracker
-import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
-import org.jetbrains.kotlin.config.APPEND_JAVA_SOURCE_ROOTS_HANDLER_KEY
-import org.jetbrains.kotlin.descriptors.ModuleDescriptor
-import org.jetbrains.kotlin.fileClasses.NoResolveFileClassesProvider
-import org.jetbrains.kotlin.java.model.elements.JeTypeElement
-import org.jetbrains.kotlin.load.java.JvmAbi
-import org.jetbrains.kotlin.psi.KtFile
-import org.jetbrains.kotlin.resolve.BindingTrace
-import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
-import java.io.File
-import java.io.IOException
-import java.io.PrintWriter
-import java.io.StringWriter
-import java.net.URLClassLoader
-import java.util.*
-import javax.annotation.processing.Processor
-import javax.tools.Diagnostic
-
-class ClasspathBasedAnnotationProcessingExtension(
- val annotationProcessingClasspath: List,
- override val options: Map,
- generatedSourcesOutputDir: File,
- classesOutputDir: File,
- javaSourceRoots: List,
- verboseOutput: Boolean,
- incrementalDataFile: File?,
- messageCollector: MessageCollector?
-) : AbstractAnnotationProcessingExtension(generatedSourcesOutputDir,
- classesOutputDir, javaSourceRoots, verboseOutput,
- incrementalDataFile, messageCollector) {
- override fun loadAnnotationProcessors(): List {
- val classLoader = URLClassLoader(annotationProcessingClasspath.map { it.toURI().toURL() }.toTypedArray())
- return ServiceLoader.load(Processor::class.java, classLoader).toList()
- }
-}
-
-abstract class AbstractAnnotationProcessingExtension(
- val generatedSourcesOutputDir: File,
- val classesOutputDir: File,
- val javaSourceRoots: List,
- val verboseOutput: Boolean,
- val incrementalDataFile: File? = null,
- messageCollector: MessageCollector? = null
-) : AnalysisHandlerExtension {
- private companion object {
- val LINE_SEPARATOR = System.getProperty("line.separator") ?: "\n"
- }
-
- private var annotationProcessingComplete = false
- private val messager = run {
- val collector = messageCollector ?: PrintingMessageCollector(System.err, MessageRenderer.WITHOUT_PATHS, verboseOutput)
- KotlinMessager(collector)
- }
-
- private inline fun log(message: () -> String) {
- if (verboseOutput) {
- messager.printMessage(Diagnostic.Kind.OTHER, "Kapt: " + message())
- }
- }
-
- private fun Int.count(noun: String) = if (this == 1) "$this $noun" else "$this ${noun}s"
-
- private inline fun T.runIf(condition: Boolean, block: T.() -> R) {
- if (condition) block()
- }
-
- override fun analysisCompleted(
- project: Project,
- module: ModuleDescriptor,
- bindingTrace: BindingTrace,
- files: Collection
- ): AnalysisResult? {
- if (annotationProcessingComplete) {
- return null
- }
-
- // Clean the generated source directory even if we don't run any annotation processors
- generatedSourcesOutputDir.deleteRecursively()
- generatedSourcesOutputDir.mkdirs()
-
- val processors = loadAnnotationProcessors()
- if (processors.isEmpty()) {
- log { "No annotation processors detected, exiting" }
- return null
- }
-
- val appendJavaSourceRootsHandler = project.getUserData(APPEND_JAVA_SOURCE_ROOTS_HANDLER_KEY)
- if (appendJavaSourceRootsHandler == null) {
- log { "Java source root handler is not set, exiting" }
- return null
- }
-
- val startTime = System.currentTimeMillis()
-
- val psiManager = PsiManager.getInstance(project)
- val javaPsiFacade = JavaPsiFacade.getInstance(project)
- val projectScope = GlobalSearchScope.projectScope(project)
-
- val options = this.options
- log { "Options: $options" }
-
- val filer = KotlinFiler(generatedSourcesOutputDir, classesOutputDir)
- val types = KotlinTypes(javaPsiFacade, PsiManager.getInstance(project), projectScope)
- val elements = KotlinElements(javaPsiFacade, projectScope)
-
- val processingEnvironment = KotlinProcessingEnvironment(
- elements, types, messager, options, filer, processors,
- project, psiManager, javaPsiFacade, projectScope, bindingTrace.bindingContext, appendJavaSourceRootsHandler)
-
- var processingResult: ProcessingResult
- try {
- processingResult = processingEnvironment.doAnnotationProcessing(files)
- processingEnvironment.dispose()
- }
- catch (thr: Throwable) {
- messager.printMessage(
- Diagnostic.Kind.ERROR,
- "An exception occurred during annotation processing. Stacktrace: \n" + thr.getStackTraceAsString())
-
- processingResult = ProcessingResult(errorCount = 1, warningCount = 0, wasAnythingGenerated = false)
- }
-
- annotationProcessingComplete = true
- log {
- "Annotation processing complete in ${System.currentTimeMillis() - startTime} ms, " +
- processingResult.errorCount.count("error") + ", " +
- processingResult.warningCount.count("warning")
- }
-
- if (processingResult.errorCount != 0) {
- val reportFile = files.firstOrNull()
- if (reportFile != null) {
- bindingTrace.report(ErrorsAnnotationProcessing.ANNOTATION_PROCESSING_ERROR.on(reportFile))
- }
-
- // Do not restart Kotlin file analysis
- return null
- }
-
- if (!processingResult.wasAnythingGenerated) {
- // Nothing was generated, do not need to restart analysis
- return null
- }
-
- return AnalysisResult.RetryWithAdditionalJavaRoots(
- bindingTrace.bindingContext,
- module,
- listOf(generatedSourcesOutputDir),
- addToEnvironment = false)
- }
-
- private fun Throwable.getStackTraceAsString(): String {
- val out = StringWriter(1024)
- val printWriter = PrintWriter(out)
- try {
- printStackTrace(printWriter)
- return out.toString().replace("\r", "")
- }
- finally {
- printWriter.close()
- }
- }
-
- private fun KotlinProcessingEnvironment.createTypeMapper(): KotlinTypeMapper {
- return KotlinTypeMapper(bindingContext(), ClassBuilderMode.full(false), NoResolveFileClassesProvider,
- IncompatibleClassTracker.DoNothing, JvmAbi.DEFAULT_MODULE_NAME, false, false)
- }
-
- private fun KotlinProcessingEnvironment.doAnnotationProcessing(files: Collection): ProcessingResult {
- run initializeProcessors@ {
- processors().forEach { it.init(this) }
- log { "Initialized processors: " + processors().joinToString { it::class.java.name } }
- }
-
- val firstRoundAnnotations = RoundAnnotations(
- bindingContext(),
- createTypeMapper())
-
- run analyzeFilesForFirstRound@ {
- log { "Analysing Kotlin files: " + files.map { it.virtualFile.path } }
- firstRoundAnnotations.analyzeFiles(files)
-
- log { "Analysing Java source roots: $javaSourceRoots" }
- for (javaSourceRoot in javaSourceRoots) {
- javaSourceRoot.walk().filter { it.isFile && it.extension == "java" }.forEach {
- val vFile = StandardFileSystems.local().findFileByPath(it.absolutePath)
- if (vFile != null) {
- val javaFile = psiManager().findFile(vFile) as? PsiJavaFile
- if (javaFile != null) {
- firstRoundAnnotations.analyzeFile(javaFile)
- }
- }
- }
- }
- }
-
- runIf(incrementalDataFile != null) processIncrementalData@ {
- val incrementalDataFile = incrementalDataFile!!
-
-
- runIf(incrementalDataFile.exists()) analyzeFilesFromPreviousIncrementalData@ {
- val incrementalData = try {
- incrementalDataFile.readText()
- } catch (e: IOException) {
- log { "An exception occurred while processing incremental data file: $incrementalDataFile" }
- null
- }
-
- if (incrementalData != null) {
- val analyzedClasses = mutableListOf()
-
- for (line in incrementalData.lines()) {
- if (line.length < 3 || !line.startsWith("i ")) continue
- val fqName = line.drop(2)
- val psiClass = javaPsiFacade().findClass(fqName, projectScope()) ?: continue
- if (firstRoundAnnotations.analyzeDeclaration(psiClass)) {
- analyzedClasses += fqName
- }
- }
-
- log { "Analysing files from incremental data: $analyzedClasses" }
- }
- }
-
- run saveNewIncrementalData@ {
- val analyzedClasses = firstRoundAnnotations.analyzedClasses
- log { "Saving incremental data: ${analyzedClasses.size} class names" }
- try {
- incrementalDataFile.parentFile.mkdirs()
- incrementalDataFile.writeText(analyzedClasses.joinToString(LINE_SEPARATOR) { "i $it" })
- }
- catch (e: IOException) {
- log { "Unable to write $incrementalDataFile" }
- }
- }
- }
-
- val finalRoundNumber = run annotationProcessing@ {
- val firstRoundEnvironment = KotlinRoundEnvironment(firstRoundAnnotations, false, 1)
- process(firstRoundEnvironment) // Dispose for firstRoundEnvironment is called inside process
- } + 1
-
- log { "Starting round $finalRoundNumber (final)" }
- val finalRoundEnvironment = KotlinRoundEnvironment(firstRoundAnnotations.copy(), true, finalRoundNumber)
- for (processor in processors()) {
- processor.process(emptySet(), finalRoundEnvironment)
- }
- finalRoundEnvironment.dispose()
-
- return ProcessingResult(messager.errorCount, messager.warningCount, filer.wasAnythingGenerated)
- }
-
- private tailrec fun KotlinProcessingEnvironment.process(roundEnvironment: KotlinRoundEnvironment): Int {
- val newFiles = doRound(roundEnvironment)
- val newJavaFiles = newFiles.filter { it.extension.toLowerCase() == "java" }
- if (newJavaFiles.isEmpty() || messager.errorCount != 0) {
- return roundEnvironment.roundNumber
- }
-
- // Add new Java source roots after the first round
- if (roundEnvironment.roundNumber == 1) {
- appendJavaSourceRootsHandler()(listOf(generatedSourcesOutputDir))
- }
-
- // Update the platform caches
- ApplicationManager.getApplication().runWriteAction {
- (psiManager().modificationTracker as? PsiModificationTrackerImpl)?.incCounter()
- }
-
- // Find generated files
- val localFileSystem = StandardFileSystems.local()
- val psiFiles = newJavaFiles
- .map { localFileSystem.findFileByPath(it.absolutePath)?.let { psiManager().findFile(it) } }
- .filterIsInstance()
-
- if (psiFiles.isEmpty()) {
- log { "Something is strange, files were generated but not found by PsiManager" }
- return roundEnvironment.roundNumber
- }
-
- // Start the next round
- val nextRoundAnnotations = roundEnvironment.roundAnnotations().copy().apply { analyzeFiles(psiFiles) }
- val nextRoundEnvironment = KotlinRoundEnvironment(nextRoundAnnotations, false, roundEnvironment.roundNumber + 1)
- roundEnvironment.dispose()
- return process(nextRoundEnvironment)
- }
-
- private fun KotlinProcessingEnvironment.doRound(roundEnvironment: KotlinRoundEnvironment): List {
- log { "Starting round ${roundEnvironment.roundNumber}" }
-
- val newFiles = mutableListOf()
- filer.onFileCreatedHandler = { newFiles += it }
-
- for (processor in processors()) {
- val supportedAnnotationNames = processor.supportedAnnotationTypes
- val acceptsAnyAnnotation = supportedAnnotationNames.contains("*")
-
- val applicableAnnotationNames = when (acceptsAnyAnnotation) {
- true -> roundEnvironment.roundAnnotations().annotationsMap.keys
- false -> processor.supportedAnnotationTypes.filter { it in roundEnvironment.roundAnnotations().annotationsMap }
- }
-
- if (applicableAnnotationNames.isEmpty()) {
- log { "Skipping processor " + processor::class.java.name + ": no relevant annotations" }
- continue
- }
-
- val applicableAnnotations = applicableAnnotationNames
- .map { javaPsiFacade().findClass(it, projectScope())?.let(::JeTypeElement) }
- .filterNotNullTo(hashSetOf())
-
- log {
- val annotationNames = applicableAnnotations.joinToString { it.qualifiedName.toString() }
- "Processing with " + processor::class.java.name + " (annotations: " + annotationNames + ")"
- }
-
- processor.process(applicableAnnotations, roundEnvironment)
- }
-
- log { "Round ${roundEnvironment.roundNumber} finished, ${newFiles.size.count("file")} generated (${newFiles.joinToString()})" }
- return newFiles
- }
-
- protected abstract fun loadAnnotationProcessors(): List
- protected abstract val options: Map
-}
-
-private class ProcessingResult(val errorCount: Int, val warningCount: Int, val wasAnythingGenerated: Boolean)
diff --git a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/AnnotationProcessingPlugin.kt b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/AnnotationProcessingPlugin.kt
deleted file mode 100755
index 4ccd8284e43..00000000000
--- a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/AnnotationProcessingPlugin.kt
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * 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.annotation.processing
-
-import com.intellij.mock.MockProject
-import com.intellij.openapi.extensions.Extensions
-import org.jetbrains.kotlin.annotation.ClasspathBasedAnnotationProcessingExtension
-import org.jetbrains.kotlin.annotation.processing.diagnostic.DefaultErrorMessagesAnnotationProcessing
-import org.jetbrains.kotlin.cli.jvm.config.IS_KAPT2_ENABLED_KEY
-import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot
-import org.jetbrains.kotlin.cli.jvm.config.JvmContentRoot
-import org.jetbrains.kotlin.compiler.plugin.CliOption
-import org.jetbrains.kotlin.compiler.plugin.CliOptionProcessingException
-import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
-import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
-import org.jetbrains.kotlin.config.CompilerConfiguration
-import org.jetbrains.kotlin.config.CompilerConfigurationKey
-import org.jetbrains.kotlin.config.JVMConfigurationKeys
-import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
-import org.jetbrains.kotlin.java.model.internal.JeElementRegistry
-import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
-import java.io.File
-
-import org.jetbrains.kotlin.annotation.processing.AnnotationProcessingConfigurationKeys.ANNOTATION_PROCESSOR_CLASSPATH
-import org.jetbrains.kotlin.annotation.processing.AnnotationProcessingConfigurationKeys.APT_OPTIONS
-import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
-
-object AnnotationProcessingConfigurationKeys {
- val GENERATED_OUTPUT_DIR: CompilerConfigurationKey =
- CompilerConfigurationKey.create("generated files output directory")
-
- val CLASS_FILES_OUTPUT_DIR: CompilerConfigurationKey =
- CompilerConfigurationKey.create("class files output directory")
-
- val ANNOTATION_PROCESSOR_CLASSPATH: CompilerConfigurationKey> =
- CompilerConfigurationKey.create>("annotation processor classpath")
-
- val APT_OPTIONS: CompilerConfigurationKey> =
- CompilerConfigurationKey.create>("annotation processing options")
-
- val INCREMENTAL_DATA_FILE: CompilerConfigurationKey =
- CompilerConfigurationKey.create("data file for incremental compilation support")
-
- val VERBOSE_MODE: CompilerConfigurationKey =
- CompilerConfigurationKey.create("verbose mode")
-}
-
-class AnnotationProcessingCommandLineProcessor : CommandLineProcessor {
- companion object {
- val ANNOTATION_PROCESSING_COMPILER_PLUGIN_ID: String = "org.jetbrains.kotlin.kapt2"
-
- val GENERATED_OUTPUT_DIR_OPTION: CliOption =
- CliOption("generated", "", "Output path for the generated files", required = false)
-
- val CLASS_FILES_OUTPUT_DIR_OPTION: CliOption =
- CliOption("classes", "", "Output path for the class files", required = false)
-
- val ANNOTATION_PROCESSOR_CLASSPATH_OPTION: CliOption =
- CliOption("apclasspath", "", "Annotation processor classpath",
- required = false, allowMultipleOccurrences = true)
-
- val APT_OPTIONS_OPTION: CliOption =
- CliOption("apoption", ":", "Annotation processor option",
- required = false, allowMultipleOccurrences = true)
-
- val INCREMENTAL_DATA_FILE_OPTION: CliOption =
- CliOption("incrementalData", "", "Location of the incremental data file", required = false)
-
- val VERBOSE_MODE_OPTION: CliOption =
- CliOption("verbose", "true | false", "Enable verbose output", required = false)
- }
-
- override val pluginId: String = ANNOTATION_PROCESSING_COMPILER_PLUGIN_ID
-
- override val pluginOptions: Collection =
- listOf(GENERATED_OUTPUT_DIR_OPTION, ANNOTATION_PROCESSOR_CLASSPATH_OPTION, APT_OPTIONS_OPTION,
- CLASS_FILES_OUTPUT_DIR_OPTION, INCREMENTAL_DATA_FILE_OPTION, VERBOSE_MODE_OPTION)
-
- override fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration) {
- when (option) {
- ANNOTATION_PROCESSOR_CLASSPATH_OPTION -> configuration.appendList(ANNOTATION_PROCESSOR_CLASSPATH, value)
- APT_OPTIONS_OPTION -> configuration.appendList(APT_OPTIONS, value)
- GENERATED_OUTPUT_DIR_OPTION -> configuration.put(AnnotationProcessingConfigurationKeys.GENERATED_OUTPUT_DIR, value)
- CLASS_FILES_OUTPUT_DIR_OPTION -> configuration.put(AnnotationProcessingConfigurationKeys.CLASS_FILES_OUTPUT_DIR, value)
- INCREMENTAL_DATA_FILE_OPTION -> configuration.put(AnnotationProcessingConfigurationKeys.INCREMENTAL_DATA_FILE, value)
- VERBOSE_MODE_OPTION -> configuration.put(AnnotationProcessingConfigurationKeys.VERBOSE_MODE, value)
- else -> throw CliOptionProcessingException("Unknown option: ${option.name}")
- }
- }
-}
-
-class AnnotationProcessingComponentRegistrar : ComponentRegistrar {
- override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
- val generatedOutputDir = configuration.get(AnnotationProcessingConfigurationKeys.GENERATED_OUTPUT_DIR) ?: return
- val apClasspath = configuration.get(ANNOTATION_PROCESSOR_CLASSPATH)?.map(::File) ?: return
-
- val apOptions = (configuration.get(APT_OPTIONS) ?: listOf())
- .map { it.split(':') }
- .filter { it.size == 2 }
- .map { it[0] to it[1] }
- .toMap()
-
- val incrementalDataFile = configuration.get(AnnotationProcessingConfigurationKeys.INCREMENTAL_DATA_FILE)?.let(::File)
-
- val generatedOutputDirFile = File(generatedOutputDir)
- generatedOutputDirFile.mkdirs()
-
- val contentRoots = configuration[JVMConfigurationKeys.CONTENT_ROOTS] ?: emptyList()
-
- val compileClasspath = contentRoots.filterIsInstance().map { it.file }
- val classpath = apClasspath + compileClasspath
-
- val javaRoots = contentRoots.filterIsInstance().map { it.file }
-
- val classesOutputDir = File(configuration.get(AnnotationProcessingConfigurationKeys.CLASS_FILES_OUTPUT_DIR)
- ?: configuration[JVMConfigurationKeys.MODULES]!!.first().getOutputDirectory())
-
- val verboseOutput = configuration.get(AnnotationProcessingConfigurationKeys.VERBOSE_MODE) == "true"
-
- Extensions.getRootArea().getExtensionPoint(DefaultErrorMessages.Extension.EP_NAME)
- .registerExtension(DefaultErrorMessagesAnnotationProcessing())
-
- // Annotations with the "SOURCE" retention will be written to class files
- project.putUserData(IS_KAPT2_ENABLED_KEY, true)
-
- val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
-
- val annotationProcessingExtension = ClasspathBasedAnnotationProcessingExtension(
- classpath, apOptions, generatedOutputDirFile, classesOutputDir, javaRoots, verboseOutput,
- incrementalDataFile, messageCollector)
-
- project.registerService(JeElementRegistry::class.java, JeElementRegistry())
-
- AnalysisHandlerExtension.registerExtension(project, annotationProcessingExtension)
- }
-}
\ No newline at end of file
diff --git a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/RoundAnnotations.kt b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/RoundAnnotations.kt
deleted file mode 100644
index 92dc5e6429c..00000000000
--- a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/RoundAnnotations.kt
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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.annotation.processing
-
-import com.intellij.psi.*
-import com.intellij.psi.util.PsiTreeUtil
-import org.jetbrains.kotlin.asJava.findFacadeClass
-import org.jetbrains.kotlin.asJava.toLightClass
-import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
-import org.jetbrains.kotlin.java.model.internal.getAnnotationsWithInherited
-import org.jetbrains.kotlin.psi.KtClassOrObject
-import org.jetbrains.kotlin.psi.KtFile
-import org.jetbrains.kotlin.resolve.BindingContext
-
-internal class RoundAnnotations(
- val bindingContext: BindingContext,
- val typeMapper: KotlinTypeMapper
-) {
- private companion object {
- private val BLACKLISTED_ANNOTATATIONS = listOf(
- "java.lang.Deprecated", "kotlin.Deprecated", // Deprecated annotations
- "java.lang.annotation.", // Java annotations
- "org.jetbrains.annotations.", // Nullable/NotNull, ReadOnly, Mutable
- "kotlin.jvm.", "kotlin.Metadata" // Kotlin annotations from runtime
- )
- }
-
- private val mutableAnnotationsMap = mutableMapOf>()
- private val mutableAnalyzedClasses = mutableSetOf()
-
- val annotationsMap: Map>
- get() = mutableAnnotationsMap
-
- val analyzedClasses: Set
- get() = mutableAnalyzedClasses
-
- fun copy() = RoundAnnotations(bindingContext, typeMapper)
-
- fun analyzeFiles(files: Collection) = files.forEach { analyzeFile(it) }
-
- @JvmName("analyzePsiJavaFiles")
- fun analyzeFiles(files: Collection) = files.forEach { analyzeFile(it) }
-
- fun analyzeFile(file: KtFile) {
- val lightClass = file.findFacadeClass()
-
- if (lightClass != null) {
- analyzeDeclaration(lightClass)
- }
-
- for (declaration in file.declarations) {
- if (declaration !is KtClassOrObject) continue
- val clazz = declaration.toLightClass() ?: continue
- analyzeDeclaration(clazz)
- }
- }
-
- fun analyzeFile(file: PsiJavaFile) {
- file.classes.forEach { analyzeDeclaration(it) }
- }
-
- fun PsiElement.getTopLevelClassParent(): PsiClass? = when (this) {
- is PsiClass -> containingClass?.let { it.getTopLevelClassParent() } ?: this
- else -> PsiTreeUtil.getParentOfType(this, PsiClass::class.java, true)?.getTopLevelClassParent()
- }
-
- private val PsiAnnotation.hasSourceRetention: Boolean
- get() {
- val annotationDeclaration = nameReferenceElement?.resolve() as? PsiClass ?: return false
- val metaAnnotations = annotationDeclaration.modifierList?.annotations ?: return false
- return metaAnnotations.any { anno ->
- val declaration = anno.nameReferenceElement?.resolve() as? PsiClass ?: return@any false
- if (declaration.qualifiedName != "java.lang.annotation.Retention") return@any false
- val value = (anno.findAttributeValue("value") as? PsiReferenceExpression)?.resolve() ?: return@any false
- value is PsiEnumConstant && value.name == "SOURCE"
- }
- }
-
- fun analyzeDeclaration(declaration: PsiElement): Boolean {
- if (declaration !is PsiModifierListOwner) return false
-
- // Do not analyze classes twice (for incremental compilation data)
- if (declaration is PsiClass && declaration.qualifiedName in analyzedClasses) return false
-
- for (annotation in declaration.getAnnotationsWithInherited()) {
- val fqName = annotation.qualifiedName ?: continue
-
- if (BLACKLISTED_ANNOTATATIONS.any { fqName.startsWith(it) }) continue
- mutableAnnotationsMap.getOrPut(fqName, { mutableListOf() }).add(declaration)
-
- // Add only top-level classes
- val topLevelClassQualifiedName = declaration.getTopLevelClassParent()?.qualifiedName
- if (topLevelClassQualifiedName != null) {
- mutableAnalyzedClasses += topLevelClassQualifiedName
- }
- }
-
- if (declaration is PsiClass) {
- declaration.methods.forEach { analyzeDeclaration(it) }
- declaration.fields.forEach { analyzeDeclaration(it) }
- declaration.innerClasses.forEach { analyzeDeclaration(it) }
- }
-
- if (declaration is PsiMethod) {
- for (parameter in declaration.parameterList.parameters) {
- analyzeDeclaration(parameter)
- }
- }
-
- return true
- }
-}
\ No newline at end of file
diff --git a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/diagnostic/DefaultErrorMessagesAnnotationProcessing.kt b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/diagnostic/DefaultErrorMessagesAnnotationProcessing.kt
deleted file mode 100644
index 0837b57b7c7..00000000000
--- a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/diagnostic/DefaultErrorMessagesAnnotationProcessing.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.annotation.processing.diagnostic
-
-import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
-import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticFactoryToRendererMap
-
-class DefaultErrorMessagesAnnotationProcessing : DefaultErrorMessages.Extension {
-
- private companion object {
- val MAP = DiagnosticFactoryToRendererMap("AnnotationProcessing")
-
- init {
- MAP.put(ErrorsAnnotationProcessing.ANNOTATION_PROCESSING_ERROR,
- "Some error(s) occurred while processing annotations. Please see the error messages above.")
- }
- }
-
- override fun getMap() = MAP
-}
\ No newline at end of file
diff --git a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/diagnostic/ErrorsAnnotationProcessing.java b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/diagnostic/ErrorsAnnotationProcessing.java
deleted file mode 100644
index 5b3ff52a303..00000000000
--- a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/diagnostic/ErrorsAnnotationProcessing.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.annotation.processing.diagnostic;
-
-import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0;
-import org.jetbrains.kotlin.diagnostics.Errors;
-import org.jetbrains.kotlin.psi.KtElement;
-
-import static org.jetbrains.kotlin.diagnostics.Severity.ERROR;
-
-public interface ErrorsAnnotationProcessing {
- DiagnosticFactory0 ANNOTATION_PROCESSING_ERROR = DiagnosticFactory0.create(ERROR);
-
- @SuppressWarnings("UnusedDeclaration")
- Object _initializer = new Object() {
- {
- Errors.Initializer.initializeFactoryNames(ErrorsAnnotationProcessing.class);
- }
- };
-
-}
diff --git a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinElements.kt b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinElements.kt
deleted file mode 100644
index 6ecb554d9a0..00000000000
--- a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinElements.kt
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * 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.annotation.processing.impl
-
-import com.intellij.openapi.Disposable
-import com.intellij.psi.*
-import com.intellij.psi.search.GlobalSearchScope
-import com.intellij.psi.util.PsiSuperMethodUtil
-import com.intellij.psi.util.TypeConversionUtil
-import org.jetbrains.kotlin.java.model.JeAnnotationOwner
-import org.jetbrains.kotlin.java.model.JeElement
-import org.jetbrains.kotlin.java.model.JeName
-import org.jetbrains.kotlin.java.model.elements.JeAnnotationMirror
-import org.jetbrains.kotlin.java.model.elements.JeMethodExecutableElement
-import org.jetbrains.kotlin.java.model.elements.JePackageElement
-import org.jetbrains.kotlin.java.model.elements.JeTypeElement
-import org.jetbrains.kotlin.java.model.internal.getTypeWithTypeParameters
-import org.jetbrains.kotlin.java.model.util.disposeAll
-import org.jetbrains.kotlin.java.model.util.toDisposable
-import java.io.PrintWriter
-import java.io.Writer
-import javax.lang.model.element.*
-import javax.lang.model.util.Elements
-
-class KotlinElements(
- javaPsiFacade: JavaPsiFacade,
- scope: GlobalSearchScope
-) : Elements, Disposable {
- internal val javaPsiFacade = javaPsiFacade.toDisposable()
- internal val scope = scope.toDisposable()
-
- override fun dispose() = disposeAll(javaPsiFacade, scope)
-
- override fun hides(hider: Element, hidden: Element): Boolean {
- val hiderMethod = (hider as? JeMethodExecutableElement)?.psi ?: return false
- val hiddenMethod = (hidden as? JeMethodExecutableElement)?.psi ?: return false
-
- val hiderMethodClass = hiderMethod.containingClass ?: return false
- val hiddenMethodClass = hiddenMethod.containingClass ?: return false
-
- if (hiddenMethodClass.getTypeWithTypeParameters() !in hiderMethodClass.superTypes) return false
-
- return isSubSignature(hiderMethod, hiddenMethod)
- }
-
- override fun overrides(overrider: ExecutableElement, overridden: ExecutableElement, type: TypeElement): Boolean {
- overrider as? JeMethodExecutableElement ?: return false
- overridden as? JeMethodExecutableElement ?: return false
- type as? JeTypeElement ?: return false
-
- if (overrider.psi == overridden.psi) return false
-
- // if 'type' is a subtype of overrider's containing class
- if (type.psi.isSubclassOf(overridden.psi.containingClass) && type.psi.isSubclassOf(overrider.psi.containingClass)) {
- return isSubSignature(overrider.psi, overridden.psi)
- }
-
- return PsiSuperMethodUtil.isSuperMethod(overrider.psi, overridden.psi)
- }
-
- override fun getName(cs: CharSequence?) = JeName(cs?.toString())
-
- override fun getElementValuesWithDefaults(a: AnnotationMirror): Map {
- a as? JeAnnotationMirror ?: return emptyMap()
- return a.getAllElementValues()
- }
-
- override fun getBinaryName(type: TypeElement) = JeName((type as JeTypeElement).psi.qualifiedName)
-
- //TODO
- override fun getDocComment(e: Element?) = null
-
- override fun isDeprecated(e: Element?): Boolean {
- val deprecated = ((e as? JeElement)?.psi as? PsiDocCommentOwner)?.isDeprecated ?: false
- if (deprecated) return true
- return (e as? JeAnnotationOwner)?.psi?.modifierList?.findAnnotation("java.lang.Deprecated") != null
- }
-
- override fun getAllMembers(type: TypeElement) = (type as? JeTypeElement)?.getAllMembers() ?: emptyList()
-
- override fun printElements(w: Writer, vararg elements: Element) {
- val printWriter = PrintWriter(w)
- for (element in elements) {
- printWriter.println(element.simpleName.toString() + " (" + element::class.java.name + ")")
- }
- }
-
- override fun getPackageElement(name: CharSequence): PackageElement? {
- val psiPackage = javaPsiFacade().findPackage(name.toString()) ?: return null
- return JePackageElement(psiPackage)
- }
-
- override fun getTypeElement(name: CharSequence): TypeElement? {
- val psiClass = javaPsiFacade().findClass(name.toString(), scope()) ?: return null
- return JeTypeElement(psiClass)
- }
-
- override fun getConstantExpression(value: Any?) = Constants.format(value)
-
- override tailrec fun getPackageOf(element: Element): PackageElement? {
- if (element is PackageElement) return element
- val parent = element.enclosingElement ?: return null
- return getPackageOf(parent)
- }
-
- override fun getAllAnnotationMirrors(e: Element): List {
- val annotations = (e as? JeElement)?.annotationMirrors?.toMutableList() ?: mutableListOf()
-
- if (e is JeTypeElement) {
- var parent = e.psi.superClass
- while (parent != null) {
- val parentAnnotations = parent.modifierList?.annotations
- if (parentAnnotations == null) {
- parent = parent.superClass
- continue
- }
-
- for (parentAnnotation in parentAnnotations) {
- val annotationClass = parentAnnotation.nameReferenceElement?.resolve() as? PsiClass ?: continue
- annotationClass.modifierList?.findAnnotation("java.lang.annotation.Inherited") ?: continue
- annotations += JeAnnotationMirror(parentAnnotation)
- }
-
- parent = parent.superClass
- }
- }
-
- return annotations
- }
-
- override fun isFunctionalInterface(type: TypeElement): Boolean {
- val jeTypeElement = type as? JeTypeElement ?: return false
- if (!jeTypeElement.psi.isInterface) return false
- if (jeTypeElement.psi.allMethods.count { it.hasModifierProperty(PsiModifier.ABSTRACT) } != 1) return false
- return true
- }
-}
-
-private fun PsiClass.isSubclassOf(other: PsiClass?): Boolean {
- if (other == null) return false
- return TypeConversionUtil.isAssignable(other.getTypeWithTypeParameters(), this.getTypeWithTypeParameters(), false)
-}
-
-private fun isSubSignature(childMethod: PsiMethod, superMethod: PsiMethod): Boolean {
- if (childMethod.name != superMethod.name) return false
- if (childMethod.parameterList.parametersCount != superMethod.parameterList.parametersCount) return false
-
- if (childMethod.returnType != superMethod.returnType) return false
- for (i in 0..childMethod.parameterList.parametersCount - 1) {
- if (childMethod.parameterList.parameters[i].type != superMethod.parameterList.parameters[i].type) return false
- }
-
- return true
-}
-
-object Constants {
- fun format(value: Any?): String {
- return when (value) {
- is Byte -> formatByte((value as Byte?)!!)
- is Short -> formatShort((value as Short?)!!)
- is Long -> formatLong((value as Long?)!!)
- is Float -> formatFloat((value as Float?)!!)
- is Double -> formatDouble((value as Double?)!!)
- is Char -> formatChar(value)
- is String -> formatString(value)
- is Int, is Boolean -> value.toString()
- else -> throw IllegalArgumentException(
- "Argument is not a primitive type or a string; it " +
- (if (value == null) "is a null value." else "has class " + value::class.java.name) + ".")
- }
- }
-
- private fun formatByte(b: Byte) = String.format("(byte)0x%02x", b)
- private fun formatShort(s: Short) = String.format("(short)%d", s)
- private fun formatLong(lng: Long) = "${lng}L"
- private fun formatChar(c: Char) = '\'' + quote(c) + '\''
- private fun formatString(s: String) = '"' + quote(s) + '"'
-
- private fun formatFloat(f: Float): String = when {
- java.lang.Float.isNaN(f) -> "0.0f/0.0f"
- java.lang.Float.isInfinite(f) -> if (f < 0) "-1.0f/0.0f" else "1.0f/0.0f"
- else -> "${f}f"
- }
-
- private fun formatDouble(d: Double): String = when {
- java.lang.Double.isNaN(d) -> "0.0/0.0"
- java.lang.Double.isInfinite(d) -> if (d < 0) "-1.0/0.0" else "1.0/0.0"
- else -> d.toString()
- }
-
- fun quote(ch: Char): String = when (ch) {
- '\b' -> "\\b"
- '\n' -> "\\n"
- '\r' -> "\\r"
- '\t' -> "\\t"
- '\'' -> "\\'"
- '\"' -> "\\\""
- '\\' -> "\\\\"
- else -> if (isPrintableAscii(ch)) ch.toString() else String.format("\\u%04x", ch.toInt())
- }
-
- fun quote(s: String): String {
- val buf = StringBuilder()
- for (i in 0..s.length - 1) {
- buf.append(quote(s[i]))
- }
- return buf.toString()
- }
-
- private fun isPrintableAscii(ch: Char) = ch >= ' ' && ch <= '~'
-}
\ No newline at end of file
diff --git a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinFiler.kt b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinFiler.kt
deleted file mode 100644
index 4aee7f1af8e..00000000000
--- a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinFiler.kt
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.annotation.processing.impl
-
-import java.io.File
-import javax.annotation.processing.Filer
-import javax.lang.model.element.Element
-import javax.tools.FileObject
-import javax.tools.JavaFileManager
-import javax.tools.JavaFileObject
-import javax.tools.StandardLocation
-
-class KotlinFiler(
- val generatedSourceDir: File,
- val classesOutputDir: File,
- internal var onFileCreatedHandler: (File) -> Unit = {}
-) : Filer {
- private companion object {
- val PACKAGE_INFO_SUFFIX = ".packageInfo"
- }
-
- internal var wasAnythingGenerated: Boolean = false
- private set
-
- private fun getGeneratedFile(nameCharSequence: CharSequence, extension: String, baseDir: File = generatedSourceDir): Pair {
- val name = nameCharSequence.toString()
- val isPackageInfo = name.endsWith(PACKAGE_INFO_SUFFIX)
- val fqName = if (isPackageInfo) name.substring(0, PACKAGE_INFO_SUFFIX.length) else name
-
- val packageName = fqName.substringBeforeLast('.', "")
-
- val packageDir = if (packageName.isNotEmpty()) {
- File(baseDir, packageName.replace('.', '/')).apply { mkdirs() }
- }
- else {
- baseDir
- }
-
- val fileName = fqName.substringAfterLast('.') + (if (isPackageInfo) PACKAGE_INFO_SUFFIX else extension)
- val file = File(packageDir, fileName)
- return Pair(file, file.toRelativeString(baseDir))
- }
-
- private fun File.notifyCreated() = apply {
- wasAnythingGenerated = true
- onFileCreatedHandler(this)
- }
-
- override fun createSourceFile(name: CharSequence, vararg originatingElements: Element?): JavaFileObject {
- val (file, fileName) = getGeneratedFile(name, ".java")
- return KotlinJavaFileObject(file.notifyCreated(), fileName)
- }
-
- override fun getResource(location: JavaFileManager.Location, pkg: CharSequence, relativeName: CharSequence): FileObject? {
- val (file, fileName) = getResourceFile(location, pkg, relativeName)
- return KotlinFileObject(file, fileName)
- }
-
- override fun createResource(
- location: JavaFileManager.Location,
- pkg: CharSequence,
- relativeName: CharSequence,
- vararg originatingElements: Element?
- ): FileObject? {
- val (resourceFile, fileName) = getResourceFile(location, pkg, relativeName)
- resourceFile.parentFile.mkdirs()
- return KotlinFileObject(resourceFile.notifyCreated(), fileName)
- }
-
- private fun getResourceFile(location: JavaFileManager.Location, pkg: CharSequence, relativeName: CharSequence): Pair {
- val baseDir = when (location) {
- StandardLocation.CLASS_OUTPUT -> classesOutputDir
- StandardLocation.SOURCE_OUTPUT -> generatedSourceDir
- else -> throw IllegalArgumentException("Location is not supported: $location (${location.name})")
- }
-
- val targetDir = File(baseDir, pkg.toString().replace('.', '/'))
- targetDir.mkdirs()
-
- val resourceFile = File(targetDir, relativeName.toString())
- return Pair(resourceFile, resourceFile.toRelativeString(baseDir))
- }
-
- override fun createClassFile(name: CharSequence, vararg originatingElements: Element?): JavaFileObject {
- val (file, fileName) = getGeneratedFile(name, ".class")
- return KotlinJavaFileObject(file.notifyCreated(), fileName)
- }
-}
\ No newline at end of file
diff --git a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinJavaFileObject.kt b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinJavaFileObject.kt
deleted file mode 100644
index a8ae333e9b1..00000000000
--- a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinJavaFileObject.kt
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.annotation.processing.impl
-
-import java.io.File
-import javax.tools.FileObject
-import javax.tools.JavaFileObject
-
-class KotlinJavaFileObject(file: File, fileName: String) : KotlinAbstractFileObject(file, fileName), JavaFileObject {
- //TODO
- override fun isNameCompatible(simpleName: String, kind: JavaFileObject.Kind) = true
-
- override fun getKind() = when (file.extension) {
- "class" -> JavaFileObject.Kind.CLASS
- "java" -> JavaFileObject.Kind.SOURCE
- "html" -> JavaFileObject.Kind.HTML
- else -> JavaFileObject.Kind.OTHER
- }
-
- //TODO
- override fun getAccessLevel() = null
-
- //TODO
- override fun getNestingKind() = null
-}
-
-class KotlinFileObject(file: File, fileName: String) : KotlinAbstractFileObject(file, fileName)
-
-abstract class KotlinAbstractFileObject(val file: File, val fileName: String) : FileObject {
- override fun openOutputStream() = file.outputStream()
-
- override fun getName() = fileName
-
- override fun openWriter() = file.writer()
-
- override fun openInputStream() = file.inputStream()
-
- override fun getCharContent(ignoreEncodingErrors: Boolean) = file.readText()
-
- override fun getLastModified() = file.lastModified()
-
- override fun toUri() = file.toURI()
-
- override fun openReader(ignoreEncodingErrors: Boolean) = file.reader()
-
- override fun delete() = file.delete()
-}
\ No newline at end of file
diff --git a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinMessager.kt b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinMessager.kt
deleted file mode 100644
index b0a96631d73..00000000000
--- a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinMessager.kt
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.annotation.processing.impl
-
-import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
-import org.jetbrains.kotlin.cli.common.messages.MessageCollector
-import javax.annotation.processing.Messager
-import javax.lang.model.element.AnnotationMirror
-import javax.lang.model.element.AnnotationValue
-import javax.lang.model.element.Element
-import javax.tools.Diagnostic
-import javax.tools.Diagnostic.Kind
-
-class KotlinMessager(private val messageCollector: MessageCollector) : Messager {
- var errorCount: Int = 0
- private set
-
- var warningCount: Int = 0
- private set
-
- override fun printMessage(kind: Diagnostic.Kind, msg: CharSequence) = printMessage(kind, msg, null)
-
- override fun printMessage(kind: Diagnostic.Kind, msg: CharSequence, e: Element?) = printMessage(kind, msg, e, null)
-
- override fun printMessage(kind: Diagnostic.Kind, msg: CharSequence, e: Element?, a: AnnotationMirror?) {
- printMessage(kind, msg, e, a, null)
- }
-
- override fun printMessage(kind: Diagnostic.Kind, msg: CharSequence, e: Element?, a: AnnotationMirror?, v: AnnotationValue?) {
- val severity = when (kind) {
- Kind.ERROR -> {
- errorCount++
- CompilerMessageSeverity.ERROR
- }
- Kind.WARNING -> {
- warningCount++
- CompilerMessageSeverity.WARNING
- }
- Kind.MANDATORY_WARNING -> {
- warningCount++
- CompilerMessageSeverity.STRONG_WARNING
- }
- else -> CompilerMessageSeverity.LOGGING
- }
- messageCollector.report(severity, msg.toString())
- }
-}
diff --git a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinProcessingEnvironment.kt b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinProcessingEnvironment.kt
deleted file mode 100644
index e332ef78ace..00000000000
--- a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinProcessingEnvironment.kt
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.annotation.processing.impl
-
-import com.intellij.openapi.Disposable
-import com.intellij.openapi.components.ServiceManager
-import com.intellij.openapi.project.Project
-import com.intellij.psi.JavaPsiFacade
-import com.intellij.psi.PsiManager
-import com.intellij.psi.search.GlobalSearchScope
-import org.jetbrains.kotlin.java.model.internal.JeElementRegistry
-import org.jetbrains.kotlin.java.model.util.disposeAll
-import org.jetbrains.kotlin.java.model.util.toDisposable
-import org.jetbrains.kotlin.resolve.BindingContext
-import java.io.File
-import java.util.*
-import javax.annotation.processing.ProcessingEnvironment
-import javax.annotation.processing.Processor
-import javax.lang.model.SourceVersion
-
-class KotlinProcessingEnvironment(
- elements: KotlinElements,
- types: KotlinTypes,
- messager: KotlinMessager,
- options: Map,
- filer: KotlinFiler,
-
- processors: List,
-
- project: Project,
- psiManager: PsiManager,
- javaPsiFacade: JavaPsiFacade,
- projectScope: GlobalSearchScope,
- bindingContext: BindingContext,
- appendJavaSourceRootsHandler: (List) -> Unit
-) : ProcessingEnvironment, Disposable {
- private val elements = elements.toDisposable()
- private val types = types.toDisposable()
- private val messager = messager.toDisposable()
- private val filer = filer.toDisposable()
- internal val processors = processors.toDisposable()
-
- internal val project = project.toDisposable()
- internal val psiManager = psiManager.toDisposable()
- internal val javaPsiFacade = javaPsiFacade.toDisposable()
- internal val projectScope = projectScope.toDisposable()
- internal val bindingContext = bindingContext.toDisposable()
-
- private val registry = ServiceManager.getService(project, JeElementRegistry::class.java).toDisposable()
- internal val appendJavaSourceRootsHandler = appendJavaSourceRootsHandler.toDisposable()
- private val options = Collections.unmodifiableMap(options).toDisposable()
-
- override fun dispose() {
- types().dispose()
- elements().dispose()
- registry().dispose()
- disposeAll(elements, types, messager, filer, processors,
- project, psiManager, javaPsiFacade, projectScope, bindingContext,
- appendJavaSourceRootsHandler, options)
- }
-
- override fun getElementUtils() = elements()
- override fun getTypeUtils() = types()
- override fun getMessager() = messager()
- override fun getLocale() = Locale.getDefault()
- override fun getSourceVersion() = SourceVersion.RELEASE_8
- override fun getOptions() = options()
- override fun getFiler() = filer()
-}
\ No newline at end of file
diff --git a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinRoundEnvironment.kt b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinRoundEnvironment.kt
deleted file mode 100644
index b11a153b312..00000000000
--- a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinRoundEnvironment.kt
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.annotation.processing.impl
-
-import com.intellij.openapi.Disposable
-import org.jetbrains.kotlin.annotation.processing.RoundAnnotations
-import org.jetbrains.kotlin.java.model.toJeElement
-import org.jetbrains.kotlin.java.model.util.disposeAll
-import org.jetbrains.kotlin.java.model.util.toDisposable
-import javax.annotation.processing.RoundEnvironment
-import javax.lang.model.element.Element
-import javax.lang.model.element.TypeElement
-
-internal class KotlinRoundEnvironment(
- roundAnnotations: RoundAnnotations,
- private val isProcessingOver: Boolean,
- internal val roundNumber: Int
-) : RoundEnvironment, Disposable {
- val roundAnnotations = roundAnnotations.toDisposable()
-
- override fun dispose() = disposeAll(roundAnnotations)
-
- private var isError = false
-
- override fun getRootElements() = emptySet()
-
- override fun processingOver() = isProcessingOver
-
- private fun getElementsAnnotatedWith(fqName: String): Set {
- val declarations = roundAnnotations().annotationsMap[fqName] ?: return emptySet()
- return hashSetOf().apply {
- for (declaration in declarations) {
- declaration.toJeElement()?.let { add(it) }
- }
- }
- }
-
- override fun getElementsAnnotatedWith(a: TypeElement) = getElementsAnnotatedWith(a.qualifiedName.toString())
- override fun getElementsAnnotatedWith(a: Class) = getElementsAnnotatedWith(a.canonicalName)
-
- override fun errorRaised() = isError
-}
\ No newline at end of file
diff --git a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinTypes.kt b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinTypes.kt
deleted file mode 100644
index 6e6dc8e6728..00000000000
--- a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinTypes.kt
+++ /dev/null
@@ -1,315 +0,0 @@
-/*
- * 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.annotation.processing.impl
-
-import com.intellij.openapi.Disposable
-import com.intellij.psi.*
-import com.intellij.psi.search.GlobalSearchScope
-import com.intellij.psi.util.MethodSignatureUtil
-import com.intellij.psi.util.PsiTypesUtil
-import com.intellij.psi.util.TypeConversionUtil
-import org.jetbrains.kotlin.java.model.JeElement
-import org.jetbrains.kotlin.java.model.elements.*
-import org.jetbrains.kotlin.java.model.types.*
-import org.jetbrains.kotlin.java.model.util.disposeAll
-import org.jetbrains.kotlin.java.model.util.toDisposable
-import javax.lang.model.element.Element
-import javax.lang.model.element.TypeElement
-import javax.lang.model.type.*
-import javax.lang.model.util.Types
-
-class KotlinTypes(
- javaPsiFacade: JavaPsiFacade,
- psiManager: PsiManager,
- scope: GlobalSearchScope
-) : Types, Disposable {
- val javaPsiFacade = javaPsiFacade.toDisposable()
- val psiManager = psiManager.toDisposable()
- val scope = scope.toDisposable()
-
- override fun dispose() = disposeAll(javaPsiFacade, psiManager, scope)
-
- override fun contains(containing: TypeMirror, contained: TypeMirror): Boolean {
- assertKindNot(containing, TypeKind.PACKAGE, TypeKind.EXECUTABLE)
- assertKindNot(contained, TypeKind.PACKAGE, TypeKind.EXECUTABLE)
-
- assertJeType(containing); containing as JePsiType
- assertJeType(contained); contained as JePsiType
-
- fun L(type: PsiType): PsiType = when {
- type is PsiWildcardType && type.isSuper -> type.superBound
- else -> type
- }
-
- fun U(type: PsiType): PsiType = when {
- type is PsiWildcardType && type.isExtends -> type.extendsBound
- else -> type
- }
-
- return when (containing) {
- is JeArrayType, is JePrimitiveType -> containing == contained
- else -> {
- !GenericsUtil.checkNotInBounds(L(contained.psiType), L(containing.psiType), false)
- && !GenericsUtil.checkNotInBounds(U(contained.psiType), U(containing.psiType), false)
- }
- }
- }
-
- override fun getArrayType(componentType: TypeMirror): ArrayType {
- if (componentType is ExecutableType || componentType is NoType) error(componentType)
- assertJeType(componentType); componentType as JePsiType
-
- return JeArrayType(PsiArrayType(componentType.psiType), psiManager(), isRaw = false)
- }
-
- override fun isAssignable(t1: TypeMirror, t2: TypeMirror): Boolean {
- assertKindNot(t1, TypeKind.PACKAGE, TypeKind.EXECUTABLE, TypeKind.NONE)
- assertKindNot(t2, TypeKind.PACKAGE, TypeKind.EXECUTABLE, TypeKind.NONE)
-
- t1 as? JePsiType ?: return false
- t2 as? JePsiType ?: return false
- return t2.psiType.isAssignableFrom(t1.psiType)
- }
-
- override fun getNullType() = JeNullType
-
- override fun getWildcardType(extendsBound: TypeMirror?, superBound: TypeMirror?): JeWildcardType {
- if (extendsBound != null && superBound != null) {
- throw IllegalArgumentException("Both extendsBound and superBound should not be specified.")
- }
-
- if (extendsBound != null && extendsBound !is JePsiType) illegalArg("extendsBound should have PsiType")
- if (superBound != null && superBound !is JePsiType) illegalArg("superBound should have PsiType")
-
- return JeWildcardType(when {
- extendsBound != null -> PsiWildcardType.createExtends(psiManager(), (extendsBound as JePsiType).psiType)
- superBound != null -> PsiWildcardType.createSuper(psiManager(), (superBound as JePsiType).psiType)
- else -> PsiWildcardType.createUnbounded(psiManager())
- }, isRaw = false)
- }
-
- override fun unboxedType(t: TypeMirror): PrimitiveType? {
- fun error(): Nothing = throw IllegalArgumentException("This type could not be unboxed: $t")
- t as? JePsiType ?: error()
- val unboxedType = PsiPrimitiveType.getUnboxedType(t.psiType) ?: error()
- return unboxedType.toJePrimitiveType()
- }
-
- override fun getPrimitiveType(kind: TypeKind) = kind.toJePrimitiveType()
-
- override fun erasure(t: TypeMirror): TypeMirror {
- if (t.kind == TypeKind.PACKAGE) throw IllegalArgumentException("Invalid type: $t")
- return when (t) {
- is JeTypeVariableType -> TypeConversionUtil.typeParameterErasure(t.parameter).toJeType(t.psiManager, isRaw = true)
- is JePsiType -> TypeConversionUtil.erasure(t.psiType).toJeType(psiManager(), isRaw = true)
- is JeMethodExecutableTypeMirror -> {
- val oldSignature = t.signature
- val parameterTypes = oldSignature?.parameterTypes?.toList() ?: t.psi.parameterList.parameters.map { it.type }
- val newSignature = MethodSignatureUtil.createMethodSignature(
- oldSignature?.name ?: t.psi.name,
- parameterTypes.map { TypeConversionUtil.erasure(it) }.toTypedArray(),
- emptyArray(),
- PsiSubstitutor.EMPTY,
- oldSignature?.isConstructor ?: t.psi.isConstructor)
- JeMethodExecutableTypeMirror(
- t.psi, newSignature,
- TypeConversionUtil.erasure(t.returnType ?: t.psi.returnType), isRaw = true)
- }
- else -> t
- }
- }
-
- override fun directSupertypes(t: TypeMirror): List {
- if (t is NoType || t is ExecutableType) throw IllegalArgumentException("Invalid type: $t")
-
- val psiType = (t as? JePsiType)?.psiType as? PsiClassType ?: return emptyList()
- return psiType.superTypes.map { it.toJeType(psiManager()) }
- }
-
- override fun boxedClass(p: PrimitiveType): TypeElement? {
- p as? JePrimitiveType ?: throw IllegalArgumentException("Unknown type: $p")
- val boxedTypeName = p.psiType.boxedTypeName
- val boxedClass = javaPsiFacade().findClass(boxedTypeName, scope())
- ?: throw IllegalStateException("Can't find boxed class $boxedTypeName")
- return JeTypeElement(boxedClass)
- }
-
- override fun asElement(t: TypeMirror): Element? {
- if (t is JeDeclaredType) {
- return t.asElement()
- } else if (t is JeTypeVariableType) {
- return t.asElement()
- }
-
- return null
- }
-
- override fun isSubtype(t1: TypeMirror, t2: TypeMirror): Boolean {
- val psiType1 = (t1 as? JePsiType)?.psiType ?: return false
- val psiType2 = (t2 as? JePsiType)?.psiType ?: return false
-
- return TypeConversionUtil.isAssignable(psiType2, psiType1, false)
- }
-
- override fun isSameType(t1: TypeMirror, t2: TypeMirror) = t1 == t2
-
- override fun getNoType(kind: TypeKind) = when (kind) {
- TypeKind.VOID -> JeVoidType
- TypeKind.NONE -> JeNoneType
- else -> illegalArg("Must be kind of VOID or NONE, got ${kind.name}")
- }
-
- override fun getDeclaredType(typeElem: TypeElement, vararg typeArgMirrors: TypeMirror): DeclaredType {
- val psiClass = (typeElem as JeTypeElement).psi
- if (!psiClass.hasTypeParameters() && typeArgMirrors.size > 0) {
- throw IllegalArgumentException("$typeElem has not type parameters")
- }
-
- // Raw type
- if (psiClass.hasTypeParameters() && typeArgMirrors.isEmpty()) {
- return JeDeclaredType(PsiTypesUtil.getClassType(psiClass).rawType(), psiClass)
- }
-
- val typeParameters = psiClass.typeParameters
- if (typeArgMirrors.size != typeParameters.size) {
- throw IllegalArgumentException("$typeElem type parameters count: " +
- "${typeParameters.size}, received ${typeArgMirrors.size} args")
- }
-
- val typeArgs = typeArgMirrors.mapIndexed {
- i, t -> (t as? JePsiType)?.psiType ?: throw IllegalArgumentException("Invalid type argument #$i: $t")
- }
-
- val psiType = createImmediateClassType(psiClass, typeArgs) ?:
- throw IllegalStateException("Can't create declared type ($psiClass, $typeArgs)")
- return JeDeclaredType(psiType, psiClass)
- }
-
- override fun getDeclaredType(
- containing: DeclaredType?,
- typeElem: TypeElement,
- vararg typeArgMirrors: TypeMirror
- ): DeclaredType? {
- if (containing == null) {
- return getDeclaredType(typeElem, *typeArgMirrors)
- }
-
- val psiClass = (typeElem as JeTypeElement).psi
- if (psiClass.containingClass == null) {
- throw IllegalArgumentException("$typeElem is a top-level class element")
- }
-
- val containingType = (containing as? JePsiType)?.psiType as? PsiClassType
- ?: throw IllegalArgumentException("Illegal containing type: $containing")
- val containingClass = containingType.resolve()
- ?: throw IllegalArgumentException("Class type can't be resolved: $containing")
-
- if (psiClass.containingClass != containingClass) {
- throw IllegalArgumentException("$containing is not an enclosing element for $typeElem")
- }
-
- val typeArgs = typeArgMirrors.mapIndexed {
- i, t -> (t as? JePsiType)?.psiType ?: throw IllegalArgumentException("Invalid type argument #$i: $t")
- }
-
- val psiType = createImmediateClassType(psiClass, typeArgs) ?:
- throw IllegalStateException("Can't create declared type ($psiClass, $typeArgs)")
- return JeDeclaredType(psiType, psiClass, containing)
- }
-
- private fun Array.findSuperType(superTypeClass: PsiClass): PsiClassType? {
- for (supertype in this) {
- if (supertype is PsiClassType && supertype.resolve() == superTypeClass) return supertype
- supertype.superTypes.findSuperType(superTypeClass)?.let { return it }
- }
- return null
- }
-
- override fun asMemberOf(containing: DeclaredType, element: Element): TypeMirror {
- if (containing !is JeDeclaredType || element is JeClassInitializerExecutableElement) return element.asType()
- val containingType = containing.psiType
-
- val member = (element as JeElement).psi as? PsiMember ?: return element.asType()
-
- val memberOwnerClass = when (member) {
- is PsiTypeParameter -> member.owner as? PsiClass
- else -> member.containingClass
- } ?: return element.asType()
-
- val relevantSuperType = if (memberOwnerClass == containingType.resolve()) {
- containingType
- } else {
- containingType.superTypes.findSuperType(memberOwnerClass) ?: return element.asType()
- }
-
- val resolveResult = relevantSuperType.resolveGenerics()
- if (!resolveResult.isValidResult) return element.asType()
- val substitutor = resolveResult.substitutor
-
- return when (element) {
- is JeMethodExecutableElement -> {
- val method = element.psi
- val signature = method.getSignature(substitutor)
- val returnType = substitutor.substitute(element.psi.returnType)
- JeMethodExecutableTypeMirror(method, signature, returnType)
- }
- is JeVariableElement -> substitutor.substitute(element.psi.type).toJeType(psiManager())
- is JeTypeParameterElement -> substitutor.substitute(element.psi)?.toJeType(psiManager()) ?: element.asType()
- else -> throw IllegalArgumentException("Invalid element type: ${element::class.java.name} ($element)")
- }
- }
-
- override fun isSubsignature(t1: ExecutableType, t2: ExecutableType): Boolean {
- val m1 = (t1 as JeClassInitializerExecutableTypeMirror).psi
- val m2 = (t2 as JeClassInitializerExecutableTypeMirror).psi
-
- // No parameters
- if (m1 is PsiClassInitializer && m2 is PsiClassInitializer) return true
-
- if (m1 !is PsiMethod || m2 !is PsiMethod) return false
-
- if (m1.parameterList.parametersCount != m2.parameterList.parametersCount) return false
-
- for (i in 0..(m1.parameterList.parametersCount - 1)) {
- val p1 = m1.parameterList.parameters[i].type
- val p2 = m2.parameterList.parameters[i].type
-
- if (p1 != p2 && TypeConversionUtil.erasure(p1) != TypeConversionUtil.erasure(p2)) return false
- }
-
- return true
- }
-
- override fun capture(t: TypeMirror): TypeMirror? {
- TODO()
- }
-}
-
-private fun illegalArg(text: String? = null): Nothing {
- val message = if (text != null) ": $text" else ""
- throw IllegalArgumentException("Illegal argument" + message)
-}
-
-private fun assertKindNot(typeMirror: TypeMirror, vararg kinds: TypeKind): Unit {
- if (typeMirror.kind in kinds) illegalArg("type must not be kind of " + kinds.joinToString { it.name } + ", got ${typeMirror.kind.name}")
-}
-
-private fun assertJeType(type: TypeMirror) {
- if (type !is JeTypeMirror) {
- illegalArg("Must be a subclass of JePsiType, got ${type::class.java.name}")
- }
-}
\ No newline at end of file
diff --git a/plugins/annotation-processing/testData/elements/GetAllMembers.kt b/plugins/annotation-processing/testData/elements/GetAllMembers.kt
deleted file mode 100644
index f25f9608527..00000000000
--- a/plugins/annotation-processing/testData/elements/GetAllMembers.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-annotation class Anno
-
-@Anno
-class MyClass {
- var myProperty: String = "A"
-
- fun myFunction() = object : java.lang.Runnable {
- override fun run() {}
- }
-}
\ No newline at end of file
diff --git a/plugins/annotation-processing/testData/elements/GetElementValuesWithDefaults.kt b/plugins/annotation-processing/testData/elements/GetElementValuesWithDefaults.kt
deleted file mode 100644
index 8392d49f6ba..00000000000
--- a/plugins/annotation-processing/testData/elements/GetElementValuesWithDefaults.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-annotation class Anno(val name: String = "Mary", val age: Int = 20)
-
-@Anno("Tom", 10)
-class A
-
-@Anno(name = "Tom")
-class B
-
-@Anno(age = 10)
-class C
-
-@Anno
-class D
\ No newline at end of file
diff --git a/plugins/annotation-processing/testData/elements/GetPackageOf.kt b/plugins/annotation-processing/testData/elements/GetPackageOf.kt
deleted file mode 100644
index ca40c542457..00000000000
--- a/plugins/annotation-processing/testData/elements/GetPackageOf.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package test
-
-annotation class Anno
-
-@Anno
-class MyClass
-
-interface MyInterface
\ No newline at end of file
diff --git a/plugins/annotation-processing/testData/elements/IsDeprecated.kt b/plugins/annotation-processing/testData/elements/IsDeprecated.kt
deleted file mode 100644
index 5ae12b7b99c..00000000000
--- a/plugins/annotation-processing/testData/elements/IsDeprecated.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-annotation class Anno
-
-@Anno
-@Deprecated("")
-class Depr
-
-class NoDepr
-
-@java.lang.Deprecated
-class JavaDepr
\ No newline at end of file
diff --git a/plugins/annotation-processing/testData/elements/IsFunctionalInterface.kt b/plugins/annotation-processing/testData/elements/IsFunctionalInterface.kt
deleted file mode 100644
index 5e36530ebf7..00000000000
--- a/plugins/annotation-processing/testData/elements/IsFunctionalInterface.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-annotation class Anno
-
-@Anno
-class A {
- interface AA {
- fun onClick(o: Any)
- }
-}
-
-enum class B { RED }
-
-interface C {
- fun onClick()
-}
-
-interface D {
- fun onClick()
- fun onDoubleClick()
-}
-
-interface E : C
-
-interface F : C {
- fun onDoubleClick()
-}
\ No newline at end of file
diff --git a/plugins/annotation-processing/testData/elements/Overrides.kt b/plugins/annotation-processing/testData/elements/Overrides.kt
deleted file mode 100644
index 8a96cd7ba0d..00000000000
--- a/plugins/annotation-processing/testData/elements/Overrides.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-annotation class Anno
-
-@Anno
-open class Parent {
- open fun a() {}
-}
-
-open class Child : Parent() {
- override fun a() {}
- fun a(name: String) {}
- open fun b() = "A"
-}
-
-class ChildOfChild : Child() {
- override fun a() {}
- override fun b() = "B"
- fun a(name: CharSequence) {}
-}
\ No newline at end of file
diff --git a/plugins/annotation-processing/testData/elements/Overrides2.kt b/plugins/annotation-processing/testData/elements/Overrides2.kt
deleted file mode 100644
index 51ce8660843..00000000000
--- a/plugins/annotation-processing/testData/elements/Overrides2.kt
+++ /dev/null
@@ -1,14 +0,0 @@
-annotation class Anno
-
-@Anno
-interface Intf {
- fun a()
-}
-
-open class A {
- open fun a() {}
-}
-
-class B : A(), Intf {
- override fun a() {}
-}
\ No newline at end of file
diff --git a/plugins/annotation-processing/testData/processors/AsMemberOf.kt b/plugins/annotation-processing/testData/processors/AsMemberOf.kt
deleted file mode 100644
index 616b74c4baa..00000000000
--- a/plugins/annotation-processing/testData/processors/AsMemberOf.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-open class Base {
- @JvmField
- val f: T = null!!
-
- fun m(t: T): T = null!!
-}
-
-class Impl : Base() {
- fun implM(t: T): T = null!!
-}
-
-annotation class Anno
-
-@Anno
-class Test {
- val f = Impl()
-}
\ No newline at end of file
diff --git a/plugins/annotation-processing/testData/processors/AsMemberOfTypeParameters.kt b/plugins/annotation-processing/testData/processors/AsMemberOfTypeParameters.kt
deleted file mode 100644
index f249cc7e91f..00000000000
--- a/plugins/annotation-processing/testData/processors/AsMemberOfTypeParameters.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-annotation class Anno
-
-@Anno
-interface Intf
-
-open class Base : Intf {
- fun factory() = Base()
-}
-
-class Impl : Base()
\ No newline at end of file
diff --git a/plugins/annotation-processing/testData/processors/DefaultValueFromBinary.kt b/plugins/annotation-processing/testData/processors/DefaultValueFromBinary.kt
deleted file mode 100644
index 54e4ee6a8d1..00000000000
--- a/plugins/annotation-processing/testData/processors/DefaultValueFromBinary.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-// Some user annotation is required because annoations from kotlin.jvm are filtered out in kapt
-annotation class Anno
-
-@JvmSuppressWildcards
-@Anno
-class Test
-
-@JvmSuppressWildcards(suppress = true)
-class TestTrue
-
-@JvmSuppressWildcards(suppress = false)
-class TestFalse
\ No newline at end of file
diff --git a/plugins/annotation-processing/testData/processors/DoesNotRun.kt b/plugins/annotation-processing/testData/processors/DoesNotRun.kt
deleted file mode 100644
index f7e70c7b871..00000000000
--- a/plugins/annotation-processing/testData/processors/DoesNotRun.kt
+++ /dev/null
@@ -1 +0,0 @@
-class Test
\ No newline at end of file
diff --git a/plugins/annotation-processing/testData/processors/DoesNotRun2.kt b/plugins/annotation-processing/testData/processors/DoesNotRun2.kt
deleted file mode 100644
index 0eced4f6f64..00000000000
--- a/plugins/annotation-processing/testData/processors/DoesNotRun2.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-class Test
-
-annotation class Anno
\ No newline at end of file
diff --git a/plugins/annotation-processing/testData/processors/EnumArray.kt b/plugins/annotation-processing/testData/processors/EnumArray.kt
deleted file mode 100644
index ab6bea58fd4..00000000000
--- a/plugins/annotation-processing/testData/processors/EnumArray.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.jetbrains.kotlin.annotation.processing.test.processor
-
-enum class RGBColors { RED, GREEN, BLUE }
-annotation class ColorsAnnotation(val colors: Array)
-
-@ColorsAnnotation(colors = arrayOf(RGBColors.BLUE, RGBColors.RED))
-class Test
\ No newline at end of file
diff --git a/plugins/annotation-processing/testData/processors/Erasure2.kt b/plugins/annotation-processing/testData/processors/Erasure2.kt
deleted file mode 100644
index 296817b98e1..00000000000
--- a/plugins/annotation-processing/testData/processors/Erasure2.kt
+++ /dev/null
@@ -1,23 +0,0 @@
-abstract class Base {
- fun baseF(): A = null!!
-}
-
-annotation class Anno
-
-@Anno
-class Test : Base() {
- fun a(): String = ""
- fun b(i: String, b: CharSequence) {}
- fun c(): Int = 5
- fun d(): T = null!!
- fun e(item: D): D = item
- fun f(items: List