IntelliJ and plugin land

I was looking at one of my earlier posts and all the replies to it. Frankly, I am not sure which ones are genuine requests and which ones are sarcastic.

http://www.intellij.net/forums/thread.jsp?forum=22&thread=54765&tstart=0&trange=30

However, this made me think about where is the line where IntelliJ functionality crosses into the plug-in land and does it make sense for some of this add-on functionality to be a plugin (and possibly made availble as open source to the IntelliJ community). To be specific, at what point the code reformatting is better of being a plug-in rather than core functionality.

I would not do Java development without IntelliJ but code reformatting just seems like something that could live outside.

18 comments

BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I don't know, I've gotten so used to code reformatting that I can't live
without it, and have a hard time even sometimes reading files which are
not formatted the way I'm used to seeing them.

R

Vinay Moharil wrote:

| I was looking at one of my earlier posts and all the replies to it.
Frankly, I am not sure which ones are genuine requests and which ones
are sarcastic.
|
|
http://www.intellij.net/forums/thread.jsp?forum=22&thread=54765&tstart=0&trange=30
|
| However, this made me think about where is the line where IntelliJ
functionality crosses into the plug-in land and does it make sense for
some of this add-on functionality to be a plugin (and possibly made
availble as open source to the IntelliJ community). To be specific, at
what point the code reformatting is better of being a plug-in rather
than core functionality.
|
| I would not do Java development without IntelliJ but code reformatting
just seems like something that could live outside.
-


BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE/vBIfcV9vuB27SARAjqHAJ0eyLMQ58ymBqlovQMK5khFBO97gCg1hbz
71sVmpqENgBC4ZfKgY1lg3Q=
=1cSd
-


END PGP SIGNATURE-----

0

I agree, but that does not address the thrust of this post, which is, I think, that it would be best if it were possible to interject a plugin into the code formatting engine. There are several code formatting idiosynchracies I employ that seem to be of little interest to the community at large, but are things that I cannot live without. For example, I would love to be able to format multi-line methods so that the curly brace appears on a new line, but for single line methods it should appear at the end. This request was blithely ignored by JetBrains so I would love the ability to write a plugin to do this myself. I do not think this is possible right now.

0

BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ah I see. Yes I think in general it would be great to open most of not
ALL APIs for that matter so that developers can extend idea any which
way they want. Of course that's a lot of work for the JetBrains folks.

The other thing that comes to mind is that of all the IDEs I've used,
IDEA has by far the best code reformatting out there, and I wonder if
there is some seriously proprietary stuff in there they don't want us to
use or extend, perhaps pattent pending issues. Dunno. So far when
there is a need to open they API they've done it.

I'm sure there's a reason.

R

Kirk Woll wrote:

| I agree, but that does not address the thrust of this post, which is,
I think, that it would be best if it were possible to interject a plugin
into the code formatting engine. There are several code formatting
idiosynchracies I employ that seem to be of little interest to the
community at large, but are things that I cannot live without. For
example, I would love to be able to format multi-line methods so that
the curly brace appears on a new line, but for single line methods it
should appear at the end. This request was blithely ignored by
JetBrains so I would love the ability to write a plugin to do this
myself. I do not think this is possible right now.
-


BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE/vBsj+cV9vuB27SARAuRsAJ0Yi5K1dXH7ABqjZ/C5CcMUk7TMHwCffqh4
pNpL/QO67qK1AFZetexnEg0=
=PV8W
-


END PGP SIGNATURE-----

0

For example, I would love to be able to format multi-line methods so that

the curly brace appears on a new line, but for single line methods it should
appear at the end. This request was blithely ignored by JetBrains so I
would love the ability to write a plugin to do this myself. I do not think
this is possible right now.

It is covered by Work in progress/Keep simple methods in one line, isn't it?

--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"


"Kirk Woll" <kirk@digimax.com> wrote in message
news:15789101.1069290854280.JavaMail.itn@is.intellij.net...

I agree, but that does not address the thrust of this post, which is, I

think, that it would be best if it were possible to interject a plugin into
the code formatting engine. There are several code formatting
idiosynchracies I employ that seem to be of little interest to the community
at large, but are things that I cannot live without. For example, I would
love to be able to format multi-line methods so that the curly brace appears
on a new line, but for single line methods it should appear at the end.
This request was blithely ignored by JetBrains so I would love the ability
to write a plugin to do this myself. I do not think this is possible right
now.


0

I'm sure there's a reason.

Exactly. As the matter of fact core formatting engine is somewhat more than
just pretty print. It should be able to perform as local as possible. This
is used in most refactorings and generation features.

--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"


"Robert S. Sfeir" <robert@codepuccino.com> wrote in message
news:bph5v4$qo2$1@is.intellij.net...

---BEGIN PGP SIGNED MESSAGE---
Hash: SHA1

>

Ah I see. Yes I think in general it would be great to open most of not
ALL APIs for that matter so that developers can extend idea any which
way they want. Of course that's a lot of work for the JetBrains folks.

>

The other thing that comes to mind is that of all the IDEs I've used,
IDEA has by far the best code reformatting out there, and I wonder if
there is some seriously proprietary stuff in there they don't want us to
use or extend, perhaps pattent pending issues. Dunno. So far when
there is a need to open they API they've done it.

>

I'm sure there's a reason.

>

R

>

Kirk Woll wrote:

>

| I agree, but that does not address the thrust of this post, which is,
I think, that it would be best if it were possible to interject a plugin
into the code formatting engine. There are several code formatting
idiosynchracies I employ that seem to be of little interest to the
community at large, but are things that I cannot live without. For
example, I would love to be able to format multi-line methods so that
the curly brace appears on a new line, but for single line methods it
should appear at the end. This request was blithely ignored by
JetBrains so I would love the ability to write a plugin to do this
myself. I do not think this is possible right now.
---BEGIN PGP SIGNATURE---
Version: GnuPG v1.2.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

>

iD8DBQE/vBsj+cV9vuB27SARAuRsAJ0Yi5K1dXH7ABqjZ/C5CcMUk7TMHwCffqh4
pNpL/QO67qK1AFZetexnEg0=
=PV8W
---END PGP SIGNATURE---

>


0

It is covered by Work in progress/Keep simple methods in one line, isn't it?


No, I don't think so. I want methods that are long to render like so:

I want short methods to render like so:

"Work in progress/Keep simple methods in one line" checked results in something like:

Not something I will ever have enabled.

0

Oh, and for the curious, the reason I like this style is because I find the following to be incredibly ugly and confusing:

It is very difficult to distinguish the third parameter in the method to the first statement in the method. I consider that very bad. Yet I like consolidating the brace to the end of the line when it fits on a single line.

0

Well, I see. Does this has a feature request in tracker? I can't promise
this will be implemented in Aurora but it sounds reasonable and I'd like
to have it myself.

0

Just to let you know, this doesn't work for me. It never converts methods with single-line bodies to single-line method definitions. The same with if statements and so on. I thought I filed a request, but it was ignored, so I thought this wasn't planned.

0

Um, yeah:

http://www.intellij.net/tracker/idea/viewSCR?publicId=5059
http://www.intellij.net/tracker/idea/viewSCR?publicId=3528
http://www.intellij.net/tracker/idea/viewSCR?publicId=6246
http://www.intellij.net/tracker/idea/viewSCR?publicId=6944
http://www.intellij.net/tracker/idea/viewSCR?publicId=14275

I don't mean to be testy, but this is why I often feel frustrated with filing tracker requests. What should I do in this situation? Should I resubmit the same tracker request over and over? Should I post a message on the forum? I've repeatedly expressed my displeasure with the voting paradigm. Frankly, I think if a request has a litany of duplicates, many people want this feature. I do not understand why a feature like this would need to be voted upon. Oh, but wait, Aspects was voted as an integral feature of Idea and resources had to be allocated to that.

0

Keith Lea wrote:

Just to let you know, this doesn't work for me. It never converts methods with single-line bodies to single-line method definitions. The same with if statements and so on. I thought I filed a request, but it was ignored, so I thought this wasn't planned.

Absolutely true since option is called keep and has nothing to
convert existing code. It just prevents formatter from breaking one-line
methods/blocks into multiline. Though it would work if you switch off
"keep line breaks when reformatting" option.

0
 public void myLongMethod(Object parm1, Object parm2,
>     Object parm3) {
>     Object myVariable = parm3;
>     System.out.println(parm3);
> }]]>


That's why Sun's conventions recommend that you indent your
continuating line at 8, as in:


I was using your technique in the past (or moving the brace down in
your example) but I've found that Sun's way makes brace placement
more consistent while still providing good readability.

Vince.



0

And of course aligning with the open parenthesis achieves the same:


N.

Vincent Mallet wrote:

>>

>public void myLongMethod(Object parm1, Object parm2,
>>    Object parm3) {
>>    Object myVariable = parm3;
>>    System.out.println(parm3);
>>}]]>


That's why Sun's conventions recommend that you indent your
continuating line at 8, as in:

 public void myLongMethod(Object parm1, Object parm2,
>         Object parm3) {
>     Object myVariable = parm3;
>     System.out.println(parm3);
> }]]>


I was using your technique in the past (or moving the brace down in
your example) but I've found that Sun's way makes brace placement
more consistent while still providing good readability.

Vince.



0

I'm pretty sure it doesn't work with "keep line breaks" but I can't test it right now. I found my request for this: http://www.intellij.net/tracker/idea/viewSCR?publicId=16762

0

Sure, and that's why we have our own code formatting preferences that Idea (usually) supports quite well. Frankly, I think what you have is just as ugly. It's purely aesthetic, but that empty space before "Object parm3" without the opening brace providing opening symmetry looks horrible to me.

0

When additional reformatting requirements have come up in the past, we've resorted to writing our own plugins, like Tabifier and Rearranger (mine) and Reformat (Timur's). The Reformat plugin calls the IDEA code reformatter and then does its own additional formatting. Tabifier and Rearranger can chain from Reformat. So with one keystroke, you get code reformatting, import optimization, any additional Reformat plugin reformatting (it has 3 minor features), "tabification" and rearrangement. Of course, since IDEA added the ability to automatically optimize imports after reformatting, the main function of the Reformat plugin is obsolete.

In my experience (of writing the tabifier plugin, which is just a glorified code reformatter) I don't think it would be feasible to externally add functionality to the IDEA "reformat code" tool; as Maxim implied, it's not designed that way. It has to do a traversal of the syntax (Psi) tree, and the code to place an open parend on one line or another based on some other criteria is very likely embedded as an inner class to their PsiRecursiveElementVisitor class, which itself is probably instantiated as an inner class to another P.R.E.V. class or called recursively from it.

I think it would be inefficient to perform code reformatting "outside IntelliJ" -- the Psi (program structure information) syntax tree is essential for obtaining all sorts of useful information necessary for reformatting.

What would be nice, however, is a way to do what the Reformat plugin does: provide an ability to register for callback, so when the IDEA code reformatter runs, it automatically invokes the other plugins. It would have to pass selection data, as the Reformat plugin does, so that subsequent plugins know what the selection is. They in turn would be able to modify the selection and pass it on to the next. (The selection can change size and position based on insertion or deletion of characters.) Finally, there should be support for a progress bar that each of the subsequent plugins can control (displaying their name, the file they are operating on if multiple files are being formatted, and the progress.)

In the meantime, the request that was discussed in this topic (about placing a method's opening brace on the same or next line) could be handled either by Reformat or Tabifier plugins. +(Timur, are you out there? Do you want to enhance Reformat to do this?) +I was keeping Tabifier out of the business of joining or breaking lines, but it looks inevitable, so I could add this feature to the Tabifier also. That would only make sense though if folks here want to Tabify. Otherwise it should be a standalone plugin.

I've submitted a feature request at http://www.intellij.net/forums/thread.jsp?nav=false&forum=15&thread=55842; please vote for it if you'd like to have the ability to run additional formatting tools automatically after the IDEA reformatter.

-Dave

0

Please sign in to leave a comment.