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 345cf8ac9c7aa2429089df51a9aeac384d830368..cb79b6d81b281603bbd664bd6705c92cbf4540d7 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 0000000000000000000000000000000000000000..9696b156fd9c17f64c6ca18b6801f54487f0d236 --- /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 b2901f3c74e3302a20b77382a5cb89e3adb83617..2c38ac263ee34b5350e0060c7610a84e8c36fe05 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