Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,8 @@ tmp/
.gradletasknamecache

# polygot
*.polyglot.META-INF
*.polyglot.META-INF

# FluentAPI
/commit-based-cipm/fluentapi/cipm.consistency.fluentapi.*/metamodel/

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src-gen"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cipm.consistency.fluentapi.java</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: cipm.consistency.fluentapi.java;singleton:=true
Bundle-Version: 0.2.0.qualifier
Bundle-ClassPath: .
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: cipm.consistency.fluentapi.java.api,
cipm.consistency.fluentapi.java.api.impl,
cipm.consistency.fluentapi.java.api.inits,
cipm.consistency.fluentapi.java.api.inits.impl,
cipm.consistency.fluentapi.java.api.inits.util,
cipm.consistency.fluentapi.java.api.placeholderTypes,
cipm.consistency.fluentapi.java.api.placeholderTypes.impl,
cipm.consistency.fluentapi.java.api.util,
cipm.consistency.fluentapi.java.builder,
cipm.consistency.fluentapi.java.metamodel,
cipm.consistency.fluentapi.java.postprocessor,
cipm.consistency.fluentapi.java.test,
cipm.consistency.fluentapi.java.test.metamodel
Automatic-Module-Name: cipm.consistency.fluentapi.java
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: cipm.consistency.fluentapi,
junit-jupiter-api,
junit-jupiter-engine,
junit-jupiter-params,
org.apache.log4j,
org.eclipse.emf.codegen.ecore,
org.eclipse.core.runtime,
org.eclipse.emf.ecore;visibility:=reexport,
org.eclipse.emf.ecore.xmi;visibility:=reexport,
org.emftext.language.java;visibility:=reexport,
org.apache.commons.lang
Bundle-ActivationPolicy: lazy
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Fluent API for Java

This plug-in contains the implementation of the fluent API generation for Java and considers the (EMF-based) [JaMoPP metamodel for Java](https://github.com/MDSD-Tools/TheExtendedJavaModelParserAndPrinter). The structure of this plug-in reflects the structure of the [base plug-in for fluent API generation](../cipm.consistency.fluentapi/README.md).

The fluent API class within this plug-in is called [FluentJavaAPI](./src-gen/cipm.consistency.fluentapi.java.api/FluentJavaAPI.java). Note that this class is not present in this plug-in by default will be generated from the fluent API model.

Note that the Layout package and the relevant JaMoPP features are excluded in this implementation, in order to keep the generated fluent API code to the metamodel elements that are directly related to Java.

For exemplary usage, refer to the test cases within the [test package of this plug-in](./src/cipm.consistency.fluentapi.java.test). For further details, refer to the [base plug-in for fluent API generation](../cipm.consistency.fluentapi/README.md).
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#

bin.includes = .,\
metamodel/,\
META-INF/,\
plugin.xml,\
plugin.properties
jars.compile.order = .
source.. = src-gen/,\
src/
output.. = bin/
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#

pluginName = java-fluentapi Model
providerName = MCSE, KIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>

<!--
-->

<plugin>

<extension point="org.eclipse.emf.ecore.generated_package">
<!-- @generated java-fluentapi -->
<package
uri="https://CIPM-tools.github.io/metamodels/fluentapi/1.0/java/api"
class="cipm.consistency.fluentapi.java.api.ApiPackage"
genModel="metamodel/java-fluentapi.genmodel"/>
</extension>

<extension point="org.eclipse.emf.ecore.generated_package">
<!-- @generated java-fluentapi -->
<package
uri="https://CIPM-tools.github.io/metamodels/fluentapi/1.0/java/api/inits"
class="cipm.consistency.fluentapi.java.api.inits.InitsPackage"
genModel="metamodel/java-fluentapi.genmodel"/>
</extension>

<extension point="org.eclipse.emf.ecore.generated_package">
<!-- @generated java-fluentapi -->
<package
uri="https://CIPM-tools.github.io/metamodels/fluentapi/1.0/java/api/placeholderTypes"
class="cipm.consistency.fluentapi.java.api.placeholderTypes.PlaceholderTypesPackage"
genModel="metamodel/java-fluentapi.genmodel"/>
</extension>

</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package cipm.consistency.fluentapi.java.builder;

import java.util.ArrayList;

import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenModelFactory;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;

import cipm.consistency.fluentapi.builder.FluentAPIAbstractBuilder;
import cipm.consistency.fluentapi.gen.FluentAPIGenerationContext;
import cipm.consistency.fluentapi.gen.FluentAPIGenerator;
import cipm.consistency.fluentapi.java.metamodel.FluentAPIJavaMetamodelFilter;
import cipm.consistency.fluentapi.java.metamodel.FluentAPIJavaMetamodelPackageProvider;
import cipm.consistency.fluentapi.java.postprocessor.FluentAPIGenerationJavaMetamodelPostProcessor;
import cipm.consistency.fluentapi.metamodel.FluentAPITargetMetamodelFilter;
import cipm.consistency.fluentapi.metamodel.FluentAPITargetMetamodelPackageProvider;
import cipm.consistency.fluentapi.postprocessor.FluentAPIGenerationBigNumberParameterPostProcessor;
import cipm.consistency.fluentapi.postprocessor.FluentAPIGenerationForEachOverloadPostProcessor;
import cipm.consistency.fluentapi.postprocessor.FluentAPIGenerationMultipleValueParameterSameMethodBodyOverloadPostProcessor;

/**
* An implementation of {@link FluentAPIAbstractBuilder} for the JaMoPP
* metamodel.
*
* @author Alp Torac Genc
*/
public class FluentJavaAPIBuilder extends FluentAPIAbstractBuilder {
private static final FluentAPITargetMetamodelPackageProvider provider = new FluentAPIJavaMetamodelPackageProvider();
private static final FluentAPITargetMetamodelFilter filter = new FluentAPIJavaMetamodelFilter();

@Override
protected GenModel generateGenModel(Resource genModelRes, Resource ecoreRes, FluentAPIGenerationContext context) {
var genModel = GenModelFactory.eINSTANCE.createGenModel();
genModelRes.getContents().add(genModel);

genModel.setModelDirectory("/" + getGeneratedFluentAPIModelDirectoryPath().toString());
genModel.setOperationReflection(true);
genModel.setImportOrganizing(true);
genModel.setComplianceLevel(getJDKVersion());
genModel.setModelName(getModelName());
genModel.setModelPluginID(getModelPluginID());
genModel.getForeignModel().add(ecoreRes.getURI().lastSegment());

var targetMetamodelGenModel = provider.getTargetMetamodelGenModels().get(0);
genModel.getUsedGenPackages().addAll(targetMetamodelGenModel.getGenPackages());

var initEPacs = new ArrayList<EPackage>();
var toGen = (EPackage) ecoreRes.getContents().get(0);

initEPacs.add(toGen);
genModel.initialize(initEPacs);

genModel.reconcile();

genModel.setCanGenerate(true);

var apiGenPac = genModel.findGenPackage(toGen);
apiGenPac.setBasePackage(context.getBasePackageName());

return genModel;
}

@Override
protected void generateEcoreModel(Resource ecoreRes, FluentAPIGenerationContext context) {
new FluentAPIGenerator().generateRootAPIPackages(context);
new FluentAPIGenerationJavaMetamodelPostProcessor(context.getAllInitEClss(), provider).apply();
new FluentAPIGenerationBigNumberParameterPostProcessor(context.getAllInitEClss()).apply();

var allEClss = new ArrayList<EClass>();
allEClss.add(context.getFluentAPIECls());
allEClss.add(context.getInitSuperECls());
allEClss.addAll(context.getAllInitEClss());

new FluentAPIGenerationForEachOverloadPostProcessor(context, allEClss).apply();
new FluentAPIGenerationMultipleValueParameterSameMethodBodyOverloadPostProcessor(context, allEClss).apply();

ecoreRes.getContents().add(context.getRootPackage());
}

@Override
protected FluentAPITargetMetamodelPackageProvider getTargetMetamodelPackageProvider() {
return provider;
}

@Override
protected FluentAPITargetMetamodelFilter getTargetMetamodelFilter() {
return filter;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Contains the builder class, which is responsible for building the fluent api
* model (for JaMoPP) that consists of an ecore and a genmodel file.
*/
package cipm.consistency.fluentapi.java.builder;
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cipm.consistency.fluentapi.java.metamodel;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.emftext.commons.layout.LayoutPackage;
import org.emftext.language.java.commons.CommonsPackage;

import cipm.consistency.fluentapi.metamodel.FluentAPITargetMetamodelFilter;

/**
* An implementation of {@link FluentAPITargetMetamodelFilter} for
* JaMoPP.
* <p>
* <p>
* Excludes the features ( {@link EStructuralFeature} ) that are present in
* {@link Commentable} and its super-types. Also excludes EClasses found under
* {@link LayoutPackage}. All other EClasses and features under
* {@link JavaPackage} are included.
*
* @author Alp Torac Genc
*/
public class FluentAPIJavaMetamodelFilter extends FluentAPITargetMetamodelFilter {
/**
* {@inheritDoc}
* <p>
* <p>
* Excludes the features ( {@link EStructuralFeature} ) that are present in
* {@link Commentable} and its super-types. All other features under
* {@link JavaPackage} are included.
*/
@Override
public boolean isFeatureEligible(EClass holderOfFeat, EStructuralFeature feat) {
return isFeatureChangeable(feat)
&& !feat.getEContainingClass().getName().equals(CommonsPackage.Literals.COMMENTABLE.getName());
// !CommonsPackage.Literals.COMMENTABLE.isSuperTypeOf(feat.getEContainingClass())
// !feat.getEContainingClass().getInstanceClass().isAssignableFrom(Commentable.class)
}

/**
* {@inheritDoc}
* <p>
* <p>
* Excludes EClasses found under the {@link LayoutPackage}. All other EClasses
* under {@link JavaPackage} are included.
*/
@Override
public boolean isEClassEligible(EClass eCls) {
return eCls.getEPackage() == null || !eCls.getEPackage().getName().equals(LayoutPackage.eNAME);
}
}
Loading