Example usage for org.aspectj.weaver BCException BCException

List of usage examples for org.aspectj.weaver BCException BCException

Introduction

In this page you can find the example usage for org.aspectj.weaver BCException BCException.

Prototype

public BCException(String s) 

Source Link

Usage

From source file:org.caesarj.compiler.aspectj.CaesarTokenSource.java

License:Open Source License

public static CaesarTokenSource createTokenSource(String input, ISourceContext sourceContext) {

    char[] chars = input.toCharArray();

    int i = 0;//from   w  ww .  j a va 2 s. c o  m
    List tokens = new ArrayList();

    while (i < chars.length) {
        char ch = chars[i++];
        switch (ch) {
        case ' ':
        case '\t':
        case '\n':
        case '\r':
            continue;
        case '*':
        case '.':
        case '(':
        case ')':
        case '+':
        case '[':
        case ']':
        case ',':
        case '!':
        case ':':
            tokens.add(BasicToken.makeOperator(new Character(ch).toString(), i - 1, i - 1));
            continue;
        case '&':
        case '|':
            if (i == chars.length) {
                throw new BCException("bad " + ch);
            }
            char nextChar = chars[i++];
            if (nextChar == ch) {
                tokens.add(BasicToken.makeOperator(new StringBuffer().append(ch).append(ch).toString(), i - 2,
                        i - 1));
            } else {
                throw new RuntimeException("bad " + ch);
            }
            continue;

        case '\"':
            int start0 = i - 1;
            while (i < chars.length && !(chars[i] == '\"'))
                i++;
            i += 1;
            tokens.add(BasicToken.makeLiteral(new String(chars, start0 + 1, i - start0 - 2), "string", start0,
                    i - 1));
        default:
            int start = i - 1;
            while (i < chars.length && Character.isJavaIdentifierPart(chars[i])) {
                i++;
            }
            tokens.add(BasicToken.makeIdentifier(new String(chars, start, i - start), start, i - 1));

        }
    }

    return new CaesarTokenSource((IToken[]) tokens.toArray(new IToken[tokens.size()]), sourceContext);
}