Search in sources :

Example 41 with ATEToken

use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.

the class EditorTips method display.

public void display(Point relativePoint, Point absolutePoint) {
    if (window.getTokens() == null)
        return;
    int position = window.getTextPane().viewToModel(relativePoint);
    Point p = null;
    try {
        ATEToken token = window.getTokenAtPosition(position, false);
        if (token != null) {
            // Make sure the mouse is over the token because
            // Swing will return a valid position even if the mouse
            // is on the remaining blank part of the line
            Rectangle r1 = window.getTextPane().modelToView(token.getStartIndex());
            Rectangle r2 = window.getTextPane().modelToView(token.getEndIndex());
            if (r1.union(r2).contains(relativePoint)) {
                p = SwingUtilities.convertPoint(window.getTextPane(), new Point(relativePoint.x + 2, r2.y - 5), window.getJavaContainer());
            }
        }
    } catch (BadLocationException e) {
    // Ignore
    }
    tipsManager.displayAnyTipsAvailable(position, p);
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken) BadLocationException(javax.swing.text.BadLocationException)

Example 42 with ATEToken

use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.

the class DBLocal method getCustomImports.

/**
     * Returns a string of import statement based on the package declaration inside any @header block
     */
private String getCustomImports() {
    List<ElementBlock> blocks = debuggerTab.getBlocks();
    if (blocks == null || blocks.isEmpty()) {
        return "";
    }
    Set<String> imports = new HashSet<String>();
    for (ElementBlock block : blocks) {
        if (!block.name.equals(GrammarSyntaxParser.PARSER_HEADER_BLOCK_NAME) && !block.name.equals(GrammarSyntaxParser.LEXER_HEADER_BLOCK_NAME)) {
            continue;
        }
        List<ATEToken> tokens = block.internalTokens;
        for (int j = 0; j < tokens.size(); j++) {
            ATEToken token = tokens.get(j);
            if (token.type == ATESyntaxLexer.TOKEN_ID && token.getAttribute().equals("package")) {
                StringBuilder sb = new StringBuilder();
                j++;
                while (j < tokens.size()) {
                    ATEToken t = tokens.get(j);
                    String at = t.getAttribute();
                    if (at.equals(";"))
                        break;
                    sb.append(at);
                    j++;
                }
                imports.add(sb.toString());
            }
        }
    }
    if (imports.isEmpty()) {
        return "";
    }
    StringBuilder importLines = new StringBuilder();
    for (String importName : imports) {
        importLines.append("import ");
        importLines.append(importName);
        importLines.append(".*;\n");
    }
    return importLines.toString();
}
Also used : ElementBlock(org.antlr.works.grammar.element.ElementBlock) ATEToken(org.antlr.works.ate.syntax.misc.ATEToken) HashSet(java.util.HashSet)

Aggregations

ATEToken (org.antlr.works.ate.syntax.misc.ATEToken)42 ElementGroup (org.antlr.works.grammar.element.ElementGroup)2 ElementRule (org.antlr.works.grammar.element.ElementRule)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 BadLocationException (javax.swing.text.BadLocationException)1 ATESyntaxEngine (org.antlr.works.ate.syntax.generic.ATESyntaxEngine)1 ATESyntaxParser (org.antlr.works.ate.syntax.generic.ATESyntaxParser)1 Usages (org.antlr.works.find.Usages)1 ElementAction (org.antlr.works.grammar.element.ElementAction)1 ElementBlock (org.antlr.works.grammar.element.ElementBlock)1 GrammarSyntaxLexer (org.antlr.works.grammar.syntax.GrammarSyntaxLexer)1 ElementTemplateRule (org.antlr.works.stringtemplate.element.ElementTemplateRule)1