Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » infer jvmType from referenced Objects(when I infer Types from referenced Objects the typeRef does not work)
infer jvmType from referenced Objects [message #1807533] Sat, 01 June 2019 18:34
Peter Luthardt is currently offline Peter LuthardtFriend
Messages: 43
Registered: February 2014
Member
I want to create JvmTypes from referenced objects, but I run into problems when I create JvmTypeReferences.
I added a small test project.
grammar siemens.lutte.test.Multifile with org.eclipse.xtext.xbase.annotations.XbaseWithAnnotations

generate multifile "http://www.lutte.siemens/test/Multifile"

Model:
	'package' name = QualifiedName
	content = Content;

Content:
	Entity | DaoImport
;

Entity:
	'entity' name=ValidID
	'{'
		fields += Field*
	'}'
;

DaoImport:
	{DaoImport} 'DaoImport'
	'{'
		('import' imports += [Entity|QualifiedName])*
	'}'
;

Field:
	'val' type=JvmParameterizedTypeReference name=ValidID
;


Quote:
package siemens.lutte.test.jvmmodel

import com.google.inject.Inject
import org.eclipse.xtext.common.types.TypesFactory
import org.eclipse.xtext.naming.IQualifiedNameProvider
import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer
import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor
import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder
import siemens.lutte.test.multifile.DaoImport
import siemens.lutte.test.multifile.Entity

class MultifileJvmModelInferrer extends AbstractModelInferrer {


@Inject extension JvmTypesBuilder
@Inject extension IQualifiedNameProvider
@Inject TypesFactory typesFactory


def dispatch void infer(Entity entity , IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
println("createEntity: "+entity.name)
acceptor.accept(entity.toClass(entity.fullyQualifiedName.toString))[
entity.fields.forEach[f|
members += f.toField(f.name, f.type)
]
]
}

def dispatch void infer(DaoImport daoImport, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
daoImport.imports.forEach[entity|
println("createEntityDao: "+entity.name)
acceptor.accept(entity.toClass(entity.fullyQualifiedName.toString+"Dao"))[
val generic = typesFactory.createJvmTypeParameter =>[
name = "T"
constraints += typesFactory.createJvmUpperBound => [
typeReference = typeRef(entity.fullyQualifiedName.toString).cloneWithProxies
]
]
typeParameters += generic
]
]
daoImport.imports.forEach[entity|
println("createEntityDao2: "+entity.name)
acceptor.accept(entity.toClass(entity.fullyQualifiedName.toString+"Dao2"))[
superTypes += typeRef(entity.fullyQualifiedName.toString+"Dao", typeRef(entity.fullyQualifiedName.toString))
]
]
}
}

	@Test
	def void loadModel() {
		val resourceSet = resourceSetProvider.get
		resourceSet.classpathURIContext = this
		val entity = parse('''
			package test
			entity Test
			{
				val String str
			}
		''', URI.createURI("test/Test.mydsl"), resourceSet)
		entity.assertNoIssues

		val daoImport = parse('''
			package test
			DaoImport
			{
				import test.Test
			}
		'''.toString.remove("\r"), URI.createURI("test/DaoImp.mydsl"), resourceSet)
		daoImport.assertNoIssues

        val fsa = new InMemoryFileSystemAccess()
        resourceSet.resources.immutableCopy.forEach[resource|
	        generator.doGenerate(resource, fsa)
		]

        val testDao2 = fsa.textFiles.get("DEFAULT_OUTPUTtest/TestDao2.java").toString;
		assertEquals('''package test;

@SuppressWarnings("all")
public class TestDao2 implements test.TestDao<Test> {
}
'''.toString, testDao2)
	}


I am sorry but I can not explain the problem in more detail, but if you could tell me why my test fails it would help a lot.

Thank you.
Previous Topic:Code Mining with Embedded Editor
Next Topic:Release of Xtext & Xtend 2.18
Goto Forum:
  


Current Time: Tue Aug 20 23:01:50 GMT 2019

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

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

Back to the top