@Test public void auto_projection_ref() { DmdlSemantics world = resolve(new String[] { "@auto_projection", "m = {", " a : INT;", " ref = {a};", "};", "projective p = {", " ref : {INT};", "};", }); ModelDeclaration model = world.findModelDeclaration("m"); List<ModelSymbol> projections = projections(model); assertThat(projections, hasSize(1)); assertThat(projections, contains(model("p"))); }
private static boolean contains( Map<String, Type> properties, Map<String, Type> references, ModelDeclaration projection) { assert properties != null; assert projection != null; List<PropertyDeclaration> projectionProperties = projection.getDeclaredProperties(); if (properties.size() < projectionProperties.size()) { return false; } for (PropertyDeclaration projectionProperty : projectionProperties) { Type type = properties.get(projectionProperty.getName().identifier); if (type == null || type.isSame(projectionProperty.getType()) == false) { return false; } } List<PropertyReferenceDeclaration> projectionReferences = projection.getDeclaredPropertyReferences(); if (references.size() < projectionReferences.size()) { return false; } if (projectionReferences.stream().anyMatch(p -> p.getReference().isStub() == false)) { return false; } for (PropertyReferenceDeclaration projectionReference : projectionReferences) { Type type = references.get(projectionReference.getName().identifier); if (type == null || type.isSame(projectionReference.getType()) == false) { return false; } } return true; }
AutoProjectionDriver extends ModelAttributeDriver { private static boolean contains( Map<String, Type> properties, Map<String, Type> references, ModelDeclaration projection) { assert properties != null; assert projection != null; List<PropertyDeclaration> projectionProperties = projection.getDeclaredProperties(); if (properties.size() < projectionProperties.size()) { return false; } for (PropertyDeclaration projectionProperty : projectionProperties) { Type type = properties.get(projectionProperty.getName().identifier); if (type == null || type.isSame(projectionProperty.getType()) == false) { return false; } } List<PropertyReferenceDeclaration> projectionReferences = projection.getDeclaredPropertyReferences(); if (references.size() < projectionReferences.size()) { return false; } if (projectionReferences.stream().anyMatch(p -> p.getReference().isStub() == false)) { return false; } for (PropertyReferenceDeclaration projectionReference : projectionReferences) { Type type = references.get(projectionReference.getName().identifier); if (type == null || type.isSame(projectionReference.getType()) == false) { return false; } } return true; } }
AutoProjectionDriver extends ModelAttributeDriver { private static boolean contains( Map<String, Type> properties, Map<String, Type> references, ModelDeclaration projection) { assert properties != null; assert projection != null; List<PropertyDeclaration> projectionProperties = projection.getDeclaredProperties(); if (properties.size() < projectionProperties.size()) { return false; } for (PropertyDeclaration projectionProperty : projectionProperties) { Type type = properties.get(projectionProperty.getName().identifier); if (type == null || type.isSame(projectionProperty.getType()) == false) { return false; } } List<PropertyReferenceDeclaration> projectionReferences = projection.getDeclaredPropertyReferences(); if (references.size() < projectionReferences.size()) { return false; } if (projectionReferences.stream().anyMatch(p -> p.getReference().isStub() == false)) { return false; } for (PropertyReferenceDeclaration projectionReference : projectionReferences) { Type type = references.get(projectionReference.getName().identifier); if (type == null || type.isSame(projectionReference.getType()) == false) { return false; } } return true; }  }
AutoProjectionDriver extends ModelAttributeDriver { private static boolean contains( Map<String, Type> properties, Map<String, Type> references, ModelDeclaration projection) { assert properties != null; assert projection != null; List<PropertyDeclaration> projectionProperties = projection.getDeclaredProperties(); if (properties.size() < projectionProperties.size()) { return false; } for (PropertyDeclaration projectionProperty : projectionProperties) { Type type = properties.get(projectionProperty.getName().identifier); if (type == null || type.isSame(projectionProperty.getType()) == false) { return false; } } List<PropertyReferenceDeclaration> projectionReferences = projection.getDeclaredPropertyReferences(); if (references.size() < projectionReferences.size()) { return false; } if (projectionReferences.stream().anyMatch(p -> p.getReference().isStub() == false)) { return false; } for (PropertyReferenceDeclaration projectionReference : projectionReferences) { Type type = references.get(projectionReference.getName().identifier); if (type == null || type.isSame(projectionReference.getType()) == false) { return false; } } return true; }  @Override String getTargetName(); @Override void process(
            DmdlSemantics environment,
            ModelDeclaration declaration,
            AstAttribute attribute); }
AutoProjectionDriver extends ModelAttributeDriver { private static boolean contains( Map<String, Type> properties, Map<String, Type> references, ModelDeclaration projection) { assert properties != null; assert projection != null; List<PropertyDeclaration> projectionProperties = projection.getDeclaredProperties(); if (properties.size() < projectionProperties.size()) { return false; } for (PropertyDeclaration projectionProperty : projectionProperties) { Type type = properties.get(projectionProperty.getName().identifier); if (type == null || type.isSame(projectionProperty.getType()) == false) { return false; } } List<PropertyReferenceDeclaration> projectionReferences = projection.getDeclaredPropertyReferences(); if (references.size() < projectionReferences.size()) { return false; } if (projectionReferences.stream().anyMatch(p -> p.getReference().isStub() == false)) { return false; } for (PropertyReferenceDeclaration projectionReference : projectionReferences) { Type type = references.get(projectionReference.getName().identifier); if (type == null || type.isSame(projectionReference.getType()) == false) { return false; } } return true; }  @Override String getTargetName(); @Override void process(
            DmdlSemantics environment,
            ModelDeclaration declaration,
            AstAttribute attribute); static final String TARGET_NAME; }