Search in sources :

Example 1 with ClassHelper.int_TYPE

use of org.codehaus.groovy.ast.ClassHelper.int_TYPE in project groovy by apache.

the class RecordTypeASTTransformation method createRecordHashCode.

private void createRecordHashCode(ClassNode cNode) {
    String desc = BytecodeHelper.getMethodDescriptor(ClassHelper.int_TYPE, new ClassNode[] { cNode });
    Statement body = stmt(bytecodeX(ClassHelper.int_TYPE, mv -> {
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInvokeDynamicInsn("hashCode", desc, createBootstrapMethod(), createBootstrapMethodArguments(cNode));
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }));
    addGeneratedMethod(cNode, "hashCode", PUBLIC_FINAL, ClassHelper.int_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, body);
}
Also used : GeneralUtils.stmt(org.codehaus.groovy.ast.tools.GeneralUtils.stmt) RecordComponentNode(org.codehaus.groovy.ast.RecordComponentNode) GeneralUtils.caseS(org.codehaus.groovy.ast.tools.GeneralUtils.caseS) CompilePhase(org.codehaus.groovy.control.CompilePhase) GeneralUtils.params(org.codehaus.groovy.ast.tools.GeneralUtils.params) AnnotatedNode(org.codehaus.groovy.ast.AnnotatedNode) GeneralUtils.classX(org.codehaus.groovy.ast.tools.GeneralUtils.classX) Type(org.objectweb.asm.Type) ACC_ABSTRACT(org.objectweb.asm.Opcodes.ACC_ABSTRACT) GeneralUtils.throwS(org.codehaus.groovy.ast.tools.GeneralUtils.throwS) ClassHelper.make(org.codehaus.groovy.ast.ClassHelper.make) BytecodeHelper(org.codehaus.groovy.classgen.asm.BytecodeHelper) GeneralUtils.propX(org.codehaus.groovy.ast.tools.GeneralUtils.propX) PropertyHandler(groovy.transform.options.PropertyHandler) GeneralUtils.mapEntryX(org.codehaus.groovy.ast.tools.GeneralUtils.mapEntryX) GeneralUtils.ctorX(org.codehaus.groovy.ast.tools.GeneralUtils.ctorX) PropertyNode(org.codehaus.groovy.ast.PropertyNode) LIST_TYPE(org.codehaus.groovy.ast.ClassHelper.LIST_TYPE) GeneralUtils.args(org.codehaus.groovy.ast.tools.GeneralUtils.args) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) Collectors(java.util.stream.Collectors) GeneralUtils.callX(org.codehaus.groovy.ast.tools.GeneralUtils.callX) GeneralUtils.plusX(org.codehaus.groovy.ast.tools.GeneralUtils.plusX) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) List(java.util.List) ClassHelper.makeWithoutCaching(org.codehaus.groovy.ast.ClassHelper.makeWithoutCaching) GeneralUtils.bytecodeX(org.codehaus.groovy.ast.tools.GeneralUtils.bytecodeX) ACC_PUBLIC(org.objectweb.asm.Opcodes.ACC_PUBLIC) Annotation(java.lang.annotation.Annotation) GeneralUtils.hasDeclaredMethod(org.codehaus.groovy.ast.tools.GeneralUtils.hasDeclaredMethod) ClassHelper.getWrapper(org.codehaus.groovy.ast.ClassHelper.getWrapper) ARETURN(org.objectweb.asm.Opcodes.ARETURN) GroovyClassLoader(groovy.lang.GroovyClassLoader) RecordOptions(groovy.transform.RecordOptions) Incubating(org.apache.groovy.lang.annotation.Incubating) ACC_SYNTHETIC(org.objectweb.asm.Opcodes.ACC_SYNTHETIC) Statement(org.codehaus.groovy.ast.stmt.Statement) GeneralUtils.constX(org.codehaus.groovy.ast.tools.GeneralUtils.constX) GeneralUtils.ternaryX(org.codehaus.groovy.ast.tools.GeneralUtils.ternaryX) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) ClassHelper.int_TYPE(org.codehaus.groovy.ast.ClassHelper.int_TYPE) ACC_FINAL(org.objectweb.asm.Opcodes.ACC_FINAL) ACC_PRIVATE(org.objectweb.asm.Opcodes.ACC_PRIVATE) GeneralUtils.thisPropX(org.codehaus.groovy.ast.tools.GeneralUtils.thisPropX) GeneralUtils.mapX(org.codehaus.groovy.ast.tools.GeneralUtils.mapX) ACC_STATIC(org.objectweb.asm.Opcodes.ACC_STATIC) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) GeneralUtils.switchS(org.codehaus.groovy.ast.tools.GeneralUtils.switchS) GeneralUtils.returnS(org.codehaus.groovy.ast.tools.GeneralUtils.returnS) CompilationUnit(org.codehaus.groovy.control.CompilationUnit) RecordBase(groovy.transform.RecordBase) GeneralUtils.param(org.codehaus.groovy.ast.tools.GeneralUtils.param) ClassNodeUtils.addGeneratedMethod(org.apache.groovy.ast.tools.ClassNodeUtils.addGeneratedMethod) GeneralUtils.getInstanceProperties(org.codehaus.groovy.ast.tools.GeneralUtils.getInstanceProperties) GeneralUtils.varX(org.codehaus.groovy.ast.tools.GeneralUtils.varX) Expression(org.codehaus.groovy.ast.expr.Expression) LinkedList(java.util.LinkedList) Opcodes(org.objectweb.asm.Opcodes) Parameter(org.codehaus.groovy.ast.Parameter) MAP_TYPE(org.codehaus.groovy.ast.ClassHelper.MAP_TYPE) CompilationUnitAware(groovy.transform.CompilationUnitAware) SourceUnit(org.codehaus.groovy.control.SourceUnit) ClassNode(org.codehaus.groovy.ast.ClassNode) ClassHelper(org.codehaus.groovy.ast.ClassHelper) GeneralUtils.listX(org.codehaus.groovy.ast.tools.GeneralUtils.listX) GenericsType(org.codehaus.groovy.ast.GenericsType) MethodNodeUtils(org.apache.groovy.ast.tools.MethodNodeUtils) RecordTypeMode(groovy.transform.RecordTypeMode) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) NamedParam(groovy.transform.NamedParam) GeneralUtils.callThisX(org.codehaus.groovy.ast.tools.GeneralUtils.callThisX) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) SwitchStatement(org.codehaus.groovy.ast.stmt.SwitchStatement) Handle(org.objectweb.asm.Handle) ASTNode(org.codehaus.groovy.ast.ASTNode) FieldNode(org.codehaus.groovy.ast.FieldNode) GenericsUtils(org.codehaus.groovy.ast.tools.GenericsUtils) IRETURN(org.objectweb.asm.Opcodes.IRETURN) MapEntryExpression(org.codehaus.groovy.ast.expr.MapEntryExpression) ALOAD(org.objectweb.asm.Opcodes.ALOAD) Statement(org.codehaus.groovy.ast.stmt.Statement) SwitchStatement(org.codehaus.groovy.ast.stmt.SwitchStatement)

Aggregations

GroovyClassLoader (groovy.lang.GroovyClassLoader)1 CompilationUnitAware (groovy.transform.CompilationUnitAware)1 NamedParam (groovy.transform.NamedParam)1 RecordBase (groovy.transform.RecordBase)1 RecordOptions (groovy.transform.RecordOptions)1 RecordTypeMode (groovy.transform.RecordTypeMode)1 PropertyHandler (groovy.transform.options.PropertyHandler)1 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ClassNodeUtils.addGeneratedMethod (org.apache.groovy.ast.tools.ClassNodeUtils.addGeneratedMethod)1 MethodNodeUtils (org.apache.groovy.ast.tools.MethodNodeUtils)1 Incubating (org.apache.groovy.lang.annotation.Incubating)1 ASTNode (org.codehaus.groovy.ast.ASTNode)1 AnnotatedNode (org.codehaus.groovy.ast.AnnotatedNode)1 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)1 ClassHelper (org.codehaus.groovy.ast.ClassHelper)1