Compilation Units

A compilation unit is a text file with the filename extension .ceylon, containing one or more toplevel declarations.


Here's an example compilation unit in the package containing three toplevel declarations:

import com.example.baz { Baz }

shared interface Foo {
    // ...

shared class DefaultFoo() satisfies Foo {
    // ...

shared Baz? doFoo(Foo foo) {
    return null;


Compilation units are a compile-time concept and have no representation or role at runtime.


A compilation unit may contain one or more declarations:

Module descriptors and package descriptors are special-purpose compilation units and may not contain declarations.

Note: Ceylon does not have Java's restriction on public (shared) classes having to be declared in a source file named after the class name.

Source Location

A compilation unit belongs a package, determined by the location of the compilation unit in the source directory. For example, the compilation unit <source-dir>/foo/bar/unit.ceylon belongs to the package if <source-dir> is the source directory.

All compilation units in a certain directory belong to the same package.

See also