|
Re: Adding API to access ImportManager or to add imports to ITreeAppendable [message #961538 is a reply to message #949670] |
Sun, 28 October 2012 11:00 |
|
On 10/19/2012 09:15 AM, Alexey Romanov wrote:
> Compared to ugly code like (from
> http://www.eclipse.org/forums/index.php/t/262321/):
>
> @Inject extension TypeReferenceSerializer
>
> ..
>
> f.toField(name, type) [
> val Procedure1<ITreeAppendable> proc = [
> append('''new ''')
> newTypeRef('java.util.BitSet').serialize(f,it)
> append('''(«dataDef.fields.size»)''')
> ]
> initializer = proc
> ]
>
> I'd prefer to write
>
> f.toField(name, type) [
> val Procedure1<ITreeAppendable> proc = [
> addImport(newTypeRef('java.util.BitSet').type)
> append('''new BitSet(«dataDef.fields.size»)''')
> ]
> initializer = proc
> ]
>
> The obvious problem is breaking user-defined classes implementing
> ITreeAppendable, but I am not sure if people do this in practice. Of
> course, after I wrote it, I saw that this problem could be solved by
> creating my own class extending TreeAppendable, and overriding
> JvmModelGenerator.createAppendable to return it... So is it worth filing
> a bug for it?
the appendable supports append of JvmType, so you could write
f.toField(name, type) [
val Procedure1<ITreeAppendable> proc = [
append('''new ''')
append(newTypeRef('java.util.BitSet').type)
append('''(«dataDef.fields.size»)''')
]
initializer = proc
]
without using the serializer... which might be less ugly?
from what I understand about the appendable and import manager, using
f.toField(name, type) [
val Procedure1<ITreeAppendable> proc = [
addImport(newTypeRef('java.util.BitSet').type)
append('''new BitSet(«dataDef.fields.size»)''')
]
initializer = proc
]
would still not be safe, since the "BitSet" you write in append('''new
BitSet(«dataDef.fields.size»)''') would not ensure that the string
"BitSet" is actually referred to the type ref java.util.BitSet (and
possible ambiguities would not be handled transparently by the
ImportManager).
somehow, the append of a type in the appendable should still be done NOT
as a string, but as a JvmType so that the ImportManager can deal with
that... at least that's how I understand it works
hope that helps
cheers
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03789 seconds