Book a Demo

Author Topic: Problem creating Java imports  (Read 3478 times)

dabeita

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Problem creating Java imports
« on: February 25, 2005, 01:36:59 pm »
Hello again.

I'm having some problems with the generation of Java Imports.  I'm trying to get all imports (from params, method returns, attributes, etc.) when generating or overwriting a file.  To do this, I've implemented the solution proposed in the following post.

http://www.sparxsystems.com.au/cgi-bin/yabb/YaBB.pl?board=general;action=display;num=1097572368;start=1#1

Now, what I found is:

1.  The imports for Attributes, Params, Method returns are returned found by the importClassName and importPackageName field substitution macros are empty. So no imports are generated for these.

2.   The packagePath field substitution macro I use in the Import template is set to 'com'.  I expected it to be 'com.xxx.yyy'.  This causes imports to be created for classes in the same package as the class that is being generated.

Here are the templates I'm using. Please note that I modified the aforementioned solution to debug.

ImportSection
Code: [Select]
$COMMENT="WARNING: THIS IS AN ADVANCED TEMPLATE"
$COMMENT="DO NOT MODIFY UNLESS YOU ARE AN"
$COMMENT="ADVANCED USER!"
%if packagePath != "" and packagePath != "." and packagePath != ".\\"%
package %packagePath%;\n
%endIf%
$imports = %fileImports%
$imports += "\n" + %list="Import" @separator="\n" importFromAggregation=="T" or importFromAssociation=="T" or importFromAtt=="T" or importFromDependency=="T" or importFromGeneralization=="T" or importFromMeth=="T" or importFromParam=="T" or importFromRealization=="T"%
$imports


Import
Code: [Select]
importPackage is: %importPackagePath%
package is: %packagePath%
importClass is: %importClassName%
%if importInFile!="T" and importPackagePath!="" and importPackagePath!=packagePath%
import %importPackagePath%.%importClassName%;
%endIf%


I've tried these templates on two different models and found the same results.

Thanks,

Dave

dabeita

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Problem creating Java imports
« Reply #1 on: February 25, 2005, 02:11:08 pm »
Additionally,  I did verify that the classes which were suppose to be imported are present in the Model.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Problem creating Java imports
« Reply #2 on: February 27, 2005, 01:28:17 pm »
1. This is a bug in the current build of EA that will be fixed for build 749.

2. This problem makes me think that you are generating Java with the language set to something other than "Java".  If that's the case you'll need to list over the namespaces to get the correct package path.

I think that it should be something like this.

File
Code: [Select]
%list="Namespace" @separator=""%
Namespace
Code: [Select]
%list="Namespace" @separator=""%
%if packageHasGenClasses == "T"%
%ImportSection%
%list="Class" @separator="\n\n"%
%endIf%

I could be wrong and your second problem could be something else, I thought that this could help sooner though.

Simon

dabeita

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Problem creating Java imports
« Reply #3 on: February 27, 2005, 07:50:54 pm »
Simon,

Thanks for the info regarding the bug.  When will 749 be available?

I tried your solution for the second problem and it worked.  :)   I did look at the at my language selection and found that everything was set to Java (my default language is set to Java).  So, I'm not sure what else could be the issue.

Our package structure looks something like this:









java
com
company
products
product_a
common
entity_x


The namespace root is set at the 'java' package level.  The classes we create are under the product_a or entity_x levels.  So, when we generate we right mouse on the product_a or entity_x level and generate all class under the selected level.  Is there something more we should have in our model for the parent levels of product_a or entity_x?


Dave