Skip to content

Commit

Permalink
[LL] don't include kotlin classes in combined java provider
Browse files Browse the repository at this point in the history
do not resolve annotations when short name doesn't match
  • Loading branch information
akozlova authored and teamcity committed Apr 27, 2023
1 parent 6ba4e37 commit d491fd2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProviderInternals
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.load.java.JavaClassFinder
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.load.java.createJavaClassFinder
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
import org.jetbrains.kotlin.name.ClassId
Expand Down Expand Up @@ -52,6 +53,7 @@ internal class LLFirCombinedJavaSymbolProvider private constructor(

private fun computeClassLikeSymbolByClassId(classId: ClassId): FirRegularClassSymbol? {
val javaClasses = javaClassFinder.findClasses(classId)
.filterNot { javaClass -> javaClass.annotations.any { it.isResolvedTo(JvmAnnotationNames.METADATA_FQ_NAME) } }
if (javaClasses.isEmpty()) return null

val (javaClass, provider) = selectFirstElementInClasspathOrder(javaClasses) { javaClass ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ val JavaClass.classKind: ClassKind
}

fun JavaClass.hasMetadataAnnotation(): Boolean =
annotations.any { it.classId?.asSingleFqName() == JvmAnnotationNames.METADATA_FQ_NAME }
annotations.any { it.isResolvedTo(JvmAnnotationNames.METADATA_FQ_NAME) }

internal fun Any?.createConstantOrError(session: FirSession): FirExpression {
return createConstantIfAny(session) ?: buildErrorExpression {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jetbrains.kotlin.name.Name;

import java.util.Collection;
import java.util.Objects;

import static org.jetbrains.kotlin.load.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.namedAnnotationArguments;

Expand Down Expand Up @@ -95,6 +96,15 @@ public boolean isIdeExternalAnnotation() {
return externalAnnotationManager.isExternalAnnotation(psi);
}

@Override
public boolean isResolvedTo(@NotNull FqName fqName) {
PsiJavaCodeReferenceElement referenceElement = getPsi().getNameReferenceElement();
if (referenceElement == null || !Objects.equals(referenceElement.getReferenceName(), fqName.shortNameOrSpecial().asString())) {
return false;
}
return getPsi().hasQualifiedName(fqName.asString());
}

@Override
public boolean isFreshlySupportedTypeUseAnnotation() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ interface JavaAnnotation : JavaElement {
val isFreshlySupportedTypeUseAnnotation: Boolean
get() = false

fun isResolvedTo(fqName: FqName) : Boolean {
return classId?.asSingleFqName() == fqName
}

fun resolve(): JavaClass?
}

Expand Down

0 comments on commit d491fd2

Please sign in to comment.