예제 #1
0
        private static ILookupItem CreateMethodItem(CSharpCodeCompletionContext context, UnityMessage message,
                                                    IClassLikeDeclaration declaration)
        {
            if (CSharpLanguage.Instance == null)
            {
                return(null);
            }

            var method = message.CreateDeclaration(CSharpElementFactory.GetInstance(declaration), declaration);

            if (method.DeclaredElement == null)
            {
                return(null);
            }

            var instance            = new DeclaredElementInstance(method.DeclaredElement);
            var declaredElementInfo = new DeclaredElementInfo(method.DeclaredName, instance, CSharpLanguage.Instance,
                                                              context.BasicContext.LookupItemsOwner, context, context.BasicContext);

            return(LookupItemFactory.CreateLookupItem(declaredElementInfo).
                   WithPresentation(
                       _ => new GenerateMemberPresentation(declaredElementInfo, PresenterStyles.DefaultPresenterStyle)).
                   WithBehavior(_ =>
            {
                var behavior = new UnityMessageBehavior(declaredElementInfo, message);
                behavior.InitializeRanges(context.CompletionRanges, context.BasicContext);
                return behavior;
            }).
                   WithMatcher(_ => new DeclaredElementMatcher(declaredElementInfo, context.BasicContext.IdentifierMatchingStyle)));
        }
        public override ResolveResultWithInfo ResolveWithoutCache()
        {
            ISymbolTable table = this.GetReferenceSymbolTable(true);
            IList<DeclaredElementInstance> elements = new List<DeclaredElementInstance>();
            {
                IList<ISymbolInfo> infos = table.GetSymbolInfos(this.GetName());
                foreach (ISymbolInfo info in infos)
                {
                    var element = new DeclaredElementInstance(info.GetDeclaredElement(), EmptySubstitution.INSTANCE);
                    elements.Add(element);
                }
            }
            if (elements.Count == 0)
            {
                var ruleName = this.myOwner as Prefix;
                // Unresolved namespaces creation
                if (ruleName != null)
                {
                    elements = new List<DeclaredElementInstance>
                        {
                            new DeclaredElementInstance(
                                new UnresolvedNamespacePrefixDeclaredElement(
                                    ruleName.GetSourceFile(), this.GetName(), this.myOwner.GetPsiServices()))
                        };
                }
            }

            return new ResolveResultWithInfo(ResolveResultFactory.CreateResolveResultFinaly(elements), ResolveErrorType.OK);
        }
        private static ILookupItem CreateMethodItem(CSharpCodeCompletionContext context, UnityEventFunction eventFunction,
                                                    IClassLikeDeclaration declaration)
        {
            if (CSharpLanguage.Instance == null)
            {
                return(null);
            }

            var method = eventFunction.CreateDeclaration(CSharpElementFactory.GetInstance(declaration), declaration);

            if (method.DeclaredElement == null)
            {
                return(null);
            }

            var instance = new DeclaredElementInstance(method.DeclaredElement);

            var declaredElementInfo = new DeclaredElementInfo(method.DeclaredName, instance, CSharpLanguage.Instance,
                                                              context.BasicContext.LookupItemsOwner, context)
            {
                Ranges = context.CompletionRanges
            };

            var withMatcher = LookupItemFactory.CreateLookupItem(declaredElementInfo).
                              WithPresentation(_ => new GenerateMemberPresentation(declaredElementInfo, PresenterStyles.DefaultPresenterStyle)).
                              WithBehavior(_ => new UnityEventFunctionBehavior(declaredElementInfo, eventFunction)).
                              WithMatcher(_ => new DeclaredElementMatcher(declaredElementInfo, context.BasicContext.IdentifierMatchingStyle));

            return(withMatcher);
        }
예제 #4
0
        public static IMethod FindOverloadByParameter([NotNull] DeclaredElementInstance <IParameter> parameterInstance)
        {
            var closureParameter = parameterInstance.Element.NotNull("closureParameter != null");

            var currentMethod = closureParameter.ContainingParametersOwner as IMethod;

            var containingType = currentMethod?.GetContainingType();

            if (containingType == null)
            {
                return(null);
            }

            var shortName = currentMethod.ShortName;

            foreach (var typeMember in containingType.GetMembers())
            {
                if (typeMember is IMethod closurelessCandidate &&
                    !ReferenceEquals(closurelessCandidate, currentMethod) &&
                    closurelessCandidate.ShortName == shortName &&
                    closurelessCandidate.IsStatic == currentMethod.IsStatic &&
                    closurelessCandidate.IsExtensionMethod == currentMethod.IsExtensionMethod)
                {
                    if (CompareSignatures(currentMethod, closurelessCandidate, closureParameter))
                    {
                        return(closurelessCandidate);
                    }
                }
            }

            return(null);
        }
예제 #5
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            return(textControl =>
            {
                var psiFiles = solution.GetComponent <IPsiFiles>();
                var psiServices = solution.GetComponent <IPsiServices>();

                var buildPsiSourceFile = textControl.Document.GetPsiSourceFile(solution).NotNull();
                var buildCSharpFile = psiFiles.GetPsiFiles <CSharpLanguage>(buildPsiSourceFile).OfType <ICSharpFile>().Single();

                var target = new DeclaredElementInstance <ITypeElement>(_taskClass);
                var usingDirective = CSharpElementFactory.GetInstance(buildCSharpFile).CreateUsingStaticDirective(target);

                if (UsingUtil.GetImportConflicts(buildCSharpFile, target).Any())
                {
                    MessageBox.ShowError("Unable to import static class (import introduces conflicts in file)");
                    return;
                }

                using (var cookie = new PsiTransactionCookie(psiServices, DefaultAction.Rollback, typeof(MissingTaskUsageFix).Name))
                {
                    UsingUtil.AddImportTo(buildCSharpFile, usingDirective);
                    cookie.Commit();
                }

                var method = _taskClass.Methods.First(x => x.ShortName.Equals(_error.Reference.GetName(), StringComparison.OrdinalIgnoreCase));
                textControl.Document.ReplaceText(_error.CalculateRange().TextRange, method.ShortName);
            });
        }
        private static TN IfElementIs <TN, TE>(IDeclaredElement element,
                                               DeclaredElementToName <TN, TE> map,
                                               ISubstitution substitution,
                                               TN unknownName,
                                               IDictionary <DeclaredElementInstance, IName> seenElements)
            where TE : class, IDeclaredElement
            where TN : class, IName
        {
            var specificElement = element as TE;

            if (specificElement == null)
            {
                return(null);
            }
            var dei = new DeclaredElementInstance(element, substitution);

            // exit if we encounter a recursive type, e.g., delegate IList<D> D();
            if (seenElements.ContainsKey(dei))
            {
                return((TN)seenElements[dei]);
            }
            // this makes us default to the unknownName, if we reencounter an element while resolving it
            seenElements[dei] = unknownName;
            // after this call we have resolved the element and cached the result
            seenElements[dei] = IsMissingDeclaration(specificElement)
                ? unknownName
                : map(specificElement, substitution, seenElements);
            return((TN)seenElements[dei]);
        }
        public override ResolveResultWithInfo ResolveWithoutCache()
        {
            ISymbolTable table = GetReferenceSymbolTable(true);
            IList <DeclaredElementInstance> elements = new List <DeclaredElementInstance>();

            {
                IList <ISymbolInfo> infos = table.GetSymbolInfos(GetName());
                foreach (ISymbolInfo info in infos)
                {
                    var element = new DeclaredElementInstance(info.GetDeclaredElement(), EmptySubstitution.INSTANCE);
                    elements.Add(element);
                }
            }
            if (elements.Count == 0)
            {
                var ruleName = myOwner as RuleName;
                if (PsiTreeUtil.HasParent <InterfacesDefinition>(myOwner) && (ruleName != null))
                {
                    elements = new List <DeclaredElementInstance> {
                        new DeclaredElementInstance(new UnresolvedRuleInterfacesDeclaredElement(ruleName.GetSourceFile(), GetName(), myOwner.GetPsiServices()))
                    };
                }
            }

            return(new ResolveResultWithInfo(ResolveResultFactory.CreateResolveResultFinaly(elements),
                                             ResolveErrorType.OK));
        }
예제 #8
0
        protected override void ProvideMemberSpecificArguments(DeclaredElementInstance <ITypeMember> member, IList <string> arguments, bool requiresBindingFlags)
        {
            //means that we have overloads
            var method = (IMethod)member.Element;
            //TODO : doesn't work with out and ref arguments..., what to do with generic methods...
            string argumentTypes = string.Format("new Type[] {{ {0} }}",
                                                 string.Join(", ", method.Parameters
                                                             .Select(p => Typeof(p, member.Substitution)))); //

            if (requiresBindingFlags)
            {
                /*Use the following overload
                 * public MethodInfo GetMethod(
                 * string name,
                 * BindingFlags bindingAttr,
                 * Binder binder,
                 * Type[] types,
                 * ParameterModifier[] modifiers
                 * )*/
                arguments.Add("null"); //Binder
                arguments.Add(argumentTypes);
                arguments.Add("null"); //ParameterModifiers //TODO
            }
            else
            {
                arguments.Add(argumentTypes);
            }
        }
예제 #9
0
        public RichText TryPresent([NotNull] DeclaredElementInstance declaredElementInstance, [NotNull] PresenterOptions options,
                                   [NotNull] PsiLanguageType languageType, bool useReSharperColors)
        {
            PresentedInfo presentedInfo;

            return(TryPresent(declaredElementInstance, options, languageType, useReSharperColors, out presentedInfo));
        }
예제 #10
0
        protected override void ProvideMemberSpecificArguments(DeclaredElementInstance <ITypeMember> member, IList <string> arguments, bool requiresBindingFlags)
        {
            var    property      = (IProperty)member.Element;
            string argumentTypes = string.Format("new [] {{ {0} }}",
                                                 string.Join(", ", property.Parameters
                                                             .Select(p => Typeof(p, member.Substitution)))); //

            if (requiresBindingFlags)
            {
                /*Use the following overload
                 * public PropertyInfo GetProperty(
                 * string name,
                 * BindingFlags bindingAttr,
                 * Binder binder,
                 * Type returnType,
                 * Type[] types,
                 * ParameterModifier[] modifiers
                 * )
                 * )*/
                arguments.Add("null");                                           //Binder
                arguments.Add(Typeof(property.ReturnType, member.Substitution)); //Return Type
                arguments.Add(argumentTypes);
                arguments.Add("null");                                           //ParameterModifiers //TODO
            }
            else
            {
                arguments.Add(argumentTypes);
            }
        }
        public override ResolveResultWithInfo ResolveWithoutCache()
        {
            ISymbolTable table = this.GetReferenceSymbolTable(true);
            IList <DeclaredElementInstance> elements = new List <DeclaredElementInstance>();

            {
                IList <ISymbolInfo> infos = table.GetSymbolInfos(this.GetName());
                foreach (ISymbolInfo info in infos)
                {
                    var element = new DeclaredElementInstance(info.GetDeclaredElement(), EmptySubstitution.INSTANCE);
                    elements.Add(element);
                }
            }
            if (elements.Count == 0)
            {
                var ruleName = this.myOwner as Prefix;
                // Unresolved namespaces creation
                if (ruleName != null)
                {
                    elements = new List <DeclaredElementInstance>
                    {
                        new DeclaredElementInstance(
                            new UnresolvedNamespacePrefixDeclaredElement(
                                ruleName.GetSourceFile(), this.GetName(), this.myOwner.GetPsiServices()))
                    };
                }
            }

            return(new ResolveResultWithInfo(ResolveResultFactory.CreateResolveResultFinaly(elements), ResolveErrorType.OK));
        }
        public RichText TryPresent([NotNull] DeclaredElementInstance declaredElementInstance, [NotNull] PresenterOptions options,
                                   [NotNull] PsiLanguageType languageType, [CanBeNull] string nameHighlightingAttributeId)
        {
            PresentedInfo presentedInfo;

            return(TryPresent(declaredElementInstance, options, languageType, nameHighlightingAttributeId, out presentedInfo));
        }
예제 #13
0
        private IdentifierTooltipContent TryPresentColorized([NotNull] DeclaredElementInstance elementInstance, [NotNull] PsiLanguageType languageType,
                                                             [NotNull] IPsiSourceFile psiSourceFile, [NotNull] IContextBoundSettingsStore settings, [CanBeNull] string highlighterAttributeId)
        {
            RichText identifierText = _colorizerPresenter.TryPresent(elementInstance, PresenterOptions.ForToolTip(settings), languageType, highlighterAttributeId);

            if (identifierText == null || identifierText.IsEmpty)
            {
                return(null);
            }

            IDeclaredElement element   = elementInstance.Element;
            IPsiModule       psiModule = psiSourceFile.PsiModule;

            var identifierContent = new IdentifierTooltipContent {
                Text        = identifierText,
                Description = TryGetDescription(element, psiModule, languageType, DeclaredElementDescriptionStyle.NO_OBSOLETE_SUMMARY_STYLE),
            };

            if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowIcon))
            {
                identifierContent.Icon = TryGetIcon(element);
            }
            if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowObsolete))
            {
                identifierContent.Obsolete = TryRemoveObsoletePrefix(TryGetDescription(element, psiModule, languageType, DeclaredElementDescriptionStyle.OBSOLETE_DESCRIPTION));
            }
            if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowExceptions))
            {
                identifierContent.Exceptions.AddRange(GetExceptions(element, languageType, psiModule, psiSourceFile.ResolveContext));
            }
            return(identifierContent);
        }
예제 #14
0
        public void ProcessMembers(CSharpCodeCompletionContext context, GroupedItemsCollector collector, ISymbolTable symbols)
        {
            symbols.ForAllSymbolInfos(symbol =>
            {
                var member = symbol.GetDeclaredElement() as ITypeMember;
                if (member != null && member.GetElementType() == ExpectedMemberType)
                {
                    string nameArgument         = string.Format("\"{0}\"", symbol.ShortName);
                    var declaredElementInstance = new DeclaredElementInstance <ITypeMember>((ITypeMember)symbol.GetDeclaredElement(),
                                                                                            symbol.GetSubstitution());

                    if (!IncludeSymbol(declaredElementInstance))
                    {
                        return;
                    }


                    IList <string> arguments = new List <string>();

                    if (IncludeNameArgument)
                    {
                        arguments.Add(nameArgument);
                    }

                    if (NeedsBindingFlags(member))
                    {
                        arguments.Add(GetExpectedBindingFlags(member).GetFullString());
                    }

                    if (ShouldProvideMemberSpecificArguments(symbols.GetSymbolInfos(member.ShortName))) //additional arguments needs to be provided
                    {
                        ProvideMemberSpecificArguments(declaredElementInstance, arguments, NeedsBindingFlags(member));
                    }

                    ReflectionMemberLookupItem lookupItem;
                    if (member is IMethod && ((IMethod)member).TypeParameters.Count != 0)
                    {
                        lookupItem = new ReflectionGenericMethodLookupItem(symbol.ShortName,
                                                                           declaredElementInstance,
                                                                           context,
                                                                           context.BasicContext.LookupItemsOwner);
                    }
                    else
                    {
                        lookupItem = new ReflectionMemberLookupItem(symbol.ShortName,
                                                                    string.Join(", ", arguments.ToArray()),
                                                                    declaredElementInstance,
                                                                    context,
                                                                    context.BasicContext.LookupItemsOwner);
                    }



                    lookupItem.InitializeRanges(context.CompletionRanges, context.BasicContext);
                    lookupItem.OrderingString = string.Format("__A_MEMBER_{0}", symbol.ShortName); //
                    collector.AddToTop(lookupItem);
                }
            });
        }
        private static bool AddEnumerationMembers([NotNull] CSharpCodeCompletionContext context,
                                                  [NotNull] GroupedItemsCollector collector,
                                                  [NotNull] IDeclaredType qualifierType,
                                                  [NotNull] IReferenceExpression referenceExpression)
        {
            var enumerationType = (IEnum)qualifierType.GetTypeElement().NotNull();
            var substitution    = qualifierType.GetSubstitution();
            var memberValues    = new List <Pair <IField, string> >();

            var isFlagsEnum = enumerationType.HasAttributeInstance(FlagsAttributeClrName, false);

            if (!isFlagsEnum)
            {
                foreach (var member in enumerationType.EnumMembers)
                {
                    var formattable = member.ConstantValue.Value as IFormattable;
                    var memberValue = (formattable != null)
            ? formattable.ToString("D", CultureInfo.InvariantCulture) : string.Empty;
                    memberValues.Add(Pair.Of(member, memberValue));
                }
            }
            else
            {
                foreach (var member in enumerationType.EnumMembers)
                {
                    var convertible = member.ConstantValue.Value as IConvertible;
                    var memberValue = (convertible != null)
            ? GetBinaryRepresentation(convertible) : string.Empty;
                    memberValues.Add(Pair.Of(member, memberValue));
                }
            }

            if (memberValues.Count == 0)
            {
                return(false);
            }

            // create pointer to . in reference expression
            var maxLength        = memberValues.Max(x => x.Second.Length);
            var reparsedDotRange = referenceExpression.Delimiter.GetTreeTextRange();
            var originalDotRange = context.UnterminatedContext.ToOriginalTreeRange(reparsedDotRange);
            var file             = context.BasicContext.File;
            var dotMarker        = file.GetDocumentRange(originalDotRange).CreateRangeMarker();

            foreach (var member in memberValues)
            {
                var normalizedValue = member.Second.PadLeft(maxLength, '0');
                var value           = isFlagsEnum ? normalizedValue : member.Second;

                var instance       = new DeclaredElementInstance <IField>(member.First, substitution);
                var textLookupItem = new EnumMemberLookupItem(dotMarker, instance, normalizedValue, value, isFlagsEnum);

                collector.AddSomewhere(textLookupItem);
            }

            return(true);
        }
        protected ShowMethodCallsBulbActionBase(IMethodDeclaration methodDeclaration, ShowCallsType callsType)
        {
            var declaredElement = methodDeclaration.DeclaredElement;

            Assertion.AssertNotNull(declaredElement, "declared is null, should be impossible");

            myMethod  = new DeclaredElementInstance <IClrDeclaredElement>(declaredElement);
            CallsType = callsType;
        }
 protected override string CalculateTypeInName(DeclaredElementInstance<IDeclaredElement> declaredElement)
 {
     string baseRet = base.CalculateTypeInName(declaredElement);
     ITypeElement typeElement = declaredElement.Element as ITypeElement;
     if (typeElement != null)
         return typeElement.CLRName;
     else
         return
             baseRet;
 }
        public RichText TryPresent(
            [NotNull] DeclaredElementInstance declaredElementInstance,
            [NotNull] PresenterOptions options,
            [NotNull] PsiLanguageType languageType,
            [NotNull] HighlighterIdProvider highlighterIdProvider)
        {
            PresentedInfo presentedInfo;

            return(TryPresent(declaredElementInstance, options, languageType, highlighterIdProvider, out presentedInfo));
        }
 protected override string CalculateDisplayName(DeclaredElementInstance<IDeclaredElement> declaredElement,
     out DeclaredElementPresenterMarking marking)
 {
     string baseRet = base.CalculateDisplayName(declaredElement, out marking);
     ITypeElement typeElement = declaredElement.Element as ITypeElement;
     if (typeElement != null)
         return typeElement.CLRName;
     else
         return
             baseRet;
 }
예제 #20
0
        private static IDeclaredElementLookupItem CreateXamlLookupItem()
        {
            var xamlDeclaredElement         = new Mock <IXamlDeclaredElement>();
            var xamlDeclaredElementInstance = new DeclaredElementInstance(xamlDeclaredElement.Object);
            var xamlLookupItem = new Mock <IDeclaredElementLookupItem>();

            xamlLookupItem.Setup(li => li.DisplayName).Returns(new RichText("XamlLookupItem"));
            xamlLookupItem.Setup(li => li.PreferredDeclaredElement).Returns(xamlDeclaredElementInstance);
            xamlLookupItem.Setup(li => li.Placement).Returns(new LookupItemPlacement(""));

            return(xamlLookupItem.Object);
        }
예제 #21
0
        private RichText GetSignatureCore(string[] namedArguments, AnnotationsDisplayKind?showAnnotations, out TextRange[] parameterRanges, out int[] mapToOriginalOrder,
                                          out ExtensionMethodInfo extensionMethodInfo)
        {
            if (showAnnotations == null)
            {
                showAnnotations = _settings.GetValue((ParameterInfoSettings s) => s.ShowAnnotations);
            }

            // TODO: handle named arguments with reordering; currently falling back to non-colored display
            if (namedArguments.Any(s => s != null))
            {
                string signature = _underlyingCandidate.GetSignature(namedArguments, showAnnotations.Value, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo);
                if (!IsIdentityMap(mapToOriginalOrder))
                {
                    return(signature);
                }
            }

            var                 options            = PresenterOptions.ForParameterInfo(_settings, showAnnotations.Value);
            bool                useReSharperColors = _settings.GetValue(HighlightingSettingsAccessor.IdentifierHighlightingEnabled);
            PresentedInfo       presentedInfo;
            InvocationCandidate invocationCandidate = _underlyingCandidate.InvocationCandidate;
            var                 elementInstance     = new DeclaredElementInstance(invocationCandidate.Element, invocationCandidate.Substitution);

            RichText richText = _colorizerPresenter.TryPresent(elementInstance, options, _underlyingCandidate.Language, useReSharperColors, out presentedInfo);

            if (richText == null)
            {
                return(_underlyingCandidate.GetSignature(namedArguments, showAnnotations.Value, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo));
            }

            if (presentedInfo.Parameters.Count == 0)
            {
                parameterRanges     = EmptyArray <TextRange> .Instance;
                mapToOriginalOrder  = EmptyArray <int> .Instance;
                extensionMethodInfo = ExtensionMethodInfo.NoExtension;
            }
            else if (presentedInfo.IsExtensionMethod)
            {
                parameterRanges    = presentedInfo.Parameters.Skip(1).ToArray();
                mapToOriginalOrder = CreateIdentityMap(presentedInfo.Parameters.Count - 1);
                TextRange firstParameterRange = presentedInfo.Parameters[0].TrimLeft(5);                 // keeps "this " highlighted with the keyword color
                extensionMethodInfo = new ExtensionMethodInfo(firstParameterRange, TextRange.InvalidRange);
            }
            else
            {
                parameterRanges     = presentedInfo.Parameters.ToArray();
                mapToOriginalOrder  = CreateIdentityMap(presentedInfo.Parameters.Count);
                extensionMethodInfo = ExtensionMethodInfo.NoExtension;
            }

            return(richText);
        }
예제 #22
0
        public RichText GetSignature(
            string[] namedArguments,
            AnnotationsDisplayKind showAnnotations,
            out TextRange[] parameterRanges,
            out int[] mapToOriginalOrder,
            out ExtensionMethodInfo extensionMethodInfo)
        {
            // TODO: handle named arguments with reordering; currently falling back to non-colored display
            if (namedArguments.Any(s => s != null))
            {
                string signature = UnderlyingCandidate.GetSignature(namedArguments, showAnnotations, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo);
                if (!IsIdentityMap(mapToOriginalOrder))
                {
                    return(signature);
                }
            }

            var                 options = PresenterOptions.ForParameterInfo(_settings, showAnnotations);
            var                 highlighterIdProvider = _highlighterIdProviderFactory.CreateProvider(_settings);
            PresentedInfo       presentedInfo;
            InvocationCandidate invocationCandidate = UnderlyingCandidate.InvocationCandidate;
            var                 elementInstance     = new DeclaredElementInstance(invocationCandidate.Element, invocationCandidate.Substitution);

            RichText richText = _colorizerPresenter.TryPresent(elementInstance, options, UnderlyingCandidate.Language, highlighterIdProvider, out presentedInfo);

            if (richText == null)
            {
                return(UnderlyingCandidate.GetSignature(namedArguments, showAnnotations, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo));
            }

            if (presentedInfo.Parameters.Count == 0)
            {
                parameterRanges     = EmptyArray <TextRange> .Instance;
                mapToOriginalOrder  = EmptyArray <int> .Instance;
                extensionMethodInfo = ExtensionMethodInfo.NoExtension;
            }
            else if (presentedInfo.IsExtensionMethod && UnderlyingCandidate.InvocationCandidate.IsExtensionMethod)
            {
                parameterRanges    = presentedInfo.Parameters.Skip(1).ToArray();
                mapToOriginalOrder = CreateOffsetMap(presentedInfo.Parameters.Count - 1, 1);
                TextRange firstParameterRange = presentedInfo.Parameters[0].TrimLeft(5);                 // keeps "this " highlighted with the keyword color
                extensionMethodInfo = new ExtensionMethodInfo(firstParameterRange, TextRange.InvalidRange);
            }
            else
            {
                parameterRanges     = presentedInfo.Parameters.ToArray();
                mapToOriginalOrder  = CreateOffsetMap(presentedInfo.Parameters.Count, 0);
                extensionMethodInfo = ExtensionMethodInfo.NoExtension;
            }

            return(richText);
        }
        private ArgumentRoleTooltipContent TryGetArgumentRoleContent([NotNull] ITreeNode node, [NotNull] IContextBoundSettingsStore settings)
        {
            if (!settings.GetValue((IdentifierTooltipSettings s) => s.ShowArgumentsRole))
            {
                return(null);
            }

            var argument = node.GetContainingNode <IArgument>();
            DeclaredElementInstance <IParameter> parameterInstance = argument?.MatchingParameter;

            if (parameterInstance == null)
            {
                return(null);
            }

            IParameter       parameter       = parameterInstance.Element;
            IParametersOwner parametersOwner = parameter.ContainingParametersOwner;

            if (parametersOwner == null)
            {
                return(null);
            }

            HighlighterIdProvider highlighterIdProvider = _highlighterIdProviderFactory.CreateProvider(settings);

            RichText final = new RichText("Argument of ", TextStyle.Default);

            final.Append(_colorizerPresenter.TryPresent(
                             new DeclaredElementInstance(parametersOwner, parameterInstance.Substitution),
                             PresenterOptions.ForArgumentRoleParametersOwnerToolTip(settings),
                             argument.Language,
                             highlighterIdProvider));
            final.Append(": ", TextStyle.Default);
            final.Append(_colorizerPresenter.TryPresent(
                             parameterInstance,
                             PresenterOptions.ForArgumentRoleParameterToolTip(settings),
                             argument.Language,
                             highlighterIdProvider));

            var content = new ArgumentRoleTooltipContent(final, argument.GetDocumentRange().TextRange)
            {
                Description = TryGetDescription(parameter, parameter.Module, argument.Language, DeclaredElementDescriptionStyle.NO_OBSOLETE_SUMMARY_STYLE)
            };

            if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowIcon))
            {
                content.Icon = PsiSymbolsThemedIcons.Parameter.Id;
            }

            return(content);
        }
예제 #24
0
        private static void GetSuperTypes(
            [NotNull] ITypeElement typeElement,
            BaseTypeDisplayKind baseTypeDisplayKind,
            ImplementedInterfacesDisplayKind implementedInterfacesDisplayKind,
            [CanBeNull] out DeclaredElementInstance baseType,
            [NotNull] out IList <DeclaredElementInstance> implementedInterfaces)
        {
            baseType = null;
            implementedInterfaces = EmptyList <DeclaredElementInstance> .InstanceList;

            var  searchForBaseType = baseTypeDisplayKind != BaseTypeDisplayKind.Never && typeElement is IClass;
            bool searchForImplementedInterfaces = implementedInterfacesDisplayKind != ImplementedInterfacesDisplayKind.Never;

            if (!searchForBaseType && !searchForImplementedInterfaces)
            {
                return;
            }

            var foundInterfaces = new LocalList <DeclaredElementInstance>();

            foreach (var superType in typeElement.GetAllSuperTypes())
            {
                ITypeElement superTypeElement = superType.GetTypeElement();

                if (superTypeElement is IClass || superTypeElement is IDelegate)
                {
                    if (searchForBaseType)
                    {
                        searchForBaseType = false;
                        if (MatchesBaseTypeDisplayKind(superTypeElement, baseTypeDisplayKind))
                        {
                            baseType = new DeclaredElementInstance(superTypeElement, superType.GetSubstitution());
                        }
                        if (!searchForImplementedInterfaces)
                        {
                            return;
                        }
                    }
                    continue;
                }

                if (searchForImplementedInterfaces &&
                    superTypeElement is IInterface @interface &&
                    MatchesImplementedInterfacesDisplayKind(@interface, implementedInterfacesDisplayKind))
                {
                    foundInterfaces.Add(new DeclaredElementInstance(superTypeElement, superType.GetSubstitution()));
                }
            }

            implementedInterfaces = foundInterfaces.ResultingList();
        }
예제 #25
0
        private static ILookupItem MockLookupItem()
        {
            var lookupItem              = new Mock <IDeclaredElementLookupItem>();
            var typeName                = GetRandomName();
            var assemblyName            = GetRandomName();
            var declaredElementInstance =
                new DeclaredElementInstance(
                    TypeMockUtils.MockTypeElement(typeName, assemblyName, "1.2.3.4"),
                    new SubstitutionImpl());

            lookupItem.Setup(i => i.PreferredDeclaredElement).Returns(declaredElementInstance);
            lookupItem.Setup(i => i.DisplayName).Returns(new RichText(GetRandomName()));
            return(lookupItem.Object);
        }
        public ResolveResultWithInfo ResolveVirtualReferences()
        {
            ISymbolTable table = this.GetReferenceSymbolTable(true);
            IList<DeclaredElementInstance> elements = new List<DeclaredElementInstance>();
            {
                IList<ISymbolInfo> infos = table.GetSymbolInfos(this.GetName());
                foreach (ISymbolInfo info in infos)
                {
                    var element = new DeclaredElementInstance(info.GetDeclaredElement(), EmptySubstitution.INSTANCE);
                    elements.Add(element);
                }
            }

            return new ResolveResultWithInfo(ResolveResultFactory.CreateResolveResultFinaly(elements), ResolveErrorType.OK);
        }
예제 #27
0
        public RichText TryPresent([NotNull] DeclaredElementInstance declaredElementInstance, [NotNull] PresenterOptions options,
                                   [NotNull] PsiLanguageType languageType, bool useReSharperColors, [NotNull] out PresentedInfo presentedInfo)
        {
            var        richText  = new RichText();
            IColorizer colorizer = TryCreateColorizer(richText, languageType, useReSharperColors);

            if (colorizer == null)
            {
                presentedInfo = new PresentedInfo();
                return(null);
            }

            presentedInfo = colorizer.AppendDeclaredElement(declaredElementInstance.Element, declaredElementInstance.Substitution, options);
            return(richText);
        }
        public RichText TryPresent([NotNull] DeclaredElementInstance declaredElementInstance, [NotNull] PresenterOptions options,
                                   [NotNull] PsiLanguageType languageType, [CanBeNull] string nameHighlightingAttributeId, [NotNull] out PresentedInfo presentedInfo)
        {
            var richText = new RichText();

            presentedInfo = new PresentedInfo();
            IColorizer colorizer = TryCreateColorizer(richText, options, languageType, presentedInfo);

            if (colorizer == null)
            {
                return(null);
            }

            colorizer.AppendDeclaredElement(declaredElementInstance.Element, declaredElementInstance.Substitution, nameHighlightingAttributeId);
            return(richText);
        }
        public override ResolveResultWithInfo ResolveWithoutCache()
        {
            ISymbolTable table = GetReferenceSymbolTable(true);
            IList <DeclaredElementInstance> elements = new List <DeclaredElementInstance>();

            {
                IList <ISymbolInfo> infos = table.GetSymbolInfos(GetName());
                foreach (ISymbolInfo info in infos)
                {
                    var element = new DeclaredElementInstance(info.GetDeclaredElement(), EmptySubstitution.INSTANCE);
                    elements.Add(element);
                }
            }
            return(new ResolveResultWithInfo(ResolveResultFactory.CreateResolveResultFinaly(elements),
                                             ResolveErrorType.OK));
        }
        /// <summary>
        /// Gets the full namespace for the Using directive with any aliases expanded.
        /// </summary>
        /// <param name="directive">
        /// The directive to use.
        /// </param>
        /// <returns>
        /// The fully qualified namespace.
        /// </returns>
        internal static string GetFullyQualifiedNamespace(this IUsingDirective directive)
        {
            if (directive is IUsingAliasDirective)
            {
                IUsingAliasDirective aliasDirective = directive as IUsingAliasDirective;

                DeclaredElementInstance <IDeclaredElement> declaredElementInstance = aliasDirective.DeclaredElement.GetAliasedSymbol();

                INamespace aliasedNamespace = declaredElementInstance == null ? null : declaredElementInstance.Element as INamespace;

                string returnValue = aliasedNamespace == null ? aliasDirective.ImportedSymbolName.QualifiedName : aliasedNamespace.QualifiedName;

                return(returnValue);
            }

            return(directive.ImportedSymbolName.QualifiedName);
        }
        private static void GetSuperTypes(
            [NotNull] ITypeElement typeElement,
            bool getBaseType,
            bool getImplementedInterfaces,
            [CanBeNull] out DeclaredElementInstance baseType,
            [NotNull] out IList <DeclaredElementInstance> implementedInterfaces)
        {
            baseType = null;
            implementedInterfaces = EmptyList <DeclaredElementInstance> .InstanceList;

            var searchForBaseType = getBaseType && typeElement is IClass;

            if (!searchForBaseType && !getImplementedInterfaces)
            {
                return;
            }

            var foundInterfaces = new LocalList <DeclaredElementInstance>();

            foreach (var superType in typeElement.GetAllSuperTypes())
            {
                ITypeElement superTypeElement = superType.GetTypeElement();

                if (superTypeElement is IClass || superTypeElement is IDelegate)
                {
                    if (searchForBaseType)
                    {
                        baseType          = new DeclaredElementInstance(superTypeElement, superType.GetSubstitution());
                        searchForBaseType = false;
                        if (!getImplementedInterfaces)
                        {
                            return;
                        }
                    }
                    continue;
                }

                if (getImplementedInterfaces && superTypeElement is IInterface)
                {
                    foundInterfaces.Add(new DeclaredElementInstance(superTypeElement, superType.GetSubstitution()));
                }
            }

            implementedInterfaces = foundInterfaces.ResultingList();
        }
예제 #32
0
        protected override void ProvideMemberSpecificArguments(DeclaredElementInstance <ITypeMember> member, IList <string> arguments, bool requiresBindingFlags)
        {
            var    constructor   = (IConstructor)member.Element;
            string argumentTypes = string.Format("new Type[] {{ {0} }}",
                                                 string.Join(", ", constructor.Parameters
                                                             .Select(p => Typeof(p, member.Substitution)))); //

            if (requiresBindingFlags)
            {
                arguments.Add("null"); //Binder
                arguments.Add(argumentTypes);
                arguments.Add("null"); //ParameterModifiers
            }
            else
            {
                arguments.Add(argumentTypes);
            }
        }
예제 #33
0
        public IdentifierTooltipContent TryGetIdentifierContent([NotNull] IHighlighter highlighter, [NotNull] PsiLanguageType languageType, [NotNull] IContextBoundSettingsStore settings)
        {
            if (!settings.GetValue((IdentifierTooltipSettings s) => s.Enabled))
            {
                return(null);
            }

            IPsiSourceFile          psiSourceFile;
            DeclaredElementInstance elementInstance = FindValidHighlightedElement(highlighter, languageType, out psiSourceFile);

            if (elementInstance == null)
            {
                return(null);
            }

            return(TryPresentColorized(elementInstance, languageType, psiSourceFile, settings, highlighter.AttributeId)
                   ?? TryPresentNonColorized(highlighter, elementInstance.Element, settings));
        }
예제 #34
0
        internal static IReferenceName GetUsedNamespaceNode([CanBeNull] this IUsingDirective directive)
        {
            var usingSymbolDirective = directive as IUsingSymbolDirective;

            if (usingSymbolDirective == null)
            {
                return(null);
            }

            DeclaredElementInstance <IDeclaredElement> importedSymbol = usingSymbolDirective.ImportedSymbol;

            if (importedSymbol == null || !(importedSymbol.Element is INamespace))
            {
                return(null);
            }

            return(usingSymbolDirective.ImportedSymbolName);
        }
		private RichText GetSignatureCore(string[] namedArguments, AnnotationsDisplayKind? showAnnotations, out TextRange[] parameterRanges, out int[] mapToOriginalOrder,
			out ExtensionMethodInfo extensionMethodInfo) {

			if (showAnnotations == null)
				showAnnotations = _settings.GetValue((ParameterInfoSettings s) => s.ShowAnnotations);

			// TODO: handle named arguments with reordering; currently falling back to non-colored display
			if (namedArguments.Any(s => s != null)) {
				string signature = _underlyingCandidate.GetSignature(namedArguments, showAnnotations.Value, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo);
				if (!IsIdentityMap(mapToOriginalOrder))
					return signature;
			}

			var options = PresenterOptions.ForParameterInfo(_settings, showAnnotations.Value);
			bool useReSharperColors = _settings.GetValue(HighlightingSettingsAccessor.IdentifierHighlightingEnabled);
			PresentedInfo presentedInfo;
			InvocationCandidate invocationCandidate = _underlyingCandidate.InvocationCandidate;
			var elementInstance = new DeclaredElementInstance(invocationCandidate.Element, invocationCandidate.Substitution);
			
			RichText richText = _colorizerPresenter.TryPresent(elementInstance, options, _underlyingCandidate.Language, useReSharperColors, out presentedInfo);
			if (richText == null)
				return _underlyingCandidate.GetSignature(namedArguments, showAnnotations.Value, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo);

			if (presentedInfo.Parameters.Count == 0) {
				parameterRanges = EmptyArray<TextRange>.Instance;
				mapToOriginalOrder = EmptyArray<int>.Instance;
				extensionMethodInfo = ExtensionMethodInfo.NoExtension;
			}
			else if (presentedInfo.IsExtensionMethod) {
				parameterRanges = presentedInfo.Parameters.Skip(1).ToArray();
				mapToOriginalOrder = CreateIdentityMap(presentedInfo.Parameters.Count - 1);
				TextRange firstParameterRange = presentedInfo.Parameters[0].TrimLeft(5); // keeps "this " highlighted with the keyword color
				extensionMethodInfo = new ExtensionMethodInfo(firstParameterRange, TextRange.InvalidRange);
			}
			else {
				parameterRanges = presentedInfo.Parameters.ToArray();
				mapToOriginalOrder = CreateIdentityMap(presentedInfo.Parameters.Count);
				extensionMethodInfo = ExtensionMethodInfo.NoExtension;
			}

			return richText;
		}
    public override ResolveResultWithInfo ResolveWithoutCache()
    {
      ISymbolTable table = GetReferenceSymbolTable(true);
      IList<DeclaredElementInstance> elements = new List<DeclaredElementInstance>();
      {
        IList<ISymbolInfo> infos = table.GetSymbolInfos(GetName());
        foreach (ISymbolInfo info in infos)
        {
          var element = new DeclaredElementInstance(info.GetDeclaredElement(), EmptySubstitution.INSTANCE);
          elements.Add(element);
        }
      }
      if(elements.Count == 0)
      {
        var ruleName = myOwner as RuleName;
        if( PsiTreeUtil.HasParent<InterfacesDefinition>(myOwner) && (ruleName != null))
        {
          elements = new List<DeclaredElementInstance>{new DeclaredElementInstance(new UnresolvedRuleInterfacesDeclaredElement(ruleName.GetSourceFile(), GetName(), myOwner.GetPsiServices()))};
        }
      }

      return new ResolveResultWithInfo(ResolveResultFactory.CreateResolveResultFinaly(elements),
        ResolveErrorType.OK);
    }
 public DeclaredElementWithAliasLookupItem(string alias, DeclaredElementInstance instance, IElementPointerFactory elementPointerFactory, PsiLanguageType languageType)
     : base(instance, elementPointerFactory, languageType)
 {
     this.alias = alias;
 }
 protected override string CalculateTypeInName(DeclaredElementInstance<IDeclaredElement> declaredElement)
 {
     base.CalculateTypeInName(declaredElement);
     return alias;
 }
예제 #39
0
 protected override string CalculateTypeInName(DeclaredElementInstance<IDeclaredElement> declaredElement)
 {
     return parameterDescriptor.Name;
 }
예제 #40
0
 protected override string CalculateDisplayName(DeclaredElementInstance<IDeclaredElement> declaredElement,
     out DeclaredElementPresenterMarking marking)
 {
     base.CalculateDisplayName(declaredElement, out marking);
     return parameterDescriptor.Name;
 }
 public DeclaredElementFullNameLookupItem(DeclaredElementInstance instance, IElementPointerFactory elementPointerFactory, PsiLanguageType languageType)
     : base(instance, elementPointerFactory, languageType)
 {
 }