Generate types in different packages from one ".xtend" file and partial classes

56 views
Skip to first unread message

kirstenk...@gmail.com

unread,
Jul 26, 2015, 10:01:31 AM7/26/15
to Xtend Programming Language
Hi,

I love the approach of separation of concerns and keeping related stuff keep together, even if the natural type hierarchy would prevent this.

Therefore, I wanna ask, if the following features have been analyzed in context of Xtend already. Might be, that you have strong agrument against these ideas, might be, that this question has been asked before, might be, that you already thought about it... IMHO it would be great feature and I would love Xtend even more. So, thanks for your answer in advance.




Generate types in different packages from one ".xtend" file

I can put several classes, interfaces, annotations etc. in one file. However, it is not possible to allow the code generation within different packages. I can imagine different syntax, e.g.


sampleFile.xtend (Example 1 - absolute):

 
package root

 
class MyClass {}    // fully qualified "root.MyClass"
 
class MyClass2 {}   // fully qualified "root.MyClass2"

 
package root.sub

 
class MyClass3 {}    // fully qualified "root.sub.MyClass"



sampleFile.xtend (Example 2 - relative):

 
 
package root

 
class MyClass {}    // fully qualified "root.MyClass"
 
class MyClass2 {}   // fully qualified "root.MyClass2"

  subpackage
sub

 
class MyClass3 {}    // fully qualified "root.sub.MyClass"



sampleFile.xtend (Example 3 - syntax within class name):


 
package root

 
class MyClass {}    // fully qualified "root.MyClass"
 
class MyClass2 {}   // fully qualified "root.MyClass2"
 
class sub.MyClass3 {}    // fully qualified "root.sub.MyClass"






Partial Classes

Simply think about the feature in C#. I know that many people hate this feature, but I really miss that feature in Java in context of code generation and separation of concerns. So, why not adding it in Xtend?


sampleFile1.xtend (Example 1):


 
partial class MyClass {
    def void func1TypeA() {}
    def void func2TypeA() {}
   
def void func3TypeA() {}
  }



sampleFile2.xtend (Example 1):


 
partial class MyClass {
   
def void func1TypeB() {}
    def void func2TypeB() {}
   
def void func3TypeB() {}
 
}



MyClass.java (Example 1):


 
public class MyClass {
   
public void func1TypeA() {}
   
public void func2TypeA() {}
   
public void func3TypeA() {}
   
public void func1TypeB() {}
   
public void func2TypeB() {}
   
public void func3TypeB() {}
 
}



Sven Efftinge

unread,
Jul 26, 2015, 1:48:29 PM7/26/15
to xtend...@googlegroups.com
Hi,

the first should be easy to do and I don’t see a reason why we shouldn’t have it other that noone else asked for it so far :-)
I would certainly want to go with the not-so-fancy first example.

Partial classes are more involved and would complicate a couple of things (like affection detection). 
I don’t see enough value in adding this feature.

Cheers,
Sven

--
You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kirstenk...@gmail.com

unread,
Jul 26, 2015, 3:27:33 PM7/26/15
to Xtend Programming Language, efft...@itemis.de
Hi Sven,

it is clear to me, that partial classes are not that easy to realize.

I used this feature frequently back in my C# times and I really miss it in Java. Google returns many hits for Java and partial classes.
However, as I switched to Xtend for most of my code, I don't need a Java with this functionality. I consider this a higher level functionality, so exactly on level of Xtend.

There are several benefits, if one might decide to use partial classes (cp. https://en.wikipedia.org/wiki/Class_(computer_programming)#Partial). Code generation approaches often have problems in the world of Java, or they are more complex than necessary. Partial classes are very helpful here and facilitaty code generators. Eclipse seems to have myriads of MDA approaches... none really convinced me because of Java's lack of partial classes.
However, this is not the only need for partial classes. I currently have a complex type hierarchy in Java, so I dream of such a functionality. My goal is to put the hierarchy into one file with all the boilerplate code. In other files, I want to include other related aspects and the real code. Fortunately, I am using Xtend, which already helps a lot. For example, with active annotations I can already outsource some boilerplate code. Thanks for this great feature!

The bugzilla for Xtend is only for bugs? Is there a way I can enter my feature requests, vote and track them?
If not, thanks for your support, and hopefully the Xtend team/committers will search for new ideas soon and fall over my post ;)

Cheers,
Kirsten

Sven Efftinge

unread,
Jul 27, 2015, 3:04:22 AM7/27/15
to xtend...@googlegroups.com
Hi Kirsten,

we use the bugzilla also for enhancement requests. So please go ahead.
You can CC yourself on any ticket which counts as ‘interested’ :-)
You’ll be auto CCed as a creator.

Best regards,
Sven
Reply all
Reply to author
Forward
0 new messages