Is there a Scala equivalent of package-info.java?

View: New views
9 Messages — Rating Filter:   Alert me  

Is there a Scala equivalent of package-info.java?

by Jesse Eichar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I just came to learn about package-info.java recently.  It seems to have two main purposes

<ul>
<li>Declare package level annotations</li>
<li>Provide package level documentation (as did package.html if I remember correctly</li>
</ul>

Does scala 2.8 have package annotation support?
How can one do package documentation for Scaladoc?

Thanks,

Jesse


Re: Is there a Scala equivalent of package-info.java?

by Martin Odersky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Nov 6, 2009 at 3:33 PM, Jesse Eichar <jeichar.w@...> wrote:
> I just came to learn about package-info.java recently.  It seems to have two
> main purposes
> <ul>
> <li>Declare package level annotations</li>
> <li>Provide package level documentation (as did package.html if I remember
> correctly</li>
> </ul>
> Does scala 2.8 have package annotation support?
> How can one do package documentation for Scaladoc?

I am not sure what scaladoc does, but you could write a package object
and annotate this. E.g.

package myproject

/** The myproject.mypackage package contains the folloing items: ...
 */
package object mypackage {
  // could be empty
}

Cheers

 -- Martin

Re: Is there a Scala equivalent of package-info.java?

by phkoester :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

martin odersky wrote:

> I am not sure what scaladoc does, but you could write a package object
> and annotate this. E.g.
>
> package myproject
>
> /** The myproject.mypackage package contains the folloing items: ...
>  */
> package object mypackage {
>   // could be empty
> }

And where would I place the annotations?

This compiles with 2.8 snapshot:

        package com.acme

        package object frob

However, this doesn't:

        package com.acme

        @WhateverAnnot
        package aboject frob

What am I missing? And how would I name the compilation unit?
`frob.scala' or `DoesntMatter.scala'? I actually use package
annotations, but for the time being, I keep them in ordinary
`package-info.java' files, which works fine, so this is not a major
issue for me. But it would of course be nice to express this in Scala.

---Ph.

Re: Is there a Scala equivalent of package-info.java?

by phkoester :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> However, this doesn't:
>
>     package com.acme
>
>     @WhateverAnnot
>     package aboject frob

I'm sorry for the typo in there---it should be `object', of course.

Re: Is there a Scala equivalent of package-info.java?

by Nils Kilden-Pedersen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Nov 6, 2009 at 2:00 PM, Philip Köster <philip.koester@...> wrote:
What am I missing? And how would I name the compilation unit?

Package objects must be in files named "package.scala"

Re: Is there a Scala equivalent of package-info.java?

by phkoester :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Package objects must be in files named "package.scala"

I don't get this to compile. Here is my `package.scala':

        package com.phrood
        @javax.annotation.Resource // Just a test
        package object scarab

Compiler says:

        C:\Users\phkoester\Data\phrood\scarab\src\main\java\com\phrood\scarab\package.scala:3:
error: expected start of definition
        package object scarab
        ^


Re: Is there a Scala equivalent of package-info.java?

by phkoester :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> I don't get this to compile. Here is my `package.scala':
>
>     package com.phrood
>     @javax.annotation.Resource // Just a test
>     package object scarab

On a side note, the `Resource' annotation cannot be applied to packages,
but that's not the reason why compiling fails. I just checked it with a
custom annotation that is capable of annoting packages, and the result
is the same.

---Ph.

Re: Is there a Scala equivalent of package-info.java?

by David Flemström :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You need to use Scala 2.8 to gain access to package objects.

On Friday 06 November 2009 21:16:46 Philip Köster wrote:

> > Package objects must be in files named "package.scala"
>
> I don't get this to compile. Here is my `package.scala':
>
> package com.phrood
> @javax.annotation.Resource // Just a test
> package object scarab
>
> Compiler says:
>
> C:\Users\phkoester\Data\phrood\scarab\src\main\java\com\phrood\scarab\pack
> age.scala:3: error: expected start of definition
> package object scarab
> ^
>

Re: Is there a Scala equivalent of package-info.java?

by phkoester :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> You need to use Scala 2.8 to gain access to package objects.

Yeah I know. I do use the latest 2.8 nightly I think. Package objects
seem to compile, and they don't seem to require a file named
`package.scala'. Only I don't know how to use annotations for package
objects. I believe it just doesn't work ...

---Ph.