Search in sources :

Example 1 with TKwPredicateOperator

use of de.be4.classicalb.core.parser.node.TKwPredicateOperator in project probparsers by bendisposto.

the class RulesGrammar method createNewToken.

@Override
public Token createNewToken(Token token) {
    Class<? extends Token> clazz = map.get(token.getText());
    try {
        // default constructor
        Token newToken = clazz.newInstance();
        newToken.setLine(token.getLine());
        newToken.setPos(token.getPos());
        return newToken;
    } catch (InstantiationException e) {
        // if the class has not default constructor we call the
        // construct with a text string as the single argument
        // e.g. TKwPredicateOperator(token.getText)
        Class<?>[] cArg = new Class<?>[] { String.class };
        try {
            Token newInstance = clazz.getDeclaredConstructor(cArg).newInstance(token.getText());
            newInstance.setLine(token.getLine());
            newInstance.setPos(token.getPos());
            return newInstance;
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e1) {
            throw new AssertionError(INSTANTIATION_ERROR_MESSAGE + clazz.getName(), e1);
        }
    } catch (IllegalAccessException e) {
        throw new AssertionError(INSTANTIATION_ERROR_MESSAGE + clazz.getName(), e);
    }
}
Also used : Token(de.be4.classicalb.core.parser.node.Token)

Example 2 with TKwPredicateOperator

use of de.be4.classicalb.core.parser.node.TKwPredicateOperator in project probparsers by bendisposto.

the class RulesLanguageExceptionTest method testUnkownPredicateOperatorException.

@Test(expected = AssertionError.class)
public void testUnkownPredicateOperatorException() throws Exception {
    AOperatorPredicate operator = new AOperatorPredicate(new TKwPredicateOperator("foo"), new ArrayList<PExpression>());
    RulesMachineChecker rulesMachineVisitor = new RulesMachineChecker(null, null, null, null);
    operator.apply(rulesMachineVisitor);
}
Also used : AOperatorPredicate(de.be4.classicalb.core.parser.node.AOperatorPredicate) TKwPredicateOperator(de.be4.classicalb.core.parser.node.TKwPredicateOperator) PExpression(de.be4.classicalb.core.parser.node.PExpression) Test(org.junit.Test)

Aggregations

AOperatorPredicate (de.be4.classicalb.core.parser.node.AOperatorPredicate)1 PExpression (de.be4.classicalb.core.parser.node.PExpression)1 TKwPredicateOperator (de.be4.classicalb.core.parser.node.TKwPredicateOperator)1 Token (de.be4.classicalb.core.parser.node.Token)1 Test (org.junit.Test)1