Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AST datastructure with Simple Parser for Text File Lines and JSON import/export #63

Merged
merged 94 commits into from
Mar 24, 2021
Merged
Changes from 1 commit
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
0136287
created library de.variantsync.core
tcerny Dec 9, 2020
ebd6b2e
refractor package name
jeremiaheinle Dec 9, 2020
40b4110
deleted openjdk10 because its not working
wurstbroteater Dec 10, 2020
fd5ea93
minor changes after creating core library project
tcerny Dec 10, 2020
2070412
first draft of a Simple Parser for Text File Lines #52
tcerny Dec 14, 2020
7a95103
implemented #51
jeremiaheinle Dec 14, 2020
2f4ad8a
added UUID as type
wurstbroteater Dec 15, 2020
b9edc59
AST: added add method WIP toString
wurstbroteater Dec 16, 2020
fba3b05
added toString
wurstbroteater Dec 16, 2020
7cc7dce
Fixed and Optimised toString()
wurstbroteater Dec 16, 2020
63b21fc
added forgotten space in toString()
wurstbroteater Dec 16, 2020
421883f
changed gitignore
wurstbroteater Dec 16, 2020
b3d8ebb
edited #51
jeremiaheinle Dec 16, 2020
a003240
removed wrong java version
wurstbroteater Dec 17, 2020
8be0f6e
del apptest, enum
jeremiaheinle Dec 17, 2020
d5417dd
changed add Method of AST and its usage. Updated POM
wurstbroteater Dec 17, 2020
b132ef9
MAVEN: set JAVA version to 11 for usage of Path
wurstbroteater Dec 17, 2020
225174a
changed toString according to pauls ideas #50
wurstbroteater Dec 17, 2020
9259bcc
prettty json and test AST.toString()
jeremiaheinle Dec 17, 2020
829e4db
Merge branch 'issue-50' into issue-51
wurstbroteater Dec 17, 2020
a3a96b7
Merge remote-tracking branch 'origin/issue-51' into issue-51
wurstbroteater Dec 17, 2020
355cec9
merge dropped LineGrammar
wurstbroteater Dec 17, 2020
06dbe23
JsonParserTest fixed
wurstbroteater Dec 17, 2020
dd854f8
exclude fiels in AST from JsonParser
jeremiaheinle Dec 17, 2020
d80b38b
added seriazable
jeremiaheinle Dec 17, 2020
94425ed
Testcase for parseDirectory
tcerny Dec 21, 2020
15c2c40
fixed bug causing that the first dir is displayed twice
wurstbroteater Jan 6, 2021
bf259dc
first try to make attributed LineGrammar Enum
wurstbroteater Jan 6, 2021
5d82215
Styleguide
wurstbroteater Jan 6, 2021
1435db5
refactoring AST.java
wurstbroteater Jan 6, 2021
84b2e15
removed main from AST.java and added toString test
wurstbroteater Jan 6, 2021
34a6d4e
added size method and WIP size testing
wurstbroteater Jan 6, 2021
4071731
removed DEBUG output
wurstbroteater Jan 6, 2021
d136154
updated travis
wurstbroteater Jan 6, 2021
6fd51b2
Update .travis.yml
wurstbroteater Jan 6, 2021
f92002d
Travis decides if this is a fix or not
wurstbroteater Jan 6, 2021
87b22c8
Refactored LineGrammar according to Pauls idea, reduced size test
wurstbroteater Jan 8, 2021
a6249c0
addressing reviewer suggestions of #53
wurstbroteater Jan 16, 2021
0e8b183
added relativePath to child pom
wurstbroteater Jan 25, 2021
fa3a8a8
added maven compiler to fix IntelliJ-only-resolving-bugs
wurstbroteater Jan 25, 2021
8fcc5cd
changes in Simple Parser for Text File Lines
tcerny Jan 26, 2021
870f484
Merge branch 'seproj_ulm_2020' into issue-52
tcerny Jan 27, 2021
4414909
applied code style to newest library
tcerny Jan 27, 2021
f06f071
implemented grammar generalisation
tcerny Jan 27, 2021
b64019b
created ast package
tcerny Jan 27, 2021
28d4135
style guide in tests
tcerny Jan 27, 2021
4bc0314
Merge branch 'seproj_ulm_2020' into issue-52
wurstbroteater Feb 2, 2021
74fed02
Issue-58 resolved
jeremiaheinle Feb 11, 2021
caaadff
processed issue 56 WIP
tcerny Feb 16, 2021
70ca60d
removed commented lines and formatted files prior to pull request
tcerny Mar 2, 2021
58ebef0
finished issue-56 and deleted previously added folder de.variantsync.…
tcerny Mar 2, 2021
84d5696
Merge branch 'issue-56' into issue-52
tcerny Mar 2, 2021
1b44903
added accidentally deleted file de.variantsync.core/.project
tcerny Mar 2, 2021
1cbeff4
adressed reviewers suggestion
tcerny Mar 3, 2021
7a57030
addressed reviewers suggestions
tcerny Mar 10, 2021
21338d5
addressed reviewers suggestion
tcerny Mar 10, 2021
0e40810
changes in LineBasedParser and LineBasedParserTest
tcerny Mar 10, 2021
22f9e9e
review fixes
jeremiaheinle Mar 10, 2021
0a6b2dd
introduced local variables to increase readability
wurstbroteater Mar 10, 2021
989f811
addressing reviewer: move toString to class bottom
wurstbroteater Mar 10, 2021
dd8fbba
removed pointer magic
wurstbroteater Mar 10, 2021
33312e1
WIP: Refactoring toString
wurstbroteater Mar 10, 2021
c571d5e
corrected mistakes made during the work on issue 56
tcerny Mar 11, 2021
fb783d2
added FormatHelper class for refactoring of code duplication
tcerny Mar 11, 2021
c902a59
removed attributes-list in LineGrammar
tcerny Mar 11, 2021
43de43f
regeneralized JsonParser String/B
jeremiaheinle Mar 12, 2021
4812732
WIP refactored separator variables as discussed
wurstbroteater Mar 20, 2021
abc220d
AST added getter, setter, getMaxDepth, docu
wurstbroteater Mar 20, 2021
13cbd01
AST added getter, setter, getMaxDepth, docu
wurstbroteater Mar 20, 2021
09823af
refactored separator vars
wurstbroteater Mar 22, 2021
769ed4f
refactored AST test and toString test
wurstbroteater Mar 22, 2021
6e466ce
added comments and java docs for readability
wurstbroteater Mar 22, 2021
0ec7870
fixed toStringTest out and restructured size test
wurstbroteater Mar 22, 2021
b79c895
naming
wurstbroteater Mar 22, 2021
2e985a6
removed unused/dangerous AST methods
wurstbroteater Mar 22, 2021
1dc99c6
added test for maxDepth of AST
wurstbroteater Mar 22, 2021
f420d69
Deactivated failing test due to new AST format
wurstbroteater Mar 22, 2021
00d542b
Code formatted and clean up
wurstbroteater Mar 22, 2021
3838c0b
Changed name of AST attribut to plural form
wurstbroteater Mar 22, 2021
c6807fe
fixed test for initial size
wurstbroteater Mar 22, 2021
e8cdf23
addressing reviewer suggestion
wurstbroteater Mar 22, 2021
70ebe21
addressing reviewer suggestion
wurstbroteater Mar 22, 2021
d8524f2
changed getSubtrees and code restructure
wurstbroteater Mar 22, 2021
a46fca3
added tests
wurstbroteater Mar 22, 2021
9fabadd
Code format and clean up
wurstbroteater Mar 22, 2021
08ab049
addressing reviewer suggestion
wurstbroteater Mar 22, 2021
063ef68
minor improvments on add methods, added tests, code format and cleanup
wurstbroteater Mar 22, 2021
0669169
renamed Test so that maven will auto exec it
wurstbroteater Mar 23, 2021
94bb0ec
refactored toString, added printTree, fixed tests for AST
wurstbroteater Mar 23, 2021
32bac5e
Code format and cleanup
wurstbroteater Mar 23, 2021
72d897c
impl. reviewer suggestions as far as possible till meeting
wurstbroteater Mar 23, 2021
d297a64
changes after meeting
wurstbroteater Mar 24, 2021
2a6957b
final after meeting changes, code format and cleanup
wurstbroteater Mar 24, 2021
954c6c6
implemented final reviewer suggestions
tcerny Mar 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
AST: added add method WIP toString
wurstbroteater committed Dec 16, 2020
commit b9edc59e5dc9a6cccec39d2063a0389bbf909be0
166 changes: 155 additions & 11 deletions de.variantsync.core/src/main/java/de/variantsync/core/AST.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,163 @@
package de.variantsync.core;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;


public class AST<Grammar, Value> {
UUID id;
public static void main(String[] args) {
AST<EnumLineGrammar.LineGrammar, String> srcDir = new AST<>(EnumLineGrammar.LineGrammar.Directory, "src");
AST<EnumLineGrammar.LineGrammar, String> mainDir = new AST<>(EnumLineGrammar.LineGrammar.Directory, "main");
AST<EnumLineGrammar.LineGrammar, String> testDir = new AST<>(EnumLineGrammar.LineGrammar.Directory, "test");
AST<EnumLineGrammar.LineGrammar, String> mainJava = new AST<>(EnumLineGrammar.LineGrammar.File, "Main.java");
AST<EnumLineGrammar.LineGrammar, String> emptyJava = new AST<>(EnumLineGrammar.LineGrammar.File, "Empty.java");
AST<EnumLineGrammar.LineGrammar, String> emptyTetJava = new AST<>(EnumLineGrammar.LineGrammar.File, "EmptyTest.java");
srcDir.children.add(testDir);
testDir.children.add(emptyTetJava);
srcDir.children.add(mainDir);
mainDir.children.add(mainJava);
mainDir.children.add(emptyJava);


mainJava.children.addAll(Arrays.asList(
new AST<>(EnumLineGrammar.LineGrammar.Line, "public class Main {"),
new AST<>(EnumLineGrammar.LineGrammar.Line, " public static void main(String[] args)"),
new AST<>(EnumLineGrammar.LineGrammar.Line, " System.out.println(\"Hello World\");"),
new AST<>(EnumLineGrammar.LineGrammar.Line, " }"),
new AST<>(EnumLineGrammar.LineGrammar.Line, "}")));
System.out.println(srcDir.size);
System.out.println(srcDir);
}

UUID id;
Grammar type;
Value value;
List<AST<Grammar, Value>> children = new ArrayList<>();

public AST(Grammar type, Value value) {
this.id = UUID.randomUUID();
this.type = type;
this.value = value;
int size;
List<AST<Grammar, Value>> children;


/**
* TODO:
* - sanity check like: A Directory can't have direct child Line or Lines are always leaf nodes
* - add
* - toString
* - equals
* - compareTo ?
* - hash ?
* - toList ?
* - size
* - get
* - contains
* - remove
* <p>
* - testing
*/

@Override
public String toString() {
String out = "";
if(value == null) {
return out;
} else {
int[] level = {1};
out += value + "\n";

HashSet<Integer> levelFinished = new HashSet<>(); // eg. is level 3 finished?
out += toString(level,levelFinished,children);

}

return out;
}

private String toString(int[] level, HashSet<Integer> levelFinished,List<AST<Grammar,Value>> children ) {
String out = "";
if(levelFinished.contains(level[0])) {
level[0]++;
out += " ";
}
if (children.size() == 0) {
return out;
}
int index = children.size() -1;
for(AST<Grammar,Value> child : children) {
if(index == 0) {
//last elem
out += "\u2514\u2500 " + child.value + " l:" + level[0] + "\n";
out +="\u2502";
levelFinished.add(--level[0]);
}
else {
out += "\u251C\u2500 " + child.value + " l:" + level[0] + "\n";
out +="\u2502";
}


out += /*"\u2514\u2500" +*/ toString(level, levelFinished,child.children);
index--;

}
levelFinished.add(level[0]);
level[0]--;
return out;
}

public AST(Grammar type, Value value) {
this.id = UUID.randomUUID();
this.type = type;
this.value = value;
this.children = new ArrayList<>();
size = 1;
}

public void add(Grammar gram, Value val) {
if (value == null) {
id = UUID.randomUUID();
type = gram;
value = val;
children = new ArrayList<>();
size = 1;
} else {
AST<Grammar, Value> toAdd = new AST<>(gram, val);
if (children.size() == 0) {
children.add(toAdd);
} else {
for (AST<Grammar, Value> act : children) {
if (isValidChild(act, toAdd)) {
act.children.add(toAdd);
size++;
break;
}

}
System.err.println("AST-WARNING: Child could not be added!");
}
}
}

private boolean isValidChild(AST<Grammar, Value> parent, AST<Grammar, Value> child) {
if (parent.type instanceof EnumLineGrammar.LineGrammar) {
if (parent.type == EnumLineGrammar.LineGrammar.Directory) {
//Dir can't have line as child
return child.type != EnumLineGrammar.LineGrammar.Line;
} else if (parent.type == EnumLineGrammar.LineGrammar.File) {
//File can't have dir or file as child
return child.type == EnumLineGrammar.LineGrammar.Line;
} else {
//Line is always leaf node
return false;
}
} else {
throw new IllegalArgumentException("Grammar has wrong type: " + parent.type.getClass());
}


}

private AST() {
/**
* Empty AST is forbidden at the moment.
*/

}
}

}
28 changes: 28 additions & 0 deletions de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.variantsync.core;

import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;

import org.junit.Before;
import org.junit.Test;

import de.variantsync.core.EnumLineGrammar.LineGrammar;

public class ASTTest {
AST<LineGrammar,String> ast;

@Before
public void setup() {
ast = new AST<>(LineGrammar.Directory, "src");
}

@Test
public void addTest() {


}

}