Velocity variables support

Hi,

how can I have IDEA to recognize Velocity variables ($request and $link for instance), coming from toolbox.xml and other VelocityStruts and VelocityView projects?

thanks
-nodje

21 comments
Comment actions Permalink

Have you tried to invoke intentions (Alt+Enter) on these variables'
references? They offer a variety of ways to make IDEA know about those
variables, by specifying them in comments in various places.

Hi,

how can I have IDEA to recognize Velocity variables ($request and $link for instance), coming from toolbox.xml and other VelocityStruts and VelocityView projects?

thanks
-nodje

---
Original message URL: http://www.jetbrains.net/devnet/message/5228495#5228495

0
Comment actions Permalink

Hi,

I've tried that yes, but nothing sounded satisfying in this regard.
Apart from managing the alert, I'm proposed to 'Define Implicit Variable' at different scopes.

Help states:
Velocity-specific intention actions:
Define Implicit variable in comment
Define macro library reference in comment
Define velocity.properties file reference in comment

It's a littlebit more clear than what's displayed upon pressing alt+enter, and sounds like what I'm looking for.
But, I can't see anything happening when I enable one of them.

I just don't know how to use this I think

cheers

0
Comment actions Permalink

It's a littlebit more clear than what's displayed upon pressing alt+enter, and sounds like what I'm looking for.
But, I can't see anything happening when I enable one of them.


Try to define implicit variable in comment in current file? Does nothing
still happen?

0
Comment actions Permalink

Actually no, nothing happens!
It just changes the 3 options to "Disable" instead of "Enable", but nothing changes in my file and I still get the 'Cannot resolve variable 'var' ' alert.

cheers

0
Comment actions Permalink

Actually no, nothing happens!
It just changes the 3 options to "Disable" instead of "Enable", but nothing changes in my file and I still get the 'Cannot resolve variable 'var' ' alert.


Which options, where did you find them? You should press Alt+Enter on an
unresolved Velocity variable, select the item 'Define implicit variable
in comment (in current file)', press Enter. A comment should be added to
your file then.

0
Comment actions Permalink

I mean the 3 different 'Define implicit variable' options you get when pressing Alt+Enter.
Nothing is added to my file when I select 'Define implicit variable in comment' or any of them.

0
Comment actions Permalink

What do you mean by 'just changes the 3 options to "Disable" instead of
"Enable"' then?

Does this reproduce in any file? I mean, if you just create an empty
Velocity file and type something like $asdf there, invoke this
intention, will anything happen?

0
Comment actions Permalink

Hi, nodje

Do you mean that you did disable/enable action on "Define implicit variable" intention? Am I wrong?
Anyway, you can post or email me that file and I'll try to reproduce the bug.

Alexey

0
Comment actions Permalink

Ok, I've been able to get this to work on another project.
I understand how this works now.

There's probably something wrong with the original project, but I should be able to fix that, and if not to manually add the @vtlvariable directives.

That said, this covers the basic cases, but how do you handle cases like this one for instance:

#foreach( $task in $request.getAttribute("executingTasks") )

I have defined $request as being a javax.servlet.http.HttpServletRequest, and this works fine.

But how can I define what $task is? Velocity doesn't require any Cast or strong typing.

Any subsequent call on $task receive a 'Cannot resolve properties ...', even with $task defines as directive.

cheers

0
Comment actions Permalink

The reason of those messages  'Cannot resolve property/method ...' is unknown runtime class of $task.
Class of a loop variable can be computed by Velocity support if there is an expression with proper "velocity-iterable" class (e.g. Iterator, Collection, Map, array) after in keyword within #foreach directive.
But HttpServletRequest#getAttribute() declared as returning just Object in other words actual runtime class of returned object is unknown, so as runtime class of loop variable $task.

0
Comment actions Permalink

Hello Alexey,

I have a suggestion. I was hitting similar issue. I have a code generation
framework which builds UML-like model and than use velocity to generate
source code from the model. The model is writteng to interfaces but have
several layers of decorators for different outputs. So knowable design time
API is far less specific than actual runtime implementation of the model
interfaces. It would be really nice if we could annotate not just variables
but properties of them

for example

#foreach($assoc in $table.associations)

#end

would be resolved to Table interface where at runtime in a specific velocity
template it is JdoAssociation with much more stuff than its super type
Table. If I could specify that $table.associations were
Collection or may be more generically once I specified $table as JdoTable, I can specify that JdoTable.getAssociations() returns Collection that would let me quickly specialize my model to its runtime implementation classess and use autocompletion and inspections properly. As it stands now I had to turn my inspections off because they produce to many warnings due to inability ro recognize properties of my model classess Alex "Alexey Chmutov" ]]> wrote in message
news:2111632.13841228908139870.JavaMail.clearspace@app4.labs.intellij.net...

The reason of those messages 'Cannot resolve property/method ...' is
unknown runtime class of $task.
Class of a loop variable can be computed by Velocity support if there is
expression with proper "velocity-iterable" class (e.g. Iterator,
Collection, Map, array) after in keyword within #foreach directive.
But HttpServletRequest#getAttribute() declared as returning just Object in
other words actual runtime class of returned object is unknown, so as
runtime class of loop variable $task.

>

---
Original message URL:
http://www.jetbrains.net/devnet/message/5228654#5228654



0
Comment actions Permalink

well well
in my deficient project, even if I manually add the velocity_implicit.vm file, the *.vm files won't recognize it, it seems.
Is there something I could specify in IDEA in order to force it recognize 'velocity_implicit.vm' or is it an automatic process?

I haven't seen anything related in the iml/ipr in my working project.

cheers

0
Comment actions Permalink

Any Velocity file will be considered as "implicitly included" provided it starts with line #* @implicitly included *#
And name of that file doesn't matter.
Moreover, no need to create implicitly included Velocity file manually: if no such file found then new one will be created by any "Define...externally" intention.
As I've recently discovered, *.vm file type registered to Text files not Velocity files by default. So make sure that your implicitly included file is considered as Velocity file by IDEA.
Possibly we should change default mapping for *.vm file type.

0
Comment actions Permalink

Hello Alex,

In current state, a runtime class of an expression cannot be specified.
But we can implement support of something like this (as it's done for @vtlvariable):
#* @vtlexpression value="$var.meth($arg1, $arg2).prop1.prop2"   type="java.util.Collection<my.pack.MyClass>"*#

0
Comment actions Permalink

That would be great!

"Alexey Chmutov" <no_reply@jetbrains.com> wrote in message
news:27079922.22771228995948087.JavaMail.clearspace@app4.labs.intellij.net...

Hello Alex,

>

In current state, a runtime class of an expression cannot be specified.
But we can implement support of something like this (as it's done for
@vtlvariable):

    • @vtlexpression value="$var.meth($arg1, $arg2).prop1.prop2"

type="java.util.Collection<my.pack.MyClass>"*#

>

---
Original message URL:
http://www.jetbrains.net/devnet/message/5228759#5228759



0
Comment actions Permalink

Hello Alexey,

this is the problem I was facing with one of my IDEA project, "Define... externally" would NOT create anything (comment or file).
That's why I decided to create it manually.
It does work now that you mentioned that the first line MUST contain #* @implicitly included *#.
My files had a SVN $Id$ keyword instead, causing the problem.

+1 for #* @vtlexpression value="$var.meth($arg1, $arg2).prop1.prop2"   type="java.util.Collection<my.pack.MyClass>"*#, thay'd be great!

cheers

0
Comment actions Permalink

Yeah - it is a little bit double-confetti to both have tools defined in toolbox.xml AND velocity_implicit.vm:

toolbox.xml:

<tool>
<key>esc</key>
<scope>application</scope>
<class>no.klp.cms.polopoly.front.util.KlpEscapeTool</class>
</tool>

velocity_implicit.vm (necessary for IntelliJ recognition, autocompletion, goto, etc.):

#* @vtlvariable name="esc" type="no.klp.cms.polopoly.front.util.KlpEscapeTool" *#
0
Comment actions Permalink

Yes, this could be improved. Could you please file a feature request to https://youtrack.jetbrains.com and reference the documentation for these tools there?

0
Comment actions Permalink

Nah - I'm too lazy for that - you do it.

Also if you could support userdirective in velocity.properties that would be cool too: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206277599-Recognizing-Velocity-user-directives

Good luck

0
Comment actions Permalink

I'd love to, but I can't do it without the specification describing the feature, to understand what exactly IDEA should do. That's why I asked for a link to documentation.

For user directives, please vote for https://youtrack.jetbrains.com/issue/IDEABKL-7455

0
Comment actions Permalink

Okay I'll see if I can remember to do it tomorrow.

The documentation for velocity is full of holes - the documentation says one thing while you should actually write something slightly different - and this 'directives' documentation is just downright useless: http://velocity.apache.org/engine/1.7/user-guide.html#directives

0

Please sign in to leave a comment.