use of org.codehaus.groovy.ast.expr.NotExpression in project gradle by gradle.
the class ExpressionReplacingVisitorSupport method visitNotExpression.
@Override
public void visitNotExpression(NotExpression expr) {
NotExpression result = new NotExpression(replaceExpr(expr.getExpression()));
result.setType(expr.getType());
result.setSourcePosition(expr);
replaceVisitedExpressionWith(result);
}
use of org.codehaus.groovy.ast.expr.NotExpression in project hale by halestudio.
the class VertexEntityTransformation method buildVertexGraphConstructor.
/**
* Create a constructor taking a Vertex and a Graph as an argument,
* assigning them to the vertex and graph fields.
*
* @param vertexField the vertex field
* @param graphField the graph field
* @param superClass the vertex entity super class or <code>null</code>
* @param typeProperty the expression specifying the name of the type
* property
* @param entityName the expression specifying the entity name
* @return a constructor taking a Vertex as an argument
*/
private ConstructorNode buildVertexGraphConstructor(FieldNode vertexField, FieldNode graphField, ClassNode superClass, Expression typeProperty, Expression entityName) {
BlockStatement block = new BlockStatement();
// parameter vertex
VariableExpression vertex = new VariableExpression("vertex");
// parameter graph
VariableExpression graph = new VariableExpression("graph");
if (superClass != null) {
// super(vertex, graph)
block.addStatement(new ExpressionStatement(new ConstructorCallExpression(ClassNode.SUPER, new ArgumentListExpression(vertex, graph))));
} else {
// > this.v = vertex
block.addStatement(AbstractASTTransformUtil.assignStatement(new FieldExpression(vertexField), new VariableExpression("vertex")));
// > this.g = graph
block.addStatement(AbstractASTTransformUtil.assignStatement(new FieldExpression(graphField), new VariableExpression("graph")));
}
// vertex.setProperty(typeProperty, entityName)
Statement notOrientStatement = new ExpressionStatement(new MethodCallExpression(vertex, "setProperty", new ArgumentListExpression(new Expression[] { typeProperty, entityName })));
// > if (!(graph instanceof OrientGraph))
// > this.v.setProperty(typeProperty, entityName)
block.addStatement(new IfStatement(new NotExpression(AbstractASTTransformUtil.isInstanceOf(graph, ORIENT_GRAPH_CLASS)), notOrientStatement, new EmptyStatement()));
return new ConstructorNode(Modifier.PUBLIC, new Parameter[] { new Parameter(VERTEX_CLASS, "vertex"), new Parameter(GRAPH_CLASS, "graph") }, new ClassNode[0], block);
}
use of org.codehaus.groovy.ast.expr.NotExpression in project groovy by apache.
the class UnaryExpressionHelper method writeNotExpression.
public void writeNotExpression(NotExpression expression) {
Expression subExpression = expression.getExpression();
int mark = controller.getOperandStack().getStackLength();
subExpression.visit(controller.getAcg());
controller.getOperandStack().castToBool(mark, true);
BytecodeHelper.negateBoolean(controller.getMethodVisitor());
controller.getAssertionWriter().record(expression);
}
use of org.codehaus.groovy.ast.expr.NotExpression in project groovy by apache.
the class StaticTypeCheckingVisitor method findInstanceOfNotReturnExpression.
/**
* Check IfStatement matched pattern :
* Object var1;
* if (!(var1 instanceOf Runnable)) {
* return
* }
* // Here var1 instance of Runnable
* <p>
* Return expression , which contains instanceOf (without not)
* Return null, if not found
*/
protected BinaryExpression findInstanceOfNotReturnExpression(final IfStatement ifElse) {
Statement elseBlock = ifElse.getElseBlock();
if (!(elseBlock instanceof EmptyStatement)) {
return null;
}
Expression conditionExpression = ifElse.getBooleanExpression().getExpression();
if (!(conditionExpression instanceof NotExpression)) {
return null;
}
NotExpression notExpression = (NotExpression) conditionExpression;
Expression expression = notExpression.getExpression();
if (!(expression instanceof BinaryExpression)) {
return null;
}
BinaryExpression instanceOfExpression = (BinaryExpression) expression;
int op = instanceOfExpression.getOperation().getType();
if (op != KEYWORD_INSTANCEOF) {
return null;
}
if (notReturningBlock(ifElse.getIfBlock())) {
return null;
}
return instanceOfExpression;
}
use of org.codehaus.groovy.ast.expr.NotExpression in project groovy by apache.
the class StaticTypesUnaryExpressionHelper method writeNotExpression.
@Override
public void writeNotExpression(final NotExpression expression) {
Expression subExpression = expression.getExpression();
TypeChooser typeChooser = controller.getTypeChooser();
if (isPrimitiveBoolean(typeChooser.resolveType(subExpression, controller.getClassNode()))) {
subExpression.visit(controller.getAcg());
controller.getOperandStack().doGroovyCast(boolean_TYPE);
bytecodeX(mv -> {
Label ne = new Label();
mv.visitJumpInsn(IFNE, ne);
mv.visitInsn(ICONST_1);
Label out = new Label();
mv.visitJumpInsn(GOTO, out);
mv.visitLabel(ne);
mv.visitInsn(ICONST_0);
mv.visitLabel(out);
}).visit(controller.getAcg());
controller.getOperandStack().remove(1);
} else {
super.writeNotExpression(expression);
}
}
Aggregations