private void AddHighlighting(IElement elementToHighlight, IHighlighting highlighting) { m_Highlightings.Add(new HighlightingInfo(elementToHighlight.GetDocumentRange(), highlighting)); }
private void ProcessElementParametersOwner(IElement element) { IDeclaredParametersOwner declaredParametersOwner = element as IDeclaredParametersOwner; // TODO use get reference if(declaredParametersOwner != null) { IParameterDescriptorProvider parameterDescriptorProvider = declaredParametersOwner as IParameterDescriptorProvider; if (parameterDescriptorProvider == null) return; if(!parameterDescriptorProvider.IsAvailable) return; ICollection<IParameterDescriptor> infos = parameterDescriptorProvider.GetParameterDescriptors(); ICollection<IDeclaredParameter> declaredParameters = declaredParametersOwner.GetParams(); // Highlight invalid names foreach (IDeclaredParameter param in declaredParameters) { if(ParametersUtil.GetByName(infos, param.Name) == null) { highlightings.Add(new HighlightingInfo(param.NameDocumentRange, new InvalidPropertyHighlighting())); } } // Highlight requred attributes IXmlTag tag = element as IXmlTag; foreach (IParameterDescriptor descriptor in infos) { if(descriptor.IsRequired) { if(ParametersUtil.GetByName(declaredParameters, descriptor.Name) != null // it is conxeption hak, TODO fix parameters conception || (tag != null && tag.GetAttribute(descriptor.Name) != null)) continue; DocumentRange range; if (tag != null) range = GetHighlightRange(tag.ToTreeNode().Header); else range = element.ToTreeNode().GetDocumentRange(); highlightings.Add(new HighlightingInfo(range, new MissedParameterError(descriptor, element))); } } // highlight invalid values foreach (IDeclaredParameter param in declaredParameters) { IParameterDescriptor descriptor = ParametersUtil.GetByName(infos, param.Name); if (descriptor == null) continue; IParameterStringValueValidator validator = ValidatorsManager.Instance().GetValidator(descriptor); if (validator == null) continue; // TODO introduce interface marker to determine tag pased parameters PropertyParamImpl propertyParam = param as PropertyParamImpl; IXmlAttributeValue attributeValue = null; if (propertyParam != null) { attributeValue = propertyParam.Value; } else // attribute { IXmlAttribute attribute = ((IXmlTag)declaredParametersOwner).GetAttribute(param.Name); if (attribute != null) attributeValue = attribute.Value; } if (attributeValue == null) continue; string unquotedValue = attributeValue.UnquotedValue; ValidationResult validateResult = validator.Validate(unquotedValue); if (validateResult == ValidationResult.Ok) continue; if(validateResult.Range == TextRange.InvalidRange) continue; int valueStart = attributeValue.ToTreeNode().GetDocumentRange().TextRange.StartOffset + 1; TextRange valueRange = new TextRange(valueStart, valueStart + unquotedValue.Length); int errorStart = valueRange.StartOffset + validateResult.Range.StartOffset; TextRange errorRange = new TextRange(errorStart, errorStart + validateResult.Range.Length); errorRange = valueRange.Intersect(errorRange); if (errorRange == TextRange.InvalidRange) continue; if(errorRange.IsEmpty) { if (attributeValue.UnquotedValue.Length == 0) { errorRange = new TextRange(errorRange.StartOffset - 1, errorRange.StartOffset + 1); } else continue; } highlightings.Add(new HighlightingInfo( new DocumentRange(element.GetDocumentRange().Document, errorRange), new InvalidValue(validateResult.Message))); } } }
/// <summary> /// Get the line number that the provided element is on. 0 based. /// </summary> /// <param name="element"> /// The element to use. /// </param> /// <returns> /// An <see cref="int"/> of the line number. 0 based. -1 if the element was invalid. /// </returns> public static JB::JetBrains.Util.dataStructures.TypedIntrinsics.Int32<DocLine> GetLineNumberForElement(IElement element) { DocumentRange range = element.GetDocumentRange(); if (range == DocumentRange.InvalidRange) { JB::JetBrains.Util.dataStructures.TypedIntrinsics.Int32<DocLine> line = (JB::JetBrains.Util.dataStructures.TypedIntrinsics.Int32<DocLine>)0; return line.Minus1(); } return range.Document.GetCoordsByOffset(range.TextRange.StartOffset).Line; }