I have to use a reporting tool (IBM Cognos analytics), which provides the ability to inserts custom scripts in HTML reports created by this reporting tool. So, we are supposed to be able to reference JS libraries like jQuery, jQueryUI, and work with them, etc..
This functionality in the reporting tool is official, and it is stated that they are using requirejs to handle this.
The model of code we need to respect in this case (from IBM "api") is the following:
define(['https://our_site/someFolder/someResource.js'], function() {
/*
A) - Here, I would expected that any code writtne here is executed only when "someResource.js" has been loaded
*/
function monModule() { };
monModule.prototype.setData= function() {
/*
B) - some code here
*/
};
monModule.prototype.draw= function(o) {
/*
C) - some code here
*/
};
return myObject;});
My questions are the following:
1) My current understanding of the behavior within a "define" block is that the JS code will be executed only once the resources mentioned in the "define" instruction are loaded/available. Is it correct?
In the example above, the part mentioned in A) or C) would be "evaluated" / executed only when the resource "someResource.js" is loaded. Do I understand correctly?
2) the RequireJs library used by IBM Cognos analytics shows the following:
/** vim: et:ts=4:sw=4:sts=4
* #license RequireJS 2.1.14 Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/requirejs for details
*/
Can I assume then that the RequireJS library used by IBM Cognos analytics is the "common" / "standard" and not a derived one, and so that all functionalities and behavior of RequireJS should be available in IBM Cognos analytics?
I'm asking all this because we are facing issues where some piece of JS code seems to be executed before the resource is loaded; we get error like ' "$" doesn't exist ..etc..'.
Any help / advice is welcome.
Thanks!
1). The callback of define() is only executed once, to define your module.So in your example, only A) will be executed, but B) and C) are the code of methods in the prototype of monModule
Here are steps which RequireJS is doing under the hood when you execute define() function:
It loads async module's dependencies
When dependencies are loaded, it executes the callback, injecting loaded dependencies as arguments. The callback should returns a value which is defined module.
It stores internally the returned value, so when other module require just defined module it will be injected as argument.
2) You can calculate md5 checksum for that file and validate it against the "official" RequireJS library
About errors you are get. Maybe you need to setup shim to make sure that jQuery is loaded before the module which needs jQuery?
I'm using Android Studio 3.0.1. I can hit fix doc comment to insert comment of method quickly in Java, but not effective in Kotlin. How can I solve it?
When you're typing # inside a kdoc, you'll see auto complete for #param, and after #param you'll see all parameters, and currently you cannot complete all parameters within one click.
Mention the /** */ comments are called kdoc in Kotlin, which is not javadoc.
Kotlin and especially KDoc encourage a different documentation style. As stated in this discussion:
The reason is that we found that referring to parameter names from the documentation text allows to write documentation that is more concise and easier to read compared to the traditional javadoc style where every parameter is documented in a separate tag. Therefore, we do not generate the template with parameter names by default. (D. Jemerov, Kotlin in Action Author)
Here’s an example of let, which is part of the standard library:
/**
* Calls the specified function [block] with `this` value as its argument and returns its result.
*/
#kotlin.internal.InlineOnly
public inline fun <T, R> T.let(block: (T) -> R): R
The basic pattern that I have a couple of times in my code is exports.thing = thingFromSomewhereElse, and I want to document the function members of thingFromSomewhereElse as though I had defined them myself. But I can't see how do do that without an actual thing.functionName = function() {...}. If I try to use the #callback tag, JSDoc classifies it as a type definition instead of a member. Is there a way to get it to properly display as an object member?
This can be accomplished by using the #name JSDoc tag. That tag is intended to be used to write a comment for something that would not be recognized by JSDoc. The #kind tag should also be used to indicate that the thing being documented is actually a function, so that the function-specific tags like #param and #return work properly. For the example given, the function would be documented with a comment like this:
/**
* Description of the function
* #name thing.functionName
* #kind function
* #param ...
* #return ...
*/
My Java.g4 grammar is generating " /**\r\n\t * A description Test. \r\n\t * \r\n\t * #see A first block tag\r\n\t * #see A second block tag\r\n\t */ " as a Token .
I'm rather interested in modifying my token permanently to " A description Test. #see A first block tag #see A second block tag " by means of TokenStreamRewrite or by some other way.
Any idea how to do it ??
The tokens are actually CommonToken instance so you could cast them to that class and call setText(..) on them. However, I believe the lexer/parser is not the right place for this kind of work. Instead do that in the following phase (e.g. when walking over the parse tree) and extract the content of your doc-comment using simple string manipulation functions. Don't overload the generated classes with work that doesn't really belong to them.
Can I use shortcut keys in Android studio to generate javadoc comments?
If not, what is the easiest way to generate javadoc comments?
I can't find any shortcut to generate javadoc comments. But if you type /** before the method declaration and press Enter, the javadoc comment block will be generated automatically.
Read this for more information.
To generatae comments type /** key before the method declaration and press Enter. It will generage javadoc comment.
Example:
/**
* #param a
* #param b
*/
public void add(int a, int b) {
//code here
}
For more information check the link
https://www.jetbrains.com/idea/features/javadoc.html
Here is an example of a JavaDoc comment from Oracle:
/**
* Returns an Image object that can then be painted on the screen.
* The url argument must specify an absolute {#link URL}. The name
* argument is a specifier that is relative to the url argument.
* <p>
* This method always returns immediately, whether or not the
* image exists. When this applet attempts to draw the image on
* the screen, the data will be loaded. The graphics primitives
* that draw the image will incrementally paint on the screen.
*
* #param url an absolute URL giving the base location of the image
* #param name the location of the image, relative to the url argument
* #return the image at the specified URL
* #see Image
*/
public Image getImage(URL url, String name) {
try {
return getImage(new URL(url, name));
} catch (MalformedURLException e) {
return null;
}
}
The basic format can be auto generated in either of the following ways:
Position the cursor above the method and type /** + Enter
Position the cursor on the method name and press Alt + Enter > click Add JavaDoc
You can install JavaDoc plugin from Settings->Plugin->Browse repositories.
get plugin documentation from the below link
JavaDoc plugin document
Javadoc comments can be automatically appended by using your IDE's autocomplete feature. Try typing /** and hitting Enter to generate a sample Javadoc comment.
/**
*
* #param action The action to execute.
* #param args The exec() arguments.
* #param callbackContext The callback context used when calling back into JavaScript.
* #return
* #throws JSONException
*/
You can use eclipse style of JavaDoc comment generation through "Fix doc comment".
Open "Preference" -> "Keymap" and assign "Fix doc comment" action to a key that you want.
Here we can some something like this.
And instead of using any shortcut we can write "default" comments at class/ package /project level. And modify as per requirement
*** Install JavaDoc Plugin ***
1.Press shift twice and Go to Plugins.
2. search for JavaDocs plugin
3. Install it.
4. Restart Android Studio.
5. Now, rightclick on Java file/package and goto
JavaDocs >> create javadocs for all elements
It will generate all default comments.
Advantage is that, you can create comment block for all the methods at a time.
In Android Studio you don't need the plug in. On A Mac just open Android Studio -> click Android Studio in the top bar -> click Prefrences -> find File and Code Templates in the list -> select includes -> build it and will be persistent in all your project
Another way to add java docs comment is press : Ctrl + Shift + A >> show a popup >> type : Add javadocs >> Enter .
Ctrl + Shirt + A: Command look-up (autocomplete command name)
Add Javadoc
/** + return
set cursor inside method name -> ⌥ Option + return -> Add Javadoc
Simply select (i.e. click) the method name, then use the key combo Alt+Enter, select "Add JavaDoc"
This assumes that you have not already added comments above the method, else the "Add JavaDoc" option will not appear.
In Android studio we have few ways to auto-generated comments:
Method I:
By typing /** and Then pressing Enter you can generate next comment line and it will auto-generate the params, etc. but when you need the hotkey for this check out method II on below.
**Method II: **
1 - Goto topMenu
2 - File > Settings
3 - Select Keymap from settings
4 - On the top right search bar search for "Fix Doc"
5 - Select the "fix doc comment" from the results and double-click on it
6 - Select Add keyboard shortcut from the opened drop down after double-click
7 - Press the shortcut keys on the keyboard
8 - Goto your code and where you want to add some comment press the shortcut key
9 - Enjoy!
Just select the Eclipse version of the keycap in the Keymap settings.
An Eclipse Keymap is included in Android Studio.
i recommendated Dokka for geneate javadoc with comment and more
I'm not sure I completely understand the question, but a list of keyboard short cuts can be found here - Hope this helps!
Android Studio -> Preferences -> Editor -> Intentions -> Java -> Declaration -> Enable "Add JavaDoc"
And, While selecting Methods to Implement (Ctrl/Cmd + i), on the left bottom, you should be seeing checkbox to enable Copy JavaDoc.
Because almost of us use Kotlin, you can generate JavaDoc (KDoc) using plugins. In Android Studio open Settings (press Ctrl+Alt+S), select Plugins and find kdoc. I downloaded KDoc-er, but you can choose any of them. Then restart Android Studio.
Find any class/method, type /**, press Enter. You will get a short description like:
/**
* User data
*
* #property name
* #property avatar
* #property gender
* #constructor Create empty User data
*/
class UserData(...
to generate javadoc comment use
/**
Your docs
*/
ALT+SHIFT+G will create the auto generated comments for your method (place the cursor at starting position of your method).