From 01362874c12f0d346f72c955db2af21ba3c195cc Mon Sep 17 00:00:00 2001 From: Tobias Cerny Date: Wed, 9 Dec 2020 18:59:35 +0100 Subject: [PATCH 01/89] created library de.variantsync.core --- de.variantsync.core/.classpath | 27 +++++++ de.variantsync.core/.project | 23 ++++++ de.variantsync.core/pom.xml | 78 +++++++++++++++++++ .../java/org/de/variantsync/core/App.java | 13 ++++ .../java/org/de/variantsync/core/AppTest.java | 20 +++++ pom.xml | 19 ++--- 6 files changed, 171 insertions(+), 9 deletions(-) create mode 100644 de.variantsync.core/.classpath create mode 100644 de.variantsync.core/.project create mode 100644 de.variantsync.core/pom.xml create mode 100644 de.variantsync.core/src/main/java/org/de/variantsync/core/App.java create mode 100644 de.variantsync.core/src/test/java/org/de/variantsync/core/AppTest.java diff --git a/de.variantsync.core/.classpath b/de.variantsync.core/.classpath new file mode 100644 index 0000000..1247f9f --- /dev/null +++ b/de.variantsync.core/.classpath @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/de.variantsync.core/.project b/de.variantsync.core/.project new file mode 100644 index 0000000..38a1870 --- /dev/null +++ b/de.variantsync.core/.project @@ -0,0 +1,23 @@ + + + de.variantsync.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/de.variantsync.core/pom.xml b/de.variantsync.core/pom.xml new file mode 100644 index 0000000..0f721e3 --- /dev/null +++ b/de.variantsync.core/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + + de.tubs.variantsync + de.tubs.variantsync + 0.0.3-SNAPSHOT + + + de.tubs.variantsync + de.variantsync.core + 0.0.3-SNAPSHOT + + de.variantsync.core + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/de.variantsync.core/src/main/java/org/de/variantsync/core/App.java b/de.variantsync.core/src/main/java/org/de/variantsync/core/App.java new file mode 100644 index 0000000..9f947e0 --- /dev/null +++ b/de.variantsync.core/src/main/java/org/de/variantsync/core/App.java @@ -0,0 +1,13 @@ +package org.de.variantsync.core; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/de.variantsync.core/src/test/java/org/de/variantsync/core/AppTest.java b/de.variantsync.core/src/test/java/org/de/variantsync/core/AppTest.java new file mode 100644 index 0000000..d58eee2 --- /dev/null +++ b/de.variantsync.core/src/test/java/org/de/variantsync/core/AppTest.java @@ -0,0 +1,20 @@ +package org.de.variantsync.core; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/pom.xml b/pom.xml index 0893581..ba71ef9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,5 @@ - + + 4.0.0 de.tubs.variantsync de.tubs.variantsync @@ -11,7 +11,7 @@ 2.1.0 UTF-8 https://download.eclipse.org/releases/2020-09/ - + @@ -21,8 +21,9 @@ de.tubs.variantsync.update - de.tubs.variantsync.core-test - + de.tubs.variantsync.core-test + de.variantsync.core + @@ -170,7 +171,7 @@ - + @@ -189,7 +190,7 @@ - + @@ -211,7 +212,7 @@ - + @@ -221,4 +222,4 @@ - + \ No newline at end of file From ebd6b2e728c2a69449a9ef826ff1f318b12bbaf8 Mon Sep 17 00:00:00 2001 From: jeremiaheinle Date: Wed, 9 Dec 2020 19:06:51 +0100 Subject: [PATCH 02/89] refractor package name --- .../src/main/java/{org => }/de/variantsync/core/App.java | 2 +- .../src/test/java/{org => }/de/variantsync/core/AppTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename de.variantsync.core/src/main/java/{org => }/de/variantsync/core/App.java (82%) rename de.variantsync.core/src/test/java/{org => }/de/variantsync/core/AppTest.java (88%) diff --git a/de.variantsync.core/src/main/java/org/de/variantsync/core/App.java b/de.variantsync.core/src/main/java/de/variantsync/core/App.java similarity index 82% rename from de.variantsync.core/src/main/java/org/de/variantsync/core/App.java rename to de.variantsync.core/src/main/java/de/variantsync/core/App.java index 9f947e0..3925de5 100644 --- a/de.variantsync.core/src/main/java/org/de/variantsync/core/App.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/App.java @@ -1,4 +1,4 @@ -package org.de.variantsync.core; +package de.variantsync.core; /** * Hello world! diff --git a/de.variantsync.core/src/test/java/org/de/variantsync/core/AppTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java similarity index 88% rename from de.variantsync.core/src/test/java/org/de/variantsync/core/AppTest.java rename to de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java index d58eee2..66caa69 100644 --- a/de.variantsync.core/src/test/java/org/de/variantsync/core/AppTest.java +++ b/de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java @@ -1,4 +1,4 @@ -package org.de.variantsync.core; +package de.variantsync.core; import static org.junit.Assert.assertTrue; From 40b41109f6e594d4648aea3af3ea078e8273db95 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 10 Dec 2020 10:15:42 +0100 Subject: [PATCH 03/89] deleted openjdk10 because its not working --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 86dff67..31041f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ dist: bionic language: java jdk: - oraclejdk11 - - openjdk10 +# - openjdk10 - openjdk11 #-----start GUI testing stuff From fd5ea938fbeac7f8d9cda5c51dad74f64d57fa89 Mon Sep 17 00:00:00 2001 From: Tobias Cerny Date: Thu, 10 Dec 2020 11:39:12 +0100 Subject: [PATCH 04/89] minor changes after creating core library project - changed execution environment to java 1.8 - moved the new module to the right place in pom --- de.variantsync.core/.classpath | 6 +----- pom.xml | 3 +-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/de.variantsync.core/.classpath b/de.variantsync.core/.classpath index 1247f9f..fd1d061 100644 --- a/de.variantsync.core/.classpath +++ b/de.variantsync.core/.classpath @@ -13,11 +13,7 @@ - - - - - + diff --git a/pom.xml b/pom.xml index ba71ef9..7c3da9a 100644 --- a/pom.xml +++ b/pom.xml @@ -19,10 +19,9 @@ de.tubs.variantsync.core de.tubs.variantsync.core.feature de.tubs.variantsync.update - + de.variantsync.core de.tubs.variantsync.core-test - de.variantsync.core From 2070412418795944f55c2ce9b19ac40d5eb64a2f Mon Sep 17 00:00:00 2001 From: Tobias Cerny Date: Mon, 14 Dec 2020 16:58:16 +0100 Subject: [PATCH 05/89] first draft of a Simple Parser for Text File Lines #52 --- .../main/java/de/variantsync/core/AST.java | 22 +++++++ .../main/java/de/variantsync/core/App.java | 13 ---- .../main/java/de/variantsync/core/Parser.java | 62 +++++++++++++++++++ 3 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 de.variantsync.core/src/main/java/de/variantsync/core/AST.java delete mode 100644 de.variantsync.core/src/main/java/de/variantsync/core/App.java create mode 100644 de.variantsync.core/src/main/java/de/variantsync/core/Parser.java diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java new file mode 100644 index 0000000..84c0421 --- /dev/null +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -0,0 +1,22 @@ +package de.variantsync.core; + +import java.util.ArrayList; +import java.util.List; + +public class AST { + int UUID; + Grammar type; + Value value; + List> children = new ArrayList<>(); + + public AST(Grammar type, Value value) { + super(); + this.type = type; + this.value = value; + } + + public enum LineGrammar { + Directory, File, Line + } + +} \ No newline at end of file diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/App.java b/de.variantsync.core/src/main/java/de/variantsync/core/App.java deleted file mode 100644 index 3925de5..0000000 --- a/de.variantsync.core/src/main/java/de/variantsync/core/App.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.variantsync.core; - -/** - * Hello world! - * - */ -public class App -{ - public static void main( String[] args ) - { - System.out.println( "Hello World!" ); - } -} diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java b/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java new file mode 100644 index 0000000..f86ab59 --- /dev/null +++ b/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java @@ -0,0 +1,62 @@ +package de.variantsync.core; + +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +import de.variantsync.core.AST.LineGrammar; + + +public class Parser +{ + public static void main( String[] args ) + { + Path path = Paths.get("src"); + try { + AST tryAndError = parseDirectory(path); + System.out.println(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static AST parseDirectory(Path folder) throws IOException { + AST result = null; + if (Files.isDirectory(folder)) { + result = new AST<>(LineGrammar.Directory, folder.getName(folder.getNameCount()-1).toString()); + DirectoryStream directoryStream = Files.newDirectoryStream(folder); + for (Path entry : directoryStream) { + result.children.add(parseDirectory(entry)); + } + } else { + if (!isBinaryFile(folder)) { + result = new AST<>(LineGrammar.File, folder.getName(folder.getNameCount()-1).toString()); + List fileStream = Files.readAllLines(folder); + for (String line : fileStream) { + result.children.add(new AST<>(LineGrammar.Line, line)); + } + } + } + return result; + } + + public static boolean isBinaryFile(Path file) { + try { + String type = Files.probeContentType(file); + if (type == null) { + //type couldn't be determined => assume binary + return true; + } else if (type.startsWith("text")) { + //non-binary + return false; + } + } catch (IOException e) { + e.printStackTrace(); + } + //type isn't text => assume binary + return true; + } +} From 7a951037b8c8fb89ea6aa0b40098b9d8f77d8375 Mon Sep 17 00:00:00 2001 From: jeremiaheinle Date: Mon, 14 Dec 2020 21:06:45 +0100 Subject: [PATCH 06/89] implemented #51 --- de.variantsync.core/pom.xml | 8 ++ .../main/java/de/variantsync/core/AST.java | 8 +- .../de/variantsync/core/EnumLineGrammar.java | 9 ++ .../de/variantsync/core/JsonParserAST.java | 54 ++++++++++ .../main/java/de/variantsync/core/Parser.java | 3 +- .../java/de/variantsync/core/AppTest.java | 98 +++++++++++++++++++ 6 files changed, 174 insertions(+), 6 deletions(-) create mode 100644 de.variantsync.core/src/main/java/de/variantsync/core/EnumLineGrammar.java create mode 100644 de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java diff --git a/de.variantsync.core/pom.xml b/de.variantsync.core/pom.xml index 0f721e3..45099c3 100644 --- a/de.variantsync.core/pom.xml +++ b/de.variantsync.core/pom.xml @@ -28,7 +28,15 @@ 4.11 test + + com.google.code.gson + gson + 2.8.6 + compile + + + diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index 84c0421..aa81353 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -4,19 +4,17 @@ import java.util.List; public class AST { - int UUID; + static int count; + int UUID; Grammar type; Value value; List> children = new ArrayList<>(); public AST(Grammar type, Value value) { super(); + this.UUID = count++; this.type = type; this.value = value; } - public enum LineGrammar { - Directory, File, Line - } - } \ No newline at end of file diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/EnumLineGrammar.java b/de.variantsync.core/src/main/java/de/variantsync/core/EnumLineGrammar.java new file mode 100644 index 0000000..23be945 --- /dev/null +++ b/de.variantsync.core/src/main/java/de/variantsync/core/EnumLineGrammar.java @@ -0,0 +1,9 @@ +package de.variantsync.core; + +class EnumLineGrammar { + + public enum LineGrammar { + Directory, File, Line + } + +} diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java b/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java new file mode 100644 index 0000000..5e66b37 --- /dev/null +++ b/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java @@ -0,0 +1,54 @@ +package de.variantsync.core; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import com.google.gson.Gson; + +class JsonParserAST { + + Gson gson = new Gson(); + + public JsonParserAST() { + } + + public String exportAST(AST ast){ + + return gson.toJson(ast); + } + + public AST importAST(String json) { + + return gson.fromJson(json, AST.class); + } + + + public String exportToFile(Path path, AST ast){ + + String content = gson.toJson(ast); + try { + Files.writeString(path, content); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + + return content; + } + + public AST importFromFile(Path path) { + + String json = ""; + try { + json = Files.readString(path); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } + + return gson.fromJson(json, AST.class); + } + +} diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java b/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java index f86ab59..d55c4c1 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java @@ -7,7 +7,8 @@ import java.nio.file.Paths; import java.util.List; -import de.variantsync.core.AST.LineGrammar; +import de.variantsync.core.EnumLineGrammar.LineGrammar; + public class Parser diff --git a/de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java index 66caa69..2aca994 100644 --- a/de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java +++ b/de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java @@ -2,8 +2,15 @@ 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.Test; +import de.variantsync.core.EnumLineGrammar.LineGrammar; + /** * Unit test for simple App. */ @@ -17,4 +24,95 @@ public void shouldAnswerWithTrue() { assertTrue( true ); } + + + @Test + public void TestJsonParserAST() + { + //init + AST srcDir = new AST<>(LineGrammar.Directory, "src"); + AST mainJava = new AST<>(LineGrammar.File, "Main.java"); + srcDir.children.add(mainJava); + mainJava.children.addAll(Arrays.asList( + new AST<>(LineGrammar.Line, "public class Main {"), + new AST<>(LineGrammar.Line, " public static void main(String[] args)"), + new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), + new AST<>(LineGrammar.Line, " }"), + new AST<>(LineGrammar.Line, "}"))); + + JsonParserAST parser = new JsonParserAST(); + + + + //export to json + String json = parser.exportAST(srcDir); + + + //import ast from json + AST ast = parser.importAST(json); + + //rexport imported AST + String jsonSec= parser.exportAST(ast); + + + + //print + System.out.println("First:"+json); + + System.out.println("Second:"+jsonSec); + + //compare json + if(json.equals(jsonSec)) { + assertTrue( true ); + }else { + assertTrue( false ); + } + + } + + + @Test + public void TestJsonParserASTtoFile() throws IOException + { + //init + AST srcDir = new AST<>(LineGrammar.Directory, "src"); + AST mainJava = new AST<>(LineGrammar.File, "Main.java"); + srcDir.children.add(mainJava); + mainJava.children.addAll(Arrays.asList( + new AST<>(LineGrammar.Line, "public class Main {"), + new AST<>(LineGrammar.Line, " public static void main(String[] args)"), + new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), + new AST<>(LineGrammar.Line, " }"), + new AST<>(LineGrammar.Line, "}"))); + + JsonParserAST parser = new JsonParserAST(); + + Path path = Path.of("out.txt"); + + + //export to json file + String json = parser.exportToFile(path, srcDir); + + //import ast from file + AST ast = parser.importFromFile(path); + + //rexport imported AST + String jsonSec= parser.exportAST(ast); + + + //print + System.out.println("FileFirst:"+json); + + System.out.println("FileSecond:"+jsonSec); + + //compare json + if(json.equals(jsonSec)) { + assertTrue( true ); + }else { + assertTrue( false ); + } + + Files.delete(path); + + } } From 2f4ad8a63989ec3a1c65ad1d3d36a377a708c905 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Tue, 15 Dec 2020 13:28:01 +0100 Subject: [PATCH 07/89] added UUID as type --- .../de.tubs.variantsync.core.iml | 34 ------------------- .../main/java/de/variantsync/core/AST.java | 7 ++-- 2 files changed, 3 insertions(+), 38 deletions(-) delete mode 100644 de.tubs.variantsync.core/de.tubs.variantsync.core.iml diff --git a/de.tubs.variantsync.core/de.tubs.variantsync.core.iml b/de.tubs.variantsync.core/de.tubs.variantsync.core.iml deleted file mode 100644 index 653a069..0000000 --- a/de.tubs.variantsync.core/de.tubs.variantsync.core.iml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index aa81353..3d226a6 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -2,17 +2,16 @@ import java.util.ArrayList; import java.util.List; +import java.util.UUID; public class AST { - static int count; - int UUID; + UUID id; Grammar type; Value value; List> children = new ArrayList<>(); public AST(Grammar type, Value value) { - super(); - this.UUID = count++; + this.id = UUID.randomUUID(); this.type = type; this.value = value; } From b9edc59e5dc9a6cccec39d2063a0389bbf909be0 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Wed, 16 Dec 2020 11:04:11 +0100 Subject: [PATCH 08/89] AST: added add method WIP toString --- .../main/java/de/variantsync/core/AST.java | 166 ++++++++++++++++-- .../java/de/variantsync/core/ASTTest.java | 28 +++ 2 files changed, 183 insertions(+), 11 deletions(-) create mode 100644 de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index 3d226a6..930ba6e 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -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 { - UUID id; + public static void main(String[] args) { + AST srcDir = new AST<>(EnumLineGrammar.LineGrammar.Directory, "src"); + AST mainDir = new AST<>(EnumLineGrammar.LineGrammar.Directory, "main"); + AST testDir = new AST<>(EnumLineGrammar.LineGrammar.Directory, "test"); + AST mainJava = new AST<>(EnumLineGrammar.LineGrammar.File, "Main.java"); + AST emptyJava = new AST<>(EnumLineGrammar.LineGrammar.File, "Empty.java"); + AST 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> children = new ArrayList<>(); - - public AST(Grammar type, Value value) { - this.id = UUID.randomUUID(); - this.type = type; - this.value = value; + int size; + List> 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 + *

+ * - testing + */ + + @Override + public String toString() { + String out = ""; + if(value == null) { + return out; + } else { + int[] level = {1}; + out += value + "\n"; + + HashSet levelFinished = new HashSet<>(); // eg. is level 3 finished? + out += toString(level,levelFinished,children); + + } + + return out; } + + private String toString(int[] level, HashSet levelFinished,List> children ) { + String out = ""; + if(levelFinished.contains(level[0])) { + level[0]++; + out += " "; + } + if (children.size() == 0) { + return out; + } + int index = children.size() -1; + for(AST 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 toAdd = new AST<>(gram, val); + if (children.size() == 0) { + children.add(toAdd); + } else { + for (AST 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 parent, AST 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. + */ + + } +} -} \ No newline at end of file diff --git a/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java new file mode 100644 index 0000000..2e72c13 --- /dev/null +++ b/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java @@ -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 ast; + + @Before + public void setup() { + ast = new AST<>(LineGrammar.Directory, "src"); + } + + @Test + public void addTest() { + + + } + +} From fba3b05eae4548acd2fdba38fbcad2add899fe0d Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Wed, 16 Dec 2020 14:10:41 +0100 Subject: [PATCH 09/89] added toString --- .../main/java/de/variantsync/core/AST.java | 114 +++++++++--------- 1 file changed, 58 insertions(+), 56 deletions(-) diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index 930ba6e..ca5780a 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -4,29 +4,29 @@ public class AST { - public static void main(String[] args) { - AST srcDir = new AST<>(EnumLineGrammar.LineGrammar.Directory, "src"); + public static void main(String[] args) { + AST srcDir = new AST<>(EnumLineGrammar.LineGrammar.Directory, "src"); AST mainDir = new AST<>(EnumLineGrammar.LineGrammar.Directory, "main"); AST testDir = new AST<>(EnumLineGrammar.LineGrammar.Directory, "test"); - AST mainJava = new AST<>(EnumLineGrammar.LineGrammar.File, "Main.java"); - AST emptyJava = new AST<>(EnumLineGrammar.LineGrammar.File, "Empty.java"); + AST mainJava = new AST<>(EnumLineGrammar.LineGrammar.File, "Main.java"); + AST emptyJava = new AST<>(EnumLineGrammar.LineGrammar.File, "Empty.java"); AST emptyTetJava = new AST<>(EnumLineGrammar.LineGrammar.File, "EmptyTest.java"); - srcDir.children.add(testDir); - testDir.children.add(emptyTetJava); - srcDir.children.add(mainDir); + srcDir.children.add(testDir); + testDir.children.add(emptyTetJava); + srcDir.children.add(mainDir); mainDir.children.add(mainJava); - mainDir.children.add(emptyJava); + 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); - } + 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; @@ -34,6 +34,8 @@ public static void main(String[] args) { int size; List> children; + private final String INDENT_STRING = " "; + /** * TODO: @@ -54,51 +56,51 @@ public static void main(String[] args) { @Override public String toString() { - String out = ""; - if(value == null) { - return out; - } else { - int[] level = {1}; - out += value + "\n"; - - HashSet levelFinished = new HashSet<>(); // eg. is level 3 finished? - out += toString(level,levelFinished,children); - - } - - return out; - } - - private String toString(int[] level, HashSet levelFinished,List> children ) { - String out = ""; - if(levelFinished.contains(level[0])) { - level[0]++; - out += " "; + StringBuilder result = new StringBuilder(); + if (value == null) { + return result.toString(); + } else { + int[] level = {1}; + result.append(value + "\n"); + + HashSet levelFinished = new HashSet<>(); // eg. is level 3 finished? + for (AST child : children) { + toString(result, child, level, levelFinished, false); + } } - if (children.size() == 0) { - return out; + + return result.toString(); + } + + + private void toString(StringBuilder result, AST parent, int[] level, HashSet levelFinished, boolean isLast) { + for (int i = 0; i < level[0]; i++) { + String toAppend = INDENT_STRING + "\u2502 "; + if (i == level[0] - 1) { + toAppend = INDENT_STRING + "\u251C\u2500 "; + if (isLast) { + toAppend = INDENT_STRING + "\u2514\u2500 "; + } + + } + result.append(toAppend); + } - int index = children.size() -1; - for(AST child : children) { - if(index == 0) { + result.append(parent.value + " Depth: " + level[0] + "\n"); + level[0]++; + for (AST child : parent.children) { + isLast = false; + if (parent.children.indexOf(child) == parent.children.size() - 1) { //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"; + levelFinished.add(level[0] - 1); + isLast = true; + } else if (parent.children.indexOf(child) == 0) { + levelFinished.remove(level[0] - 1); } - - - out += /*"\u2514\u2500" +*/ toString(level, levelFinished,child.children); - index--; + toString(result, child, level, levelFinished, isLast); } - levelFinished.add(level[0]); level[0]--; - return out; } public AST(Grammar type, Value value) { @@ -129,7 +131,7 @@ public void add(Grammar gram, Value val) { } } - System.err.println("AST-WARNING: Child could not be added!"); + System.err.println("AST-WARNING: Child could not be added!"); } } } From 7cc7dce0a4278ad13a509b068f03614a766050dd Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Wed, 16 Dec 2020 15:23:17 +0100 Subject: [PATCH 10/89] Fixed and Optimised toString() --- .../main/java/de/variantsync/core/AST.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index ca5780a..6253429 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -60,13 +60,13 @@ public String toString() { if (value == null) { return result.toString(); } else { - int[] level = {1}; + int[] level = {0}; result.append(value + "\n"); HashSet levelFinished = new HashSet<>(); // eg. is level 3 finished? - for (AST child : children) { - toString(result, child, level, levelFinished, false); - } + //levelFinished.add(level[0]); + //level[0]++; + toString(result, this, level, levelFinished, false); } return result.toString(); @@ -76,25 +76,35 @@ public String toString() { private void toString(StringBuilder result, AST parent, int[] level, HashSet levelFinished, boolean isLast) { for (int i = 0; i < level[0]; i++) { String toAppend = INDENT_STRING + "\u2502 "; + if (levelFinished.contains(i)) { + // no need of signs like | because of depth + toAppend = INDENT_STRING + " "; + } if (i == level[0] - 1) { - toAppend = INDENT_STRING + "\u251C\u2500 "; + // end of indent make arrow + toAppend = INDENT_STRING + "\u251C\u2500"; if (isLast) { - toAppend = INDENT_STRING + "\u2514\u2500 "; + // last child of parent, no arrow down needed + toAppend = INDENT_STRING + "\u2514\u2500"; } } result.append(toAppend); } - result.append(parent.value + " Depth: " + level[0] + "\n"); + result.append(parent.value); + result.append("Depth: "); + result.append(level[0]); + result.append("\n"); level[0]++; for (AST child : parent.children) { isLast = false; if (parent.children.indexOf(child) == parent.children.size() - 1) { - //last elem + // last child of subtree, meaning level finished, needs | levelFinished.add(level[0] - 1); isLast = true; } else if (parent.children.indexOf(child) == 0) { + // first child of new sub tree with unfinished level needs | levelFinished.remove(level[0] - 1); } toString(result, child, level, levelFinished, isLast); From 63b21fcd134a32616a71f3d230034b5f0d861cbb Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Wed, 16 Dec 2020 15:40:51 +0100 Subject: [PATCH 11/89] added forgotten space in toString() --- .../src/main/java/de/variantsync/core/AST.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index 6253429..7e2b9f0 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -92,8 +92,10 @@ private void toString(StringBuilder result, AST parent, int[] le result.append(toAppend); } + + result.append(" "); result.append(parent.value); - result.append("Depth: "); + result.append(" Depth: "); result.append(level[0]); result.append("\n"); level[0]++; From 421883f6a1c6249f5044195625fa7d3b9fd91705 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Wed, 16 Dec 2020 15:46:56 +0100 Subject: [PATCH 12/89] changed gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7ed634f..e92a655 100644 --- a/.gitignore +++ b/.gitignore @@ -106,7 +106,8 @@ local.properties # .idea/modules.xml # .idea/*.iml # .idea/modules -# *.iml +*.iml +.idea/ # *.ipr # CMake From b3d8ebbad21541d9e51431e1658974e6b3442b8d Mon Sep 17 00:00:00 2001 From: jeremiaheinle Date: Wed, 16 Dec 2020 21:16:57 +0100 Subject: [PATCH 13/89] edited #51 --- .../de/variantsync/core/JsonParserAST.java | 32 ++++--- .../de/variantsync/core/JsonParserTest.java | 96 +++++++++++++++++++ 2 files changed, 116 insertions(+), 12 deletions(-) create mode 100644 de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java b/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java index 5e66b37..c1d7b42 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java @@ -1,32 +1,38 @@ package de.variantsync.core; import java.io.IOException; +import java.lang.reflect.Type; import java.nio.file.Files; import java.nio.file.Path; import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; class JsonParserAST { - Gson gson = new Gson(); + static Gson gson = new Gson(); - public JsonParserAST() { - } - public String exportAST(AST ast){ + public static String exportAST(AST ast){ + + Type type = new TypeToken>() {}.getType(); - return gson.toJson(ast); + return gson.toJson(ast, type); } - public AST importAST(String json) { + public static AST importAST(String json) { - return gson.fromJson(json, AST.class); + Type type = new TypeToken>() {}.getType(); + + return gson.fromJson(json, type); } - public String exportToFile(Path path, AST ast){ + public static String exportToFile(Path path, AST ast){ - String content = gson.toJson(ast); + Type type = new TypeToken>() {}.getType(); + + String content = gson.toJson(ast, type); try { Files.writeString(path, content); } catch (IOException e) { @@ -37,7 +43,7 @@ public String exportToFile(Path path, AST ast){ return content; } - public AST importFromFile(Path path) { + public static AST importFromFile(Path path) { String json = ""; try { @@ -48,7 +54,9 @@ public AST importFromFile(Path path) { return null; } - return gson.fromJson(json, AST.class); + Type type = new TypeToken>() {}.getType(); + + return gson.fromJson(json, type); } -} +} \ No newline at end of file diff --git a/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java new file mode 100644 index 0000000..45abde4 --- /dev/null +++ b/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java @@ -0,0 +1,96 @@ +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 JsonParserTest { + + AST exampleAst; + Path exmaplePath; + + + @Before + public void InitJsonTest() throws IOException + { + //init + exampleAst = new AST<>(LineGrammar.Directory, "src"); + AST mainJava = new AST<>(LineGrammar.File, "Main.java"); + exampleAst.children.add(mainJava); + mainJava.children.addAll(Arrays.asList( + new AST<>(LineGrammar.Line, "public class Main {"), + new AST<>(LineGrammar.Line, " public static void main(String[] args)"), + new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), + new AST<>(LineGrammar.Line, " }"), + new AST<>(LineGrammar.Line, "}"))); + + + exmaplePath = Path.of("out.txt"); + + } + + @Test + public void TestJsonParserAST() + { + + + //export to json + String json = JsonParserAST.exportAST(exampleAst); + + + //import ast from json + AST ast = JsonParserAST.importAST(json); + + //rexport imported AST + String jsonSec= JsonParserAST.exportAST(ast); + + + + //print + System.out.println("First:"+json); + + System.out.println("Second:"+jsonSec); + + //compare json + assertTrue(json.equals(jsonSec)); + + } + + + @Test + public void TestJsonParserASTtoFile() throws IOException + { + + //export to json file + String json = JsonParserAST.exportToFile(exmaplePath, exampleAst); + + //import ast from file + AST ast = JsonParserAST.importFromFile(exmaplePath); + + //rexport imported AST + String jsonSec= JsonParserAST.exportAST(ast); + + + //print + System.out.println("FileFirst:"+json); + + System.out.println("FileSecond:"+jsonSec); + + //compare json + assertTrue(json.equals(jsonSec)); + + //delete created file + Files.delete(exmaplePath); + } + + +} + From a003240cb73218f67bd65d44ee3f1b72001cbf0e Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Thu, 17 Dec 2020 14:56:30 +0100 Subject: [PATCH 14/89] removed wrong java version --- de.variantsync.core/pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/de.variantsync.core/pom.xml b/de.variantsync.core/pom.xml index 45099c3..38116ff 100644 --- a/de.variantsync.core/pom.xml +++ b/de.variantsync.core/pom.xml @@ -17,8 +17,6 @@ UTF-8 - 1.7 - 1.7 From 8be0f6e88b0b5a883242697d5ae5143f86215bf1 Mon Sep 17 00:00:00 2001 From: jeremiaheinle Date: Thu, 17 Dec 2020 16:15:40 +0100 Subject: [PATCH 15/89] del apptest, enum --- .../de/variantsync/core/EnumLineGrammar.java | 9 -- .../java/de/variantsync/core/LineGrammar.java | 7 ++ .../main/java/de/variantsync/core/Parser.java | 2 +- .../java/de/variantsync/core/AppTest.java | 118 ------------------ .../de/variantsync/core/JsonParserTest.java | 2 +- 5 files changed, 9 insertions(+), 129 deletions(-) delete mode 100644 de.variantsync.core/src/main/java/de/variantsync/core/EnumLineGrammar.java create mode 100644 de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java delete mode 100644 de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/EnumLineGrammar.java b/de.variantsync.core/src/main/java/de/variantsync/core/EnumLineGrammar.java deleted file mode 100644 index 23be945..0000000 --- a/de.variantsync.core/src/main/java/de/variantsync/core/EnumLineGrammar.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.variantsync.core; - -class EnumLineGrammar { - - public enum LineGrammar { - Directory, File, Line - } - -} diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java b/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java new file mode 100644 index 0000000..1859368 --- /dev/null +++ b/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java @@ -0,0 +1,7 @@ +package de.variantsync.core; + + +public enum LineGrammar { + Directory, File, Line +} + diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java b/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java index d55c4c1..4a18df5 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java @@ -7,7 +7,7 @@ import java.nio.file.Paths; import java.util.List; -import de.variantsync.core.EnumLineGrammar.LineGrammar; +import de.variantsync.core.LineGrammar; diff --git a/de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java deleted file mode 100644 index 2aca994..0000000 --- a/de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java +++ /dev/null @@ -1,118 +0,0 @@ -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.Test; - -import de.variantsync.core.EnumLineGrammar.LineGrammar; - -/** - * Unit test for simple App. - */ -public class AppTest -{ - /** - * Rigorous Test :-) - */ - @Test - public void shouldAnswerWithTrue() - { - assertTrue( true ); - } - - - @Test - public void TestJsonParserAST() - { - //init - AST srcDir = new AST<>(LineGrammar.Directory, "src"); - AST mainJava = new AST<>(LineGrammar.File, "Main.java"); - srcDir.children.add(mainJava); - mainJava.children.addAll(Arrays.asList( - new AST<>(LineGrammar.Line, "public class Main {"), - new AST<>(LineGrammar.Line, " public static void main(String[] args)"), - new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), - new AST<>(LineGrammar.Line, " }"), - new AST<>(LineGrammar.Line, "}"))); - - JsonParserAST parser = new JsonParserAST(); - - - - //export to json - String json = parser.exportAST(srcDir); - - - //import ast from json - AST ast = parser.importAST(json); - - //rexport imported AST - String jsonSec= parser.exportAST(ast); - - - - //print - System.out.println("First:"+json); - - System.out.println("Second:"+jsonSec); - - //compare json - if(json.equals(jsonSec)) { - assertTrue( true ); - }else { - assertTrue( false ); - } - - } - - - @Test - public void TestJsonParserASTtoFile() throws IOException - { - //init - AST srcDir = new AST<>(LineGrammar.Directory, "src"); - AST mainJava = new AST<>(LineGrammar.File, "Main.java"); - srcDir.children.add(mainJava); - mainJava.children.addAll(Arrays.asList( - new AST<>(LineGrammar.Line, "public class Main {"), - new AST<>(LineGrammar.Line, " public static void main(String[] args)"), - new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), - new AST<>(LineGrammar.Line, " }"), - new AST<>(LineGrammar.Line, "}"))); - - JsonParserAST parser = new JsonParserAST(); - - Path path = Path.of("out.txt"); - - - //export to json file - String json = parser.exportToFile(path, srcDir); - - //import ast from file - AST ast = parser.importFromFile(path); - - //rexport imported AST - String jsonSec= parser.exportAST(ast); - - - //print - System.out.println("FileFirst:"+json); - - System.out.println("FileSecond:"+jsonSec); - - //compare json - if(json.equals(jsonSec)) { - assertTrue( true ); - }else { - assertTrue( false ); - } - - Files.delete(path); - - } -} diff --git a/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java index 45abde4..67bf551 100644 --- a/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java +++ b/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java @@ -10,7 +10,7 @@ import org.junit.Before; import org.junit.Test; -import de.variantsync.core.EnumLineGrammar.LineGrammar; +import de.variantsync.core.LineGrammar; public class JsonParserTest { From d5417dde6e932f6ec68f79fbe49be31034ea152e Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Thu, 17 Dec 2020 16:22:23 +0100 Subject: [PATCH 16/89] changed add Method of AST and its usage. Updated POM --- de.variantsync.core/pom.xml | 12 +- .../main/java/de/variantsync/core/AST.java | 90 ++++++------- ...{EnumLineGrammar.java => LineGrammar.java} | 5 +- .../main/java/de/variantsync/core/Parser.java | 6 +- .../java/de/variantsync/core/ASTTest.java | 2 +- .../java/de/variantsync/core/AppTest.java | 118 ------------------ 6 files changed, 52 insertions(+), 181 deletions(-) rename de.variantsync.core/src/main/java/de/variantsync/core/{EnumLineGrammar.java => LineGrammar.java} (51%) delete mode 100644 de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java diff --git a/de.variantsync.core/pom.xml b/de.variantsync.core/pom.xml index 45099c3..01e0092 100644 --- a/de.variantsync.core/pom.xml +++ b/de.variantsync.core/pom.xml @@ -17,8 +17,6 @@ UTF-8 - 1.7 - 1.7 @@ -82,5 +80,15 @@ + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index 7e2b9f0..c4d5246 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -5,34 +5,31 @@ public class AST { public static void main(String[] args) { - AST srcDir = new AST<>(EnumLineGrammar.LineGrammar.Directory, "src"); - AST mainDir = new AST<>(EnumLineGrammar.LineGrammar.Directory, "main"); - AST testDir = new AST<>(EnumLineGrammar.LineGrammar.Directory, "test"); - AST mainJava = new AST<>(EnumLineGrammar.LineGrammar.File, "Main.java"); - AST emptyJava = new AST<>(EnumLineGrammar.LineGrammar.File, "Empty.java"); - AST 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); + AST srcDir = new AST<>(LineGrammar.Directory, "src"); + AST mainDir = new AST<>(LineGrammar.Directory, "main"); + AST testDir = new AST<>(LineGrammar.Directory, "test"); + AST mainJava = new AST<>(LineGrammar.File, "Main.java"); + AST emptyJava = new AST<>(LineGrammar.File, "Empty.java"); + AST emptyTetJava = new AST<>(LineGrammar.File, "EmptyTest.java"); + srcDir.addChild(testDir); + testDir.addChild(emptyTetJava); + srcDir.addChild(mainDir); + mainDir.addChild(mainJava); + mainDir.addChild(emptyJava); + + mainJava.addChildren(Arrays.asList( + new AST<>(LineGrammar.Line, "public class Main {"), + new AST<>(LineGrammar.Line, " public static void main(String[] args)"), + new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), + new AST<>(LineGrammar.Line, " }"), + new AST<>(LineGrammar.Line, "}"))); System.out.println(srcDir); } - UUID id; - Grammar type; - Value value; - int size; - List> children; + private UUID id; + private Grammar type; + private Value value; + private List> children; private final String INDENT_STRING = " "; @@ -60,7 +57,7 @@ public String toString() { if (value == null) { return result.toString(); } else { - int[] level = {0}; + int[] level = {0}; //pointer magic result.append(value + "\n"); HashSet levelFinished = new HashSet<>(); // eg. is level 3 finished? @@ -120,42 +117,29 @@ public AST(Grammar type, Value value) { 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 toAdd = new AST<>(gram, val); - if (children.size() == 0) { - children.add(toAdd); - } else { - for (AST act : children) { - if (isValidChild(act, toAdd)) { - act.children.add(toAdd); - size++; - break; - } - } - System.err.println("AST-WARNING: Child could not be added!"); - } + public void addChildren(List> toAdd) { + if(toAdd != null) { + children.addAll(toAdd); + } + } + + public void addChild(AST toAdd) { + if(toAdd != null) { + children.add(toAdd); } } private boolean isValidChild(AST parent, AST child) { - if (parent.type instanceof EnumLineGrammar.LineGrammar) { - if (parent.type == EnumLineGrammar.LineGrammar.Directory) { + if (parent.type instanceof LineGrammar) { + if (parent.type == LineGrammar.Directory) { //Dir can't have line as child - return child.type != EnumLineGrammar.LineGrammar.Line; - } else if (parent.type == EnumLineGrammar.LineGrammar.File) { + return child.type != LineGrammar.Line; + } else if (parent.type == LineGrammar.File) { //File can't have dir or file as child - return child.type == EnumLineGrammar.LineGrammar.Line; + return child.type == LineGrammar.Line; } else { //Line is always leaf node return false; diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/EnumLineGrammar.java b/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java similarity index 51% rename from de.variantsync.core/src/main/java/de/variantsync/core/EnumLineGrammar.java rename to de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java index 23be945..3c4ac01 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/EnumLineGrammar.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java @@ -1,9 +1,6 @@ package de.variantsync.core; -class EnumLineGrammar { - - public enum LineGrammar { +public enum LineGrammar { Directory, File, Line - } } diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java b/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java index d55c4c1..afad3c4 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java @@ -7,7 +7,7 @@ import java.nio.file.Paths; import java.util.List; -import de.variantsync.core.EnumLineGrammar.LineGrammar; +import de.variantsync.core.LineGrammar; @@ -30,14 +30,14 @@ public static AST parseDirectory(Path folder) throws IOExce result = new AST<>(LineGrammar.Directory, folder.getName(folder.getNameCount()-1).toString()); DirectoryStream directoryStream = Files.newDirectoryStream(folder); for (Path entry : directoryStream) { - result.children.add(parseDirectory(entry)); + result.addChild(parseDirectory(entry)); } } else { if (!isBinaryFile(folder)) { result = new AST<>(LineGrammar.File, folder.getName(folder.getNameCount()-1).toString()); List fileStream = Files.readAllLines(folder); for (String line : fileStream) { - result.children.add(new AST<>(LineGrammar.Line, line)); + result.addChild(new AST<>(LineGrammar.Line, line)); } } } diff --git a/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java index 2e72c13..4ce4d6a 100644 --- a/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java +++ b/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java @@ -9,7 +9,7 @@ import org.junit.Before; import org.junit.Test; -import de.variantsync.core.EnumLineGrammar.LineGrammar; +import de.variantsync.core.LineGrammar; public class ASTTest { AST ast; diff --git a/de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java deleted file mode 100644 index 2aca994..0000000 --- a/de.variantsync.core/src/test/java/de/variantsync/core/AppTest.java +++ /dev/null @@ -1,118 +0,0 @@ -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.Test; - -import de.variantsync.core.EnumLineGrammar.LineGrammar; - -/** - * Unit test for simple App. - */ -public class AppTest -{ - /** - * Rigorous Test :-) - */ - @Test - public void shouldAnswerWithTrue() - { - assertTrue( true ); - } - - - @Test - public void TestJsonParserAST() - { - //init - AST srcDir = new AST<>(LineGrammar.Directory, "src"); - AST mainJava = new AST<>(LineGrammar.File, "Main.java"); - srcDir.children.add(mainJava); - mainJava.children.addAll(Arrays.asList( - new AST<>(LineGrammar.Line, "public class Main {"), - new AST<>(LineGrammar.Line, " public static void main(String[] args)"), - new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), - new AST<>(LineGrammar.Line, " }"), - new AST<>(LineGrammar.Line, "}"))); - - JsonParserAST parser = new JsonParserAST(); - - - - //export to json - String json = parser.exportAST(srcDir); - - - //import ast from json - AST ast = parser.importAST(json); - - //rexport imported AST - String jsonSec= parser.exportAST(ast); - - - - //print - System.out.println("First:"+json); - - System.out.println("Second:"+jsonSec); - - //compare json - if(json.equals(jsonSec)) { - assertTrue( true ); - }else { - assertTrue( false ); - } - - } - - - @Test - public void TestJsonParserASTtoFile() throws IOException - { - //init - AST srcDir = new AST<>(LineGrammar.Directory, "src"); - AST mainJava = new AST<>(LineGrammar.File, "Main.java"); - srcDir.children.add(mainJava); - mainJava.children.addAll(Arrays.asList( - new AST<>(LineGrammar.Line, "public class Main {"), - new AST<>(LineGrammar.Line, " public static void main(String[] args)"), - new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), - new AST<>(LineGrammar.Line, " }"), - new AST<>(LineGrammar.Line, "}"))); - - JsonParserAST parser = new JsonParserAST(); - - Path path = Path.of("out.txt"); - - - //export to json file - String json = parser.exportToFile(path, srcDir); - - //import ast from file - AST ast = parser.importFromFile(path); - - //rexport imported AST - String jsonSec= parser.exportAST(ast); - - - //print - System.out.println("FileFirst:"+json); - - System.out.println("FileSecond:"+jsonSec); - - //compare json - if(json.equals(jsonSec)) { - assertTrue( true ); - }else { - assertTrue( false ); - } - - Files.delete(path); - - } -} From b132ef92fab8f69ba969631430b69fc3215a1819 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Thu, 17 Dec 2020 16:26:13 +0100 Subject: [PATCH 17/89] MAVEN: set JAVA version to 11 for usage of Path --- de.variantsync.core/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/de.variantsync.core/pom.xml b/de.variantsync.core/pom.xml index 01e0092..5cfd5f5 100644 --- a/de.variantsync.core/pom.xml +++ b/de.variantsync.core/pom.xml @@ -85,8 +85,8 @@ org.apache.maven.plugins maven-compiler-plugin - 8 - 8 + 11 + 11 From 225174a3d0ef631d7e7068fb1891d63d3eeaa51b Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Thu, 17 Dec 2020 16:37:24 +0100 Subject: [PATCH 18/89] changed toString according to pauls ideas #50 --- .../src/main/java/de/variantsync/core/AST.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index c4d5246..0154f4d 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -90,11 +90,7 @@ private void toString(StringBuilder result, AST parent, int[] le } - result.append(" "); - result.append(parent.value); - result.append(" Depth: "); - result.append(level[0]); - result.append("\n"); + result.append(" ").append(parent.type).append(" ").append(parent.value).append(" Depth: ").append(level[0]).append("\n"); level[0]++; for (AST child : parent.children) { isLast = false; From 9259bcc4cfeea62989fb5c4b33ef22c3748c7c0e Mon Sep 17 00:00:00 2001 From: jeremiaheinle Date: Thu, 17 Dec 2020 16:41:28 +0100 Subject: [PATCH 19/89] prettty json and test AST.toString() --- .../de/variantsync/core/JsonParserAST.java | 3 +- .../de/variantsync/core/JsonParserTest.java | 29 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java b/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java index c1d7b42..2ef2987 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java @@ -6,11 +6,12 @@ import java.nio.file.Path; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; class JsonParserAST { - static Gson gson = new Gson(); + static Gson gson = new GsonBuilder().setPrettyPrinting().create(); public static String exportAST(AST ast){ diff --git a/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java index 67bf551..fafd49e 100644 --- a/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java +++ b/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java @@ -50,7 +50,7 @@ public void TestJsonParserAST() AST ast = JsonParserAST.importAST(json); //rexport imported AST - String jsonSec= JsonParserAST.exportAST(ast); + String jsonSec = JsonParserAST.exportAST(ast); @@ -79,6 +79,33 @@ public void TestJsonParserASTtoFile() throws IOException String jsonSec= JsonParserAST.exportAST(ast); + //print + System.out.println("FileFirst:"+json); + + System.out.println("FileSecond:"+jsonSec); + + //compare json + assertTrue(json.equals(jsonSec)); + + //delete created file + Files.delete(exmaplePath); + } + + @Test + public void TestJsonParserASTtoFileToString() throws IOException + { + + //export to json file + JsonParserAST.exportToFile(exmaplePath, exampleAst); + + //import ast from file + AST ast = JsonParserAST.importFromFile(exmaplePath); + + //get toString + String json = exampleAst.toString(); + String jsonSec = ast.toString(); + + //print System.out.println("FileFirst:"+json); From 355cec9289727af6ccb4e31eac8a835cf4ed37be Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Thu, 17 Dec 2020 16:51:51 +0100 Subject: [PATCH 20/89] merge dropped LineGrammar --- .../src/main/java/de/variantsync/core/LineGrammar.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java b/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java new file mode 100644 index 0000000..405cfe9 --- /dev/null +++ b/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java @@ -0,0 +1,5 @@ +package de.variantsync.core; + +public enum LineGrammar { + Directory, File, Line; +} From 06dbe23498b1433c6eea592765914813523d8510 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Thu, 17 Dec 2020 16:54:49 +0100 Subject: [PATCH 21/89] JsonParserTest fixed --- .../src/test/java/de/variantsync/core/JsonParserTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java index fafd49e..2c9da3f 100644 --- a/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java +++ b/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java @@ -24,8 +24,8 @@ public void InitJsonTest() throws IOException //init exampleAst = new AST<>(LineGrammar.Directory, "src"); AST mainJava = new AST<>(LineGrammar.File, "Main.java"); - exampleAst.children.add(mainJava); - mainJava.children.addAll(Arrays.asList( + exampleAst.addChild(mainJava); + mainJava.addChildren(Arrays.asList( new AST<>(LineGrammar.Line, "public class Main {"), new AST<>(LineGrammar.Line, " public static void main(String[] args)"), new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), From dd854f800d77bfef108247dc368fcea3c0697a4e Mon Sep 17 00:00:00 2001 From: jeremiaheinle Date: Thu, 17 Dec 2020 17:02:02 +0100 Subject: [PATCH 22/89] exclude fiels in AST from JsonParser --- .../src/main/java/de/variantsync/core/AST.java | 6 ++++++ .../src/main/java/de/variantsync/core/JsonParserAST.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index 0154f4d..e315b0d 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -2,6 +2,8 @@ import java.util.*; +import com.google.gson.annotations.Expose; + public class AST { public static void main(String[] args) { @@ -26,9 +28,13 @@ public static void main(String[] args) { System.out.println(srcDir); } + @Expose private UUID id; + @Expose private Grammar type; + @Expose private Value value; + @Expose private List> children; private final String INDENT_STRING = " "; diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java b/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java index 2ef2987..d123c99 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/JsonParserAST.java @@ -11,7 +11,7 @@ class JsonParserAST { - static Gson gson = new GsonBuilder().setPrettyPrinting().create(); + static Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create(); public static String exportAST(AST ast){ From d80b38b977b6f2977bf992f02e29f38a446ff331 Mon Sep 17 00:00:00 2001 From: jeremiaheinle Date: Thu, 17 Dec 2020 17:10:30 +0100 Subject: [PATCH 23/89] added seriazable --- .../src/main/java/de/variantsync/core/AST.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index e315b0d..a8c008c 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -3,6 +3,7 @@ import java.util.*; import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; public class AST { @@ -28,13 +29,17 @@ public static void main(String[] args) { System.out.println(srcDir); } - @Expose + @Expose + @SerializedName(value = "uuid") private UUID id; @Expose - private Grammar type; - @Expose + @SerializedName(value = "value") private Value value; - @Expose + @Expose + @SerializedName(value = "grammar_type") + private Grammar type; + @Expose + @SerializedName(value = "children") private List> children; private final String INDENT_STRING = " "; From 94425edfdcfa5329848f6e619fe87438d009c332 Mon Sep 17 00:00:00 2001 From: Tobias Cerny Date: Mon, 21 Dec 2020 17:09:30 +0100 Subject: [PATCH 24/89] Testcase for parseDirectory additionally adjustments in simple parser --- .../main/java/de/variantsync/core/AST.java | 8 +-- .../java/de/variantsync/core/LineGrammar.java | 2 +- .../main/java/de/variantsync/core/Parser.java | 30 +++------ .../de/variantsync/core/JsonParserTest.java | 4 +- .../java/de/variantsync/core/ParserTest.java | 67 +++++++++++++++++++ 5 files changed, 82 insertions(+), 29 deletions(-) create mode 100644 de.variantsync.core/src/test/java/de/variantsync/core/ParserTest.java diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index a8c008c..dfd9951 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -11,9 +11,9 @@ public static void main(String[] args) { AST srcDir = new AST<>(LineGrammar.Directory, "src"); AST mainDir = new AST<>(LineGrammar.Directory, "main"); AST testDir = new AST<>(LineGrammar.Directory, "test"); - AST mainJava = new AST<>(LineGrammar.File, "Main.java"); - AST emptyJava = new AST<>(LineGrammar.File, "Empty.java"); - AST emptyTetJava = new AST<>(LineGrammar.File, "EmptyTest.java"); + AST mainJava = new AST<>(LineGrammar.TextFile, "Main.java"); + AST emptyJava = new AST<>(LineGrammar.TextFile, "Empty.java"); + AST emptyTetJava = new AST<>(LineGrammar.TextFile, "EmptyTest.java"); srcDir.addChild(testDir); testDir.addChild(emptyTetJava); srcDir.addChild(mainDir); @@ -144,7 +144,7 @@ private boolean isValidChild(AST parent, AST chi if (parent.type == LineGrammar.Directory) { //Dir can't have line as child return child.type != LineGrammar.Line; - } else if (parent.type == LineGrammar.File) { + } else if (parent.type == LineGrammar.TextFile) { //File can't have dir or file as child return child.type == LineGrammar.Line; } else { diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java b/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java index 405cfe9..0613899 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java @@ -1,5 +1,5 @@ package de.variantsync.core; public enum LineGrammar { - Directory, File, Line; + Directory, TextFile, BinaryFile, Line; } diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java b/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java index afad3c4..3bd2467 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/Parser.java @@ -7,23 +7,9 @@ import java.nio.file.Paths; import java.util.List; -import de.variantsync.core.LineGrammar; +public class Parser { - -public class Parser -{ - public static void main( String[] args ) - { - Path path = Paths.get("src"); - try { - AST tryAndError = parseDirectory(path); - System.out.println(); - } catch (IOException e) { - e.printStackTrace(); - } - } - public static AST parseDirectory(Path folder) throws IOException { AST result = null; if (Files.isDirectory(folder)) { @@ -34,17 +20,19 @@ public static AST parseDirectory(Path folder) throws IOExce } } else { if (!isBinaryFile(folder)) { - result = new AST<>(LineGrammar.File, folder.getName(folder.getNameCount()-1).toString()); - List fileStream = Files.readAllLines(folder); - for (String line : fileStream) { - result.addChild(new AST<>(LineGrammar.Line, line)); - } + result = new AST<>(LineGrammar.TextFile, folder.getName(folder.getNameCount()-1).toString()); + List fileStream = Files.readAllLines(folder); + for (String line : fileStream) { + result.addChild(new AST<>(LineGrammar.Line, line)); + } + } else { + result = new AST<>(LineGrammar.BinaryFile, folder.getName(folder.getNameCount()-1).toString()); } } return result; } - public static boolean isBinaryFile(Path file) { + private static boolean isBinaryFile(Path file) { try { String type = Files.probeContentType(file); if (type == null) { diff --git a/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java index 2c9da3f..9344e01 100644 --- a/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java +++ b/de.variantsync.core/src/test/java/de/variantsync/core/JsonParserTest.java @@ -10,8 +10,6 @@ import org.junit.Before; import org.junit.Test; -import de.variantsync.core.LineGrammar; - public class JsonParserTest { AST exampleAst; @@ -23,7 +21,7 @@ public void InitJsonTest() throws IOException { //init exampleAst = new AST<>(LineGrammar.Directory, "src"); - AST mainJava = new AST<>(LineGrammar.File, "Main.java"); + AST mainJava = new AST<>(LineGrammar.TextFile, "Main.java"); exampleAst.addChild(mainJava); mainJava.addChildren(Arrays.asList( new AST<>(LineGrammar.Line, "public class Main {"), diff --git a/de.variantsync.core/src/test/java/de/variantsync/core/ParserTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/ParserTest.java new file mode 100644 index 0000000..898a566 --- /dev/null +++ b/de.variantsync.core/src/test/java/de/variantsync/core/ParserTest.java @@ -0,0 +1,67 @@ +package de.variantsync.core; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import static org.junit.Assert.assertEquals; + + +public class ParserTest { + private AST srcDir; + + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); + + @Before + public void setupAST() { + srcDir = new AST<>(LineGrammar.Directory, "src"); + AST mainDir = new AST<>(LineGrammar.Directory, "main"); + srcDir.addChild(mainDir); + AST testDir = new AST<>(LineGrammar.Directory, "test"); + srcDir.addChild(testDir); + AST mainJava = new AST<>(LineGrammar.TextFile, "Main.java"); + mainDir.addChild(mainJava); + mainJava.addChildren(Arrays.asList( + new AST<>(LineGrammar.Line, "public class Main {"), + new AST<>(LineGrammar.Line, " public static void main(String[] args)"), + new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), + new AST<>(LineGrammar.Line, " }"), + new AST<>(LineGrammar.Line, "}"))); + AST binFile = new AST<>(LineGrammar.BinaryFile, "binaryFile"); + mainDir.addChild(binFile); + } + + @Test + public void parseDirectoryTest() throws IOException { + Path src = tempFolder.newFolder("src").toPath(); + Path mainDir = Files.createDirectory(Paths.get(src + File.separator + "main")); + Path testDir = Files.createDirectory(Paths.get(src + File.separator + "test")); + Path mainFile = Files.createFile(Paths.get(mainDir + File.separator + "Main.java")); + Files.writeString(mainFile, + "public class Main {\n"+ + " public static void main(String[] args)\n"+ + " System.out.println(\"Hello World\");\n"+ + " }\n"+ + "}"); + + Path binFile = Files.createFile(Paths.get(mainDir + File.separator + "binaryFile")); + byte[] bytes = "stringForCreationOfByteArray".getBytes(); + Files.write(binFile, bytes); + + AST parsedAST = Parser.parseDirectory(src); + + // Test fails at the moment due to an inequality of the toString() methods + // waiting for equals() method for AST +// assertEquals(parsedAST, srcDir); + } + +} From 15c2c4004c22cb83d02b4d039532cd3a89fb98b6 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Wed, 6 Jan 2021 15:50:32 +0100 Subject: [PATCH 25/89] fixed bug causing that the first dir is displayed twice --- .../src/main/java/de/variantsync/core/AST.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index dfd9951..44555ee 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -69,7 +69,7 @@ public String toString() { return result.toString(); } else { int[] level = {0}; //pointer magic - result.append(value + "\n"); + //result.append(value + "\n"); HashSet levelFinished = new HashSet<>(); // eg. is level 3 finished? //levelFinished.add(level[0]); @@ -98,10 +98,11 @@ private void toString(StringBuilder result, AST parent, int[] le } result.append(toAppend); + if(i != 0) result.append(" "); } - result.append(" ").append(parent.type).append(" ").append(parent.value).append(" Depth: ").append(level[0]).append("\n"); + result.append(parent.type).append(" ").append(parent.value).append(" Depth: ").append(level[0]).append("\n"); level[0]++; for (AST child : parent.children) { isLast = false; From bf259dc99b89848bb8de16096fc947790678ff62 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Wed, 6 Jan 2021 15:51:26 +0100 Subject: [PATCH 26/89] first try to make attributed LineGrammar Enum --- .../java/de/variantsync/core/LineGrammar.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java b/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java index 0613899..9c6d121 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java @@ -1,5 +1,37 @@ package de.variantsync.core; +import java.util.ArrayList; +import java.util.List; + public enum LineGrammar { - Directory, TextFile, BinaryFile, Line; + Directory, TextFile, BinaryFile, Line; + + private List addAttributes; + + LineGrammar() { + addAttributes = new ArrayList<>(); + } + + LineGrammar(List addAttributes) { + this.addAttributes = addAttributes; + } + + public List getAttributes() { + return addAttributes; + } + + private boolean isValidChild(LineGrammar parent, LineGrammar child) { + if (parent == LineGrammar.Directory) { + //Dir can't have line as child + return child != LineGrammar.Line; + } else if (parent == LineGrammar.TextFile || parent == LineGrammar.BinaryFile) { + //File can't have dir or file as child + return child == LineGrammar.Line; + } else { + //Line is always leaf node + return false; + } + + } + } From 5d822153be8bd1e8a614bea0c70eb6732719e439 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Wed, 6 Jan 2021 15:52:11 +0100 Subject: [PATCH 27/89] Styleguide --- .../main/java/de/variantsync/core/AST.java | 303 +++++++++--------- 1 file changed, 144 insertions(+), 159 deletions(-) diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index 44555ee..a3a772f 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -5,165 +5,150 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; - public class AST { - public static void main(String[] args) { - AST srcDir = new AST<>(LineGrammar.Directory, "src"); - AST mainDir = new AST<>(LineGrammar.Directory, "main"); - AST testDir = new AST<>(LineGrammar.Directory, "test"); - AST mainJava = new AST<>(LineGrammar.TextFile, "Main.java"); - AST emptyJava = new AST<>(LineGrammar.TextFile, "Empty.java"); - AST emptyTetJava = new AST<>(LineGrammar.TextFile, "EmptyTest.java"); - srcDir.addChild(testDir); - testDir.addChild(emptyTetJava); - srcDir.addChild(mainDir); - mainDir.addChild(mainJava); - mainDir.addChild(emptyJava); - - mainJava.addChildren(Arrays.asList( - new AST<>(LineGrammar.Line, "public class Main {"), - new AST<>(LineGrammar.Line, " public static void main(String[] args)"), - new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), - new AST<>(LineGrammar.Line, " }"), - new AST<>(LineGrammar.Line, "}"))); - System.out.println(srcDir); - } - - @Expose - @SerializedName(value = "uuid") - private UUID id; - @Expose - @SerializedName(value = "value") - private Value value; - @Expose - @SerializedName(value = "grammar_type") - private Grammar type; - @Expose - @SerializedName(value = "children") - private List> children; - - private final String INDENT_STRING = " "; - - - /** - * 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 - *

- * - testing - */ - - @Override - public String toString() { - StringBuilder result = new StringBuilder(); - if (value == null) { - return result.toString(); - } else { - int[] level = {0}; //pointer magic - //result.append(value + "\n"); - - HashSet levelFinished = new HashSet<>(); // eg. is level 3 finished? - //levelFinished.add(level[0]); - //level[0]++; - toString(result, this, level, levelFinished, false); - } - - return result.toString(); - } - - - private void toString(StringBuilder result, AST parent, int[] level, HashSet levelFinished, boolean isLast) { - for (int i = 0; i < level[0]; i++) { - String toAppend = INDENT_STRING + "\u2502 "; - if (levelFinished.contains(i)) { - // no need of signs like | because of depth - toAppend = INDENT_STRING + " "; - } - if (i == level[0] - 1) { - // end of indent make arrow - toAppend = INDENT_STRING + "\u251C\u2500"; - if (isLast) { - // last child of parent, no arrow down needed - toAppend = INDENT_STRING + "\u2514\u2500"; - } - - } - result.append(toAppend); - if(i != 0) result.append(" "); - - } - - result.append(parent.type).append(" ").append(parent.value).append(" Depth: ").append(level[0]).append("\n"); - level[0]++; - for (AST child : parent.children) { - isLast = false; - if (parent.children.indexOf(child) == parent.children.size() - 1) { - // last child of subtree, meaning level finished, needs | - levelFinished.add(level[0] - 1); - isLast = true; - } else if (parent.children.indexOf(child) == 0) { - // first child of new sub tree with unfinished level needs | - levelFinished.remove(level[0] - 1); - } - toString(result, child, level, levelFinished, isLast); - - } - level[0]--; - } - - public AST(Grammar type, Value value) { - this.id = UUID.randomUUID(); - this.type = type; - this.value = value; - this.children = new ArrayList<>(); - } - - - public void addChildren(List> toAdd) { - if(toAdd != null) { - children.addAll(toAdd); - } - } - - public void addChild(AST toAdd) { - if(toAdd != null) { - children.add(toAdd); - } - } - - private boolean isValidChild(AST parent, AST child) { - if (parent.type instanceof LineGrammar) { - if (parent.type == LineGrammar.Directory) { - //Dir can't have line as child - return child.type != LineGrammar.Line; - } else if (parent.type == LineGrammar.TextFile) { - //File can't have dir or file as child - return child.type == 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. - */ - - } + + public static void main(String[] args) { + AST srcDir = new AST<>(LineGrammar.Directory, "src"); + AST mainDir = new AST<>(LineGrammar.Directory, "main"); + AST testDir = new AST<>(LineGrammar.Directory, "test"); + AST mainJava = new AST<>(LineGrammar.TextFile, "Main.java"); + AST emptyJava = new AST<>(LineGrammar.TextFile, "Empty.java"); + AST emptyTetJava = new AST<>(LineGrammar.TextFile, "EmptyTest.java"); + srcDir.addChild(testDir); + testDir.addChild(emptyTetJava); + srcDir.addChild(mainDir); + mainDir.addChild(mainJava); + mainDir.addChild(emptyJava); + + mainJava.addChildren( + Arrays.asList(new AST<>(LineGrammar.Line, "public class Main {"), new AST<>(LineGrammar.Line, " public static void main(String[] args)"), + new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), new AST<>(LineGrammar.Line, " }"), + new AST<>(LineGrammar.Line, "}"))); + System.out.println(srcDir); + } + + @Expose @SerializedName(value = "uuid") private UUID id; + @Expose @SerializedName(value = "value") private Value value; + @Expose @SerializedName(value = "grammar_type") private Grammar type; + @Expose @SerializedName(value = "children") private List> children; + + private final String INDENT_STRING = " "; + + /** + * 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 + *

+ * - testing + */ + + @Override public String toString() { + StringBuilder result = new StringBuilder(); + if (value == null) { + return result.toString(); + } else { + int[] level = { 0 }; //pointer magic + //result.append(value + "\n"); + + HashSet levelFinished = new HashSet<>(); // eg. is level 3 finished? + //levelFinished.add(level[0]); + //level[0]++; + toString(result, this, level, levelFinished, false); + } + + return result.toString(); + } + + private void toString(StringBuilder result, AST parent, int[] level, HashSet levelFinished, boolean isLast) { + for (int i = 0; i < level[0]; i++) { + String toAppend = INDENT_STRING + "\u2502 "; + if (levelFinished.contains(i)) { + // no need of signs like | because of depth + toAppend = INDENT_STRING + " "; + } + if (i == level[0] - 1) { + // end of indent make arrow + toAppend = INDENT_STRING + "\u251C\u2500"; + if (isLast) { + // last child of parent, no arrow down needed + toAppend = INDENT_STRING + "\u2514\u2500"; + } + + } + result.append(toAppend); + if (i != 0) result.append(" "); + + } + + result.append(parent.type).append(" ").append(parent.value).append(" Depth: ").append(level[0]).append("\n"); + level[0]++; + for (AST child : parent.children) { + isLast = false; + if (parent.children.indexOf(child) == parent.children.size() - 1) { + // last child of subtree, meaning level finished, needs | + levelFinished.add(level[0] - 1); + isLast = true; + } else if (parent.children.indexOf(child) == 0) { + // first child of new sub tree with unfinished level needs | + levelFinished.remove(level[0] - 1); + } + toString(result, child, level, levelFinished, isLast); + + } + level[0]--; + } + + public AST(Grammar type, Value value) { + this.id = UUID.randomUUID(); + this.type = type; + this.value = value; + this.children = new ArrayList<>(); + } + + public void addChildren(List> toAdd) { + if (toAdd != null) { + children.addAll(toAdd); + } + } + + public void addChild(AST toAdd) { + if (toAdd != null) { + children.add(toAdd); + } + } + + private boolean isValidChild(AST parent, AST child) { + if (parent.type instanceof LineGrammar) { + if (parent.type == LineGrammar.Directory) { + //Dir can't have line as child + return child.type != LineGrammar.Line; + } else if (parent.type == LineGrammar.TextFile) { + //File can't have dir or file as child + return child.type == 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. + */ + + } } From 1435db5584d11027a5bd6589e89eb108f0fc14e9 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Wed, 6 Jan 2021 15:54:31 +0100 Subject: [PATCH 28/89] refactoring AST.java --- .../main/java/de/variantsync/core/AST.java | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index a3a772f..6396715 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -125,25 +125,7 @@ public void addChild(AST toAdd) { children.add(toAdd); } } - - private boolean isValidChild(AST parent, AST child) { - if (parent.type instanceof LineGrammar) { - if (parent.type == LineGrammar.Directory) { - //Dir can't have line as child - return child.type != LineGrammar.Line; - } else if (parent.type == LineGrammar.TextFile) { - //File can't have dir or file as child - return child.type == 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. From 84b2e15dbf64a11f7dcb353c83d2e34ba7182c76 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Wed, 6 Jan 2021 16:03:02 +0100 Subject: [PATCH 29/89] removed main from AST.java and added toString test --- .../main/java/de/variantsync/core/AST.java | 23 +------------ .../java/de/variantsync/core/ASTTest.java | 32 +++++++++++++++++-- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index 6396715..d76e122 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -6,27 +6,6 @@ import com.google.gson.annotations.SerializedName; public class AST { - - public static void main(String[] args) { - AST srcDir = new AST<>(LineGrammar.Directory, "src"); - AST mainDir = new AST<>(LineGrammar.Directory, "main"); - AST testDir = new AST<>(LineGrammar.Directory, "test"); - AST mainJava = new AST<>(LineGrammar.TextFile, "Main.java"); - AST emptyJava = new AST<>(LineGrammar.TextFile, "Empty.java"); - AST emptyTetJava = new AST<>(LineGrammar.TextFile, "EmptyTest.java"); - srcDir.addChild(testDir); - testDir.addChild(emptyTetJava); - srcDir.addChild(mainDir); - mainDir.addChild(mainJava); - mainDir.addChild(emptyJava); - - mainJava.addChildren( - Arrays.asList(new AST<>(LineGrammar.Line, "public class Main {"), new AST<>(LineGrammar.Line, " public static void main(String[] args)"), - new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), new AST<>(LineGrammar.Line, " }"), - new AST<>(LineGrammar.Line, "}"))); - System.out.println(srcDir); - } - @Expose @SerializedName(value = "uuid") private UUID id; @Expose @SerializedName(value = "value") private Value value; @Expose @SerializedName(value = "grammar_type") private Grammar type; @@ -125,7 +104,7 @@ public void addChild(AST toAdd) { children.add(toAdd); } } - + private AST() { /** * Empty AST is forbidden at the moment. diff --git a/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java index 4ce4d6a..968768c 100644 --- a/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java +++ b/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java @@ -1,5 +1,6 @@ package de.variantsync.core; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.IOException; import java.nio.file.Files; @@ -17,12 +18,37 @@ public class ASTTest { @Before public void setup() { ast = new AST<>(LineGrammar.Directory, "src"); + AST mainDir = new AST<>(LineGrammar.Directory, "main"); + AST testDir = new AST<>(LineGrammar.Directory, "test"); + AST mainJava = new AST<>(LineGrammar.TextFile, "Main.java"); + AST emptyJava = new AST<>(LineGrammar.TextFile, "Empty.java"); + AST emptyTetJava = new AST<>(LineGrammar.TextFile, "EmptyTest.java"); + ast.addChild(testDir); + testDir.addChild(emptyTetJava); + ast.addChild(mainDir); + mainDir.addChild(mainJava); + mainDir.addChild(emptyJava); + + mainJava.addChildren( + Arrays.asList(new AST<>(LineGrammar.Line, "public class Main {"), new AST<>(LineGrammar.Line, " public static void main(String[] args)"), + new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), new AST<>(LineGrammar.Line, " }"), + new AST<>(LineGrammar.Line, "}"))); } @Test - public void addTest() { - - + public void toStringTest() { + String expected = "Directory src Depth: 0\n" + + " ├─Directory test Depth: 1\n" + + " │ └─ TextFile EmptyTest.java Depth: 2\n" + + " └─Directory main Depth: 1\n" + + " ├─ TextFile Main.java Depth: 2\n" + + " │ ├─ Line public class Main { Depth: 3\n" + + " │ ├─ Line public static void main(String[] args) Depth: 3\n" + + " │ ├─ Line System.out.println(\"Hello World\"); Depth: 3\n" + + " │ ├─ Line } Depth: 3\n" + + " │ └─ Line } Depth: 3\n" + + " └─ TextFile Empty.java Depth: 2\n"; + assertEquals(expected,ast.toString()); } } From 34a6d4e69dd4bf3ba903b0901a3ddd1f3b9a27d3 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Wed, 6 Jan 2021 17:13:12 +0100 Subject: [PATCH 30/89] added size method and WIP size testing --- .../main/java/de/variantsync/core/AST.java | 20 +++++ .../java/de/variantsync/core/ASTTest.java | 81 ++++++++++--------- 2 files changed, 64 insertions(+), 37 deletions(-) diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index d76e122..8c4dc8a 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -6,6 +6,7 @@ import com.google.gson.annotations.SerializedName; public class AST { + @Expose @SerializedName(value = "uuid") private UUID id; @Expose @SerializedName(value = "value") private Value value; @Expose @SerializedName(value = "grammar_type") private Grammar type; @@ -105,6 +106,25 @@ public void addChild(AST toAdd) { } } + public int size() { + if (children.size() == 0) { + return 0; + } else { + return size(children, 1); + } + } + + private int size(List> children, int tmpSize) { + if (children.size() != 0) { + for (AST act : children) { + System.out.println(act.value + " tmpSize " + tmpSize + " childs " + act.children.size()); + tmpSize = size(act.children, tmpSize); + } + tmpSize += children.size(); + } + return tmpSize; + } + private AST() { /** * Empty AST is forbidden at the moment. diff --git a/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java index 968768c..5056755 100644 --- a/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java +++ b/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java @@ -2,6 +2,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -13,42 +14,48 @@ import de.variantsync.core.LineGrammar; public class ASTTest { - AST ast; - - @Before - public void setup() { - ast = new AST<>(LineGrammar.Directory, "src"); - AST mainDir = new AST<>(LineGrammar.Directory, "main"); - AST testDir = new AST<>(LineGrammar.Directory, "test"); - AST mainJava = new AST<>(LineGrammar.TextFile, "Main.java"); - AST emptyJava = new AST<>(LineGrammar.TextFile, "Empty.java"); - AST emptyTetJava = new AST<>(LineGrammar.TextFile, "EmptyTest.java"); - ast.addChild(testDir); - testDir.addChild(emptyTetJava); - ast.addChild(mainDir); - mainDir.addChild(mainJava); - mainDir.addChild(emptyJava); - - mainJava.addChildren( - Arrays.asList(new AST<>(LineGrammar.Line, "public class Main {"), new AST<>(LineGrammar.Line, " public static void main(String[] args)"), - new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), new AST<>(LineGrammar.Line, " }"), - new AST<>(LineGrammar.Line, "}"))); - } - - @Test - public void toStringTest() { - String expected = "Directory src Depth: 0\n" - + " ├─Directory test Depth: 1\n" - + " │ └─ TextFile EmptyTest.java Depth: 2\n" - + " └─Directory main Depth: 1\n" - + " ├─ TextFile Main.java Depth: 2\n" - + " │ ├─ Line public class Main { Depth: 3\n" - + " │ ├─ Line public static void main(String[] args) Depth: 3\n" - + " │ ├─ Line System.out.println(\"Hello World\"); Depth: 3\n" - + " │ ├─ Line } Depth: 3\n" - + " │ └─ Line } Depth: 3\n" - + " └─ TextFile Empty.java Depth: 2\n"; - assertEquals(expected,ast.toString()); - } + + AST ast; + AST mainJava; + + @Before public void setup() { + ast = new AST<>(LineGrammar.Directory, "src"); + AST mainDir = new AST<>(LineGrammar.Directory, "main"); + AST testDir = new AST<>(LineGrammar.Directory, "test"); + mainJava = new AST<>(LineGrammar.TextFile, "Main.java"); + AST emptyJava = new AST<>(LineGrammar.TextFile, "Empty.java"); + AST emptyTetJava = new AST<>(LineGrammar.TextFile, "EmptyTest.java"); + ast.addChild(testDir); + testDir.addChild(emptyTetJava); + ast.addChild(mainDir); + mainDir.addChild(mainJava); + mainDir.addChild(emptyJava); + + mainJava.addChildren( + Arrays.asList(new AST<>(LineGrammar.Line, "public class Main {"), new AST<>(LineGrammar.Line, " public static void main(String[] args)"), + new AST<>(LineGrammar.Line, " System.out.println(\"Hello World\");"), new AST<>(LineGrammar.Line, " }"), + new AST<>(LineGrammar.Line, "}"))); + } + + @Test public void sizeTest() { + assertEquals(11, ast.size()); + + mainJava = null; + int size = ast.size(); + //TODO: FIND OUT WHY THIS IS NOT WORKING + //assertEquals(6,size); + + ast = new AST<>(null, null); + assertEquals(0, ast.size()); + } + + @Test public void toStringTest() { + String expected = "Directory src Depth: 0\n" + " ├─Directory test Depth: 1\n" + " │ └─ TextFile EmptyTest.java Depth: 2\n" + + " └─Directory main Depth: 1\n" + " ├─ TextFile Main.java Depth: 2\n" + " │ ├─ Line public class Main { Depth: 3\n" + + " │ ├─ Line public static void main(String[] args) Depth: 3\n" + + " │ ├─ Line System.out.println(\"Hello World\"); Depth: 3\n" + " │ ├─ Line } Depth: 3\n" + + " │ └─ Line } Depth: 3\n" + " └─ TextFile Empty.java Depth: 2\n"; + assertEquals(expected, ast.toString()); + } } From 4071731b56db704bf30c732583af272d435ca3c9 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Wed, 6 Jan 2021 17:14:33 +0100 Subject: [PATCH 31/89] removed DEBUG output --- de.variantsync.core/src/main/java/de/variantsync/core/AST.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index 8c4dc8a..50ccf9b 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -117,7 +117,7 @@ public int size() { private int size(List> children, int tmpSize) { if (children.size() != 0) { for (AST act : children) { - System.out.println(act.value + " tmpSize " + tmpSize + " childs " + act.children.size()); + //System.out.println(act.value + " tmpSize " + tmpSize + " childs " + act.children.size()); tmpSize = size(act.children, tmpSize); } tmpSize += children.size(); From d1361545c9aac2bc4f6ae4a4cce5b3e871ab6229 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Wed, 6 Jan 2021 17:15:57 +0100 Subject: [PATCH 32/89] updated travis --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 31041f0..a4fb269 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,7 @@ dist: bionic language: java jdk: - - oraclejdk11 -# - openjdk10 + - openjdk10 - openjdk11 #-----start GUI testing stuff From 6fd51b2e55d357144aacd90ba083ae33adc91ade Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 6 Jan 2021 18:08:53 +0100 Subject: [PATCH 33/89] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a4fb269..c4204e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ jdk: #-----start GUI testing stuff services: - xvfb -#-----end GUI testin stuff +#-----end GUI testing stuff cache: directories: - "$HOME/.m2" From f92002d787d099b9651b953b06451f0c2a9b6ded Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 6 Jan 2021 18:12:36 +0100 Subject: [PATCH 34/89] Travis decides if this is a fix or not --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 7c3da9a..399e813 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ 2.1.0 2.1.0 UTF-8 - https://download.eclipse.org/releases/2020-09/ + https://download.eclipse.org/releases/2019-12/ @@ -19,7 +19,7 @@ de.tubs.variantsync.core de.tubs.variantsync.core.feature de.tubs.variantsync.update - de.variantsync.core + de.variantsync.core de.tubs.variantsync.core-test @@ -52,8 +52,8 @@ ${tycho-version} true - - SYSTEM + + SYSTEM @@ -221,4 +221,4 @@ - \ No newline at end of file + From 87b22c8db138c3b1131ad91866112cad12d7451b Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Fri, 8 Jan 2021 14:00:15 +0100 Subject: [PATCH 35/89] Refactored LineGrammar according to Pauls idea, reduced size test --- .../main/java/de/variantsync/core/AST.java | 18 ++++----------- .../java/de/variantsync/core/LineGrammar.java | 22 +++++++++++++++---- .../variantsync/core/interfaces/Grammar.java | 10 +++++++++ .../java/de/variantsync/core/ASTTest.java | 14 ++---------- 4 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 de.variantsync.core/src/main/java/de/variantsync/core/interfaces/Grammar.java diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java index 50ccf9b..65e0cdb 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/AST.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/AST.java @@ -107,24 +107,14 @@ public void addChild(AST toAdd) { } public int size() { - if (children.size() == 0) { - return 0; - } else { - return size(children, 1); - } - } - - private int size(List> children, int tmpSize) { - if (children.size() != 0) { - for (AST act : children) { - //System.out.println(act.value + " tmpSize " + tmpSize + " childs " + act.children.size()); - tmpSize = size(act.children, tmpSize); - } - tmpSize += children.size(); + int tmpSize = 1; + for (AST act : children) { + tmpSize += act.size(); } return tmpSize; } + private AST() { /** * Empty AST is forbidden at the moment. diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java b/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java index 9c6d121..0d2e4fc 100644 --- a/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java +++ b/de.variantsync.core/src/main/java/de/variantsync/core/LineGrammar.java @@ -1,9 +1,11 @@ package de.variantsync.core; +import de.variantsync.core.interfaces.Grammar; + import java.util.ArrayList; import java.util.List; -public enum LineGrammar { +public enum LineGrammar implements Grammar { Directory, TextFile, BinaryFile, Line; private List addAttributes; @@ -20,11 +22,11 @@ public List getAttributes() { return addAttributes; } - private boolean isValidChild(LineGrammar parent, LineGrammar child) { - if (parent == LineGrammar.Directory) { + @Override public boolean isValidChild(LineGrammar child) { + if (this == LineGrammar.Directory) { //Dir can't have line as child return child != LineGrammar.Line; - } else if (parent == LineGrammar.TextFile || parent == LineGrammar.BinaryFile) { + } else if (this == LineGrammar.TextFile || this == LineGrammar.BinaryFile) { //File can't have dir or file as child return child == LineGrammar.Line; } else { @@ -34,4 +36,16 @@ private boolean isValidChild(LineGrammar parent, LineGrammar child) { } + @Override public OptionalType getTypeOf(LineGrammar sym) { + switch (sym) { + case Directory: + return OptionalType.NodeOptional; + case TextFile: + case BinaryFile: + case Line: + return OptionalType.TreeOptional; + default: + throw new IllegalArgumentException("[BUG] There is not OptionalType for symbol " + sym + " specified!"); + } + } } diff --git a/de.variantsync.core/src/main/java/de/variantsync/core/interfaces/Grammar.java b/de.variantsync.core/src/main/java/de/variantsync/core/interfaces/Grammar.java new file mode 100644 index 0000000..f8ee346 --- /dev/null +++ b/de.variantsync.core/src/main/java/de/variantsync/core/interfaces/Grammar.java @@ -0,0 +1,10 @@ +package de.variantsync.core.interfaces; + +public interface Grammar { + enum OptionalType { + NodeOptional, TreeOptional, Mandatory + } + + public boolean isValidChild(T child); + public OptionalType getTypeOf(T sym); +} diff --git a/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java b/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java index 5056755..29ba630 100644 --- a/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java +++ b/de.variantsync.core/src/test/java/de/variantsync/core/ASTTest.java @@ -1,11 +1,7 @@ package de.variantsync.core; +import static java.lang.Thread.sleep; import static org.junit.Assert.assertEquals; -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; @@ -39,14 +35,8 @@ public class ASTTest { @Test public void sizeTest() { assertEquals(11, ast.size()); - - mainJava = null; - int size = ast.size(); - //TODO: FIND OUT WHY THIS IS NOT WORKING - //assertEquals(6,size); - ast = new AST<>(null, null); - assertEquals(0, ast.size()); + assertEquals(1, ast.size()); } @Test public void toStringTest() { From a6249c0a112dff0af8a55b6c2c5a816c0f5223d6 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Sat, 16 Jan 2021 01:02:56 +0100 Subject: [PATCH 36/89] addressing reviewer suggestions of #53 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c4204e9..51fdc6b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ dist: bionic language: java jdk: - - openjdk10 - openjdk11 #-----start GUI testing stuff From 0e8b1838f89ce30376c67a5957f160c08e020448 Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Mon, 25 Jan 2021 16:48:30 +0100 Subject: [PATCH 37/89] added relativePath to child pom --- de.tubs.variantsync.core/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/de.tubs.variantsync.core/pom.xml b/de.tubs.variantsync.core/pom.xml index b69f88b..0d8aecc 100644 --- a/de.tubs.variantsync.core/pom.xml +++ b/de.tubs.variantsync.core/pom.xml @@ -6,10 +6,11 @@ de.tubs.variantsync de.tubs.variantsync 0.0.3-SNAPSHOT + ../pom.xml de.tubs.variantsync.core eclipse-plugin de.tubs.variantsync.core - \ No newline at end of file + From fa3a8a88aa886208aeddec7f77908b473dc4db9c Mon Sep 17 00:00:00 2001 From: wurstbroteater Date: Mon, 25 Jan 2021 17:02:00 +0100 Subject: [PATCH 38/89] added maven compiler to fix IntelliJ-only-resolving-bugs --- pom.xml | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 399e813..7725576 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 de.tubs.variantsync de.tubs.variantsync @@ -9,6 +10,7 @@ 2.1.0 2.1.0 + 3.8.1 UTF-8 https://download.eclipse.org/releases/2019-12/ @@ -19,27 +21,38 @@ de.tubs.variantsync.core de.tubs.variantsync.core.feature de.tubs.variantsync.update - de.variantsync.core + de.variantsync.core de.tubs.variantsync.core-test - + - + eclipse-release ${eclipse-repo.url} p2 - + featureide http://featureide.cs.ovgu.de/update/v3/ p2 - + - + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-version} + + 11 + 11 + + + org.eclipse.tycho tycho-maven-plugin @@ -52,16 +65,16 @@ ${tycho-version} true - - SYSTEM + + SYSTEM - + org.eclipse.tycho target-platform-configuration ${tycho-version} - + consider @@ -103,8 +116,8 @@ - +