Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Help: annotation introduction not working

I'm using the ant task iajc to achieve some binary weaving of .class
files, where I want to introduce not only fields and methods but also
class-level annotations.

The iajc compiler is emitting messages that say that it is adding the
annotations, but when I decompile or use reflection against the woven
classes, there are none on the class.

Anyone know why this might be happening?

Here is my iajc invocation (run from within maven-antrun-plugin):
<iajc destDir="${project.build.outputDirectory}" source="1.6"
	target="1.6" debug="true" preserveAllLocals="true"
	showWeaveInfo="true" verbose="true" classpathref="cp" noimporterror="false">
	<sourceroots>
		<pathelement location="${project.build.sourceDirectory}" />
		<pathelement location="${project.build.sourceDirectory}/../aspect" />
	</sourceroots>
	<inpath>
		<pathelement location="${resource.entity.source.classes.path}" />
	</inpath>
</iajc>

Above, classpathref cp evaluates to a path that is
maven.compile.classpath, and resource.entity.source.classes.path is
the directory containing the .class files that I'm trying to weave.

The ajc compiler says (package names abbreviated with "org...." to
protect the innocent):
     [iajc] ajc [-source, 1.6, -verbose, -target, 1.6, -g, -d,
C:\dev\ECO\svn\trunk\case\case-rest-resource-entity\target\classes,
-showWeaveInfo, -preserveAllLocals, -classpath, ...
     ...
     [iajc] info Pipelining compilation
     ...
     [iajc] info weaver operating in reweavable mode.  Need to verify
any required types exist.
     ...
     [iajc] weaveinfo 'org.....rest.entity.Person' (Person.java) is
annotated with @XmlRootElement type annotation from
'org.....rest.entity.aspects.RestResourceEntityMixin'
(RestResourceEntityMixin.aj:14)
     [iajc] weaveinfo 'org.....rest.entity.Person' (Person.java) is
annotated with @Generated type annotation from
'org.....rest.entity.aspects.RestResourceEntityMixin'
(RestResourceEntityMixin.aj:13)
     [iajc] weaveinfo 'org.....rest.entity.User' (User.java) is
annotated with @XmlRootElement type annotation from
'org.....rest.entity.aspects.RestResourceEntityMixin'
(RestResourceEntityMixin.aj:14)
     [iajc] weaveinfo 'org.....rest.entity.User' (User.java) is
annotated with @Generated type annotation from
'org.....rest.entity.aspects.RestResourceEntityMixin'
(RestResourceEntityMixin.aj:13)

Below is the aspect that's being applied.  Note interestingly that
while the @Generated and @XmlRootElements don't appear in the final
woven .class file, the introduced fields and methods actually do show
up.

import org.....rest.entity.annotations.Generated;
import javax.xml.bind.annotation.XmlRootElement;

public aspect RestResourceEntityMixin {

	public static interface Introduced {}
	
	declare @type: (org.....rest.entity.*) : @Generated;
	declare @type: (org.....rest.entity.*) : @XmlRootElement;
	
	declare parents: (@Generated *) implements Introduced;
	
	private String Introduced.etag;
	private String Introduced.href;
	
	public String Introduced.getEtag() {
		return etag;
	}
	public void Introduced.setEtag(String etag) {
		this.etag = etag;
	}
	
	public String Introduced.getHref() {
		return href;
	}
	public void Introduced.setHref(String href) {
		this.href = href;
	}
}

Can anyone help?

Thanks,
Matthew


Back to the top