use of org.codehaus.groovy.ast.expr.ConstantExpression in project groovy-core by groovy.
the class AbstractASTTransformation method getMemberList.
public List<String> getMemberList(AnnotationNode anno, String name) {
List<String> list;
Expression expr = anno.getMember(name);
if (expr != null && expr instanceof ListExpression) {
list = new ArrayList<String>();
final ListExpression listExpression = (ListExpression) expr;
for (Expression itemExpr : listExpression.getExpressions()) {
if (itemExpr != null && itemExpr instanceof ConstantExpression) {
Object value = ((ConstantExpression) itemExpr).getValue();
if (value != null)
list.add(value.toString());
}
}
} else {
list = tokenize(getMemberStringValue(anno, name));
}
return list;
}
use of org.codehaus.groovy.ast.expr.ConstantExpression in project groovy-core by groovy.
the class ImmutableASTTransformation method getKnownImmutables.
private List<String> getKnownImmutables(AnnotationNode node) {
final ArrayList<String> immutables = new ArrayList<String>();
final Expression expression = node.getMember(MEMBER_KNOWN_IMMUTABLES);
if (expression == null)
return immutables;
if (!(expression instanceof ListExpression)) {
addError("Use the Groovy list notation [el1, el2] to specify known immutable property names via \"" + MEMBER_KNOWN_IMMUTABLES + "\"", node);
return immutables;
}
final ListExpression listExpression = (ListExpression) expression;
for (Expression listItemExpression : listExpression.getExpressions()) {
if (listItemExpression instanceof ConstantExpression) {
immutables.add((String) ((ConstantExpression) listItemExpression).getValue());
}
}
return immutables;
}
use of org.codehaus.groovy.ast.expr.ConstantExpression in project groovy-core by groovy.
the class ImmutableASTTransformation method createConstructorStatementGuarded.
private Statement createConstructorStatementGuarded(ClassNode cNode, FieldNode fNode) {
final Expression fieldExpr = varX(fNode);
Expression initExpr = fNode.getInitialValueExpression();
final Statement assignInit;
if (initExpr == null || (initExpr instanceof ConstantExpression && ((ConstantExpression) initExpr).isNullExpression())) {
assignInit = assignS(fieldExpr, ConstantExpression.EMPTY_EXPRESSION);
} else {
assignInit = assignS(fieldExpr, checkUnresolved(fNode, initExpr));
}
Expression unknown = findArg(fNode.getName());
return ifElseS(equalsNullX(unknown), assignInit, assignS(fieldExpr, checkUnresolved(fNode, unknown)));
}
use of org.codehaus.groovy.ast.expr.ConstantExpression in project groovy-core by groovy.
the class ImmutableASTTransformation method createConstructorStatementDate.
private Statement createConstructorStatementDate(FieldNode fNode) {
final Expression fieldExpr = varX(fNode);
Expression initExpr = fNode.getInitialValueExpression();
final Statement assignInit;
if (initExpr == null || (initExpr instanceof ConstantExpression && ((ConstantExpression) initExpr).isNullExpression())) {
assignInit = assignS(fieldExpr, ConstantExpression.EMPTY_EXPRESSION);
} else {
assignInit = assignS(fieldExpr, cloneDateExpr(initExpr));
}
final Expression date = findArg(fNode.getName());
return ifElseS(equalsNullX(date), assignInit, assignS(fieldExpr, cloneDateExpr(date)));
}
use of org.codehaus.groovy.ast.expr.ConstantExpression in project groovy-core by groovy.
the class GrabAnnotationTransformation method addGrabResolverAsStaticInitIfNeeded.
private void addGrabResolverAsStaticInitIfNeeded(ClassNode grapeClassNode, AnnotationNode node, List<Statement> grabResolverInitializers, Map<String, Object> grabResolverMap) {
if ((node.getMember("initClass") == null) || (node.getMember("initClass") == ConstantExpression.TRUE)) {
MapExpression resolverArgs = new MapExpression();
for (Map.Entry<String, Object> next : grabResolverMap.entrySet()) {
resolverArgs.addMapEntryExpression(new ConstantExpression(next.getKey()), new ConstantExpression(next.getValue()));
}
grabResolverInitializers.add(new ExpressionStatement(new StaticMethodCallExpression(grapeClassNode, "addResolver", new ArgumentListExpression(resolverArgs))));
}
}
Aggregations