Skip to content

enterpriseDomain/ClassMaker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c014a59 · Oct 2, 2024
Oct 2, 2024
Apr 11, 2020
Jul 19, 2022
Jan 15, 2023
Aug 29, 2022
Aug 17, 2022
Aug 17, 2022
Jan 15, 2023
Nov 14, 2021
Aug 17, 2022
Jul 19, 2022
Oct 11, 2018
Mar 28, 2017
Mar 12, 2018
Apr 4, 2017
Sep 28, 2016
Dec 3, 2023
Aug 17, 2022
Aug 17, 2022

Repository files navigation

ClassMaker Java CI & CD with Maven Open Source Helpers

ClassMaker is an Eclipse plug-in that allows to create classes programmatically, providing them to client bundle.

ClassMaker, automatically, generates the source code from the provided model, compiles and releases binary, then installs it into its own runtime, and loads classes, making available to client's code, through model reflective API.

Here is how you can use it:

// Design a blueprint model - dynamic EMF EPackage
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("library");
ePackage.setNsPrefix("library");
ePackage.setNsURI("http://library/1.0");
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("Book");
EAttribute eAttr = EcoreFactory.eINSTANCE.createEAttribute();
eAttr.setName("pages");
eAttr.setEType(EcorePackage.Literals.EINT);
eClass.getEStructuralFeatures().add(eAttr);
ePackage.getEClassifiers().add(eClass);

// Acquire ClassMaker's OSGi service
BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass())
                            .getBundleContext();
ServiceReference<?> serviceReference = bundleContext
                            .getServiceReference(ClassMakerService.class);
ClassMakerService classMaker = (ClassMakerService) bundleContext
                            .getService(serviceReference);

// Produce the result by combining them
EPackage jPackage = (EPackage) classMaker.make(ePackage, progressMonitor);

...
// Use the generated model at runtime
EClass jClass = (EClass) jPackage.getEClassifier(eClass.getName());
EObject jObject = jPackage.getEFactoryInstance().create(jClass); 
int pages = 500;
EStructuralFeature jAttr = jClass.getEStructuralFeature(eAttr
    .getName());
jObject.eSet(jAttr, pages);
assertEquals(pages, jObject.eGet(jAttr));
assertEquals(eClass.getName(), jObject.getClass().getSimpleName());  

There is more code, where you can specify a method body and call a method or create a meta-model of any meta-level.

Download

Download latest release.

Feedback

If you have anything to complain or suggest, please feel free to file a bug at GitHub.