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
Pipeline #6289 passed with stage
in 1 minute and 49 seconds
......@@ -160,12 +160,40 @@ aspect ComponentAnalysis {
return set;
}
//--- needUnresolvedClass ---
syn boolean TypeDecl.needUnresolvedClass() {
// a TypeDecl needs an unresolved class, if it can appear in a relation
// TODO
/**
* @return a set of all types that refer to this type using a non-containment relation
*/
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;
}
}
//--- isList ---
syn boolean Component.isList() = false;
......@@ -201,6 +229,8 @@ aspect InstanceSupplier {
return subDecls;
}
syn boolean TypeDecl.instantiable() = instantiableSubType() != null;
//--- instantiableSubType ---
syn TypeDecl TypeDecl.instantiableSubType() {
if (getAbstract() == false) {
......
......@@ -149,8 +149,10 @@ aspect NameResolutionHelper {
sb.append("aspect ReferenceCreation {\n\n");
for (TypeDecl decl : getTypeDeclList()) {
if (decl.isReferenceTarget()) {
decl.createReferenceCreator(sb);
}
}
sb.append("}\n\n");
......@@ -172,7 +174,7 @@ aspect NameResolutionHelper {
sb.append(ind(1) + "}\n\n");
for (TypeDecl td: getTypeDecls()) {
if (td.needUnresolvedClass()) {
if (td.requiresUresolvedClass()) {
td.generateUnresolvedClass(sb);
}
}
......@@ -182,11 +184,10 @@ aspect NameResolutionHelper {
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();
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(2) + unresolvedPrefix + instantiableSubType.getID() + " unresolvedNode = new " + unresolvedPrefix + instantiableSubType.getID() + "();\n");
sb.append(ind(2) + "unresolvedNode.set" + unresolvedPrefix + "Token(ref);\n");
......@@ -201,6 +202,7 @@ aspect NameResolutionHelper {
sb.append(ind(2) + "return unresolvedNode;\n");
sb.append(ind(1) + "}\n");
}
}
public void TypeDecl.generateContextIndependentNameResolution(StringBuilder sb) {
sb.append(ind(1) + "// context-independent name resolution\n");
......
......@@ -268,6 +268,9 @@ aspect Serializer {
public void TypeDecl.deserialize(StringBuilder sb) {
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(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");
......@@ -329,6 +332,9 @@ aspect Serializer {
}
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");
}
......
......@@ -62,3 +62,5 @@ G : C ::= [D] ;
// line 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*;
rel A.Bi7* <-> B.Bi7;
rel A.Bi8* <-> B.Bi8?;
rel A.Bi9* <-> B.Bi9*;
abstract Uninstantiable:A;
......@@ -21,3 +21,5 @@ rel A.Bi6l? <-> B.Bi6*;
rel A.Bi7l* <-> B.Bi7;
rel A.Bi8l* <-> B.Bi8?;
rel A.Bi9l* <-> B.Bi9*;
abstract Uninstantiable:A;
......@@ -21,3 +21,5 @@ rel A.Bi6? <-> B.Bi6*;
rel A.Bi9* <-> B.Bi9*;
rel Root.D <-> D.Root?;
abstract Uninstantiable:A;
......@@ -21,3 +21,5 @@ rel A.Bi6? <-> B.Bi6*;
rel A.Bi9* <-> B.Bi9*;
rel Root.D <-> D.Root?;
abstract Uninstantiable:A;
......@@ -32,3 +32,5 @@ rel A.Bi5? <-> B.Bi5?;
rel A.Bi6? <-> B.Bi6*;
rel A.Bi9* <-> B.Bi9*;
abstract Uninstantiable:A;
......@@ -21,3 +21,5 @@ rel A.Bi6? <-> B.Bi6*;
rel A.Bi9* <-> B.Bi9*;
rel Root.D <-> D.Root?;
abstract Uninstantiable:A;
......@@ -32,3 +32,5 @@ rel A.Bi5? <-> B.Bi5?;
rel A.Bi6? <-> B.Bi6*;
rel A.Bi9* <-> B.Bi9*;
abstract Uninstantiable:A;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment