Skip to content

Commit

Permalink
Merge pull request #206 from Ladicek/improve-annotation-string
Browse files Browse the repository at this point in the history
improve AnnotationInstance.toString() when the annotation only has the "value" member
  • Loading branch information
Ladicek authored May 25, 2022
2 parents 7fea727 + 497b8f2 commit c9779b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 5 additions & 1 deletion core/src/main/java/org/jboss/jandex/AnnotationInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,11 @@ public boolean runtimeVisible() {
public String toString(boolean simple) {
StringBuilder builder = new StringBuilder("@").append(simple ? name.local() : name);

if (values.length > 0) {
if (simple && values.length == 1 && values[0].name().equals("value")) {
builder.append("(");
builder.append(values[0].toString(false));
builder.append(')');
} else if (values.length > 0) {
builder.append("(");
for (int i = 0; i < values.length; i++) {
builder.append(values[i]);
Expand Down
14 changes: 9 additions & 5 deletions core/src/main/java/org/jboss/jandex/AnnotationValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,12 @@ public AnnotationInstance[] asNestedArray() {
}

public String toString() {
return toString(true);
}

String toString(boolean includeName) {
StringBuilder builder = new StringBuilder();
if (name.length() > 0)
if (includeName && name.length() > 0)
builder.append(name).append(" = ");
return builder.append(value()).toString();
}
Expand Down Expand Up @@ -581,9 +585,9 @@ public Kind kind() {
return Kind.STRING;
}

public String toString() {
String toString(boolean includeName) {
StringBuilder builder = new StringBuilder();
if (super.name.length() > 0)
if (includeName && super.name.length() > 0)
builder.append(super.name).append(" = ");

return builder.append('"').append(value).append('"').toString();
Expand Down Expand Up @@ -1239,9 +1243,9 @@ AnnotationValue[] asArray() {
return value;
}

public String toString() {
String toString(boolean includeName) {
StringBuilder builder = new StringBuilder();
if (super.name.length() > 0)
if (includeName && super.name.length() > 0)
builder.append(super.name).append(" = ");
builder.append('[');
for (int i = 0; i < value.length; i++) {
Expand Down

0 comments on commit c9779b8

Please # to comment.