Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Invalid 'import is never used' warning for annotations
Invalid 'import is never used' warning for annotations [message #1222605] Fri, 20 December 2013 22:00 Go to next message
Michel de Blok is currently offline Michel de BlokFriend
Messages: 8
Registered: August 2013
Junior Member
Hi all,

I'm using XText 2.5, extending the XbaseWithAnnotations grammar, and I have a list of annotations on my elements using:

annotations+=XAnnotation*


This works fine, and XBase auto-imports the annotations nicely, but the DSL editor always shows the warning "The import 'xxx' is never used." for the imported annotation in my model file. And if I organize the imports, the annotation import is removed and my model contains an error (couldn't resolve reference to the annotation).

How can I tell XBase that the import is actually used and should not be removed? And why isn't this recognized automatically?

I do map the XAnnotation elements to a JvmAnnotationReference in my JvmModelInferrer with:

annotations.translateAnnotationsTo(it)


The organize imports function works properly for other imported JvmTypes, like classes that are imported and extended in my model, but only for annotations it seems that XBase never 'sees' that the annotations are being used.

Does anyone else have this problem and solved it?

Regards,
MdB


Re: Invalid 'import is never used' warning for annotations [message #1222622 is a reply to message #1222605] Fri, 20 December 2013 23:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13666
Registered: July 2009
Senior Member
Hi,

i acutually cannot reproduce that.
can you share a reproduceable grammar?

here is mine

grammar org.xtext.example.mydsl2.MyDsl with org.eclipse.xtext.xbase.annotations.XbaseWithAnnotations

generate myDsl "http://www.xtext.org/example/mydsl2/MyDsl"

Model:
	i=XImportSection
	greetings+=Greeting*;

	
Greeting:
	annos+=XAnnotation*
	'Hello' name=ID '!';


class MyDslJvmModelInferrer extends AbstractModelInferrer {
	@Inject extension JvmTypesBuilder
   	def dispatch void infer(Model element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
   		acceptor.accept(element.toClass("my.company.greeting.MyGreetings"))
   			.initializeLater([
   				for (greeting : element.greetings) {
   					val m = greeting.toMethod("hello" + greeting.name, greeting.newTypeRef(typeof(String))) [
   						body = [
   							append('''return "Hello Ā«greeting.nameĀ»";''')
   						]
   					]
   					members += m
   					greeting.annos.translateAnnotationsTo(m)
   				}
   			])
   	}
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 20 December 2013 23:04]

Report message to a moderator

Re: Invalid 'import is never used' warning for annotations [message #1222845 is a reply to message #1222622] Sat, 21 December 2013 15:39 Go to previous messageGo to next message
Michel de Blok is currently offline Michel de BlokFriend
Messages: 8
Registered: August 2013
Junior Member
Hi,

your sample works fine for me too, no unused import issues there.
However, if I use the following grammar:

grammar org.xtext.example.mydsl2.MyDsl with org.eclipse.xtext.xbase.annotations.XbaseWithAnnotations

generate myDsl "http://www.xtext.org/example/mydsl2/MyDsl"

Model:
	importSection=XImportSection?
	packages+=PackageDeclaration*
;
PackageDeclaration: {PackageDeclaration} (
    'package' name=QualifiedName '{'
	elements+=AnnotatedElement*
    '}'
)
;
AnnotatedElement:
	annotations+=XAnnotation*
	target=AbstractElement
;
AbstractElement:
	ElementA | ElementB
;
ElementA:
	'elementA' name=ValidID
;
ElementB:
	'elementB' name=ValidID
;


And the following inferrer:
class MyDslJvmModelInferrer extends AbstractModelInferrer {

	@Inject extension JvmTypesBuilder
	@Inject extension IQualifiedNameProvider

	def dispatch void infer(AbstractElement element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
		acceptor.accept(element.toClass(element.fullyQualifiedName)).initializeLater(
			[
				(element.eContainer as AnnotatedElement).annotations.translateAnnotationsTo(it)
			])
	}
}


With the following model:

import javax.persistence.Entity
import javax.jws.WebService

package my.domain {
	
	@WebService
	elementA TestA
	
	@Entity
	elementB TestB
}


Then both imports have the "unused import" warning, although they are used by both the model and the generated Java code.

And if I do an "organize imports" on this model, then the @WebService annotation import is removed and the @Entity annotation import is not removed (?)

[Updated on: Sat, 21 December 2013 15:58]

Report message to a moderator

Re: Invalid 'import is never used' warning for annotations [message #1222861 is a reply to message #1222845] Sat, 21 December 2013 16:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13666
Registered: July 2009
Senior Member
can you please file a bug

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Invalid 'import is never used' warning for annotations [message #1225999 is a reply to message #1222861] Tue, 31 December 2013 11:27 Go to previous message
Michel de Blok is currently offline Michel de BlokFriend
Messages: 8
Registered: August 2013
Junior Member
It's now registered as the following bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=424775
Previous Topic:jar in Editor-Plugin
Next Topic:ANTLR replacement
Goto Forum:
  


Current Time: Tue Dec 01 17:56:13 GMT 2020

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

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

Back to the top