Example #1
0
        private static ITypeDeclaration GetTargetTypeDeclaration([NotNull] ITypeElement baseClass)
        {
            if (!baseClass.IsValid())
            {
                return(null);
            }

            return(baseClass
                   .GetDeclarations()
                   .OfType <ITypeDeclaration>()
                   .FirstOrDefault(decl => LanguageManager.Instance.TryGetService <IntentionLanguageSpecific>(decl.Language) != null));
        }
Example #2
0
        private void AppendDeclaredType([NotNull] IDeclaredType declaredType, QualifierDisplays expectedQualifierDisplay, Context context)
        {
            if (declaredType.IsNullable())
            {
                IType underlyingType = declaredType.GetNullableUnderlyingType();
                if (underlyingType != null)
                {
                    AppendTypeWithoutModule(underlyingType, expectedQualifierDisplay, context);
                    AppendText("?", _highlighterIdProvider.Operator);
                    return;
                }
            }

            if (declaredType is IDynamicType)
            {
                AppendText("dynamic", _highlighterIdProvider.Keyword);
                return;
            }

            if (context.Options.UseTypeKeywords)
            {
                string typeKeyword = CSharpTypeFactory.GetTypeKeyword(declaredType.GetClrName());
                if (typeKeyword != null)
                {
                    AppendText(typeKeyword, _highlighterIdProvider.Keyword);
                    return;
                }
            }
            else if (declaredType.IsVoid())
            {
                AppendText("void", _highlighterIdProvider.Keyword);
                return;
            }

            ITypeElement typeElement = declaredType.GetTypeElement();

            if (typeElement == null || !typeElement.IsValid())
            {
                PsiLanguageType language = CSharpLanguage.Instance ?? (PsiLanguageType)UnknownLanguage.Instance;
                AppendText(declaredType.GetPresentableName(language), null);
            }
            else
            {
                AppendTypeElement(typeElement, declaredType.GetSubstitution(), expectedQualifierDisplay, context);
            }
        }
Example #3
0
        private void AppendDeclaredType([NotNull] IDeclaredType declaredType, NamespaceDisplays expectedNamespaceDisplay)
        {
            if (declaredType.IsNullable())
            {
                IType underlyingType = declaredType.GetNullableUnderlyingType();
                if (underlyingType != null)
                {
                    AppendType(underlyingType, expectedNamespaceDisplay);
                    AppendText("?", VsHighlightingAttributeIds.Operator);
                    return;
                }
            }

            if (declaredType is IDynamicType)
            {
                AppendText("dynamic", VsHighlightingAttributeIds.Keyword);
                return;
            }

            if (_options.UseTypeKeywords)
            {
                string typeKeyword = CSharpTypeFactory.GetTypeKeyword(declaredType.GetClrName());
                if (typeKeyword != null)
                {
                    AppendText(typeKeyword, VsHighlightingAttributeIds.Keyword);
                    return;
                }
            }
            else if (declaredType.IsVoid())
            {
                AppendText("void", VsHighlightingAttributeIds.Keyword);
                return;
            }

            ITypeElement typeElement = declaredType.GetTypeElement();

            if (typeElement == null || !typeElement.IsValid())
            {
                AppendText(declaredType.GetPresentableName(UnknownLanguage.Instance), null);
                return;
            }

            AppendTypeElement(typeElement, declaredType.GetSubstitution(), expectedNamespaceDisplay);
        }
        public override ICollection <IOccurrence> Search(IProgressIndicator progressIndicator)
        {
            if (!_typeElement.IsValid())
            {
                return(EmptyList <IOccurrence> .InstanceList);
            }

            var linkedTypes = LinkedTypesUtil.GetLinkedTypes(_typeElement);

            if (linkedTypes.Count == 0)
            {
                ModificationUtility.TryCreateTestOrProductionClass(_typeElement, _textControl);
            }

            bool IsDerivedName(ITypeElement typeElement) =>
            _typeElement.ShortName.Contains(typeElement.ShortName) ||
            typeElement.ShortName.Contains(_typeElement.ShortName);

            return(linkedTypes
                   .Select(x => new LinkedTypesOccurrence(x, OccurrenceType.Occurrence, IsDerivedName(x)))
                   .Where(x => !_derivedNamesOnly || x.HasNameDerived)
                   .ToArray());
        }
        private void PopulateAssemblyTypes(List<StaticDeclaredTypeWrapper> types, ITypeElement typeHandle, bool includeNonPublicTypes)
        {
            if (!typeHandle.IsValid())
                return;

            IModifiersOwner modifiers = typeHandle as IModifiersOwner;
            if (modifiers != null && (includeNonPublicTypes || modifiers.GetAccessRights() == AccessRights.PUBLIC))
            {
                types.Add(MakeDeclaredTypeWithoutSubstitution(typeHandle));

                foreach (ITypeElement nestedType in typeHandle.NestedTypes)
                    PopulateAssemblyTypes(types, nestedType, includeNonPublicTypes);
            }
        }
        /// <summary>
        /// It is possible for GetSuperTypes to return types that would form a cycle
        /// if the user typed in something like "class A : A" (even accidentally).
        /// This will cause big problems down the line so we drop supertypes with cycles.
        /// </summary>
        private static IEnumerable<IDeclaredType> SafeGetSuperTypes(ITypeElement typeElement)
        {
            if (!typeElement.IsValid())
                yield break;

            IList<IDeclaredType> superTypes = typeElement.GetSuperTypes();
            if (superTypes.Count == 0)
                yield break;

            foreach (IDeclaredType superType in typeElement.GetSuperTypes())
            {
#if RESHARPER_31 || RESHARPER_40 || RESHARPER_41
                if (superType.IsValid)
#else
                if (superType.IsValid())
#endif
                {
                    ITypeElement superTypeElement = superType.GetTypeElement();
                    if (superTypeElement.IsValid())
                    {
                        if (!HasSuperTypeCycle(superTypeElement))
                            yield return superType;
                    }
                }
            }
        }
 public override bool IsAvailable(IUserDataHolder cache) => base.IsAvailable(cache) && myTargetType.IsValid();