【发布时间】:2015-11-18 08:33:27
【问题描述】:
我对 Eclipse 和 AspectJ 有很烦人的问题。每次更改受方面影响的类后,我都需要进行完整的项目重建(清理)。 任何人都知道我该如何避免这种情况?
package pl.xxx.infrastructure.jdbc;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.DeclareParents;
import org.aspectj.lang.annotation.Pointcut;
import pl.xxx.infrastructure.jdbc.common.UpdateEntityInterface;
@Aspect
public class UpdateEntityAspect {
/**
* Wyszukiwanie wszystkich klas z adnotacją Entity
*/
@Pointcut("within(@javax.persistence.Entity pl.xxx..*)")
public void beanAnnotatedWithEntity() {
}
/**
* Wyszukiwanie wszystkich metod z nazwą rozpoczynającą się od set
*/
@Pointcut("execution(public * set*(..))")
public void setMethod() {
}
/**
* Wyszukiwanie wszystkich pol w momencie zmodyfikacji ich stanu
*/
@Pointcut("set(private * *)")
public void privateField() {
}
/**
* Nadawanie encji dodatkowego interfejsu / wstrzykiwanie dodatkowych pol
*/
@DeclareParents(value = "@javax.persistence.Entity pl.xxx..*", defaultImpl = UpdateEntityInterface.UpdateEntityInterfaceImpl.class)
UpdateEntityInterface updateEntityInterface;
/**
* Kod wstrzykiwany podczas modyfikowania pola encji
*
* @param joinPoint
* @param entity
*/
@Before("beanAnnotatedWithEntity() && privateField() && target(entity)")
public void onSetExecuted(JoinPoint joinPoint, Object entity) {
if (entity instanceof UpdateEntityInterface) {
UpdateEntityInterface updateEntityInterface = (UpdateEntityInterface) entity;
updateEntityInterface._markUpdated(joinPoint.getSignature().getName());
}
}
}
Aspect 影响下的类:
package pl.xxx.model.entity;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.apache.commons.lang3.StringUtils;
@Entity
@Table(name="CUSTOMER")
public class Customer implements Serializable {
private static final long serialVersionUID = 9128787620983157104L;
@Id
@SequenceGenerator(name="IdGenerator", sequenceName="SEQ_CUSTOMER", allocationSize=1)
@Column(name="ID", unique=true, nullable=false, precision=15, scale=0)
protected Long id;
@Column(name="FILE_TYPE", length=3)
@CorelatedEnum(IncomingFileType.class)
private String fileType;
}
错误:类型 Customer 必须实现继承的抽象方法 UpdateEntityInterface._getUpdatedFields() Customer.java 第 17 行 Java 问题
【问题讨论】:
-
这听起来像是一个 AspectJ 错误,增量编译器没有做出正确的决定。您是否尝试过使用
@DeclareMixin而不是@DeclareParents- 它应该可以实现类似的效果,但我只是想知道增量编译是否能更好地处理mixin 情况。新的 AspectJ 错误在这里:bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ -
它正在与@DeclareMixin 合作!谢谢你,兄弟。你为我节省了很多重建工作。
标签: java eclipse aspectj aspect