Fork me on GitHub Fuji Logo

Fuji: An Extensible Compiler for
Feature-Oriented Programming in Java



Overview

Feature-oriented programming aims at the modularization of features in source code. A feature is a unit of functionality of a software system that satisfies a requirement, represents a design decision, and provides a potential configuration option. Implementing a feature on top of a base program involves the addition of new program elements and the extension and refinement of existing program elements. For example, the implementation of a transaction feature on top of a database system requires the addition of new program structures for representing transactions as well as the integration of transaction management code into the core database system. For more information on feature orientation we refer the interested reader to a survey paper.

Fuji is an extensible compiler that supports feature-oriented programming in Java. In contrast to other feature-oriented tools (e.g., the AHEAD Tool Suite and FeatureHouse), Fuji does not rely on a source-to-source transformation but is a fully-fledged compiler that produces standard Java bytecode. Technically, Fuji is based on the JastAdd Extensible Java Compiler and supports the full Java 7 standard.

Background

We illustrate the basic capabilities of Fuji by means of an example. It is not meant as a comprehensive tutorial, but merely as a start-off aid. For an introduction to feature-oriented programming we refer the reader to the websites of the AHEAD Tool Suite and FeatureHouse.

Containment Hierarchies

Fuji follows the tradition of feature orientation to represent features as containment hierarchies, which are technically realized by file system directories. The files found inside a containment hierachy belong to the corresponding feature. For example, to implement a simple graph library that consists of the two features BasicGraph and Weight, a programmer creates two directories, each of which contains the files that belong to the feature in question:



A feature may contain standard Java packages, interfaces, and classes. For example, feature BasicGraph contains the three classes Node, Edge, and Graph:

/* BasicGraph/Graph/Node.java */
package Graph;
class Node {
  int id = 0;
  Node(int _id) {
    id = _id;
  }
}

/* BasicGraph/Graph/Edge.java */
package Graph;
class Edge {
  Node a, b;
  Edge(Node _a, Node _b) {
    a = _a; b = _b;
  }
}

/* BasicGraph/Graph/Graph.java */
package Graph;
class Graph {
  java.util.Vector nodes = new java.util.Vector();
  java.util.Vector edges = new java.util.Vector();
  Edge add(Node n, Node m) {
    Edge e = new Edge(n, m);
    nodes.add(n); nodes.add(m); edges.add(e);
    return e;
  }
}

Class Refinement

Furthermore, Fuji supports the concept of class refinement. That is, when a feature is composed with another feature, it may refine the classes of the other feature. For example, to implement feature Weight, we add a new class Weight representing edge weights and we refine class Edge such that each Edge object has a field weight. Furthermore we refine class Graph by appending a new add method that allows to add weighted edges to a graph:

/* Weight/Graph/Weight.java */
package Graph;
class Weight {
  int w = 0;
  Weight(int _w) {
    w = _w;
  }
}

/* Weight/Graph/Edge.java */
package Graph;
class Edge {
  Weight w = new Weight(0);
  void setWeight(Weight _w) {
    w = _w;
  }
}

/* Weight/Graph/Graph.java */
package Graph;
class Graph {
  Edge add(Node n, Node m, Weight w) {
    Edge res = this.add(n, m);
    res.setWeight(w);
    return res;
  }
}

Technically, the composition of features and refinement of classes are implemented via superimposition. For more details, we refer the interested reader to the FeatureHouse website.

Access Control Mechanisms

Fuji is fully compatible with FeatureHouse. Additionally, it implements a novel access control model for feature-oriented programming. It provides three new modifiers feature, subsequent, and program for class members. The semantics of the modifiers and the details of the model are described in a scientific paper. We provide two versions of Fuji: one with and one without the novel access control model.

HowTo

Fuji is deployed in the form of a single Jar archive. As command line arguments, it expects a file that lists the features to be composed. The features listed in the file must be implemented by corresponding containment hierarchies reachable from the working directory.

To try out the graph example we described above, download the example programs and compile Fuji first. We assume that Fuji Jar archive is in the Graph directory (the root directory of the example). Then invoke Fuji as follows:

cd Graph
java -jar fuji.jar -d classes GraphComp.features

The file GraphComp.features lists the two features we want to compose:

BasicGraph
Weight

The generated class files will be put in the classes sub-directory. To invoke the compiled program run:

java -cp classes Graph.Graph

Type Checker

Fuji type checker implements product-based, feature-based, and family-based typechecking strategies.

HowTo

To perform a family-based type check, run in the command line:

java -jar fuji.jar -timer -fopRefs -typechecker Lists.family.model

To perform a feature-based type check, run in the command line:

java -jar fuji.jar -timer -fopRefs -typechecker -novariability -ignoreOriginal Lists.Base-feature.model
java -jar fuji.jar -timer -fopRefs -typechecker -novariability -ignoreOriginal Lists.Batch-feature.model

To perform a product-based type check, run in the command line:

java -jar fuji.jar -timer -fopRefs -typechecker -novariability Lists.Base-product.model
java -jar fuji.jar -timer -fopRefs -typechecker -novariability Lists.Base-Batch-product.model

You can use the same procedure to type check the 12 subject systems from the Fuji collection. Alternatively, you can use the scripts from the complete project data.

We empirically compared the three typechecking strategies and presented the results in a scientific paper.

Download

Git repository.

Contact

Fuji has been developed at the University of Passau, Germany. For more information please contact the developers: