private IEnumerable <AttributeInfo> GetSpecificAttributeInfosLocked(IHtmlTagDeclaredElement tag) { return(from d in cache.Directives where d.IsAttribute && d.IsForTagSpecific(tag.ShortName) from n in GetPrefixedNames(d.Name) select new AttributeInfo(GetOrCreateAttributeLocked(n, tag), DefaultAttributeValueType.IMPLIED, null)); }
private IEnumerable <AttributeInfo> GetParameterAttributeInfosLocked(IHtmlTagDeclaredElement tag) { return(from d in cache.Directives where d.IsElement && d.Name.Equals(tag.ShortName, StringComparison.InvariantCultureIgnoreCase) from p in d.Parameters from n in GetPrefixedNames(p.Name) select new AttributeInfo(GetOrCreateAttributeLocked(n, tag), DefaultAttributeValueType.IMPLIED, null)); }
public AngularJsHtmlAttributeDeclaredElement(IPsiServices psiServices, string shortName, IHtmlAttributeValueType type, IHtmlTagDeclaredElement tag) { ShortName = shortName; ValueType = type; Tag = tag; this.psiServices = psiServices; }
private IHtmlAttributeDeclaredElement CreateAndCacheAttributeLocked(string lookupKey, string attributeName, IHtmlTagDeclaredElement tag) { var psiServices = solution.GetComponent <IPsiServices>(); var attribute = new AngularJsHtmlAttributeDeclaredElement(psiServices, attributeName, cdataAttributeValueType, tag); attributes.Add(lookupKey, attribute); return(attribute); }
private IHtmlAttributeDeclaredElement GetOrCreateAttributeLocked(string attributeName, string tagName) { var key = GetAttributeLookupKey(attributeName, tagName); var attribute = GetAttributeLocked(key); if (attribute != null) { return(attribute); } IHtmlTagDeclaredElement tag = null; if (!tagName.Equals(Directive.AnyTagName, StringComparison.InvariantCultureIgnoreCase)) { // This overload is only called when creating attributes as part of GetAttributes or // GetAllAttributesSymbolTable. If the caches aren't populated, we need to create an // attribute which has a reference to its owning tag. This might be an angular tag, // or a standard HTML tag. If it's a standard HTML tag, we can ask the ReSharper to // get it for us. If it's an angular tag, it won't already exist (or the attribute // will already exist, belonging to the tag), so we need to create it, at which // point, it will create the attribute, so we can then look it up in the cache. // Since creating an angular tag using GetTag doesn't cause re-entry, we can just // let HtmlDeclaredElementsCache do all of the work. // // Using IHtmlDeclaredElementsProvider to add elements and attributes is surprisingly // tricky. Perhaps I should be creating all attributes and tags at once, rather than // doing it piecemeal. Would definitely be nice to get more fine grained caching for that. var htmlDeclaredElementsCache = solution.GetComponent <HtmlDeclaredElementsCache>(); // Ugh. The API changed between 2016.1 and 2016.1.2... //tag = htmlDeclaredElementsCache.GetTag(null, tagName); if (getTagMethodInfo.GetParameters().Length == 3) { tag = (IHtmlTagDeclaredElement)getTagMethodInfo.Invoke(htmlDeclaredElementsCache, new object[] { null, tagName, null }); } else { tag = (IHtmlTagDeclaredElement)getTagMethodInfo.Invoke(htmlDeclaredElementsCache, new object[] { tagName, null }); } attribute = GetAttributeLocked(key); if (attribute != null) { return(attribute); } } return(CreateAndCacheAttributeLocked(key, attributeName, tag)); }
private IEnumerable<AttributeInfo> GetSpecificAttributeInfosLocked(IHtmlTagDeclaredElement tag) { return from d in cache.Directives where d.IsAttribute && d.IsForTagSpecific(tag.ShortName) from n in GetPrefixedNames(d.Name) select new AttributeInfo(GetOrCreateAttributeLocked(n, tag), DefaultAttributeValueType.IMPLIED, null); }
private IEnumerable<AttributeInfo> GetParameterAttributeInfosLocked(IHtmlTagDeclaredElement tag) { return from d in cache.Directives where d.IsElement && d.Name.Equals(tag.ShortName, StringComparison.InvariantCultureIgnoreCase) from p in d.Parameters from n in GetPrefixedNames(p.Name) select new AttributeInfo(GetOrCreateAttributeLocked(n, tag), DefaultAttributeValueType.IMPLIED, null); }
private IHtmlAttributeDeclaredElement GetOrCreateAttributeLocked(string attributeName, IHtmlTagDeclaredElement tag) { var key = GetAttributeLookupKey(attributeName, tag == null ? null : tag.ShortName); return GetAttributeLocked(key) ?? CreateAndCacheAttributeLocked(key, attributeName, tag); }
private IHtmlAttributeDeclaredElement CreateAndCacheAttributeLocked(string lookupKey, string attributeName, IHtmlTagDeclaredElement tag) { var psiServices = solution.GetComponent<IPsiServices>(); var attribute = new AngularJsHtmlAttributeDeclaredElement(psiServices, attributeName, cdataAttributeValueType, tag); attributes.Add(lookupKey, attribute); return attribute; }
// Gets (additional) attributes that should apply to the tag. Should not return attributes that are // already known by the tag. The standard standard HtmlDeclaredElementsProvider returns only common // attributes. // Used by HtmlDeclaredElementsCache.GetAdditionalAttributesForTag so a provider can add additional // attributes to a known tag (e.g. angular attributes to a standard HTML tag) // Also used when generating descriptions for tags public IEnumerable<AttributeInfo> GetAttributeInfos(IPsiSourceFile sourceFile, IHtmlTagDeclaredElement tag, bool strict) { lock (lockObject) { // We have nothing to add to an angular tag - it already knows all angular tags if (tag is IAngularJsDeclaredElement) return EmptyArray<AttributeInfo>.Instance; // Note that this includes common attributes var attributeInfos = from d in cache.Directives where d.IsAttribute && d.IsForTag(tag.ShortName) from n in GetPrefixedNames(d.Name) select new AttributeInfo(GetOrCreateAttributeLocked(n, tag), DefaultAttributeValueType.IMPLIED, null); // Get any elements that have the same name as the tag, and add the parameters as attributes // Don't include any attributes that are aleady defined by other providers (this causes the // HTML description cache component to crash) var providers = solution.GetComponents<IHtmlDeclaredElementsProvider>(); var parameterAttributeInfos = from d in cache.Directives where d.IsElement && d.Name == tag.ShortName from p in d.Parameters where !IsKnownCommonAttribute(p.Name, providers) from n in GetPrefixedNames(p.Name) select new AttributeInfo(GetOrCreateAttributeLocked(n, tag), p.IsOptional ? DefaultAttributeValueType.IMPLIED : DefaultAttributeValueType.REQUIRED, null); // Parameter attributes take precedence over attribute directives. Only include one. return parameterAttributeInfos.Concat(attributeInfos) .Distinct(ai => ai.AttributeDeclaredElement.ShortName).ToList(); } }
// Gets (additional) attributes that should apply to the tag. Should not return attributes that are // already known by the tag. The standard standard HtmlDeclaredElementsProvider returns only common // attributes. // Used by HtmlDeclaredElementsCache.GetAdditionalAttributesForTag so a provider can add additional // attributes to a known tag (e.g. angular attributes to a standard HTML tag) // Also used when generating descriptions for tags public IEnumerable <AttributeInfo> GetAttributeInfos(IPsiSourceFile sourceFile, IHtmlTagDeclaredElement tag, bool strict) { lock (lockObject) { // We have nothing to add to an angular tag - it already knows all angular tags if (tag is IAngularJsDeclaredElement) { return(EmptyArray <AttributeInfo> .Instance); } // Note that this includes common attributes var attributeInfos = from d in cache.Directives where d.IsAttribute && d.IsForTag(tag.ShortName) from n in GetPrefixedNames(d.Name) select new AttributeInfo(GetOrCreateAttributeLocked(n, tag), DefaultAttributeValueType.IMPLIED, null); // Get any elements that have the same name as the tag, and add the parameters as attributes // Don't include any attributes that are aleady defined by other providers (this causes the // HTML description cache component to crash) var providers = solution.GetComponents <IHtmlDeclaredElementsProvider>(); var parameterAttributeInfos = from d in cache.Directives where d.IsElement && d.Name == tag.ShortName from p in d.Parameters where !IsKnownCommonAttribute(p.Name, providers) from n in GetPrefixedNames(p.Name) select new AttributeInfo(GetOrCreateAttributeLocked(n, tag), p.IsOptional ? DefaultAttributeValueType.IMPLIED : DefaultAttributeValueType.REQUIRED, null); // Parameter attributes take precedence over attribute directives. Only include one. return(parameterAttributeInfos.Concat(attributeInfos) .Distinct(ai => ai.AttributeDeclaredElement.ShortName).ToList()); } }
private IHtmlAttributeDeclaredElement GetOrCreateAttributeLocked(string attributeName, IHtmlTagDeclaredElement tag) { var key = GetAttributeLookupKey(attributeName, tag == null ? null : tag.ShortName); return(GetAttributeLocked(key) ?? CreateAndCacheAttributeLocked(key, attributeName, tag)); }