#98 Facets

brian Tue 4 Jul 2006

I did some major work to provide a reflection API for facets. The fcode format was changed so that each facet has a one byte bitmask. If the Reflective flag is set, then the facet is exposed via the API. All reflective facets must have a UTF string value.

At the API level there is a new sys::Facets class which is basically a map of Str key/value pairs. I started down a path of making the values Bufs, but the mutability issues led back to simple Str values. Facets support the same isRO, isRW, ro, rw API as List and Map. There is also a facets() method on both Type and Slot to access the facets:

echo(Sys.findType("sys::Obj").facets)
// will print
[LineNumber:10, SourceFile:Obj.fan]

Both Type and Slot have a "LineNumber" facet with a lineNumber() convenience method. Type also has a "SourceFile" facet with a sourceFile() convenience. So if the pod was compiled with the "-src" flag you can access the source file using:

t.pod.files["/src/$t.sourceFile".toUri]

Eventually we will add some type of source code syntax for defining facets like Java annotations or C# attributes, which is really purpose of this feature. But now Andy you should have everything you need to support source code browsing in the fandoc weblet.

Login or Signup to reply.