当子类继承编织到其基类并在单独的jar中定义的intertyped方法时,aspectj iajc失败

时间:2011-08-10 23:27:10

标签: inheritance compilation aspectj

我正在使用aspectJ来注入接口实现。 Eclipse编译所有内容都很好。 然而,该项目也必须用蚂蚁建造。

iajc任务失败: “类型Foo必须实现继承的抽象方法Bar.doThings()” 其中Bar是具有intertype(ITD)实现的接口。

代码看起来像这样(在各自的文件中):

class Foo extends BaseFoo {...}
abstract class BaseFoo implements Bar {...}
interface Bar{ 
     void doThings{} 
     public static aspect Implementation {
           void Bar.doThings() {
               //whatever
            }
     }
 }

编织消息会显示类BaseFoo,方法doThings()是intertyped 但是Foo没有。 并因此失败并出现“必须实施......”错误。

我很确定我在common.jar中有类似的情况正常工作。 当我编译另一个定义了Bar并且在common.jar中实现ITD /实现的模块时会发生这种情况。 common.jar在<iajc .... aspectPathRef..>中正确指定,否则BaseFoo将不会进行交互式。

所以看起来编译器没有看到从它被交互的基类继承的实现。

以下是iajc的样子:

   <iajc destdir="${build.dir}" sourceroots="${javasrc.dir}"`
            source="1.6"
            classpathref="classpath" 
            Xlint="warnings" 
            aspectPathRef="aspectlib"
            showWeaveInfo="true" />

其中aspectlib包含apsectjrt.jar和my common.jar

还有一件事:编译和运行的eclipse项目不分为通用模块和其他模块 - 所有src目录都只是导入到一个聚合项目中。

所以请 - 这里有什么问题?

3 个答案:

答案 0 :(得分:1)

这是我提交给aspectj bugzilla的错误的链接 https://bugs.eclipse.org/bugs/show_bug.cgi?id=354683

我将问题归结为: 在jar中定义的方面和接口 - 分层接口及其分层实现无法在eclipse和命令行中的目标项目中正确编织。

以下是“jar”项目中的所有代码:

public interface CommonData {void getData();}
public interface CommonDataImpl extends CommonData {}
public aspect CommonDataImplementation {
     public void CommonDataImpl.getData() {}
}
public interface DerivedCommonDataInterface extends CommonData {
    void getDerivedData();
}
public interface DerivedCommonDataInterfaceImpl 
           extends DerivedCommonDataInterface, CommonDataImpl {}
public aspect DerivedCommonDataInterfaceImplementation {
    public void DerivedCommonDataInterfaceImpl.getDerivedData() {}
}

请注意,“derived”接口扩展了另一个接口,其实现扩展了“common”实现。

以下是整个目标项目:

public abstract class AbstractBaseClass <T extends Whatever> 
    implements DerivedCommonDataInterfaceImpl {}
public class DerivedClass extends AbstractBaseClass {}

build.xml文件在这里浪费空间 - 您可以从bug附件(上面的链接)下载tar。 因此,直到aspectj项目的某个人对其进行权衡 - 这才是答案。

即使这个问题是一个非常严重的问题并且会使它成为许多情况下的一个showstopper,我将通过符号链接或svnexternals或其他任何方式将我的所有实际工作聚合到一个eclipse / ant项目中,因为通过实现接口ITD - 由于ITD,我删除但尚未删除的代码量很难高估。

对你来说,大家都赞不绝口(错误是'全部:)

答案 1 :(得分:0)

你描述事物的方式,听起来是对的。它可能是AspectJ中的一个错误,因为静态内部方面和ITD不会混合使用jar文件。

我刚试过你在Eclipse和AJDT中描述的设置(不是使用jar文件,而是使用单独的项目),它对我来说很好。

首先,您可以尝试将该方面设为顶级方位吗?

如果这不起作用,您可以将问题提炼到可以附加到eclipse.org上的错误报告的项目吗?如果是这样,我或其他人会看一看。

https://bugs.eclipse.org/bugs/

答案 2 :(得分:0)

尝试将所有与AspetJ相关的代码放在inpath标记中,而不是aspectPathRef。我有非常复杂的Ant + AspectJ构建。并且不要遇到像你这样的问题。

这是我的AspectJ构建任务的结构:

 <iajc destDir="${aop.output}" Xlintwarnings="true" showWeaveInfo="true" target="1.6"
         source="1.6" 
            bootclasspathref="android.target.classpath">

            <sourceroots>                   
                <path refid="${main.project.sources}" />

            </sourceroots>
            <inpath>                    
                <path refid="all.your.AspetJ.related.code.from.other.projects "/>                   
            </inpath>
            <classpath>

                <pathelement location="libs/httpmime-4.0.3.jar"/>
                <pathelement location="libs/apache-mime4j-0.6.jar"/>
                <pathelement location="libs/commons-io-2.0.1.jar"/>
                ....
                <pathelement location="${aspectj.home}/aspectjrt.jar"/>

            </classpath>
        </iajc>

如您所见,我根本不使用aspectPathRef。