ScalaDocs tags in InitelliJ? - scala

When I type out a method with parameters in IntelliJ then try to add doc tags to it, when I type
/**
I would expect that the #param and #return tags are filled out for me. How can I get that to automatically happen when I type the above
e.g.
/**
*
* #param field1
* #return String
*/
def testMethod(field1:String): String = "hi"
but instead when I do that it does this:
/**
*/
def testMethod(field1:String): String = "hi"

It is working in IntelliJ idea v11.1.2 and scala pluggin v0.5.800
Just type /** and then press "return" on top of a function. It generates the following code:
/**
*
* #param field1
* #return
*/
def testMethod(field1:String): String = "hi"
You can also try to update your scala pluggin, this feature is young.
Edit: There is an open ticket in JetBrains for the doc, but "it seems to be fixed"
http://youtrack.jetbrains.com/issue/SCL-2433#tab=Comments

Must have been a problem with my existing settings somewhere, I cleared out my settings on OSX deleting the ~/Library/Preferences/IntelliJ* folder and starting it back up, reconfiguring my IntelliJ setup. It's now working with scaladoc tags now.

Related

Why symfony FOSRest bundle doesn't find the right controller?

I have two actions:
/**
* #Rest\Get("/items/{itemId}")
*/
public function getAction(UuidInterface $id): View
And
/**
* #Rest\Get("/items/available")
*/
public function getAvailableAction() : View
The thing is that when I'm trying to call getAvailableAction by a link items/available, the getAction is being called. I guess it interprets the word available as an {itemId} somewhy.
How should I solve it?
You guessed right. Just define a proper requirement:
/**
* #Rest\Get("/items/{itemId}", requirements={"itemId" = "\d+"})
*/
If your itemId is an UUID, change the number regex from \d+ to [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12} or a simplified [a-fA-F0-9\-]{36}.
Don't forget to clear the cache.

JSDoc Class suggested layout

I'm brand new to JSDoc, and I'm trying to figure out the best way to tag my code. For some reason after I label something as a #class, I can't get anything to appear as #inner:
/**
* The logger, to simply output logs to the console (or potentially a variable)
* #class Logger
* #requires 'config/globalConfig'
*/
define(["config/globalConfig"], function (config) {
/**
* Instantiate a new copy of the logger for a class/object
* #constructor
* #param name {string} - The name of the class instantiating the logger
*/
return function (name) {
/**
* #memberOf Logger
* #type {string}
*/
this.name = name;
/**
* Place the message on the console, only for "DEV" level debugging
* #function
* #memberOf Logger
* #param message {string}
*/
this.debug = function (message) {
... some code ...
};
};
});
Right now all the members are appearing as <static>. If I add the #inner tag to any of the attributes/functions they vanish completely from the output.
Edit: I also forgot to mention. The #constructor flag doesn't seem to be working either. If I remove that entire section, it appears the same in the output. The output does not include the #param that I would like to mention with my constructor.
Please let me know if this is completely off, I'm just kind of guessing here since the JSDoc3 documentation is a bit difficult to read.
So I figured it out, still not sure if it's absolutely correct. I had to use "Logger~name" to have it appear correctly as an inner function. According to the JSDoc documentation, this ~ is "rarely used". Seems to be the only thing that works for me.
define(["config/globalConfig"], function (config) {
/**
* The logger, to simply output logs to the console (or potentially a variable)
* #class Logger
* #param name {string} - The name of the class instantiating the logger
*/
return function (name) {
this.name = name;
/**
* Place the message on the console, only for "DEV" level debugging
* #function Logger~debug
* #param message {string}
*/
this.debug = function (message) {
... code ...
};
};
});

MongoException: zero-length keys are not allowed, did you use $ with double quotes?

I'm using symfony2 and mongodb, until today, everything is OK, but I create a new document, and suddenly, appears this error :
"MongoException: zero-length keys are not allowed, did you use $ with double quotes?"
$dm = $this->get('doctrine.odm.mongodb.document_manager');
$_repo = $dm->getRepository('CantaoCustomerBundle:CustomerTags');
$_repo->findOneByCustomer($customer);
The $customer it's OK, the repository is empty, and my document class is like this :
/**
* #MongoDB\ID
**/
private $id;
/**
* #MongoDB\ReferenceOne(targetDocument="Tapronto\Mats\ProductBundle\Document\Tag", cascade={"persist"})
**/
private $tag;
/**
* #MongoDB\ReferenceOne(targetDocument="Tapronto\Mats\CustomerBundle\Document\Customer", cascade={"persist"})
**/
private $customer;
/**
* #MongoDB\Float
**/
private $points;
/**
* #MongoDB\Int
**/
private $viewed;
/**
* #MongoDB\Int
**/
private $brought;
/**
* #MongoDB\Int
**/
private $favorited;
/**
* #MongoDB\Date
* #Gedmo\Timestampable(on="create")
**/
private $createdAt;
/**
* #MongoDB\Date
* #Gedmo\Timestampable(on="update")
**/
private $updatedAt;
Can anyone help me, have some idea, I tried everything and nothing seems to work
I just fixed this by using the referenced object's ID instead of the reference object itself as my search term.
$_repo->findOneByCustomer($customer->getId());
EDIT:
That isn't throwing the exception but it isn't actually returning anything either. I tried using new MongoId($id) as was suggested a few places (Doctrine MongoDB find by id), but that didn't work either. Finally, I found something in the full query builder that searches by references (note: this uses the object instead of the object's ID).
$dm->createQueryBuilder()->find('CantaoCustomerBundle:CustomerTags')
->field('customer')->references($customer)
->getQuery()->execute();
I feel like this should be done more simply (like you did originally), but this fix is working for me.
It could be that you're trying to persist an object private attribute.
If that's not the case a good way to debug is to shut off the zero-length key check so that you can actually debug by checking what it's being written into mongo.
zero-length keys are not allowed, did you use $ with double quotes?
Code: 1
You tried to save "" as a key. You generally should not do this. "" can mess up subobject access and is used by MongoDB internally. However, if you really want, you can set mongo.allow_empty_keys to true in your php.ini file to override this sanity check. If you override this, it is highly recommended that you set error checking to strict to avoid string interpolation errors.
http://php.net/manual/en/mongo.configuration.php#ini.mongo.allow-empty-keys

How to Document following function in JSDoc JS-Toolkit

*How to Document following function in JSDoc JS-Toolkit *
I want to document try and help method in this main function
but i did not figure it out how to do that.
/** Sample doc
* #class
* #constructor
* #name Sample
*/
var main=function(){
this.value="";
/** help function
* #param {String} Name
*/
this.help=function(name){
console.log('help me'+name);
}
/** help function
* #param {String} Name
*/
this.try=function(name){
console.log('try me'+name);
}
}
I just struggled with this for several hours. I tried:
#member
#augments
#method
#this
From the examples and tutorials I found, member functions and variables should appear in the output simply by having /** description/* comments above them, but I found that was not the case. Like you, I'm using standard JavaScript constructors, where this should be able to be inferred automatically due to the #constructor being in place. Maybe there's some wrinkle I'm not seeing.
In the end, I found two tags that worked for me, #name and#memberof. They both allow you to specify the object that the property is a member of. Using #name in this way is undocumented (at least, I didn't see it anywhere), but very straightforward. You'll also need to use #function.
Here's an example with the #name tag:
/** help function
* #name Sample.try
* #function
* #param {String} Name
*/
this.try=function(name){
console.log('try me'+name);
};
And here's an example with the #memberof tag:
/** help function
* #memberof Sample
* #function
* #param {String} Name
*/
this.try=function(name){
console.log('try me'+name);
};
As you can see the output is almost the same. The only difference that I see is that #memberof includes this. in the method name. For that reason I've settled on using #name.
The remaining issue is that the functions are per-instance, not <static>.
Hope this helps!

How can I protect my methods bodies (not the attached JavaDoc and Signature) using Acceleo code-generator

I use Acceleo in order to generate code with a model I have made. I managed to protect my methods in order to protect them usinig "#generated NOT" in case I need to regenerate my code with Acceleo. The problem is that adding #generated NOT protect all the method content, that is to say the body, the signature and JavaDocs.
The thing is that I only need to keep the method body, or at least the method body and its signature, but I need the doc to be updated. How can I do this ?
Just for information here is an example of a potential generated class :
/*
* #generated
*/
public class ActeurRefEntrepriseServicesImpl implements ActeurRefEntrepriseServices {
#Autowired
HelloWorldService helloWorldService;
/**
* Service which say hello
*
* #param name
* user name
* #return print Hello username
*
* #generated NOT
*/
#Override
public void sayHello(final String name) {
helloWorldService.print(name);
}
}
Baptiste,
The #generated tags use the standard EMF protection rules : "#generated" means that the body of the block for which it is set will be generated, anything else means no re-generation. If you set something as "#generated" in any of your metamodels' generated code, you will see that there, too, the javadoc is preserved whatever the edits you do.
In short, you cannot tell EMF to re-generate anything other than the code itself.
If you need to have the body protected but not the javadoc, you have to shift from the "#generated" protection to Acceleo's [protected] blocks. i.e, change your template from :
[template generatedMethod(methodName : String)]
/**
* Some doc.
* #param param1
* param documentation.
* #generated
*/
[generateSignature(methodName)/] {
[generateBody()/]
}
[/template]
to something using a protected block :
[template generatedMethod(methodName : String)]
/**
* Some doc.
* #param param1
* param documentation.
*/
[protected (methodName)]
[generateSignature(methodName)/] {
[generateBody()/]
}
[/protected]
[/template]
With this paradigm, anything that is outside of the protected area will be regenerated, everything else will remain untouched by a regeneration.
See also the full documentation available from the Acceleo website.
If you absolutely need to use the "#generated" protection method for your model, you will need to tamper with the JMerger API from EMF and alter the launcher Acceleo generated for you in order to use your own merging strategy (see the getGenerationStrategy method from that launcher). Note that this is by no means an easy task.