Skip to content

Commit

Permalink
First Draft - Unrolled Generics
Browse files Browse the repository at this point in the history
This replaces Realized... classes:
1) Realized shouldn't have been in the name since they don't follow the
realization path at all. Instead, these classes create the net of
following specialization links
2) Original was Platform only - but has been converted to generics so it
can be used at C/L levels as well (because tooling will have queries at
all 3 levels - and the queries will use these Unrolled classes to
resolve things)
  • Loading branch information
steve-hickman-epistimis committed Feb 15, 2024
1 parent 88b5f34 commit d42c2f7
Show file tree
Hide file tree
Showing 27 changed files with 1,144 additions and 276 deletions.
11 changes: 6 additions & 5 deletions com.epistimis.uddl/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ Require-Bundle: org.eclipse.xtext,
org.eclipse.acceleo.query;bundle-version="7.0.0",
org.eclipse.core.resources
Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: com.epistimis.uddl,
Export-Package: com.epistimis.uddl,
com.epistimis.uddl.constraints,
com.epistimis.uddl.constraints.standalone,
com.epistimis.uddl.exceptions,
com.epistimis.uddl.extension,
com.epistimis.uddl.formatting2,
com.epistimis.uddl.generator,
com.epistimis.uddl.parser.antlr,
Expand All @@ -34,10 +37,8 @@ Export-Package: com.epistimis.uddl,
com.epistimis.uddl.serializer,
com.epistimis.uddl.services,
com.epistimis.uddl.uddl,
com.epistimis.uddl.extension,
com.epistimis.uddl.uddl.impl,
com.epistimis.uddl.uddl.util,
com.epistimis.uddl.validation,
com.epistimis.uddl.constraints,
com.epistimis.uddl.constraints.standalone
com.epistimis.uddl.unrolled,
com.epistimis.uddl.validation
Import-Package: org.apache.log4j
124 changes: 77 additions & 47 deletions com.epistimis.uddl/src/com/epistimis/uddl/RealizationResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.lang.invoke.MethodHandles;
import java.text.MessageFormat;
import java.util.Map;

import org.apache.log4j.Logger;
import org.eclipse.emf.ecore.EObject;
Expand All @@ -14,10 +15,12 @@
import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.xbase.lib.IteratorExtensions;

import com.epistimis.uddl.scoping.IndexUtilities;
import com.epistimis.uddl.uddl.PlatformAssociation;
import com.epistimis.uddl.uddl.PlatformComposableElement;
import com.epistimis.uddl.uddl.PlatformDataType;
import com.epistimis.uddl.uddl.PlatformEntity;
import com.epistimis.uddl.unrolled.UnrollingFactoryP;
import com.google.common.collect.Iterables;
import com.google.inject.Inject;

Expand Down Expand Up @@ -51,52 +54,79 @@ public static void resolve(Resource resource) {
*/
public static void resolve(ResourceSet rs) {

/**
* Before doing anything else, resolve all ECore cross references - because we
* don't know if some have been lazy linked
*/
// EcoreUtil2.resolveAll(rs);

// Before creating new instances, check to see if we already have an instance.
// TODO: We need a way to determine if the AST has changed so we can invalidate the cache.
// How do we do that? Since the cache is keyed by instance ID, it is sufficient that a change
// will cause a new instance to be created, so the old instance won't be found? The problem
// is that approach leaves the old instances in the cache, just unused - which creates a memory
// leak. We need to know to remove old instances. Alternatively, we just always flush the cache
// at this point - which is what we do here.
RealizedComposableElement.allComposable2Realized.clear();
RealizedComposableElement.allRealized2Composable.clear();

for (Resource res : rs.getResources()) {
/**
* This will only collect all the realization info from a PlatformEntity ->
* LogicalEntity -> ConceptualEntity to determine what is available. The results
* can then be used to create instances, generate code, or ....
*/
final Iterable<PlatformComposableElement> elements = Iterables.<PlatformComposableElement>filter(
IteratorExtensions.<EObject>toIterable(res.getAllContents()), PlatformComposableElement.class);

for (final PlatformComposableElement elem : elements) {
if ((elem instanceof PlatformAssociation)) {
new RealizedAssociation(((PlatformAssociation) elem));
} else {
if ((elem instanceof PlatformDataType)) {
new RealizedDataType(((PlatformDataType) elem));
} else {
if ((elem instanceof PlatformEntity)) {
new RealizedEntity(((PlatformEntity) elem));
} else {
logger.warn(MessageFormat.format("No processing available for type {0}",
elem.getClass().toString()));
}
}
}
}
}
/**
* Now go back and link all the PlatformEntity types
*
*/
RealizedComposableElement.linkTypes();
UnrollingFactoryP fp = new UnrollingFactoryP();
fp.resolve(rs);
// /**
// * Before doing anything else, resolve all ECore cross references - because we
// * don't know if some have been lazy linked
// */
// // EcoreUtil2.resolveAll(rs);
//
// // Before creating new instances, check to see if we already have an instance.
// // TODO: We need a way to determine if the AST has changed so we can invalidate the cache.
// // How do we do that? Since the cache is keyed by instance ID, it is sufficient that a change
// // will cause a new instance to be created, so the old instance won't be found? The problem
// // is that approach leaves the old instances in the cache, just unused - which creates a memory
// // leak. We need to know to remove old instances. Alternatively, we just always flush the cache
// // at this point - which is what we do here.
// UnrolledComposableElement.allComposable2Realized.clear();
// UnrolledComposableElement.allRealized2Composable.clear();
//
// for (Resource res : rs.getResources()) {
// /**
// * This will only collect all the realization info from a PlatformEntity ->
// * LogicalEntity -> ConceptualEntity to determine what is available. The results
// * can then be used to create instances, generate code, or ....
// */
// final Iterable<PlatformComposableElement> elements = Iterables.<PlatformComposableElement>filter(
// IteratorExtensions.<EObject>toIterable(res.getAllContents()), PlatformComposableElement.class);
//
// for (final PlatformComposableElement elem : elements) {
// if ((elem instanceof PlatformAssociation)) {
// new UnrolledAssociation(((PlatformAssociation) elem));
// } else {
// if ((elem instanceof PlatformDataType)) {
// new UnrolledDataType(((PlatformDataType) elem));
// } else {
// if ((elem instanceof PlatformEntity)) {
// new RealizedEntity(((PlatformEntity) elem));
// } else {
// logger.warn(MessageFormat.format("No processing available for type {0}",
// elem.getClass().toString()));
// }
// }
// }
// }
// }
// /**
// * Now go back and link all the PlatformEntity types
// *
// */
// UnrolledComposableElement.linkTypes();
}

// static final String FMT_STRING = "Could not find realization for type [{0}] and role [{1}] when processing [{2}] with description [{3}]";
// /**
// * Use the maps to match types. This uses the PlatformComposableElement instances as keys, not FQNs. This should work but it is based on
// * object identity.
// */
// public void linkTypes() {
// for (Map.Entry<ComposableElement, RealizedComposableElement<ComposableElement>> entry: getC2REntrySet()) {
// ComposableElement ce = entry.getKey();
// RealizedComposableElement<ComposableElement> rce = entry.getValue();
// if (rce instanceof RealizedEntity) {
// RealizedEntity re = (RealizedEntity) rce;
// for (RealizedComposition rc: re.getComposition().values()) {
// ComposableElement type = IndexUtilities.unProxiedEObject(rc.getType(),ce);
// RealizedComposableElement<ComposableElement> realizedType = allComposable2Unrolled.get(type);
// if (realizedType == null) {
// String typename = (type != null ? type.getName() : "null");
// logger.warn(MessageFormat.format(FMT_STRING,typename,rc.getRolename(), re.getName(), re.getDescription()));
// }
// rc.setRealizedType(realizedType);
// }
// }
// }
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGenerator2
import org.eclipse.xtext.generator.IGeneratorContext
import org.eclipse.xtext.naming.IQualifiedNameProvider
import com.epistimis.uddl.RealizedComposableElement
import com.epistimis.uddl.unrolled.UnrolledComposableElementP
import org.apache.log4j.Logger
import java.lang.invoke.MethodHandles
import com.epistimis.uddl.unrolled.UnrolledComposableElement

/**
* NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering.
Expand All @@ -43,9 +44,9 @@ abstract class CommonDataStructureGenerator implements IGenerator2 {
List<PlatformEntity> processedEntities;
List<PlatformDataModel> processedPDMs;

protected Map<PlatformComposableElement, RealizedComposableElement> allComposableElements;
protected Map<PlatformComposableElement, UnrolledComposableElement<PlatformComposableElement>> allComposableElements;

new(Map<PlatformComposableElement, RealizedComposableElement> ace) {
new(Map<PlatformComposableElement, UnrolledComposableElement<PlatformComposableElement>> ace) {
allComposableElements = ace;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import com.epistimis.uddl.uddl.PlatformULong
import com.epistimis.uddl.uddl.PlatformULongLong
import com.epistimis.uddl.uddl.PlatformUShort
import com.epistimis.uddl.uddl.PlatformUnsignedInteger
import com.epistimis.uddl.unrolled.UnrolledComposableElement
import java.util.Map
import org.eclipse.emf.ecore.EObject
import com.epistimis.uddl.RealizedComposableElement

/**
* NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering.
Expand All @@ -36,7 +36,7 @@ import com.epistimis.uddl.RealizedComposableElement
*/
class CppDataStructureGenerator extends CommonDataStructureGenerator {

new(Map<PlatformComposableElement,RealizedComposableElement> ace) {
new(Map<PlatformComposableElement,UnrolledComposableElement<PlatformComposableElement>> ace) {
super(ace);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.epistimis.uddl.generator

import com.epistimis.uddl.ModelFilters
import com.epistimis.uddl.RealizedComposableElement
import com.epistimis.uddl.uddl.LogicalValueTypeUnit
import com.epistimis.uddl.uddl.PlatformArray
import com.epistimis.uddl.uddl.PlatformBoolean
Expand Down Expand Up @@ -29,10 +28,11 @@ import com.epistimis.uddl.uddl.PlatformStruct
import com.epistimis.uddl.uddl.PlatformULong
import com.epistimis.uddl.uddl.PlatformULongLong
import com.epistimis.uddl.uddl.PlatformUShort
import com.epistimis.uddl.unrolled.UnrolledComposableElement
import com.google.inject.Inject
import java.util.List
import java.util.Map
import org.eclipse.emf.ecore.EObject
import com.google.inject.Inject

/**
* NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering.
Expand All @@ -46,7 +46,7 @@ class IDLDataStructureGenerator extends CommonDataStructureGenerator {
@Inject
ModelFilters modelFilters;

new(Map<PlatformComposableElement,RealizedComposableElement> ace) {
new(Map<PlatformComposableElement,UnrolledComposableElement<PlatformComposableElement>> ace) {
super(ace);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import com.epistimis.uddl.uddl.PlatformParticipant
import com.epistimis.uddl.uddl.PlatformString
import com.epistimis.uddl.uddl.PlatformULong
import com.epistimis.uddl.uddl.PlatformUnsignedInteger
import com.epistimis.uddl.unrolled.UnrolledComposableElement
import java.util.Map
import org.eclipse.emf.ecore.EObject
import com.epistimis.uddl.RealizedComposableElement

/**
* NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering.
Expand All @@ -31,7 +31,7 @@ import com.epistimis.uddl.RealizedComposableElement
*/
class ProtobufDataStructureGenerator extends CommonDataStructureGenerator {

new(Map<PlatformComposableElement, RealizedComposableElement> ace) {
new(Map<PlatformComposableElement, UnrolledComposableElement<PlatformComposableElement>> ace) {
super(ace);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import com.epistimis.uddl.uddl.PlatformFloat
import com.epistimis.uddl.uddl.PlatformInteger
import com.epistimis.uddl.uddl.PlatformParticipant
import com.epistimis.uddl.uddl.PlatformString
import com.epistimis.uddl.unrolled.UnrolledComposableElement
import java.util.Map
import org.eclipse.emf.ecore.EObject
import com.epistimis.uddl.RealizedComposableElement

/**
* NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering.
Expand All @@ -29,7 +29,7 @@ import com.epistimis.uddl.RealizedComposableElement
*/
class PythonDataStructureGenerator extends CommonDataStructureGenerator {

new(Map<PlatformComposableElement,RealizedComposableElement> ace) {
new(Map<PlatformComposableElement,UnrolledComposableElement<PlatformComposableElement>> ace) {
super(ace);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import com.epistimis.uddl.uddl.PlatformBoolean
import com.epistimis.uddl.uddl.PlatformBoundedString
import com.epistimis.uddl.uddl.PlatformChar
import com.epistimis.uddl.uddl.PlatformCharArray
import com.epistimis.uddl.uddl.PlatformComposableElement
import com.epistimis.uddl.uddl.PlatformComposition
import com.epistimis.uddl.uddl.PlatformDataModel
import com.epistimis.uddl.uddl.PlatformDataType
import com.epistimis.uddl.uddl.PlatformDouble
import com.epistimis.uddl.uddl.PlatformEntity
import com.epistimis.uddl.uddl.PlatformFixed
import com.epistimis.uddl.uddl.PlatformFloat
import com.epistimis.uddl.uddl.PlatformInteger
import com.epistimis.uddl.uddl.PlatformParticipant
import com.epistimis.uddl.uddl.PlatformShort
import com.epistimis.uddl.uddl.PlatformComposableElement
import com.epistimis.uddl.unrolled.UnrolledComposableElement
import java.util.Map
import com.epistimis.uddl.uddl.PlatformDataModel
import com.epistimis.uddl.uddl.PlatformEntity
import com.epistimis.uddl.uddl.PlatformComposition
import com.epistimis.uddl.uddl.PlatformParticipant
import org.eclipse.emf.ecore.EObject
import com.epistimis.uddl.RealizedComposableElement

/**
* NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering.
Expand All @@ -29,7 +29,7 @@ import com.epistimis.uddl.RealizedComposableElement
*/
class RDBMSDataStructureGenerator extends CommonDataStructureGenerator {

new(Map<PlatformComposableElement, RealizedComposableElement> ace) {
new(Map<PlatformComposableElement, UnrolledComposableElement<PlatformComposableElement>> ace) {
super(ace);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import com.epistimis.uddl.uddl.PlatformBoundedString
import com.epistimis.uddl.uddl.PlatformChar
import com.epistimis.uddl.uddl.PlatformCharArray
import com.epistimis.uddl.uddl.PlatformComposableElement
import com.epistimis.uddl.uddl.PlatformComposition
import com.epistimis.uddl.uddl.PlatformDataModel
import com.epistimis.uddl.uddl.PlatformDataType
import com.epistimis.uddl.uddl.PlatformDouble
import com.epistimis.uddl.uddl.PlatformEntity
import com.epistimis.uddl.uddl.PlatformFloat
import com.epistimis.uddl.uddl.PlatformInteger
import com.epistimis.uddl.uddl.PlatformLong
import com.epistimis.uddl.uddl.PlatformLongLong
import com.epistimis.uddl.uddl.PlatformParticipant
import com.epistimis.uddl.uddl.PlatformShort
import com.epistimis.uddl.uddl.PlatformString
import com.epistimis.uddl.unrolled.UnrolledComposableElement
import java.util.Map
import com.epistimis.uddl.uddl.PlatformDataModel
import com.epistimis.uddl.uddl.PlatformEntity
import com.epistimis.uddl.uddl.PlatformComposition
import com.epistimis.uddl.uddl.PlatformParticipant
import org.eclipse.emf.ecore.EObject
import com.epistimis.uddl.RealizedComposableElement

/**
* NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering.
Expand All @@ -31,7 +31,7 @@ import com.epistimis.uddl.RealizedComposableElement
*/
class ScalaDataStructureGenerator extends CommonDataStructureGenerator {

new(Map<PlatformComposableElement, RealizedComposableElement> ace) {
new(Map<PlatformComposableElement, UnrolledComposableElement<PlatformComposableElement>> ace) {
super(ace);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import com.epistimis.uddl.uddl.PlatformBoundedString
import com.epistimis.uddl.uddl.PlatformChar
import com.epistimis.uddl.uddl.PlatformCharArray
import com.epistimis.uddl.uddl.PlatformComposableElement
import com.epistimis.uddl.uddl.PlatformComposition
import com.epistimis.uddl.uddl.PlatformDataModel
import com.epistimis.uddl.uddl.PlatformDataType
import com.epistimis.uddl.uddl.PlatformEntity
import com.epistimis.uddl.uddl.PlatformNumber
import com.epistimis.uddl.uddl.PlatformParticipant
import com.epistimis.uddl.uddl.PlatformString
import com.epistimis.uddl.unrolled.UnrolledComposableElement
import java.util.Map
import com.epistimis.uddl.uddl.PlatformDataModel
import com.epistimis.uddl.uddl.PlatformEntity
import com.epistimis.uddl.uddl.PlatformComposition
import com.epistimis.uddl.uddl.PlatformParticipant
import org.eclipse.emf.ecore.EObject
import com.epistimis.uddl.RealizedComposableElement

/**
* NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering.
Expand All @@ -26,7 +26,7 @@ import com.epistimis.uddl.RealizedComposableElement
*/
class TypescriptDataStructureGenerator extends CommonDataStructureGenerator {

new(Map<PlatformComposableElement, RealizedComposableElement> ace) {
new(Map<PlatformComposableElement, UnrolledComposableElement<PlatformComposableElement>> ace) {
super(ace);
}

Expand Down
Loading

0 comments on commit d42c2f7

Please sign in to comment.