论文标题

在Java中产生通用的Fluent API

Generating a Generic Fluent API in Java

论文作者

Nakamaru, Tomoki, Chiba, Shigeru

论文摘要

上下文:这些年来积极研究用于生成安全流利API的算法。安全的Fluent API是流利的API,它报告了API方法的错误链接,作为API用户的类型错误。尽管这样的安全属性提高了用户的生产率,但对于开发人员来说,安全流利的API的构建太复杂了。研究了生成算法以降低安全流利的API的开发成本。关于这一代的研究将使许多程序员受益,因为流利的API是现实世界中的一种流行设计。 询问:通用流利的API的产生未被弄脏。通用流利的API是指提供通用方法的流利API(在其定义中包含类型参数的方法)。 Java中的流API是这样的通用API的一个示例。最近对安全流利API生成的研究集中在算法可以处理语法检查的语法类别上。先前研究的关键思想是使用嵌套通用物来代表在类型系统顶部构建的解析器的堆栈结构。在这个想法中,类型参数的作用仅限于内部代表该类型系统上该解析器的堆栈元素。库开发人员无法使用类型参数在其API中包含一个通用方法,因此可以静态检查其API的语义约束,例如,对通过流传递的项目的类型约束。 方法:我们提出了一种算法来生成通用流利的API。我们的翻译算法建模为使用类型参数信息的确定性有限自动机(DFA)的构建。 DFA的每个状态都有有关该状态已绑定的类型参数的信息。该信息用于确定链中的方法调用是将类型新绑定到类型参数还是指先前绑定的类型。由于链中的类型参数在特定的方法调用处绑定,因此需要标识,并且该界类型在以下方法调用中被引用。我们的算法通过分析类型参数的结合时间及其在DFA中的传播来构建DFA,而DFA的传播是由给定语法天真构建的。 知识和重要性:我们的算法可帮助图书馆开发人员开发通用流利的API。生成通用流利API的能力对于将安全流利的API生成带入现实世界至关重要,因为使用类型参数是库API设计中的一种常见技术。根据我们的算法,将准备好使用安全的API供实际使用。 接地:我们实施了一个名为ProtoCool的发电机来演示我们的算法。我们还使用ProtoCool生成了几个库来显示我们算法的能力和局限性。

Context: The algorithms for generating a safe fluent API are actively studied these years. A safe fluent API is the fluent API that reports incorrect chaining of the API methods as a type error to the API users. Although such a safe property improves the productivity of its users, the construction of a safe fluent API is too complicated for the developers. The generation algorithms are studied to reduce the development cost of a safe fluent API. The study on the generation would benefit a number of programmers since a fluent API is a popular design in the real world. Inquiry: The generation of a generic fluent API has been left untackled. A generic fluent API refers to the fluent API that provides generic methods (methods that contain type parameters in their definitions). The Stream API in Java is an example of such a generic API. The recent research on the safe fluent API generation rather focuses on the grammar class that the algorithm can deal with for syntax checking. The key idea of the previous study is to use nested generics to represent a stack structure for the parser built on top of the type system. In that idea, the role of a type parameter was limited to internally representing a stack element of that parser on the type system. The library developers could not use type parameters to include a generic method in their API so that the semantic constraints for their API would be statically checked, for example, the type constraint on the items passed through a stream. Approach: We propose an algorithm to generate a generic fluent API. Our translation algorithm is modeled as the construction of deterministic finite automaton (DFA) with type parameter information. Each state of the DFA holds information about which type parameters are already bound in that state. This information is used to identify whether a method invocation in a chain newly binds a type to a type parameter, or refers to a previously bound type. The identification is required since a type parameter in a chain is bound at a particular method invocation, and that bound type is referred to in the following method invocations. Our algorithm constructs the DFA by analyzing the binding time of type parameters and their propagation among the states in a DFA that is naively constructed from the given grammar. Knowledge and Importance: Our algorithm helps library developers to develop a generic fluent API. The ability to generate a generic fluent API is essential to bring the safe fluent API generation to the real world since the use of type parameters is a common technique in the library API design. By our algorithm, the generation of a safe fluent API will be ready for practical use. Grounding: We implemented a generator named Protocool to demonstrate our algorithm. We also generated several libraries using Protocool to show the ability and the limitations of our algorithm.

扫码加入交流群

加入微信交流群

微信交流群二维码

扫码加入学术交流群,获取更多资源