Пример #1
0
        /// <summary>
        /// Removes the text.
        /// </summary>
        /// <param name="textRange">The text range.</param>
        /// <returns></returns>
        public TextDocument RemoveText(TextRange textRange)
        {
            Assume.NotNull(textRange, nameof(textRange));

            ChangeText(textRange, String.Empty);
            removeTextRange(textRange);

            return(this);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ActualParameterElement"/> class.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="parameterName">Name of the parameter.</param>
        public ActualParameterElement(ConstantElement value, String parameterName)
        {
            Assume.NotNull(value, nameof(value));
            Assume.NotNull(parameterName, nameof(parameterName));

            Value         = value;
            ParameterName = Option.Some(parameterName);
            Position      = Option.None;
        }
        /// <summary>
        /// Creates the document node
        /// </summary>
        public ICsvTreeFactory CreateDocument(TextRange textRange)
        {
            Assume.NotNull(textRange, nameof(textRange));
            var csvCompilationUnit = new CsvCompilationUnit(textRange);

            _csvCompilationUnits.Push(csvCompilationUnit);

            return(this);
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultSelectorResolver"/> class.
        /// </summary>
        public DefaultSelectorResolver(ISelectorFactory selectorFactory, IDescriptorRepository descriptorRepository, INameMatcher nameMatcher = null)
        {
            Assume.NotNull(selectorFactory, nameof(selectorFactory));
            Assume.NotNull(descriptorRepository, nameof(descriptorRepository));

            SelectorFactory      = selectorFactory;
            DescriptorRepository = descriptorRepository;
            NameMatcher          = nameMatcher ?? new EqualityNameMatcher();
        }
        /// <summary>
        /// Creates a selectorElement ElementTypeSelector
        /// </summary>
        public AttributeElement CreateAttributeSelector(String name, ConstantElement value)
        {
            Assume.NotNull(name, nameof(name));

            return(new AttributeElement {
                Name = name,
                Value = value ?? new ConstantElement(null, typeof(Object))
            });
        }
Пример #6
0
        public virtual CsvSyntaxTreeBuilder Visit(String input, IParseTree tree)
        {
            Assume.NotNull(input, nameof(input));
            Assume.NotNull(tree, nameof(tree));

            _textDocument = new TextDocument(input);

            return(base.Visit(tree));
        }
Пример #7
0
        public CommandDescriptor(String name, String description, IEnumerable <ArgumentDescriptor> arguments, IEnumerable <String> commandNames)
        {
            Assume.NotNull(name, nameof(name));
            Assume.NotNull(description, nameof(description));

            Name         = name;
            Description  = description;
            Arguments    = arguments ?? Enumerable.Empty <ArgumentDescriptor>();
            CommandNames = commandNames ?? Enumerable.Empty <String>();
        }
Пример #8
0
        /// <summary>
        /// Changes text in text document without updating positions of other text ranges.
        /// </summary>
        public TextDocument ChangeRawText(TextRange textRange, String replacedText)
        {
            Assume.NotNull(textRange, "updatableTextRange");
            Assume.NotNull(replacedText, "replacedText");

            _text.Remove(textRange.Start, textRange.Stop - textRange.Start)
            .Insert(textRange.Start, replacedText);

            return(this);
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Command"/> class.
        /// </summary>
        public Command(IRunnable runnable, CommandDescriptor commandDescriptor, IDictionary <String, Object> actualArguments)
        {
            Assume.NotNull(runnable, nameof(runnable));
            Assume.NotNull(commandDescriptor, nameof(commandDescriptor));
            Assume.NotNull(actualArguments, nameof(actualArguments));

            Runnable          = runnable;
            CommandDescriptor = commandDescriptor;
            ActualArguments   = new ReadOnlyDictionary <String, Object>(actualArguments);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CombinatorDescriptor"/> class.
        /// </summary>
        public CombinatorDescriptor(String name, String value, Type combinatorType)
        {
            Assume.NotNull(name, nameof(name));
            Assume.NotNull(value, nameof(value));
            Assume.NotNull(combinatorType, nameof(combinatorType));

            Name           = name;
            Value          = value;
            CombinatorType = combinatorType;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BinarySelectorElement"/> class.
        /// </summary>
        public BinarySelectorElement(SelectorElementBase left, SelectorElementBase right, CombinatorElementBase combinatorElement)
        {
            Assume.NotNull(left, nameof(left));
            Assume.NotNull(right, nameof(right));
            Assume.NotNull(combinatorElement, nameof(combinatorElement));

            Left              = left;
            Right             = right;
            CombinatorElement = combinatorElement;
        }
Пример #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SelectorDescriptor"/> class.
        /// </summary>
        public SelectorDescriptor(String name, String value, Type type)
        {
            Assume.NotNull(value, nameof(value));
            Assume.NotNull(name, nameof(name));
            Assume.NotNull(type, nameof(type));

            Value = value;
            Name  = name;
            Type  = type;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultControlFlowFactory"/> class.
        /// </summary>
        public DefaultControlFlowFactory(ICommandCallResolver commandCallResolver, ISelectorResolver selectorResolver, IExecutor executor)
        {
            Assume.NotNull(commandCallResolver, nameof(commandCallResolver));
            Assume.NotNull(selectorResolver, nameof(selectorResolver));
            Assume.NotNull(executor, nameof(executor));

            CommandCallResolver = commandCallResolver;
            SelectorResolver    = selectorResolver;
            Executor            = executor;
        }
Пример #14
0
        /// <summary>
        /// Changes text in text document without updating positions of other text ranges.
        /// </summary>
        protected internal TextDocument changeRawText(TextRange textRange, String replacedText)
        {
            Assume.NotNull(textRange, nameof(textRange));
            Assume.NotNull(replacedText, nameof(replacedText));

            text.Remove(textRange.Start, textRange.Stop - textRange.Start)
            .Insert(textRange.Start, replacedText);

            return(this);
        }
Пример #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextDocument"/> class.
        /// </summary>
        public TextDocument(String text)
        {
            Assume.NotNull(text, nameof(text));

            Text       = text;
            textRanges = new SortedList <TextRange, TextRange>(TextRange.PositionComparer);
            TextRange  = CreateOrGetTextRange(0, text.Length);

            textRangesOffsetList = new SortedList <TextRange, String>(TextRange.PositionComparer);
        }
        /// <summary>
        /// Creates field and appends it to actual row
        /// </summary>
        public ICsvTreeFactory CreateField(TextRange textRange)
        {
            Assume.NotNull(textRange, nameof(textRange));
            checkIsRowAdded();

            var field = new FieldDeclarationSyntax(textRange);

            addChildToLastDefinedRow(field);

            return(this);
        }
        public RowDeclarationSyntax Row(TextRange textRange, IEnumerable <CommaToken> commas, IEnumerable <FieldDeclarationSyntax> fields)
        {
            Assume.NotNull(commas, nameof(commas));
            Assume.NotNull(fields, nameof(fields));

            return(new RowDeclarationSyntax(textRange)
            {
                Commas = commas,
                Fields = fields
            });
        }
        /// <summary>
        /// Creates comma and appends it to actual row
        /// </summary>
        /// <param name="textRange">The text range.</param>
        public ICsvTreeFactory CreateComma(TextRange textRange)
        {
            Assume.NotNull(textRange, nameof(textRange));
            checkIsRowAdded();

            var comma = new CommaToken(textRange);

            addChildToLastDefinedRow(comma);

            return(this);
        }
        /// <summary>
        /// Creates a class element selector.
        /// </summary>
        public ClassSelectorElement CreateClassSelectorElement(String name, Boolean isRegularExpression)
        {
            Assume.NotNull(name, nameof(name));

            if (isRegularExpression)
            {
                return(new RegularExpressionClassSelectorElement(name));
            }

            return(new RawClassSelectorElement(name));
        }
Пример #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyValueDeclaration"/> class.
        /// </summary>
        public KeyValueDeclaration(KeyDeclaration key, ValueDeclaration value, TextRange textRange)
            : base(textRange)
        {
            Assume.NotNull(key, nameof(key));
            Assume.NotNull(value, nameof(value));

            this.key   = key;
            this.value = value;

            children = new Node[2];
            updateChildren(key, value);
        }
Пример #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ModifierDescriptor"/> class.
        /// </summary>
        public ModifierDescriptor(String name, String value, IEnumerable <String> arguments, Type type, Boolean isClassSelector)
        {
            Assume.NotNull(name, nameof(name));
            Assume.NotNull(value, nameof(value));
            Assume.NotNull(arguments, nameof(arguments));
            Assume.NotNull(type, nameof(type));

            Name            = name;
            Value           = value;
            Arguments       = arguments;
            Type            = type;
            IsClassSelector = isClassSelector;
        }
Пример #22
0
        /// <summary>
        /// Creates the number constant.
        /// </summary>
        public JsonNode CreateNumberConstant(TextRange textRange)
        {
            Assume.NotNull(textRange, nameof(textRange));
            var     text = textRange.GetText();
            Decimal value;

            if (!Decimal.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
            {
                throw new NotSupportedException(String.Format("Not supported number format: {0}", text));
            }

            return(new NumberConstant(value, textRange));
        }
Пример #23
0
        public static TObject InstantiateWithDefaultConstructor <TObject>(this Type value)
        {
            Assume.NotNull(value, nameof(value));

            var defaultConstructor = value.GetDefaultConstructor();

            if (defaultConstructor != null)
            {
                return((TObject)defaultConstructor.Invoke(Enumerable.Empty <Object>().ToArray()));
            }

            return(default(TObject));
        }
        /// <summary>
        /// Gets the producers of specified runnable
        /// </summary>
        public IEnumerable <IValueProducer> GetProducers(IRunnable runnable)
        {
            Assume.NotNull(runnable, nameof(runnable));
            var type = runnable.GetType();

            var attributes = type.GetCustomAttributes(inherit: true)
                             .OfType <ProducesAttribute>();

            var producers = attributes.Select(attribute => attribute.ProducerType)
                            .Select(producerType => (IValueProducer)Activator.CreateInstance(producerType));

            return(producers);
        }
Пример #25
0
        public static IEnumerable <TResult> Select <TElement, TResult>(this TElement element, Func <TElement, TResult> func)
            where TElement : IHasNext <TElement>
        {
            Assume.NotNull(func, nameof(func));

            var current = element;

            while (current != null)
            {
                yield return(func(current));

                current = current.Next;
            }
        }
        /// <summary>
        /// Creates a selector by specified name.
        /// </summary>
        public virtual SelectorBase CreateSelector(Type selectorType, IEnumerable <Regex> classSelectors)
        {
            Assume.NotNull(selectorType, nameof(selectorType));

            var selector = (SelectorBase)objectCreator.Create(selectorType);

            if (selector == null)
            {
                throw new Exception($"Cannot instantiate specified selector: {selectorType.FullName}");
            }

            selector.AddClassSelectors(classSelectors);
            return(selector);
        }
Пример #27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextRange"/> class.
        /// </summary>
        internal TextRange(Int32 start, Int32 stop, TextDocument textDocument, TextRange previous = null,
                           TextRange next = null)
        {
            Assume.IsTrue(start >= 0, "start must be positive or zero!");
            Assume.IsTrue(start <= stop, "start must be lesser than stop!");
            Assume.NotNull(textDocument, "textDocument");

            Start        = start;
            Stop         = stop;
            TextDocument = textDocument;

            Previous = previous;
            Next     = next;
        }
        /// <summary>
        /// Creates the specified command call.
        /// </summary>
        public ControlFlowBase Create(CommandCallControlFlowElement commandCall)
        {
            Assume.NotNull(commandCall, nameof(commandCall));

            // resolve command by call
            var command = getCommand(commandCall.CommandCallElement);

            if (command == null)
            {
                throw new Exception("Command is not available!");
            }

            return(new CommandCallControlFlow(command, Executor));
        }
        public void CopyAnnotationsFrom_will_process_lifecycle_events_on_clones()
        {
            var doc  = new DomDocument();
            var anno = new FLifecycleAnnotation();

            var element = doc.CreateElement("a").AddAnnotation(anno);
            var clone   = element.Clone();

            var clonedAnnotation = clone.Annotation <FLifecycleAnnotation>();

            Assume.NotNull(clonedAnnotation);
            Assert.Equal(1, clonedAnnotation.AttachingCallCount);
            Assert.Same(clone, clonedAnnotation.LastAttachingArguments);
        }
Пример #30
0
        /// <summary>
        /// Changes the text in text document. It removes passed text range and creates a new one. Finally, it returns the updated text range.
        /// </summary>
        public TextDocument ChangeText(TextRange textRange, String replacedText)
        {
            Assume.NotNull(textRange, "textRange");
            Assume.NotNull(replacedText, "replacedText");

            ChangeRawText(textRange, replacedText);

            var offset = textRange.Start + replacedText.Length - textRange.Stop;

            updateTextRanges(textRange, offset);

            textRange.Stop = textRange.Start + replacedText.Length;

            return(this);
        }