internal FSharpConversionOperator([NotNull] ITypeMemberDeclaration declaration, [NotNull] FSharpMemberOrFunctionOrValue mfv, [CanBeNull] IFSharpTypeDeclaration typeDeclaration, bool isExplicitCast) : base(declaration, mfv, typeDeclaration) { myIsExplicitCast = isExplicitCast; }
public static string GetMfvHighlightingAttributeId([NotNull] this FSharpMemberOrFunctionOrValue mfv) { if (mfv.IsEvent || mfv.IsEventAddMethod || mfv.IsEventRemoveMethod || mfv.EventForFSharpProperty != null) { return(HighlightingAttributeIds.EVENT_IDENTIFIER_ATTRIBUTE); } if (mfv.IsImplicitConstructor || mfv.IsConstructor) { return(HighlightingAttributeIds.TYPE_CLASS_ATTRIBUTE); } var entity = mfv.DeclaringEntity; if (mfv.IsModuleValueOrMember && (entity != null && !entity.Value.IsFSharpModule || mfv.IsExtensionMember)) { return(mfv.IsProperty || mfv.IsPropertyGetterMethod || mfv.IsPropertySetterMethod ? HighlightingAttributeIds.FIELD_IDENTIFIER_ATTRIBUTE : HighlightingAttributeIds.METHOD_IDENTIFIER_ATTRIBUTE); } if (mfv.LiteralValue != null) { return(HighlightingAttributeIds.CONSTANT_IDENTIFIER_ATTRIBUTE); } if (mfv.IsActivePattern) { return(HighlightingAttributeIds.METHOD_IDENTIFIER_ATTRIBUTE); } return(mfv.IsMutable || mfv.IsRefCell ? HighlightingAttributeIds.MUTABLE_LOCAL_VARIABLE_IDENTIFIER_ATTRIBUTE : HighlightingAttributeIds.LOCAL_VARIABLE_IDENTIFIER_ATTRIBUTE); }
public FSharpLiteral([NotNull] ITypeMemberDeclaration declaration, FSharpMemberOrFunctionOrValue mfv) : base(declaration) { Type = FSharpTypesUtil.GetType(mfv.FullType, declaration, Module) ?? TypeFactory.CreateUnknownType(Module); ConstantValue = new ConstantValue(mfv.LiteralValue.Value, Type); }
protected FSharpPropertyBase([NotNull] ITypeMemberDeclaration declaration, [NotNull] FSharpMemberOrFunctionOrValue mfv) : base(declaration, mfv) { IsReadable = mfv.HasGetterMethod || mfv.IsPropertyGetterMethod || mfv.IsModuleValueOrMember && !mfv.IsMember; IsWritable = mfv.IsMutable || mfv.HasSetterMethod || mfv.IsPropertySetterMethod; }
private static IDeclaredElement GetFSharpSourceTypeMember([NotNull] FSharpMemberOrFunctionOrValue mfv, [NotNull] IFSharpTypeElement fsTypeElement) { var name = mfv.GetMfvCompiledName(); var symbolTableCache = fsTypeElement.GetPsiServices().Caches.GetPsiCache <SymbolTableCache>(); var symbolTable = symbolTableCache.TryGetCachedSymbolTable(fsTypeElement, SymbolTableMode.FULL); if (symbolTable != null) { var members = symbolTable.GetSymbolInfos(name).SelectNotNull(info => info.GetDeclaredElement() is ITypeMember member && member.ShortName == name ? member : null); return(ChooseTypeMember(mfv, members.AsList())); } var fcsRange = mfv.DeclarationLocation; var path = FileSystemPath.TryParse(fcsRange.FileName); if (path.IsEmpty) { return(GetTypeMember(mfv, fsTypeElement)); } var declarations = new List <FSharpProperTypeMemberDeclarationBase>(); var typeElement = (TypeElement)fsTypeElement; foreach (var typePart in typeElement.EnumerateParts()) { var typeDeclaration = typePart.GetDeclaration() as FSharpTypeElementDeclarationBase; var sourceFile = typeDeclaration?.GetSourceFile(); if (sourceFile == null || sourceFile.GetLocation() != path) { continue; } foreach (var declaration in typeDeclaration.MemberDeclarations) { if (declaration is FSharpProperTypeMemberDeclarationBase fsDeclaration && fsDeclaration.CompiledName == name) { declarations.Add(fsDeclaration); } } } if (declarations.Count == 0) { return(GetTypeMember(mfv, typeElement)); } var singleDeclaration = declarations.SingleItem(decl => { var range = decl.GetSourceFile().NotNull().Document.GetTreeTextRange(fcsRange); return(range.Contains(decl.GetNameIdentifierRange())); }); return(singleDeclaration?.GetOrCreateDeclaredElement(mfv)); }
private FSharpMemberOrFunctionOrValue GetProperty([NotNull] FSharpMemberOrFunctionOrValue prop) { // Property returned in AccessorProperty currently returns HasSetterMethod = false. // Workaround it by getting mfv property from declaring entity. var entity = prop.DeclaringEntity?.Value; var propertyName = prop.LogicalName; return(entity?.MembersFunctionsAndValues.FirstOrDefault(m => m.LogicalName == propertyName) ?? prop); }
public static IList <IParameter> GetParameters <T>(this T function, FSharpMemberOrFunctionOrValue mfv) where T : IParametersOwner, IFSharpTypeParametersOwner { if (mfv == null) { return(EmptyList <IParameter> .Instance); } var module = function.Module; var paramGroups = mfv.CurriedParameterGroups; var isFsExtension = mfv.IsExtensionMember; var isVoidReturn = paramGroups.Count == 1 && paramGroups[0].Count == 1 && paramGroups[0][0].Type.IsUnit; if (!isFsExtension && isVoidReturn) { return(EmptyArray <IParameter> .Instance); } var paramsCount = GetElementsCount(paramGroups); if (paramsCount == 0) { return(EmptyList <IParameter> .Instance); } var typeParameters = function.AllTypeParameters; var methodParams = new List <IParameter>(paramsCount); if (isFsExtension && mfv.IsInstanceMember) { var typeElement = mfv.ApparentEnclosingEntity.GetTypeElement(module); var type = typeElement != null ? TypeFactory.CreateType(typeElement) : TypeFactory.CreateUnknownType(function.Module); methodParams.Add(new FSharpExtensionMemberParameter(function, type)); } if (isVoidReturn) { return(methodParams); } foreach (var paramsGroup in paramGroups) { foreach (var param in paramsGroup) { methodParams.Add(new FSharpMethodParameter(param, function, methodParams.Count, param.Type.MapType(typeParameters, module, true))); } } return(methodParams); }
private static IDeclaredElement GetTypeMember([NotNull] FSharpMemberOrFunctionOrValue mfv, [NotNull] ITypeElement typeElement) { var compiledName = mfv.GetMfvCompiledName(); var members = mfv.IsConstructor ? typeElement.Constructors.AsList <ITypeMember>() : typeElement.EnumerateMembers(compiledName, true).AsList(); return(ChooseTypeMember(mfv, members)); }
protected FSharpPropertyMemberBase([NotNull] ITypeMemberDeclaration declaration, [NotNull] FSharpMemberOrFunctionOrValue mfv) : base(declaration) { var prop = GetProperty(mfv); IsReadable = prop.HasGetterMethod || prop.IsPropertyGetterMethod || prop.IsModuleValueOrMember && !prop.IsMember; IsWritable = prop.IsMutable || prop.HasSetterMethod || prop.IsPropertySetterMethod; }
public static string GetMfvHighlightingAttributeId([NotNull] this FSharpMemberOrFunctionOrValue mfv) { if (mfv.IsEvent || mfv.IsEventAddMethod || mfv.IsEventRemoveMethod || mfv.EventForFSharpProperty != null) { return(FSharpHighlightingAttributeIdsModule.Event); } if (mfv.IsImplicitConstructor || mfv.IsConstructor) { return mfv.DeclaringEntity?.Value is { IsValueType : true } }
public static string GetMfvHighlightingAttributeId([NotNull] this FSharpMemberOrFunctionOrValue mfv) { if (mfv.IsEvent || mfv.IsEventAddMethod || mfv.IsEventRemoveMethod || mfv.EventForFSharpProperty != null) { return(FSharpHighlightingAttributeIds.Event); } if (mfv.IsImplicitConstructor || mfv.IsConstructor) { return(mfv.DeclaringEntity?.Value is FSharpEntity declEntity && declEntity.IsValueType ? FSharpHighlightingAttributeIds.Struct : FSharpHighlightingAttributeIds.Class); } var entity = mfv.DeclaringEntity; if (mfv.IsModuleValueOrMember && (entity != null && !entity.Value.IsFSharpModule || mfv.IsExtensionMember)) { return(mfv.IsProperty || mfv.IsPropertyGetterMethod || mfv.IsPropertySetterMethod ? FSharpHighlightingAttributeIds.Property : FSharpHighlightingAttributeIds.Method); } if (mfv.LiteralValue != null) { return(FSharpHighlightingAttributeIds.Literal); } if (mfv.IsActivePattern) { return(FSharpHighlightingAttributeIds.ActivePatternCase); } if (mfv.IsMutable || mfv.IsRefCell()) { return(FSharpHighlightingAttributeIds.MutableValue); } if (IsMangledOpName(mfv.LogicalName)) { return(FSharpHighlightingAttributeIds.Operator); } var fsType = mfv.FullType; if (fsType.HasTypeDefinition && fsType.TypeDefinition is var mfvTypeEntity && mfvTypeEntity.IsByRef) { return(FSharpHighlightingAttributeIds.MutableValue); } return(FSharpHighlightingAttributeIds.Value); }
private static string GetXmlDocId([NotNull] FSharpMemberOrFunctionOrValue mfv) { try { return(mfv.XmlDocSig); } catch (Exception e) { Logger.LogMessage(LoggingLevel.WARN, "Could not get XmlDocId for {0}", mfv); Logger.LogExceptionSilently(e); return(null); } }
public FSharpCliEvent([NotNull] ITypeMemberDeclaration declaration, FSharpMemberOrFunctionOrValue mfv) : base(declaration, mfv) { try { ReturnType = FSharpTypesUtil.GetType(mfv.FullType, declaration, Module) ?? TypeFactory.CreateUnknownType(Module); } catch (ErrorLogger.ReportedError e) { ReturnType = TypeFactory.CreateUnknownType(Module); } }
private static IDeclaredElement GetLocalValueDeclaredElement(FSharpMemberOrFunctionOrValue mfv, IFSharpReferenceOwner referenceExpression) { var declaration = FindNode <IFSharpDeclaration>(mfv.DeclarationLocation, referenceExpression); if (declaration is IFSharpLocalDeclaration localDeclaration) { return(localDeclaration); } return(declaration is IFSharpPattern ? declaration.DeclaredElement : null); }
public static bool IsImplicitAccessor([NotNull] this FSharpMemberOrFunctionOrValue mfv) { if (mfv.IsPropertyGetterMethod) { return(mfv.CurriedParameterGroups[0].IsEmpty()); } if (mfv.IsPropertySetterMethod) { return(mfv.CurriedParameterGroups[0]?.Count == 1); } return(false); }
private static IClrDeclaredElement FindLocalDeclaration([NotNull] FSharpMemberOrFunctionOrValue mfv, [CanBeNull] FSharpIdentifierToken referenceOwnerToken) { var fsFile = referenceOwnerToken?.GetContainingFile() as IFSharpFile; var document = fsFile?.GetSourceFile()?.Document; if (document == null) { return(null); } var idToken = fsFile.FindTokenAt(document.GetTreeEndOffset(mfv.DeclarationLocation) - 1); return(idToken?.GetContainingNode <LocalDeclaration>()); }
public static string GetMfvCompiledName([NotNull] this FSharpMemberOrFunctionOrValue mfv) { try { var compiledNameAttr = mfv.Attributes.TryFindAttribute(CompiledNameAttrName); var compiledName = compiledNameAttr != null && !compiledNameAttr.Value.ConstructorArguments.IsEmpty() ? compiledNameAttr.Value.ConstructorArguments[0].Item2 as string : null; return(compiledName ?? (IsImplicitAccessor(mfv) ? mfv.DisplayName : mfv.LogicalName)); } catch (Exception e) { Logger.LogMessage(LoggingLevel.WARN, "Couldn't get CompiledName attribute value:"); Logger.LogExceptionSilently(e); } return(SharedImplUtil.MISSING_DECLARATION_NAME); }
public static string GetXmlDocId([NotNull] this FSharpMemberOrFunctionOrValue mfv) { try { var xmlDocId = mfv.XmlDocSig; if (xmlDocId.StartsWith("P", StringComparison.Ordinal) && mfv.IsCliEvent()) { return("E" + xmlDocId.Substring(1)); } return(xmlDocId); } catch (Exception e) { Logger.LogMessage(LoggingLevel.WARN, "Could not get XmlDocId for {0}", mfv); Logger.LogExceptionSilently(e); return(""); } }
protected FSharpFunctionBase([NotNull] ITypeMemberDeclaration declaration, [NotNull] FSharpMemberOrFunctionOrValue mfv, [CanBeNull] IFSharpTypeDeclaration typeDeclaration) : base(declaration, mfv) { var mfvTypeParams = mfv.GenericParameters; var typeParams = new FrugalLocalList <ITypeParameter>(); var outerTypeParamsCount = typeDeclaration?.TypeParameters.Count ?? 0; for (var i = outerTypeParamsCount; i < mfvTypeParams.Count; i++) { typeParams.Add(new FSharpTypeParameterOfMethod(this, mfvTypeParams[i].DisplayName, i - outerTypeParamsCount)); } TypeParameters = typeParams.ToList(); ReturnType = mfv.IsConstructor || mfv.ReturnParameter.Type.IsUnit ? Module.GetPredefinedType().Void : FSharpTypesUtil.GetType(mfv.ReturnParameter.Type, declaration, TypeParameters, Module, true) ?? TypeFactory.CreateUnknownType(Module); var methodParams = new FrugalLocalList <IParameter>(); var mfvParamGroups = mfv.CurriedParameterGroups; if (mfvParamGroups.Count == 1 && mfvParamGroups[0].Count == 1 && mfvParamGroups[0][0].Type.IsUnit) { Parameters = EmptyList <IParameter> .InstanceList; return; } foreach (var paramsGroup in mfv.CurriedParameterGroups) { foreach (var param in paramsGroup) { var paramType = param.Type; var paramName = param.DisplayName; methodParams.Add(new FSharpMethodParameter(param, this, methodParams.Count, FSharpTypesUtil.GetParameterKind(param), FSharpTypesUtil.GetType(paramType, declaration, TypeParameters, Module, false), paramName.IsEmpty() ? SharedImplUtil.MISSING_DECLARATION_NAME : paramName)); } } Parameters = methodParams.ToList(); }
protected FSharpPropertyBase([NotNull] ITypeMemberDeclaration declaration, [NotNull] FSharpMemberOrFunctionOrValue mfv) : base(declaration, mfv) { var property = mfv.IsModuleValueOrMember ? mfv.DeclaringEntity?.Value.MembersFunctionsAndValues.FirstOrDefault( m => m.IsProperty && m.DisplayName == mfv.DisplayName) ?? mfv : mfv; IsReadable = property.HasGetterMethod || property.IsPropertyGetterMethod || property.IsModuleValueOrMember && !property.IsMember; IsWritable = property.IsMutable || property.HasSetterMethod || property.IsPropertySetterMethod; var returnType = property.IsPropertySetterMethod ? property.CurriedParameterGroups[0][0].Type : property.ReturnParameter.Type; ReturnType = FSharpTypesUtil.GetType(returnType, declaration, Module) ?? TypeFactory.CreateUnknownType(Module); }
private static IDeclaredElement GetTypeMember([NotNull] FSharpMemberOrFunctionOrValue mfv, [NotNull] IPsiModule psiModule) { Assertion.Assert(mfv.IsModuleValueOrMember, "mfv.IsModuleValueOrMember"); var entity = mfv.DeclaringEntity.NotNull().Value; var typeElement = GetTypeElement(entity, psiModule); if (typeElement == null) { return(null); } // todo: provided types: return provided member, use FSharpSearcherFactory.GetNavigateToTargets instead if (entity.IsProvided) { return(typeElement); } return(typeElement is IFSharpTypeElement fsTypeElement && !mfv.IsConstructor ? GetFSharpSourceTypeMember(mfv, fsTypeElement) : GetTypeMember(mfv, typeElement)); }
private static IDeclaredElement ChooseTypeMember(FSharpMemberOrFunctionOrValue mfv, [NotNull] IReadOnlyList <ITypeMember> members) { switch (members.Count) { case 0: return(null); case 1: return(members[0]); } var mfvXmlDocId = GetXmlDocId(mfv); if (mfvXmlDocId.IsEmpty()) { return(null); } return(members.FirstOrDefault(member => // todo: Fix signature for extension properties member is IFSharpMember fsMember && fsMember.Mfv?.GetXmlDocId() == mfvXmlDocId || member.XMLDocId == mfvXmlDocId)); }
internal FSharpOperatorBase([NotNull] ITypeMemberDeclaration declaration, [NotNull] FSharpMemberOrFunctionOrValue mfv) : base(declaration, mfv) { }
protected FSharpMethodBase([NotNull] ITypeMemberDeclaration declaration, [NotNull] FSharpMemberOrFunctionOrValue mfv) : base(declaration, mfv) { }
public FSharpCliEvent([NotNull] ITypeMemberDeclaration declaration, FSharpMemberOrFunctionOrValue mfv) : base(declaration, mfv) { }
protected FSharpMethodBase([NotNull] ITypeMemberDeclaration declaration, [NotNull] FSharpMemberOrFunctionOrValue mfv, [CanBeNull] IFSharpTypeDeclaration typeDeclaration) : base(declaration, mfv, typeDeclaration) { ShortName = mfv.GetMemberCompiledName(); }
internal FSharpConversionOperator([NotNull] ITypeMemberDeclaration declaration, [NotNull] FSharpMemberOrFunctionOrValue mfv, bool isExplicitCast) : base(declaration, mfv) =>
public static bool IsAccessor([NotNull] this FSharpMemberOrFunctionOrValue mfv) => mfv.IsPropertyGetterMethod || mfv.IsPropertySetterMethod || mfv.IsEventAddMethod || mfv.IsEventRemoveMethod;
public static bool IsCliEvent(this FSharpMemberOrFunctionOrValue mfv) => mfv.IsProperty && mfv.Attributes.HasAttributeInstance(FSharpPredefinedType.CLIEventAttribute);
public FSharpImplicitConstructor([NotNull] ITypeMemberDeclaration declaration, [NotNull] FSharpMemberOrFunctionOrValue mfv) : base(declaration, mfv) { }