How to include comments for a package with scaladoc? - scala

So, for scaladoc, you can specify comments for a particular component of your code like so:
package connector
import java.io.RandomAccessFile;
/** Fs class guides file opening
*
*/
object fs {
def printFile(path:String):Unit = {
val fl = new RandomAccessFile(path, "rw");
println(fl.readLine());
println(fl.getFilePointer());
fl.close();
}
}
However, I don't see where or how you would include a comment that will appear in the index.html generated by scaladoc for the package starting page. How is this done?

Create a package object (package.scala) and add you documentation there:
/**
* Fs class guides file opening
*/
package object connector {}

Related

doxygen is not creating class for child interface

I am creating document for .hal files using doxygen with enabling idl support.I have file called A.hal with following content.
/**
* A.hal
*/
interface A extends B {
//some content
}
If i generate document for above file, i could able to see class name as B under class list (in doxygen output file i.e index.html). But, my expectation is A should come under class list. What is solution to achieve this? If extends B is not present, then A is coming in class list.
I am using following configuration.
JAVADOC_AUTOBRIEF = NO
OPTIMIZE_OUTPUT_JAVA = NO
EXTENSION_MAPPING = hal=idl
IDL_PROPERTY_SUPPORT = YES
CASE_SENSE_NAMES = YES
FILE_PATTERNS = *.hal

illegal cyclic reference involving object models

When I try to pass a list to the view page of a Play application I receive an error:
illegal cyclic reference involving object models
Error screenshot:
models.scala.html:
#(liValues: List[String])
#for(value <- liValues){
<li>#value</li>
}
entry in routes files:
GET /models/tictactoe controllers.ModelController.index
index method in ModelController.scala where I pass the values:
def index = Action {
Ok(views.html.models(List("Link1" , "Link2" , "Link3")))
}
Complete ModelController:
package controllers
import javax.inject._
import play.api.libs.json.Json
import play.api.mvc._
/**
* This controller creates an `Action` to handle HTTP requests to the
* application's home page.
*/
#Singleton
class ModelController #Inject()(cc: ControllerComponents) extends AbstractController(cc) {
/**
* Create an Action to render an HTML page with a welcome message.
* The configuration in the `routes` file means that this method
* will be called when the application receives a `GET` request with
* a path of `/`.
*/
def index = Action {
Ok(views.html.models(List("Link1" , "Link2" , "Link3")))
}
def sj = Action {
Ok(Json.toJson(List(1,2,3)).toString());
}
}
it seems I'm not declaring the list value in the view page correctly ?
It seems DummyPlaceHolder.scala
package models
/*
* Empty placeholder object to make sure templates keep compiling (due to
* imports in template files), even if projects don't have any models.
*/
object DummyPlaceHolder
is interfering with your views.html.models which also has models so the generated template target/scala-2.13/twirl/main/views/html/models.template.scala will have something like
import models._
object models extends ...
which causes illegal cycle. Try changing the name of your template from views.html.models to say views.html.model.

jsdoc : reference typedef-ed type from other module

Assuming I have a typedef type in a js module
// somewhere/foo.js
/**
* #module
*/
/**
* #typedef Foo
* #type {object}
* property {string} bar - some property
*/
Is it possible to reference this type in another module, so that in the HTML page generated by jsdoc, the type is displayed as a link to the typedef-ed module ?
I tried variations of this, but nothing seems to work...
// somewhere_else/bar.js
/**
* #module
*/
/**
* #param {somewhere/foo/Foo} foo - some param
*/
export default function doStuff(foo) {
...
}
This works for me ...
// somewhere/foo.js
/**
* #module foo
*/
/**
* #typedef module:foo.Foo
* #type {object}
* #property {string} bar - some property
*/
and ...
// somewhere_else/bar.js
/// <reference path="foo.js" />
/**
* #module bar
*/
/**
* #param {module:foo.Foo} foo - some param
*/
function doStuff(foo) {
//...
};
The above answer shows up high in search results so I'm documenting what worked for me in case it helps someone in a similar situation.
I'm using Visual Studio code for a node project with // #ts-check on all my modules. Using the above syntax hiccups on the module: syntax. Also, the code assistance doesn't work properly. It took me a while but the answer ended up being quite simple
If I have the typedef myTypedef in a module myModule then in the second module where I require myModule
mm = require(myModule)
I can use something like
/** #param {mm.myTypedef} myParamName */
The module syntax is not supported by TypeScript so if you're getting here assuming it to work, I haven't been able to get the solutions above to work.
To get it working with TypeScript use Import Types
For the OP the way I would do it is
// foo.d.ts
export type Foo = {
/**
* some property
*/
bar: string,
};
Then refer to it in the JS module as
/**
* #typedef { import("./foo").Foo } Foo
*/
/**
* #param {Foo} foo - some param
*/
export default function doStuff(foo) {
...
}
You can verify things are working on an individual file more strictly by adding the following to the beginning of the file. This will enable typescript checking in Visual Studio code for the specific file to help prepare your move to Typescript in the future.
// #ts-check
Many libraries export types from their root file, to access those in typedefs, change your import to use the import * as format.
For example:
import * as testingLibrary from '#testing-library/react';
/**
* #returns {testingLibrary.RenderResult}
*/
export function myCustomRender() { }
I've tried both of the above approaches.
Firstly, in the case of #typedef module:foo.Foo, VSCode treated the usage of Foo within the same file as any. Which I didn't find acceptable.
Secondly, when using ES6 imports the following issue emerges:
import foo from 'foo'
/** #param {foo.Foo} a - Error Foo does not exist on foo */
On the other hand VSCode recognizes import { Foo } from 'foo' without even using the JSDoc module syntax:
/**
* #module bar
*/
What's more I was also able to reference a property on the imported type, namely:
import { Foo } from 'foo'
/** #param {Foo['bar']} bar */
Note
This project uses Babel and assume compiling code which uses type imports in not feasible without a transpiler.
I'm working with vscode-powertools script which provides access to vscode module at runtime (as opposed to it being available to VSCode at edit time via the local node_modules).
If I would try to import the types with the usual jsdoc import
//#ts-check
/** #typedef {import('c:/Users/USERNAME/.vscode/extensions/ego-digital.vscode-powertools-0.64.0/node_modules/vscode').TextEditor} TextEditor */
I would be getting the File is not a module error:
File 'C:/Users/USERNAME/.vscode/extensions/ego-digital.vscode-powertools-0.64.0/node_modules/vscode/vscode.d.ts' is not a module. ts(2306)
So here's the trick I'm using to typecheck that kind of script:
//#ts-check
/// <reference types="c:/Users/USERNAME/.vscode/extensions/ego-digital.vscode-powertools-0.64.0/node_modules/vscode" />
// Allows us to reference the `vscode` module with jsdoc `#type`
async function vscodeⁱ() {if (1 == 1) return null; return import ('vscode')}
exports.execute = async (args) => {
// Allows us to reference the `vscode` module with jsdoc `#type`
const vscode = await vscodeⁱ()
/** #type {vscode} */
const vs = args.require ('vscode')
// NB: The following code is fully typed in VSCode
const windowᵛ = vs.window
const editorᵛ = windowᵛ.activeTextEditor
const start = editorᵛ.selection.start
}

Custom hovering in Xtext 2.10

I use Xtext 2.10.0.v201605250459 with Eclipse Neon 4.6.1 and want to implement custom hover texts like described in this tutorial. However it does not work (no custom text appears as expected, but the default one as handled by Xtext framework).
My implementation of the hover provider:
package demo.ui.hover
import org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider
import org.eclipse.emf.ecore.EObject
class DemoEObjectHoverProvider extends DefaultEObjectHoverProvider
{
override protected getFirstLine(EObject o)
{
return "This is some demo text!"
}
}
Here is how I register it:
/*
* generated by Xtext 2.10.0
*/
package demo.ui
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
import demo.ui.hover.DemoEObjectHoverProvider
/**
* Use this class to register components to be used within the Eclipse IDE.
*/
#FinalFieldsConstructor
class DemoUiModule extends AbstractDemoUiModule
{
def bindIEObjectHoverProvider()
{
typeof(DemoEObjectHoverProvider)
}
}
Can you identify some error there?
your guice binding is wrong
def Class<? extends IEObjectHoverProvider> bindIEObjectHoverProvider() {
DemoEObjectHoverProvider
}
see https://www.eclipse.org/Xtext/documentation/302_configuration.html#dependency-injection for the conventions

Play: additional public / assets directory

In order to have a clean directory structure, I would like to make an additional assets folder public. I've created a directory 'assets' in my project folder, wrote an 'PictureAssets' controller which is nearly identical to 'controller.Assets', added 'assets' to the playAssetsDirectories in the build.sbt and tried following some route entries without success.
PictureAssets:
package controllers
import play.api.mvc.Action
import play.api.mvc.AnyContent
object PictureAssets extends AssetsBuilder {
def create : Action[AnyContent] = Action {
Ok(views.html.fileUploadForm())
}
}
build.sbt
playAssetsDirectories <+= baseDirectory / "assets"
routes
# GET /file controllers.PictureAssets.at(path="/assets", file="MM1.png")
GET /datei/*file controllers.PictureAssets.at(path="/assets", file)
# GET /datei/*file controllers.Assets.at(path="/assets", file)
If I try to access the URL, either nothing is displayed, or the error 'The image http:9000//localhost/datei/MM1.png cannot be displayed because it contains errors' is displayed or the css references to handled by the 'controller.Assets' don't work any more.
What am I missing?
I think the issue comes from the fact that the at method used is the default one used previously by Assets.
I ran into the same issue at some point last year, where I wanted to serve images that would be stored in a external folder, a folder that is somewhere on disk, and here is how I coded this:
I created a simple controller called Photos, that contained one Action:
object Photos extends Controller {
val AbsolutePath = """^(/|[a-zA-Z]:\\).*""".r
/**
* Generates an `Action` that serves a static resource from an external folder
*
* #param absoluteRootPath the root folder for searching the static resource files.
* #param file the file part extracted from the URL
*/
def at(rootPath: String, file: String): Action[AnyContent] = Action { request =>
val fileToServe = rootPath match {
case AbsolutePath(_) => new File(rootPath, file)
case _ => new File(Play.application.getFile(rootPath), file)
}
if (fileToServe.exists) {
Ok.sendFile(fileToServe, inline = true)
} else {
Logger.error("Photos controller failed to serve photo: " + file)
NotFound
}
}
}
Then, in my routes, I defined the following:
GET /photos/*file controllers.Photos.at(path="/absolute/path/to/photos",file)
This worked just fine for me. Hope this helps.
PS: This was in addition to the normal Assets controller that helped serving js and css files.