mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
J2K: more correct set of annotations to drop
This commit is contained in:
@@ -6,4 +6,10 @@
|
||||
name='com.intellij.codeInsight.NullableNotNullManager com.intellij.codeInsight.NullableNotNullManager getInstance(com.intellij.openapi.project.Project)'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.intellij.codeInsight.NullableNotNullManager java.util.List<java.lang.String> getNotNulls()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.intellij.codeInsight.NullableNotNullManager java.util.List<java.lang.String> getNullables()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
</root>
|
||||
@@ -18,14 +18,19 @@ package org.jetbrains.jet.j2k
|
||||
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.jet.j2k.ast.*
|
||||
import com.intellij.codeInsight.NullableNotNullManager
|
||||
|
||||
class AnnotationConverter(private val converter: Converter) {
|
||||
public val annotationsToRemove: Set<String> = (NullableNotNullManager.getInstance(converter.project).getNotNulls()
|
||||
+ NullableNotNullManager.getInstance(converter.project).getNullables()
|
||||
+ listOf(CommonClassNames.JAVA_LANG_OVERRIDE)).toSet()
|
||||
|
||||
public fun convertAnnotations(owner: PsiModifierListOwner): Annotations
|
||||
= (convertAnnotationsOnly(owner) + convertModifiersToAnnotations(owner)).assignNoPrototype()
|
||||
|
||||
private fun convertAnnotationsOnly(owner: PsiModifierListOwner): Annotations {
|
||||
val modifierList = owner.getModifierList()
|
||||
val annotations = modifierList?.getAnnotations()?.filter { it.getQualifiedName() !in ANNOTATIONS_TO_REMOVE }
|
||||
val annotations = modifierList?.getAnnotations()?.filter { it.getQualifiedName() !in annotationsToRemove }
|
||||
if (annotations == null || annotations.isEmpty()) return Annotations.Empty
|
||||
|
||||
val newLines = run {
|
||||
|
||||
@@ -52,7 +52,7 @@ public class Converter private(val project: Project, val settings: ConverterSett
|
||||
private val expressionVisitor = state.expressionVisitorFactory(this)
|
||||
private val statementVisitor = state.statementVisitorFactory(this)
|
||||
|
||||
private val annotationConverter = AnnotationConverter(this)
|
||||
val annotationConverter = AnnotationConverter(this)
|
||||
|
||||
class object {
|
||||
public fun create(project: Project, settings: ConverterSettings, conversionScope: ConversionScope): Converter {
|
||||
@@ -595,10 +595,6 @@ public class Converter private(val project: Project, val settings: ConverterSett
|
||||
}
|
||||
}
|
||||
|
||||
val NOT_NULL_ANNOTATIONS: Set<String> = setOf("org.jetbrains.annotations.NotNull", "com.sun.istack.internal.NotNull", "javax.annotation.Nonnull")
|
||||
val NULLABLE_ANNOTATIONS: Set<String> = setOf("org.jetbrains.annotations.Nullable", "com.sun.istack.internal.Nullable", "javax.annotation.Nullable")
|
||||
val ANNOTATIONS_TO_REMOVE: Set<String> = HashSet(NOT_NULL_ANNOTATIONS + NULLABLE_ANNOTATIONS + listOf(CommonClassNames.JAVA_LANG_OVERRIDE))
|
||||
|
||||
val PRIMITIVE_TYPE_CONVERSIONS: Map<String, String> = mapOf(
|
||||
"byte" to BYTE.asString(),
|
||||
"short" to SHORT.asString(),
|
||||
|
||||
@@ -64,8 +64,8 @@ public fun Converter.convertImport(anImport: PsiImportStatementBase, filter: Boo
|
||||
return doConvert()?.assignPrototype(anImport)
|
||||
}
|
||||
|
||||
private fun filterImport(name: String, ref: PsiJavaCodeReferenceElement): String? {
|
||||
if (name in ANNOTATIONS_TO_REMOVE) return null
|
||||
private fun Converter.filterImport(name: String, ref: PsiJavaCodeReferenceElement): String? {
|
||||
if (name in annotationConverter.annotationsToRemove) return null
|
||||
|
||||
// If imported class has a kotlin analog, drop the import
|
||||
if (!JavaToKotlinClassMap.getInstance().mapPlatformClass(FqName(name)).isEmpty()) return null
|
||||
|
||||
Reference in New Issue
Block a user