Bug 397909 - Develop Vala importer
Summary: Develop Vala importer
Status: REPORTED
Alias: None
Product: umbrello
Classification: Applications
Component: importer (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Umbrello Development Group
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-27 01:46 UTC by Nine-H
Modified: 2022-02-19 21:45 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 2.33.80 (KDE releases 22.03.80)


Attachments
screenshot from imported vala test file (80.34 KB, image/png)
2018-08-28 12:40 UTC, Ralf Habacker
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nine-H 2018-08-27 01:46:40 UTC
I need to develop some UML diagrams for vala projects, I've been using draw.io to generate one by hand, but it's labour intensive. I understand that Umbrello has code generation for Vala, it'd be nice to to have code import too.
Comment 1 Ralf Habacker 2018-08-27 10:38:47 UTC
This requires a Vala parser in C++ and a class/method that runs through the parsed tree to create the corresponding uml objects.
Comment 2 Ralf Habacker 2018-08-27 10:41:53 UTC
According to https://wiki.gnome.org/Projects/Vala/Syntax, the syntax is like C#, which would make it possible to use the already available C# importer (called CSharpImport).
Comment 3 Nine-H 2018-08-28 00:32:18 UTC
I'm not familiar with the project or C++, are you able to set the C# importer to load .vala and .vapi files in a branch I can test?
Comment 4 Ralf Habacker 2018-08-28 06:11:39 UTC
At first glance, the C# import internally has the extension'*.cs' permanently wired and would require several modifications. 
To start it would be possible to rename a *.vala file to *.cs without any further changes and then try to import it as C#.
Comment 5 Ralf Habacker 2018-08-28 06:14:58 UTC
Some test files showing the syntax for classes, methods, attributes, visibility, associations such as generalizations would also be useful to see how much work it would be.
Comment 6 Nine-H 2018-08-28 06:52:11 UTC
Here's the project I'm trying to map out, there's quite a few vala projects on GitHub at different sizes and complexities.

https://github.com/elementary/music

There's also an extensive manual of features here.

http://www.vala-project.org/doc/vala/

I could knock out a test class that covers the syntax and types but it might take a while for me to complete it.

linked list data structures aren't in the core they use the Gee package.

https://valadoc.org/gee-0.8/Gee.html
Comment 7 Ralf Habacker 2018-08-28 12:40:38 UTC
Created attachment 114654 [details]
screenshot from imported vala test file

For a quick impression 
1. I downloaded the code fragment from https://wiki.gnome.org/Projects/Vala/GIOSamples#Asynchronous_File_Listing to test.vala
2. created a symbolic link named test.cs
3. Imported test.cs with c# importer

The appended screenshot shows the result:
1. The class ASyncGIOSample was imported with inheritance correctly
2. the attribue 'model' has been imported with visibility and correct type
3. The constructor has been imported correctly
4. method 'list_directory' shows some errors 
4.1 'async' has been wrongly imported as type
4.2 the name of the method is 'voidlist_directory(){stdout.printf("Start scanning home directory\n")', which is incorrect
Comment 8 Ralf Habacker 2018-08-28 13:05:59 UTC
Just for the record: umbrello already supports a vala writer, which may be used to generate test files for a vala importer.
Comment 9 Ralf Habacker 2018-08-28 13:32:29 UTC
Git commit ae8b7ca95e405dddbe87a5a505d7600c70e916f7 by Ralf Habacker.
Committed on 28/08/2018 at 13:31.
Pushed by habacker into branch 'work/397909-vala-importer'.

Add initial support for a vala importer

M  +1    -0    umbrello/CMakeLists.txt
M  +7    -0    umbrello/basictypes.cpp
M  +3    -0    umbrello/codeimport/classimport.cpp
M  +8    -2    umbrello/codeimport/csharp/csharpimport.cpp
M  +6    -0    umbrello/codeimport/csharp/csharpimport.h
A  +27   -0    umbrello/codeimport/valaimport.cpp     [License: GPL (v2+)]
A  +25   -0    umbrello/codeimport/valaimport.h     [License: GPL (v2+)]

https://commits.kde.org/umbrello/ae8b7ca95e405dddbe87a5a505d7600c70e916f7
Comment 10 Ralf Habacker 2018-08-28 13:40:11 UTC
I just pushed https://cgit.kde.org/umbrello.git/log/?h=work/397909-vala-importer with an initial vala importer based on C# import. I added member m_language to class CSharpImport holding the currently processed language. 

https://github.com/KDE/umbrello is a clone of the git repo mentioned above, from which you can create and edit a fork.

For working on class method parsing you may inspect bool CSharpImport::parseStmt().
Comment 11 Bug Janitor Service 2022-02-16 03:53:27 UTC
A possibly relevant merge request was started @ https://invent.kde.org/sdk/umbrello/-/merge_requests/27
Comment 12 Oliver Kellogg 2022-02-19 21:28:31 UTC
Git commit 7dbb75549a72334cf426969295364aee5f9ff0c7 by Oliver Kellogg.
Committed on 16/02/2022 at 03:44.
Pushed by okellogg into branch 'master'.

New class CsValaImportBase is quasi abstract base for C# and Vala import

- Move content of umbrello/codeimport/csharp/csharpimport.{h,cpp} to
  umbrello/codeimport/csvalaimportbase.{h,cpp} and adjust class name to
  CsValaImportBase.
- Move umbrello/codeimport/valaimport.{h,cpp} to new subdirectory vala
  and derive the class from CsValaImportBase.
- Copy content of umbrello/codeimport/vala/valaimport.{h,cpp} to
  umbrello/codeimport/csharp/csharpimport.{h,cpp}, restore class name
  CSharpImport, and restore correct body of function fileExtension().
- In umbrello/codeimport/CMakeLists.txt add file csvalaimportbase.cpp
  and adjust to new subdirectory "vala" with file valaimport.cpp.

M  +3    -1    umbrello/codeimport/CMakeLists.txt
M  +5    -760  umbrello/codeimport/csharp/csharpimport.cpp
M  +5    -67   umbrello/codeimport/csharp/csharpimport.h
C  +42   -42   umbrello/codeimport/csvalaimportbase.cpp [from: umbrello/codeimport/csharp/csharpimport.cpp - 090% similarity]
C  +6    -7    umbrello/codeimport/csvalaimportbase.h [from: umbrello/codeimport/csharp/csharpimport.h - 088% similarity]
A  +31   -0    umbrello/codeimport/vala/valaimport.cpp     [License: GPL(v2.0+)]
A  +25   -0    umbrello/codeimport/vala/valaimport.h     [License: GPL(v2.0+)]
D  +0    -27   umbrello/codeimport/valaimport.cpp
D  +0    -25   umbrello/codeimport/valaimport.h

https://invent.kde.org/sdk/umbrello/commit/7dbb75549a72334cf426969295364aee5f9ff0c7
Comment 13 Ralf Habacker 2022-02-19 21:28:39 UTC
Git commit ae8b7ca95e405dddbe87a5a505d7600c70e916f7 by Ralf Habacker.
Committed on 28/08/2018 at 13:31.
Pushed by okellogg into branch 'master'.

Add initial support for a vala importer

M  +1    -0    umbrello/CMakeLists.txt
M  +7    -0    umbrello/basictypes.cpp
M  +3    -0    umbrello/codeimport/classimport.cpp
M  +8    -2    umbrello/codeimport/csharp/csharpimport.cpp
M  +6    -0    umbrello/codeimport/csharp/csharpimport.h
A  +27   -0    umbrello/codeimport/valaimport.cpp     [License: GPL (v2+)]
A  +25   -0    umbrello/codeimport/valaimport.h     [License: GPL (v2+)]

https://invent.kde.org/sdk/umbrello/commit/ae8b7ca95e405dddbe87a5a505d7600c70e916f7
Comment 14 Oliver Kellogg 2022-02-19 21:28:47 UTC
Git commit 43a486bff7096f091c4ee649088752d3e2a105cf by Oliver Kellogg.
Committed on 19/02/2022 at 16:39.
Pushed by okellogg into branch 'master'.

umbrello/codeimport/csvalaimportbase.cpp followup to commit a5893a5 :

- In function fillSource condense single dimension array into the type
  name as done in the defaultDatatypes() of CSharpWriter and ValaWriter.

M  +10   -0    umbrello/codeimport/csvalaimportbase.cpp

https://invent.kde.org/sdk/umbrello/commit/43a486bff7096f091c4ee649088752d3e2a105cf
Comment 15 Oliver Kellogg 2022-02-19 21:29:19 UTC
Git commit c28f11f6e59819b108b8c3b18e5c0c255d5476cd by Oliver Kellogg.
Committed on 19/02/2022 at 17:00.
Pushed by okellogg into branch 'master'.

test/import/vala/helloWorld.vala : First rudimentary test case for ValaImport

A  +13   -0    test/import/vala/helloWorld.vala

https://invent.kde.org/sdk/umbrello/commit/c28f11f6e59819b108b8c3b18e5c0c255d5476cd