@Test public void testCreateJCasCoverClass() throws InvalidXMLException, IOException, ResourceInitializationException { File file = JUnitExtension.getFile("JCasGen/typeSystemAllKinds.xml"); TypeSystemDescription tsDesc = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(file)); CAS cas = CasCreationUtils.createCas(tsDesc, null, null); JCasCoverClassFactory jcf = new JCasCoverClassFactory(); byte[] r = jcf.createJCasCoverClass((TypeImpl) cas.getTypeSystem().getType("pkg.sample.name.All")); Path root = Paths.get("."); Path dir = root.resolve("temp/test/JCasGen"); dir.toFile().mkdirs(); Files.write(dir.resolve("testOutputAllKinds.class"), r); System.out.println("debug: generated byte array"); }
byte[] createJCasCoverClass(TypeImpl type) { this.type = type; typeJavaDescriptor = type.getNameAsJavaDescriptor(); typeJavaClassName = type.getName().replace('.', '/'); cn = new ClassNode(ASM5); cn.version = javaClassVersion; cn.access = ACC_PUBLIC + ACC_SUPER; cn.name = typeJavaClassName; cn.superName = type.getSuperType().getName().replace('.', '/'); cn.fields.add(new FieldNode(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "type", "I", null, null)); type.getMergedStaticFeaturesIntroducedByThisType().stream() .forEach(this::addFeatureFieldGetSet); addStaticInitAndConstructors(); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); cn.accept(cw); return cw.toByteArray(); }
JCasCoverClassFactory { byte[] createJCasCoverClass(TypeImpl type) { this.type = type; typeJavaDescriptor = type.getNameAsJavaDescriptor(); typeJavaClassName = type.getName().replace('.', '/'); cn = new ClassNode(ASM5); cn.version = javaClassVersion; cn.access = ACC_PUBLIC + ACC_SUPER; cn.name = typeJavaClassName; cn.superName = type.getSuperType().getName().replace('.', '/'); cn.fields.add(new FieldNode(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "type", "I", null, null)); type.getMergedStaticFeaturesIntroducedByThisType().stream() .forEach(this::addFeatureFieldGetSet); addStaticInitAndConstructors(); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); cn.accept(cw); return cw.toByteArray(); } }
JCasCoverClassFactory { byte[] createJCasCoverClass(TypeImpl type) { this.type = type; typeJavaDescriptor = type.getNameAsJavaDescriptor(); typeJavaClassName = type.getName().replace('.', '/'); cn = new ClassNode(ASM5); cn.version = javaClassVersion; cn.access = ACC_PUBLIC + ACC_SUPER; cn.name = typeJavaClassName; cn.superName = type.getSuperType().getName().replace('.', '/'); cn.fields.add(new FieldNode(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "type", "I", null, null)); type.getMergedStaticFeaturesIntroducedByThisType().stream() .forEach(this::addFeatureFieldGetSet); addStaticInitAndConstructors(); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); cn.accept(cw); return cw.toByteArray(); }  }
JCasCoverClassFactory { byte[] createJCasCoverClass(TypeImpl type) { this.type = type; typeJavaDescriptor = type.getNameAsJavaDescriptor(); typeJavaClassName = type.getName().replace('.', '/'); cn = new ClassNode(ASM5); cn.version = javaClassVersion; cn.access = ACC_PUBLIC + ACC_SUPER; cn.name = typeJavaClassName; cn.superName = type.getSuperType().getName().replace('.', '/'); cn.fields.add(new FieldNode(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "type", "I", null, null)); type.getMergedStaticFeaturesIntroducedByThisType().stream() .forEach(this::addFeatureFieldGetSet); addStaticInitAndConstructors(); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); cn.accept(cw); return cw.toByteArray(); }  void setGeneratedJavaVersion(int i); }
JCasCoverClassFactory { byte[] createJCasCoverClass(TypeImpl type) { this.type = type; typeJavaDescriptor = type.getNameAsJavaDescriptor(); typeJavaClassName = type.getName().replace('.', '/'); cn = new ClassNode(ASM5); cn.version = javaClassVersion; cn.access = ACC_PUBLIC + ACC_SUPER; cn.name = typeJavaClassName; cn.superName = type.getSuperType().getName().replace('.', '/'); cn.fields.add(new FieldNode(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "type", "I", null, null)); type.getMergedStaticFeaturesIntroducedByThisType().stream() .forEach(this::addFeatureFieldGetSet); addStaticInitAndConstructors(); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); cn.accept(cw); return cw.toByteArray(); }  void setGeneratedJavaVersion(int i);  }