Search in sources :

Example 1 with ElementImport

use of org.antlr.works.grammar.element.ElementImport in project antlrworks by antlr.

the class GrammarWindow method goToDeclaration.

public void goToDeclaration(final Jumpable ref) {
    goToHistoryRememberCurrentPosition();
    if (ref instanceof ElementImport) {
    //    getContainer().selectEditor(ref.getName());
    } else if (ref != null) {
        GrammarEngine engine = getGrammarEngine();
        int index = engine.getFirstDeclarationPosition(ref.getName());
        if (index == -1) {
            // This grammar does not contain the declaration. Search in the other children
            // starting from the root grammarEngine
            engine = engine.getRootEngine();
            List<String> grammars = engine.getGrammarsOverriddenByRule(ref.getName());
            if (!grammars.isEmpty()) {
                //getContainer().selectEditor(grammars.get(0));
                // set the caret position
                SwingUtilities.invokeLater(new Runnable() {

                    public void run() {
                        GrammarEngine engine = getGrammarEngine();
                        int index = engine.getFirstDeclarationPosition(ref.getName());
                        if (index != -1) {
                            setCaretPosition(index);
                        }
                    }
                });
            }
        } else {
            setCaretPosition(index);
        }
    }
}
Also used : List(java.util.List) ElementImport(org.antlr.works.grammar.element.ElementImport) GrammarEngine(org.antlr.works.grammar.engine.GrammarEngine)

Aggregations

List (java.util.List)1 ElementImport (org.antlr.works.grammar.element.ElementImport)1 GrammarEngine (org.antlr.works.grammar.engine.GrammarEngine)1