private static string GetParameterType(CommonTree tree)
        {
            int index = 0;

            while (index < tree.ChildCount)
            {
                switch (tree.GetChild(index).Type)
                {
                case Java2Lexer.MONKEYS_AT:
                case Java2Lexer.FINAL:
                    index++;
                    continue;

                default:
                    break;
                }

                break;
            }

            string typeText = GetTypeText((CommonTree)tree.GetChild(index));

            if (tree.GetFirstChildWithType(Java2Lexer.ELLIPSIS) != null)
            {
                typeText = typeText + "...";
            }

            return(typeText);
        }
Beispiel #2
0
        private IEnumerable <string> ProcessFunctionParameters(CommonTree child)
        {
            CommonTree parameterTree = child.GetFirstChildWithType(GoLexer.LPAREN) as CommonTree;

            if (parameterTree == null)
            {
                yield break;
            }

            foreach (CommonTree parameter in parameterTree.Children)
            {
                if (parameter.Type == GoLexer.RPAREN)
                {
                    continue;
                }

                if (parameter.ChildCount == 0)
                {
                    yield return(parameter.Text);
                }
                else if (parameter.ChildCount == 1)
                {
                    yield return(string.Format("{0} {1}", parameter.Text, GetTypeString((CommonTree)parameter.GetChild(0))));
                }
                else
                {
                    yield return("<unknown parameter>");
                }
            }
        }
Beispiel #3
0
        public int CountAltsForRule(CommonTree t)
        {
            CommonTree block = (CommonTree)t.GetFirstChildWithType(BLOCK);

            if (block == null || block.ChildCount == 0)
            {
                return(0);
            }

            return(block.Children.Count(i => i.Type == ALT));
        }
Beispiel #4
0
        private IEnumerable <TeaseButton> GetButtons(CommonTree propertiesNode)
        {
            var result = new List <TeaseButton>();

            var goNode = propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.GO) as CommonTree;

            if (goNode != null)
            {
                result.Add(new TeaseButton {
                    Text = "Continue", Target = GetPageId(goNode.GetChild(0) as CommonTree)
                });
            }
            var ynNode = propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.YN) as CommonTree;

            if (ynNode != null)
            {
                result.Add(new TeaseButton {
                    Text = "Yes", Target = GetPageId(ynNode.GetFirstChildWithType(FlashTeaseScriptLexer.YES).GetChild(0) as CommonTree)
                });
                result.Add(new TeaseButton {
                    Text = "No", Target = GetPageId(ynNode.GetFirstChildWithType(FlashTeaseScriptLexer.NO).GetChild(0) as CommonTree)
                });
            }
            var buttonsNode = propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.BUTTONS) as CommonTree;

            if (buttonsNode != null)
            {
                foreach (CommonTree buttonNode in buttonsNode.Children.Where(x => x.Type == FlashTeaseScriptLexer.BUTTON))
                {
                    result.Add(new TeaseButton
                    {
                        Text   = buttonNode.GetFirstChildWithType(FlashTeaseScriptLexer.CAP).GetChild(0).Text.Trim('\'', '"'),
                        Target = GetPageId(buttonNode.GetFirstChildWithType(FlashTeaseScriptLexer.TARGET).GetChild(0) as CommonTree)
                    });
                }
            }

            result.Reverse();
            return(result);
        }
Beispiel #5
0
        private TeaseDelay GetDelay(CommonTree delayNode)
        {
            if (delayNode == null)
            {
                return(null);
            }

            var result = new TeaseDelay();

            var timeNode = delayNode.GetFirstChildWithType(FlashTeaseScriptLexer.TIME) as CommonTree;

            if (timeNode != null)
            {
                int secs = System.Convert.ToInt32(timeNode.GetChild(0).Text);
                if (timeNode.GetChild(1).Text == "min")
                {
                    secs = secs * 60;
                }
                result.Seconds = secs.ToString();
            }

            result.Target = GetPageId(delayNode.GetFirstChildWithType(FlashTeaseScriptLexer.TARGET).GetChild(0) as CommonTree);

            var styleNode = delayNode.GetFirstChildWithType(FlashTeaseScriptLexer.STYLE) as CommonTree;

            if (styleNode != null && styleNode.ChildCount > 0)
            {
                switch (styleNode.GetChild(0).Text)
                {
                case "hidden": result.Style = DelayStyle.Hidden; break;

                case "secret": result.Style = DelayStyle.Secret; break;

                default: result.Style = DelayStyle.Normal; break;
                }
            }

            return(result);
        }
Beispiel #6
0
        private TeaseMedia GetAudio(CommonTree soundNode)
        {
            if (soundNode == null)
            {
                return(null);
            }

            var result = new  TeaseMedia();

            var idNode = soundNode.GetFirstChildWithType(FlashTeaseScriptLexer.ID) as CommonTree;

            if (idNode != null)
            {
                result.Id = idNode.GetChild(0).Text.Trim('\'', '"');
            }

            var loopsNode = soundNode.GetFirstChildWithType(FlashTeaseScriptLexer.LOOPS) as CommonTree;

            if (loopsNode != null && loopsNode.ChildCount > 0)
            {
                result.Repeat = loopsNode.GetChild(0).Text;
            }
            return(result);
        }
Beispiel #7
0
        private string GetPageId(CommonTree node)
        {
            if (node.Type == FlashTeaseScriptLexer.RANGE)
            {
                var fromNode = node.GetChild(0) as CommonTree;
                var toNode   = node.GetChild(1) as CommonTree;
                if (fromNode != null && toNode != null)
                {
                    var fromText = String.Concat(fromNode.Children.Select(child => child.Text).ToArray());
                    var toText   = String.Concat(toNode.Children.Select(child => child.Text).ToArray());

                    var prefix = node.GetFirstChildWithType(FlashTeaseScriptLexer.PREFIX) as CommonTree;

                    string prefixText = (prefix != null) ? prefix.GetChild(0).Text.Trim('\'', '"') : null;

                    return(String.Format("{0}({1}..{2})", prefixText, fromText, toText));
                }
            }
            return(String.Concat(node.Children.Select(child => child.Text).ToArray()));
        }
Beispiel #8
0
 public static CommonTree GetFirstChildArguments(this CommonTree tree)
 {
     return(tree.GetFirstChildWithType(ES3Parser.ARGS) as CommonTree);
 }
Beispiel #9
0
        private TeaseDelay GetDelay(CommonTree delayNode)
        {
            if (delayNode == null)
            {
                return(null);
            }

            var result = new TeaseDelay();

            var timeNode = delayNode.GetFirstChildWithType(FlashTeaseScriptLexer.TIME) as CommonTree;

            if (timeNode != null)
            {
                var minNode = (CommonTree)timeNode.GetFirstChildWithType(FlashTeaseScriptLexer.MIN);
                int minSecs = Convert.ToInt32(minNode.GetChild(0).Text);
                if (minNode.ChildCount > 1)
                {
                    var minUnit = minNode.GetChild(1).Text;
                    switch (minUnit)
                    {
                    case "hrs": { minSecs = minSecs * 60 * 60; break; }

                    case "min": { minSecs = minSecs * 60; break; }

                    default: break;
                    }
                }

                var maxNode = timeNode.GetFirstChildWithType(FlashTeaseScriptLexer.MAX) as CommonTree;
                int maxSecs = -1;
                if (maxNode != null)
                {
                    maxSecs = Convert.ToInt32(maxNode.GetChild(0).Text);
                    if (maxNode.ChildCount > 1)
                    {
                        var maxUnit = maxNode.GetChild(1).Text;
                        switch (maxUnit)
                        {
                        case "hrs": { maxSecs = maxSecs * 60 * 60; break; }

                        case "min": { maxSecs = maxSecs * 60; break; }

                        default: break;
                        }
                    }
                }

                result.Seconds = (maxSecs > minSecs) ? String.Format("({0}..{1})", minSecs, maxSecs) : String.Format("{0}", minSecs);
            }

            result.Target = GetPageId(delayNode.GetFirstChildWithType(FlashTeaseScriptLexer.TARGET).GetChild(0) as CommonTree);

            var styleNode = delayNode.GetFirstChildWithType(FlashTeaseScriptLexer.STYLE) as CommonTree;

            if (styleNode != null && styleNode.ChildCount > 0)
            {
                switch (styleNode.GetChild(0).Text.ToLowerInvariant())
                {
                case "hidden": result.Style = DelayStyle.Hidden; break;

                case "secret": result.Style = DelayStyle.Secret; break;

                default: result.Style = DelayStyle.Normal; break;
                }
            }

            return(result);
        }
        private void UpdateTags(AntlrParseResultEventArgs antlrParseResultArgs)
        {
            List <IEditorNavigationTarget> navigationTargets = new List <IEditorNavigationTarget>();

            IAstRuleReturnScope resultArgs = antlrParseResultArgs.Result as IAstRuleReturnScope;
            var result = resultArgs != null ? resultArgs.Tree as CommonTree : null;

            if (result != null)
            {
                ITextSnapshot snapshot = antlrParseResultArgs.Snapshot;

                string package = string.Empty;

                /* ^('package' qualifiedName)
                 *
                 * ^(CLASS_TYPE_IDENTIFIER modifiers .* ^(TYPE_BODY .* '}'))
                 *
                 * ^(INTERFACE_TYPE_IDENTIFIER modifiers .* ^(TYPE_BODY .* '}'))
                 *
                 * ^(ANNOTATION_TYPE_IDENTIFIER modifiers .* ^(TYPE_BODY .* '}'))
                 *
                 * ^(FIELD_DECLARATION modifiers (.* ^(VARIABLE_IDENTIFIER .*))*)
                 *
                 * ^(METHOD_IDENTIFIER modifiers .* ^(FORMAL_PARAMETERS .* ')') .* ^(METHOD_BODY .* '}'))
                 */

                /* STATEMENT COMPLETION (description unrelated to this file)
                 *
                 * IDENTIFIER ('.' IDENTIFIER)*
                 *
                 * ^(CALL IDENTIFIER .*)
                 *
                 * ^('(' ^('==' .*) ')')
                 *
                 */

                for (CommonTreeNodeStream treeNodeStream = new CommonTreeNodeStream(result);
                     treeNodeStream.LA(1) != CharStreamConstants.EndOfFile;
                     treeNodeStream.Consume())
                {
                    switch (treeNodeStream.LA(1))
                    {
                    case Java2Lexer.PACKAGE:
                        // ^('package' qualifiedName)
                    {
                        CommonTree child = treeNodeStream.LT(1) as CommonTree;
                        if (child != null && child.ChildCount > 0)
                        {
                            package = GetQualifiedIdentifier(child.GetChild(0));
                        }
                    }

                    break;

                    case Java2Lexer.VARIABLE_IDENTIFIER:
                        // ^(FIELD_DECLARATION (.* ^(VARIABLE_IDENTIFIER))*)
                    {
                        CommonTree child = treeNodeStream.LT(1) as CommonTree;
                        if (child != null && child.HasAncestor(Java2Lexer.FIELD_DECLARATION))
                        {
                            string name = child.Token.Text;
                            IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Members);
                            var                   startToken     = antlrParseResultArgs.Tokens[child.TokenStartIndex];
                            var                   stopToken      = antlrParseResultArgs.Tokens[child.TokenStopIndex];
                            SnapshotSpan          span           = new SnapshotSpan(snapshot, new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1));
                            SnapshotSpan          seek           = new SnapshotSpan(snapshot, new Span(child.Token.StartIndex, 0));
                            StandardGlyphGroup    glyphGroup     = StandardGlyphGroup.GlyphGroupJSharpField;
                            StandardGlyphItem     glyphItem      = GetGlyphItemFromChildModifier((CommonTree)child.GetAncestor(Java2Lexer.FIELD_DECLARATION));
                            ImageSource           glyph          = _provider.GlyphService.GetGlyph(glyphGroup, glyphItem);
                            NavigationTargetStyle style          = NavigationTargetStyle.None;
                            navigationTargets.Add(new EditorNavigationTarget(name, navigationType, span, seek, glyph, style));
                        }
                    }

                    break;

                    case Java2Lexer.METHOD_IDENTIFIER:
                        // ^(METHOD_IDENTIFIER ^(FORMAL_PARAMETERS formalParameterDecls?) ^(METHOD_BODY .* END_METHOD_BODY))
                    {
                        CommonTree child = treeNodeStream.LT(1) as CommonTree;
                        if (child != null)
                        {
                            string name = child.Token.Text;
                            IEnumerable <string> args = ProcessArguments((CommonTree)child.GetFirstChildWithType(Java2Lexer.FORMAL_PARAMETERS));
                            string sig = string.Format("{0}({1})", name, string.Join(", ", args));
                            IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Members);
                            var                   startToken     = antlrParseResultArgs.Tokens[child.TokenStartIndex];
                            var                   stopToken      = antlrParseResultArgs.Tokens[child.TokenStopIndex];
                            SnapshotSpan          span           = new SnapshotSpan(snapshot, new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1));
                            SnapshotSpan          seek           = new SnapshotSpan(snapshot, new Span(child.Token.StartIndex, 0));
                            StandardGlyphGroup    glyphGroup     = StandardGlyphGroup.GlyphGroupJSharpMethod;
                            StandardGlyphItem     glyphItem      = GetGlyphItemFromChildModifier(child);
                            ImageSource           glyph          = _provider.GlyphService.GetGlyph(glyphGroup, glyphItem);
                            NavigationTargetStyle style          = NavigationTargetStyle.None;
                            navigationTargets.Add(new EditorNavigationTarget(sig, navigationType, span, seek, glyph, style));
                        }
                    }

                    break;

                    case Java2Lexer.ENUM_TYPE_IDENTIFIER:
                    case Java2Lexer.ANNOTATION_TYPE_IDENTIFIER:
                    case Java2Lexer.INTERFACE_TYPE_IDENTIFIER:
                    case Java2Lexer.CLASS_TYPE_IDENTIFIER:
                    {
                        CommonTree child = treeNodeStream.LT(1) as CommonTree;
                        if (child != null)
                        {
                            string name = child.Token.Text;
                            for (ITree parent = child.Parent; parent != null; parent = parent.Parent)
                            {
                                switch (parent.Type)
                                {
                                case Java2Lexer.ENUM_TYPE_IDENTIFIER:
                                case Java2Lexer.ANNOTATION_TYPE_IDENTIFIER:
                                case Java2Lexer.INTERFACE_TYPE_IDENTIFIER:
                                case Java2Lexer.CLASS_TYPE_IDENTIFIER:
                                    name = parent.Text + "." + name;
                                    continue;

                                default:
                                    continue;
                                }
                            }

                            if (!string.IsNullOrEmpty(package))
                            {
                                name = package + "." + name;
                            }

                            IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Types);
                            var          startToken = antlrParseResultArgs.Tokens[child.TokenStartIndex];
                            var          stopToken  = antlrParseResultArgs.Tokens[child.TokenStopIndex];
                            SnapshotSpan span       = new SnapshotSpan(snapshot, new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1));
                            SnapshotSpan seek       = new SnapshotSpan(snapshot, new Span(child.Token.StartIndex, 0));

                            StandardGlyphGroup glyphGroup;
                            switch (child.Type)
                            {
                            case Java2Lexer.ENUM_TYPE_IDENTIFIER:
                                glyphGroup = StandardGlyphGroup.GlyphGroupEnum;
                                break;

                            case Java2Lexer.ANNOTATION_TYPE_IDENTIFIER:
                            case Java2Lexer.INTERFACE_TYPE_IDENTIFIER:
                                glyphGroup = StandardGlyphGroup.GlyphGroupJSharpInterface;
                                break;

                            case Java2Lexer.CLASS_TYPE_IDENTIFIER:
                            default:
                                glyphGroup = StandardGlyphGroup.GlyphGroupJSharpClass;
                                break;
                            }

                            StandardGlyphItem     glyphItem = GetGlyphItemFromChildModifier(child);
                            ImageSource           glyph     = _provider.GlyphService.GetGlyph(glyphGroup, glyphItem);
                            NavigationTargetStyle style     = NavigationTargetStyle.None;
                            navigationTargets.Add(new EditorNavigationTarget(name, navigationType, span, seek, glyph, style));
                        }
                    }

                    break;

                    default:
                        continue;
                    }
                }
            }

            this._navigationTargets = navigationTargets;
            OnNavigationTargetsChanged(EventArgs.Empty);
        }