Skip to content
Snippets Groups Projects
Commit f11bded4 authored by Johannes Mey's avatar Johannes Mey
Browse files

only create reference creation and resolution methods for types that can be instantiated

parent 8a5cec44
No related branches found
No related tags found
2 merge requests!200.4.0,!17WIP: Feature/better placeholders
Pipeline #6289 passed
...@@ -160,12 +160,40 @@ aspect ComponentAnalysis { ...@@ -160,12 +160,40 @@ aspect ComponentAnalysis {
return set; return set;
} }
//--- needUnresolvedClass --- /**
syn boolean TypeDecl.needUnresolvedClass() { * @return a set of all types that refer to this type using a non-containment relation
// a TypeDecl needs an unresolved class, if it can appear in a relation */
// TODO coll Set<TypeDecl> TypeDecl.referencingTypes() [new HashSet<TypeDecl>()];
RelationComponent contributes opposite().getTypeUse().decl()
when opposite().isNavigable()
to TypeDecl.referencingTypes()
for getTypeUse().decl();
/**
* @return true, if the type can be the target of a non-containment relation
*/
syn boolean TypeDecl.isReferenceTarget() {
return !referencingTypes().isEmpty();
}
/**
* @return true, if the type or one of its abstract supertypes can be the target of a non-containment relation
*/
syn boolean TypeDecl.requiresUresolvedClass() {
if (referencingTypes().isEmpty()) {
// if the type is not referenced itself, it may still be required by an abstract supertype that is referenced
TypeDecl decl = this;
while (decl.hasSuper()) {
decl = decl.getSuper().decl();
if (decl.getAbstract() && !decl.referencingTypes().isEmpty()) {
return true;
}
}
return false;
} else {
return true; return true;
} }
}
//--- isList --- //--- isList ---
syn boolean Component.isList() = false; syn boolean Component.isList() = false;
...@@ -201,6 +229,8 @@ aspect InstanceSupplier { ...@@ -201,6 +229,8 @@ aspect InstanceSupplier {
return subDecls; return subDecls;
} }
syn boolean TypeDecl.instantiable() = instantiableSubType() != null;
//--- instantiableSubType --- //--- instantiableSubType ---
syn TypeDecl TypeDecl.instantiableSubType() { syn TypeDecl TypeDecl.instantiableSubType() {
if (getAbstract() == false) { if (getAbstract() == false) {
......
...@@ -149,8 +149,10 @@ aspect NameResolutionHelper { ...@@ -149,8 +149,10 @@ aspect NameResolutionHelper {
sb.append("aspect ReferenceCreation {\n\n"); sb.append("aspect ReferenceCreation {\n\n");
for (TypeDecl decl : getTypeDeclList()) { for (TypeDecl decl : getTypeDeclList()) {
if (decl.isReferenceTarget()) {
decl.createReferenceCreator(sb); decl.createReferenceCreator(sb);
} }
}
sb.append("}\n\n"); sb.append("}\n\n");
...@@ -172,7 +174,7 @@ aspect NameResolutionHelper { ...@@ -172,7 +174,7 @@ aspect NameResolutionHelper {
sb.append(ind(1) + "}\n\n"); sb.append(ind(1) + "}\n\n");
for (TypeDecl td: getTypeDecls()) { for (TypeDecl td: getTypeDecls()) {
if (td.needUnresolvedClass()) { if (td.requiresUresolvedClass()) {
td.generateUnresolvedClass(sb); td.generateUnresolvedClass(sb);
} }
} }
...@@ -182,11 +184,10 @@ aspect NameResolutionHelper { ...@@ -182,11 +184,10 @@ aspect NameResolutionHelper {
public void TypeDecl.createReferenceCreator(StringBuilder sb) { public void TypeDecl.createReferenceCreator(StringBuilder sb) {
if (!instantiable()) {
System.out.println("WARNING: unable to find instantiable subtype for " + getID() + "! Skipping the creation of reference creator methods.");
} else {
TypeDecl instantiableSubType = instantiableSubType(); TypeDecl instantiableSubType = instantiableSubType();
if (instantiableSubType == null) {
throw new RuntimeException("unable to find instantiable subtype for " + getID());
}
sb.append(ind(1) + "public static " + getID() + " " + getID() + "." + createRefMethod + "(String ref) {\n"); sb.append(ind(1) + "public static " + getID() + " " + getID() + "." + createRefMethod + "(String ref) {\n");
sb.append(ind(2) + unresolvedPrefix + instantiableSubType.getID() + " unresolvedNode = new " + unresolvedPrefix + instantiableSubType.getID() + "();\n"); sb.append(ind(2) + unresolvedPrefix + instantiableSubType.getID() + " unresolvedNode = new " + unresolvedPrefix + instantiableSubType.getID() + "();\n");
sb.append(ind(2) + "unresolvedNode.set" + unresolvedPrefix + "Token(ref);\n"); sb.append(ind(2) + "unresolvedNode.set" + unresolvedPrefix + "Token(ref);\n");
...@@ -201,6 +202,7 @@ aspect NameResolutionHelper { ...@@ -201,6 +202,7 @@ aspect NameResolutionHelper {
sb.append(ind(2) + "return unresolvedNode;\n"); sb.append(ind(2) + "return unresolvedNode;\n");
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
} }
}
public void TypeDecl.generateContextIndependentNameResolution(StringBuilder sb) { public void TypeDecl.generateContextIndependentNameResolution(StringBuilder sb) {
sb.append(ind(1) + "// context-independent name resolution\n"); sb.append(ind(1) + "// context-independent name resolution\n");
......
...@@ -268,6 +268,9 @@ aspect Serializer { ...@@ -268,6 +268,9 @@ aspect Serializer {
public void TypeDecl.deserialize(StringBuilder sb) { public void TypeDecl.deserialize(StringBuilder sb) {
sb.append(ind(1) + "public static " + getID() + " " + getID() + ".deserialize(java.io.File file) throws DeserializationException {\n"); sb.append(ind(1) + "public static " + getID() + " " + getID() + ".deserialize(java.io.File file) throws DeserializationException {\n");
if (instantiable()) {
sb.append(ind(2) + "try {\n"); sb.append(ind(2) + "try {\n");
sb.append(ind(3) + "com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();\n"); sb.append(ind(3) + "com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();\n");
sb.append(ind(3) + "com.fasterxml.jackson.core.JsonFactory factory = mapper.getFactory();\n"); sb.append(ind(3) + "com.fasterxml.jackson.core.JsonFactory factory = mapper.getFactory();\n");
...@@ -329,6 +332,9 @@ aspect Serializer { ...@@ -329,6 +332,9 @@ aspect Serializer {
} }
sb.append(ind(2) + "return element;\n"); sb.append(ind(2) + "return element;\n");
} else {
sb.append(ind(2) + "throw new DeserializationException(\"Unable to deserialize type \\\"" + getID() + "\\\" because it is not instantiable.\");\n");
}
sb.append(ind(1) + "}\n"); sb.append(ind(1) + "}\n");
} }
......
...@@ -62,3 +62,5 @@ G : C ::= [D] ; ...@@ -62,3 +62,5 @@ G : C ::= [D] ;
// line comment with special symbols like |, *, ->, <-, <->, [A], B ::= C, :, \n, \r, ~, #, /A/ // line comment with special symbols like |, *, ->, <-, <->, [A], B ::= C, :, \n, \r, ~, #, /A/
/* block comment with special symbols like |, *, ->, <-, <->, [A], B ::= C, :, \n, \r, ~, #, /A/ */ /* block comment with special symbols like |, *, ->, <-, <->, [A], B ::= C, :, \n, \r, ~, #, /A/ */
abstract Uninstantiable:A;
...@@ -21,3 +21,5 @@ rel A.Bi6? <-> B.Bi6*; ...@@ -21,3 +21,5 @@ rel A.Bi6? <-> B.Bi6*;
rel A.Bi7* <-> B.Bi7; rel A.Bi7* <-> B.Bi7;
rel A.Bi8* <-> B.Bi8?; rel A.Bi8* <-> B.Bi8?;
rel A.Bi9* <-> B.Bi9*; rel A.Bi9* <-> B.Bi9*;
abstract Uninstantiable:A;
...@@ -21,3 +21,5 @@ rel A.Bi6l? <-> B.Bi6*; ...@@ -21,3 +21,5 @@ rel A.Bi6l? <-> B.Bi6*;
rel A.Bi7l* <-> B.Bi7; rel A.Bi7l* <-> B.Bi7;
rel A.Bi8l* <-> B.Bi8?; rel A.Bi8l* <-> B.Bi8?;
rel A.Bi9l* <-> B.Bi9*; rel A.Bi9l* <-> B.Bi9*;
abstract Uninstantiable:A;
...@@ -21,3 +21,5 @@ rel A.Bi6? <-> B.Bi6*; ...@@ -21,3 +21,5 @@ rel A.Bi6? <-> B.Bi6*;
rel A.Bi9* <-> B.Bi9*; rel A.Bi9* <-> B.Bi9*;
rel Root.D <-> D.Root?; rel Root.D <-> D.Root?;
abstract Uninstantiable:A;
...@@ -21,3 +21,5 @@ rel A.Bi6? <-> B.Bi6*; ...@@ -21,3 +21,5 @@ rel A.Bi6? <-> B.Bi6*;
rel A.Bi9* <-> B.Bi9*; rel A.Bi9* <-> B.Bi9*;
rel Root.D <-> D.Root?; rel Root.D <-> D.Root?;
abstract Uninstantiable:A;
...@@ -32,3 +32,5 @@ rel A.Bi5? <-> B.Bi5?; ...@@ -32,3 +32,5 @@ rel A.Bi5? <-> B.Bi5?;
rel A.Bi6? <-> B.Bi6*; rel A.Bi6? <-> B.Bi6*;
rel A.Bi9* <-> B.Bi9*; rel A.Bi9* <-> B.Bi9*;
abstract Uninstantiable:A;
...@@ -21,3 +21,5 @@ rel A.Bi6? <-> B.Bi6*; ...@@ -21,3 +21,5 @@ rel A.Bi6? <-> B.Bi6*;
rel A.Bi9* <-> B.Bi9*; rel A.Bi9* <-> B.Bi9*;
rel Root.D <-> D.Root?; rel Root.D <-> D.Root?;
abstract Uninstantiable:A;
...@@ -32,3 +32,5 @@ rel A.Bi5? <-> B.Bi5?; ...@@ -32,3 +32,5 @@ rel A.Bi5? <-> B.Bi5?;
rel A.Bi6? <-> B.Bi6*; rel A.Bi6? <-> B.Bi6*;
rel A.Bi9* <-> B.Bi9*; rel A.Bi9* <-> B.Bi9*;
abstract Uninstantiable:A;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment