From 77aee062ff568c14a09957dc27e19c1f25c28f6d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mikl=C3=B3s=20T=C3=B3th?= <tothmiklostibor@gmail.com>
Date: Sun, 28 Feb 2021 19:33:20 +0100
Subject: [PATCH] fix class diag

---
 Dockerfile        |  5 ++---
 plab/classdiag.go | 40 +++++++++++++++++++++++++++-------------
 plab/javadoc.go   |  2 +-
 plab/unescape.go  |  9 +++++++++
 4 files changed, 39 insertions(+), 17 deletions(-)
 create mode 100644 plab/unescape.go

diff --git a/Dockerfile b/Dockerfile
index e517f80..7ebb394 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,8 +1,7 @@
 FROM texlive/texlive
 RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get -y upgrade && apt-get -y install inkscape plantuml openjdk-11-jdk-headless hunspell hunspell-hu hunspell-en-gb hunspell-en-us python3-pip && pip3 install javalang
 COPY tikz-uml.sty /usr/local/texlive/2020/texmf-dist/tex/latex/tikz-uml/tikz-uml.sty
-COPY jsonDoclet.jar /root/jsonDoclet.jar
-COPY ./plab/out/plab /usr/bin/plab
 RUN mktexlsr
 COPY gen_seq_diag.py /
-RUN chmod +x /gen_seq_diag.py
\ No newline at end of file
+COPY jsonDoclet.jar /root/jsonDoclet.jar
+COPY ./plab/out/plab /usr/bin/plab
diff --git a/plab/classdiag.go b/plab/classdiag.go
index 19720c7..c1f6003 100644
--- a/plab/classdiag.go
+++ b/plab/classdiag.go
@@ -2,7 +2,6 @@ package main
 
 import (
 	"bytes"
-	"encoding/json"
 	"fmt"
 	"io/ioutil"
 	"os"
@@ -80,12 +79,14 @@ func genPlantUMLStr(classes map[string]*Class) {
 					for _, e := range a.Elements {
 						switch e.QualifiedName {
 						case "projlab.Docs.uml":
-							e.Value = strings.ReplaceAll(e.Value, "\\\"", "🍆")
-							e.Value = strings.ReplaceAll(e.Value, "\"", "")
-							e.Value = strings.ReplaceAll(e.Value, "🍆", "\"")
+							e.Value = unescape(e.Value)
 							uml = true
+							t := f.Type.Name
+							if strings.Contains(t, "..") {
+								t = strings.Split(t, " ")[0]
+							}
 							if e.Value != "" {
-								after += fmt.Sprintf("\n%s %s %s", f.Type.Name, e.Value, c.Name)
+								after += fmt.Sprintf("\n%s %s %s", t, e.Value, c.Name)
 							}
 						}
 					}
@@ -118,9 +119,7 @@ func genPlantUMLStr(classes map[string]*Class) {
 				for _, e := range a.Elements {
 					switch e.QualifiedName {
 					case "projlab.Docs.uml":
-						e.Value = strings.ReplaceAll(e.Value, "\\\"", "🍆")
-						e.Value = strings.ReplaceAll(e.Value, "\"", "")
-						e.Value = strings.ReplaceAll(e.Value, "🍆", "\"")
+						e.Value = unescape(e.Value)
 						output.WriteString(fmt.Sprintln(e.Value))
 					}
 				}
@@ -144,16 +143,31 @@ func genPlantUMLStr(classes map[string]*Class) {
 	}
 
 	for _, c := range classes {
-		out, e := json.Marshal(*c)
-		if e != nil {
-			panic(e)
+		deps := make([]string, 0)
+		hasdep := func(dep string) bool {
+			for _, d := range deps {
+				if d == dep {
+					return true
+				}
+			}
+			return false
 		}
-		str := string(out)
+
+		for _, dep := range c.Fields {
+			deps = append(deps, dep.Type.Name)
+		}
+		for _, dep := range c.Methods {
+			deps = append(deps, dep.ReturnType.Name)
+			for _, d := range dep.Parameters {
+				deps = append(deps, d.Type.Name)
+			}
+		}
+
 		for _, c2 := range classes {
 			if c2.Name == c.Name {
 				continue
 			}
-			if strings.Contains(str, c2.Name) {
+			if hasdep(c2.Name) {
 				skips := skip[c2.Name]
 				shouldSkip := false
 				for _, s := range skips {
diff --git a/plab/javadoc.go b/plab/javadoc.go
index 1c02f09..8ffc747 100644
--- a/plab/javadoc.go
+++ b/plab/javadoc.go
@@ -204,7 +204,7 @@ func readJson(fname string) (*Class, error) {
 					for _, e := range a.Elements {
 						switch e.QualifiedName {
 						case "projlab.Docs.type":
-							e.Value = strings.ReplaceAll(e.Value, "\"", "")
+							e.Value = unescape(e.Value)
 							if e.Value != "" {
 								replace(arr[i], e.Value)
 							}
diff --git a/plab/unescape.go b/plab/unescape.go
new file mode 100644
index 0000000..616e103
--- /dev/null
+++ b/plab/unescape.go
@@ -0,0 +1,9 @@
+package main
+
+import "encoding/json"
+
+func unescape(s string) string {
+	var ret string
+	_ = json.Unmarshal([]byte(s), &ret)
+	return ret
+}
-- 
GitLab