Search in sources :

Example 1 with ListLiteral

use of abs.frontend.ast.ListLiteral in project abstools by abstools.

the class AnnotationUtil method addToAnnotations.

private static void addToAnnotations(List<Annotation> annotations, Access annotationType, int expansionId) {
    IntLiteral indexLiteral = new IntLiteral(Integer.toString(expansionId));
    Annotation toAdd = getAnnotation(annotations, annotationType);
    if (toAdd == null) {
        toAdd = new TypedAnnotation(new ListLiteral(new List<>()), annotationType);
        annotations.add(toAdd);
    }
    PureExp value = toAdd.getValue();
    if (value instanceof ListLiteral) {
        ListLiteral list = (ListLiteral) value;
        for (PureExp exp : list.getPureExps()) {
            if (exp instanceof IntLiteral) {
                IntLiteral intLiteral = (IntLiteral) exp;
                if (intLiteral.getContent().equals(indexLiteral.getContent())) {
                    return;
                }
            }
        }
        list.addPureExp(indexLiteral);
    } else {
        throw new IllegalArgumentException("Annotation list contains invalid expansion annotation");
    }
}
Also used : ListLiteral(abs.frontend.ast.ListLiteral) IntLiteral(abs.frontend.ast.IntLiteral) TypedAnnotation(abs.frontend.ast.TypedAnnotation) PureExp(abs.frontend.ast.PureExp) Annotation(abs.frontend.ast.Annotation) TypedAnnotation(abs.frontend.ast.TypedAnnotation)

Aggregations

Annotation (abs.frontend.ast.Annotation)1 IntLiteral (abs.frontend.ast.IntLiteral)1 ListLiteral (abs.frontend.ast.ListLiteral)1 PureExp (abs.frontend.ast.PureExp)1 TypedAnnotation (abs.frontend.ast.TypedAnnotation)1