Generic Aspects Problem - The method ... from the type ... refers to the missing type ... [message #1707812] |
Wed, 09 September 2015 13:49 |
Bogdan Va Messages: 2 Registered: September 2015 |
Junior Member |
|
|
Hi all,
//Short story
I have a problem that's been bugging me for a relatively long time, and, as mentioned in the title, refers to Generic Aspects.
More specifically, when I use an ITD method, I get in eclipse the error "The method ... from the type ... refers to the missing type ...". The code compiles with some warnings, but it works in the end.
I have the same problem even if I use Java 7, AspectJ 1.8.1 or older and eclipse Kepler or Mars... in any combination .
Do you have any advices for me on how I could make that error disappear?
//Loooooooong story
In my projects I need to implement an aspect similar to the one described here (ParentChildRelationship)
I define an interface for the child:
@SuppressWarnings("rawtypes")
public interface ChildHasParent<PARENT extends ParentHasChildren> {
int getCategoryId();
void setCategoryId(int categoryId);
PARENT getParent();
void setParent(PARENT entity);
}
... and one for the parent:
@SuppressWarnings("rawtypes")
public static interface ParentHasChildren<CHILD extends ChildHasParent> {
public void addChild(CHILD child);
public Class<CHILD> getChildrenClass();
public Set<CHILD> getChildren();
public CHILD getChild(Integer categoryId);
public void setChildren(Set<CHILD> children);
}
.. which will be injected in the selected objects.
These interfaces are defined in the following aspect:
public abstract aspect TranslatableDefaultImpl<PARENT, CHILD> {
I inject the function definitions for the parent in the following way:
private java.util.Set<C> ParentHasChildren<C>.children;
...
public void ParentHasChildren<C>.addChild(C child) {
Set<C> children = this.getChildren();
if(children == null) {
children = new HashSet<C>();
setChildren(children);
}
children.add(child);
}
public java.util.Set<C> ParentHasChildren<C>.getChildren() {
return this.children;
}
public void ParentHasChildren<C>.setChildren(java.util.Set<C> children) {
this.children = children;
}
...
I apply the aspect on two classes:
Parent : Ent_Language
Child : Ent_LanguageTr
public aspect Ent_LanguageTranslatableDefaultImpl extends TranslatableDefaultImpl<Ent_Language, Ent_LanguageTr> {
declare parents: Ent_Language implements ParentHasChildren<Ent_LanguageTr>;
declare parents: Ent_LanguageTr implements ChildHasParent<Ent_Language>;
...
}
When I open Ent_LanguageTest in the editor, Eclipse reports the error "The method getChildren() from the type Ent_Language refers to the missing type CHILD" on the parent.getChildren() call, but NOT on parent.addChild(tr1):
Ent_Language parent = new Ent_Language();
Ent_LanguageTr tr1 = new Ent_LanguageTr();
Ent_LanguageTr tr2 = new Ent_LanguageTr();
Assert.assertNull( parent.getChildren() );// ERROR
parent.addChild(tr1);//OK
parent.addChild(tr2);//OK
Assert.assertNotNull( parent.getChildren() );//ERROR
Assert.assertTrue( parent.getChildren().size() == 2 );//ERROR
I would say that CHILD should never appear in the classes definitions, because I understand that in the case of abstract aspects it serves as a placeholder...
//Project setup
You can download the test project from the attachment.
I currently have the following system setup:
Windows 7 x64
JDK 1.8.0_60
Eclipse STS 3.7.0 , x64
Maven 3.2.3
AspectJ 1.8.6 (defined in pom)
I have created a simplified test project, from which I eliminated all other aspects and classes/interfaces, which I attached to this message.
In order to import the project in eclipse, I use the maven-eclipse-plugin to generate the project settings, by running mvn eclipse:eclipse. After that the project can be imported in eclipse with "Import existing projects into workspace" (not import Maven project)
It would be great if you could test it on your machine.
Or please tell me what should I do to help solve this problem faster.
Thank you in advance for your time and support,
Bogdan
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04702 seconds