Support external annotations in IDE when approximating flexible types
This commit is contained in:
+11
-2
@@ -32,9 +32,14 @@ class LazyJavaAnnotations(
|
||||
c.resolveAnnotation(annotation)
|
||||
}
|
||||
|
||||
override fun findAnnotation(fqName: FqName) = annotationOwner.findAnnotation(fqName)?.let(annotationDescriptors)
|
||||
override fun findAnnotation(fqName: FqName) =
|
||||
annotationOwner.findAnnotation(fqName)?.let(annotationDescriptors)
|
||||
|
||||
override fun iterator() = annotationOwner.getAnnotations().sequence().map(annotationDescriptors).filterNotNull().iterator()
|
||||
override fun findExternalAnnotation(fqName: FqName) =
|
||||
c.externalAnnotationResolver.findExternalAnnotation(annotationOwner, fqName)?.let(annotationDescriptors)
|
||||
|
||||
override fun iterator() =
|
||||
annotationOwner.getAnnotations().sequence().map(annotationDescriptors).filterNotNull().iterator()
|
||||
|
||||
override fun isEmpty() = !iterator().hasNext()
|
||||
}
|
||||
@@ -47,6 +52,10 @@ class FilteredAnnotations(
|
||||
if (fqNameFilter(fqName)) delegate.findAnnotation(fqName)
|
||||
else null
|
||||
|
||||
override fun findExternalAnnotation(fqName: FqName) =
|
||||
if (fqNameFilter(fqName)) delegate.findExternalAnnotation(fqName)
|
||||
else null
|
||||
|
||||
override fun iterator() = delegate.sequence()
|
||||
.filter { annotation ->
|
||||
val descriptor = annotation.getType().getConstructor().getDeclarationDescriptor()
|
||||
|
||||
@@ -24,12 +24,16 @@ public trait Annotations : Iterable<AnnotationDescriptor> {
|
||||
|
||||
public fun findAnnotation(fqName: FqName): AnnotationDescriptor?
|
||||
|
||||
public fun findExternalAnnotation(fqName: FqName): AnnotationDescriptor?
|
||||
|
||||
companion object {
|
||||
public val EMPTY: Annotations = object : Annotations {
|
||||
override fun isEmpty() = true
|
||||
|
||||
override fun findAnnotation(fqName: FqName) = null
|
||||
|
||||
override fun findExternalAnnotation(fqName: FqName) = null
|
||||
|
||||
override fun iterator() = emptyList<AnnotationDescriptor>().iterator()
|
||||
|
||||
override fun toString() = "EMPTY"
|
||||
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* 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.descriptors.annotations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class AnnotationsImpl implements Annotations {
|
||||
private final List<AnnotationDescriptor> annotations;
|
||||
|
||||
public AnnotationsImpl(@NotNull List<AnnotationDescriptor> annotations) {
|
||||
this.annotations = annotations;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<AnnotationDescriptor> getAnnotationDescriptors() {
|
||||
return annotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return getAnnotationDescriptors().isEmpty();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AnnotationDescriptor findAnnotation(@NotNull FqName fqName) {
|
||||
for (AnnotationDescriptor annotation : annotations) {
|
||||
ClassifierDescriptor descriptor = annotation.getType().getConstructor().getDeclarationDescriptor();
|
||||
if (descriptor instanceof ClassDescriptor && fqName.toUnsafe().equals(DescriptorUtils.getFqName(descriptor))) {
|
||||
return annotation;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<AnnotationDescriptor> iterator() {
|
||||
return getAnnotationDescriptors().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return annotations.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.descriptors.annotations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
|
||||
public class AnnotationsImpl(private val annotations: List<AnnotationDescriptor>) : Annotations {
|
||||
override fun isEmpty() = annotations.isEmpty()
|
||||
|
||||
override fun findAnnotation(fqName: FqName) = annotations.firstOrNull {
|
||||
val descriptor = it.getType().getConstructor().getDeclarationDescriptor()
|
||||
descriptor is ClassDescriptor && fqName.toUnsafe() == DescriptorUtils.getFqName(descriptor)
|
||||
}
|
||||
|
||||
override fun findExternalAnnotation(fqName: FqName) = null
|
||||
|
||||
override fun iterator() = annotations.iterator()
|
||||
|
||||
override fun toString() = annotations.toString()
|
||||
}
|
||||
+6
-4
@@ -16,13 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
|
||||
class DeserializedAnnotations(
|
||||
storageManager: StorageManager,
|
||||
@@ -32,11 +32,13 @@ class DeserializedAnnotations(
|
||||
|
||||
override fun isEmpty(): Boolean = annotations().isEmpty()
|
||||
|
||||
override fun findAnnotation(fqName: FqName): AnnotationDescriptor? = annotations().firstOrNull {
|
||||
override fun findAnnotation(fqName: FqName) = annotations().firstOrNull {
|
||||
annotation ->
|
||||
val descriptor = annotation.getType().getConstructor().getDeclarationDescriptor()
|
||||
descriptor is ClassDescriptor && fqName.equalsTo(DescriptorUtils.getFqName(descriptor))
|
||||
}
|
||||
|
||||
override fun findExternalAnnotation(fqName: FqName) = null
|
||||
|
||||
override fun iterator(): Iterator<AnnotationDescriptor> = annotations().iterator()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user