# Bndtools: New Quick Fixes

**URL:** <https://bnd.discourse.group/t/bndtools-new-quick-fixes/412>\
**Category:** GENERAL\
**Created:** [January 22, 2024, 2:14pm UTC](https://bnd.discourse.group/t/bndtools-new-quick-fixes/412 "2024-01-22T14:14:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkriens](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/pkriens/32/3_2.png) [@pkriens](https://bnd.discourse.group/u/pkriens)\
**Post date:** [January 22, 2024, 2:14pm UTC](https://bnd.discourse.group/t/bndtools-new-quick-fixes/412/1 "2024-01-22T14:14:54Z")

</div>

The current [Bndtools 7.1.0-SNAPSHOT Eclipse Plugin](https://bndtools.jfrog.io/bndtools/update-snapshot) has recently received a number of new quick fixes. Before we finalize them, it would be nice to get some feedback how they work in practice.

Without further ado, let’s dive into them.

## Binary, Hex, Separators

Maybe it is me, but in the embedded world hex and binary are often used. So you an now you can easily convert decimal to hex and binary and hex and binary to decimal.

![bndtools-refactor-numbers](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/ac542c01a1a00a06a20367b10ed732f8208f5980.gif)

## Versions

Originally I added a version bump in a special refactoring for the `package-info.java` file. However, then I realized this could also be useful in other source files.

![bndtools-refactor-version](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/941d0df887d31651e7461ca9dd3bad426a00055f.gif)

## Strings & Text Blocks

Make string upper case or lower case; convert strings to text blocks and text blocks to strings

![bndtools-refactor-string](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/c2aed00691bb22f075e322d9ac67dc0c77c6bcc1.gif)

## Constructor Assignment

Methods and constructors get a quick fix to assign a parameter to a field. However, this parameter is `private`. Personally I do not think class private is very useful (package private suffices for me and it makes testing easier). Then again, I am going out of my way nowadays to make fields final. So I added a fix to assign a parameter to a `final` field.  
 ![bndtools-refactor-constructor-final-field](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/bbbe983ea1db985444405409b064af48acaedbf4.gif)

## Turning Private into `final`

As stated, I really don’t like final. I know it helps to find unused fields but that is just a limitation of the compiler, you could also provide this information on package level. Less is more and private takes real estate and imho provides no value. Therefore a quick fix to change `private` field to `final`!  
 ![bndtools-private-final](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/9de6f7cbb6b0232a494ec2bcb8075716d055e379.gif)

## Export a package

If you have a `package-info.java` file, you can now export it.  
 ![bndtools-refactor-export](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/94c577264155e6964b17f4af26aecbc2d6fcdf1e.gif)

If you do not have a `package-info.java` file, you can now create it with `File/New`.  
 ![bndtools-new-packageinfo](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/9b4761e2c02e99613bf0c6f42c11b0e9ea106f27.gif)

## Declarative Services

You can now add all the Declarative Services/Component annotations with quick fixes.  
 ![bndtools-refactor-component](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/54410a55e34f91e82bb7df4a63e64aad3f5a5136.gif)

## Gogo Commands

In a recent version Gogo added an annotation @GogoCommand that simplifies making a component that can provide Gogo commands. The quick fixes for the Gogo Command assume that methods with the @Descriptor annotation are commands. It will assemble the hard to maintain `function` annotation field for you.

![bndtools-refactor-gogo](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/89b93f62ee09e11cbeb95578ac288fb56de727d0.gif)

It can also add a @Parameter annotation all filed in:

![bndtools-gogo-parameter](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/c37d4a250d569d6ce9323d404e213f76f209ef51.gif)

Oh, yeah. It can also clean up:

![bndtools-refactor-gogo-remove](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/7f4a34c47b61a8909b53466e9ed75127cb422655.gif)

## Selection

You can now expand the selection to the type the cursor is in. If the cursor is on a method declaration, it will select the whole method. If it is on a class declaration it will select the class. This makes it simpler to copy a part of the source code without having to chase the proper closing bracket.

![bndtools-selection-extend-astnode](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/09f94f15b368ef553c1e89e1bef1492b63ab2026.gif)

## Open AI

Unless you’ve been living under a rock you are aware that AI is going to revolutionize the software world. I already had been dabbling in. As an experiment, I’ve added an AI dialog to the quick fixes. It will copy the current node to a OpenAI dialog and then allows you to tell it to change the code.

![bndtools-openai-select](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/6beb9b80112a446c88d1d88b536ae7a8347e57f2.gif)  
 ![bndtools.openai](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/e97fa6d30ea909ebbee321e82e1b0b755dd6ece9.gif)

The OpenAI quick fix is only available if you set an [OpenAI API key](https://platform.openai.com/api-keys). This can be done with the following `bnd` command:

```bnd
bnd settings openai.apikey=sk-...hqyl

```

## Concluding

This is preliminary code. Quick fixes are good when you need them but unnecessary quick fixes become annoying when they are in your face. For this reason, I need feedback how they work in practice.

The OpenAI stuff is highly experimental. I am aware there is another AI assistant available for Eclipse now but I think it is worth to expand the usage of AI to bndtools. The current implementation is very much generic Java but I think AI could really help with debugging the resolving and doing things in the bnd file.

Again, feedback on this is needed. I am open to spend some significant time to make this a really cool tool if I get some engagement.

Last point. I’ve spent significant effort to make the refactoring a lot easier. If you’re interested in quickfix/refactoring support for your company annotations, let me know. I am looking for some new customers 🙂

---

<div class="post-metadata">

**Author:** ![chrisrueger](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/chrisrueger/32/18_2.png) [@chrisrueger](https://bnd.discourse.group/u/chrisrueger)\
**Post date:** [January 31, 2024, 9:58pm UTC](https://bnd.discourse.group/t/bndtools-new-quick-fixes/412/2 "2024-01-31T21:58:57Z")

</div>

Not exactly related to quick fix , but close and I though worth sharing:  
I just found out today that there is a subtle difference in the keyboard shortcuts for code completion:

`Control + Space` vs. `Control + Shift + Space`  
**⌃␣** vs. **⌃⇧␣**

I think the ChatGPT explanation is good in this regard:

> In Eclipse, there is indeed a subtle yet important difference between using Control + Space and Control + Shift + Space for code completion:
> 
> 1. **Control + Space** : This is the standard code completion shortcut. It triggers a context-sensitive dropdown list of suggestions that includes methods, variables, and other relevant code snippets based on the current context. For instance, if you start typing the name of a variable or a method, this shortcut will bring up a list of matching names that you can quickly select from.
> 2. **Control + Shift + Space** : This key combination is often used for what’s called “smart type-aware code completion.” The difference lies in its “type-aware” aspect. When you use this shortcut, Eclipse not only looks at the immediate context but also considers the expected type of the expression. For example, if you’re writing a method call and you’ve typed the method name followed by an open parenthesis, using Control + Shift + Space will suggest parameters that match the expected type for the current argument position. It’s particularly useful for filling in method arguments because it filters the suggestions to only those that are type-compatible with the expected parameter.
> 
> In summary, while both shortcuts are used for code completion, Control + Shift + Space is more contextually advanced, offering suggestions that are more finely tailored to the expected types and method signatures based on the current coding context.

`Control + Shift + Space` is what I was looking for, because it helps to see the tooltip with the parameters of a method (and the current parameter highlighted) like this:

 ![image](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/df6ed9a0a2268dedabe059748f0807f5792158a7.png)

Usually this appears also with `Control + Space` too when you start typing the method, but only if you continuously type. BUT in case you leave with the cursor to another place in the middle of typing, this little helper is gone, and I couldn’t find a way to get it back at the cursor position. Until I found `Control + Shift + Space` 🙂

---

<div class="post-metadata">

**Author:** ![pkriens](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/pkriens/32/3_2.png) [@pkriens](https://bnd.discourse.group/u/pkriens)\
**Post date:** [February 1, 2024, 8:48am UTC](https://bnd.discourse.group/t/bndtools-new-quick-fixes/412/3 "2024-02-01T08:48:49Z")

</div>

Every time I work with people that use Eclipse there are always new tips exchanged. Thanks, useful.
