Skip to main content



      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 17:00 Go to next message
Eclipse UserFriend
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 18:03 Go to previous messageGo to next message
Eclipse UserFriend
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)
   				}
   			])
   	}
}

[Updated on: Fri, 20 December 2013 18:04] by Moderator

Re: Invalid 'import is never used' warning for annotations [message #1222845 is a reply to message #1222622] Sat, 21 December 2013 10:39 Go to previous messageGo to next message
Eclipse UserFriend
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 10:58] by Moderator

Re: Invalid 'import is never used' warning for annotations [message #1222861 is a reply to message #1222845] Sat, 21 December 2013 11:44 Go to previous messageGo to next message
Eclipse UserFriend
can you please file a bug
Re: Invalid 'import is never used' warning for annotations [message #1225999 is a reply to message #1222861] Tue, 31 December 2013 06:27 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 16:21:56 EDT 2025

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

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

Back to the top