use of org.jetbrains.kotlin.name.Name in project kotlin by JetBrains.
the class AbstractAnnotationDescriptorResolveTest method getPropertyDescriptor.
@NotNull
private static PropertyDescriptor getPropertyDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
Name propertyName = Name.identifier(name);
MemberScope memberScope = classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList());
Collection<PropertyDescriptor> properties = memberScope.getContributedVariables(propertyName, NoLookupLocation.FROM_TEST);
assert properties.size() == 1 : "Failed to find property " + propertyName + " in class " + classDescriptor.getName();
return properties.iterator().next();
}
use of org.jetbrains.kotlin.name.Name in project kotlin by JetBrains.
the class AbstractAnnotationDescriptorResolveTest method getClassDescriptor.
@NotNull
protected static ClassDescriptor getClassDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name) {
Name className = Name.identifier(name);
ClassifierDescriptor aClass = packageView.getMemberScope().getContributedClassifier(className, NoLookupLocation.FROM_TEST);
assertNotNull("Failed to find class: " + packageView.getName() + "." + className, aClass);
assert aClass instanceof ClassDescriptor : "Not a class: " + aClass;
return (ClassDescriptor) aClass;
}
use of org.jetbrains.kotlin.name.Name in project kotlin by JetBrains.
the class SignaturesPropagationData method modifyValueParametersAccordingToSuperMethods.
private ValueParameters modifyValueParametersAccordingToSuperMethods(@NotNull List<ValueParameterDescriptor> parameters) {
KotlinType resultReceiverType = null;
List<ValueParameterDescriptor> resultParameters = new ArrayList<ValueParameterDescriptor>(parameters.size());
boolean shouldBeExtension = checkIfShouldBeExtension();
for (final ValueParameterDescriptor originalParam : parameters) {
final int originalIndex = originalParam.getIndex();
List<TypeAndName> typesFromSuperMethods = ContainerUtil.map(superFunctions, new Function<FunctionDescriptor, TypeAndName>() {
@Override
public TypeAndName fun(FunctionDescriptor superFunction) {
ReceiverParameterDescriptor receiver = superFunction.getExtensionReceiverParameter();
int index = receiver != null ? originalIndex - 1 : originalIndex;
if (index == -1) {
assert receiver != null : "can't happen: index is -1, while function is not extension";
return new TypeAndName(receiver.getType(), originalParam.getName());
}
ValueParameterDescriptor parameter = superFunction.getValueParameters().get(index);
return new TypeAndName(parameter.getType(), parameter.getName());
}
});
VarargCheckResult varargCheckResult = checkVarargInSuperFunctions(originalParam);
KotlinType altType = varargCheckResult.parameterType;
if (shouldBeExtension && originalIndex == 0) {
resultReceiverType = altType;
} else {
Name stableName = null;
for (int i = 0; i < superFunctions.size(); i++) {
if (superFunctions.get(i).hasStableParameterNames()) {
// When there's more than one stable name in super functions, we pick the first one. This behaviour is similar to
// the compiler front-end, except that it reports a warning in such cases
// TODO: report a warning somewhere if there's more than one stable name in super functions
stableName = typesFromSuperMethods.get(i).name;
break;
}
}
resultParameters.add(new ValueParameterDescriptorImpl(originalParam.getContainingDeclaration(), null, shouldBeExtension ? originalIndex - 1 : originalIndex, originalParam.getAnnotations(), stableName != null ? stableName : originalParam.getName(), altType, originalParam.declaresDefaultValue(), originalParam.isCrossinline(), originalParam.isNoinline(), varargCheckResult.isVararg ? DescriptorUtilsKt.getBuiltIns(originalParam).getArrayElementType(altType) : null, SourceElement.NO_SOURCE));
}
}
boolean hasStableParameterNames = CollectionsKt.any(superFunctions, new Function1<FunctionDescriptor, Boolean>() {
@Override
public Boolean invoke(FunctionDescriptor descriptor) {
return descriptor.hasStableParameterNames();
}
});
return new ValueParameters(resultReceiverType, resultParameters, hasStableParameterNames);
}
use of org.jetbrains.kotlin.name.Name 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.Name in project kotlin by JetBrains.
the class KtAnnotationEntryElementType method createStub.
@Override
public KotlinAnnotationEntryStub createStub(@NotNull KtAnnotationEntry psi, StubElement parentStub) {
Name shortName = KtPsiUtil.getShortName(psi);
String resultName = shortName != null ? shortName.asString() : psi.getText();
KtValueArgumentList valueArgumentList = psi.getValueArgumentList();
boolean hasValueArguments = valueArgumentList != null && !valueArgumentList.getArguments().isEmpty();
return new KotlinAnnotationEntryStubImpl(parentStub, StringRef.fromString(resultName), hasValueArguments);
}
Aggregations