eclipse-jdt / eclipse-jdt/eclipse.jdt.core

[Formatter] Javadoc formatter sometimes incorrectly encodes `@` to `@` inside {@code} blocks

Open
#4,874 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

The formatter incorrectly encodes certain `@` symbols that are included in `

 {@code` javadoc blocks. I am not sure the rules for encoding the `@` on annotations, it doesn't appear to break anything but encoding it on a `{@code` does break the javadoc rendering.

Possibly related to: https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2071

Reproduction Input:

```
/**
* Example showing formatter bug with {@code @} in pre blocks.
*
*

   * {@code

* @MyAnnotation
* public class Example {
*
* @AnotherAnnotation
* private String field;
* }
* }
*

*/
public interface ExampleService {

/**
* Another method with annotation in javadoc.
*
*

       * {@code

* @Override
* public void doSomething() {
* // implementation
* }
* }
*

*/
void doSomething();
}
```

---

With "Enable Classic Javadoc formatting" : False
With "Format Java code snippets inside 'pre' tags": False
Result: No Change

---

With "Enable Classic Javadoc formatting" : True
With "Format Java code snippets inside 'pre' tags": False
Result: `@`'s on some Annotations are converted to `@`

```
/**
* Example showing formatter bug with {@code @} in pre blocks.
*
*

 * {@code

* @MyAnnotation <--- Possible error
* public class Example {
*
* @AnotherAnnotation <--- Why did this not get encoded
* private String field;
* }
* }
*

*/
public interface ExampleService {
/**
* Another method with annotation in javadoc.
*
*
	 * {@code

* @Override <--- Possible error
* public void doSomething() {
* // implementation
* }
* }
*

*/
void doSomething();
}
```
---

With "Enable Classic Javadoc formatting" : True
With "Format Java code snippets inside 'pre' tags": True
Result: `@`'s on some Annotations _and_ some `{@code` are converted to `@`

```
/**
* Example showing formatter bug with {@code @} in pre blocks.
*
*

 * {

* @code <--- Definitive error
* @MyAnnotation
* public class Example {
* @AnotherAnnotation
* private String field;
* }
* }
*

*/
public interface ExampleService {
/**
* Another method with annotation in javadoc.
*
*
	 * {@code

* @Override
* public void doSomething() {
* // implementation
* }
* }
*

*/
void doSomething();
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.