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>, i: Int) {} - fun g(item: D) {} - fun h(): Array> = null!! - fun i(): T where T : CharSequence, T : Appendable = null!! -} - -class Test2, out B : List> { - fun a(items: A) {} - fun b(): B = null!! -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/ErasureSimple.kt b/plugins/annotation-processing/testData/processors/ErasureSimple.kt deleted file mode 100644 index 3173669eabb..00000000000 --- a/plugins/annotation-processing/testData/processors/ErasureSimple.kt +++ /dev/null @@ -1,7 +0,0 @@ -annotation class Anno - -@Anno -class Test { - fun a(): Int = 5 - fun b(): Unit {} -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/IncrementalDataSimple.kt b/plugins/annotation-processing/testData/processors/IncrementalDataSimple.kt deleted file mode 100644 index d52bb8a4c4d..00000000000 --- a/plugins/annotation-processing/testData/processors/IncrementalDataSimple.kt +++ /dev/null @@ -1,44 +0,0 @@ -annotation class Anno - -@Anno -class Test - -@Anno -interface Intf - -class Test2 { - @Anno - fun test2Fun() {} -} - -class Test3 { - @Anno - class Test3Nested - - @Anno - inner class Test3Inner -} - -class Test4 - -class Test5 { - fun test5Fun() {} -} - -annotation class Surprise - -@Surprise -class Test6 - -class Test7 { - @Surprise - fun test7Fun(): String = "ABC" -} - -class Test8 { - @Anno - fun test8Fun1() {} - - @Anno - fun test8Fun2() {} -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/InheritedAnnotations.kt b/plugins/annotation-processing/testData/processors/InheritedAnnotations.kt deleted file mode 100644 index a4ea0cb51ee..00000000000 --- a/plugins/annotation-processing/testData/processors/InheritedAnnotations.kt +++ /dev/null @@ -1,12 +0,0 @@ -@java.lang.annotation.Inherited -annotation class Anno - -@Anno -open class Base - -class Impl : Base() - -@Anno -interface Intf - -class IntfImpl : Intf \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/InheritedAnnotationsOverridden.kt b/plugins/annotation-processing/testData/processors/InheritedAnnotationsOverridden.kt deleted file mode 100644 index 61595a3a811..00000000000 --- a/plugins/annotation-processing/testData/processors/InheritedAnnotationsOverridden.kt +++ /dev/null @@ -1,9 +0,0 @@ -@Repeatable -@java.lang.annotation.Inherited -annotation class Anno(val name: String) - -@Anno("Mary") -open class Base - -@Anno("Tom") -class Impl : Base() \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/KotlinAnnotations.kt b/plugins/annotation-processing/testData/processors/KotlinAnnotations.kt deleted file mode 100644 index 2cee342a12e..00000000000 --- a/plugins/annotation-processing/testData/processors/KotlinAnnotations.kt +++ /dev/null @@ -1,25 +0,0 @@ -annotation class Anno - -@Anno -class AnnoAnnotated - -class Test { - @kotlin.jvm.Transient - val f: String = "" - - // explicitly - @org.jetbrains.annotations.NotNull - fun a() {} - - @kotlin.jvm.Synchronized - fun b() {} - - @kotlin.jvm.JvmOverloads - fun c(a: Int = 3, b: String = "") {} - - @java.lang.Deprecated - fun d() {} - - @kotlin.Deprecated("") - fun e() {} -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/MapMutableMap.kt b/plugins/annotation-processing/testData/processors/MapMutableMap.kt deleted file mode 100644 index 28bf97ac033..00000000000 --- a/plugins/annotation-processing/testData/processors/MapMutableMap.kt +++ /dev/null @@ -1,12 +0,0 @@ -annotation class Anno - -interface Intf - -@Anno -class Test { - fun a(map: Map) {} - fun b(map: MutableMap) {} - - fun c(map: Map) {} - fun d(map: MutableMap) {} -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/Nested.kt b/plugins/annotation-processing/testData/processors/Nested.kt deleted file mode 100644 index 55feac868b4..00000000000 --- a/plugins/annotation-processing/testData/processors/Nested.kt +++ /dev/null @@ -1,7 +0,0 @@ -import kotlin.reflect.KClass - -annotation class Anno(val a: Anno2, val b: Array, val c: String, val d: KClass<*>, val e: Array>) -annotation class Anno2(val name: String) - -@Anno(a = Anno2("Tim"), b = arrayOf(Anno2("Kate"), Anno2("Mary")), c = "ABC", d = Anno2::class, e = arrayOf(Anno::class)) -class Test \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/SeveralAnnotations.kt b/plugins/annotation-processing/testData/processors/SeveralAnnotations.kt deleted file mode 100644 index d7649390ebd..00000000000 --- a/plugins/annotation-processing/testData/processors/SeveralAnnotations.kt +++ /dev/null @@ -1,11 +0,0 @@ - -@Name("Mary") -@Age(18) -class Mary - -@Name("Kate") -@Age(22) -class Kate - -annotation class Name(val name: String) -annotation class Age(val age: Int) \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/Simple.kt b/plugins/annotation-processing/testData/processors/Simple.kt deleted file mode 100644 index 19a6070bf17..00000000000 --- a/plugins/annotation-processing/testData/processors/Simple.kt +++ /dev/null @@ -1,10 +0,0 @@ -annotation class Anno(val name: String) - -@Anno("MyClassAnno") -class MyClass { - @Anno("myFuncAnno") - fun myFunc(): String = "Mary" - - @field:Anno("myFieldAnno") - val myField: String = "Tom" -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/SourceRetention.kt b/plugins/annotation-processing/testData/processors/SourceRetention.kt deleted file mode 100644 index fc396566c4f..00000000000 --- a/plugins/annotation-processing/testData/processors/SourceRetention.kt +++ /dev/null @@ -1,42 +0,0 @@ -@Retention(AnnotationRetention.SOURCE) -annotation class Source1 - -@Retention(AnnotationRetention.SOURCE) -annotation class Source2 - -@Retention(AnnotationRetention.SOURCE) -annotation class Source3 - -@Retention(AnnotationRetention.SOURCE) -annotation class Source4 - -@Retention(AnnotationRetention.BINARY) -annotation class Binary - -@Retention(AnnotationRetention.RUNTIME) -annotation class Runtime - -@Source1 -class Test - -class Test2 { - @Source2 - fun t() {} -} - -class Test3 { - @field:Source3 - val p: String = "A" -} - -class Test4 { - fun t(@Source4 a: String) {} -} - -class Test5 { - @Retention(AnnotationRetention.SOURCE) - annotation class Source5 - - @Source5 - fun t() {} -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/Star.kt b/plugins/annotation-processing/testData/processors/Star.kt deleted file mode 100644 index 8a3e7756f0b..00000000000 --- a/plugins/annotation-processing/testData/processors/Star.kt +++ /dev/null @@ -1,4 +0,0 @@ -@Anno -class MyClass - -annotation class Anno \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/Star3.kt b/plugins/annotation-processing/testData/processors/Star3.kt deleted file mode 100644 index 3fdcd9aa6e9..00000000000 --- a/plugins/annotation-processing/testData/processors/Star3.kt +++ /dev/null @@ -1,5 +0,0 @@ -@Anno2 -class MyClass - -annotation class Anno -annotation class Anno2 \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/StringArray.kt b/plugins/annotation-processing/testData/processors/StringArray.kt deleted file mode 100644 index afac1d3f65e..00000000000 --- a/plugins/annotation-processing/testData/processors/StringArray.kt +++ /dev/null @@ -1,2 +0,0 @@ -@Suppress("Tom", "Mary") -class Test \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/TypeArguments.kt b/plugins/annotation-processing/testData/processors/TypeArguments.kt deleted file mode 100644 index 43bf6bf997e..00000000000 --- a/plugins/annotation-processing/testData/processors/TypeArguments.kt +++ /dev/null @@ -1,8 +0,0 @@ -annotation class Anno - -@Anno -class A : B(), C - -open class B - -interface C {} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/processors/TypeArguments2.kt b/plugins/annotation-processing/testData/processors/TypeArguments2.kt deleted file mode 100644 index 26b5d64c46d..00000000000 --- a/plugins/annotation-processing/testData/processors/TypeArguments2.kt +++ /dev/null @@ -1,17 +0,0 @@ -interface I - -abstract class A : I - -annotation class Anno - -@Anno -class B : A() - -class C : A() - -interface I2 -open class B2 -class A2 : B2(), I2 - -interface I3 -class A3 : I3> \ No newline at end of file diff --git a/plugins/annotation-processing/testData/sourceRetention/withSource.kt b/plugins/annotation-processing/testData/sourceRetention/withSource.kt deleted file mode 100644 index c4a917d64e0..00000000000 --- a/plugins/annotation-processing/testData/sourceRetention/withSource.kt +++ /dev/null @@ -1,15 +0,0 @@ -// Same as withoutSource.kt - -@Retention(AnnotationRetention.SOURCE) -annotation class SourceAnno - -@Retention(AnnotationRetention.BINARY) -annotation class BinaryAnno - -@Retention(AnnotationRetention.RUNTIME) -annotation class RuntimeAnno - -@SourceAnno -@BinaryAnno -@RuntimeAnno -class Test \ No newline at end of file diff --git a/plugins/annotation-processing/testData/sourceRetention/withSource.txt b/plugins/annotation-processing/testData/sourceRetention/withSource.txt deleted file mode 100644 index 5046723ba8d..00000000000 --- a/plugins/annotation-processing/testData/sourceRetention/withSource.txt +++ /dev/null @@ -1,22 +0,0 @@ -@kotlin.annotation.Retention -@java.lang.annotation.Retention -@kotlin.Metadata -public annotation class BinaryAnno - -@kotlin.annotation.Retention -@java.lang.annotation.Retention -@kotlin.Metadata -public annotation class RuntimeAnno - -@kotlin.annotation.Retention -@java.lang.annotation.Retention -@kotlin.Metadata -public annotation class SourceAnno - -@RuntimeAnno -@kotlin.Metadata -@SourceAnno -@BinaryAnno -public final class Test { - public method (): void -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/sourceRetention/withoutSource.kt b/plugins/annotation-processing/testData/sourceRetention/withoutSource.kt deleted file mode 100644 index 8a42e91e835..00000000000 --- a/plugins/annotation-processing/testData/sourceRetention/withoutSource.kt +++ /dev/null @@ -1,15 +0,0 @@ -// Same as withSource.kt - -@Retention(AnnotationRetention.SOURCE) -annotation class SourceAnno - -@Retention(AnnotationRetention.BINARY) -annotation class BinaryAnno - -@Retention(AnnotationRetention.RUNTIME) -annotation class RuntimeAnno - -@SourceAnno -@BinaryAnno -@RuntimeAnno -class Test \ No newline at end of file diff --git a/plugins/annotation-processing/testData/sourceRetention/withoutSource.txt b/plugins/annotation-processing/testData/sourceRetention/withoutSource.txt deleted file mode 100644 index 2b9ada9f9de..00000000000 --- a/plugins/annotation-processing/testData/sourceRetention/withoutSource.txt +++ /dev/null @@ -1,21 +0,0 @@ -@kotlin.annotation.Retention -@java.lang.annotation.Retention -@kotlin.Metadata -public annotation class BinaryAnno - -@kotlin.annotation.Retention -@java.lang.annotation.Retention -@kotlin.Metadata -public annotation class RuntimeAnno - -@kotlin.annotation.Retention -@java.lang.annotation.Retention -@kotlin.Metadata -public annotation class SourceAnno - -@RuntimeAnno -@kotlin.Metadata -@BinaryAnno -public final class Test { - public method (): void -} diff --git a/plugins/annotation-processing/testData/withFiler/MethodsFields.kt b/plugins/annotation-processing/testData/withFiler/MethodsFields.kt deleted file mode 100644 index f2fa6ffab92..00000000000 --- a/plugins/annotation-processing/testData/withFiler/MethodsFields.kt +++ /dev/null @@ -1,9 +0,0 @@ -annotation class Inject - -class Test { - @Inject - fun myFunc(): String = "Mary" - - @field:Inject - val myField: String = "Tom" -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/withFiler/OneRound.kt b/plugins/annotation-processing/testData/withFiler/OneRound.kt deleted file mode 100644 index 420ce4dd24e..00000000000 --- a/plugins/annotation-processing/testData/withFiler/OneRound.kt +++ /dev/null @@ -1,9 +0,0 @@ -annotation class Inject -annotation class Inject2 - -@Inject2 -class Test { - @Inject - @Inject2 - fun myFunc(): String = "Mary" -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/withFiler/Simple.kt b/plugins/annotation-processing/testData/withFiler/Simple.kt deleted file mode 100644 index 1f930a90a10..00000000000 --- a/plugins/annotation-processing/testData/withFiler/Simple.kt +++ /dev/null @@ -1,4 +0,0 @@ -annotation class Inject2 - -@Inject2 -class Test \ No newline at end of file diff --git a/plugins/annotation-processing/testData/withFiler/TwoRounds.kt b/plugins/annotation-processing/testData/withFiler/TwoRounds.kt deleted file mode 100644 index cde0a2101c3..00000000000 --- a/plugins/annotation-processing/testData/withFiler/TwoRounds.kt +++ /dev/null @@ -1,8 +0,0 @@ -annotation class Inject -annotation class Inject2 - -@Inject -class Test { - @Inject - fun myFunc(): String = "Mary" -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/withFiler/ZeroRounds.kt b/plugins/annotation-processing/testData/withFiler/ZeroRounds.kt deleted file mode 100644 index f7e70c7b871..00000000000 --- a/plugins/annotation-processing/testData/withFiler/ZeroRounds.kt +++ /dev/null @@ -1 +0,0 @@ -class Test \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/javaWrappers/EnumClass.kt b/plugins/annotation-processing/testData/wrappers/javaWrappers/EnumClass.kt deleted file mode 100644 index 52c46914f47..00000000000 --- a/plugins/annotation-processing/testData/wrappers/javaWrappers/EnumClass.kt +++ /dev/null @@ -1,17 +0,0 @@ -// FQNAME: EnumClass - -// FILE: EnumClass.java -enum EnumClass { - RED, GREEN, BLUE; - - void someMethod() { - System.out.println("Hello, world!") - } - - String getStringRepresentation() { - return this.toString(); - } -} - -// FILE: Anno.kt -annotation class Anno \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/javaWrappers/EnumClass.txt b/plugins/annotation-processing/testData/wrappers/javaWrappers/EnumClass.txt deleted file mode 100644 index 75d4b9ef917..00000000000 --- a/plugins/annotation-processing/testData/wrappers/javaWrappers/EnumClass.txt +++ /dev/null @@ -1,11 +0,0 @@ -final enum EnumClass { - public static final EnumClass RED - - public static final EnumClass GREEN - - public static final EnumClass BLUE - - void someMethod() - - java.lang.String getStringRepresentation() -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/javaWrappers/MetaAnnotation.kt b/plugins/annotation-processing/testData/wrappers/javaWrappers/MetaAnnotation.kt deleted file mode 100644 index b43f5e671b7..00000000000 --- a/plugins/annotation-processing/testData/wrappers/javaWrappers/MetaAnnotation.kt +++ /dev/null @@ -1,17 +0,0 @@ -// FQNAME: MetaAnnotation - -// FILE: MetaAnnotation.java -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Deprecated -@Target({ ElementType.CONSTRUCTOR, ElementType.FIELD }) -@Retention(RetentionPolicy.RUNTIME) -public @interface MetaAnnotation { - String strValue(); -} - -// FILE: Anno.kt -annotation class Anno \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/javaWrappers/MetaAnnotation.txt b/plugins/annotation-processing/testData/wrappers/javaWrappers/MetaAnnotation.txt deleted file mode 100644 index 653e513877d..00000000000 --- a/plugins/annotation-processing/testData/wrappers/javaWrappers/MetaAnnotation.txt +++ /dev/null @@ -1,6 +0,0 @@ -@java.lang.Deprecated -@java.lang.annotation.Target(value = { CONSTRUCTOR, FIELD }) -@java.lang.annotation.Retention(value = RUNTIME) -public abstract @interface MetaAnnotation { - public abstract java.lang.String strValue() -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/javaWrappers/Simple.kt b/plugins/annotation-processing/testData/wrappers/javaWrappers/Simple.kt deleted file mode 100644 index 60b6c437cf3..00000000000 --- a/plugins/annotation-processing/testData/wrappers/javaWrappers/Simple.kt +++ /dev/null @@ -1,36 +0,0 @@ -// FQNAME: Simple - -// FILE: Simple.java -@interface Anno { - String[] numbers(); -} - -@interface AnnoValue { - String[] value(); -} - -@KotlinAnnotation(a = "A", b = 5) -@Anno(numbers = { "five", "six" }) -@AnnoValue({ "five", "six" }) -public abstract class Simple { - @Anno(numbers = "seven") - @AnnoValue("seven") - final String field = "A"; - - abstract void voidMethod(); - - static { - System.out.println("A"); - } - - { - System.out.println("b"); - } - - protected String strMethod(int param) { - return "A"; - } -} - -// FILE: KotlinAnnotation.kt -annotation class KotlinAnnotation(val a: String, val b: Int) \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/javaWrappers/Simple.txt b/plugins/annotation-processing/testData/wrappers/javaWrappers/Simple.txt deleted file mode 100644 index c7215571bb8..00000000000 --- a/plugins/annotation-processing/testData/wrappers/javaWrappers/Simple.txt +++ /dev/null @@ -1,18 +0,0 @@ -@KotlinAnnotation(a = "A", b = 5) -@Anno(numbers = { "five", "six" }) -@AnnoValue(value = { "five", "six" }) -public abstract class Simple { - static {} - - {} - - @Anno(numbers = { "seven" }) - @AnnoValue(value = { "seven" }) - final java.lang.String field - - abstract void voidMethod() - - protected java.lang.String strMethod(int param) - - public void () -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/javaWrappers/WithNested.kt b/plugins/annotation-processing/testData/wrappers/javaWrappers/WithNested.kt deleted file mode 100644 index 37a65e82256..00000000000 --- a/plugins/annotation-processing/testData/wrappers/javaWrappers/WithNested.kt +++ /dev/null @@ -1,25 +0,0 @@ -// FQNAME: WithNested - -// FILE: WithNested.java -class WithNested { - void myClassFun() {} - - static class NestedClass { - void nestedClassFun() {} - } - - class InnerClass { - void innerClassFun() {} - - class InnerInnerClass { - void innerInnerClassFun() {} - } - } - - interface NestedInterface { - void nestedInterfaceFun() {} - } -} - -// FILE: Anno.kt -annotation class Anno \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/javaWrappers/WithNested.txt b/plugins/annotation-processing/testData/wrappers/javaWrappers/WithNested.txt deleted file mode 100644 index 45cfca8574f..00000000000 --- a/plugins/annotation-processing/testData/wrappers/javaWrappers/WithNested.txt +++ /dev/null @@ -1,27 +0,0 @@ -class WithNested { - void myClassFun() - - static class NestedClass { - void nestedClassFun() - - void () - } - - class InnerClass { - void innerClassFun() - - class InnerInnerClass { - void innerInnerClassFun() - - void (WithNested.InnerClass $instance) - } - - void (WithNested $instance) - } - - static abstract interface NestedInterface { - public abstract void nestedInterfaceFun() - } - - void () -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/annotations.kt b/plugins/annotation-processing/testData/wrappers/kotlinWrappers/annotations.kt deleted file mode 100644 index 720ad0e66d6..00000000000 --- a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/annotations.kt +++ /dev/null @@ -1,33 +0,0 @@ -// FQNAME: test.Main - -package test - -import kotlin.reflect.KClass - -@MainAnno("A", 5) -class Main { - @field:XAnno(color = Color.GREEN) - val x: String = "" - - @get:YAnno(arrayOf("Mary", "Tom"), intArrayOf(1, 3, 5), arrayOf(Color.GREEN, Color.RED)) - val y: String = "" - - @set:ZAnno(String::class, arrayOf(String::class, Long::class, Main::class)) - var z: String = "" - - // Property annotations are lost here (we don't create Elements (javac API) for the synthetic propertyName$annotations() methods) - @MainAnno("B", 6) - val zz: String = "" -} - -enum class Color { - RED, GREEN, BLUE -} - -annotation class MainAnno(val a: String, val b: Int) - -annotation class XAnno(val color: Color) - -annotation class YAnno(val names: Array, val ints: IntArray, val colors: Array) - -annotation class ZAnno(val clazz: KClass<*>, val classes: Array>) \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/annotations.txt b/plugins/annotation-processing/testData/wrappers/kotlinWrappers/annotations.txt deleted file mode 100644 index f8eb0aa57f6..00000000000 --- a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/annotations.txt +++ /dev/null @@ -1,33 +0,0 @@ -@test.MainAnno(a = "A", b = 5) -public final class Main { - @test.XAnno(color = GREEN) - @org.jetbrains.annotations.NotNull - private final java.lang.String x - - @org.jetbrains.annotations.NotNull - private final java.lang.String y - - @org.jetbrains.annotations.NotNull - private java.lang.String z - - @org.jetbrains.annotations.NotNull - private final java.lang.String zz - - @org.jetbrains.annotations.NotNull - public final java.lang.String getX() - - @test.YAnno(names = { "Mary", "Tom" }, ints = { 1, 3, 5 }, colors = { GREEN, RED }) - @org.jetbrains.annotations.NotNull - public final java.lang.String getY() - - @org.jetbrains.annotations.NotNull - public final java.lang.String getZ() - - @test.ZAnno(clazz = java.lang.String.class, classes = { java.lang.String.class, long.class, test.Main.class }) - public final void setZ(java.lang.String p) - - @org.jetbrains.annotations.NotNull - public final java.lang.String getZz() - - public void () -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/enum.kt b/plugins/annotation-processing/testData/wrappers/kotlinWrappers/enum.kt deleted file mode 100644 index 8cd46537f5d..00000000000 --- a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/enum.kt +++ /dev/null @@ -1,11 +0,0 @@ -// FQNAME: EnumClass - -enum class EnumClass { - RED, GREEN, BLUE; - - fun someFun() { - System.out.println("Hello, world!") - } - - fun stringRepresentation() = this.toString() -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/enum.txt b/plugins/annotation-processing/testData/wrappers/kotlinWrappers/enum.txt deleted file mode 100644 index 449b5b0641b..00000000000 --- a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/enum.txt +++ /dev/null @@ -1,14 +0,0 @@ -public enum EnumClass { - public static final EnumClass RED - - public static final EnumClass GREEN - - public static final EnumClass BLUE - - public final void someFun() - - @org.jetbrains.annotations.NotNull - public final java.lang.String stringRepresentation() - - protected void () -} diff --git a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/kotlinAnnotations.kt b/plugins/annotation-processing/testData/wrappers/kotlinWrappers/kotlinAnnotations.kt deleted file mode 100644 index 4dede841b0b..00000000000 --- a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/kotlinAnnotations.kt +++ /dev/null @@ -1,22 +0,0 @@ -// FQNAME: Test - -class Test { - @kotlin.jvm.Transient - val f: String = "" - - // explicitly - @org.jetbrains.annotations.NotNull - fun a() {} - - @kotlin.jvm.Synchronized - fun b() {} - - @kotlin.jvm.JvmOverloads - fun c(a: Int = 3, b: String = "") {} - - @java.lang.Deprecated - fun d() {} - - @kotlin.Deprecated("") - fun e() {} -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/kotlinAnnotations.txt b/plugins/annotation-processing/testData/wrappers/kotlinWrappers/kotlinAnnotations.txt deleted file mode 100644 index 39a3e2df9f7..00000000000 --- a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/kotlinAnnotations.txt +++ /dev/null @@ -1,32 +0,0 @@ -public final class Test { - @kotlin.jvm.Transient - @org.jetbrains.annotations.NotNull - private final transient java.lang.String f - - @org.jetbrains.annotations.NotNull - public final java.lang.String getF() - - @org.jetbrains.annotations.NotNull - @org.jetbrains.annotations.NotNull - public final void a() - - @kotlin.jvm.Synchronized - public final synchronized void b() - - @kotlin.jvm.JvmOverloads - public final void c(int a, java.lang.String b) - - @kotlin.jvm.JvmOverloads - public final void c(int a) - - @kotlin.jvm.JvmOverloads - public final void c() - - @java.lang.Deprecated - public final void d() - - @kotlin.Deprecated(message = "") - public final void e() - - public void () -} diff --git a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/metaAnnotations.kt b/plugins/annotation-processing/testData/wrappers/kotlinWrappers/metaAnnotations.kt deleted file mode 100644 index fa5e50b9546..00000000000 --- a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/metaAnnotations.kt +++ /dev/null @@ -1,7 +0,0 @@ -// FQNAME: Anno - -@Repeatable -@Deprecated("") -@Retention(AnnotationRetention.RUNTIME) -@Target(AnnotationTarget.CLASS, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.EXPRESSION) -annotation class Anno \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/metaAnnotations.txt b/plugins/annotation-processing/testData/wrappers/kotlinWrappers/metaAnnotations.txt deleted file mode 100644 index 16b7578067a..00000000000 --- a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/metaAnnotations.txt +++ /dev/null @@ -1,9 +0,0 @@ -@kotlin.annotation.Repeatable -@kotlin.Deprecated(message = "") -@kotlin.annotation.Retention(value = RUNTIME) -@kotlin.annotation.Target(allowedTargets = { CLASS, CONSTRUCTOR, EXPRESSION }) -@java.lang.annotation.Retention(value = RUNTIME) -@java.lang.annotation.Target(value = { TYPE, CONSTRUCTOR }) -public abstract @interface Anno { - -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/nestedClasses.kt b/plugins/annotation-processing/testData/wrappers/kotlinWrappers/nestedClasses.kt deleted file mode 100644 index 2bc666def8b..00000000000 --- a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/nestedClasses.kt +++ /dev/null @@ -1,30 +0,0 @@ -// FQNAME: MyClass - -class MyClass { - companion object { - val CONST = 2 - } - - fun myClassFun() {} - - class NestedClass { - companion object A { - val CONSTA = 3 - } - - fun nestedClassFun() {} - - class NestedNestedClass { - fun nestedNestedClassFun() {} - } - } - - inner class InnerClass { - fun innerClassFun() {} - } - - interface InnerInterface { - fun innerInterfaceFun() - fun innerInterfaceFunWithImpl() = 5 - } -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/nestedClasses.txt b/plugins/annotation-processing/testData/wrappers/kotlinWrappers/nestedClasses.txt deleted file mode 100644 index 65daf606ae5..00000000000 --- a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/nestedClasses.txt +++ /dev/null @@ -1,55 +0,0 @@ -public final class MyClass { - private static final int CONST - - public static final MyClass.Companion Companion - - public final void myClassFun() - - public void () - - public static final class Companion { - public final int getCONST() - - private void () - } - - public static final class NestedClass { - private static final int CONSTA - - public static final MyClass.NestedClass.A A - - public final void nestedClassFun() - - public void () - - public static final class A { - public final int getCONSTA() - - private void () - } - - public static final class NestedNestedClass { - public final void nestedNestedClassFun() - - public void () - } - } - - public final class InnerClass { - public final void innerClassFun() - - public void () - } - - public static abstract interface InnerInterface { - public abstract void innerInterfaceFun() - - public default int innerInterfaceFunWithImpl() - - public static final class DefaultImpls { - public static int innerInterfaceFunWithImpl(MyClass.InnerInterface $this) - - public void () - } - } -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/repeatableAnnotations.kt b/plugins/annotation-processing/testData/wrappers/kotlinWrappers/repeatableAnnotations.kt deleted file mode 100644 index 352f56f8939..00000000000 --- a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/repeatableAnnotations.kt +++ /dev/null @@ -1,9 +0,0 @@ -// FQNAME: MyClass - -@Retention(AnnotationRetention.SOURCE) -@Repeatable -annotation class Anno(val name: String) - -@Anno("Mary") -@Anno("Tom") -class MyClass \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/repeatableAnnotations.txt b/plugins/annotation-processing/testData/wrappers/kotlinWrappers/repeatableAnnotations.txt deleted file mode 100644 index b2614274855..00000000000 --- a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/repeatableAnnotations.txt +++ /dev/null @@ -1,5 +0,0 @@ -@Anno(name = "Mary") -@Anno(name = "Tom") -public final class MyClass { - public void () -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/simple.kt b/plugins/annotation-processing/testData/wrappers/kotlinWrappers/simple.kt deleted file mode 100644 index 18c72fd47d4..00000000000 --- a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/simple.kt +++ /dev/null @@ -1,10 +0,0 @@ -// FQNAME: test.Simple - -package test - -abstract class Simple(private val prop: String) { - protected val anotherProp: Int = 5 - - abstract fun strFun(x: Long): String - fun voidFun() {} -} \ No newline at end of file diff --git a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/simple.txt b/plugins/annotation-processing/testData/wrappers/kotlinWrappers/simple.txt deleted file mode 100644 index 2625f57ea62..00000000000 --- a/plugins/annotation-processing/testData/wrappers/kotlinWrappers/simple.txt +++ /dev/null @@ -1,14 +0,0 @@ -public abstract class Simple { - private final int anotherProp - - private final java.lang.String prop - - protected final int getAnotherProp() - - @org.jetbrains.annotations.NotNull - public abstract java.lang.String strFun(long x) - - public final void voidFun() - - public void (java.lang.String prop) -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/java-model-wrappers.iml b/plugins/java-model-wrappers/java-model-wrappers.iml deleted file mode 100755 index c8bb463aa64..00000000000 --- a/plugins/java-model-wrappers/java-model-wrappers.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeAnnotationOwner.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeAnnotationOwner.kt deleted file mode 100644 index ae5e6f03bb6..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeAnnotationOwner.kt +++ /dev/null @@ -1,82 +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.java.model - -import com.intellij.psi.PsiClass -import com.intellij.psi.PsiModifierListOwner -import org.jetbrains.kotlin.java.model.elements.JeAnnotationMirror -import org.jetbrains.kotlin.java.model.internal.KotlinAnnotationProxyMaker -import org.jetbrains.kotlin.java.model.internal.getAnnotationsWithInherited -import javax.lang.model.element.AnnotationMirror -import javax.lang.model.element.Element -import java.lang.reflect.Array as RArray - -interface JeAnnotationOwner : JeElement { - override val psi: PsiModifierListOwner - - override fun getAnnotationMirrors() = psi.getAnnotationsWithInherited().map(::JeAnnotationMirror) - - override fun getAnnotation(annotationClass: Class): A? { - return getAnnotationsByType(annotationClass, onlyFirst = true).firstOrNull() - } - - @Suppress("UNCHECKED_CAST") - override fun getAnnotationsByType(annotationClass: Class): Array { - val annotations = getAnnotationsByType(annotationClass, onlyFirst = false) - - return (RArray.newInstance(annotationClass, annotations.size) as Array).apply { - annotations.forEachIndexed { i, annotation -> RArray.set(this, i, annotation) } - } - } - - private fun getAnnotationsByType(annotationClass: Class, onlyFirst: Boolean): List { - if (!annotationClass.isAnnotation) { - throw IllegalArgumentException("Not an annotation class: " + annotationClass) - } - - val annotationFqName = annotationClass.canonicalName - - val allAnnotations = psi.getAnnotationsWithInherited().filter { it.qualifiedName == annotationFqName } - if (allAnnotations.isEmpty()) return emptyList() - - val annotations = if (onlyFirst) listOf(allAnnotations.first()) else allAnnotations - - val annotationDeclarations = annotations.map { it to it.nameReferenceElement?.resolve() as? PsiClass }.filter { it.second != null } - - @Suppress("UNCHECKED_CAST") - val annotationProxies = annotationDeclarations.map { - val (annotation, annotationDeclaration) = it - KotlinAnnotationProxyMaker(annotation, annotationDeclaration!!, annotationClass).generate() as? A - } - - @Suppress("UNCHECKED_CAST") - return annotationProxies as List - } -} - -interface JeNoAnnotations : Element { - override fun getAnnotationMirrors() = emptyList() - - override fun getAnnotation(annotationClass: Class?): Nothing? { - return null - } - - @Suppress("UNCHECKED_CAST") - override fun getAnnotationsByType(annotationType: Class): Array { - return RArray.newInstance(annotationType, 0) as Array - } -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeConverter.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeConverter.kt deleted file mode 100644 index dfac90d8ce1..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeConverter.kt +++ /dev/null @@ -1,31 +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.java.model - -import com.intellij.psi.* -import org.jetbrains.kotlin.java.model.elements.* - -// to extension function? -fun PsiElement?.toJeElement(): JeElement? = when (this) { - null -> null - is PsiPackage -> JePackageElement(this) - is PsiClass -> JeTypeElement(this) - is PsiVariable -> JeVariableElement(this) - is PsiMethod -> JeMethodExecutableElement(this) - is PsiClassInitializer -> JeClassInitializerExecutableElement(this) - else -> null -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeElement.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeElement.kt deleted file mode 100644 index 53686e763fb..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeElement.kt +++ /dev/null @@ -1,52 +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.java.model - -import com.intellij.openapi.Disposable -import com.intellij.openapi.components.ServiceManager -import com.intellij.psi.PsiElement -import com.intellij.psi.PsiManager -import org.jetbrains.kotlin.java.model.internal.JeElementRegistry -import org.jetbrains.kotlin.java.model.util.toDisposable -import javax.lang.model.element.Element - -interface JePsiElementOwner { - val psi: PsiElement -} - -interface JeElement : Element, JePsiElementOwner - -abstract class JeDisposablePsiElementOwner(element: T) : JePsiElementOwner, Disposable { - private val disposablePsi = element.toDisposable() - - init { - @Suppress("LeakingThis") - ServiceManager.getService(element.project, JeElementRegistry::class.java).register(this) - } - - override fun dispose() { - disposablePsi.dispose() - } - - override val psi: T - get() = disposablePsi() - - val psiManager: PsiManager - get() = disposablePsi().manager -} - -abstract class JeAbstractElement(element: T) : JeDisposablePsiElementOwner(element), JeElement, Disposable \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeModifierListOwner.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeModifierListOwner.kt deleted file mode 100644 index 22b24c52436..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeModifierListOwner.kt +++ /dev/null @@ -1,26 +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.java.model - -import com.intellij.psi.PsiModifierListOwner -import org.jetbrains.kotlin.java.model.internal.getJavaModifiers -import javax.lang.model.element.Element - -interface JeModifierListOwner : Element { - val psi: PsiModifierListOwner - override fun getModifiers() = psi.getJavaModifiers() -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeName.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeName.kt deleted file mode 100644 index 841e1b60eb4..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/JeName.kt +++ /dev/null @@ -1,33 +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.java.model - -import javax.lang.model.element.Name - -fun JeName(name: String?) = name?.let(::JeName) ?: JeName.EMPTY - -class JeName(val name: String) : Name, CharSequence by name { - override fun contentEquals(cs: CharSequence?) = cs?.toString() == name - - override fun toString() = name - - companion object { - val EMPTY = JeName("") - val INIT = JeName("") - val CLINIT = JeName("") - } -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/DefaultJeElementRenderer.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/DefaultJeElementRenderer.kt deleted file mode 100644 index d28f2dd3e1b..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/DefaultJeElementRenderer.kt +++ /dev/null @@ -1,120 +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.java.model.elements - -import org.jetbrains.kotlin.java.model.JeElement -import org.jetbrains.kotlin.java.model.types.* -import javax.lang.model.element.AnnotationMirror -import javax.lang.model.element.AnnotationValue -import javax.lang.model.element.Element -import javax.lang.model.element.ElementKind -import javax.lang.model.type.TypeMirror - -class DefaultJeElementRenderer : JeElementRenderer { - override fun render(element: JeElement): String { - return when (element) { - is JePackageElement -> buildString { - appendln("package ${element.qualifiedName}").appendln() - element.enclosedElements.forEach { appendln(render(it).withMargin()).appendln() } - } - is JeTypeElement -> buildString { - val classType = when (element.kind) { - ElementKind.ANNOTATION_TYPE -> "@interface" - ElementKind.INTERFACE -> "interface" - ElementKind.ENUM -> "enum" - ElementKind.CLASS -> "class" - else -> throw IllegalStateException("Invalid class type: ${element.kind}") - } - appendln(renderModifiers(element) + classType + ' ' + element.simpleName + " {") - appendln(element.enclosedElements.joinToString(LINE_SEPARATOR.repeat(2)) { render(it).withMargin() }) - append("}") - } - is JeVariableElement -> renderModifiers(element) + renderType(element.asType()) + " " + element.simpleName - is JeMethodExecutableElement -> buildString { - append(renderModifiers(element) + renderType(element.returnType, noneAsVoid = true) + " " + element.simpleName) - append(element.parameters.joinToString(prefix = "(", postfix = ")") { renderType(it.asType()) + " " + it.simpleName }) - } - is JeClassInitializerExecutableElement -> renderModifiers(element) + "{}" - else -> throw IllegalArgumentException("Unsupported element: $element") - } - } - - private fun renderType(type: TypeMirror, noneAsVoid: Boolean = false): String { - return when (type) { - is JeNullType -> "null" - is JeVoidType -> "void" - is JeErrorType -> "" - is JeNoneType -> if (noneAsVoid) "void" else throw IllegalArgumentException("Unexpected 'none' type") - is JePsiType -> type.psiType.getCanonicalText(false) - else -> throw IllegalArgumentException("Unsupported type: $type") - } - } - - private fun renderModifiers(element: Element): String { - val renderedAnnotations = renderAnnotations(element) - val modifiers = element.modifiers - - return if (modifiers.isEmpty()) - renderedAnnotations - else - renderedAnnotations + modifiers.joinToString(" ", postfix = " ") { it.name.toLowerCase() } - } - - private fun renderAnnotations(element: Element): String { - val annotations = element.annotationMirrors - if (annotations.isEmpty()) return "" - return annotations.joinToString(LINE_SEPARATOR, postfix = LINE_SEPARATOR) { renderAnnotation(it) } - } - - private fun renderAnnotation(anno: AnnotationMirror): String { - val name = "@" + renderType(anno.annotationType) - val args = anno.elementValues - if (args.isEmpty()) return name - - return name + args - .map { it.key.simpleName.toString() + " = " + renderAnnotationValue(it.value) } - .joinToString(prefix = "(", postfix = ")") - } - - private fun renderAnnotationValue(av: AnnotationValue): String { - return when (av) { - is JeAnnotationAnnotationValue -> renderAnnotation(av.value) - is JeArrayAnnotationValue -> av.value.joinToString(prefix = "{ ", postfix = " }") { renderAnnotationValue(it) } - is JeSingletonArrayAnnotationValue -> av.value.joinToString(prefix = "{ ", postfix = " }") { renderAnnotationValue(it) } - is JeEnumValueAnnotationValue -> av.value.simpleName.toString() - is JeErrorAnnotationValue -> "" - is JeExpressionAnnotationValue, is JeLiteralAnnotationValue -> av.value?.let { renderConstantValue(it) } ?: "null" - is JeTypeAnnotationValue -> renderType(av.value) + ".class" - else -> throw IllegalArgumentException("Unsupported annotation value: $av") - } - } - - private fun renderConstantValue(value: Any?): String { - return when (value) { - null -> "null" - is String -> "\"" + value.replace("\"", "\\\"") + "\"" - else -> value.toString() - } - } - - private fun String.withMargin() = lines().joinToString(LINE_SEPARATOR) { MARGIN + it } - - private companion object { - val MARGIN = " " - val LINE_SEPARATOR: String = System.getProperty("line.separator") - } -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeAnnotationMirror.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeAnnotationMirror.kt deleted file mode 100644 index 6aea97a1191..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeAnnotationMirror.kt +++ /dev/null @@ -1,63 +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.java.model.elements - -import com.intellij.psi.* -import org.jetbrains.kotlin.java.model.JeDisposablePsiElementOwner -import org.jetbrains.kotlin.java.model.internal.getTypeWithTypeParameters -import org.jetbrains.kotlin.java.model.types.JeDeclaredErrorType -import org.jetbrains.kotlin.java.model.types.JeDeclaredType -import javax.lang.model.element.AnnotationMirror -import javax.lang.model.element.AnnotationValue -import javax.lang.model.element.ExecutableElement -import javax.lang.model.type.DeclaredType - -class JeAnnotationMirror(psi: PsiAnnotation) : JeDisposablePsiElementOwner(psi), AnnotationMirror { - override fun getAnnotationType(): DeclaredType? { - val psiClass = resolveAnnotationClass() ?: return JeDeclaredErrorType - return JeDeclaredType(psiClass.getTypeWithTypeParameters(), psiClass) - } - - override fun getElementValues(): Map = getElementValues(false) - - fun getAllElementValues(): Map = getElementValues(true) - - private fun getElementValues(withDefaults: Boolean): Map { - val annotationClass = resolveAnnotationClass() ?: return emptyMap() - - return mutableMapOf().apply { - for (method in annotationClass.methods) { - method as? PsiAnnotationMethod ?: continue - val returnType = method.returnType ?: continue - - val attributeValue = psi.findDeclaredAttributeValue(method.name) - ?: (if (withDefaults) method.defaultValue else null) - ?: continue - - val annotationValue = when { - returnType is PsiArrayType && attributeValue !is PsiArrayInitializerMemberValue -> - JeSingletonArrayAnnotationValue(attributeValue) - else -> JeAnnotationValue(attributeValue) - } - - put(JeMethodExecutableElement(method), annotationValue) - } - } - } - - private fun resolveAnnotationClass() = psi.nameReferenceElement?.resolve() as? PsiClass -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeAnnotationValue.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeAnnotationValue.kt deleted file mode 100644 index fc2033d7b33..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeAnnotationValue.kt +++ /dev/null @@ -1,106 +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.java.model.elements - -import com.intellij.psi.* -import org.jetbrains.kotlin.java.model.JeDisposablePsiElementOwner -import org.jetbrains.kotlin.java.model.internal.calcConstantValue -import org.jetbrains.kotlin.java.model.types.toJeType -import java.util.* -import javax.lang.model.element.AnnotationValue -import javax.lang.model.element.AnnotationValueVisitor - -fun JeAnnotationValue(psi: PsiAnnotationMemberValue): AnnotationValue { - val original = psi.originalElement - val annotationValue = when (original) { - is PsiLiteral -> JeLiteralAnnotationValue(original) - is PsiAnnotation -> JeAnnotationAnnotationValue(original) - is PsiArrayInitializerMemberValue -> JeArrayAnnotationValue(original) - is PsiClassObjectAccessExpression -> JeTypeAnnotationValue(original) - is PsiReferenceExpression -> { - val element = original.resolve() - if (element is PsiEnumConstant) { - JeEnumValueAnnotationValue(element) - } - else if (element is PsiField && element.hasInitializer()) { - JeAnnotationValue(element.initializer ?: error("Field should have an initializer")) - } - else { - JeErrorAnnotationValue(psi) - } - } - is PsiExpression -> JeExpressionAnnotationValue(original) - else -> throw AssertionError("Unsupported annotation element value: $psi (original = $original)") - } - return annotationValue -} - -class JeAnnotationAnnotationValue(psi: PsiAnnotation) : JeDisposablePsiElementOwner(psi), AnnotationValue { - override fun getValue() = JeAnnotationMirror(psi) - override fun accept(v: AnnotationValueVisitor, p: P) = v.visitAnnotation(value, p) -} - -class JeEnumValueAnnotationValue(psi: PsiEnumConstant) : JeDisposablePsiElementOwner(psi), AnnotationValue { - override fun getValue() = JeVariableElement(psi) - override fun accept(v: AnnotationValueVisitor, p: P) = v.visitEnumConstant(value, p) -} - -class JeTypeAnnotationValue(psi: PsiClassObjectAccessExpression) : JeDisposablePsiElementOwner(psi), AnnotationValue { - override fun getValue() = psi.operand.type.toJeType(psi.manager) - override fun accept(v: AnnotationValueVisitor, p: P) = v.visitType(value, p) -} - -abstract class JePrimitiveAnnotationValue(psi: T) : JeDisposablePsiElementOwner(psi), AnnotationValue { - override fun accept(v: AnnotationValueVisitor, p: P): R { - val value = this.value - return when (value) { - is String -> v.visitString(value, p) - is Int -> v.visitInt(value, p) - is Boolean -> v.visitBoolean(value, p) - is Char -> v.visitChar(value, p) - is Byte -> v.visitByte(value, p) - is Short -> v.visitShort(value, p) - is Long -> v.visitLong(value, p) - is Float -> v.visitFloat(value, p) - is Double -> v.visitDouble(value, p) - else -> throw AssertionError("Bad annotation element value: $value") - } - } -} - -class JeLiteralAnnotationValue(psi: PsiLiteral) : JePrimitiveAnnotationValue(psi) { - override fun getValue() = psi.value -} - -class JeExpressionAnnotationValue(psi: PsiExpression) : JePrimitiveAnnotationValue(psi) { - override fun getValue() = psi.calcConstantValue() -} - -class JeArrayAnnotationValue(psi: PsiArrayInitializerMemberValue) : JeDisposablePsiElementOwner(psi), AnnotationValue { - override fun getValue() = psi.initializers.map(::JeAnnotationValue) - override fun accept(v: AnnotationValueVisitor, p: P) = v.visitArray(value, p) -} - -class JeSingletonArrayAnnotationValue(psi: PsiAnnotationMemberValue) : JeDisposablePsiElementOwner(psi), AnnotationValue { - override fun getValue(): List = Collections.singletonList(JeAnnotationValue(psi)) - override fun accept(v: AnnotationValueVisitor, p: P) = v.visitArray(value, p) -} - -class JeErrorAnnotationValue(psi: PsiElement) : JeDisposablePsiElementOwner(psi), AnnotationValue { - override fun accept(v: AnnotationValueVisitor, p: P) = v.visitString(psi.text, p) - override fun getValue() = null -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeClassInitializerExecutableElement.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeClassInitializerExecutableElement.kt deleted file mode 100644 index 9fb18b96e4b..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeClassInitializerExecutableElement.kt +++ /dev/null @@ -1,71 +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.java.model.elements - -import com.intellij.psi.PsiClassInitializer -import org.jetbrains.kotlin.java.model.* -import org.jetbrains.kotlin.java.model.internal.isStatic -import org.jetbrains.kotlin.java.model.types.JeClassInitializerExecutableTypeMirror -import org.jetbrains.kotlin.java.model.types.JeNoneType -import javax.lang.model.element.* -import javax.lang.model.type.TypeMirror - -class JeClassInitializerExecutableElement( - psi: PsiClassInitializer -) : JeAbstractElement(psi), ExecutableElement, JeNoAnnotations, JeModifierListOwner { - val isStaticInitializer = psi.isStatic - - override fun getEnclosingElement() = psi.containingClass?.let(::JeTypeElement) - - override fun getSimpleName() = if (isStaticInitializer) JeName.CLINIT else JeName.EMPTY - - override fun getThrownTypes() = emptyList() - - override fun getTypeParameters() = emptyList() - - override fun getParameters() = emptyList() - - override fun getDefaultValue() = null - - override fun getReturnType() = JeNoneType - - override fun getReceiverType() = JeNoneType - - override fun isVarArgs() = false - - override fun isDefault() = false - - override fun getKind() = if (isStaticInitializer) ElementKind.STATIC_INIT else ElementKind.INSTANCE_INIT - - override fun asType() = JeClassInitializerExecutableTypeMirror(psi) - - override fun accept(v: ElementVisitor, p: P) = v.visitExecutable(this, p) - - override fun getEnclosedElements() = emptyList() - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - - return psi == (other as JeClassInitializerExecutableElement).psi - } - - override fun hashCode() = psi.hashCode() - - override fun toString() = psi.containingClass?.qualifiedName - ?.let { it + if (isStaticInitializer) "." else "." } ?: "" -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeElementRenderer.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeElementRenderer.kt deleted file mode 100644 index 4820297f6ac..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeElementRenderer.kt +++ /dev/null @@ -1,23 +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.java.model.elements - -import org.jetbrains.kotlin.java.model.JeElement - -interface JeElementRenderer { - fun render(element: JeElement): String -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeMethodExecutableElement.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeMethodExecutableElement.kt deleted file mode 100644 index 3b2e3f31360..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeMethodExecutableElement.kt +++ /dev/null @@ -1,97 +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.java.model.elements - -import com.intellij.psi.* -import org.jetbrains.kotlin.java.model.* -import org.jetbrains.kotlin.java.model.internal.getTypeWithTypeParameters -import org.jetbrains.kotlin.java.model.internal.isStatic -import org.jetbrains.kotlin.java.model.types.JeMethodExecutableTypeMirror -import org.jetbrains.kotlin.java.model.types.JeNoneType -import org.jetbrains.kotlin.java.model.types.toJeType -import javax.lang.model.element.* -import javax.lang.model.type.TypeMirror - -class JeMethodExecutableElement(psi: PsiMethod) : JeAbstractElement(psi), ExecutableElement, JeModifierListOwner, JeAnnotationOwner { - override fun getEnclosingElement() = psi.containingClass?.let(::JeTypeElement) - - override fun getSimpleName(): JeName { - if (psi.isConstructor) return JeName.INIT - return JeName(psi.name) - } - - override fun getThrownTypes() = psi.throwsList.referencedTypes.map { it.toJeType(psi.manager) } - - override fun getTypeParameters() = psi.typeParameters.map { JeTypeParameterElement(it, this) } - - override fun getParameters() = psi.parameterList.parameters.map(::JeVariableElement) - - override fun getDefaultValue(): AnnotationValue? { - val annotationMethod = psi as? PsiAnnotationMethod ?: return null - val defaultValue = annotationMethod.defaultValue ?: return null - return JeAnnotationValue(defaultValue) - } - - override fun getReturnType() = psi.returnType?.let { it.toJeType(psi.manager) } ?: JeNoneType - - override fun getReceiverType() = psi.getReceiverTypeMirror() - - override fun isVarArgs() = psi.isVarArgs - - override fun isDefault() = psi.hasModifierProperty(PsiModifier.DEFAULT) - - override fun getKind() = when { - psi.isConstructor -> ElementKind.CONSTRUCTOR - else -> ElementKind.METHOD - } - - override fun asType() = JeMethodExecutableTypeMirror(psi) - - override fun accept(v: ElementVisitor, p: P) = v.visitExecutable(this, p) - - override fun getEnclosedElements() = emptyList() - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - - return psi == (other as JeMethodExecutableElement).psi - } - - override fun hashCode() = psi.hashCode() - - override fun toString() = psi.name -} - -fun PsiMethod.getReceiverTypeMirror(): TypeMirror { - if (isStatic) return JeNoneType - - if (isConstructor) { - val containingClass = containingClass - if (containingClass != null && !containingClass.isStatic) { - containingClass.containingClass?.let { - return it.getTypeWithTypeParameters().toJeType(manager) - } - } - - return JeNoneType - } - - val containingClass = containingClass ?: return JeNoneType - return containingClass.getTypeWithTypeParameters().toJeType(manager) - -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JePackageElement.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JePackageElement.kt deleted file mode 100644 index bc91bac06bd..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JePackageElement.kt +++ /dev/null @@ -1,53 +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.java.model.elements - -import com.intellij.psi.PsiPackage -import org.jetbrains.kotlin.java.model.* -import org.jetbrains.kotlin.java.model.types.JePackageTypeMirror -import javax.lang.model.element.ElementKind -import javax.lang.model.element.ElementVisitor -import javax.lang.model.element.PackageElement - -class JePackageElement(psi: PsiPackage) : JeAbstractElement(psi), PackageElement, JeModifierListOwner, JeNoAnnotations { - override fun getEnclosingElement() = null - - override fun getSimpleName() = JeName(psi.name) - - override fun getKind() = ElementKind.PACKAGE - - override fun accept(v: ElementVisitor, p: P) = v.visitPackage(this, p) - - override fun isUnnamed() = psi.name.isNullOrEmpty() - - override fun getQualifiedName() = JeName(psi.qualifiedName) - - override fun getEnclosedElements() = psi.classes.map(::JeTypeElement) - - override fun asType() = JePackageTypeMirror - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - - return psi == (other as JePackageElement).psi - } - - override fun hashCode() = psi.hashCode() - - override fun toString() = psi.qualifiedName -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeTypeElement.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeTypeElement.kt deleted file mode 100644 index 96bd09d10f3..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeTypeElement.kt +++ /dev/null @@ -1,142 +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.java.model.elements - -import com.intellij.psi.* -import com.intellij.psi.impl.source.PsiClassReferenceType -import com.intellij.psi.util.ClassUtil -import org.jetbrains.kotlin.asJava.elements.LightParameter -import org.jetbrains.kotlin.java.model.* -import org.jetbrains.kotlin.java.model.internal.DefaultConstructorPsiMethod -import org.jetbrains.kotlin.java.model.internal.getTypeWithTypeParameters -import org.jetbrains.kotlin.java.model.types.JeNoneType -import org.jetbrains.kotlin.java.model.types.toJeType -import javax.lang.model.element.* -import javax.lang.model.type.TypeMirror - -class JeTypeElement(psi: PsiClass) : JeAbstractElement(psi), TypeElement, JeAnnotationOwner, JeModifierListOwner { - override fun getEnclosingElement(): Element? { - psi.containingClass?.let { return JeTypeElement(it) } - val javaFile = psi.containingFile as? PsiJavaFile ?: return null - return JavaPsiFacade.getInstance(psi.project).findPackage(javaFile.packageName)?.let(::JePackageElement) - } - - override fun getSimpleName() = JeName(psi.name) - - override fun getQualifiedName() = JeName(psi.qualifiedName) - - private fun getSuperType(superTypes: Array, superClass: PsiClass): PsiClassType { - return superTypes.firstOrNull { it is PsiClassReferenceType && it.resolve() == superClass } - ?: superClass.getTypeWithTypeParameters() - } - - override fun getSuperclass(): TypeMirror { - val superClass = psi.superClass ?: return JeNoneType - val psiType = getSuperType(psi.superTypes, superClass) - return psiType.toJeType(psi.manager) - } - - override fun getInterfaces(): List { - val superTypes = psi.superTypes - val interfaces = mutableListOf() - - for (intf in psi.interfaces) { - val psiType = getSuperType(superTypes, intf) - interfaces += psiType.toJeType(psi.manager) - } - - return interfaces - } - - override fun getTypeParameters() = psi.typeParameters.map { JeTypeParameterElement(it, this) } - - override fun getNestingKind() = when { - ClassUtil.isTopLevelClass(psi) -> NestingKind.TOP_LEVEL - psi.parent is PsiClass -> NestingKind.MEMBER - psi is PsiAnonymousClass -> NestingKind.ANONYMOUS - else -> NestingKind.LOCAL - } - - override fun getEnclosedElements(): List { - val declarations = mutableListOf() - psi.initializers.forEach { declarations += JeClassInitializerExecutableElement(it) } - psi.fields.forEach { declarations += JeVariableElement(it) } - psi.methods.forEach { declarations += JeMethodExecutableElement(it) } - psi.innerClasses.forEach { declarations += JeTypeElement(it) } - - // Add default constructor if possible - if (!psi.isInterface && !psi.isAnnotationType && psi.constructors.isEmpty()) { - val superClass = psi.superClass - val canHaveDefaultConstructor = superClass == null || run { - val constructors = superClass.constructors - constructors.isEmpty() || constructors.any { - (it.hasModifierProperty(PsiModifier.PUBLIC) || it.hasModifierProperty(PsiModifier.PROTECTED) || run { - it.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) && psi.packageName == superClass.packageName - }) && it.parameterList.parametersCount == 0 - } - } - - if (canHaveDefaultConstructor) { - declarations += JeMethodExecutableElement(DefaultConstructorPsiMethod(psi, psi.language).apply { - val containingClass = psi.containingClass - if (containingClass != null && !psi.hasModifierProperty(PsiModifier.STATIC)) { - addParameter(LightParameter("\$instance", containingClass.getTypeWithTypeParameters(), this, psi.language)) - } - }) - } - } - - return declarations - } - - private val PsiClass.packageName: String - get() = (containingFile as? PsiJavaFile)?.packageName ?: "" - - fun getAllMembers(): List { - val declarations = mutableListOf() - psi.allFields.forEach { declarations += JeVariableElement(it) } - psi.allMethods.forEach { - if (it.isConstructor && it.containingClass != this@JeTypeElement.psi) return@forEach - declarations += JeMethodExecutableElement(it) - } - psi.allInnerClasses.forEach { declarations += JeTypeElement(it) } - psi.initializers.forEach { declarations += JeClassInitializerExecutableElement(it) } - return declarations - } - - override fun getKind() = when { - psi.isEnum -> ElementKind.ENUM - psi.isAnnotationType -> ElementKind.ANNOTATION_TYPE - psi.isInterface -> ElementKind.INTERFACE - else -> ElementKind.CLASS - } - - override fun asType() = psi.getTypeWithTypeParameters().toJeType(psi.manager) - - override fun accept(v: ElementVisitor, p: P) = v.visitType(this, p) - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - - return psi == (other as JeTypeElement).psi - } - - override fun hashCode() = psi.hashCode() - - override fun toString() = psi.qualifiedName ?: " extends " + psi.superClass?.qualifiedName ?: "" -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeTypeParameterElement.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeTypeParameterElement.kt deleted file mode 100644 index 7edad08318d..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeTypeParameterElement.kt +++ /dev/null @@ -1,58 +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.java.model.elements - -import com.intellij.psi.PsiTypeParameter -import org.jetbrains.kotlin.java.model.* -import org.jetbrains.kotlin.java.model.internal.getTypeWithTypeParameters -import org.jetbrains.kotlin.java.model.types.toJeType -import javax.lang.model.element.Element -import javax.lang.model.element.ElementKind -import javax.lang.model.element.ElementVisitor -import javax.lang.model.element.TypeParameterElement - -class JeTypeParameterElement( - psi: PsiTypeParameter, - val parent: JeElement? -) : JeAbstractElement(psi), TypeParameterElement, JeAnnotationOwner, JeModifierListOwner { - override fun getSimpleName() = JeName(psi.name) - - override fun getEnclosingElement() = parent - - override fun getKind() = ElementKind.TYPE_PARAMETER - - override fun asType() = psi.getTypeWithTypeParameters().toJeType(psi.manager) - - override fun accept(v: ElementVisitor, p: P) = v.visitTypeParameter(this, p) - - override fun getEnclosedElements() = emptyList() - - override fun getBounds() = psi.superTypes.map { it.toJeType(psi.manager) } - - override fun getGenericElement() = parent - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - - return psi == (other as JeTypeParameterElement).psi - } - - override fun hashCode() = psi.hashCode() - - override fun toString() = psi.name ?: "T" -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeVariableElement.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeVariableElement.kt deleted file mode 100644 index 708dd97bda7..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/elements/JeVariableElement.kt +++ /dev/null @@ -1,67 +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.java.model.elements - -import com.intellij.psi.* -import com.intellij.psi.util.PsiTreeUtil -import org.jetbrains.kotlin.java.model.* -import org.jetbrains.kotlin.java.model.internal.calcConstantValue -import org.jetbrains.kotlin.java.model.types.toJeType -import javax.lang.model.element.Element -import javax.lang.model.element.ElementKind -import javax.lang.model.element.ElementVisitor -import javax.lang.model.element.VariableElement - -class JeVariableElement(psi: PsiVariable) : JeAbstractElement(psi), VariableElement, JeModifierListOwner, JeAnnotationOwner { - override fun getSimpleName() = JeName(psi.name) - - override fun getEnclosingElement(): JeElement? { - val psi = psi - - if (psi is PsiParameter) { - (psi.declarationScope as? PsiMethod)?.let { return JeMethodExecutableElement(it) } - } - - val containingClass = (psi as? PsiMember)?.containingClass ?: PsiTreeUtil.getParentOfType(psi, PsiClass::class.java) - return containingClass?.let(::JeTypeElement) - } - - override fun getConstantValue() = psi.initializer?.calcConstantValue() - - override fun getKind() = when (psi) { - is PsiField -> ElementKind.FIELD - is PsiParameter -> ElementKind.PARAMETER - else -> ElementKind.LOCAL_VARIABLE - } - - override fun asType() = psi.type.toJeType(psi.manager) - - override fun accept(v: ElementVisitor, p: P) = v.visitVariable(this, p) - - override fun getEnclosedElements() = emptyList() - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - - return psi == (other as JeVariableElement).psi - } - - override fun hashCode() = psi.hashCode() - - override fun toString() = psi.name ?: "" -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/AnnotationUtil.java b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/AnnotationUtil.java deleted file mode 100644 index 4708dbb81f7..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/AnnotationUtil.java +++ /dev/null @@ -1,54 +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.java.model.internal; - -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiType; -import sun.reflect.annotation.EnumConstantNotPresentExceptionProxy; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public final class AnnotationUtil { - public static final Map> ARRAY_TYPES_MAP; - - static { - Map> classes = new HashMap>(); - - classes.put(PsiType.BYTE, byte.class); - classes.put(PsiType.SHORT, short.class); - classes.put(PsiType.INT, int.class); - classes.put(PsiType.CHAR, char.class); - classes.put(PsiType.BOOLEAN, boolean.class); - classes.put(PsiType.LONG, long.class); - classes.put(PsiType.FLOAT, float.class); - classes.put(PsiType.DOUBLE, double.class); - - ARRAY_TYPES_MAP = Collections.unmodifiableMap(classes); - } - - public static Object createEnumValue(Class enumClass, String name) { - try { - return Enum.valueOf((Class)enumClass, name); - } catch (IllegalArgumentException ex) { - //noinspection unchecked - return new EnumConstantNotPresentExceptionProxy((Class>) enumClass, name); - } - - } -} diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/DefaultConstructorPsiMethod.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/DefaultConstructorPsiMethod.kt deleted file mode 100644 index cb2935b2b74..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/DefaultConstructorPsiMethod.kt +++ /dev/null @@ -1,38 +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.java.model.internal - -import com.intellij.lang.Language -import com.intellij.psi.PsiClass -import com.intellij.psi.PsiModifier.* -import com.intellij.psi.impl.light.LightMethodBuilder - -internal class DefaultConstructorPsiMethod( - clazz: PsiClass, - language: Language -) : LightMethodBuilder(clazz, language) { - init { - val modifier = when { - clazz.hasModifierProperty(PUBLIC) -> PUBLIC - clazz.hasModifierProperty(PRIVATE) -> PRIVATE - clazz.hasModifierProperty(PROTECTED) -> PROTECTED - else -> PACKAGE_LOCAL - } - setModifiers(modifier) - isConstructor = true - } -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/JeElementRegistry.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/JeElementRegistry.kt deleted file mode 100644 index eb036d9c492..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/JeElementRegistry.kt +++ /dev/null @@ -1,42 +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.java.model.internal - -import com.intellij.openapi.Disposable - -/* - Some annotation processors (I'm looking at you, Data Binding) - have a habit to cache Element or TypeMirror instances into static fields. - Because almost every JeElement or JeTypeMirror is dependent on some PsiElement, and PsiElements are dependent on PsiProject, - the entire project will not be gc'ed normally. - JeElementRegistry allows us to remove all Psi*-references from our wrapper Element and TypeMirror instances. - - So this class basically remembers all instances created by kapt, and disposes all of them as the Annotation Processing is complete. - */ -class JeElementRegistry : Disposable { - private val list = mutableListOf() - - fun register(obj: Disposable) { - list += obj - } - - override fun dispose() { - val list = this.list - list.forEach { it.dispose() } - this.list.clear() - } -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/KotlinAnnotationProxyMaker.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/KotlinAnnotationProxyMaker.kt deleted file mode 100644 index 8634ef4a035..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/KotlinAnnotationProxyMaker.kt +++ /dev/null @@ -1,211 +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.java.model.internal - -import com.intellij.psi.* -import com.intellij.psi.util.PsiTypesUtil -import org.jetbrains.kotlin.java.model.types.toJeType -import sun.reflect.annotation.AnnotationParser -import sun.reflect.annotation.ExceptionProxy -import java.io.ObjectInputStream -import java.lang.reflect.Array -import java.lang.reflect.Method -import java.util.* -import javax.lang.model.type.MirroredTypeException -import javax.lang.model.type.MirroredTypesException -import javax.lang.model.type.TypeMirror - -class KotlinAnnotationProxyMaker(val annotation: PsiAnnotation, val annotationClass: PsiClass, val annotationType: Class) { - fun generate(): Annotation { - return AnnotationParser.annotationForMap(annotationType, getAllValuesForParser(getAllPsiValues())) - } - - private data class AnnotationParameterData( - val method: PsiAnnotationMethod, - val value: PsiAnnotationMemberValue, - val jMethod: Method) - - private fun getAllPsiValues(): List { - val values = mutableListOf() - for (method in annotationClass.methods) { - if (method !is PsiAnnotationMethod) continue - if (method.returnType == null) continue - - val jMethod = try { annotationType.getMethod(method.name) } catch (e : NoSuchMethodException) { continue } - - val value = annotation.findAttributeValue(method.name) ?: method.defaultValue ?: continue - values += AnnotationParameterData(method, value, jMethod) - } - return values - } - - private fun getAllValuesForParser(values: List): Map { - val parserValues = mutableMapOf() - val evaluator = JavaPsiFacade.getInstance(annotation.project).constantEvaluationHelper - for ((method, value, jMethod) in values) { - val jReturnType = jMethod.returnType ?: unexpectedType("no return type for ${jMethod.name}") - parserValues.put(method.name, getConstantValue(value, method.returnType!!, jReturnType, evaluator)) - } - return parserValues - } -} - -private val JAVA_LANG_STRING = "java.lang.String" - -private fun getConstantValue( - psiValue: PsiAnnotationMemberValue, - returnType: PsiType, - jReturnType: Class<*>, - evaluator: PsiConstantEvaluationHelper -): Any? { - val manager = psiValue.manager - - when { - returnType == PsiType.NULL || returnType == PsiType.VOID -> unexpectedType("void") - returnType.fqName == JAVA_LANG_STRING -> return (psiValue as? PsiExpression)?.calcConstantValue(evaluator) - jReturnType.isAnnotation -> { - if (psiValue !is PsiAnnotation) error("psiValue is not a PsiAnnotation") - val annotationClass = PsiTypesUtil.getPsiClass(returnType) ?: error("Can't resolve type $returnType") - @Suppress("UNCHECKED_CAST") - val annotation = KotlinAnnotationProxyMaker(psiValue, annotationClass, jReturnType as Class) - return jReturnType.cast(annotation.generate()) - } - jReturnType.isArray -> { - val jComponentType = jReturnType.componentType ?: unexpectedType("no component type for $jReturnType") - if (returnType !is PsiArrayType) unexpectedType(returnType) - - val arrayValues = when (psiValue) { - is PsiArrayInitializerMemberValue -> psiValue.initializers.toList() - else -> listOf(psiValue) - } - - if (jComponentType.isPrimitive - || jComponentType.isAnnotation - || jComponentType.isEnum - || jComponentType.canonicalName == JAVA_LANG_STRING - ) { - val arr = Array.newInstance(jComponentType, arrayValues.size) - arrayValues.forEachIndexed { i, componentPsiValue -> - val componentValue = getConstantValue(componentPsiValue, returnType.componentType, jComponentType, evaluator) - try { Array.set(arr, i, componentValue) } catch (e: IllegalArgumentException) { return null } - } - return arr - } else { - val typeMirrors = arrayValues.map { getObjectType(it).toJeType(manager) } - return MirroredTypesExceptionProxy(Collections.unmodifiableList(typeMirrors)) - } - } - jReturnType.isEnum -> { - val enumConstant = (psiValue.originalElement as? PsiReference)?.resolve() as? PsiEnumConstant - ?: error("$psiValue can not be resolved to enum constant") - return AnnotationUtil.createEnumValue(jReturnType, enumConstant.name) - } - else -> return if (returnType is PsiClassType) { - val type = getObjectType(psiValue).toJeType(manager) - MirroredTypeExceptionProxy(type) - } else { - castPrimitiveValue(returnType, (psiValue as? PsiExpression)?.calcConstantValue(evaluator)) - } - } -} - -private val PsiType.fqName: String? - get() = (this as? PsiClassType)?.resolve()?.qualifiedName - -private fun getObjectType(value: PsiAnnotationMemberValue): PsiType { - when (value) { - is PsiClassObjectAccessExpression -> return value.operand.type - is PsiReference -> { - val resolvedElement = value.resolve() - if (resolvedElement is PsiField && resolvedElement.isStatic && resolvedElement.isFinal) { - val initializer = resolvedElement.initializer - if (initializer != null) { - return getObjectType(initializer) - } - } - } - } - - throw IllegalArgumentException("Illegal value type: ${value::class.java}") -} - -private fun castPrimitiveValue(type: PsiType, value: Any?): Any = when (type) { - PsiType.BYTE -> byteValue(value) - PsiType.SHORT -> shortValue(value) - PsiType.INT -> intValue(value) - PsiType.CHAR -> charValue(value) - PsiType.BOOLEAN -> booleanValue(value) - PsiType.LONG -> longValue(value) - PsiType.FLOAT -> floatValue(value) - PsiType.DOUBLE -> doubleValue(value) - else -> unexpectedType(type) -} - -private fun byteValue(value: Any?): Byte = (value as? Number)?.toByte() ?: 0 -private fun intValue(value: Any?): Int = (value as? Number)?.toInt() ?: 0 -private fun shortValue(value: Any?): Short = (value as? Number)?.toShort() ?: 0 -private fun booleanValue(value: Any?): Boolean = value == true -private fun charValue(value: Any?): Char = value as? Char ?: 0.toChar() - -private fun longValue(value: Any?): Long = (value as? Number)?.toLong() ?: 0 -private fun floatValue(value: Any?): Float = (value as? Number)?.toFloat() ?: 0f -private fun doubleValue(value: Any?): Double = (value as? Number)?.toDouble() ?: 0.0 - -private fun unexpectedType(type: String): Nothing = error("Unexpected type: $type") -private fun unexpectedType(type: PsiType): Nothing = unexpectedType(type.presentableText) - -private class MirroredTypeExceptionProxy(@Transient private var type: TypeMirror?) : ExceptionProxy() { - private val typeString = type.toString() - - @Suppress("IMPLICIT_CAST_TO_ANY") - override fun hashCode() = (if (type != null) type else typeString)?.hashCode() ?: 0 - override fun equals(other: Any?) = type != null && other is MirroredTypeExceptionProxy && type == other.type - override fun toString() = typeString - - override fun generateException() = MirroredTypeException(type) - - // Explicitly set all transient fields. - private fun readObject(s: ObjectInputStream) { - s.defaultReadObject() - type = null - } - - companion object { - private const val serialVersionUID: Long = 269 - } -} - -private class MirroredTypesExceptionProxy(@Transient private var types: List?) : ExceptionProxy() { - private val typeStrings: String = types.toString() - - @Suppress("IMPLICIT_CAST_TO_ANY") - override fun hashCode() = (if (types != null) types else typeStrings)?.hashCode() ?: 0 - override fun equals(other: Any?) = types != null && other is MirroredTypesExceptionProxy && types == other.types - override fun toString() = typeStrings - - override fun generateException() = MirroredTypesException(types) - - // Explicitly set all transient fields. - private fun readObject(s: ObjectInputStream) { - s.defaultReadObject() - types = null - } - - companion object { - private const val serialVersionUID: Long = 269 - } -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/internalUtil.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/internalUtil.kt deleted file mode 100644 index 1b2f82ea4ac..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/internalUtil.kt +++ /dev/null @@ -1,107 +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.java.model.internal - -import com.intellij.psi.* -import com.intellij.psi.PsiModifier.* -import com.intellij.psi.impl.PsiSubstitutorImpl -import com.intellij.psi.util.PsiTypesUtil -import org.jetbrains.kotlin.asJava.elements.KtLightAnnotationForSourceEntry -import javax.lang.model.element.Modifier - -private val HAS_DEFAULT by lazy { - Modifier::class.java.declaredFields.any { it.name == "DEFAULT" } -} - -private fun PsiModifierList.getJavaModifiers(): Set { - fun MutableSet.check(modifier: String, javaModifier: Modifier) { - if (hasModifierProperty(modifier)) this += javaModifier - } - - return mutableSetOf().apply { - check(PUBLIC, Modifier.PUBLIC) - check(PROTECTED, Modifier.PROTECTED) - check(PRIVATE, Modifier.PRIVATE) - check(STATIC, Modifier.STATIC) - check(ABSTRACT, Modifier.ABSTRACT) - check(FINAL, Modifier.FINAL) - check(NATIVE, Modifier.NATIVE) - check(SYNCHRONIZED, Modifier.SYNCHRONIZED) - check(STRICTFP, Modifier.STRICTFP) - check(TRANSIENT, Modifier.TRANSIENT) - check(VOLATILE, Modifier.VOLATILE) - - if (HAS_DEFAULT) { - check(DEFAULT, Modifier.DEFAULT) - } - } -} - -internal fun PsiExpression.calcConstantValue(evaluator: PsiConstantEvaluationHelper? = null): Any? { - return when (this) { - is PsiLiteral -> value - is KtLightAnnotationForSourceEntry.LightExpressionValue<*> -> getConstantValue() ?: delegate.calcConstantValue(evaluator) - is PsiExpression -> (evaluator ?: getConstantEvaluator(this)).computeConstantExpression(this) - else -> null - } -} - -private fun getConstantEvaluator(expression: PsiExpression) = JavaPsiFacade.getInstance(expression.project).constantEvaluationHelper - -internal val PsiModifierListOwner.isStatic: Boolean - get() = hasModifierProperty(PsiModifier.STATIC) - -internal val PsiModifierListOwner.isFinal: Boolean - get() = hasModifierProperty(PsiModifier.FINAL) - -fun PsiModifierListOwner.getJavaModifiers() = modifierList?.getJavaModifiers() ?: emptySet() - -fun PsiModifierListOwner.getAnnotationsWithInherited(): List { - val annotations = modifierList?.annotations?.filter { it.qualifiedName != null }?.toMutableList() ?: mutableListOf() - - if (this is PsiClass) { - var superClass = superClass - while (superClass != null) { - superClass.modifierList?.annotations?.let { superClassAnnotations -> - for (annotation in superClassAnnotations) { - // Do not add the inherited annotation from the superclass - // if the current class has an annotation with the same qualified name - if (!annotation.isInherited() - || annotations.any { it.qualifiedName == annotation.qualifiedName }) continue - annotations += annotation - } - } - - superClass = superClass.superClass - } - } - - return annotations -} - -fun PsiClass.getTypeWithTypeParameters(): PsiClassType { - val elementFactory = JavaPsiFacade.getElementFactory(project) - val params = mutableMapOf() - typeParameters.forEach { params.put(it, PsiTypesUtil.getClassType(it)) } - return elementFactory.createType(this, PsiSubstitutorImpl.createSubstitutor(params)) -} - -private fun PsiAnnotation.isInherited(): Boolean { - val annotationClass = nameReferenceElement?.resolve() as? PsiClass ?: return false - val annotations = annotationClass.modifierList?.annotations ?: return false - return annotations.any { it.qualifiedName == "java.lang.annotation.Inherited" } -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeArrayType.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeArrayType.kt deleted file mode 100644 index 1c431fdafbb..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeArrayType.kt +++ /dev/null @@ -1,50 +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.java.model.types - -import com.intellij.psi.PsiArrayType -import com.intellij.psi.PsiManager -import javax.lang.model.type.ArrayType -import javax.lang.model.type.TypeKind -import javax.lang.model.type.TypeVisitor - -class JeArrayType( - psiType: PsiArrayType, - psiManager: PsiManager, - private val isRaw: Boolean -) : JePsiTypeBase(psiType, psiManager), ArrayType { - override fun getKind() = TypeKind.ARRAY - override fun accept(v: TypeVisitor, p: P) = v.visitArray(this, p) - override fun getComponentType() = psiType.componentType.toJeType(psiManager, isRaw = isRaw) - - override fun toString() = psiType.getCanonicalText(false) - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - other as? JeArrayType ?: return false - - return componentType == other.componentType - && isRaw == other.isRaw - } - - override fun hashCode(): Int { - var result = componentType.hashCode() - result = 31 * result + isRaw.hashCode() - return result - } -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeClassInitializerExecutableTypeMirror.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeClassInitializerExecutableTypeMirror.kt deleted file mode 100644 index 733fa9a027e..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeClassInitializerExecutableTypeMirror.kt +++ /dev/null @@ -1,52 +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.java.model.types - -import com.intellij.psi.PsiClassInitializer -import org.jetbrains.kotlin.java.model.JeDisposablePsiElementOwner -import org.jetbrains.kotlin.java.model.internal.isStatic -import javax.lang.model.type.* - -class JeClassInitializerExecutableTypeMirror( - psi: PsiClassInitializer -) : JeDisposablePsiElementOwner(psi), JeTypeMirror, JeTypeWithManager, ExecutableType { - override fun getKind() = TypeKind.EXECUTABLE - - override fun accept(v: TypeVisitor, p: P) = v.visitExecutable(this, p) - - override fun getReturnType() = JeVoidType - - override fun getReceiverType() = JeNoneType - - override fun getThrownTypes() = emptyList() - - override fun getParameterTypes() = emptyList() - - override fun getTypeVariables() = emptyList() - - override fun toString() = (psi.containingClass?.qualifiedName?.let { it + "." } ?: "") + - (if (psi.isStatic) "" else "") - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - other as? JeClassInitializerExecutableTypeMirror ?: return false - return psi == other.psi - } - - override fun hashCode() = psi.hashCode() -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeDeclaredType.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeDeclaredType.kt deleted file mode 100644 index 3159182185d..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeDeclaredType.kt +++ /dev/null @@ -1,132 +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.java.model.types - -import com.intellij.pom.java.LanguageLevel -import com.intellij.psi.PsiClass -import com.intellij.psi.PsiClassType -import com.intellij.psi.PsiManager -import com.intellij.psi.PsiType -import com.intellij.psi.impl.PsiSubstitutorImpl -import com.intellij.psi.impl.source.PsiClassReferenceType -import com.intellij.psi.impl.source.PsiImmediateClassType -import org.jetbrains.kotlin.java.model.elements.JeTypeElement -import org.jetbrains.kotlin.java.model.internal.getTypeWithTypeParameters -import org.jetbrains.kotlin.java.model.internal.isStatic -import org.jetbrains.kotlin.java.model.util.toDisposable -import javax.lang.model.type.DeclaredType -import javax.lang.model.type.TypeKind -import javax.lang.model.type.TypeMirror -import javax.lang.model.type.TypeVisitor - -fun createImmediateClassType(psiClass: PsiClass, typeArgs: List): PsiImmediateClassType? { - val typeParameters = psiClass.typeParameters - assert(typeParameters.size == typeArgs.size) { "Type parameters size: ${typeParameters.size}, type args size: ${typeArgs.size}" } - - val parametersMap = typeParameters.zip(typeArgs).toMap() - val substitutor = PsiSubstitutorImpl.createSubstitutor(parametersMap) - return PsiImmediateClassType(psiClass, substitutor, LanguageLevel.JDK_1_8) -} - -class JeDeclaredType( - psiType: PsiClassType, - psiClass: PsiClass, - val enclosingDeclaredType: DeclaredType? = null, - val isRaw: Boolean = false -) : JePsiTypeBase(psiType, psiClass.manager), DeclaredType { - private val disposablePsiClass = psiClass.toDisposable() - - val psiClass: PsiClass - get() = disposablePsiClass() - - // JeElementRegistry registration is done in JePsiType - override fun dispose() { - super.dispose() - disposablePsiClass.dispose() - } - - override fun getKind() = TypeKind.DECLARED - - override fun accept(v: TypeVisitor, p: P) = v.visitDeclared(this, p) - - override val psiManager: PsiManager - get() = psiClass.manager - - override fun getTypeArguments(): List { - return when (psiType) { - is PsiClassReferenceType -> psiType.parameters.map { it.toJeType(psiManager) } - is PsiClassType -> { - if (isRaw) return emptyList() - - val substitutor = psiType.resolveGenerics().substitutor - val psiClass = psiType.resolve() ?: return psiType.parameters.map { it.toJeType(psiManager) } - - val args = mutableListOf() - for (typeParameter in psiClass.typeParameters) { - val substitutedParameter = substitutor.substitute(typeParameter) - args += if (substitutedParameter != null) - substitutedParameter.toJeType(psiManager) - else - JeTypeVariableType(typeParameter.getTypeWithTypeParameters(), typeParameter) - } - - args - } - else -> emptyList() - } - } - - override fun asElement() = JeTypeElement(psiClass) - - override fun getEnclosingType(): TypeMirror { - if (!psiClass.isStatic) return JeNoneType - - if (enclosingDeclaredType != null) return enclosingDeclaredType - - val psiClass = psiClass.containingClass ?: return JeNoneType - return psiClass.getTypeWithTypeParameters().toJeType(psiManager) - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - other as? JeDeclaredType ?: return false - - return enclosingType == other.enclosingType - && psiClass == other.psiClass - && typeArguments == other.typeArguments - && isRaw == other.isRaw - } - - override fun hashCode(): Int { - var result = enclosingType.hashCode() - result = 31 * result + psiClass.hashCode() - result = 31 * result + typeArguments.hashCode() - result = 31 * result + isRaw.hashCode() - return result - } - - override fun toString() = buildString { - append(psiClass.qualifiedName ?: psiClass.name) - val typeArgs = typeArguments - if (typeArgs.isNotEmpty()) { - append('<') - append(typeArguments.joinToString(",")) - append('>') - } - } -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeIntersectionType.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeIntersectionType.kt deleted file mode 100644 index 3148c86a8bf..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeIntersectionType.kt +++ /dev/null @@ -1,51 +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.java.model.types - -import com.intellij.psi.PsiIntersectionType -import com.intellij.psi.PsiManager -import javax.lang.model.type.IntersectionType -import javax.lang.model.type.TypeKind -import javax.lang.model.type.TypeVisitor - -class JeIntersectionType( - psiType: PsiIntersectionType, - psiManager: PsiManager, - private val isRaw: Boolean -) : JePsiTypeBase(psiType, psiManager), IntersectionType { - override fun getKind() = TypeKind.INTERSECTION - override fun accept(v: TypeVisitor, p: P) = v.visitIntersection(this, p) - - override fun getBounds() = psiType.superTypes.map { it.toJeType(psiManager, isRaw = isRaw) } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - other as? JeIntersectionType ?: return false - - return bounds == other.bounds - && isRaw == other.isRaw - } - - override fun hashCode(): Int { - var result = bounds.hashCode() - result = 31 * result + isRaw.hashCode() - return result - } - - override fun toString() = bounds.joinToString("&") -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeMethodExecutableTypeMirror.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeMethodExecutableTypeMirror.kt deleted file mode 100644 index 9a9c9d38428..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeMethodExecutableTypeMirror.kt +++ /dev/null @@ -1,94 +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.java.model.types - -import com.intellij.psi.PsiMethod -import com.intellij.psi.PsiType -import com.intellij.psi.util.MethodSignature -import com.intellij.psi.util.PsiTypesUtil -import org.jetbrains.kotlin.java.model.JeDisposablePsiElementOwner -import org.jetbrains.kotlin.java.model.elements.getReceiverTypeMirror -import org.jetbrains.kotlin.java.model.util.disposeAll -import org.jetbrains.kotlin.java.model.util.toDisposable -import javax.lang.model.type.ExecutableType -import javax.lang.model.type.TypeKind -import javax.lang.model.type.TypeMirror -import javax.lang.model.type.TypeVisitor - -class JeMethodExecutableTypeMirror( - psi: PsiMethod, - signature: MethodSignature? = null, - returnType: PsiType? = null, - val isRaw: Boolean = false -) : JeDisposablePsiElementOwner(psi), JeTypeMirror, JeTypeWithManager, ExecutableType { - private val disposableSignature = signature?.toDisposable() - private val disposableReturnType = returnType?.toDisposable() - - val signature: MethodSignature? - get() = disposableSignature?.invoke() - - val returnType: PsiType? - get() = disposableReturnType?.invoke() - - // JeElementRegistry registration is done in JeDisposablePsiElementOwner - override fun dispose() { - super.dispose() - disposeAll(disposableSignature, disposableReturnType) - } - - override fun getKind() = TypeKind.EXECUTABLE - - override fun accept(v: TypeVisitor, p: P) = v.visitExecutable(this, p) - - override fun getReturnType() = (returnType ?: psi.returnType)?.let { it.toJeType(psi.manager, isRaw = isRaw) } ?: JeVoidType - - override fun getReceiverType() = psi.getReceiverTypeMirror() - - override fun getThrownTypes() = psi.throwsList.referencedTypes.map { it.toJeType(psi.manager, isRaw = isRaw) } - - override fun getParameterTypes(): List { - signature?.parameterTypes?.let { types -> return types.map { it.toJeType(psi.manager, isRaw = isRaw) } } - return psi.parameterList.parameters.map { it.type.toJeType(psi.manager, isRaw = isRaw) } - } - - override fun getTypeVariables(): List { - if (isRaw) return emptyList() - val typeParameters = signature?.typeParameters ?: psi.typeParameters - return typeParameters.map { JeTypeVariableType(PsiTypesUtil.getClassType(it), it) } - } - - override fun toString() = buildString { - val typeVariables = this@JeMethodExecutableTypeMirror.typeVariables - if (typeVariables.isNotEmpty()) { - append('<') - typeVariables.joinTo(this, ",") - append('>') - } - append('(') - parameterTypes.joinTo(this, ",") - append(')') - append((this@JeMethodExecutableTypeMirror as ExecutableType).returnType) - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - return psi == (other as? JeMethodExecutableTypeMirror)?.psi - } - - override fun hashCode() = psi.hashCode() -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeNullType.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeNullType.kt deleted file mode 100644 index 7f441d42f88..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeNullType.kt +++ /dev/null @@ -1,27 +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.java.model.types - -import javax.lang.model.type.NullType -import javax.lang.model.type.TypeKind -import javax.lang.model.type.TypeVisitor - -object JeNullType : JeTypeMirror, NullType { - override fun getKind() = TypeKind.NULL - override fun accept(v: TypeVisitor, p: P) = v.visitNull(this, p) - override fun toString() = "null" -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JePrimitiveType.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JePrimitiveType.kt deleted file mode 100644 index f2f224dc07f..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JePrimitiveType.kt +++ /dev/null @@ -1,50 +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.java.model.types - -import com.intellij.psi.PsiPrimitiveType -import com.intellij.psi.PsiType -import javax.lang.model.type.PrimitiveType -import javax.lang.model.type.TypeKind -import javax.lang.model.type.TypeVisitor - -class JePrimitiveType(override val psiType: PsiPrimitiveType) : JePsiType, PrimitiveType { - override fun accept(v: TypeVisitor, p: P) = v.visitPrimitive(this, p) - - override fun getKind() = when (psiType) { - PsiType.BYTE -> TypeKind.BYTE - PsiType.CHAR -> TypeKind.CHAR - PsiType.DOUBLE -> TypeKind.DOUBLE - PsiType.FLOAT -> TypeKind.FLOAT - PsiType.INT -> TypeKind.INT - PsiType.LONG -> TypeKind.LONG - PsiType.SHORT -> TypeKind.SHORT - PsiType.BOOLEAN -> TypeKind.BOOLEAN - PsiType.VOID -> TypeKind.VOID - else -> TypeKind.ERROR - } - - override fun toString() = psiType.canonicalText - - override fun equals(other: Any?): Boolean{ - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - return psiType == (other as? JePrimitiveType)?.psiType - } - - override fun hashCode() = psiType.hashCode() -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JePsiType.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JePsiType.kt deleted file mode 100644 index 65bc1b8583d..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JePsiType.kt +++ /dev/null @@ -1,49 +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.java.model.types - -import com.intellij.openapi.Disposable -import com.intellij.openapi.components.ServiceManager -import com.intellij.psi.PsiManager -import com.intellij.psi.PsiType -import org.jetbrains.kotlin.java.model.internal.JeElementRegistry -import org.jetbrains.kotlin.java.model.util.disposeAll -import org.jetbrains.kotlin.java.model.util.toDisposable - -interface JePsiType : JeTypeMirror { - val psiType: PsiType -} - -abstract class JePsiTypeBase( - psiType: T, - manager: PsiManager -) : JePsiType, JeTypeWithManager, Disposable { - private val disposableManager = manager.toDisposable() - private val disposableType = psiType.toDisposable() - - init { - ServiceManager.getService(manager.project, JeElementRegistry::class.java).register(this) - } - - override fun dispose() = disposeAll(disposableManager, disposableType) - - override val psiManager: PsiManager - get() = disposableManager() - - override val psiType: T - get() = disposableType() -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeTypeMirror.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeTypeMirror.kt deleted file mode 100644 index 43f01cac296..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeTypeMirror.kt +++ /dev/null @@ -1,32 +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.java.model.types - -import javax.lang.model.element.AnnotationMirror -import javax.lang.model.type.TypeMirror - -//TODO support type annotations -interface JeTypeMirror : TypeMirror { - override fun getAnnotationMirrors() = emptyList() - - override fun getAnnotation(annotationClass: Class?) = null - - @Suppress("UNCHECKED_CAST") - override fun getAnnotationsByType(annotationType: Class): Array { - return java.lang.reflect.Array.newInstance(annotationType, 0) as Array - } -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeTypeVariableType.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeTypeVariableType.kt deleted file mode 100644 index 55c5d1ffdba..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeTypeVariableType.kt +++ /dev/null @@ -1,78 +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.java.model.types - -import com.intellij.psi.PsiClassType -import com.intellij.psi.PsiIntersectionType -import com.intellij.psi.PsiManager -import com.intellij.psi.PsiTypeParameter -import org.jetbrains.kotlin.java.model.elements.JeTypeParameterElement -import org.jetbrains.kotlin.java.model.toJeElement -import org.jetbrains.kotlin.java.model.util.toDisposable -import javax.lang.model.type.TypeKind -import javax.lang.model.type.TypeMirror -import javax.lang.model.type.TypeVariable -import javax.lang.model.type.TypeVisitor - -class JeTypeVariableType( - psiType: PsiClassType, - parameter: PsiTypeParameter -) : JePsiTypeBase(psiType, parameter.manager), TypeVariable { - private val disposableParameter = parameter.toDisposable() - - val parameter: PsiTypeParameter - get() = disposableParameter() - - // JeElementRegistry registration is done in JeDisposablePsiElementOwner - override fun dispose() { - super.dispose() - disposableParameter.dispose() - } - - override fun getKind() = TypeKind.TYPEVAR - - override fun accept(v: TypeVisitor, p: P) = v.visitTypeVariable(this, p) - - override val psiManager: PsiManager - get() = parameter.manager - - override fun getLowerBound(): TypeMirror? { - //TODO support captured lower bounds - return JeNullType - } - - override fun getUpperBound(): TypeMirror? { - val superTypes = parameter.superTypes - return if (superTypes.size == 1) { - superTypes.first().toJeType(psiManager) - } else { - PsiIntersectionType.createIntersection(*superTypes).toJeType(psiManager) - } - } - - override fun asElement() = JeTypeParameterElement(parameter, parameter.owner.toJeElement()) - - override fun equals(other: Any?): Boolean{ - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - return psiType == (other as? JeTypeVariableType)?.psiType - } - - override fun toString() = parameter.name ?: "" - - override fun hashCode() = psiType.hashCode() -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeTypeWithManager.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeTypeWithManager.kt deleted file mode 100644 index f600435ac98..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeTypeWithManager.kt +++ /dev/null @@ -1,23 +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.java.model.types - -import com.intellij.psi.PsiManager - -interface JeTypeWithManager : JeTypeMirror { - val psiManager: PsiManager -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeWildcardType.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeWildcardType.kt deleted file mode 100644 index 877ff40f83b..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeWildcardType.kt +++ /dev/null @@ -1,93 +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.java.model.types - -import com.intellij.psi.PsiCapturedWildcardType -import com.intellij.psi.PsiManager -import com.intellij.psi.PsiWildcardType -import javax.lang.model.type.TypeKind -import javax.lang.model.type.TypeVisitor -import javax.lang.model.type.WildcardType - -class JeWildcardType( - psiType: PsiWildcardType, - private val isRaw: Boolean -) : JePsiTypeBase(psiType, psiType.manager), WildcardType { - override fun getKind() = TypeKind.WILDCARD - override fun accept(v: TypeVisitor, p: P) = v.visitWildcard(this, p) - - override fun getSuperBound() = psiType.superBound.toJeType(psiManager, isRaw = isRaw) - override fun getExtendsBound() = psiType.extendsBound.toJeType(psiManager, isRaw = isRaw) - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - other as? JeWildcardType ?: return false - - return superBound == other.superBound - && extendsBound == other.extendsBound - && isRaw == other.isRaw - } - - override fun hashCode(): Int { - var result = superBound.hashCode() - result = 31 * result + extendsBound.hashCode() - result = 31 * result + isRaw.hashCode() - return result - } - - override fun toString() = when { - psiType.isExtends -> "? extends $extendsBound" - psiType.isSuper -> "? super $superBound" - else -> "?" - } -} - -class JeCapturedWildcardType( - psiType: PsiCapturedWildcardType, - psiManager: PsiManager, - private val isRaw: Boolean -) : JePsiTypeBase(psiType, psiManager), WildcardType { - override fun getKind() = TypeKind.WILDCARD - override fun accept(v: TypeVisitor, p: P) = v.visitWildcard(this, p) - - override fun getSuperBound() = psiType.lowerBound.toJeType(psiManager, isRaw = isRaw) - override fun getExtendsBound() = psiType.upperBound.toJeType(psiManager, isRaw = isRaw) - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other::class.java != this::class.java) return false - other as? JeCapturedWildcardType ?: return false - - return superBound == other.superBound - && extendsBound == other.extendsBound - && isRaw == other.isRaw - } - - override fun hashCode(): Int { - var result = superBound.hashCode() - result = 31 * result + extendsBound.hashCode() - result = 31 * result + isRaw.hashCode() - return result - } - - override fun toString() = when { - psiType.wildcard.isSuper -> "? extends $extendsBound" - psiType.wildcard.isExtends -> "? super $superBound" - else -> "?" - } -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/noTypes.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/noTypes.kt deleted file mode 100644 index 2b071087241..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/noTypes.kt +++ /dev/null @@ -1,54 +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.java.model.types - -import javax.lang.model.type.* - -interface JeNoType : JeTypeMirror, NoType - -object JePackageTypeMirror : JeNoType { - override fun getKind() = TypeKind.PACKAGE - override fun accept(v: TypeVisitor, p: P) = v.visitNoType(this, p) - override fun toString() = "" -} - -object JeNoneType : JeNoType { - override fun getKind() = TypeKind.NONE - override fun accept(v: TypeVisitor, p: P) = v.visitNoType(this, p) - override fun toString() = "" -} - -object JeVoidType : JeNoType { - override fun getKind() = TypeKind.VOID - override fun accept(v: TypeVisitor, p: P) = v.visitNoType(this, p) - override fun toString() = "void" -} - -object JeErrorType : JeNoType { - override fun getKind() = TypeKind.ERROR - override fun accept(v: TypeVisitor, p: P) = v.visitNoType(this, p) - override fun toString() = "" -} - -object JeDeclaredErrorType : JeNoType, DeclaredType { - override fun getKind() = TypeKind.ERROR - override fun accept(v: TypeVisitor, p: P) = v.visitNoType(this, p) - - override fun getTypeArguments() = emptyList() - override fun asElement() = null - override fun getEnclosingType() = JeNoneType -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/types.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/types.kt deleted file mode 100644 index a19f4276a55..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/types.kt +++ /dev/null @@ -1,62 +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. - */ - -@file:JvmName("JeTypeUtils") -package org.jetbrains.kotlin.java.model.types - -import com.intellij.psi.* -import javax.lang.model.type.TypeKind -import javax.lang.model.type.TypeMirror -import java.lang.reflect.Array as RArray - -private val PSI_PRIMITIVES_MAP = listOf( - PsiType.BYTE, PsiType.CHAR, PsiType.DOUBLE, - PsiType.FLOAT, PsiType.INT, PsiType.LONG, - PsiType.SHORT, PsiType.BOOLEAN -).associate { it to JePrimitiveType(it) } - -private val TYPE_KIND_TO_PSI_PRIMITIVE_MAP = mapOf( - TypeKind.BYTE to PsiType.BYTE, - TypeKind.CHAR to PsiType.CHAR, - TypeKind.DOUBLE to PsiType.DOUBLE, - TypeKind.FLOAT to PsiType.FLOAT, - TypeKind.INT to PsiType.INT, - TypeKind.LONG to PsiType.LONG, - TypeKind.SHORT to PsiType.SHORT, - TypeKind.BOOLEAN to PsiType.BOOLEAN) - -fun TypeKind?.toJePrimitiveType() = PSI_PRIMITIVES_MAP[TYPE_KIND_TO_PSI_PRIMITIVE_MAP[this]] - -fun PsiType.toJePrimitiveType() = PSI_PRIMITIVES_MAP[this] - -fun PsiType.toJeType(manager: PsiManager, isRaw: Boolean = false): TypeMirror = when (this) { - PsiType.VOID -> JeVoidType - PsiType.NULL -> JeNullType - is PsiPrimitiveType -> PSI_PRIMITIVES_MAP[this] ?: JeErrorType - is PsiArrayType -> JeArrayType(this, manager, isRaw) - is PsiWildcardType -> JeWildcardType(this, isRaw) - is PsiCapturedWildcardType -> JeCapturedWildcardType(this, manager, isRaw) - is PsiClassType -> { - val resolvedClass = this.resolve() - when (resolvedClass) { - is PsiTypeParameter -> JeTypeVariableType(this, resolvedClass) - is PsiClass -> JeDeclaredType(this, resolvedClass, isRaw = isRaw) - else -> JeErrorType - } - } - is PsiIntersectionType -> JeIntersectionType(this, manager, isRaw) - else -> JeErrorType -} \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/util/DisposableRef.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/util/DisposableRef.kt deleted file mode 100644 index 3a4396ae589..00000000000 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/util/DisposableRef.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.java.model.util - -import com.intellij.openapi.Disposable - -class DisposableRef(initialValue: T): Disposable { - @Volatile - private var value: T? = initialValue - - operator fun invoke() = value ?: throw IllegalStateException("Reference is disposed") - - override fun dispose() { - value = null - } -} - -fun T.toDisposable() = DisposableRef(this) - -fun disposeAll(vararg refs: DisposableRef<*>?) { - refs.forEach { it?.dispose() } -} diff --git a/plugins/plugins-tests/plugins-tests.iml b/plugins/plugins-tests/plugins-tests.iml index 4922c477991..bb54d63ef5b 100755 --- a/plugins/plugins-tests/plugins-tests.iml +++ b/plugins/plugins-tests/plugins-tests.iml @@ -31,10 +31,8 @@ - - diff --git a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/AbstractProcessorTest.kt b/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/AbstractProcessorTest.kt deleted file mode 100755 index 001365a9a97..00000000000 --- a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/AbstractProcessorTest.kt +++ /dev/null @@ -1,178 +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.test.processor - -import com.intellij.openapi.extensions.Extensions -import com.intellij.testFramework.registerServiceInstance -import org.jetbrains.kotlin.annotation.AbstractAnnotationProcessingExtension -import org.jetbrains.kotlin.annotation.processing.diagnostic.DefaultErrorMessagesAnnotationProcessing -import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles -import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment -import org.jetbrains.kotlin.codegen.AbstractBytecodeTextTest -import org.jetbrains.kotlin.codegen.CodegenTestUtil -import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages -import org.jetbrains.kotlin.java.model.elements.JeAnnotationMirror -import org.jetbrains.kotlin.java.model.elements.JeMethodExecutableElement -import org.jetbrains.kotlin.java.model.elements.JeTypeElement -import org.jetbrains.kotlin.java.model.elements.JeVariableElement -import org.jetbrains.kotlin.java.model.internal.JeElementRegistry -import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension -import org.jetbrains.kotlin.test.ConfigurationKind -import org.jetbrains.kotlin.test.KotlinTestUtils -import org.jetbrains.kotlin.test.TestJdkKind -import java.io.File -import java.nio.file.Files -import javax.annotation.processing.Completion -import javax.annotation.processing.ProcessingEnvironment -import javax.annotation.processing.Processor -import javax.annotation.processing.RoundEnvironment -import javax.lang.model.SourceVersion -import javax.lang.model.element.* - -class AnnotationProcessingExtensionForTests( - val processors: List -) : AbstractAnnotationProcessingExtension(createTempDir(), createTempDir(), listOf(), true, - createIncrementalDataFile()) { - override fun loadAnnotationProcessors() = processors - - override val options: Map - get() = emptyMap() - - private companion object { - fun createTempDir(): File = Files.createTempDirectory("ap-test").toFile().apply { - deleteOnExit() - } - - fun createIncrementalDataFile(): File = File.createTempFile("incrementalData", "txt").apply { - deleteOnExit() - } - } -} - -abstract class AbstractProcessorTest : AbstractBytecodeTextTest() { - abstract val testDataDir: String - - private fun createTestEnvironment(processors: List): KotlinCoreEnvironment { - val configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK) - val environment = KotlinCoreEnvironment.createForTests(testRootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES) - val project = environment.project - - val apExtension = AnnotationProcessingExtensionForTests(processors) - AnalysisHandlerExtension.registerExtension(project, apExtension) - - project.registerServiceInstance(JeElementRegistry::class.java, JeElementRegistry()) - - Extensions.getRootArea().getExtensionPoint(DefaultErrorMessages.Extension.EP_NAME) - .registerExtension(DefaultErrorMessagesAnnotationProcessing()) - - return environment - } - - fun doTest(path: String, processors: List) { - myEnvironment = createTestEnvironment(processors) - - loadFileByFullPath(path) - CodegenTestUtil.generateFiles(myEnvironment, myFiles) - } - - protected fun Element.assertHasAnnotation(fqName: String, vararg parameterValues: Any?) { - val annotation = annotationMirrors.first { it is JeAnnotationMirror && it.psi.qualifiedName == fqName } - val actualValues = annotation.elementValues.values - assertEquals(parameterValues.size, actualValues.size) - - for ((expected, actual) in parameterValues.zip(actualValues)) { - assertEquals(expected, actual.value) - } - } - - protected fun test( - name: String, - vararg supportedAnnotations: String, - process: (Set, RoundEnvironment, ProcessingEnvironment) -> Unit - ) = testAP(true, name, process, *supportedAnnotations) - - protected fun testShouldNotRun( - name: String, - vararg supportedAnnotations: String - ) = testAP(false, name, { _, _, _ -> fail("Should not run") }, *supportedAnnotations) - - protected fun testAP( - shouldRun: Boolean, - name: String, - process: (Set, RoundEnvironment, ProcessingEnvironment) -> Unit, - vararg supportedAnnotations: String - ) { - val ktFileName = File(testDataDir, name + ".kt") - var started = false - val processor = object : Processor { - lateinit var processingEnv: ProcessingEnvironment - - override fun getSupportedOptions() = setOf() - - override fun process(annotations: Set, roundEnv: RoundEnvironment): Boolean { - if (!roundEnv.processingOver()) { - started = true - process(annotations, roundEnv, processingEnv) - } - return true - } - - override fun init(env: ProcessingEnvironment) { - processingEnv = env - } - - override fun getCompletions( - element: Element?, - annotation: AnnotationMirror?, - member: ExecutableElement?, - userText: String? - ): Iterable? { - return emptyList() - } - - override fun getSupportedSourceVersion() = SourceVersion.RELEASE_6 - override fun getSupportedAnnotationTypes() = supportedAnnotations.toSet() - } - - doTest(ktFileName.canonicalPath, listOf(processor)) - - if (started != shouldRun) { - fail("Annotation processor " + (if (shouldRun) "was not started" else "was started")) - } - } - - protected fun TypeElement.findMethods(name: String): List { - return enclosedElements.filterIsInstance().filter { it.simpleName.toString() == name } - } - - protected fun TypeElement.findMethod(name: String, vararg parameterTypes: String): JeMethodExecutableElement { - return enclosedElements.first { - if (it !is JeMethodExecutableElement - || it.simpleName.toString() != name - || parameterTypes.size != it.parameters.size) return@first false - parameterTypes.zip(it.parameters).all { it.first == it.second.asType().toString() } - } as JeMethodExecutableElement - } - - protected fun TypeElement.findField(name: String): JeVariableElement { - return enclosedElements.first { it is JeVariableElement && it.simpleName.toString() == name } as JeVariableElement - } - - protected fun ProcessingEnvironment.findClass(fqName: String) = elementUtils.getTypeElement(fqName) as JeTypeElement - - protected fun assertEquals(expected: String, actual: Name) = assertEquals(expected, actual.toString()) -} \ No newline at end of file diff --git a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/ElementsTests.kt b/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/ElementsTests.kt deleted file mode 100644 index 8309f933ad1..00000000000 --- a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/ElementsTests.kt +++ /dev/null @@ -1,138 +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.test.processor - -import org.jetbrains.kotlin.annotation.processing.impl.KotlinElements -import org.jetbrains.kotlin.java.model.elements.JeTypeElement -import org.jetbrains.kotlin.java.model.types.JeArrayType -import javax.lang.model.element.ExecutableElement -import javax.lang.model.element.TypeElement - -class ElementsTests : AbstractProcessorTest() { - override val testDataDir = "plugins/annotation-processing/testData/elements" - - fun testOverrides() = test("Overrides", "*") { _, _, env -> - val (parent, child, childChild) = Triple(env.findClass("Parent"), env.findClass("Child"), env.findClass("ChildOfChild")) - - val parentA = parent.findMethod("a") - - val childA = child.findMethod("a") - val childAString = child.findMethod("a", "java.lang.String") - val childB = child.findMethod("b") - - val childChildA = childChild.findMethod("a") - val childChildACharSequence = childChild.findMethod("a", "java.lang.CharSequence") - val childChildB = childChild.findMethod("b") - - fun ExecutableElement.assertOverrides(overridden: ExecutableElement, result: Boolean) { - assertEquals(result, env.elementUtils.overrides(this, overridden, enclosingElement as JeTypeElement)) - } - - parentA.assertOverrides(parentA, false) - childA.assertOverrides(parentA, true) - childAString.assertOverrides(childA, false) - childB.assertOverrides(parentA, false) - childChildA.assertOverrides(parentA, true) - childChildA.assertOverrides(childA, true) - childChildB.assertOverrides(childB, true) - childChildACharSequence.assertOverrides(childA, false) - } - - fun testOverrides2() = test("Overrides2", "*") { _, _, env -> - val classes = listOf(env.findClass("Intf"), env.findClass("A"), env.findClass("B")) - val (intf, a, b) = classes.map { it.findMethod("a") } - - fun ExecutableElement.assertOverrides(overridden: ExecutableElement, context: TypeElement, result: Boolean) { - assertEquals(result, env.elementUtils.overrides(this, overridden, context)) - } - - a.assertOverrides(intf, classes[1], false) - b.assertOverrides(a, classes[2], true) - b.assertOverrides(intf, classes[2], true) - a.assertOverrides(intf, classes[2], true) - } - - fun testIsFunctionalInterface() = test("IsFunctionalInterface", "*") { _, _, env -> - with (env.elementUtils as KotlinElements) { - fun assertIsFunctionalInterface(fqName: String, isIntf: Boolean) { - assertEquals(isIntf, isFunctionalInterface(env.findClass(fqName))) - } - - assertIsFunctionalInterface("A", false) - assertIsFunctionalInterface("A.AA", true) - assertIsFunctionalInterface("B", false) - assertIsFunctionalInterface("C", true) - assertIsFunctionalInterface("D", false) - assertIsFunctionalInterface("E", true) - assertIsFunctionalInterface("F", false) - } - } - - fun testIsDeprecated() = test("IsDeprecated", "*") { _, _, env -> - with (env.elementUtils) { - assertEquals(true, isDeprecated(env.findClass("Depr"))) - assertEquals(false, isDeprecated(env.findClass("NoDepr"))) - assertEquals(true, isDeprecated(env.findClass("JavaDepr"))) - } - } - - fun testGetElementValuesWithDefaults() = test("GetElementValuesWithDefaults", "Anno") { _, _, env -> - val (a, b, c, d) = listOf(env.findClass("A"), env.findClass("B"), env.findClass("C"), env.findClass("D")) - fun getValues(e: JeTypeElement) = env.elementUtils - .getElementValuesWithDefaults(e.annotationMirrors.first { it.psi.qualifiedName == "Anno" }) - .values.map { it.value } - - assertEquals(listOf("Tom", 10), getValues(a)) - assertEquals(listOf("Tom", 20), getValues(b)) - assertEquals(listOf("Mary", 10), getValues(c)) - assertEquals(listOf("Mary", 20), getValues(d)) - } - - fun testGetAllMembers() = test("GetAllMembers", "*") { _, _, env -> - val clazz = env.findClass("MyClass") - val members = clazz.enclosedElements - assertEquals(5, members.size) // constructor, field, getter/setter, arbitrary method - - val allMembers = env.elementUtils.getAllMembers(clazz) - assertEquals(17, allMembers.size) - assertEquals(", clone, equals, finalize, getClass, getMyProperty, hashCode, myFunction, myProperty, " + - "notify, notifyAll, registerNatives, setMyProperty, toString, wait, wait, wait", - allMembers.sortedBy { it.simpleName.toString() }.joinToString { it.simpleName }) - } - - fun testGetPackageOf() = test("GetPackageOf", "*") { _, _, env -> - val e = env.elementUtils - - val myClass = env.findClass("test.MyClass") - val packageElement = e.getPackageOf(myClass) - assertEquals("test", packageElement.qualifiedName) - assertEquals(packageElement, e.getPackageOf(packageElement)) - - assertNull(e.getPackageElement("SomethingStrange")) - val testPackageElement = e.getPackageElement("test") - assertEquals(packageElement, testPackageElement) - assertFalse(packageElement.isUnnamed) - val classes = packageElement.enclosedElements.filterIsInstance() - assertEquals(3, classes.size) - } - - fun testGetArrayType() = test("GetPackageOf", "*") { _, _, env -> - val myClass = env.findClass("test.MyClass").asType() - val array = env.typeUtils.getArrayType(myClass) - assert(array is JeArrayType) - } -} \ No newline at end of file diff --git a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/ProcessorTests.kt b/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/ProcessorTests.kt deleted file mode 100644 index b96cd1a56ec..00000000000 --- a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/ProcessorTests.kt +++ /dev/null @@ -1,374 +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.test.processor - -import org.intellij.lang.annotations.Language -import org.jetbrains.kotlin.annotation.processing.impl.KotlinProcessingEnvironment -import org.jetbrains.kotlin.java.model.elements.* -import org.jetbrains.kotlin.java.model.types.JeDeclaredType -import org.jetbrains.kotlin.java.model.types.JeMethodExecutableTypeMirror -import org.jetbrains.kotlin.java.model.util.DisposableRef -import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension -import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance -import javax.annotation.processing.ProcessingEnvironment -import javax.lang.model.element.AnnotationMirror -import javax.lang.model.element.Element -import javax.lang.model.type.DeclaredType -import javax.lang.model.type.TypeMirror -import javax.lang.model.type.TypeVariable - -// See EnumArray.kt -enum class RGBColors { RED, GREEN, BLUE } -annotation class ColorsAnnotation(val colors: Array) - -class ProcessorTests : AbstractProcessorTest() { - override val testDataDir = "plugins/annotation-processing/testData/processors" - - fun testSimple() = test("Simple", "Anno") { set, roundEnv, _ -> - assertEquals(1, set.size) - val annotated = roundEnv.getElementsAnnotatedWith(set.first()) - assertEquals(3, annotated.size) - - val clazz = annotated.firstIsInstance() - val method = annotated.firstIsInstance() - val field = annotated.firstIsInstance() - - listOf(clazz, method, field).forEach { - it.assertHasAnnotation("Anno", it.simpleName.toString() + "Anno") - } - } - - fun testSeveralAnnotations() = test("SeveralAnnotations", "Name", "Age") { set, roundEnv, _ -> - val annos = set.toList() - - assertEquals(2, annos.size) - val annotated1 = roundEnv.getElementsAnnotatedWith(annos[0]).sortedBy { it.simpleName.toString() } - val annotated2 = roundEnv.getElementsAnnotatedWith(annos[1]).sortedBy { it.simpleName.toString() } - assertEquals(2, annotated1.size) - assertEquals(annotated1, annotated2) - - val (kate, mary) = Pair(annotated1[0] as JeTypeElement, annotated1[1] as JeTypeElement) - assertEquals("Mary", mary.simpleName) - with (kate) { - assertEquals("Kate", simpleName) - assertHasAnnotation("Name", "Kate") - assertHasAnnotation("Age", 22) - } - } - - fun testStar() = test("Star", "*") { set, _, _ -> - assertEquals(true, set.any { it.qualifiedName.toString() == "Anno" }) - } - - fun testStar2() = test("Star", "Anno", "*") { set, _, _ -> - assertEquals(true, set.any { it.qualifiedName.toString() == "Anno" }) - } - - fun testStar3() = test("Star3", "Anno", "*") { set, _, _ -> - assertEquals(true, set.any { it.qualifiedName.toString() == "Anno2" }) - } - - fun testDoesNotRun() = testShouldNotRun("DoesNotRun", "Anno") - fun testDoesNotRun2() = testShouldNotRun("DoesNotRun2", "Anno") - - fun testInheritedAnnotations() { - val handledClasses = mutableListOf() - test("InheritedAnnotations", "Anno") { set, roundEnv, _ -> - assertEquals(1, set.size) - val annotatedElements = roundEnv.getElementsAnnotatedWith(set.first()) - for (element in annotatedElements) { - handledClasses += element.simpleName.toString() - } - - val implAnnotations = annotatedElements.first { it.simpleName.toString() == "Impl" }.annotationMirrors - // Should contain the inherited annotation - assertEquals(1, implAnnotations.size) - assertEquals("Anno", (implAnnotations.first() as JeAnnotationMirror).psi.qualifiedName) - } - // IntfImpl should not be here. Annotations can be inherited only from superclasses (not interfaces). - assertEquals(listOf("Base", "Impl", "Intf"), handledClasses.sorted()) - } - - fun testInheritedAnnotationsOverridden() = test("InheritedAnnotationsOverridden", "Anno") { set, roundEnv, _ -> - assertEquals(1, set.size) - val annotatedElements = roundEnv.getElementsAnnotatedWith(set.first()) - assertEquals(2, annotatedElements.size) - val implAnnotations = annotatedElements.first { it.simpleName.toString() == "Impl" }.annotationMirrors - assertEquals(1, implAnnotations.size) - assertEquals("Tom", implAnnotations.first().elementValues.values.first().value) - } - - fun testNested() = test("Nested", "Anno") { set, roundEnv, _ -> - assertEquals(1, set.size) - val annotatedElements = roundEnv.getElementsAnnotatedWith(set.first()) - assertEquals(1, annotatedElements.size) - val test = annotatedElements.first() - val anno2 = test.annotationMirrors.first { it is JeAnnotationMirror && it.psi.qualifiedName == "Anno" } - - fun AnnotationMirror.getParam(name: String) = elementValues.entries.first { it.key.simpleName.toString() == name }.value - assertTrue(anno2.getParam("a") is JeAnnotationAnnotationValue) - assertTrue((anno2.getParam("b") as JeArrayAnnotationValue).value.first() is JeAnnotationAnnotationValue) - assertTrue(anno2.getParam("c") is JePrimitiveAnnotationValue<*>) - assertTrue(anno2.getParam("d") is JeTypeAnnotationValue) - assertTrue((anno2.getParam("e") as JeArrayAnnotationValue).value.first() is JeTypeAnnotationValue) - } - - fun testEnumArray() = test("EnumArray", "*") { _, _, env -> - val testClass = env.findClass("org.jetbrains.kotlin.annotation.processing.test.processor.Test") - val enumAnno = testClass.getAnnotation(ColorsAnnotation::class.java) - assertNotNull(enumAnno) - assertEquals(listOf("BLUE", "RED"), enumAnno!!.colors.map { it.name }) - } - - fun testStringArray() = test("StringArray", "*") { _, _, env -> - val testClass = env.findClass("Test") - val suppress = testClass.getAnnotation(Suppress::class.java) - assertNotNull(suppress) - assertEquals(listOf("Tom", "Mary"), suppress!!.names.toList()) - } - - fun testTypeArguments() = test("TypeArguments", "*") { _, _, env -> - val classA = env.findClass("A") - val superB = classA.superclass as JeDeclaredType - val interfaceC = classA.interfaces[0] as JeDeclaredType - - assertTrue(superB.typeArguments.size == 1) - assertTrue(interfaceC.typeArguments.size == 1) - } - - fun testTypeArguments2() = test("TypeArguments2", "*") { _, _, env -> - val b = env.findClass("B") - val bSuperTypes = env.typeUtils.directSupertypes(b.asType()) - assertEquals(1, bSuperTypes.size) - val bASuperTypes = env.typeUtils.directSupertypes(bSuperTypes.first()) - assertEquals(2, bASuperTypes.size) // Object and I - - fun List.iInterface() = first { it.toString().matches("I(<.*>)?".toRegex()) } as DeclaredType - - val bai = bASuperTypes.iInterface() - assertEquals(1, bai.typeArguments.size) - assertEquals("java.lang.String", bai.typeArguments.first().toString()) - - val c = env.findClass("C") - val cSuperTypes = env.typeUtils.directSupertypes(c.asType()) - assertEquals(1, cSuperTypes.size) - val cai = env.typeUtils.directSupertypes(cSuperTypes.first()).iInterface() - assertEquals(1, cai.typeArguments.size) - val typeArg = cai.typeArguments.first() - assertTrue(typeArg is TypeVariable) - - val a2 = env.findClass("A2") - val i2 = env.typeUtils.directSupertypes(a2.asType()).first { it.toString().matches("I2(<.*>)?".toRegex()) } as JeDeclaredType - assertEquals("I2", i2.toString()) - - val stringType = env.elementUtils.getTypeElement("java.lang.String").asType() - val a3 = env.findClass("A3") - val resolvedA3 = env.typeUtils.getDeclaredType(a3, stringType) - val i3 = env.typeUtils.directSupertypes(resolvedA3).first { it.toString().matches("I3(<.*>)?".toRegex()) } as JeDeclaredType - assertEquals("I3>", i3.toString()) - } - - fun testErasureSimple() = test("ErasureSimple", "*") { _, _, env -> - val test = env.findClass("Test") - val int = test.findMethod("a").returnType - val void = test.findMethod("b").returnType - assertEquals(int, env.typeUtils.erasure(int)) - assertEquals(void, env.typeUtils.erasure(void)) - } - - fun testErasure2() = test("Erasure2", "*") { _, _, env -> - val erasure = fun (t: JeMethodExecutableTypeMirror) = env.typeUtils.erasure(t) - fun JeTypeElement.check(methodName: String, toString: String, transform: (JeMethodExecutableTypeMirror) -> TypeMirror = { it }) { - val method = enclosedElements.first { it is JeMethodExecutableElement && it.simpleName.toString() == methodName } - assertEquals(toString, transform((method as JeMethodExecutableElement).asType()).toString()) - } - - with (env.findClass("Test")) { - val classType = asType() as DeclaredType - assertEquals(1, classType.typeArguments.size) - assertEquals("Test", classType.toString()) - - val erasedType = env.typeUtils.erasure(asType()) as DeclaredType - assertEquals(0, erasedType.typeArguments.size) - assertEquals("Test", erasedType.toString()) - - check("a", "()java.lang.String") - check("b", "(java.lang.String,java.lang.CharSequence)void") - check("c", "()int") - - check("d", "()T") - check("e", "(D)D") - check("e", "(java.lang.Object)java.lang.Object", erasure) - check("f", "(java.util.List>,int)void") - check("f", "(java.util.List,int)void", erasure) - check("g", "(D)void") - check("g", "(java.lang.String)void", erasure) - check("h", "()java.util.List[]") - check("h", "()java.util.List[]", erasure) - check("i", "()T") - check("i", "()java.lang.CharSequence", erasure) - } - - with (env.findClass("Test2")) { - assertEquals("Test2", asType().toString()) - assertEquals("Test2", env.typeUtils.erasure(asType()).toString()) - - check("a", "(A)void") - check("a", "(java.util.List)void", erasure) - check("b", "()B") - check("b", "()java.util.List", erasure) - } - } - - fun testIncrementalDataSimple() = incrementalDataTest( - "IncrementalDataSimple", - "i Intf, i Test, i Test2, i Test3, i Test6, i Test7, i Test8") - - fun testIncrementalDataKotlinAnnotations() = incrementalDataTest( - "KotlinAnnotations", - "i AnnoAnnotated") - - private fun getKapt2Extension() = AnalysisHandlerExtension.getInstances(myEnvironment.project) - .firstIsInstance() - - private fun incrementalDataTest(fileName: String, @Language("TEXT") expectedText: String) { - test(fileName, "Anno", "Anno2", "Anno3") { _, _, _ -> } - val ext = getKapt2Extension() - val incrementalDataFile = ext.incrementalDataFile - assertNotNull(incrementalDataFile) - val text = incrementalDataFile!!.readText().lines().sorted().joinToString(", ") - assertEquals(expectedText, text) - } - - fun testKotlinAnnotationDefaultValueFromBinary() = test("DefaultValueFromBinary", "*") { _, _, env -> - fun check(expectedValue: Boolean, className: String) { - val clazz = env.findClass(className) - val anno = clazz.getAnnotation(JvmSuppressWildcards::class.java)!! - assertEquals(expectedValue, anno.suppress) - } - - check(true, "Test") - check(true, "TestTrue") - check(false, "TestFalse") - } - - fun testAsMemberOf() = test("AsMemberOf", "*") { _, _, env -> - val f = env.findClass("Test").findField("f") - val fType = f.asType() as JeDeclaredType - - val base = env.findClass("Base") - val impl = env.findClass("Impl") - val baseF = base.findField("f") - val baseM = base.findMethod("m", "T") - val implM = impl.findMethod("implM", "T") - - fun check(element: Element, expectedTypeSignature: String) { - assertEquals(expectedTypeSignature, env.typeUtils.asMemberOf(fType, element).toString()) - } - - assertEquals("(T)T", baseM.asType().toString()) - check(baseM, "(java.lang.String)java.lang.String") - - assertEquals("T", baseF.asType().toString()) - check(baseF, "java.lang.String") - - assertEquals("(T)T", implM.asType().toString()) - check(implM, "(java.lang.String)java.lang.String") - } - - fun testAsMemberOfTypeParameters() = test("AsMemberOfTypeParameters", "*") { _, _, env -> - val intf = env.findClass("Intf") - val intfT = intf.typeParameters[0] - val base = env.findClass("Base") - val baseFactory = base.findMethod("factory") - val impl = env.findClass("Impl") - - assertEquals("T", intfT.asType().toString()) - - val implT = env.typeUtils.asMemberOf(impl.asType() as DeclaredType, intfT) - assertEquals("java.lang.String", implT.toString()) - - val baseT = env.typeUtils.asMemberOf(baseFactory.returnType as DeclaredType, intfT) - assertEquals("java.lang.CharSequence", baseT.toString()) - } - - fun testDispose() { - var savedEnv: ProcessingEnvironment? = null - - test("AsMemberOf", "*") { _, _, env -> - savedEnv = env - } - - fun T.test(f: T.() -> Unit) { - var exceptionCaught = false - try { - f() - } - catch (e: IllegalStateException) { - exceptionCaught = true - } - - assertEquals("Exception was not caught", true, exceptionCaught) - } - - with (savedEnv as KotlinProcessingEnvironment) { - test { elementUtils } - test { typeUtils } - test { messager } - test { options } - test { filer } - - fun testDisposable(name: String) { - test { (this::class.java.methods.first { it.name.startsWith("$name$") }.invoke(this) as DisposableRef<*>).invoke() } - } - - testDisposable("getProject") - testDisposable("getJavaPsiFacade") - testDisposable("getBindingContext") - } - } - - fun testMapMutableMap() = test("MapMutableMap", "*") { _, _, env -> - val test = env.findClass("Test") - fun test(name: String, expected: String) { - assertEquals(expected, test.findMethods(name).single().parameters.single().asType().toString()) - } - - test("a", "java.util.Map") - test("b", "java.util.Map") - test("c", "java.util.Map") - test("d", "java.util.Map") - } - - fun testExceptionDuringAp() { - class HiThere : RuntimeException() - - var kotlinEnv: KotlinProcessingEnvironment? = null - try { - test("MapMutableMap", "*") { _, _, env -> - kotlinEnv = env as KotlinProcessingEnvironment - throw HiThere() - } - } catch (e: IllegalStateException) { - assertTrue(e.message!!.startsWith("ANNOTATION_PROCESSING_ERROR")) - } - val env = kotlinEnv!! - - assertEquals(1, env.messager.errorCount) - assertEquals(0, env.messager.warningCount) - } -} \ No newline at end of file diff --git a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/TestsWithFiler.kt b/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/TestsWithFiler.kt deleted file mode 100644 index e4c9207704a..00000000000 --- a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/TestsWithFiler.kt +++ /dev/null @@ -1,74 +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.test.processor - -import java.io.File -import javax.lang.model.element.TypeElement -import javax.tools.JavaFileObject - -class TestsWithFiler : AbstractProcessorTest() { - override val testDataDir = "plugins/annotation-processing/testData/withFiler" - - fun testSimple() = filerTest("Simple", 1, "generated/Inject2Test.java") - - fun testMethodsFields() = filerTest("MethodsFields", 1, - "generated/InjectmyField.java", - "generated/InjectmyFunc.java") - - fun testTwoRounds() = filerTest("TwoRounds", 2, - "generated/Inject2InjectTest.java", - "generated/InjectTest.java", - "generated/InjectmyFunc.java") - - fun testOneRound() = filerTest("OneRound", 1, - "generated/Inject2Test.java", - "generated/Inject2myFunc.java", - "generated/InjectmyFunc.java") - - fun testZeroRounds() = filerTest("ZeroRounds", 0) - - private fun filerTest( - fileName: String, - roundCount: Int, - vararg expectedFiles: String - ) { - val filesCreated = mutableSetOf() - var actualRoundCount = 0 - - testAP(roundCount > 0, fileName, { set, roundEnv, env -> - if (!roundEnv.processingOver()) actualRoundCount++ - - for (anno in set) { - val annotated = roundEnv.getElementsAnnotatedWith(anno) - annotated.forEach { el -> - val className = anno.simpleName.toString() + el.simpleName.toString() - env.filer.createSourceFile("generated.$className").apply { - filesCreated += this - val inject2 = if (el is TypeElement && anno.simpleName.toString() == "Inject") "@Inject2\n" else "" - openWriter().use { - it.write("package generated;\n" + inject2 + - "public class $className {}") - } - } - } - } - }, "Inject", "Inject2") - - assertEquals(roundCount, actualRoundCount) - assertEquals(expectedFiles.map { it.replace('/', File.separatorChar) }, filesCreated.map { it.name }.sorted()) - } -} \ No newline at end of file diff --git a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/sourceRetention/AbstractBytecodeListingTestForSourceRetention.kt b/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/sourceRetention/AbstractBytecodeListingTestForSourceRetention.kt deleted file mode 100644 index a55e3ffcfba..00000000000 --- a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/sourceRetention/AbstractBytecodeListingTestForSourceRetention.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.test.sourceRetention - -import org.jetbrains.kotlin.codegen.AbstractBytecodeListingTest -import org.jetbrains.kotlin.codegen.ClassBuilderFactories -import org.jetbrains.kotlin.codegen.ClassBuilderFactory - -abstract class AbstractBytecodeListingTestForSourceRetention : AbstractBytecodeListingTest() { - override fun getClassBuilderFactory(): ClassBuilderFactory { - return if (getTestName(true).contains("withSource", ignoreCase = true)) - ClassBuilderFactories.TEST_WITH_SOURCE_RETENTION_ANNOTATIONS - else - ClassBuilderFactories.TEST - } - - override fun verifyWithDex(): Boolean { - return false - } -} \ No newline at end of file diff --git a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/sourceRetention/BytecodeListingTestForSourceRetentionGenerated.java b/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/sourceRetention/BytecodeListingTestForSourceRetentionGenerated.java deleted file mode 100644 index e4a1b1279b8..00000000000 --- a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/sourceRetention/BytecodeListingTestForSourceRetentionGenerated.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.annotation.processing.test.sourceRetention; - -import com.intellij.testFramework.TestDataPath; -import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.TargetBackend; -import org.jetbrains.kotlin.test.TestMetadata; -import org.junit.runner.RunWith; - -import java.io.File; -import java.util.regex.Pattern; - -/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ -@SuppressWarnings("all") -@TestMetadata("plugins/annotation-processing/testData/sourceRetention") -@TestDataPath("$PROJECT_ROOT") -@RunWith(JUnit3RunnerWithInners.class) -public class BytecodeListingTestForSourceRetentionGenerated extends AbstractBytecodeListingTestForSourceRetention { - public void testAllFilesPresentInSourceRetention() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("plugins/annotation-processing/testData/sourceRetention"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); - } - - @TestMetadata("withSource.kt") - public void testWithSource() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/sourceRetention/withSource.kt"); - doTest(fileName); - } - - @TestMetadata("withoutSource.kt") - public void testWithoutSource() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/sourceRetention/withoutSource.kt"); - doTest(fileName); - } -} diff --git a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/wrappers/AbstractAnnotationProcessingTest.kt b/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/wrappers/AbstractAnnotationProcessingTest.kt deleted file mode 100755 index 17637457259..00000000000 --- a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/wrappers/AbstractAnnotationProcessingTest.kt +++ /dev/null @@ -1,60 +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.test.wrappers - -import com.intellij.openapi.util.io.FileUtil -import com.intellij.psi.JavaPsiFacade -import com.intellij.psi.search.GlobalSearchScope -import com.intellij.testFramework.registerServiceInstance -import org.jetbrains.kotlin.codegen.AbstractBytecodeTextTest -import org.jetbrains.kotlin.codegen.CodegenTestCase -import org.jetbrains.kotlin.codegen.CodegenTestUtil -import org.jetbrains.kotlin.java.model.elements.DefaultJeElementRenderer -import org.jetbrains.kotlin.java.model.internal.JeElementRegistry -import org.jetbrains.kotlin.java.model.toJeElement -import org.jetbrains.kotlin.test.ConfigurationKind -import org.jetbrains.kotlin.test.KotlinTestUtils - -import java.io.File -import java.util.regex.Pattern - -abstract class AbstractAnnotationProcessingTest : AbstractBytecodeTextTest() { - companion object { - private val SUBJECT_FQ_NAME_PATTERN = Pattern.compile("^// FQNAME: \\s*(.*)$", Pattern.MULTILINE) - private val RENDERER = DefaultJeElementRenderer() - } - - override fun doMultiFileTest(wholeFile: File, files: List, javaFilesDir: File?) { - createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL, files, javaFilesDir) - myEnvironment.project.registerServiceInstance(JeElementRegistry::class.java, JeElementRegistry()) - - loadMultiFiles(files) - - val text = FileUtil.loadFile(wholeFile, true) - val matcher = SUBJECT_FQ_NAME_PATTERN.matcher(text) - assertTrue("No FqName specified. First line of the form '// f.q.Name' expected", matcher.find()) - val fqName = matcher.group(1) - - CodegenTestUtil.generateFiles(myEnvironment, myFiles) - val project = myEnvironment.project - val psiClass = JavaPsiFacade.getInstance(project).findClass(fqName, GlobalSearchScope.projectScope(project))!! - - val modelFile = File(wholeFile.parent, wholeFile.nameWithoutExtension + ".txt") - val jeElement = psiClass.toJeElement() ?: error("JeElement is null") - KotlinTestUtils.assertEqualsToFile(modelFile, RENDERER.render(jeElement)) - } -} \ No newline at end of file diff --git a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/wrappers/AnnotationProcessingTestGenerated.java b/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/wrappers/AnnotationProcessingTestGenerated.java deleted file mode 100644 index f851723ca28..00000000000 --- a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/wrappers/AnnotationProcessingTestGenerated.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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.annotation.processing.test.wrappers; - -import com.intellij.testFramework.TestDataPath; -import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.TargetBackend; -import org.jetbrains.kotlin.test.TestMetadata; -import org.junit.runner.RunWith; - -import java.io.File; -import java.util.regex.Pattern; - -/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ -@SuppressWarnings("all") -@TestMetadata("plugins/annotation-processing/testData/wrappers") -@TestDataPath("$PROJECT_ROOT") -@RunWith(JUnit3RunnerWithInners.class) -public class AnnotationProcessingTestGenerated extends AbstractAnnotationProcessingTest { - public void testAllFilesPresentInWrappers() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("plugins/annotation-processing/testData/wrappers"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); - } - - @TestMetadata("plugins/annotation-processing/testData/wrappers/javaWrappers") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class JavaWrappers extends AbstractAnnotationProcessingTest { - public void testAllFilesPresentInJavaWrappers() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("plugins/annotation-processing/testData/wrappers/javaWrappers"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); - } - - @TestMetadata("EnumClass.kt") - public void testEnumClass() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/wrappers/javaWrappers/EnumClass.kt"); - doTest(fileName); - } - - @TestMetadata("MetaAnnotation.kt") - public void testMetaAnnotation() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/wrappers/javaWrappers/MetaAnnotation.kt"); - doTest(fileName); - } - - @TestMetadata("Simple.kt") - public void testSimple() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/wrappers/javaWrappers/Simple.kt"); - doTest(fileName); - } - - @TestMetadata("WithNested.kt") - public void testWithNested() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/wrappers/javaWrappers/WithNested.kt"); - doTest(fileName); - } - } - - @TestMetadata("plugins/annotation-processing/testData/wrappers/kotlinWrappers") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class KotlinWrappers extends AbstractAnnotationProcessingTest { - public void testAllFilesPresentInKotlinWrappers() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("plugins/annotation-processing/testData/wrappers/kotlinWrappers"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); - } - - @TestMetadata("annotations.kt") - public void testAnnotations() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/wrappers/kotlinWrappers/annotations.kt"); - doTest(fileName); - } - - @TestMetadata("enum.kt") - public void testEnum() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/wrappers/kotlinWrappers/enum.kt"); - doTest(fileName); - } - - @TestMetadata("kotlinAnnotations.kt") - public void testKotlinAnnotations() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/wrappers/kotlinWrappers/kotlinAnnotations.kt"); - doTest(fileName); - } - - @TestMetadata("metaAnnotations.kt") - public void testMetaAnnotations() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/wrappers/kotlinWrappers/metaAnnotations.kt"); - doTest(fileName); - } - - @TestMetadata("nestedClasses.kt") - public void testNestedClasses() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/wrappers/kotlinWrappers/nestedClasses.kt"); - doTest(fileName); - } - - @TestMetadata("repeatableAnnotations.kt") - public void testRepeatableAnnotations() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/wrappers/kotlinWrappers/repeatableAnnotations.kt"); - doTest(fileName); - } - - @TestMetadata("simple.kt") - public void testSimple() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/wrappers/kotlinWrappers/simple.kt"); - doTest(fileName); - } - } -}