From 77aad06008de05c8e9e990a6aad3704bae3b7ec7 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 30 Nov 2020 12:27:15 +0300 Subject: [PATCH] [FE] Add bunch files to fix compilation on 201 platform --- .../java/structure/impl/JavaClassImpl.kt.201 | 6 + .../structure/impl/JavaElementUtil.java.201 | 113 ++++++++++++++++++ .../impl/classFiles/BinaryJavaClass.kt.201 | 2 + 3 files changed, 121 insertions(+) create mode 100644 compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/JavaElementUtil.java.201 diff --git a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/JavaClassImpl.kt.201 b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/JavaClassImpl.kt.201 index 345cf8ac9c7..cb79b6d81b2 100644 --- a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/JavaClassImpl.kt.201 +++ b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/JavaClassImpl.kt.201 @@ -62,6 +62,12 @@ class JavaClassImpl(psiClass: PsiClass) : JavaClassifierImpl(psiClass) override val isRecord: Boolean get() = false + override val isSealed: Boolean + get() = JavaElementUtil.isSealed(this) + + override val permittedTypes: Collection + get() = emptyList() + override val outerClass: JavaClassImpl? get() { val outer = psi.containingClass diff --git a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/JavaElementUtil.java.201 b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/JavaElementUtil.java.201 new file mode 100644 index 00000000000..9696b156fd9 --- /dev/null +++ b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/JavaElementUtil.java.201 @@ -0,0 +1,113 @@ +/* + * Copyright 2010-2015 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.load.java.structure.impl; + +import com.intellij.codeInsight.ExternalAnnotationsManager; +import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiAnnotationOwner; +import com.intellij.psi.PsiModifier; +import com.intellij.psi.PsiModifierListOwner; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.kotlin.descriptors.Visibilities; +import org.jetbrains.kotlin.descriptors.Visibility; +import org.jetbrains.kotlin.descriptors.java.JavaVisibilities; +import org.jetbrains.kotlin.load.java.structure.JavaAnnotation; +import org.jetbrains.kotlin.name.FqName; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + +import static org.jetbrains.kotlin.load.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.annotations; +import static org.jetbrains.kotlin.load.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.nullabilityAnnotations; + +/* package */ class JavaElementUtil { + private JavaElementUtil() { + } + + public static boolean isAbstract(@NotNull JavaModifierListOwnerImpl owner) { + return owner.getPsi().hasModifierProperty(PsiModifier.ABSTRACT); + } + + public static boolean isStatic(@NotNull JavaModifierListOwnerImpl owner) { + return owner.getPsi().hasModifierProperty(PsiModifier.STATIC); + } + + public static boolean isFinal(@NotNull JavaModifierListOwnerImpl owner) { + return owner.getPsi().hasModifierProperty(PsiModifier.FINAL); + } + + public static boolean isSealed(@NotNull JavaModifierListOwnerImpl owner) { + return false; + } + + @NotNull + public static Visibility getVisibility(@NotNull JavaModifierListOwnerImpl owner) { + PsiModifierListOwner psiOwner = owner.getPsi(); + if (psiOwner.hasModifierProperty(PsiModifier.PUBLIC)) { + return Visibilities.Public.INSTANCE; + } + if (psiOwner.hasModifierProperty(PsiModifier.PRIVATE)) { + return Visibilities.Private.INSTANCE; + } + if (psiOwner.hasModifierProperty(PsiModifier.PROTECTED)) { + return owner.isStatic() ? JavaVisibilities.ProtectedStaticVisibility.INSTANCE : JavaVisibilities.ProtectedAndPackage.INSTANCE; + } + return JavaVisibilities.PackageVisibility.INSTANCE; + } + + @NotNull + public static Collection getAnnotations(@NotNull JavaAnnotationOwnerImpl owner) { + PsiAnnotationOwner annotationOwnerPsi = owner.getAnnotationOwnerPsi(); + if (annotationOwnerPsi != null) { + return annotations(annotationOwnerPsi.getAnnotations()); + } + return Collections.emptyList(); + } + + @Nullable + private static PsiAnnotation[] getExternalAnnotations(@NotNull JavaModifierListOwnerImpl modifierListOwner) { + PsiModifierListOwner psiModifierListOwner = modifierListOwner.getPsi(); + ExternalAnnotationsManager externalAnnotationManager = ExternalAnnotationsManager + .getInstance(psiModifierListOwner.getProject()); + return externalAnnotationManager.findExternalAnnotations(psiModifierListOwner); + } + + @NotNull + static + Collection getRegularAndExternalAnnotations(@NotNull T owner) { + PsiAnnotation[] externalAnnotations = getExternalAnnotations(owner); + if (externalAnnotations == null) { + return getAnnotations(owner); + } + Collection annotations = new ArrayList<>(getAnnotations(owner)); + annotations.addAll(nullabilityAnnotations(externalAnnotations)); + return annotations; + } + + + @Nullable + public static JavaAnnotation findAnnotation(@NotNull JavaAnnotationOwnerImpl owner, @NotNull FqName fqName) { + PsiAnnotationOwner annotationOwnerPsi = owner.getAnnotationOwnerPsi(); + if (annotationOwnerPsi != null) { + PsiAnnotation psiAnnotation = annotationOwnerPsi.findAnnotation(fqName.asString()); + return psiAnnotation == null ? null : new JavaAnnotationImpl(psiAnnotation); + } + return null; + } +} diff --git a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt.201 b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt.201 index b2901f3c74e..2c38ac263ee 100644 --- a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt.201 +++ b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt.201 @@ -69,6 +69,8 @@ class BinaryJavaClass( override val isRecord get() = false override val lightClassOriginKind: LightClassOriginKind? get() = null + override val isSealed: Boolean get() = permittedTypes.isNotEmpty() + override val permittedTypes = arrayListOf() override fun isFromSourceCodeInScope(scope: SearchScope): Boolean = false -- GitLab