public void Resolve_ThreeVariablesOneCombination_ReturnsListOfString() { List <string> symbols = new List <string> { "x", "y", "z" }; List <IdentifierResolution> combinations = IdentifierResolver.Resolve(symbols, "xyz"); Assert.AreEqual(1, combinations.Count); Assert.AreEqual("x, y, z", combinations[0].ToString()); }
public void Resolve_ManyVariablesOneCombination_ReturnsListOfString() { List <string> symbols = new List <string> { "x", "a", "y", "b", "c", "d", "ef", "gh" }; List <IdentifierResolution> combinations = IdentifierResolver.Resolve(symbols, "xy"); Assert.AreEqual(1, combinations.Count); Assert.AreEqual("x, y", combinations[0].ToString()); }
public void Resolve_OneVariableRepeatedOneCombination_ReturnsListOfString() { List <string> symbols = new List <string> { "x" }; List <IdentifierResolution> combinations = IdentifierResolver.Resolve(symbols, "xxx"); Assert.AreEqual(1, combinations.Count); Assert.AreEqual("x, x, x", combinations[0].ToString()); }
/// <summary> /// Attempts to retrieve a database object. /// </summary> /// <typeparam name="T">The type of database object to retrieve.</typeparam> /// <param name="objects">Database objects.</param> /// <param name="objectName">The name of the database object to retrieve.</param> /// <returns>An option type with a database object, if available, otherwise an option type in the none state.</returns> /// <exception cref="ArgumentNullException"><paramref name="objectName"/> is <c>null</c>.</exception> protected OptionAsync <T> GetResolvedObject <T>(IReadOnlyCollection <T> objects, Identifier objectName) where T : IDatabaseEntity { if (objectName == null) { throw new ArgumentNullException(nameof(objectName)); } var resolvedNames = IdentifierResolver .GetResolutionOrder(objectName) .Select(QualifyObjectName); return(resolvedNames .Select(name => { var obj = objects.FirstOrDefault(o => QualifyObjectName(o.Name) == name); return obj != null ? Option <T> .Some(obj) : Option <T> .None; }) .FirstSome() .ToAsync()); }
public void Parse() { _dependencyBuilder = new DependencyBuilder(_context.Log, _context.Scripts); _propertySetValueCorrector = new PropertySetValueCorrector(); _propertyPartConsolidator = new PropertyPartConsolidator(); _createObjectStrongTyper = new CreateObjectStrongTyper( new ComTypeImporter( Path.Combine(_context.Settings.OutputDirectory, "lib"), _context.KeyPair, _context.References)); _nestedClassConstructorCorrector = new NestedClassConstructorCorrector(); _identifierDiscoverer = new IdentifierDiscoverer(_context.Log); _staticSetter = new StaticSetter(); _identifierResolver = new IdentifierResolver(_context.Log); _returnValueCorrector = new ReturnValueCorrector(); _stringLocalizer = new StringLocalizer(_context.Settings.Namespace, _context.LocalizedStrings); _assemblyReferenceGatherer = new AssemblyReferenceGatherer(_context.References); _namespaceFactorizer = new NamespaceFactorizer(); using (_context.Status.BeginStep("Parsing scripts...", _context.Plugins.Count + 1)) { foreach (Plugin plugin in _context.Plugins) { if (plugin.Type == PluginType.ActiveScript) { _context.Log.SourcePlugin = plugin; LogInfo(false, "Parsing '{0}' script", plugin); Parse(plugin); _context.Log.SourcePlugin = null; } if (!_context.Status.Advance()) { return; } } bool unfinished = true; while (unfinished) { unfinished = false; foreach (ScriptInfo script in new List<ScriptInfo>(_context.Scripts.Values)) { if (script.TypeDeclaration == null && !script.IsInvalid) { _context.Log.SourcePlugin = script.Plugin; LogInfo(false, "Parsing '{0}' script", script); if (script.IsForm) { ParseNew(script); } else { Parse(script); } unfinished = true; _context.Log.SourcePlugin = null; } if (_context.Status.IsCancelled) { return; } } } } }
public static void SpellCheck(IDocument document, ITokenNode token, ISpellChecker spellChecker, ISolution solution, DefaultHighlightingConsumer consumer, IContextBoundSettingsStore settingsStore, StringSettings settings) { if (spellChecker == null) { return; } string buffer = unescape(token.GetText()); ILexer wordLexer = new WordLexer(buffer); wordLexer.Start(); while (wordLexer.TokenType != null) { string tokenText = wordLexer.GetCurrTokenText(); if (SpellCheckUtil.ShouldSpellCheck(tokenText, settings.CompiledWordsToIgnore) && !spellChecker.TestWord(tokenText, true)) { IClassMemberDeclaration containingElement = token.GetContainingNode <IClassMemberDeclaration>(false); if (containingElement == null || !IdentifierResolver.IsIdentifier(containingElement, solution, tokenText)) { CamelHumpLexer camelHumpLexer = new CamelHumpLexer(buffer, wordLexer.TokenStart, wordLexer.TokenEnd); foreach (LexerToken humpToken in camelHumpLexer) { if (SpellCheckUtil.ShouldSpellCheck(humpToken.Value, settings.CompiledWordsToIgnore) && !spellChecker.TestWord(humpToken.Value, true)) { //int start = token.GetTreeStartOffset().Offset + wordLexer.TokenStart; //int end = start + tokenText.Length; //TextRange range = new TextRange(start, end); //DocumentRange documentRange = new DocumentRange(document, range); DocumentRange documentRange = token.GetContainingFile().TranslateRangeForHighlighting(token.GetTreeTextRange()); documentRange = documentRange.ExtendLeft(-wordLexer.TokenStart); documentRange = documentRange.ExtendRight(-1 * (documentRange.GetText().Length - tokenText.Length)); TextRange textRange = new TextRange(humpToken.Start - wordLexer.TokenStart, humpToken.End - wordLexer.TokenStart); //string word = document.GetText(range); string word = documentRange.GetText(); consumer.AddHighlighting( new StringSpellCheckHighlighting( word, documentRange, humpToken.Value, textRange, solution, spellChecker, settingsStore), documentRange); break; } } } } wordLexer.Advance(); } }