CodeFormatter | Format code to move all those pesky semicolons | Runtime Evironment library
kandi X-RAY | CodeFormatter Summary
kandi X-RAY | CodeFormatter Summary
Have you ever been looking at someone's program and noticed how many annoying semicolons and brackets are in the way of their code? Well now you can move them all to the side, to keep them away from your beautiful code!.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of CodeFormatter
CodeFormatter Key Features
CodeFormatter Examples and Code Snippets
Community Discussions
Trending Discussions on CodeFormatter
QUESTION
I'm using Eclipse JDT to modify java source code. This happens in three steps:
- At first I create an instance of org.eclipse.jdt.core.dom.CompilationUnit and call it's accept() method with an ASTVisitor
- Then I manipulate the CompilationUnit. I remove and add ASTNodes to the tree (this is not shown here)
- Then I write compilationUnit.toString() back to a file.
Creation of the compilation unit:
...ANSWER
Answered 2019-Sep-17 at 20:33I believe you start losing information when you do compilationUnit.toString()
. Later when you format the text, you finally lose any existing formatting.
Instead, I recommend to learn how to use ASTRewrite
, which allows you to incrementally apply your changes into the existing AST. The goal is to let the rewrite generate the minimal TextEdit
s that can be applied
to the (original!) document.
If using ASTRewrite
inside your visitor is not an option, you could even try using ASTRewrite
in "recording" mode, see org.eclipse.jdt.core.dom.CompilationUnit.recordModifications()
.
QUESTION
I'm trying to make use of the extension point org.eclipse.cdt.core.CodeFormatter
but it seems to have no effect. Unfortunately I cannot find any example. The extension point description isn't very comprehensive.
My plugin.xml looks like this:
...ANSWER
Answered 2019-Jul-09 at 21:35Declaring your formatter in plugin.xml
just makes it available as a formatter.
If you want to use it as the current formatter, you have to select it in the preferences UI (Preferences -> C/C++ -> Code Style -> Formatter, there should be a drop-down with your formatter's name as one of the options).
(The above selection affects the entire workspace. You can also choose a formatter on a per-project basis in Project Properties -> C/C++ General -> Formatter.)
That said, note the caveat in greywolf82's comment.
UPDATE: To answer your comment, yes, I believe the current formatter can be changed programmatically via CDT's public API. I would expect something like the following to work:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install CodeFormatter
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page