Skip to main content



      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 09:00 Go to next message
Eclipse UserFriend
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 09:59 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: [xbase] how to define an array [message #901259 is a reply to message #901254] Fri, 10 August 2012 10:04 Go to previous messageGo to next message
Eclipse UserFriend
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 10:07 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: [xbase] how to define an array [message #901370 is a reply to message #901261] Sat, 11 August 2012 11:54 Go to previous messageGo to next message
Eclipse UserFriend
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 11:59 Go to previous messageGo to next message
Eclipse UserFriend
[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 12:18 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: [xbase] how to define an array [message #901407 is a reply to message #901373] Sat, 11 August 2012 18:28 Go to previous messageGo to next message
Eclipse UserFriend
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 02:30 Go to previous messageGo to next message
Eclipse UserFriend
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
	}
}
Re: [xbase] how to define an array [message #901435 is a reply to message #901429] Sun, 12 August 2012 06:33 Go to previous message
Eclipse UserFriend
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: Mon Jul 07 18:34:23 EDT 2025

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

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

Back to the top