We have lot of java files which were developed using a code formatter ,code style (has copyright info) templates. Now we decided to update the formatter and style template. Is it possible to update all the java files based on the new code formatter and code style templates?
It is a tedious process to manually go and edit all copy right statements in the java files. So if we could do it quickly, it will be very helpful for us.
We are using eclipse v3.4 for our development.
Eclipse 3.4 is quite old, so I'm not 100% sure this feature is available...
Right-click on the project or package you want to format, and select Source > Format.
That will only apply the format settings selected in Preferences/Java/ Code Style/Formatter. It will not add or alter code or comments. You choose a template when you create a new class/file.
yes, manually this works with Ctrl-Shift-f, which autoformats the current code / class, with the formatting rules.
For full automatic reformatting via batch you need further answers. But beware sometimes the rukles can destroy the readability of some special classes.
I would prefer manually go throug all classes, and apply Ctrl-Shift-f.
During this you might see, than some formatting rules should be adapted.
Related
ItelliJ IDEA can be called from command line on a single file - as described in here:
Running IntelliJ IDEA as a Diff or Merge Command Line Tool
Intellij like Text Editor (which BTW does not answer my question!)
However, it seems that you have to provide IntelliJ with a project, as described here:
Opening Files from Command Line
In the command line, type the following:
[IntelliJ IDEA] [path1] --line [number] [path2]
where:
[IntelliJ IDEA] is the platform-specific product launcher
[path1] is the path to the project that contains the desired file
[number] is the number of the line, where the caret should rest
[path2] is the path to the file to be opened
Is there a way of using a "light version" of IntelliJ IDEA as a pure file editor, without a project?
IntelliJ IDEA is especially good editor for some file types, such as Java, XML, HTML, ... I'd like to associate it with these types and use it from Total Commander, but currently Idea opens too slowly with all the project overhead. And I sometimes need to edit files across the projects.
UPDATE: It's now supported using the LightEdit mode.
Original answer:
It's not possible at the moment, there is a related request (created 11 Dec 2010), you can vote for:
IDEABKL-5939 using IDEA as a general-purpose text editor
Since IntelliJ IDEA 2020.1, there is LightEdit Mode. It's really light :)
LightEdit mode lets you use IntelliJ IDEA’s text editing features without creating or opening a dedicated project. In LightEdit mode, a file is opened in a separate editor window which may coexist with other (project) windows.
The mode has certain limitations: it offers simpler code completion (or sometimes none at all), no code inspections, only basic code highlighting that doesn’t require sophisticated code analysis, and so on. But if you just need to open a single file, make a few changes, and save, LightEdit is the quickest way to do it, and you don’t have to use a third-party editor either.
The upcoming JetBrains Fleet editor should fit the bill, when it is eventually released (probably some time in 2022). LSP is probably the greatest recent invention in the area of programmer tooling. I'm glad Microsoft spearheaded it sufficiently and it is now seeing adoption from JetBrains.
In the meantime, there is LightEdit mode, or simply switch to some other editor for the task.
I am currently using SequenceDiagram Plugin from https://plugins.jetbrains.com/plugin/8286?pr= to generate Sequence Diagrams.
But here the drawback is that I am not able to save them in a format like .uml or any other format so anyone can open this file and edit it.
It only allows to export the sequnce diagram as an image.
Is there any way to save the sequence diagrams generated so they can be edited later?
As the file https://github.com/Vanco/SequencePlugin/blob/master/src/org/intellij/sequencer/diagram/app/actions/ExportAction.java shows the plugin is able to export into images only. According to the licence you can modify the software if you keep in mind this part of the licence.
I think it is a good feature you suggested, it is not an easy job tho. If you plan to extend the feature try to contact with https://github.com/Vanco. I think it would be a handy thing for all of us!
Edit:
I posted it as a comment, but it is part of the answer:
Here is a github repo: https://github.com/sherif181/java-sequence-diagram-generator it is not a plugin but looks handy for your case. It will generate LaTex documents that could be edited.
Is this possible?
Here is the problem I am trying to solve:
I have 3 configuration files one .ini, one .config, and one .json
Then I have a bunch of SQL files that have sort-of a customized version of sql in them.
I need to do some syntax validation on these files, and I also added syntax highlighting. In the performSave function I made a call to the validator.
It would be nice to have this update dynamically as you typed, but I couldn't figure that part out just yet.
My problem is this: most of these config files and sql files have our own special brand of syntax, but the JSON file is just a regular old json file so it seems silly to create my own editor and re implement syntax coloring for something so widely in use. I was hoping that I could just extend a current existing editor already in eclipse then just add my hooks where I need them.
Heres what I have done so far:
I created some Eclipse plugins for work ing with these files. Most notably I have created a .sql editor, a .config editor, and a .ini editor. So for the most part I know how to create an editor and do my syntax coloring and problem marking etc. I would just like to ride the coat tails of someone who has already created a JSON editor so that all I need to add is my validation calls.
If you have any insight into extending an existing editor that would be great.
Also any help with where to put my validator call to mark up files while they are being created except on a save would be awesome too.
-Best,
Jeff
Have you considered using Xtext to get a feature rich editor (on the fly syntax correction, code completion etc..) rather than implementing from scratch ?
For JSON, the grammar fits in a few lines :
https://gist.github.com/nightscape/629651
Just build a "New->Xtext Project", then stick this grammar into it and run as "Generate Xtext artifacts", you'll get an extensible editor in no time.
There is a feature to add validation rules checked on the fly easily using Java or Xtend.
I am aware of http://omnidroid.googlecode.com/svn/tools/Eclipse_Formatter-ITP_Conventions.xml that can be imported into my Android projects Formatter , but it doesn't enforce naming convention standards. I know there are many standards available per project but I'd rather if there were rules set to ensure it. Is there another XML file I can import into my formatter to ensure such? Something like the Resource Style Rules at the end of the page at https://github.com/iamshanedoyle/Android-CodingConvention would be great to have, but I don't really know how to code this into the XML file?
Formatter can only help you to maintain formatting.
Also check the Code Style part of the project configuration, like variable prefixes and suffixes; those help to use Content Assist for example with getters: if you have a member named m_x and prefix is set to m_ you get a suggestion for getX()/setX(T) upon pressing Ctrl+Space; without it, you'd get a funny getM_x() suggestion.
The best solution to your problem may be setting up PMD/Checkstyle for your project and failing build in CI if invalid code is submitted.
I sometimes set all these up together, so Formatter/Code Style helps to write code which adheres to PMD/Checkstyle rules. Also I set up Save Actions in Eclipse so that I don't have to press Ctrl+Shift+F and Ctrl+Shift+O, etc. repeatedly, just a simple Ctrl+S does the work.
I've been using WinMerge, Eclipse's compare tool and Tortoise's to see my changes before committing. The problem is that when I edit a file that hasn't been edited by someone else since we last updated our autoformatter-configuration I'll see many, many changes caused by the autoformatter.
Now I have to copy the code from the previous revision, autoformat it in Eclipse and copy it into WinMerge to only see I really made.
Is there a tool that can automatically autoformat both versions of the file I'm comparing?
Any diff tool that allows you to set up an external conversion before the comparison should handle that. External conversions are primarily intended for things like Word/Excel/PDF to Text conversion, but you can do anything you want as long as you can run it from the command line.
For Beyond Compare we already have an optional add-on rule that will use Jalopy to format Java source and another one that use HTML Tidy for HTML files.
WinMerge doesn't look like it supports a Java reformatter out of the box, but their plugins page does describe how you could add one using a dll or Windows Scripting Host scriptlet.