private static IdentifierInfo AnalizeStatement(IStatement statement) { var typeDeclarations = new List<string>(); var typePropertyDeclarations = new List<string>(); foreach (var fact in statement.FactsEnumerable) { var predicate = fact.Predicate; if (predicate != null && predicate.FirstChild != null && predicate.FirstChild.GetTokenType() == NTriplesTokenType.A_KEYWORD) { typeDeclarations.AddRange( fact.ObjectsEnumerable.Select(expression => expression.ToUri()).Where(uri => uri != null)); } else if (GetExpressionUri(fact.PredicateIdentifiersEnumerable) == TypePropertyDeclaration) { typePropertyDeclarations.AddRange(fact.ObjectsEnumerable.SelectNotNull(e => e.ToUri())); } } bool isClass = typeDeclarations.Any(declaration => declaration == Class); if (isClass || typePropertyDeclarations.Count > 0) { return IdentifierInfo.CreateClassDeclaration(isClass, typePropertyDeclarations.ToArray()); } if (typeDeclarations.Any()) { return IdentifierInfo.CreateClassInstantiation(typeDeclarations.ToArray()); } return new IdentifierInfo(IdentifierKind.Subject); }
private static IdentifierInfo AnalizeStatement(IStatement statement) { var typeDeclarations = new List <string>(); var typePropertyDeclarations = new List <string>(); foreach (var fact in statement.FactsEnumerable) { var predicate = fact.Predicate; if (predicate != null && predicate.FirstChild != null && predicate.FirstChild.GetTokenType() == NTriplesTokenType.A_KEYWORD) { typeDeclarations.AddRange( fact.ObjectsEnumerable.Select(expression => expression.ToUri()).Where(uri => uri != null)); } else if (GetExpressionUri(fact.PredicateIdentifiersEnumerable) == TypePropertyDeclaration) { typePropertyDeclarations.AddRange(fact.ObjectsEnumerable.SelectNotNull(e => e.ToUri())); } } bool isClass = typeDeclarations.Any(declaration => declaration == Class); if (isClass || typePropertyDeclarations.Count > 0) { return(IdentifierInfo.CreateClassDeclaration(isClass, typePropertyDeclarations.ToArray())); } if (typeDeclarations.Any()) { return(IdentifierInfo.CreateClassInstantiation(typeDeclarations.ToArray())); } return(new IdentifierInfo(IdentifierKind.Subject)); }
public override void VisitStatement(IStatement statementParam, IHighlightingConsumer consumer) { var canBeSimplified = statementParam.FactsEnumerable.GroupBy(x => x.Predicate.GetText()).Any(x => x.Count() >= 2); if (canBeSimplified) { this.AddFactsSuggestionHighlighting( consumer, "Facts can be simplified", statementParam.FactsEnumerable.First(), statementParam.FactsEnumerable.Last()); } }
public override void VisitStatement(IStatement statementParam, IHighlightingConsumer consumer) { var canBeSimplified = statementParam.FactsEnumerable.GroupBy(x => x.Predicate.GetText()).Any(x => x.Count() >= 2); if (canBeSimplified) { this.AddFactsSuggestionHighlighting( consumer, "Facts can be simplified", statementParam.FactsEnumerable.First(), statementParam.FactsEnumerable.Last()); } }
public static IEnumerable <string> GetPropertyUris(this IStatement statement) { return(statement.FactsEnumerable.Where(fact => fact.Predicate.ToUri() == TypePropertyDeclaration) .SelectMany(propertyFact => propertyFact.ObjectsEnumerable).SelectNotNull(ToUri)); }
public static IEnumerable <IExpression> GetPropertyExpressions(this IStatement statement) { return(statement.FactsEnumerable.Where(fact => fact.Predicate.ToUri() == TypePropertyDeclaration) .SelectMany(propertyFact => propertyFact.ObjectsEnumerable)); }
public virtual ReSharper.NTriples.Tree.IStatement SetStatement(ReSharper.NTriples.Tree.IStatement param) { using (JetBrains.Application.WriteLockCookie.Create(this.IsPhysical())) { TreeElement current = null, next = GetNextFilteredChild(current), result = null; next = GetNextFilteredChild(current); if (next.NodeType == ReSharper.NTriples.Impl.Tree.ElementType.STATEMENT) { next = GetNextFilteredChild(current); if (next == null) { if (param == null) { return(null); } result = current = (TreeElement)JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.AddChildAfter(this, current, (JetBrains.ReSharper.Psi.Tree.ITreeNode)param); } else { if (next.NodeType == ReSharper.NTriples.Impl.Tree.ElementType.STATEMENT) { if (param != null) { result = current = (TreeElement)JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.ReplaceChild(next, (JetBrains.ReSharper.Psi.Tree.ITreeNode)param); } else { current = GetNextFilteredChild(next); JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.DeleteChild(next); } } else { if (param == null) { return(null); } result = (TreeElement)JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.AddChildBefore(next, (JetBrains.ReSharper.Psi.Tree.ITreeNode)param); current = next; } } } else if (next.NodeType == ReSharper.NTriples.Impl.Tree.ElementType.DIRECTIVE) { next = GetNextFilteredChild(current); if (next == null) { if (param == null) { return(null); } result = current = (TreeElement)JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.AddChildAfter(this, current, (JetBrains.ReSharper.Psi.Tree.ITreeNode)param); } else { if (next.NodeType == ReSharper.NTriples.Impl.Tree.ElementType.DIRECTIVE) { if (param != null) { result = current = (TreeElement)JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.ReplaceChild(next, (JetBrains.ReSharper.Psi.Tree.ITreeNode)param); } else { current = GetNextFilteredChild(next); JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.DeleteChild(next); } } else { if (param == null) { return(null); } result = (TreeElement)JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.AddChildBefore(next, (JetBrains.ReSharper.Psi.Tree.ITreeNode)param); current = next; } } } else { next = GetNextFilteredChild(current); if (next == null) { if (param == null) { return(null); } result = current = (TreeElement)JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.AddChildAfter(this, current, (JetBrains.ReSharper.Psi.Tree.ITreeNode)param); } else { if (next.NodeType == ReSharper.NTriples.Impl.Tree.ElementType.STATEMENT) { if (param != null) { result = current = (TreeElement)JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.ReplaceChild(next, (JetBrains.ReSharper.Psi.Tree.ITreeNode)param); } else { current = GetNextFilteredChild(next); JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.DeleteChild(next); } } else { if (param == null) { return(null); } result = (TreeElement)JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.AddChildBefore(next, (JetBrains.ReSharper.Psi.Tree.ITreeNode)param); current = next; } } } return((ReSharper.NTriples.Tree.IStatement)result); } }