Closure joinpoints: block joinpoints without surprises

Closure joinpoints: block joinpoints without surprises
复制标题

关闭连接点:毫无意外地阻止连接点

DOI:
--
复制
发表时间:
2011
期刊:
Aspect-Oriented Software Development
影响因子:
--
通讯作者:
E. Bodden
E. Bodden
中科院分区:
--
文献类型:
--
作者:
E. Bodden

文献摘要

被引文献

相似文献

块连接点允许程序员将基本代码区域显式标记为“待通知”,从而避免仅仅为了创建连接点而将块提取到方法中。块连接点的定义和实现似乎很简单。毕竟,类 Java 语言中的常规块语句是程序员熟知的结构,并且具有简单的控制流和数据流语义。 然而,我们的主要见解是,通过将代码块公开为连接点,代码不再仅在其声明静态上下文中调用,而且还可以从方面代码内调用。该块实际上变成了一个闭包,即可以从封闭的词法范围捕获值的匿名函数。我们讨论关于闭包的研究,这些研究揭示了闭包或块连接点的任何语义定义都必须回答的几个重要的设计问题。在本文中,我们表明所有现有的块连接点提案都不足以回答这些问题,因此表现出的语义要么未定义,要么可能令 Java 程序员感到惊讶。 作为解决方案,我们提出了闭包连接点(基于闭包的块连接点)的语法、语义和实现。正如我们所展示的,我们的设计决策产生了遵循最小意外原则的语义。
Block joinpoints allow programmers to explicitly mark regions of base code as "to be advised", thus avoiding the need to extract the block into a method just for the sake of creating a joinpoint. Block joinpoints appear simple to define and implement. After all, regular block statements in Java-like languages are constructs well-known to the programmer and have simple control-flow and data-flow semantics. Our major insight is, however, that by exposing a block of code as a joinpoint, the code is no longer only called in its declaring static context but also from within aspect code. The block effectively becomes a closure, i.e., an anonymous function that may capture values from the enclosing lexical scope. We discuss research on closures that reveals several important design questions that any semantic definition of closures or block joinpoints must answer. In this paper we show that all existing proposals for block joinpoints answer these questions insufficiently, and hence exhibit a semantics either undefined or likely surprising to Java programmers. As a solution, we propose a syntax, semantics, and implementation of Closure Joinpoints, block joinpoints based on closures. As we show, our design decisions yield a semantics that follows the principle of least surprise.