This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 89934 - Need a way to generate initial values for multiplicity attributes with Collection Override
Summary: Need a way to generate initial values for multiplicity attributes with Collec...
Status: NEW
Alias: None
Product: uml
Classification: Unclassified
Component: Code Generation (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: issues@uml
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-23 11:39 UTC by Alexandr Scherbatiy
Modified: 2009-01-23 15:08 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexandr Scherbatiy 2006-11-23 11:39:32 UTC
Steps to reproduce:

- Put a Class element on a class diagram
- Insert 'private String[] array = {"1", "2", "3"}' attribute
- Generate code for the Class element

  The generated attribute is 
  --------------------------------------------------
  private ArrayList<String> array = {"1", "2", "3"};
  --------------------------------------------------
  
  The code is not compiled.
  There should be a way to generate initial values for
  Collections.
Comment 1 Craig Conover 2006-11-30 23:08:54 UTC
Because Collections don't allow init values to be declared during construction,
actual implementation code would have to be generated. Not sure we want to do
this, or how we would want to do this since there are multiple ways to do it.
Probably the simplest way would be in a instance initialize block:

for example:
private ArrayList<String> foo = new ArrayList<String>();
{
    foo.add("one");
    foo.add("two");
}

Or, in the constructor... but which constructor if more than one?

If member is static, then code would need to be gen'ed into the static init block.

Or, we could just ignore the initial values when using Collection overriding.
Comment 2 Alexandr Scherbatiy 2006-12-01 13:55:52 UTC
The instance initialize block and static init block are enough to
initialize a collection. 
I could suggest the following pattern:

-------------------------------------------------------------
  private ArrayList<String> foo = new ArrayList<String>();
  {
      for( String value: new String [] {"1", "2", "3"} ){
          foo.add(value);
      }
  }
-------------------------------------------------------------



Comment 3 Craig Conover 2007-06-26 04:01:29 UTC
problem still exists in new code gen module
Comment 4 Sergey Petrov 2009-01-23 15:08:56 UTC
support for advanced initial values is more like enhancement, currently it's just like literal/string value