Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spaces around type parameters in class/interface/record declarations #443 #444

Merged
merged 1 commit into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.jdt.core.formatter.IndentManipulation;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions;
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions.Alignment;
Expand Down Expand Up @@ -13305,4 +13306,24 @@ public void testBug576954() {
" }\n" +
"}");
}
/**
* https://github.com/eclipse-jdt/eclipse.jdt.core/issues/443
*/
public void testIssue443a() {
setComplianceLevel(CompilerOptions.VERSION_17);
this.formatterPrefs.insert_space_after_closing_angle_bracket_in_type_parameters = true;
formatSource(
"record MyRecord<A>() {\n" +
"}");
}
public void testIssue443b() {
setComplianceLevel(CompilerOptions.VERSION_17);
this.formatterPrefs.insert_space_after_closing_angle_bracket_in_type_parameters = false;
formatSource(
"class MyClass<A> extends AnotherClass {\n" +
"}\n" +
"\n" +
"sealed interface Expr<A> permits MathExpr {\n" +
"}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ public boolean visit(TypeDeclaration node) {
List<TypeParameter> typeParameters = node.typeParameters();
handleTypeParameters(typeParameters);

if (!node.isInterface() && !node.superInterfaceTypes().isEmpty()) {
// fix for: class A<E> extends ArrayList<String>implements Callable<String>
handleToken(node.getName(), TokenNameimplements, true, false);
}
if (!node.superInterfaceTypes().isEmpty())
handleTokenAfter(node.getName(), node.isInterface() ? TokenNameextends : TokenNameimplements, true, true);
if (node.getSuperclassType() != null)
handleTokenAfter(node.getName(), TokenNameextends, true, true);
if (!node.permittedTypes().isEmpty())
handleTokenAfter(node.getName(), TokenNameRestrictedIdentifierpermits, true, true);

handleToken(node.getName(), TokenNameLBRACE,
this.options.insert_space_before_opening_brace_in_type_declaration, false);
Expand Down Expand Up @@ -366,7 +368,8 @@ private void handleTypeParameters(List<TypeParameter> typeParameters) {
this.options.insert_space_after_opening_angle_bracket_in_type_parameters);
handleTokenAfter(typeParameters.get(typeParameters.size() - 1), TokenNameGREATER,
this.options.insert_space_before_closing_angle_bracket_in_type_parameters,
this.options.insert_space_after_closing_angle_bracket_in_type_parameters);
typeParameters.get(0).getParent() instanceof RecordDeclaration ? false
: this.options.insert_space_after_closing_angle_bracket_in_type_parameters);
handleCommas(typeParameters, this.options.insert_space_before_comma_in_type_parameters,
this.options.insert_space_after_comma_in_type_parameters);
}
Expand Down