Example usage for org.aspectj.weaver.patterns ParserException ParserException

List of usage examples for org.aspectj.weaver.patterns ParserException ParserException

Introduction

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

Prototype

public ParserException(String message, IHasPosition token) 

Source Link

Usage

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

License:Open Source License

public CaesarPointcut parsePointcut() {
    CaesarPointcut ret;/*from ww w  .  ja  v  a 2s . c o m*/
    try {
        ret = new CaesarPointcut(patternParser.parsePointcut());
    } catch (ParserException ex) {
        throw new CaesarParserException(ex);
    }
    if (tokenSource.peek() != IToken.EOF) {
        throw new CaesarParserException(
                new ParserException("symbols found after pointcut", tokenSource.peek()));
    }
    return ret;
}

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

License:Open Source License

private CaesarPointcutWrapper parseKindedPointcut() {
    String kind = parseIdentifier();
    eat("(");/*from   w  w w.j  a va 2s .  co  m*/
    SignaturePattern sig;

    Shadow.Kind shadowKind = null;
    if (kind.equals("execution")) {
        sig = parseMethodOrConstructorSignaturePattern();
        if (sig.getKind() == Member.METHOD) {
            shadowKind = Shadow.MethodExecution;
        } else if (sig.getKind() == Member.CONSTRUCTOR) {
            shadowKind = Shadow.ConstructorExecution;
        }
    } else if (kind.equals("call")) {
        sig = parseMethodOrConstructorSignaturePattern();
        if (sig.getKind() == Member.METHOD) {
            shadowKind = Shadow.MethodCall;
        } else if (sig.getKind() == Member.CONSTRUCTOR) {
            shadowKind = Shadow.ConstructorCall;
        }
    } else if (kind.equals("get")) {
        sig = parseFieldSignaturePattern();
        shadowKind = Shadow.FieldGet;
    } else if (kind.equals("set")) {
        sig = parseFieldSignaturePattern();
        shadowKind = Shadow.FieldSet;
    } else {
        throw new ParserException("bad kind: " + kind, tokenSource.peek());
    }
    eat(")");

    // Creates the wrapper

    if (Shadow.MethodCall.equals(shadowKind) || Shadow.MethodExecution.equals(shadowKind)) {

        // Method call and execution are wrapped in an "and pointcut" to avoid getting constructors
        CaesarKindedPointcut p = new CaesarKindedPointcut(shadowKind, sig);
        registerPointcut(new CaesarPointcutWrapper(p));

        Pointcut andPointcut = new AndPointcut(p,
                new NotPointcut(new CaesarKindedPointcut(shadowKind, this.createConstructorSignature()),
                        tokenSource.peek().getStart()));

        return new CaesarPointcutWrapper(andPointcut);
    } else if (Shadow.ConstructorCall.equals(shadowKind) || Shadow.ConstructorExecution.equals(shadowKind)) {

        Shadow.Kind cclassShadowKind = null;

        // Transform the constructor call/execution to a method call/execution, 
        // using $constructor and the same parameters
        if (Shadow.ConstructorCall.equals(shadowKind)) {
            cclassShadowKind = Shadow.MethodCall;
        } else {
            cclassShadowKind = Shadow.MethodExecution;
        }

        CaesarCloner c = CaesarCloner.instance();

        SignaturePattern cclassSig = new SignaturePattern(Member.METHOD, sig.getModifiers(),
                createCaesarObjectPattern(), c.clone(sig.getDeclaringType()), new NamePattern("$constructor"),
                c.clone(sig.getParameterTypes()), c.clone(sig.getThrowsPattern()));

        CaesarKindedPointcut regular = new CaesarKindedPointcut(shadowKind, sig);

        CaesarKindedPointcut cclass = new CaesarKindedPointcut(cclassShadowKind, cclassSig);

        registerPointcut(new CaesarPointcutWrapper(regular));
        registerPointcut(new CaesarPointcutWrapper(cclass));

        // Creates an orPointcut for both the regular java and cclass constructors
        Pointcut orPointcut = new OrPointcut(regular, cclass);

        return new CaesarPointcutWrapper(orPointcut);
    }

    if (Shadow.FieldGet.equals(shadowKind) || Shadow.FieldSet.equals(shadowKind)) {

        // Creates the wrapper and register it
        CaesarKindedPointcut p = new CaesarKindedPointcut(shadowKind, sig);
        CaesarPointcutWrapper wrapper = new CaesarPointcutWrapper(p);
        registerPointcut(wrapper);

        // Append something like || get(public * Classname_Impl_Mixin_*.field)
        TypePattern mixinType = createMixinType(sig.getDeclaringType());
        SignaturePattern mixinSignature = createMixinSignature(sig, mixinType);

        CaesarKindedPointcut mixin = new CaesarKindedPointcut(shadowKind, mixinSignature);

        // Register the mixin
        wrapper = new CaesarPointcutWrapper(mixin, sig.getDeclaringType());
        wrapper.setDeclaringType(mixinType);
        registerPointcut(wrapper);

        // Creates an orPointcut for both the type and the mixin
        Pointcut orPointcut = new OrPointcut(p, mixin);

        return new CaesarPointcutWrapper(orPointcut);

    }
    CaesarKindedPointcut p = new CaesarKindedPointcut(shadowKind, sig);
    return new CaesarPointcutWrapper(p);
}

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

License:Open Source License

/**
 * /* ww w.j a v a2 s . c om*/
 * @return
 */
private CaesarPointcutWrapper parseIfPointcut() {
    String kind = parseIdentifier();
    eat("(");
    CaesarPointcutWrapper w = null;
    if (maybeEatIdentifier("true")) {
        w = new CaesarPointcutWrapper(IfPointcut.makeIfTruePointcut(Pointcut.SYMBOLIC));
    }
    if (maybeEatIdentifier("false")) {
        w = new CaesarPointcutWrapper(IfPointcut.makeIfFalsePointcut(Pointcut.SYMBOLIC));
    }
    eat(")");
    if (w == null)
        throw new ParserException("If pointcuts currently accept only 'true' or 'false' as values",
                tokenSource.peek());

    return w;
}

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

License:Open Source License

/**
 * When the token "super" is found in a pointcut, parse a super pointcut.
 * //from ww w  .j  av a  2s. c o m
 * @return a wrapper to the super pointcut
 */
private CaesarPointcutWrapper parseSuperPointcut() {
    String kind = parseIdentifier();
    eat(".");
    TypePattern onType = parseTypePattern();
    NamePattern name = tryToExtractName(onType);
    if (name == null) {
        throw new ParserException("Super pointcut must reference a named pointcut", tokenSource.peek());
    }

    TypePatternList arguments = parseArgumentsPattern();

    // Creates the wrapper 
    CaesarSuperPointcut p = new CaesarSuperPointcut(name.maybeGetSimpleName(), arguments);
    CaesarPointcutWrapper wrapper = new CaesarPointcutWrapper(p);
    return wrapper;
}

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

License:Open Source License

private SignaturePattern parseConstructorSignaturePattern() {
    SignaturePattern ret = parseMethodOrConstructorSignaturePattern();
    if (ret.getKind() == Member.CONSTRUCTOR)
        return ret;

    throw new ParserException("constructor pattern required, found method pattern", ret);
}

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

License:Open Source License

private CaesarPointcutWrapper parseReferencePointcut() {
    TypePattern onType = parseTypePattern();
    NamePattern name = tryToExtractName(onType);
    if (name == null) {
        throw new ParserException("name pattern", tokenSource.peek());
    }//www. ja v  a 2  s  .  c  om
    if (onType.toString().equals("")) {
        onType = null;
    }

    TypePatternList arguments = parseArgumentsPattern();

    // Creates the wrapper 
    ReferencePointcut p = new ReferencePointcut(onType, name.maybeGetSimpleName(), arguments);
    CaesarPointcutWrapper wrapper = new CaesarPointcutWrapper(p);
    wrapper.setOnTypeSymbolic(p.onTypeSymbolic);
    return wrapper;
}

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

License:Open Source License

public List<NamePattern> parseDottedNamePattern() {
    List<NamePattern> names = new ArrayList<NamePattern>();
    StringBuffer buf = new StringBuffer();
    IToken previous = null;//ww  w. j  av  a  2  s .c o  m
    boolean justProcessedEllipsis = false; // Remember if we just dealt with an ellipsis (PR61536)
    boolean justProcessedDot = false;
    boolean onADot = false;
    while (true) {
        IToken tok = null;
        int startPos = tokenSource.peek().getStart();
        String afterDot = null;
        while (true) {
            if (previous != null && previous.getString().equals("."))
                justProcessedDot = true;
            tok = tokenSource.peek();
            onADot = (tok.getString().equals("."));
            if (previous != null) {
                if (!isAdjacent(previous, tok))
                    break;
            }
            if (tok.getString() == "*" || tok.isIdentifier()) {
                buf.append(tok.getString());
            } else if (tok.getLiteralKind() != null) {
                //System.err.println("literal kind: " + tok.getString());
                String s = tok.getString();
                int dot = s.indexOf('.');
                if (dot != -1) {
                    buf.append(s.substring(0, dot));
                    afterDot = s.substring(dot + 1);
                    previous = tokenSource.next();
                    break;
                }
                buf.append(s); // ??? so-so
            } else {
                break;
            }
            previous = tokenSource.next();
            //XXX need to handle floats and other fun stuff
        }
        int endPos = tokenSource.peek(-1).getEnd();
        if (buf.length() == 0 && names.isEmpty()) {
            throw new ParserException("expected name pattern", tok);
        }

        if (buf.length() == 0 && justProcessedEllipsis) {
            throw new ParserException("name pattern cannot finish with ..", tok);
        }
        if (buf.length() == 0 && justProcessedDot && !onADot) {
            throw new ParserException("name pattern cannot finish with .", tok);
        }

        if (buf.length() == 0) {
            names.add(NamePattern.ELLIPSIS);
            justProcessedEllipsis = true;
        } else {
            checkLegalName(buf.toString(), previous);
            NamePattern ret = new NamePattern(buf.toString());
            ret.setLocation(sourceContext, startPos, endPos);
            names.add(ret);
            justProcessedEllipsis = false;
        }

        if (afterDot == null) {
            buf.setLength(0);
            if (!maybeEat("."))
                break;
            else
                previous = tokenSource.peek(-1);
        } else {
            buf.setLength(0);
            buf.append(afterDot);
            afterDot = null;
        }
    }
    //System.err.println("parsed: " + names);
    return names;
}

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

License:Open Source License

private void checkLegalName(String s, IToken tok) {
    char ch = s.charAt(0);
    if (!(ch == '*' || Character.isJavaIdentifierStart(ch))) {
        throw new ParserException("illegal identifier start (" + ch + ")", tok);
    }//from w  ww  . j  a v  a2s . c o  m

    for (int i = 1, len = s.length(); i < len; i++) {
        ch = s.charAt(i);
        if (!(ch == '*' || Character.isJavaIdentifierPart(ch))) {
            throw new ParserException("illegal identifier character (" + ch + ")", tok);
        }
    }

}