public AlternativeFieldSignatureData( @NotNull JavaAnnotationResolver annotationResolver, @NotNull JavaFieldImpl field, @NotNull JetType originalReturnType, boolean isVar) { String signature = SignaturesUtil.getKotlinSignature(annotationResolver, field); if (signature == null) { setAnnotated(false); return; } setAnnotated(true); Project project = field.getPsi().getProject(); JetProperty altPropertyDeclaration = JetPsiFactory.createProperty(project, signature); try { checkForSyntaxErrors(altPropertyDeclaration); checkFieldAnnotation(altPropertyDeclaration, field, isVar); altReturnType = computeReturnType( originalReturnType, altPropertyDeclaration.getTypeRef(), new HashMap<TypeParameterDescriptor, TypeParameterDescriptorImpl>()); } catch (AlternativeSignatureMismatchException e) { setError(e.getMessage()); } }
private JavaDescriptorResolver.ValueParameterDescriptors modifyValueParametersAccordingToSuperMethods( @NotNull JavaDescriptorResolver.ValueParameterDescriptors parameters // descriptors built by parameters resolver ) { // we are not processing receiver type specifically: // if this function comes from Kotlin, then we don't need to do it, if it doesn't, then it can't // have receiver List<ValueParameterDescriptor> resultParameters = Lists.newArrayList(); for (ValueParameterDescriptor originalParam : parameters.getDescriptors()) { final int index = originalParam.getIndex(); List<TypeAndVariance> typesFromSuperMethods = ContainerUtil.map( superFunctions, new Function<FunctionDescriptor, TypeAndVariance>() { @Override public TypeAndVariance fun(FunctionDescriptor superFunction) { return new TypeAndVariance( superFunction.getValueParameters().get(index).getType(), INVARIANT); } }); VarargCheckResult varargCheckResult = checkVarargInSuperFunctions(originalParam); JetType altType = modifyTypeAccordingToSuperMethods( varargCheckResult.parameterType, typesFromSuperMethods, MEMBER_SIGNATURE_CONTRAVARIANT); resultParameters.add( new ValueParameterDescriptorImpl( originalParam.getContainingDeclaration(), index, originalParam.getAnnotations(), originalParam.getName(), altType, originalParam.declaresDefaultValue(), varargCheckResult.isVararg ? KotlinBuiltIns.getInstance().getArrayElementType(altType) : null)); } JetType originalReceiverType = parameters.getReceiverType(); if (originalReceiverType != null) { JetType substituted = SignaturesUtil.createSubstitutorForFunctionTypeParameters(autoTypeParameterToModified) .substitute(originalReceiverType, INVARIANT); assert substituted != null; return new JavaDescriptorResolver.ValueParameterDescriptors(substituted, resultParameters); } else { return new JavaDescriptorResolver.ValueParameterDescriptors(null, resultParameters); } }
public AlternativeMethodSignatureData( @NotNull ExternalAnnotationResolver externalAnnotationResolver, @NotNull JavaMethod method, @Nullable JetType receiverType, @NotNull Project project, @NotNull List<ValueParameterDescriptor> valueParameters, @Nullable JetType originalReturnType, @NotNull List<TypeParameterDescriptor> methodTypeParameters, boolean hasSuperMethods) { String signature = SignaturesUtil.getKotlinSignature(externalAnnotationResolver, method); if (signature == null) { setAnnotated(false); altFunDeclaration = null; return; } if (receiverType != null) { throw new UnsupportedOperationException( "Alternative annotations for extension functions are not supported yet"); } setAnnotated(true); altFunDeclaration = JetPsiFactory.createFunction(project, signature); originalToAltTypeParameters = DescriptorResolverUtils.recreateTypeParametersAndReturnMapping(methodTypeParameters, null); try { checkForSyntaxErrors(altFunDeclaration); checkEqualFunctionNames(altFunDeclaration, method); computeTypeParameters(methodTypeParameters); computeValueParameters(valueParameters); if (originalReturnType != null) { altReturnType = computeReturnType( originalReturnType, altFunDeclaration.getReturnTypeRef(), originalToAltTypeParameters); } if (hasSuperMethods) { checkParameterAndReturnTypesForOverridingMethods( valueParameters, methodTypeParameters, originalReturnType); } } catch (AlternativeSignatureMismatchException e) { setError(e.getMessage()); } }
public SignaturesPropagationData( @NotNull ClassDescriptor containingClass, @NotNull JetType autoReturnType, // type built by JavaTypeTransformer from Java signature and @NotNull // annotations @NotNull JavaDescriptorResolver.ValueParameterDescriptors autoValueParameters, // descriptors built by parameters resolver @NotNull List<TypeParameterDescriptor> autoTypeParameters, // descriptors built by signature resolver @NotNull PsiMethodWrapper method, @NotNull BindingTrace trace) { this.containingClass = containingClass; superFunctions = getSuperFunctionsForMethod(method, trace, containingClass); autoTypeParameterToModified = SignaturesUtil.recreateTypeParametersAndReturnMapping(autoTypeParameters); modifiedTypeParameters = modifyTypeParametersAccordingToSuperMethods(autoTypeParameters); modifiedReturnType = modifyReturnTypeAccordingToSuperMethods(autoReturnType); modifiedValueParameters = modifyValueParametersAccordingToSuperMethods(autoValueParameters); }