public override AttributeDefinition VisitAttribute_name_part(V1QueryParser.Attribute_name_partContext context) { var attributeName = context.NAME().GetText(); var downcast = context.downcast()?.asset_type_token().GetText(); var filter = context.attribute_filter(); AttributeDefinition result; if (!_metaModel.TryGetAttributeDefinition(_rootAssetType, attributeName, out result)) { throw new InvalidOperationException($"Cannot find attribute definition {_rootAssetType.Token}.{attributeName}"); } if (!string.IsNullOrEmpty(downcast)) { var downcastAssetType = _metaModel.GetAssetType(downcast); result = result.CreateDowncastAttributeDefinition(downcastAssetType); } if (filter != null) { var subVisitor = new FilterVisitor(result.RelatedAssetType, _metaModel); var subFilter = subVisitor.Visit(filter); result = result.CreateFilteredAttributeDefinition(subFilter); } return(result); }
public static AttributeDefinition Parse(string attributeDefinitionToken, MetaModel metaModel) { ICharStream charStream = new AntlrInputStream(attributeDefinitionToken); ITokenSource tokenSource = new V1QueryLexer(charStream); ITokenStream tokenStream = new CommonTokenStream(tokenSource); var parser = new V1QueryParser(tokenStream); var parseTree = parser.attribute_definition_token(); var assetTypeToken = parseTree.asset_type_token().GetText(); var assetType = metaModel.GetAssetType(assetTypeToken); var attributeName = parseTree.attribute_name().GetText(); return(Parse(attributeName, assetType, metaModel)); }
public static QueryBuilder For(string assetTypeToken, MetaModel metaModel) { var assetType = metaModel.GetAssetType(assetTypeToken); return new QueryBuilder(assetType, metaModel); }