Bug 368453 - Java import fails to import enum
Summary: Java import fails to import enum
Status: REPORTED
Alias: None
Product: umbrello
Classification: Applications
Component: general (show other bugs)
Version: 2.9.5
Platform: Other All
: NOR normal
Target Milestone: ---
Assignee: Umbrello Development Group
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-08 13:11 UTC by Ralf Habacker
Modified: 2020-01-12 12:49 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Test.java (86 bytes, text/x-java)
2016-09-08 13:12 UTC, Ralf Habacker
Details
main.java (72 bytes, text/x-java)
2016-09-08 13:12 UTC, Ralf Habacker
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ralf Habacker 2016-09-08 13:11:34 UTC
Java fails to import enums in a case where imports references the dedicated enum instead of the parent package as shown by the following example:

--- file main.java ----
import Test.Enum;

public class main {
    public Test.Enum myEnum;
}
--------- file Test.java ---------
public class Test { public enum Enum {  A, B, C } }
 

Reproducible: Always

Steps to Reproduce:
1. start umbrello
2. switch active language to 'java'
3. import the appended file main.java
4. Inspect the imported type 'Enum'

Actual Results:  
type 'Enum' is imported as class instead of being an enum.


Expected Results:  
Type 'Enum' should be imported as java type enum.



umbrello version 2.9.5 is the oldest version I have currently access to; the bug itself may also be in older version.
Comment 1 Ralf Habacker 2016-09-08 13:12:27 UTC
Created attachment 100984 [details]
Test.java
Comment 2 Ralf Habacker 2016-09-08 13:12:40 UTC
Created attachment 100985 [details]
main.java
Comment 3 Oliver Kellogg 2020-01-11 15:11:37 UTC
Git commit 372b1e0203847cc8ff7dc79a2a799d9a79b215f9 by Oliver Kellogg.
Committed on 11/01/2020 at 15:10.
Pushed by okellogg into branch 'release/19.12'.

Fix crash on importing Java code attached to bug 368453:
The example uses the global scope and JavaImport crashes on adding
objects in the global scope without prior defined Java package.

umbrello/codeimport/import_utils.{h,cpp}
- Add function globalScope() returning the package of the global scope.

umbrello/codeimport/nativeimportbase.cpp
- In function parseFile() do not push a null pointer as the global
  scope; instead, push Import_Utils::globalScope().

M  +9    -0    umbrello/codeimport/import_utils.cpp
M  +2    -0    umbrello/codeimport/import_utils.h
M  +1    -1    umbrello/codeimport/nativeimportbase.cpp

https://invent.kde.org/kde/umbrello/commit/372b1e0203847cc8ff7dc79a2a799d9a79b215f9
Comment 4 Oliver Kellogg 2020-01-12 12:48:18 UTC
Observation for narrowing down the problem:

After importing the two files, the treeview shows

 <Class> main
 <Package> Test
     |
     > <Class> Enum (empty)
     > <Class> Test
          |
          > <Enumeration> Enum

That looks wrong.

If I rename main.java to Umain.java and redo the import, the treeview shows:

 <Class> Test
   |
   > <Enumeration> Enum
 <Class> Umain

That looks right.

In the in the first case, main.java is imported before Test.java
but in the second case, Test.java is imported after Umain.java.
Comment 5 Oliver Kellogg 2020-01-12 12:49:26 UTC
(In reply to Oliver Kellogg from comment #4)
> In the in the first case, main.java is imported before Test.java
> but in the second case, Test.java is imported after Umain.java.

Oops typo:
In the second case, Test.java is imported *before* Umain.java.