Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [xbase] how to define an array(How to write "new Object [] { this }" in xbase)
[xbase] how to define an array [message #901235] Fri, 10 August 2012 13:00 Go to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Hello

the question I am asking here has it's roots in the following discussion concerning xcore: http://www.eclipse.org/forums/index.php/mv/msg/367759/901193/#msg_901193

How can I write "new Object [] { this }" in xbase? Or more abstract: How can static arrays be declared in xbase?

Thanks for your help!

Greetings
Christoph
Re: [xbase] how to define an array [message #901254 is a reply to message #901235] Fri, 10 August 2012 13:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13359
Registered: July 2009
Senior Member
Hi afaik Xbase does not support array literals but it supports auto
boxing com list to array and vice versa so you won't need and extra
literal for arrays.

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [xbase] how to define an array [message #901259 is a reply to message #901254] Fri, 10 August 2012 14:04 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
so this would be the recommended way?
val List<Object> list = new ArrayList
list.add(this)
Re: [xbase] how to define an array [message #901261 is a reply to message #901259] Fri, 10 August 2012 14:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13359
Registered: July 2009
Senior Member
No: newArrayList(this)

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [xbase] how to define an array [message #901370 is a reply to message #901261] Sat, 11 August 2012 15:54 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
thanks! Is it possible to pass multiple arguments? I. e.
val List<String> list = new ArrayList("one", "two", "three")
Re: [xbase] how to define an array [message #901371 is a reply to message #901261] Sat, 11 August 2012 15:59 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
[quote title=Christian Dietrich wrote on Fri, 10 August 2012 16:07]
> No: newArrayList(this)

Unfortunately, this doesn't work in xcore. This is the error message:
Multiple markers at this line
- Missig error message for org.eclipse.xtext.xbase.validation.IssueCodes.invalid_generic_argument_types
- Incompatible types. Expected java.util.Collection<? extends
   E> or E[] but was de.emsw.model.company.CompanyElement
Re: [xbase] how to define an array [message #901373 is a reply to message #901371] Sat, 11 August 2012 16:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13359
Registered: July 2009
Senior Member
Then try to type the collection
newArrayList("a","b","c")
should work as well.

can you post a complete reproducable xcore file?
maybe <E>newArrayList(this) or something like that will work but since i do not know what you try to
do hard to say.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [xbase] how to define an array [message #901407 is a reply to message #901373] Sat, 11 August 2012 22:28 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Hi Christian,

here is my test code. The experiment was to introduce an invariant on a class in score. The error arrises in line 18.
package de.emsw.model.company

import org.eclipse.emf.ecore.EDiagnosticChain
import org.eclipse.emf.ecore.EMap
import org.eclipse.emf.common.util.BasicDiagnostic
import org.eclipse.emf.common.util.Diagnostic
import java.util.ArrayList

class CompanyElement {
	String name
	String comment
	op boolean hasName(EDiagnosticChain diagnostics, EMap<Object, Object> context) {
		if (name == null || name == "") {
			if (diagnostics != null) {
				diagnostics.add(new BasicDiagnostic(Diagnostic::ERROR,
					"de.emsw.model.company", //CompanyValidator::DIAGNOSTIC_SOURCE,
					0, //CompanyValidator::COMPANY_ELEMENT__HAS_NAME,
					"The name may not be emtpy.",
					new ArrayList<Object>(this)))
			}
		} else true
	}
}

Eclipse Build id: 20120614-1722
EMF Version: 2.8.0.v20120608-0554
XCore Version: 1.0.0.v20120612-0950

Greetings
Christoph
Re: [xbase] how to define an array [message #901429 is a reply to message #901407] Sun, 12 August 2012 06:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13359
Registered: July 2009
Senior Member
Hi,

seems you never did what i asked you to do

	String name
	String comment
	op boolean hasName(EDiagnosticChain diagnostics, EMap<Object, Object> context) {
		if (name == null || name == "") {
			if (diagnostics != null) {
				diagnostics.add(new BasicDiagnostic(Diagnostic::ERROR,
					"de.emsw.model.company", //CompanyValidator::DIAGNOSTIC_SOURCE,
					0, //CompanyValidator::COMPANY_ELEMENT__HAS_NAME,
					"The name may not be emtpy.",
					<Object>newArrayList(this)))
			}
		} else true
	}
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [xbase] how to define an array [message #901435 is a reply to message #901429] Sun, 12 August 2012 10:33 Go to previous message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Hi Christian,

now I see it! Thanks for the insight Smile. I didn't know about CollectionLiterals.

Greetings
Christoph
Previous Topic:Content assist and validation
Next Topic:Overloaded/ambiguous matching
Goto Forum:
  


Current Time: Sat Feb 22 22:01:35 GMT 2020

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

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

Back to the top