use of org.jetbrains.kotlin.name.FqNameUnsafe in project kotlin by JetBrains.
the class SignaturesPropagationData method getSuperFunctionsForMethod.
private static List<FunctionDescriptor> getSuperFunctionsForMethod(@NotNull JavaMethod method, @NotNull JavaMethodDescriptor autoMethodDescriptor, @NotNull ClassDescriptor containingClass) {
List<FunctionDescriptor> superFunctions = Lists.newArrayList();
// TODO: Add propagation for other kotlin descriptors (KT-3621)
Name name = method.getName();
Method autoSignature = null;
boolean autoMethodContainsVararg = SignaturePropagationUtilKt.containsVarargs(autoMethodDescriptor);
for (KotlinType supertype : containingClass.getTypeConstructor().getSupertypes()) {
Collection<SimpleFunctionDescriptor> superFunctionCandidates = supertype.getMemberScope().getContributedFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS);
if (!autoMethodContainsVararg && !SignaturePropagationUtilKt.containsAnyNotTrivialSignature(superFunctionCandidates))
continue;
if (autoSignature == null) {
autoSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(autoMethodDescriptor);
}
for (FunctionDescriptor candidate : superFunctionCandidates) {
// TODO: remove this continue when KT-15747 is fixed
if (candidate.isSuspend())
continue;
Method candidateSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(candidate);
if (KotlinToJvmSignatureMapperKt.erasedSignaturesEqualIgnoringReturnTypes(autoSignature, candidateSignature)) {
superFunctions.add(candidate);
}
}
}
// sorting for diagnostic stability
Collections.sort(superFunctions, new Comparator<FunctionDescriptor>() {
@Override
public int compare(@NotNull FunctionDescriptor fun1, @NotNull FunctionDescriptor fun2) {
FqNameUnsafe fqName1 = getFqName(fun1.getContainingDeclaration());
FqNameUnsafe fqName2 = getFqName(fun2.getContainingDeclaration());
return fqName1.asString().compareTo(fqName2.asString());
}
});
return superFunctions;
}
use of org.jetbrains.kotlin.name.FqNameUnsafe in project kotlin by JetBrains.
the class AbstractClassTypeConstructor method equals.
@Override
public boolean equals(Object other) {
if (!(other instanceof TypeConstructor))
return false;
// performance optimization: getFqName is slow method
if (other.hashCode() != hashCode())
return false;
// To avoid problems in type checker we suppose that it is different type constructors.
if (((TypeConstructor) other).getParameters().size() != getParameters().size())
return false;
ClassifierDescriptor myDescriptor = getDeclarationDescriptor();
ClassifierDescriptor otherDescriptor = ((TypeConstructor) other).getDeclarationDescriptor();
// descriptor for type is created once per module
if (myDescriptor == otherDescriptor)
return true;
// All error types have the same descriptor
if (!hasMeaningfulFqName(myDescriptor) || otherDescriptor != null && !hasMeaningfulFqName(otherDescriptor)) {
return this == other;
}
if (myDescriptor instanceof ClassDescriptor && otherDescriptor instanceof ClassDescriptor) {
FqNameUnsafe otherFqName = DescriptorUtils.getFqName(otherDescriptor);
FqNameUnsafe myFqName = DescriptorUtils.getFqName(myDescriptor);
return myFqName.equals(otherFqName);
}
return false;
}
use of org.jetbrains.kotlin.name.FqNameUnsafe in project kotlin by JetBrains.
the class RangeCodegenUtil method getPrimitiveRangeOrProgressionElementType.
@Nullable
private static PrimitiveType getPrimitiveRangeOrProgressionElementType(@NotNull KotlinType rangeOrProgression, @NotNull ImmutableMap<FqName, PrimitiveType> map) {
ClassifierDescriptor declarationDescriptor = rangeOrProgression.getConstructor().getDeclarationDescriptor();
if (declarationDescriptor == null)
return null;
FqNameUnsafe fqName = DescriptorUtils.getFqName(declarationDescriptor);
if (!fqName.isSafe())
return null;
return map.get(fqName.toSafe());
}
use of org.jetbrains.kotlin.name.FqNameUnsafe in project kotlin by JetBrains.
the class Namer method getFunctionTag.
@NotNull
public static String getFunctionTag(@NotNull CallableDescriptor functionDescriptor) {
functionDescriptor = (CallableDescriptor) JsDescriptorUtils.findRealInlineDeclaration(functionDescriptor);
String moduleName = getModuleName(functionDescriptor);
FqNameUnsafe fqNameParent = DescriptorUtils.getFqName(functionDescriptor).parent();
String qualifier = null;
if (!fqNameParent.isRoot()) {
qualifier = fqNameParent.asString();
}
SuggestedName suggestedName = new NameSuggestion().suggest(functionDescriptor);
assert suggestedName != null : "Suggested name can be null only for module descriptors: " + functionDescriptor;
String mangledName = suggestedName.getNames().get(0);
return StringUtil.join(Arrays.asList(moduleName, qualifier, mangledName), ".");
}
use of org.jetbrains.kotlin.name.FqNameUnsafe in project kotlin by JetBrains.
the class RangeCodegenUtil method isPrimitiveRangeSpecializationOfType.
/*
* Checks whether for expression 'x in a..b' a..b is primitive integral range
* with same type as x.
*/
public static boolean isPrimitiveRangeSpecializationOfType(@NotNull Type argumentType, @NotNull KtExpression rangeExpression, @NotNull BindingContext bindingContext) {
if (rangeExpression instanceof KtBinaryExpression && ((KtBinaryExpression) rangeExpression).getOperationReference().getReferencedNameElementType() == KtTokens.RANGE) {
KotlinType kotlinType = bindingContext.getType(rangeExpression);
assert kotlinType != null;
DeclarationDescriptor descriptor = kotlinType.getConstructor().getDeclarationDescriptor();
if (descriptor != null) {
FqNameUnsafe fqName = DescriptorUtils.getFqName(descriptor);
if (fqName.equals(KotlinBuiltIns.FQ_NAMES.longRange)) {
return argumentType == Type.LONG_TYPE;
}
if (fqName.equals(KotlinBuiltIns.FQ_NAMES.charRange) || fqName.equals(KotlinBuiltIns.FQ_NAMES.intRange)) {
return AsmUtil.isIntPrimitive(argumentType);
}
}
}
return false;
}
Aggregations