- Configuration (complex types) - Type - Simple Type (simpletypetype - string / long / int / enum, enum class) - ComplexType (attributes, some properties) - Attribute (name, type, some properties, some JPA properties)
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:meta ="http://www.arptek.ru/core/meta" targetNamespace ="http://www.arptek.ru/core/meta/test" > < xs:complexType name ="Test" > < xs:annotation > < xs:appinfo > < meta:java.interface > ru.arptek.meta.SomeInterface </ meta:java.interface > </ xs:appinfo > </ xs:annotation > < xs:sequence > < xs:element name ="id" type ="xs:int" meta:jpa . Id ="true" /> < xs:element name ="string" type ="xs:string" /> < xs:element name ="boolean" type ="xs:boolean" /> < xs:element name ="integer" type ="xs:int" /> < xs:element name ="long" type ="xs:long" /> </ xs:sequence > </ xs:complexType > </ xs:schema > * This source code was highlighted with Source Code Highlighter .
return this.a;
0 aload_0 1 getfield classname.a 4 lreturn
ce.declare_field (Constants.ACC_PROTECTED, fieldName, type, null);
codeEmitter.load_this (); codeEmitter.getfield (constantName); codeEmitter.return_value ();
codeEmitter.load_this (); codeEmitter.getfield (constantName);
codeEmitter.return_value ();
codeEmitter.load_arg (0);
codeEmitter.load_this (); codeEmitter.load_arg (0); codeEmitter.putfield (fieldName); codeEmitter.return_value ();
codeEmitter.invoke_virtual (parentClass, new Signature ( getterName, fieldValueType, TYPES_EMPTY));
Local local = e.make_local (TYPE_LINKED_HASH_MAP); e.new_instance (TYPE_LINKED_HASH_MAP); e.dup (); e.push (fieldClasses.size ()); e.push (10); e.push (1f); e.invoke_constructor (TYPE_LINKED_HASH_MAP, SIG_MAP_INIT_INT_FLOAT); e.store_local (local);
* This source code was highlighted with Source Code Highlighter .
- ClassWriter cw = new DebuggingClassWriter (
- ClassWriter.COMPUTE_FRAMES);
- ClassEmitter ce = new ClassEmitter (cw);
- Type [] interfaces = getInterfacesTypes (complexType);
- ce.begin_class (Constants.V1_6, Constants.ACC_PUBLIC, className,
- Type.getType (complexType.getSuperClass ()), interfaces,
- Constants.SOURCE_FILE);
- if (complexType.isJpaEntity ()) {
- ce.visitAnnotation (ANNOTATION_DESCRIPTOR_ENTITY, true )
- .visitEnd ();
- }
- if (StringUtils.isNotEmpty (complexType.getJpaTableName ())) {
- final AnnotationVisitor av = ce.visitAnnotation (
- ANNOTATION_DESCRIPTOR_TABLE, true );
- av.visit ( "name" , complexType.getJpaTableName ());
- av.visitEnd ();
- }
- {
- if (options.generateFieldAccessors) {
- final String fieldsMapFieldName = "$ fields $" ;
- ce.declare_field (Constants.ACC_PRIVATE
- | Constants.ACC_FINAL, fieldsMapFieldName,
- TYPE_MAP, null );
- generateConstructorWithFieldsInit (mainClass, ce,
- fieldClasses, fieldsMapFieldName);
- generateGetFieldsMethod (ce, fieldsMapFieldName);
- generateGetFieldMethod (ce, fieldsMapFieldName);
- } else {
- EmitUtils.null_constructor (ce);
- }
- for (Attribute attribute: complexType.getAttributes ()) {
- processAttribute (ce, attribute);
- }
- }
- ce.end_class ();
- {
- byte [] bs = cw.toByteArray ();
- log.info ( "Generated class '" + className + "' of" + bs.length
- + "bytes" );
- result.put (className, bs);
- }
* This source code was highlighted with Source Code Highlighter .
- if (attribute.getType () instanceof EmptyType)
- return ;
- String fieldName = attribute.getFieldName ();
- String getterName = attribute.getGetterName ();
- String setterName = attribute.getSetterName ();
- final String javaMethodNamePart = WordUtils.capitalize (
- attribute.getAttrName (), new char [] { '_' }). replace ( "_" , "" );
- final Type type = getTypeFromXmlSchemaTypeName (attribute.getType ());
- if (fieldName == null )
- fieldName = "m $" + StringUtils.uncapitalize (javaMethodNamePart);
- if (getterName == null )
- getterName = "get" + javaMethodNamePart;
- if (setterName == null )
- setterName = "set" + javaMethodNamePart;
- final boolean jpaId = attribute.isJpaId ();
- final String strDefaultValue;
- if (! jpaId) {
- strDefaultValue = attribute.getStrDefaultValue ();
- } else {
- strDefaultValue = null ;
- }
- if (strDefaultValue == null ) {
- ce.declare_field (Constants.ACC_PRIVATE, fieldName, type, null );
- {
- // create getter
- CodeEmitter codeEmitter = ce.begin_method (Constants.ACC_PUBLIC,
- new Signature (getterName, type, TYPES_EMPTY),
- TYPES_EMPTY);
- proceedAttributeJpaColumnName (attribute, codeEmitter);
- proceedAttributeJpaLob (attribute, codeEmitter);
- proceedAttributeJpaId (attribute, codeEmitter);
- codeEmitter.load_this ();
- codeEmitter.getfield (fieldName);
- codeEmitter.return_value ();
- codeEmitter.end_method ();
- }
- {
- // create null safe setter
- CodeEmitter codeEmitter = ce.begin_method (Constants.ACC_PUBLIC,
- new Signature (setterName, Type.VOID_TYPE,
- new Type [] {type}), TYPES_EMPTY);
- codeEmitter.load_this ();
- codeEmitter.load_arg (0);
- codeEmitter.putfield (fieldName);
- codeEmitter.return_value ();
- codeEmitter.end_method ();
- }
- } else {
- final Object defaultValue = toValue (type, strDefaultValue);
- final String constantName = "DEFAULT_" + fieldName;
- ce.declare_field (Constants.ACC_PROTECTED | Constants.ACC_FINAL
- | Constants.ACC_STATIC, constantName, type, null );
- {
- CodeEmitter staticHook = ce.getStaticHook ();
- EmitUtils.push_object (staticHook, defaultValue);
- staticHook.putfield (constantName);
- }
- ce.declare_field (Constants.ACC_PROTECTED, fieldName, type, null );
- {
- // create getter
- final Signature signature = new Signature (getterName, type,
- TYPES_EMPTY);
- final CodeEmitter codeEmitter = ce.begin_method (
- Constants.ACC_PUBLIC, signature, TYPES_EMPTY);
- proceedAttributeJpaColumnName (attribute, codeEmitter);
- proceedAttributeJpaLob (attribute, codeEmitter);
- codeEmitter.load_this ();
- codeEmitter.getfield (fieldName);
- Label ifNull = codeEmitter.make_label ();
- codeEmitter.ifnull (ifNull);
- {
- codeEmitter.load_this ();
- codeEmitter.getfield (fieldName);
- codeEmitter.return_value ();
- }
- codeEmitter.mark (ifNull);
- {
- codeEmitter.load_this ();
- codeEmitter.getfield (constantName);
- codeEmitter.return_value ();
- }
- codeEmitter.end_method ();
- }
- {
- // create setter
- final Signature signature = new Signature (setterName,
- Type.VOID_TYPE, new Type [] {type});
- final CodeEmitter codeEmitter = ce.begin_method (
- Constants.ACC_PUBLIC, signature, TYPES_EMPTY);
- codeEmitter.load_this ();
- codeEmitter.load_arg (0);
- codeEmitter.putfield (fieldName);
- codeEmitter.return_value ();
- codeEmitter.end_method ();
- }
- }
* This source code was highlighted with Source Code Highlighter .
- final String holderFieldName = "$ parent $" ;
- ce.declare_field (Constants.ACC_PRIVATE | Constants.ACC_FINAL,
- holderFieldName, parentClass, null );
- {
- CodeEmitter e = ce.begin_method (Constants.ACC_PUBLIC,
- new Signature ( "<init>" , Type.VOID_TYPE,
- new Type [] {parentClass}), null );
- e.load_this ();
- e.super_invoke_constructor ();
- e.load_this ();
- e.load_arg (0);
- e.putfield (holderFieldName);
- e.return_value ();
- e.end_method ();
- }
* This source code was highlighted with Source Code Highlighter .
- {
- // create getter
- CodeEmitter codeEmitter = ce.begin_method (Constants.ACC_PUBLIC,
- new Signature ( "getValue" , fieldValueType, TYPES_EMPTY),
- TYPES_EMPTY);
- codeEmitter.load_this ();
- codeEmitter.getfield (holderFieldName);
- codeEmitter.invoke_virtual (parentClass, new Signature (
- getterName, fieldValueType, TYPES_EMPTY));
- codeEmitter.return_value ();
- codeEmitter.end_method ();
- }
- {
- // create null safe setter
- CodeEmitter codeEmitter = ce.begin_method (Constants.ACC_PUBLIC,
- new Signature ( "setValue" , Type.VOID_TYPE,
- new Type [] {fieldValueType}), TYPES_EMPTY);
- codeEmitter.load_this ();
- codeEmitter.getfield (holderFieldName);
- codeEmitter.load_arg (0);
- codeEmitter.invoke_virtual (parentClass, new Signature (
- setterName, Type.VOID_TYPE,
- new Type [] {fieldValueType}));
- codeEmitter.return_value ();
- codeEmitter.end_method ();
- }
* This source code was highlighted with Source Code Highlighter .
- ClassWriter cw = new DebuggingClassWriter (
- ClassWriter.COMPUTE_FRAMES);
- ClassEmitter ce = new ClassEmitter (cw);
- String fieldClassName = processAttributeField (className,
- mainClass, ce, attribute);
- fieldClasses.put (attribute, ce.getClassType ());
* This source code was highlighted with Source Code Highlighter .
- public void generateConstructorWithFieldsInit (final Type mainClass,
- ClassEmitter ce, Map <Attribute, Type> fieldClasses,
- final String fieldsMapFieldName) {
- CodeEmitter e = ce.begin_method (Constants.ACC_PUBLIC, TypeUtils
- .parseConstructor ( "" ), null );
- e.load_this ();
- e.super_invoke_constructor ();
- Local local = e.make_local (TYPE_LINKED_HASH_MAP);
- e.new_instance (TYPE_LINKED_HASH_MAP);
- e.dup ();
- e.push (fieldClasses.size ());
- e.push (1f);
- e.invoke_constructor (TYPE_LINKED_HASH_MAP, SIG_MAP_INIT_INT_FLOAT);
- e.store_local (local);
- for (Entry <Attribute, Type> fieldTypes: fieldClasses.entrySet ()) {
- e.load_local (local);
- e.push (fieldTypes.getKey (). getAttrName ());
- // = new <...> Field (this);
- e.new_instance (fieldTypes.getValue ());
- e.dup ();
- e.load_this ();
- e.invoke_constructor (fieldTypes.getValue (), new Signature ( "<init>" ,
- Type.VOID_TYPE, new Type [] {mainClass}));
- // $ fields $ .put (fieldName, field);
- e.invoke_virtual (TYPE_LINKED_HASH_MAP, SIG_MAP_PUT);
- }
- e.load_this ();
- e.load_local (local);
- e.invoke_static (TYPE_COLLECTIONS, SIG_COLLECTIONS_UNMODIFIABLEMAP);
- e.putfield (fieldsMapFieldName);
- e.return_value ();
- e.end_method ();
- }
* This source code was highlighted with Source Code Highlighter .
- public void generateGetFieldMethod (ClassEmitter ce,
- final String fieldsMapFieldName) {
- CodeEmitter e = ce.begin_method (Constants.ACC_PUBLIC,
- SIG_FIELDSHOLDER_GETFIELD, null );
- e.visitAnnotation (ANNOTATION_DESCRIPTOR_TRANSIENT, true ) .visitEnd ();
- e.load_this ();
- e.getfield (fieldsMapFieldName);
- e.load_arg (0);
- e.checkcast (TYPE_OBJECT);
- e.invoke_interface (TYPE_MAP, SIG_MAP_GET);
- e.checkcast (TYPE_FIELD);
- e.return_value ();
- e.end_method ();
- }
- public void generateGetFieldsMethod (ClassEmitter ce,
- final String fieldsMapFieldName) {
- CodeEmitter e = ce.begin_method (Constants.ACC_PUBLIC,
- SIG_FIELDSHOLDER_GETFIELDS, null );
- e.visitAnnotation (ANNOTATION_DESCRIPTOR_TRANSIENT, true ) .visitEnd ();
- e.load_this ();
- e.getfield (fieldsMapFieldName);
- e.return_value ();
- e.end_method ();
- }
* This source code was highlighted with Source Code Highlighter .
- protected Map <String, Class <? >> loadClasses (
- final Map <String, byte []> generated) {
- final Thread currentThread = Thread.currentThread ();
- final ClassLoader classLoader = currentThread.getContextClassLoader ();
- final Map <String, Class <? >> classes = new ClassLoader (classLoader) {
- protected Map <String, Class <? >> loadClasses () {
- Map <String, Class <? >> result = new LinkedHashMap <String, Class <? >> (
- generated.size ());
- for (Entry <String, byte []> entry: generated.entrySet ()) {
- final String className = entry.getKey ();
- final byte [] byteCode = entry.getValue ();
- log.info ( "Defining class" + className + "..." );
- final Class <?> cls = defineClass (className, byteCode, 0,
- byteCode.length);
- result.put (cls.getName (), cls);
- }
- return result;
- }
- } .loadClasses ();
- return classes;
- }
Source: https://habr.com/ru/post/91239/
All Articles