Skip to content

Commit

Permalink
#12 #13 #14 #15 #16 #17 #18 #19 Reviewed and fixed @todos and created…
Browse files Browse the repository at this point in the history
… tickets
  • Loading branch information
studio42gmbh committed Apr 23, 2022
1 parent c6a09e7 commit 648250e
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 50 deletions.
3 changes: 0 additions & 3 deletions src/main/java/de/s42/dl/DLCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public interface DLCore

public Object resolveExportedPath(String path);

// @todo DL will have to solve the basic name handling in types (types have 1 name but can be mapped with different aliases)
public DLType defineType(DLType type, String... aliases) throws DLException;

public boolean hasType(String name);
Expand All @@ -117,7 +116,6 @@ public interface DLCore

public List<DLEnum> getEnums();

// @todo DL will have to solve the basic name handling in annotations (annotations have 1 name but can be mapped with different aliases)
public DLAnnotation defineAnnotation(DLAnnotation annotation, String... aliases) throws DLException;

public DLAnnotation defineAliasForAnnotation(String alias, DLAnnotation annotation) throws DLException;
Expand All @@ -128,7 +126,6 @@ public interface DLCore

public List<DLAnnotation> getAnnotations();

// @todo DL will have to solve the basic name handling in pragmas (pragmas have 1 name but can be mapped with different aliases)
public DLPragma definePragma(DLPragma pragma, String... aliases) throws DLException;

public DLPragma defineAliasForPragma(String alias, DLPragma pragma) throws DLException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void validate(DLInstance instance) throws InvalidInstance
{
assert instance != null;

// @todo DL is this risky to do that lookup lazy?
// @todo https://github.com/studio42gmbh/dl/issues/14 Remove sketchy lookup of other type at instance validation time and move it back to type validation time
if (type == null) {
Optional<DLType> optType = core.getType(typeName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void validate(DLInstance instance) throws InvalidInstance
{
assert instance != null;

// @todo DL is this risky to do that lookup lazy?
// @todo https://github.com/studio42gmbh/dl/issues/14 Remove sketchy lookup of other type at instance validation time and move it back to type validation time
if (type == null) {
Optional<DLType> optType = core.getType(typeName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void validate(DLInstance instance) throws InvalidInstance
{
assert instance != null;

// @todo DL is this risky to do that lookup lazy?
// @todo https://github.com/studio42gmbh/dl/issues/14 Remove sketchy lookup of other type at instance validation time and move it back to type validation time
if (type == null) {
Optional<DLType> optType = core.getType(typeName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import de.s42.dl.exceptions.InvalidAnnotation;
import de.s42.dl.exceptions.InvalidAttribute;

// @todo DL implement mechanism to ensure write only
/**
*
* @author Benjamin Schiller
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/de/s42/dl/instances/DefaultDLInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,15 @@ public Set<String> getAttributeNames()
{
if (getType() != null) {

// @todo DL is there a faster way to combine the attributes of the instance and the type?
// merge type and instance attributes in case of a dynamic type
//if (getType().isAllowDynamicAttributes()) {
Set<String> attributeNames = new HashSet<>(attributes.map().keySet());
// @improvement is there a faster way to combine the attributes of the instance and the type? dynamic of parents is tricky
Set<String> attributeNames = new HashSet<>(attributes.keys());

attributeNames.addAll(getType().getAttributeNames());

return Collections.unmodifiableSet(attributeNames);
//} // return attributes of type if not dynamic
//else {
// return getType().getAttributeNames();
//}
}

return Collections.unmodifiableSet(attributes.map().keySet());
return Collections.unmodifiableSet(attributes.keys());
}

@Override
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/de/s42/dl/io/binary/BinaryDLWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
*
* @author Benjamin Schiller
*/
// @todo https://github.com/studio42gmbh/dl/issues/15 BinaryDLWriter finish first complete version (types, pragmas, requires, annotations, ...)
public class BinaryDLWriter implements DLWriter
{

Expand Down Expand Up @@ -111,6 +112,8 @@ public BinaryDLWriter(OutputStream out, DLCore core) throws IOException

private void writeSignature(OutputStream out) throws IOException
{
assert out != null;

//write file header
ByteBuffer buf = ByteBuffer.wrap(new byte[4]);
buf.putInt(DLHelper.BIN_SIGNATURE);
Expand All @@ -121,18 +124,12 @@ private void writeSignature(OutputStream out) throws IOException
public void write(DLPragma pragma) throws IOException
{
assert pragma != null;

// @todo DL implement to write pragma
//log.debug("write", pragma);
}

@Override
public void write(DLType type) throws IOException
{
assert type != null;

// @todo DL implement to write type
//log.debug("write", type);
}

@Override
Expand All @@ -149,6 +146,8 @@ public void write(Object instance) throws IOException

protected int getOrMapSymbol(String symbol) throws IOException
{
assert symbol != null;

Integer symbolId = symbols.get(symbol);

// symbol is mapped - just return
Expand Down
1 change: 0 additions & 1 deletion src/main/java/de/s42/dl/io/hrf/HrfDLReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public HrfDLReader(Path file, DLCore core) throws IOException, DLException
assert file != null;
assert core != null;

// @todo DL should get replaced later by a streaming approach
module = DLHrfParsing.parse(
core,
file.toString(),
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/de/s42/dl/io/hrf/HrfDLWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
*
* @author Benjamin Schiller
*/
// @todo https://github.com/studio42gmbh/dl/issues/16 HrfDLWriter finish first complete version (types, pragmas, requires, annotations, ...)
public class HrfDLWriter implements DLWriter
{

Expand Down Expand Up @@ -69,9 +70,6 @@ public HrfDLWriter(Path file, DLCore core, boolean prettyPrint) throws IOExcepti
public void write(DLPragma pragma) throws IOException
{
assert pragma != null;

// @todo DL implement to write pragma
//log.debug("write", pragma);
}

@Override
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/de/s42/dl/parser/DLHrfParsing.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class DLHrfParsing extends DLParserBaseListener
private DefaultDLEnum currentEnum;
private final DLCore core;

// @todo DL this is a preliminary prototypal implementation of dlinstance attribute assignments!
// @todo https://github.com/studio42gmbh/dl/issues/18 this is a preliminary prototypal implementation of dlinstance attribute assignments!
private final Deque<AttributeAssignmentContext> attributeAssignableContextQueue = new ArrayDeque<>();
private final Deque<String> attributeAssignableKeyQueue = new ArrayDeque<>();
private final Deque<DLInstance> currentAttributeAssignmentInstances = new ArrayDeque<>();
Expand Down Expand Up @@ -306,6 +306,7 @@ else if (core.hasPragma(aliasDefinitionName)) {
}

@Override
@SuppressWarnings("UseSpecificCatch")
public void enterRequire(DLParser.RequireContext ctx)
{
try {
Expand Down Expand Up @@ -462,7 +463,7 @@ public void exitInstanceDefinition(DLParser.InstanceDefinitionContext ctx)
{
try {
try {
// @todo DL support multi nested instances - currently just 1 stack is allowed
// @todo https://github.com/studio42gmbh/dl/issues/18 DLHrfParsing support multi nested instances in attribute assignment - currently just 1 stack is allowed
if (currentInstance.getType() != null) {

//log.debug("currentInstance validate " + currentInstance.getName());
Expand Down Expand Up @@ -816,6 +817,8 @@ public void exitAttributeAssignment(AttributeAssignmentContext ctx)
}

@Override
// @todo https://github.com/studio42gmbh/dl/issues/17 DLHrfParsing improve, refactor and cleanup enterAttributeAssignment
@SuppressWarnings("null")
public void enterAttributeAssignment(AttributeAssignmentContext ctx)
{
try {
Expand Down Expand Up @@ -922,7 +925,7 @@ else if (assignables != null && assignables.length == 1 && assignable.REF() != n
} else if (assignables != null
&& assignables.length == 1
&& assignable.REF() != null
&& // @todo DL this way of preventing arrays to be matched has to be optimized
&& // @todo https://github.com/studio42gmbh/dl/issues/17 DL this way of preventing arrays to be matched has to be optimized
!(currentInstance.getType().getAttribute(key).orElseThrow().getType() instanceof ArrayDLType)) {

Object ref = resolveReference(assignable.getText(), assignable);
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/de/s42/dl/util/CoreHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public static void validateCoreJavaTypes(DLCore core) throws InvalidType, Invali

for (DLType type : core.getTypes()) {

// @todo DL assuming it is a DefaultType
if (((DefaultDLType) type).getJavaType() != null) {
String className = ((DefaultDLType) type).getJavaType().getName();
Class typeInstanceClass = null;
Expand All @@ -79,7 +78,6 @@ public static void validateCoreJavaTypes(DLCore core) throws InvalidType, Invali
final Class fTypeInstanceClass = typeInstanceClass;
type.getParents().forEach((DLType parent) -> {

// @todo DL assuming it is a DefaultType
if (((DefaultDLType) parent).getJavaType() != null) {
String parentClassName = ((DefaultDLType) type).getJavaType().getName();

Expand Down
37 changes: 24 additions & 13 deletions src/main/java/de/s42/dl/util/DLHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public static String toString(DLType type, boolean prettyPrint)
if (prettyPrint) {
result.append("\t");
}

result
.append(attribute.getType().getCanonicalName())
.append(" ")
Expand Down Expand Up @@ -400,7 +400,8 @@ public static String toString(DLInstance instance, boolean prettyPrint, int inde
result.append(":");
}

// @todo DL deal in a more generic manner with string conversion of values -> Use DLType.write
// @todo https://github.com/studio42gmbh/dl/issues/19 Deal in a more generic manner with string conversion of values
// -> Use DLType.write, Use Stringhelper
if (value instanceof DLInstance) {
value = toString((DLInstance) value, prettyPrint, indent + 1);
} else if (value instanceof Date) {
Expand Down Expand Up @@ -430,6 +431,17 @@ public static String toString(DLInstance instance, boolean prettyPrint, int inde
}

public static boolean isDLB(Path file)
{
return isDLB(getIntFileSignature(file));
}

public static boolean isDLB(int fileSignature)
{
return fileSignature == BIN_SIGNATURE;
}

// see https://en.wikipedia.org/wiki/List_of_file_signatures
public static int getIntFileSignature(Path file)
{
assert file != null;
assert Files.isRegularFile(file);
Expand All @@ -441,17 +453,16 @@ public static boolean isDLB(Path file)
// handle if you like
}

// see https://en.wikipedia.org/wiki/List_of_file_signatures
// file signature
return fileSignature == BIN_SIGNATURE;
return fileSignature;
}

// @todo DL optimize performance of recognition preventing opening the file multiple times
public static DLFileType recognizeFileType(Path file)
{
if (isDLB(file)) {
return DLFileType.BINCOMPRESSED;
} else if (ZipHelper.isArchive(file)) {
int fileSignature = getIntFileSignature(file);

if (isDLB(fileSignature)) {
return DLFileType.BIN;
} else if (ZipHelper.isArchive(fileSignature)) {
return DLFileType.BINCOMPRESSED;
} else {
return DLFileType.HRF;
Expand Down Expand Up @@ -504,12 +515,12 @@ public static void writeTypesToFile(DLCore core, Path file, DLFileType fileType,
throw new IOException("The given file type " + fileType + " is not supported");
}
}

public static <EntityType> EntityType readInstanceFromFile(DLCore core, Path file) throws DLException
{
assert core != null;
assert file != null;
return (EntityType)core.parse(file.toString()).getChildAsJavaObject(0, core);
}

return (EntityType) core.parse(file.toString()).getChildAsJavaObject(0, core);
}
}
2 changes: 1 addition & 1 deletion src/test/java/de/s42/dl/types/DLTypesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void invalidTypeAttributeTypeNotDefined() throws DLException
core.parse("Anonymous", "type T { A id; }");
}

// @todo raise exception when trying to assign into a complex type
// @todo https://github.com/studio42gmbh/dl/issues/12 raise exception when trying to assign into a complex type
@Test(expectedExceptions = InvalidType.class, enabled = false)
public void invalidComplexTypeAssigned() throws DLException
{
Expand Down
12 changes: 7 additions & 5 deletions src/test/java/de/s42/dl/types/ListDLTypeNGTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import de.s42.dl.exceptions.InvalidType;
import de.s42.dl.exceptions.InvalidValue;
import de.s42.dl.exceptions.UndefinedType;
import de.s42.dl.instances.SimpleTypeDLInstance;
import java.util.List;
import org.testng.Assert;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -63,17 +64,18 @@ public void validListGenericsInDL() throws DLException
Assert.assertEquals(data, List.of(1, 2, 3));
}

// @todo allow to assign lists from outside
@Test(enabled = false)
@Test
public void validListGenericsInJava() throws DLException
{
DefaultCore core = new DefaultCore();
core.defineAliasForType("java.util.ImmutableCollections$ListN", core.getType(List.class).orElseThrow());
//core.defineAliasForType("java.util.ArrayList", core.getType(List.class).orElseThrow());
core.defineAliasForType(
"java.util.ImmutableCollections$ListN",
core.getType(List.class).orElseThrow());
core.addExported("listData", List.of(1, 2, 3));
core.parse("Anonymous", "type T { List data; } T t @export { data : $listData; }");
DLInstance instance = core.getExported("t").orElseThrow();
List data = instance.get("data");
// @todo https://github.com/studio42gmbh/dl/issues/13 avoid sketchy SimpleTypeDLInstance wrappings when getting values from instances that were added with addExported
List data = ((SimpleTypeDLInstance<List>) instance.get("data")).getData();
Assert.assertEquals(data, List.of(1, 2, 3));
}

Expand Down

0 comments on commit 648250e

Please sign in to comment.