use of org.jetbrains.kotlin.descriptors.ClassDescriptor in project kotlin by JetBrains.
the class ResolveSessionUtils method getClassOrObjectDescriptorsByFqName.
@NotNull
public static Collection<ClassDescriptor> getClassOrObjectDescriptorsByFqName(@NotNull ModuleDescriptor module, @NotNull FqName fqName, @NotNull Predicate<ClassDescriptor> filter) {
if (fqName.isRoot())
return Collections.emptyList();
Collection<ClassDescriptor> result = new ArrayList<ClassDescriptor>(1);
FqName packageFqName = fqName.parent();
while (true) {
PackageViewDescriptor packageDescriptor = module.getPackage(packageFqName);
if (!packageDescriptor.isEmpty()) {
FqName relativeClassFqName = FqNamesUtilKt.tail(fqName, packageFqName);
ClassDescriptor classDescriptor = findClassByRelativePath(packageDescriptor.getMemberScope(), relativeClassFqName);
if (classDescriptor != null && filter.apply(classDescriptor)) {
result.add(classDescriptor);
}
}
if (packageFqName.isRoot()) {
break;
}
packageFqName = packageFqName.parent();
}
return result;
}
use of org.jetbrains.kotlin.descriptors.ClassDescriptor in project kotlin by JetBrains.
the class CommonSupertypes method computeSupertypeProjections.
// constructor - type constructor of a supertype to be instantiated
// types - instantiations of constructor occurring as supertypes of classes we are trying to intersect
@NotNull
private static SimpleType computeSupertypeProjections(@NotNull TypeConstructor constructor, @NotNull Set<SimpleType> types, int recursionDepth, int maxDepth) {
assert !types.isEmpty();
if (types.size() == 1) {
return types.iterator().next();
}
List<TypeParameterDescriptor> parameters = constructor.getParameters();
List<TypeProjection> newProjections = new ArrayList<TypeProjection>(parameters.size());
for (TypeParameterDescriptor parameterDescriptor : parameters) {
Set<TypeProjection> typeProjections = new HashSet<TypeProjection>();
for (KotlinType type : types) {
typeProjections.add(type.getArguments().get(parameterDescriptor.getIndex()));
}
newProjections.add(computeSupertypeProjection(parameterDescriptor, typeProjections, recursionDepth, maxDepth));
}
boolean nullable = false;
for (KotlinType type : types) {
nullable |= type.isMarkedNullable();
}
ClassifierDescriptor classifier = constructor.getDeclarationDescriptor();
MemberScope newScope;
if (classifier instanceof ClassDescriptor) {
newScope = ((ClassDescriptor) classifier).getMemberScope(newProjections);
} else if (classifier instanceof TypeParameterDescriptor) {
newScope = classifier.getDefaultType().getMemberScope();
} else {
newScope = ErrorUtils.createErrorScope("A scope for common supertype which is not a normal classifier", true);
}
return KotlinTypeFactory.simpleType(Annotations.Companion.getEMPTY(), constructor, newProjections, nullable, newScope);
}
use of org.jetbrains.kotlin.descriptors.ClassDescriptor in project kotlin by JetBrains.
the class FieldInfo method createForSingleton.
@NotNull
public static FieldInfo createForSingleton(@NotNull ClassDescriptor classDescriptor, @NotNull KotlinTypeMapper typeMapper) {
if (!classDescriptor.getKind().isSingleton() || DescriptorUtils.isEnumEntry(classDescriptor)) {
throw new UnsupportedOperationException("Can't create singleton field for class: " + classDescriptor);
}
if (isNonCompanionObject(classDescriptor) || CompanionObjectMapping.INSTANCE.isMappedIntrinsicCompanionObject(classDescriptor)) {
return createSingletonViaInstance(classDescriptor, typeMapper);
}
ClassDescriptor ownerDescriptor = DescriptorUtils.getParentOfType(classDescriptor, ClassDescriptor.class);
assert ownerDescriptor != null : "Owner not found for class: " + classDescriptor;
Type ownerType = typeMapper.mapType(ownerDescriptor);
return new FieldInfo(ownerType, typeMapper.mapType(classDescriptor), classDescriptor.getName().asString(), true);
}
use of org.jetbrains.kotlin.descriptors.ClassDescriptor in project kotlin by JetBrains.
the class CompileTimeConstantUtils method isAcceptableTypeForAnnotationParameter.
private static boolean isAcceptableTypeForAnnotationParameter(@NotNull KotlinType parameterType) {
ClassDescriptor typeDescriptor = TypeUtils.getClassDescriptor(parameterType);
if (typeDescriptor == null) {
return false;
}
if (isEnumClass(typeDescriptor) || isAnnotationClass(typeDescriptor) || KotlinBuiltIns.isKClass(typeDescriptor) || KotlinBuiltIns.isPrimitiveArray(parameterType) || KotlinBuiltIns.isPrimitiveType(parameterType) || KotlinBuiltIns.isString(parameterType)) {
return true;
}
if (KotlinBuiltIns.isArray(parameterType)) {
List<TypeProjection> arguments = parameterType.getArguments();
if (arguments.size() == 1) {
KotlinType arrayType = arguments.get(0).getType();
if (arrayType.isMarkedNullable()) {
return false;
}
ClassDescriptor arrayTypeDescriptor = TypeUtils.getClassDescriptor(arrayType);
if (arrayTypeDescriptor != null) {
return isEnumClass(arrayTypeDescriptor) || isAnnotationClass(arrayTypeDescriptor) || KotlinBuiltIns.isKClass(arrayTypeDescriptor) || KotlinBuiltIns.isString(arrayType);
}
}
}
return false;
}
use of org.jetbrains.kotlin.descriptors.ClassDescriptor in project kotlin by JetBrains.
the class AbstractClassTypeConstructor method hashCode.
@Override
public final int hashCode() {
int currentHashCode = hashCode;
if (currentHashCode != 0)
return currentHashCode;
ClassifierDescriptor descriptor = getDeclarationDescriptor();
if (descriptor instanceof ClassDescriptor && hasMeaningfulFqName(descriptor)) {
currentHashCode = DescriptorUtils.getFqName(descriptor).hashCode();
} else {
currentHashCode = System.identityHashCode(this);
}
hashCode = currentHashCode;
return currentHashCode;
}
Aggregations