Closed GoogleCodeExporter closed 9 years ago
Are we certain this only applies in Eclipse? We should get to the root cause of
why generation is in certain cases different in Eclipse That should never be
the case, and hasn't in the past.
Original comment by TimothyCLethbridge
on 10 Sep 2014 at 12:39
[deleted comment]
[deleted comment]
Well, I compiled the code on the command line, and there were no package
statements generated, so the code generation is unchanged in this respect
(between eclipse and the command line). I figure this makes sense, since there
is only one umple file being compiled and all the files generated are in the
same directory, so compiling them on the command line there is no reason for
them to be in a specific package (but package statements are important in
eclipse, so they really should be generated).
However, there was a difference between the code generated in eclipse and the
code generated on the command line. When I put a main method in one of the
umple classes, an UncaughtExceptionHandler static inner class is generated in
the java code; in eclipse, there is an extra terminating } before the
UncaughtExceptionHandler is declared (Alexi and I ran into this problem before,
we talked about it in our logs for September 9th). Also, in the main method,
the UncaughtExceptionHandler is initialized incorrectly:
Code generated in eclipse:
public static void main(String [] args){
Thread.currentThread().setUncaughtExceptionHandler(new .Pair.UmpleExceptionHandler());
Thread.setDefaultUncaughtExceptionHandler(new .Pair.UmpleExceptionHandler());
The class is Pair.java, but I'm not sure why the class name is included. Also,
the . in front of Pair causes the file not to compile. I would imagine the
package name would fit in front of here (i.e.
packageName.Pair.UmpleExceptionHandler()) but it isn't added - maybe this is
linked to the problem of the package statements not being added.
Code generated on the command line:
public static void main(String [] args){
Thread.currentThread().setUncaughtExceptionHandler(new UmpleExceptionHandler());
Thread.setDefaultUncaughtExceptionHandler(new UmpleExceptionHandler());
I am not sure what causes the difference between the generated codes but I'll
definitely keep looking into it.
Original comment by ellen.ar...@gmail.com
on 10 Sep 2014 at 7:51
It would be worth consulting with Geoffrey Guest (redeyedmars) about this,
since he was the one who originally injected the code that handles exceptions.
It is certainly strange that the code differs depending on where it is
generated, and the whole general issue needs resolving.
Original comment by TimothyCLethbridge
on 11 Sep 2014 at 4:47
An update on the initial problem of missing package statements:
I found that for the umple file to generate package statements it needs a
namespace command in the file.
For example, if the umple file has:
namespace test;
class X { }
Then a directory 'test' is created in the current directory, and X.java is
generated in this directory, with 'package test;' at the start of the file.
However, if no namespace command is included, the umple file doesn't generated
any package statements even if the umple file is in an eclipse package (not the
default package). Adding a namespace command with the same name as the current
directory makes a subdirectory so that the package statement in the java file
is still wrong.
i.e. f the umple file has
namespace test;
inside of the package 'test'
then the generated java files will have 'package test;' but will actually be
inside package test.test so this also results in a java compiler error.
At this point I still think it would be a good idea to have package statements
included if the umple is in a package in eclipse so that the generated code
will compile (even if the umple doesn't have a namespace command), but this
would mean treating code compiled via eclipse differently, and also figuring
out if the umple file is in a package. Let me know if you think this is a bad
idea...
I will continue looking at how to do this and also work on the exception code!
Original comment by ellen.ar...@gmail.com
on 11 Sep 2014 at 6:24
Ok, so I have discovered what seems to be the source of the problem - the
UmpleExceptionHandler is added to a file if it is the "mainMainClass" (in the
JavaClassGenerator). Regardless of how many files have main methods, there is
only one "mainMainClass", and all other files who need to reference the
UmpleExceptionHandler reference the static inner class in the mainMainClass.
The problem in eclipse is with mainMainClass -- even in a project where there
is only one class with a main method, the instances of UmpleExceptionHandler
(in the main method) reference the entire path to the class itself.
Then, since it is not considered the mainMainClass, it ends the class in a },
but then also adds the UmpleExceptionHandler.
This raises the question of how a class can be both the mainMainClass and not
the mainMainClass at the same time. I think the reason for this is due to the
mainMainClass not being reset to null in eclipse before something new is
compiled. For instance, the first time after eclipse that something is
compiled with a main method, there are no errors. But then, if that file is
recompiled, the error crops up again (reference to itself and extra } ).
I am trying to reset mainMainClass to null before a new set of files is
compiled.
As it is a public static variable in JavaClassGenerator, this can be done
globally from any file.
Original comment by ellen.ar...@gmail.com
on 19 Sep 2014 at 7:43
I fixed it! It was the mainMainClass variable not being reset to null before
compiling in eclipse. I reset this variable (JavaClassGenerator.mainMainClass
= null) in UmpleAction.java (in
cruise.umple.eclipse/src/cruise/umple/ui/eclipse/), in the run() method, before
anything else is called.
I have submitted a patch.
Original comment by ellen.ar...@gmail.com
on 20 Sep 2014 at 5:11
This issue was closed by revision r4491.
Original comment by TimothyCLethbridge
on 20 Sep 2014 at 11:12
Original issue reported on code.google.com by
ellen.ar...@gmail.com
on 9 Sep 2014 at 8:41