/// <summary>
    /// Returns a string containing declared element text presentation made according to this presenter settings.
    ///              This method is usefull when additional processing is required for the returned string,
    ///              e.g. as is done in the following method:
    ///              
    /// <code>
    ///              RichText Foo(IMethod method)
    ///              {
    ///                DeclaredElementPresenterMarking marking;
    ///                RichTextParameters rtp = new RichTextParameters(ourFont);
    ///                // make rich text with declared element presentation
    ///                RichText result = new RichText(ourInvocableFormatter.Format(method, out marking),rtp);
    ///                // highlight name of declared element in rich text
    ///                result.SetColors(SystemColors.HighlightText,SystemColors.Info,marking.NameRange.StartOffset,marking.NameRange.EndOffset);
    ///                return result;
    ///              }
    ///              </code>
    /// </summary>
    /// <param name="style">The style.</param>
    /// <param name="element">Contains <see cref="T:JetBrains.ReSharper.Psi.IDeclaredElement" /> to provide string presentation of.</param>
    /// <param name="substitution">The substitution.</param>
    /// <param name="marking">Returns the markup of the string with a <see cref="T:JetBrains.ReSharper.Psi.IDeclaredElement" /> presentation.</param>
    /// <returns>System.String.</returns>
    public string Format(DeclaredElementPresenterStyle style, IDeclaredElement element, ISubstitution substitution, out DeclaredElementPresenterMarking marking)
    {
      marking = new DeclaredElementPresenterMarking();

      var itemDeclaredElement = (IItemDeclaredElement)element;
      var sb = new StringBuilder();
      
      if (style.ShowEntityKind != EntityKindForm.NONE)
      {
        marking.EntityKindRange = AppendString(sb, style.ShowEntityKind == EntityKindForm.NORMAL_IN_BRACKETS ? "[Item] " : "Item ");
      }
      
      if (style.ShowName != NameStyle.NONE)
      {
        if (style.ShowNameInQuotes)
        {
          sb.Append('"');
        }

        marking.NameRange = style.ShowName == NameStyle.SHORT || style.ShowName == NameStyle.SHORT_RAW ? AppendString(sb, itemDeclaredElement.ShortName) : AppendString(sb, itemDeclaredElement.ItemName);
        if (style.ShowNameInQuotes)
        {
          sb.Append('"');
        }
      }
      
      return sb.ToString();
    }
Пример #2
0
 static ShaderLabDeclaredElementPresenterStyles()
 {
     CANDIDATE_PRESENTER = new DeclaredElementPresenterStyle
     {
         ShowName = NameStyle.QUALIFIED,
         ShowType = TypeStyle.DEFAULT
     };
 }
        protected override string Format(IDeclaredElement declaredElement, ISubstitution substitution, PsiLanguageType languageType,
            DeclaredElementPresenterStyle presenter, IReference reference)
        {
            if (declaredElement == null)
                return "null";

            // Output the element like it is in the QuickDoc - element name + type
            return DeclaredElementPresenter.Format(JavaScriptLanguage.Instance, XmlDocPresenterUtil.MemberPresentationStyle,
                declaredElement, EmptySubstitution.INSTANCE);
        }
Пример #4
0
 public string Format(DeclaredElementPresenterStyle style, IDeclaredElement element, ISubstitution substitution, out DeclaredElementPresenterMarking marking)
 {
   marking = new DeclaredElementPresenterMarking();
   var ruleDeclaration = element as IRuleDeclaration;
   if (ruleDeclaration != null)
   {
     return ruleDeclaration.RuleName.GetText();
   }
   return element.ShortName;
 }
 public string Format(DeclaredElementPresenterStyle style, IDeclaredElement element, ISubstitution substitution, out DeclaredElementPresenterMarking marking)
 {
   marking = new DeclaredElementPresenterMarking();
   var ruleDeclaration = element as IRuleDeclaration;
   if (ruleDeclaration != null)
   {
     return ruleDeclaration.RuleName.GetText();
   }
   return element.ShortName;
 }
Пример #6
0
        private JetBrains.UI.RichText.RichText ProcessCRef(string value)
        {
            DeclaredElementPresenterStyle presenterStyle = XmlDocPresenterUtil.LinkedElementPresentationStyle;

            if (this.myTextStyles != null)
            {
                presenterStyle            = presenterStyle.Clone();
                presenterStyle.TextStyles = this.myTextStyles;
            }
            return(XmlDocRichTextPresenterEx.ProcessCRef(value, this.myLanguageType, this.myModule, presenterStyle));
        }
        public string Format(DeclaredElementPresenterStyle style, IDeclaredElement element, ISubstitution substitution, out DeclaredElementPresenterMarking marking)
        {
            marking = new DeclaredElementPresenterMarking();
            var tokenDeclaration = element as ITokenDeclaration;

            if (tokenDeclaration != null)
            {
                return(tokenDeclaration.TokenName.GetText());
            }
            return(element.ShortName);
        }
Пример #8
0
        private string FormatTypeElement(string format)
        {
            // uses DeclaredElementPresenter to format type element, which is standard way to present code elements
            var style = new DeclaredElementPresenterStyle(NameStyle.SHORT)
            {
                ShowTypeParameters = TypeParameterStyle.FULL
            };
            string typeElementText = DeclaredElementPresenter.Format(PresentationUtil.GetPresentationLanguage(TypeElement),
                                                                     style, TypeElement);

            return(string.Format(format, typeElementText));
        }
        protected override string Format(IDeclaredElement declaredElement, ISubstitution substitution, PsiLanguageType languageType,
                                         DeclaredElementPresenterStyle presenter, IReference reference)
        {
            if (declaredElement == null)
            {
                return("null");
            }

            // Output the element like it is in the QuickDoc - element name + type
            return(DeclaredElementPresenter.Format(JavaScriptLanguage.Instance, XmlDocPresenterUtil.MemberPresentationStyle,
                                                   declaredElement, EmptySubstitution.INSTANCE));
        }
Пример #10
0
        ///<param name="element">Contains <see cref="T:JetBrains.ReSharper.Psi.IDeclaredElement" /> to provide string presentation of.</param>
        ///<param name="marking">Returns the markup of the string with a <see cref="T:JetBrains.ReSharper.Psi.IDeclaredElement" /> presentation.</param>
        ///<summary>
        ///
        ///             Returns a string containing declared element text presentation made according to this presenter settings.
        ///             This method is usefull when additional processing is required for the returned string,
        ///             e.g. as is done in the following method:
        ///             
        ///<code>
        ///
        ///             RichText Foo(IMethod method)
        ///             {
        ///               DeclaredElementPresenterMarking marking;
        ///               RichTextParameters rtp = new RichTextParameters(ourFont);
        ///               // make rich text with declared element presentation
        ///               RichText result = new RichText(ourInvocableFormatter.Format(method, out marking),rtp);
        ///               // highlight name of declared element in rich text
        ///               result.SetColors(SystemColors.HighlightText,SystemColors.Info,marking.NameRange.StartOffset,marking.NameRange.EndOffset);
        ///               return result;
        ///             }
        ///             
        ///</code>
        ///
        ///</summary>
        ///
        public string Format(DeclaredElementPresenterStyle style, IDeclaredElement element, ISubstitution substitution,
            out DeclaredElementPresenterMarking marking)
        {
            DeclaredElementPresenterMarking m = new DeclaredElementPresenterMarking();

            if (style.ShowName != NameStyle.NONE)
            {
                m.NameRange = new TextRange(0, element.ShortName.Length);
            }

            marking = m;
            return element.ShortName;
        }
Пример #11
0
        public string Format(DeclaredElementPresenterStyle style, IDeclaredElement declaredElement, ISubstitution substitution, out DeclaredElementPresenterMarking marking)
        {
            if (!declaredElement.IsValid())
            throw new ArgumentException("declaredElement should be valid", "declaredElement");

              var nitraDeclaredElement = declaredElement as NitraDeclaredElement;
              if (nitraDeclaredElement == null)
            throw new ArgumentException("declaredElement should have language supported by Nitra", "declaredElement");

              var result = new StringBuilder();
              marking = new DeclaredElementPresenterMarking();

              if (style.ShowEntityKind != EntityKindForm.NONE)
              {
            string entityKind = GetEntityKindStr(nitraDeclaredElement);
            if (entityKind != "")
            {
              if (style.ShowEntityKind == EntityKindForm.NORMAL_IN_BRACKETS)
            entityKind = "(" + entityKind + ")";
              marking.EntityKindRange = AppendString(result, entityKind);
              result.Append(" ");
            }
              }

              if (style.ShowNameInQuotes)
            result.Append("\'");

              if (style.ShowName != NameStyle.NONE)
              {
            var elementName = nitraDeclaredElement.ShortName;

            if (elementName == SharedImplUtil.MISSING_DECLARATION_NAME)
              elementName = "<unknown name>";

            marking.NameRange = AppendString(result, elementName);
              }

              if (style.ShowNameInQuotes)
              {
            if (result[result.Length - 1] == '\'')
              result.Remove(result.Length - 1, 1);
            else
            {
              TrimString(result);
              result.Append("\' ");
            }
              }

              TrimString(result);
              return result.ToString();
        }
        public RichText Format(DeclaredElementPresenterStyle style, IDeclaredElement element, ISubstitution substitution,
                               out DeclaredElementPresenterMarking marking)
        {
            marking = new DeclaredElementPresenterMarking();
            if (!(element is JsonNewDeclaredElementBase))
            {
                return(null);
            }

            var result = new StringBuilder();

            if (style.ShowEntityKind != EntityKindForm.NONE)
            {
                var entityKind = GetEntityKind(element);
                if (entityKind != string.Empty)
                {
                    if (style.ShowEntityKind == EntityKindForm.NORMAL_IN_BRACKETS)
                    {
                        entityKind = "(" + entityKind + ")";
                    }
                    marking.EntityKindRange = AppendString(result, entityKind);
                    result.Append(" ");
                }
            }

            if (style.ShowNameInQuotes)
            {
                result.Append("\'");
            }

            if (style.ShowName != NameStyle.NONE)
            {
                marking.NameRange = AppendString(result, element.ShortName);
                result.Append(" ");
            }

            if (style.ShowNameInQuotes)
            {
                TrimString(result);
                result.Append("\'");
            }

            if (style.ShowConstantValue)
            {
            }

            TrimString(result);
            return(result.ToString());
        }
        public string Format(
            DeclaredElementPresenterStyle style,
            IDeclaredElement element,
            ISubstitution substitution,
            out DeclaredElementPresenterMarking marking)
        {
            marking = new DeclaredElementPresenterMarking();
            var uriIdentifier = element as IUriIdentifierDeclaredElement;
            if (uriIdentifier != null)
            {
                return uriIdentifier.GetUri();
            }

            return element.ShortName;
        }
Пример #14
0
        private static DeclaredElementPresentation <DeclaredElementInfo> GetOrCreatePresentation(
            DeclaredElementInfo info,
            DeclaredElementPresenterStyle style,
            string typeParameterString = null)
        {
            var preferredDeclaredElement = info.PreferredDeclaredElement;

            if (preferredDeclaredElement != null && preferredDeclaredElement.Element is ICompiledElement &&
                preferredDeclaredElement.Element.Type() == null)
            {
                return(CSharpLookupItemFactory.GetPresentationCache(preferredDeclaredElement.Element.GetSolution())
                       .GetPresentation(info, (ICompiledElement)preferredDeclaredElement.Element, style, typeParameterString));
            }
            return(new DeclaredElementPresentation <DeclaredElementInfo>(info, style, typeParameterString, LogoThemedIcons.NukeLogo.Id));
        }
        public string Format(
            DeclaredElementPresenterStyle style,
            IDeclaredElement element,
            ISubstitution substitution,
            out DeclaredElementPresenterMarking marking)
        {
            marking = new DeclaredElementPresenterMarking();
            var uriIdentifier = element as IUriIdentifierDeclaredElement;

            if (uriIdentifier != null)
            {
                return(uriIdentifier.GetUri());
            }

            return(element.ShortName);
        }
Пример #16
0
        public string Format(DeclaredElementPresenterStyle style, IDeclaredElement declaredElement, ISubstitution substitution, out DeclaredElementPresenterMarking marking)
        {
            if (!declaredElement.IsValid())
            {
                throw new ArgumentException("declaredElement should be valid", "declaredElement");
            }

            var nitraDeclaredElement = declaredElement as NitraDeclaredElement;

            if (nitraDeclaredElement == null)
            {
                throw new ArgumentException("declaredElement should have language supported by Nitra", "declaredElement");
            }

            var result = new StringBuilder();

            marking = new DeclaredElementPresenterMarking();

            if (style.ShowEntityKind != EntityKindForm.NONE)
            {
                string entityKind = GetEntityKindStr(nitraDeclaredElement);
                if (entityKind != "")
                {
                    if (style.ShowEntityKind == EntityKindForm.NORMAL_IN_BRACKETS)
                    {
                        entityKind = "(" + entityKind + ")";
                    }
                    marking.EntityKindRange = AppendString(result, entityKind);
                    result.Append(" ");
                }
            }

            if (style.ShowNameInQuotes)
            {
                result.Append("\'");
            }

            if (style.ShowName != NameStyle.NONE)
            {
                var elementName = nitraDeclaredElement.ShortName;

                if (elementName == SharedImplUtil.MISSING_DECLARATION_NAME)
                {
                    elementName = "<unknown name>";
                }

                marking.NameRange = AppendString(result, elementName);
            }

            if (style.ShowNameInQuotes)
            {
                if (result[result.Length - 1] == '\'')
                {
                    result.Remove(result.Length - 1, 1);
                }
                else
                {
                    TrimString(result);
                    result.Append("\' ");
                }
            }

            TrimString(result);
            return(result.ToString());
        }
Пример #17
0
 public string GetSpecialElementType(DeclaredElementPresenterStyle presenter, IDeclaredElement declaredElement, ISubstitution substitution)
 {
     return(null);
 }
 public string GetSpecialMethodType(DeclaredElementPresenterStyle presenter, IMethod method, ISubstitution substitution)
 {
     return null;
 }
        public RichText Format(DeclaredElementPresenterStyle style, IDeclaredElement element, ISubstitution substitution,
                               out DeclaredElementPresenterMarking marking)
        {
            marking = new DeclaredElementPresenterMarking();
            if (!(element is IShaderLabDeclaredElement))
            {
                return(null);
            }

            var result = new StringBuilder();

            if (style.ShowEntityKind != EntityKindForm.NONE)
            {
                var entityKind = GetEntityKind(element);
                if (entityKind != string.Empty)
                {
                    if (style.ShowEntityKind == EntityKindForm.NORMAL_IN_BRACKETS)
                    {
                        entityKind = "(" + entityKind + ")";
                    }
                    marking.EntityKindRange = AppendString(result, entityKind);
                    result.Append(" ");
                }
            }

            if (style.ShowNameInQuotes)
            {
                result.Append("\'");
            }

            if (style.ShowType == TypeStyle.DEFAULT)
            {
                var typeName = GetTypeName(element);
                if (!string.IsNullOrEmpty(typeName))
                {
                    marking.TypeRange = marking.ScalarTypeRange = AppendString(result, typeName);
                    result.Append(" ");
                }
            }

            if (style.ShowName != NameStyle.NONE)
            {
                marking.NameRange = AppendString(result, element.ShortName);
                result.Append(" ");
            }

            if (style.ShowType == TypeStyle.AFTER)
            {
                var typeName = GetTypeName(element);
                if (!string.IsNullOrEmpty(typeName))
                {
                    result.Append(": ");
                    marking.TypeRange = marking.ScalarTypeRange = AppendString(result, typeName);
                    result.Append(" ");
                }
            }

            if (style.ShowNameInQuotes)
            {
                TrimString(result);
                result.Append("\'");
            }

            if (style.ShowName != NameStyle.NONE && style.ShowName != NameStyle.SHORT &&
                style.ShowName != NameStyle.SHORT_RAW)
            {
                AppendDisplayName(result, element);
            }

            if (style.ShowConstantValue)
            {
            }

            TrimString(result);
            return(result.ToString());
        }
 public string GetSpecialElementType(DeclaredElementPresenterStyle presenter, IDeclaredElement declaredElement, ISubstitution substitution)
 {
     return null;
 }
 protected override string Format(IDeclaredElement declaredElement, ISubstitution substitution, PsiLanguageType languageType, DeclaredElementPresenterStyle presenter, IReference reference)
 {
     var format = base.Format(declaredElement, substitution, languageType, presenter, reference);
     if (declaredElement != null)
         format += " (" + declaredElement.GetElementType().PresentableName + ")";
     return format;
 }
Пример #22
0
        public static JetBrains.UI.RichText.RichText ProcessCRef(string crefValue, PsiLanguageType languageType, IPsiModule psiModule, DeclaredElementPresenterStyle presenterStyle)
        {
            var element = psiModule == null ? null : XMLDocUtil.ResolveId(psiModule.GetPsiServices(), crefValue, psiModule, true);

            return(element == null || !element.IsValid() ? new JetBrains.UI.RichText.RichText(XmlDocPresenterUtil.ProcessCref(crefValue), XmlDocRichTextPresenterEx.ourCRefStyle) : DeclaredElementPresenter.Format(languageType, presenterStyle, element));
        }
 private string FormatTypeElement(string format)
 {
   // uses DeclaredElementPresenter to format type element, which is standard way to present code elements
   var style = new DeclaredElementPresenterStyle(NameStyle.SHORT)
                 {
                   ShowTypeParameters = TypeParameterStyle.FULL
                 };
   string typeElementText = DeclaredElementPresenter.Format(PresentationUtil.GetPresentationLanguage(TypeElement),
                                                            style, TypeElement);
   return string.Format(format, typeElementText);
 }
Пример #24
0
 public string GetSpecialMethodType(DeclaredElementPresenterStyle presenter, IMethod method, ISubstitution substitution)
 {
     return(null);
 }
Пример #25
0
        protected override string Format(IDeclaredElement declaredElement, ISubstitution substitution, PsiLanguageType languageType, DeclaredElementPresenterStyle presenter, IReference reference)
        {
            var format = base.Format(declaredElement, substitution, languageType, presenter, reference);

            if (declaredElement != null)
            {
                format += " (" + declaredElement.GetElementType().PresentableName + ")";
            }
            return(format);
        }