Skip to content

Commit

Permalink
Exclude prefix handling for enums in convert method
Browse files Browse the repository at this point in the history
  • Loading branch information
jevanlingen committed Feb 10, 2025
1 parent 888fd2e commit ab07902
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1655,12 +1655,8 @@ public J visitWildcard(WildcardTree node, Space fmt) {
return null;
}
try {
String prefix;
if (t instanceof JCNewClass && (((JCNewClass) t).type.tsym.flags() & Flags.ENUM) != 0L) {
prefix = "";
} else {
prefix = source.substring(cursor, indexOfNextNonWhitespace(cursor, source));
}
String prefix = t instanceof JCNewClass && hasFlag(((JCNewClass) t).type.tsym.flags(), Flags.ENUM) ? ""
: source.substring(cursor, indexOfNextNonWhitespace(cursor, source));
cursor += prefix.length();
@SuppressWarnings("unchecked") J2 j = (J2) scan(t, formatWithCommentTree(prefix, (JCTree) t, docCommentTable.getCommentTree((JCTree) t)));
return j;
Expand Down Expand Up @@ -2040,7 +2036,11 @@ private void cursor(int n) {
}

private boolean hasFlag(ModifiersTree modifiers, long flag) {
return (((JCModifiers) modifiers).flags & flag) != 0L;
return hasFlag(((JCModifiers) modifiers).flags, flag);
}

private boolean hasFlag(long flags, long flag) {
return (flags & flag) != 0L;
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1738,12 +1738,8 @@ public J visitWildcard(WildcardTree node, Space fmt) {
return null;
}
try {
String prefix;
if (t instanceof JCNewClass && (((JCNewClass) t).type.tsym.flags() & Flags.ENUM) != 0L) {
prefix = "";
} else {
prefix = source.substring(cursor, indexOfNextNonWhitespace(cursor, source));
}
String prefix = t instanceof JCNewClass && hasFlag(((JCNewClass) t).type.tsym.flags(), Flags.ENUM) ? ""
: source.substring(cursor, indexOfNextNonWhitespace(cursor, source));
cursor += prefix.length();
Space p = formatWithCommentTree(prefix, (JCTree) t, docCommentTable.getCommentTree((JCTree) t));
@SuppressWarnings("unchecked") J2 j = (J2) scan(t, p);
Expand Down Expand Up @@ -2121,7 +2117,11 @@ private void cursor(int n) {
}

private boolean hasFlag(ModifiersTree modifiers, long flag) {
return (((JCModifiers) modifiers).flags & flag) != 0L;
return hasFlag(((JCModifiers) modifiers).flags, flag);
}

private boolean hasFlag(long flags, long flag) {
return (flags & flag) != 0L;
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1766,12 +1766,8 @@ public J visitWildcard(WildcardTree node, Space fmt) {
return null;
}
try {
String prefix;
if (t instanceof JCNewClass && (((JCNewClass) t).type.tsym.flags() & Flags.ENUM) != 0L) {
prefix = "";
} else {
prefix = source.substring(cursor, indexOfNextNonWhitespace(cursor, source));
}
String prefix = t instanceof JCNewClass && hasFlag(((JCNewClass) t).type.tsym.flags(), Flags.ENUM) ? ""
: source.substring(cursor, indexOfNextNonWhitespace(cursor, source));
cursor += prefix.length();
// Java 21 and 23 have a different return type from getCommentTree; with reflection we can support both
Method getCommentTreeMethod = DocCommentTable.class.getMethod("getCommentTree", JCTree.class);
Expand Down Expand Up @@ -2154,7 +2150,11 @@ private void cursor(int n) {
}

private boolean hasFlag(ModifiersTree modifiers, long flag) {
return (((JCModifiers) modifiers).flags & flag) != 0L;
return hasFlag(((JCModifiers) modifiers).flags, flag);
}

private boolean hasFlag(long flags, long flag) {
return (flags & flag) != 0L;
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1639,12 +1639,8 @@ public J visitWildcard(WildcardTree node, Space fmt) {
return null;
}
try {
String prefix;
if (t instanceof JCNewClass && (((JCNewClass) t).type.tsym.flags() & Flags.ENUM) != 0L) {
prefix = "";
} else {
prefix = source.substring(cursor, indexOfNextNonWhitespace(cursor, source));
}
String prefix = t instanceof JCNewClass && hasFlag(((JCNewClass) t).type.tsym.flags(), Flags.ENUM) ? ""
: source.substring(cursor, indexOfNextNonWhitespace(cursor, source));
cursor += prefix.length();
@SuppressWarnings("unchecked") J2 j = (J2) scan(t, formatWithCommentTree(prefix, (JCTree) t, docCommentTable.getCommentTree((JCTree) t)));
return j;
Expand Down Expand Up @@ -2036,7 +2032,11 @@ private void cursor(int n) {
}

private boolean hasFlag(ModifiersTree modifiers, long flag) {
return (((JCModifiers) modifiers).flags & flag) != 0L;
return hasFlag(((JCModifiers) modifiers).flags, flag);
}

private boolean hasFlag(long flags, long flag) {
return (flags & flag) != 0L;
}

@SuppressWarnings("unused")
Expand Down

0 comments on commit ab07902

Please sign in to comment.