/// <summary> /// Obtains a reflection wrapper for a declared element. /// </summary> /// <param name="target">The element, or null if none.</param> /// <returns>The reflection wrapper, or null if none.</returns> public ICodeElementInfo Wrap(IDeclaredElement target) { if (target == null) return null; ITypeElement typeElement = target as ITypeElement; if (typeElement != null) return Wrap(typeElement); IFunction function = target as IFunction; if (function != null) return Wrap(function); IProperty property = target as IProperty; if (property != null) return Wrap(property); IField field = target as IField; if (field != null) return Wrap(field); IEvent @event = target as IEvent; if (@event != null) return Wrap(@event); IParameter parameter = target as IParameter; if (parameter != null) return Wrap(parameter); INamespace @namespace = target as INamespace; if (@namespace != null) return Reflector.WrapNamespace(@namespace.QualifiedName); return null; }
protected override bool CanBeAnnotated(IDeclaredElement declaredElement, ITreeNode context, IPsiModule module) { var method = declaredElement as IMethod; if (method != null && IsAvailableForType(method.ReturnType, context)) { return true; } var parameter = declaredElement as IParameter; if (parameter != null && IsAvailableForType(parameter.Type, context)) { return true; } var property = declaredElement as IProperty; if (property != null && IsAvailableForType(property.Type, context)) { return true; } var delegateType = declaredElement as IDelegate; if (delegateType != null && IsAvailableForType(delegateType.InvokeMethod.ReturnType, context)) { return true; } var field = declaredElement as IField; if (field != null && IsAvailableForType(field.Type, context)) { return true; } return false; }
public MakeAccessedPrivatePropertyGetterProtectedQuickFix(UseOfPrivateMemberInInheritedNestedClassHighlight highlight) { this.highlight = highlight; this.text = "Fix access rights to allow accessing the getter from inherited classes."; var referenceExpression = this.highlight.ReferenceExpression; this.declaredElement = referenceExpression.Reference.CurrentResolveResult.DeclaredElement; }
public IDeclaredElement GetPrimaryDeclaredElement(IDeclaredElement declaredElement, IReference reference) { IDeclaredElement derivedElement = null; var method = declaredElement as IMethod; if (method != null) { derivedElement = DerivedDeclaredElementUtil.GetPrimaryDeclaredElementForMethod(method); } var @class = declaredElement as IClass; if (@class != null) derivedElement = DerivedDeclaredElementUtil.GetPrimaryDeclaredElementForClass(@class); var @interface = declaredElement as IInterface; if (@interface != null) derivedElement = DerivedDeclaredElementUtil.GetPrimaryDeclaredElementForInterface(@interface); if(derivedElement != null) { return derivedElement; } return declaredElement; }
public RichTextBlock GetElementDescription(IDeclaredElement element, DeclaredElementDescriptionStyle style, PsiLanguageType language, IPsiModule module = null) { if (!element.IsFromUnityProject()) return null; var method = element as IMethod; if (method != null) { var eventFunction = myUnityApi.GetUnityEventFunction(method); if (eventFunction?.Description != null) return new RichTextBlock(eventFunction.Description); } var parameter = element as IParameter; var owner = parameter?.ContainingParametersOwner as IMethod; if (owner != null) { var eventFunction = myUnityApi.GetUnityEventFunction(owner); var eventFunctionParameter = eventFunction?.GetParameter(parameter.ShortName); if (eventFunctionParameter?.Description != null) return new RichTextBlock(eventFunctionParameter.Description); } return null; }
public ContextSpecificationElement CreateContextSpecification(IDeclaredElement field) { var clazz = ((ITypeMember) field).GetContainingType() as IClass; if (clazz == null) { return null; } ContextElement context; _cache.Contexts.TryGetValue(clazz, out context); if (context == null) { return null; } return GetOrCreateContextSpecification(_provider, _manager, _psiModuleManager, _cacheManager, _project, context, _projectEnvoy, clazz.GetClrName().GetPersistent(), field.ShortName, field.IsIgnored()); }
protected override string GetHighlightAttributeForReference(IDeclaredElement element) { if (element is ModuleDeclaredElement) return HighlightingAttributeIds.NAMESPACE_IDENTIFIER_ATTRIBUTE; else return null; }
public ISearchDomain GetDeclaredElementSearchDomain(IDeclaredElement declaredElement) { if (declaredElement is NitraDeclaredElement) return mySearchDomainFactory.CreateSearchDomain(declaredElement.GetSolution(), false); return EmptySearchDomain.Instance; }
public Element FindElement(IDeclaredElement declared) { ITypeElement type = declared.GetTypeElement(); if (type != null) { var assemblyFile = type.GetAssemblyFile(); if (assemblyFile != null) { return new Element(assemblyFile, type.CLRName, ""); } } var member = declared.GetTypeMember(); if (member != null) { var file = member.GetAssemblyFile(); if (file != null) { return new Element( file, member.GetContainingType().CLRName, member.ShortName ); } } return Element.NotFound; }
public ContextSpecificationElement CreateContextSpecification(IDeclaredElement field) { #if RESHARPER_6 IClass clazz = ((ITypeMember)field).GetContainingType() as IClass; #else IClass clazz = field.GetContainingType() as IClass; #endif if (clazz == null) { return null; } ContextElement context; _cache.Classes.TryGetValue(clazz, out context); if (context == null) { return null; } return GetOrCreateContextSpecification(_provider, _project, context, _projectEnvoy, #if RESHARPER_6 clazz.GetClrName().FullName, #else clazz.CLRName, #endif field.ShortName, clazz.GetTags(), field.IsIgnored()); }
// This is the ReSharper 8.1 version public RichTextBlock GetElementDescription(IDeclaredElement element, DeclaredElementDescriptionStyle style, PsiLanguageType language, IPsiModule module) { var attribute = element as IHtmlAttributeDeclaredElement; if (attribute == null) return null; var attributeDescription = GetAttributeDescription(attribute.ShortName); var block = new RichTextBlock(); var typeDescription = new RichText(htmlDescriptionsCache.GetDescriptionForHtmlValueType(attribute.ValueType)); if (style.IntendedDescriptionPlacement == DescriptionPlacement.AFTER_NAME && (style.ShowSummary || style.ShowFullDescription)) block.SplitAndAdd(typeDescription); string description = null; if (style.ShowSummary && attributeDescription != null) description = attributeDescription.Summary; else if (style.ShowFullDescription && attributeDescription != null) description = attributeDescription.Description; if (!string.IsNullOrEmpty(description)) block.SplitAndAdd(description); if (style.IntendedDescriptionPlacement == DescriptionPlacement.ON_THE_NEW_LINE && (style.ShowSummary || style.ShowFullDescription)) { // TODO: Perhaps we should show Value: Expression for attributes that take an Angular expression, etc typeDescription.Prepend("Value: "); block.SplitAndAdd(typeDescription); } return block; }
public BehaviorElement CreateBehavior(IDeclaredElement field) { IClass clazz = ((ITypeMember)field).GetContainingType() as IClass; if (clazz == null) { return null; } ContextElement context; _cache.Classes.TryGetValue(clazz, out context); if (context == null) { return null; } string fullyQualifiedTypeName = null; if (field is ITypeOwner) { // Work around the difference in how the MetaData API and Psi API return different type strings for generics. TypeNameCache.TryGetValue(GetFirstGenericNormalizedTypeName(field), out fullyQualifiedTypeName); } return GetOrCreateBehavior(_provider, #if RESHARPER_61 _manager, _psiModuleManager, _cacheManager, #endif _project, _projectEnvoy, context, clazz.GetClrName(), field.ShortName, field.IsIgnored(), fullyQualifiedTypeName); }
protected override string GetHighlightAttributeForReference(IDeclaredElement element) { if (element is IDatabaseObjectDeclaredElement) return HighlightingAttributeIds.CONSTANT_IDENTIFIER_ATTRIBUTE; else return null; }
public BehaviorElement CreateBehavior(IDeclaredElement field) { var clazz = ((ITypeMember)field).GetContainingType() as IClass; if (clazz == null) { return null; } var context = this._cache.TryGetContext(clazz); if (context == null) { return null; } var fieldType = new NormalizedTypeName(field as ITypeOwner); var behavior = this.GetOrCreateBehavior(context, clazz.GetClrName(), field.ShortName, field.IsIgnored(), fieldType); foreach (var child in behavior.Children) { child.State = UnitTestElementState.Pending; } this._cache.AddBehavior(field, behavior); return behavior; }
/// <summary> /// Check if the member is visible as C# type member I.e. it skips accessors except to properties with parameters /// </summary> public static bool IsCollectionInitializerAddMethod(IDeclaredElement declaredElement) { var method = declaredElement as IMethod; if (method == null) { return false; } if (method.IsStatic) { return false; } if (method.ShortName != "Add") { return false; } ITypeElement containingType = method.GetContainingType(); if (containingType == null) { return false; } if (method.Parameters.Any(parameter => parameter.Kind != ParameterKind.VALUE)) { return false; } if (!containingType.IsDescendantOf(method.Module.GetPredefinedType().IEnumerable.GetTypeElement())) { return false; } return true; }
public override IEnumerable<AtomicRenameBase> CreateAtomicRenames(IDeclaredElement declaredElement, string newName, bool doNotAddBindingConflicts) { yield return new PsiAtomicRename(declaredElement, newName, doNotAddBindingConflicts); if (declaredElement is RuleDeclaration) { var ruleDeclaration = declaredElement as RuleDeclaration; ruleDeclaration.UpdateDerivedDeclaredElements(); foreach (IDeclaredElement element in ruleDeclaration.DerivedParserMethods) { yield return new PsiDerivedElementRename(element, "parse" + NameToCamelCase(newName), doNotAddBindingConflicts); } foreach (IDeclaredElement element in ruleDeclaration.DerivedClasses) { yield return new PsiDerivedElementRename(element, NameToCamelCase(newName), doNotAddBindingConflicts); } foreach (IDeclaredElement element in ruleDeclaration.DerivedInterfaces) { yield return new PsiDerivedElementRename(element, ruleDeclaration.InterfacePrefix + NameToCamelCase(newName), doNotAddBindingConflicts); } foreach (IDeclaredElement element in ruleDeclaration.DerivedVisitorMethods) { yield return new PsiDerivedElementRename(element, ruleDeclaration.VisitorMethodPrefix + NameToCamelCase(newName) + ruleDeclaration.VisitorMethodSuffix, doNotAddBindingConflicts); } } }
public IconId GetImageId(IDeclaredElement declaredElement, PsiLanguageType languageType, out bool canApplyExtensions) { canApplyExtensions = false; if (declaredElement is IAngularJsDeclaredElement) return LogoThemedIcons.Angularjs.Id; return null; }
/// <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(); }
public static MemberWithAccess FromDeclaredElement(IDeclaredElement declaredElement) { Contract.Requires(declaredElement != null); var clrDeclaredElement = declaredElement as IClrDeclaredElement; if (clrDeclaredElement == null) return null; var accessRightsOwner = declaredElement as IAccessRightsOwner; if (accessRightsOwner == null) return null; var declaringTypeAccessRights = declaredElement.GetDeclarations() .FirstOrDefault() .With(x => x.GetContainingNode<IClassLikeDeclaration>()) .With(x => (AccessRights?)x.GetAccessRights()); if (declaringTypeAccessRights == null) return null; return new MemberWithAccess(clrDeclaredElement, declaringTypeAccessRights.Value, GetMemberType(declaredElement), accessRightsOwner.GetAccessRights()); }
private bool IsEqualGeneric(IDeclaredElement element) { var topLevelTypeElement = DeclaredElementUtil.GetTopLevelTypeElement(element as IClrDeclaredElement); var elementSuperTypes = TypeElementUtil.GetAllSuperTypesReversed(topLevelTypeElement); var elementSuperTypeParams = GetTypeParametersFromTypes(elementSuperTypes).Where(x => x.Any()); return new GenericSequenceEqualityComparer().Equals(elementSuperTypeParams.First(), _originTypeParams); }
public static bool IsAnyUnitTestElement(IDeclaredElement element) { return IsDirectUnitTestClass(element as IClass) || IsContainingUnitTestClass(element as IClass) || IsUnitTestMethod(element) || IsUnitTestDataProperty(element) || IsUnitTestClassConstructor(element); }
public bool SuppressUsageInspectionsOnElement(IDeclaredElement element, out ImplicitUseKindFlags flags) { flags = 0; var suppress = element.IsAnyUnitTestElement(); if (suppress) flags = ImplicitUseKindFlags.Default; return suppress; }
public override bool IsApplicable(IDeclaredElement declaredElement) { if (declaredElement.PresentationLanguage.Is<PsiLanguage>()) { return true; } return false; }
public DeclaredElementInfo([NotNull] IDeclaredElement declaredElement, [NotNull] ISubstitution substitution, [NotNull] IFile file, TextRange sourceRange, [CanBeNull] IReference reference) { DeclaredElement = declaredElement; Substitution = substitution; File = file; SourceRange = sourceRange; Reference = reference; }
static string GetFirstGenericNormalizedTypeName(IDeclaredElement field) { var typeName = ((ITypeOwner) field).Type.ToString(); typeName = typeName.Substring(typeName.IndexOf("-> ") + 3); typeName = typeName.Remove(typeName.Length - 1); typeName = Regex.Replace(typeName, @"\[.*->\s", "["); return typeName; }
protected override bool CanBeAnnotated(IDeclaredElement declaredElement, ITreeNode context, IPsiModule module) { var method = declaredElement as IMethod; return method != null && (!method.ReturnType.IsVoid() || method.Parameters.Any(parameter => parameter.AssertNotNull().Kind == ParameterKind.OUTPUT)) && method.Parameters.All(parameter => parameter.AssertNotNull().Kind != ParameterKind.REFERENCE); }
public override bool Accepts(IDeclaredElement declaredElement, ISubstitution substitution) { IModifiersOwner modifiersOwner = declaredElement as IModifiersOwner; if (modifiersOwner == null) return false; return modifiersOwner.GetAccessRights() == AccessRights.PUBLIC || modifiersOwner.GetAccessRights() == AccessRights.PROTECTED; }
public IEnumerable<Pair<IDeclaredElement, Predicate<FindResult>>> GetRelatedDeclaredElements(IDeclaredElement element) { var ruleDeclaration = element as RuleDeclaration; if (ruleDeclaration != null) { return ruleDeclaration.GetRelatedDeclaredElements(); } return EmptyList<Pair<IDeclaredElement, Predicate<FindResult>>>.InstanceList; }
static IProjectFile GetProjectFile(IDeclaredElement field) { var sourceFile = field.GetSourceFiles(); if (sourceFile.Count > 0) { return sourceFile[0].ToProjectFile(); } return null; }
public PsiDerivedElementRename(IDeclaredElement declaredElement, [NotNull] string newName, bool doNotShowBindingConflicts) { myOriginalElementPointer = declaredElement.CreateElementPointer(); myNewName = newName; myDoNotShowBindingConflicts = doNotShowBindingConflicts; mySecondaryElements = new List<IDeclaredElementPointer<IDeclaredElement>>(); mySecondaryElements = RenameRefactoringService.Instance.GetRenameService(PsiLanguage.Instance).GetSecondaryElements(declaredElement).Select(x => x.CreateElementPointer()).ToList(); BuildDeclarations(); }
public bool Matches(IDeclaredElement signature) { return(true); }
private static bool IsParameter([NotNull] IDeclaredElement declaredElement) { return(declaredElement is IParameter || declaredElement is IQueryAnonymousTypeProperty); }
public static bool IsSupportingField(this IDeclaredElement element) { return(element.IsValidFieldOfType(typeof(Establish)) || element.IsValidFieldOfType(typeof(Because)) || element.IsValidFieldOfType(typeof(Cleanup))); }
private IconId TryGetIcon([NotNull] IDeclaredElement declaredElement) { var psiIconManager = _solution.GetComponent <PsiIconManager>(); return(psiIconManager.GetImage(declaredElement, declaredElement.PresentationLanguage, true)); }
public override IReference BindTo(IDeclaredElement element) => this;
public void MarkElementAsCostlyReachable(IDeclaredElement element) { myCostlyMethods.Add(element); }
public IEnumerable <FindResult> GetRelatedFindResults(IDeclaredElement element) { return(EmptyList <FindResult> .InstanceList); }
public Tuple <ICollection <IDeclaredElement>, bool> GetNavigateToTargets(IDeclaredElement element) { return(null); }
public bool IsAvailable(IDeclaredElement element) { return(element.IsFromUnityProject()); }
public override IReference BindTo(IDeclaredElement element, ISubstitution substitution) => BindTo(element);
public override LocalList <IDeclaredElement> GetBanMarksFromNode(ITreeNode currentNode, IDeclaredElement containingFunction) { return(new LocalList <IDeclaredElement>()); }
private IdentifierTooltipContent TryPresentColorized([NotNull] DeclaredElementInfo info, [NotNull] IContextBoundSettingsStore settings) { PsiLanguageType languageType = info.TreeNode.Language; IDeclaredElement element = info.DeclaredElement; IPsiModule psiModule = info.TreeNode.GetPsiModule(); HighlighterIdProvider highlighterIdProvider = _highlighterIdProviderFactory.CreateProvider(settings); RichText identifierText = _colorizerPresenter.TryPresent( new DeclaredElementInstance(element, info.Substitution), PresenterOptions.ForIdentifierToolTip(settings), languageType, highlighterIdProvider); if (identifierText == null || identifierText.IsEmpty) { return(null); } var identifierContent = new IdentifierTooltipContent(identifierText, info.SourceRange) { 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)); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowOverloadCount)) { identifierContent.OverloadCount = TryGetOverloadCountCount(element as IFunction, info.Reference, languageType); } var typeElement = info.DeclaredElement as ITypeElement; if (typeElement != null) { bool showBaseType = settings.GetValue((IdentifierTooltipSettings s) => s.ShowBaseType); bool showImplementedInterfaces = settings.GetValue((IdentifierTooltipSettings s) => s.ShowImplementedInterfaces); if (showBaseType || showImplementedInterfaces) { AddSuperTypes(identifierContent, typeElement, showBaseType, showImplementedInterfaces, languageType, highlighterIdProvider); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowAttributesUsage) && typeElement.IsAttribute()) { identifierContent.AttributeUsage = GetAttributeUsage((IClass)info.DeclaredElement); } } return(identifierContent); }
private string GetShortName(IDeclaredElement declaredElement) { return(declaredElement.ShortName); }
public IEnumerable <RelatedDeclaredElement> GetRelatedDeclaredElements(IDeclaredElement element) { return(EmptyList <RelatedDeclaredElement> .InstanceList); }
public bool IsDeclaredElementCostlyReachable(IDeclaredElement element) { return(myCostlyMethods.Contains(element)); }
public IEnumerable <string> GetAllPossibleWordsInFile(IDeclaredElement element) { yield return(element.ShortName); }
public RenameAvailabilityCheckResult CheckRenameAvailability(IDeclaredElement element) { return(RenameAvailabilityCheckResult.CanBeRenamed); }
public bool IsElementOfKind(IDeclaredElement declaredElement, UnitTestElementKind elementKind) { return(myNUnitTestProvider.IsElementOfKind(declaredElement, elementKind)); }
public override IReference BindTo(IDeclaredElement element) { // TODO: Handle rename throw new NotImplementedException(); }
private static void ReportClosureAllocations( [NotNull] ITreeNode topDeclaration, [CanBeNull] IParametersOwner thisElement, [CanBeNull] ILocalScope topScope, [NotNull] ClosureInspector inspector, [NotNull] IHighlightingConsumer consumer) { var scopesMap = new Dictionary <IDeclaredElement, ILocalScope>(); var captureScopes = new Dictionary <ILocalScope, JetHashSet <IDeclaredElement> >(); // group captures by their scope, report non-cached delegates foreach (var closure in inspector.Closures) { foreach (var capture in closure.Value) { ILocalScope scope = null; if (capture is IFunction) { scope = topScope; // 'this' capture } else { var declarations = capture.GetDeclarations(); if (declarations.Count == 0) // accessors 'value' parameter { if (thisElement is IAccessor accessor && Equals(accessor.ValueVariable, capture)) { scope = topScope; } } else { foreach (var declaration in declarations) { if (declaration is IRegularParameterDeclaration) { scope = topScope; } else { scope = declaration.GetContainingScope <ILocalScope>(); } break; } } } if (scope == null) { continue; } if (!captureScopes.TryGetValue(scope, out var captures)) { captureScopes[scope] = captures = new JetHashSet <IDeclaredElement>(); } captures.Add(capture); scopesMap[capture] = scope; } { var highlightingRange = GetClosureRange(closure.Key); if (highlightingRange.IsValid()) { if (IsExpressionLambda(closure.Key)) { var highlighting = new ObjectAllocationHighlighting(closure.Key, "expression tree construction"); consumer.AddHighlighting(highlighting, highlightingRange); } else { var description = FormatClosureDescription(closure.Value); var highlighting = new DelegateAllocationHighlighting(closure.Key, "capture of " + description); consumer.AddHighlighting(highlighting, highlightingRange); ReportClosurelessOverloads(closure.Key, consumer); } } } } // highlight first captured entity per every scope foreach (var scopeToCaptures in captureScopes) { var firstOffset = TreeOffset.MaxValue; IDeclaredElement firstCapture = null; foreach (var capture in scopeToCaptures.Value) { if (capture is IFunction) { continue; } var offset = GetCaptureStartOffset(capture); if (offset < firstOffset) { firstOffset = offset; firstCapture = capture; } } var scopeClosure = FormatClosureDescription(scopeToCaptures.Value); // collect outer captures JetHashSet <IDeclaredElement> outerCaptures = null; foreach (var closureToCaptures in inspector.Closures) { if (!scopeToCaptures.Key.Contains(closureToCaptures.Key)) { continue; } foreach (var capture in closureToCaptures.Value) { if (!scopesMap.TryGetValue(capture, out var scope)) { continue; } if (scopeToCaptures.Key.Contains(scope)) { continue; } outerCaptures = outerCaptures ?? new JetHashSet <IDeclaredElement>(); outerCaptures.Add(capture); } } if (outerCaptures != null) { var description = FormatClosureDescription(outerCaptures); scopeClosure += $" + (outer closure of {description})"; } if (firstCapture != null) { var anchor = GetCaptureHighlightingRange(topDeclaration, thisElement, firstCapture, out var highlightingRange); if (anchor != null && highlightingRange.IsValid()) { consumer.AddHighlighting(new ClosureAllocationHighlighting(anchor, scopeClosure), highlightingRange); } } } }
private IdentifierTooltipContent TryPresentNonColorized([CanBeNull] IHighlighter highlighter, [CanBeNull] IDeclaredElement element, [NotNull] IContextBoundSettingsStore settings) { RichTextBlock richTextToolTip = highlighter?.RichTextToolTip; if (richTextToolTip == null) { return(null); } RichText richText = richTextToolTip.RichText; if (richText.IsNullOrEmpty()) { return(null); } var identifierContent = new IdentifierTooltipContent(richText, highlighter.Range); if (element != null && settings.GetValue((IdentifierTooltipSettings s) => s.ShowIcon)) { identifierContent.Icon = TryGetIcon(element); } return(identifierContent); }
private static ITreeNode GetCaptureHighlightingRange( [NotNull] ITreeNode topDeclaration, [CanBeNull] IParametersOwner thisElement, [NotNull] IDeclaredElement capture, out DocumentRange range) { var declarations = capture.GetDeclarations(); if (declarations.Count == 0) // accessors 'value' parameter { if (thisElement is IAccessor accessor && Equals(accessor.ValueVariable, capture)) { var identifier = ((IAccessorDeclaration)topDeclaration).NameIdentifier; range = identifier.GetDocumentRange(); return(identifier); } range = DocumentRange.InvalidRange; return(null); } var declaration = declarations[0]; range = declaration.GetNameDocumentRange(); var nameEndOffset = range.EndOffset; if (declaration is ILocalVariableDeclaration variableDeclaration) { var multiple = MultipleLocalVariableDeclarationNavigator.GetByDeclarator(variableDeclaration); if (multiple != null && multiple.Declarators[0] == variableDeclaration) { var documentRange = multiple.GetTypeRange(); range = documentRange.SetEndTo(nameEndOffset); return(variableDeclaration); } return(null); } if (declaration is IRegularParameterDeclaration parameterDeclaration) { if (range.TextRange.Length < 3) { range = parameterDeclaration.TypeUsage.GetDocumentRange().SetEndTo(nameEndOffset); } return(parameterDeclaration); } if (declaration is IAnonymousMethodParameterDeclaration anonymousParameter) { range = anonymousParameter.TypeUsage.GetDocumentRange().SetEndTo(nameEndOffset); return(anonymousParameter); } return(declaration); }
/// <summary> /// Gets the state of the expression null reference. /// </summary> /// <param name="treeNode">The element.</param> /// <param name="declaredElement">The declared element.</param> /// <param name="anchor">The anchor.</param> /// <returns>Returns the expression null reference state.</returns> public CodeAnnotationAttribute GetExpressionNullReferenceState(ITreeNode treeNode, IDeclaredElement declaredElement, IDeclarationStatement anchor) { return(this.GetNullReferenceState(treeNode, declaredElement, anchor)); /* * var state = CodeAnnotationAttribute.Undefined; * * const string CookieName = "CodeAnnotations"; * * var solution = treeNode.GetSolution(); * * var cookie = solution.CreateTransactionCookie(DefaultAction.Rollback, CookieName); * try * { * var psiServices = solution.GetPsiServices(); * * Shell.Instance.GetComponent<UITaskExecutor>().SingleThreaded.ExecuteTask(CookieName, TaskCancelable.Yes, delegate(IProgressIndicator progress1) * { * progress1.TaskName = CookieName; * * psiServices.PsiManager.DoTransaction(() => state = this.GetNullReferenceState(treeNode, name, anchorStatement), CookieName); * * cookie.Rollback(); * }); * } * finally * { * if (cookie != null) * { * cookie.Dispose(); * } * } * * return state; */ }
public static bool IsSpecification(this IDeclaredElement element) { return(element.IsValidFieldOfType(typeof(It))); }
public IEnumerable <string> GetAllPossibleWordsInFile(IDeclaredElement element) { return(FSharpNamesUtil.GetPossibleSourceNames(element)); }
/// <summary> /// Gets the state of the expression null reference. /// </summary> /// <param name="treeNode">The element.</param> /// <param name="declaredElement">The declared element.</param> /// <param name="statement">The statement.</param> /// <returns>Returns the expression null reference state.</returns> private CodeAnnotationAttribute GetNullReferenceState(ITreeNode treeNode, IDeclaredElement declaredElement, IDeclarationStatement statement) { var project = treeNode.GetProject(); if (project == null) { return(CodeAnnotationAttribute.Undefined); } var projectFile = project.ProjectFile; if (projectFile == null) { return(CodeAnnotationAttribute.Undefined); } var functionDeclaration = treeNode.GetContainingNode <ICSharpFunctionDeclaration>(true); if (functionDeclaration == null) { return(CodeAnnotationAttribute.Undefined); } var builder = new CSharpControlFlowBuilder(); var graf = builder.GraphFromNode(functionDeclaration, null, true) as ICSharpControlFlowGraph; if (graf == null) { return(CodeAnnotationAttribute.Undefined); } var inspect = graf.Inspect(ValueAnalysisMode.OPTIMISTIC); var position = this.FindPosition(graf.BodyElement.Children, statement); if (position == null) { return(CodeAnnotationAttribute.Undefined); } position = this.FindFollowing(position); if (position == null) { return(CodeAnnotationAttribute.Undefined); } var result = inspect.GetVariableStateAt(position, declaredElement); switch (result) { case CSharpControlFlowNullReferenceState.NOT_NULL: return(CodeAnnotationAttribute.NotNull); case CSharpControlFlowNullReferenceState.NULL: return(CodeAnnotationAttribute.CanBeNull); case CSharpControlFlowNullReferenceState.MAY_BE_NULL: return(CodeAnnotationAttribute.CanBeNull); } return(CodeAnnotationAttribute.Undefined); /* * var block = treeNode.GetContainingNode<IBlock>(true); * if (block == null) * { * return CodeAnnotationAttribute.Undefined; * } * * var project = treeNode.GetProject(); * if (project == null) * { * return CodeAnnotationAttribute.Undefined; * } * * var projectFile = project.ProjectFile; * if (projectFile == null) * { * return CodeAnnotationAttribute.Undefined; * } * * var factory = CSharpElementFactory.GetInstance(treeNode.GetPsiModule()); * var statement = factory.CreateStatement("if(" + name + " == null) { }"); * * var ifStatement = block.AddStatementAfter(statement, (ICSharpStatement)anchorStatement) as IIfStatement; * if (ifStatement == null) * { * return CodeAnnotationAttribute.Undefined; * } * * var equalityExpression = ifStatement.Condition as IEqualityExpression; * if (equalityExpression == null) * { * return CodeAnnotationAttribute.Undefined; * } * * var referenceExpression = equalityExpression.LeftOperand as IReferenceExpression; * if (referenceExpression == null) * { * return CodeAnnotationAttribute.Undefined; * } * * var functionDeclaration = ifStatement.GetContainingNode<ICSharpFunctionDeclaration>(true); * if (functionDeclaration == null) * { * return CodeAnnotationAttribute.Undefined; * } * * var graf = CSharpControlFlowBuilder.Build(functionDeclaration); * if (graf == null) * { * return CodeAnnotationAttribute.Undefined; * } * * var inspect = graf.Inspect(HighlightingSettingsManager.Instance.GetValueAnalysisMode(projectFile)); * if (inspect == null) * { * return CodeAnnotationAttribute.Undefined; * } * * var position = graf.AllElements.FirstOrDefault(e => e.SourceElement == treeNode); * * var result = inspect.GetVariableStateAt(position, declaredElement); * * result = inspect.GetExpressionNullReferenceState(referenceExpression, false); * switch (result) * { * case CSharpControlFlowNullReferenceState.NOT_NULL: * return CodeAnnotationAttribute.NotNull; * * case CSharpControlFlowNullReferenceState.NULL: * return CodeAnnotationAttribute.CanBeNull; * * case CSharpControlFlowNullReferenceState.MAY_BE_NULL: * return CodeAnnotationAttribute.CanBeNull; * } * * return CodeAnnotationAttribute.Undefined; */ }
public static bool IsLocal(this IDeclaredElement element) { return(element is ILocalVariable); }
protected override ICSharpExpression CreateReplacementExpression(ICSharpExpression expression, IDeclaredElement declaredElement) { CSharpElementFactory factory = CSharpElementFactory.GetInstance(expression); return(factory.CreateExpression("\"$0\"", declaredElement.ShortName)); }
public static bool IsField(this IDeclaredElement element) { return(element is IField); }
public bool IsElementOfKind(IDeclaredElement declaredElement, UnitTestElementKind elementKind) { throw new System.NotImplementedException(); }