Package org.antlr.works.ate.syntax.misc

Examples of org.antlr.works.ate.syntax.misc.ATEToken


    }

    public void replaceLiteralWithTokenLabel() {
        StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_REPLACE_LITERALS);

        ATEToken token = window.getCurrentToken();
        if(token == null)
            return;

        if(token.type != ATESyntaxLexer.TOKEN_SINGLE_QUOTE_STRING && token.type != ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING) {
            XJAlert.display(window.getJavaContainer(), "Cannot Replace Literal With Token Label", "The current token is not a literal.");
            return;
        }

        window.selectTextRange(token.getStartIndex(), token.getEndIndex());
        String s = (String)JOptionPane.showInputDialog(window.getJavaContainer(), "Replace Literal '"+token.getAttribute()+"' with token label:", "Replace Literal With Token Label",
                JOptionPane.QUESTION_MESSAGE, null, null, "");
        if(s != null && !s.equals(token.getAttribute())) {
            beginRefactor("Replace Literal With Token Label");
            replaceLiteralTokenWithTokenLabel(token, s);
            endRefactor();
        }
    }
View Full Code Here


        final ATESyntaxEngine engine = textEditor.getParserEngine();
        tokens = engine.getTokens();
        int p = p0;
        final int start = findStartingTokenIndex(p0, 0, tokens.size(), 0);
        for (int i = start; i < tokens.size(); i++) {
            ATEToken t = tokens.get(i);
            AttributeSet attribute = engine.getAttributeForToken(t);
            if(t.start >= p0 && t.start <= p1) {
                // Fill any non-contiguous token with default color
                if(t.start > p) {
                    x = action.renderTextPortion(g, x, y, p, t.start, p1, doc, null);
View Full Code Here

    private int findStartingTokenIndex(int p0, int low, int high, int candidate) {
        if(Math.abs(high-low) <= 1)
            return Math.min(candidate, low);

        final int middle = low + (high-low) / 2;
        final ATEToken t = tokens.get(middle);
        if(p0 >= t.startLineIndex && p0 <= t.endLineIndex) {
            return findStartingTokenIndex(p0, low, middle, middle);
        } else {
            if(t.startLineIndex < p0)
                return findStartingTokenIndex(p0, middle, high, candidate);
View Full Code Here

        // Then rename all strings token
        List<ATEToken> tokens = window.getTokens();
        String attr = t.getAttribute();
        for(int index = tokens.size()-1; index>0; index--) {
            ATEToken token = tokens.get(index);
            if(token.type != ATESyntaxLexer.TOKEN_SINGLE_QUOTE_STRING && token.type != ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING)
                continue;

            if(!token.getAttribute().equals(attr))
                continue;

            mutator.replace(token.getStartIndex(), token.getEndIndex(), name);
        }
    }
View Full Code Here

        beginRefactor("Convert Literals To C-style Quote Literals");

        List<ATEToken> tokens = window.getTokens();
        for(int index = tokens.size()-1; index>0; index--) {
            ATEToken token = tokens.get(index);

            String attribute;
            String stripped;
            String replaced = null;

            if(token.type == ATESyntaxLexer.TOKEN_SINGLE_QUOTE_STRING || token.type == ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING) {
                attribute = token.getAttribute();
                stripped = attribute.substring(1, attribute.length()-1);
            } else
                continue;

            if(token.type == ATESyntaxLexer.TOKEN_SINGLE_QUOTE_STRING) {
                // Only one character allowed
                if(stripped.length() == 1)
                    continue;
                else if(stripped.length() == 2 && stripped.charAt(0) == '\\')
                    continue;

                if(stripped.indexOf('"') != -1 || stripped.indexOf('\'') != -1)
                    stripped = escapeStringQuote(stripped, '"', '\'');

                replaced = '"'+stripped+'"';
            } else if(token.type == ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING) {
                // String with one character should be converted to single-quote

                if(stripped.length() > 1 && stripped.charAt(0) != '\\')
                    continue;

                if(stripped.indexOf('\'') != -1 || stripped.indexOf('"') != -1)
                    stripped = escapeStringQuote(stripped, '\'', '"');

                replaced = '\''+stripped+'\'';
            }

            mutator.replace(token.getStartIndex(), token.getEndIndex(), replaced);
        }

        endRefactor();
    }
View Full Code Here

    }

    protected void convertLiteralsToSpecifiedQuote(int tokenType, char quote, char unescapeQuote) {
        List<ATEToken> tokens = window.getTokens();
        for(int index = tokens.size()-1; index>0; index--) {
            ATEToken token = tokens.get(index);
            if(token.type != tokenType)
                continue;

            // FIX AW-56
            if(RefactorEngine.ignoreScopeForDoubleQuoteLiteral(token.scope))
                continue;

            String attribute = token.getAttribute();
            String stripped = attribute.substring(1, attribute.length()-1);
            if(stripped.indexOf(quote) != -1 || stripped.indexOf(unescapeQuote) != -1)
                stripped = escapeStringQuote(stripped, quote, unescapeQuote);

            mutator.replace(token.getStartIndex(), token.getEndIndex(), quote+stripped+quote);
        }
    }
View Full Code Here

    /**
     * Resolves the unresolved references by looking at the set of declared references
     */
    private void resolveReferences() {
        for(int i=unresolvedReferences.size()-1; i >= 0; i--) {
            ATEToken ref = unresolvedReferences.get(i);
            if(declaredReferenceNames.contains(ref.getAttribute())) {
                ref.type = ATEStringTemplateSyntaxLexer.TOKEN_REFERENCE;
                references.add(new ElementTemplateReference(refsToRules.get(ref), ref));
                unresolvedReferences.remove(i);
            }
        }
View Full Code Here

            return false;
        }
    }

    private boolean tryMatchName() {
        ATEToken start = T(0);

        if(!matchID(0, "group")) return false;

        // After the 'group' comes the name of the template
        ATEToken name = T(0);
        if(!nextToken()) return false;

        matchSuperGroup(); // match the optional super group
        matchInterface(); // match the optional interface/s
View Full Code Here

            currentTemplateRule = null;
        }
    }

    private boolean tryMatchTemplate() {
        ATEToken start = T(0);
        if(start == null) return false;

        String name = start.getAttribute();
        if(!matchID(0)) return false;

        currentArgs = new ArrayList<ATEToken>();
        currentArgNames.clear();
        // Match any optional argument
        matchArguments();

        // should be '::=' after arguments
        if(isDEFINED_TO_BE(0)) {
            // When a defineToBe is matched, we are at the beginning of the content of the template rule
            nextToken();
        } else {
            // Invalid template rule matching
            return false;
        }

        final ATEToken definedToBeToken = T(-1);
        currentTemplateRule = new ElementTemplateRule(this, name, start, definedToBeToken, null, currentArgs);

        // loop through all new lines
        while (matchNewline(0));
View Full Code Here

        rewind();
        return false;
    }

    private boolean matchLiteral() {
        ATEToken t = T(0);
        if (t == null) return false;
        t.type = ATEStringTemplateSyntaxLexer.TOKEN_LITERAL;
        nextToken();
        return true;
    }
View Full Code Here

TOP

Related Classes of org.antlr.works.ate.syntax.misc.ATEToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.