Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtend2 fails initializing String[](Xtend2 fails initializing String[])
Xtend2 fails initializing String[] [message #967443] Thu, 01 November 2012 19:22 Go to next message
Michael Veit is currently offline Michael VeitFriend
Messages: 12
Registered: January 2012
Junior Member
Hello,

When initalizing a String[] in Xtend 2 (using Xtext 2.3.1), Eclipse does not compile.
Using the org.eclipse.xtext.example.domainmodel.tests, I added some simple lines of code to ComplierTest.xtend in order to isolate the problem.
The syntax which causes the problem:
import org.eclipse.emf.common.util.BasicEList
[...]
val test = new BasicEList<String>
test.addAll({'bla'})

However, running with addAll():
val test = new BasicEList<String>
var arr = 'a,b,c'.split(',')
test.addAll(arr)
val arr2 = {'bla2'}
test.addAll(arr2)

The behavior is quite frustating, because it took a very long time until I found the problem. No error message is shown in the Eclipse GUI. The Java class is missing in the xtend-gen folder, and building the workspace does not show "100%" when having such an array initializer.
The Eclipse log file shows:
!ENTRY org.apache.log4j 4 0 2012-11-01 20:07:23.328
!MESSAGE org.eclipse.xtext.builder.impl.XtextBuilder  - JvmSynonymTypeReference: JvmGenericArrayTypeReference: java.lang.String[] | JvmDelegateTypeReference: JvmParameterizedTypeReference: java.lang.String

!STACK 0
java.lang.IllegalArgumentException: JvmSynonymTypeReference: JvmGenericArrayTypeReference: java.lang.String[] | JvmDelegateTypeReference: JvmParameterizedTypeReference: java.lang.String
	at org.eclipse.xtext.xbase.compiler.TypeReferenceSerializer.serialize(TypeReferenceSerializer.java:171)
	at org.eclipse.xtext.xbase.compiler.TypeReferenceSerializer.serialize(TypeReferenceSerializer.java:154)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.compileAsJavaExpression(AbstractXbaseCompiler.java:140)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.appendArgument(FeatureCallCompiler.java:800)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.appendArguments(FeatureCallCompiler.java:768)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.appendFeatureCall(FeatureCallCompiler.java:710)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.featureCalltoJavaExpression(FeatureCallCompiler.java:267)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler._toJavaStatement(FeatureCallCompiler.java:135)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.doInternalToJavaStatement(FeatureCallCompiler.java:113)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.doInternalToJavaStatement(XbaseCompiler.java:127)
	at org.eclipse.xtend.core.compiler.XtendCompiler.doInternalToJavaStatement(XtendCompiler.java:308)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:289)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler._toJavaStatement(XbaseCompiler.java:152)
[...]

I assume this is a bug.
Either the syntax should be forbidden and cause error messages in the Eclipse GUI, or the compilation should be able to handle this syntax (which was ported from Xtend1 to Xtend2 without changes):
bo.attributes != null ? setAttributes({bo.attributes}) : null
  //converted to
if (bo.attributes != null) setAttributes({bo.attributes})

An hidden error message without telling me the problem isn't a good thing... Confused

[Updated on: Thu, 01 November 2012 19:24]

Report message to a moderator

Re: Xtend2 fails initializing String[] [message #967453 is a reply to message #967443] Thu, 01 November 2012 19:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi

{} is a block and not a literal for a list or array.

~Christian
Re: Xtend2 fails initializing String[] [message #967624 is a reply to message #967443] Thu, 01 November 2012 22:35 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 2961
Registered: July 2009
Senior Member
Michael,

Christian is right, {} is not the notation for arrays. However, the
exception is a bug. Could you please file a ticket. Thanks.

Best regards,
Sebastian

Am 01.11.12 20:22, schrieb Michael Veit:
> Hello,
>
> When initalizing a String[] in Xtend 2 (using Xtext 2.3.1), Eclipse does
> not compile.
> Using the org.eclipse.xtext.example.domainmodel.tests, I added some
> simple lines of code to ComplierTest.xtend in order to isolate the problem.
> The syntax which causes the problem:
> test.addAll({'bla'})
> However, running with addAll():
> var arr = 'a,b,c'.split(',')
> test.addAll(arr)
> val arr2 = {'bla2'}
> test.addAll(arr2)
>
> The behavior is quite frustating, because it took a very long time until
> I found the problem. No error message is shown in the Eclipse GUI. The
> Java class is missing in the xtend-gen folder, and building the
> workspace does not show "100%" when having such an array initializer.
> The Eclipse log file shows:
> !ENTRY org.apache.log4j 4 0 2012-11-01 20:07:23.328
> !MESSAGE org.eclipse.xtext.builder.impl.XtextBuilder -
> JvmSynonymTypeReference: JvmGenericArrayTypeReference:
> java.lang.String[] | JvmDelegateTypeReference:
> JvmParameterizedTypeReference: java.lang.String
>
> !STACK 0
> java.lang.IllegalArgumentException: JvmSynonymTypeReference:
> JvmGenericArrayTypeReference: java.lang.String[] |
> JvmDelegateTypeReference: JvmParameterizedTypeReference: java.lang.String
> at
> org.eclipse.xtext.xbase.compiler.TypeReferenceSerializer.serialize(TypeReferenceSerializer.java:171)
>
> at
> org.eclipse.xtext.xbase.compiler.TypeReferenceSerializer.serialize(TypeReferenceSerializer.java:154)
>
> at
> org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.compileAsJavaExpression(AbstractXbaseCompiler.java:140)
>
> at
> org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.appendArgument(FeatureCallCompiler.java:800)
>
> at
> org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.appendArguments(FeatureCallCompiler.java:768)
>
> at
> org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.appendFeatureCall(FeatureCallCompiler.java:710)
>
> at
> org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.featureCalltoJavaExpression(FeatureCallCompiler.java:267)
>
> at
> org.eclipse.xtext.xbase.compiler.FeatureCallCompiler._toJavaStatement(FeatureCallCompiler.java:135)
>
> at
> org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.doInternalToJavaStatement(FeatureCallCompiler.java:113)
>
> at
> org.eclipse.xtext.xbase.compiler.XbaseCompiler.doInternalToJavaStatement(XbaseCompiler.java:127)
>
> at
> org.eclipse.xtend.core.compiler.XtendCompiler.doInternalToJavaStatement(XtendCompiler.java:308)
>
> at
> org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:289)
>
> at
> org.eclipse.xtext.xbase.compiler.XbaseCompiler._toJavaStatement(XbaseCompiler.java:152)
>
> [...]
>
> I assume this is a bug.
> Either the syntax should be forbidden and cause error messages in the
> Eclipse GUI, or the compilation should be able to handle this syntax
> (which was ported from Xtend1 to Xtend2 without changes):
> bo.attributes != null ? setAttributes({bo.attributes}) : null
> //converted to
> if (bo.attributes != null) setAttributes({bo.attributes})
>
> An hidden error message without telling me the problem isn't a good
> thing... :?
Re: Xtend2 fails initializing String[] [message #968051 is a reply to message #967624] Fri, 02 November 2012 06:57 Go to previous messageGo to next message
Michael Veit is currently offline Michael VeitFriend
Messages: 12
Registered: January 2012
Junior Member
As {} is not allowed for String[] initialization, two questions:

1) Why did the behaviour change from Xtend1 (allowed) to Xtend2 (not allowed)?
2) Why does it work when using the initializer standalone like:
      var test = new BasicEList<String>
      val arr2 = {'bla2'}
      test.addAll(arr2)
      assertEquals(1, test.size)

[Updated on: Fri, 02 November 2012 06:58]

Report message to a moderator

Re: Xtend2 fails initializing String[] [message #968203 is a reply to message #968051] Fri, 02 November 2012 09:28 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi

(1) i guess the answer is: we need real blocks
the replacement is newArrayList("A","B","C")

(2) it does work through some extension magic (org.eclipse.xtext.xbase.lib.CollectionExtensions.addAll(Collection<? super T>, T...))
and not java.util.List.addAll
Previous Topic:New to Xtext Grammar help
Next Topic:Getting an element from a list by name in Xtend
Goto Forum:
  


Current Time: Sun Dec 21 18:00:13 GMT 2014

Powered by FUDForum. Page generated in 0.04235 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software