use of org.codehaus.groovy.classgen.BytecodeSequence in project groovy by apache.
the class NullCheckASTTransformation method adjustMethod.
private void adjustMethod(MethodNode mn, boolean includeGenerated) {
BlockStatement newCode = getCodeAsBlock(mn);
if (mn.getParameters().length == 0)
return;
boolean generated = isGenerated(mn);
int startingIndex = 0;
if (!includeGenerated && generated)
return;
if (isMarkedAsProcessed(mn))
return;
if (mn instanceof ConstructorNode) {
// some transform has been here already and we assume it knows what it is doing
if (mn.getFirstStatement() instanceof BytecodeSequence)
return;
// ignore any constructors calling this(...) or super(...)
ConstructorCallExpression cce = ConstructorNodeUtils.getFirstIfSpecialConstructorCall(mn.getCode());
if (cce != null) {
if (generated) {
return;
} else {
// skip over this/super() call
startingIndex = 1;
}
}
}
for (Parameter p : mn.getParameters()) {
if (ClassHelper.isPrimitiveType(p.getType()))
continue;
newCode.getStatements().add(startingIndex, ifS(isNullX(varX(p)), makeThrowStmt(p.getName())));
}
mn.setCode(newCode);
}
use of org.codehaus.groovy.classgen.BytecodeSequence in project groovy by apache.
the class StaticTypesLambdaWriter method addDeserializeLambdaMethodForEachLambdaExpression.
private void addDeserializeLambdaMethodForEachLambdaExpression(final LambdaExpression expression, final ClassNode lambdaClass) {
ClassNode enclosingClass = controller.getClassNode();
Statement code = block(new BytecodeSequence(new BytecodeInstruction() {
@Override
public void visit(final MethodVisitor mv) {
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(ICONST_0);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/SerializedLambda", "getCapturedArg", "(I)Ljava/lang/Object;", false);
mv.visitTypeInsn(CHECKCAST, BytecodeHelper.getClassInternalName(lambdaClass));
OperandStack operandStack = controller.getOperandStack();
operandStack.push(lambdaClass);
}
}), returnS(expression));
enclosingClass.addSyntheticMethod(createDeserializeLambdaMethodName(lambdaClass), ACC_PUBLIC | ACC_STATIC, OBJECT_TYPE, createDeserializeLambdaMethodParams(), ClassNode.EMPTY_ARRAY, code);
}
Aggregations