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

Expression body indent wrong #1300

Open
JakeWharton opened this issue Jun 29, 2022 · 3 comments
Open

Expression body indent wrong #1300

JakeWharton opened this issue Jun 29, 2022 · 3 comments
Labels

Comments

@JakeWharton
Copy link
Member

Today:

  public override val descriptor: SerialDescriptor = buildString {
      }
  public override val descriptor: SerialDescriptor =
      buildClassSerialDescriptor("RowVerticalAlignment") {
      }

Should be:

  public override val descriptor: SerialDescriptor = buildString {
  }
  public override val descriptor: SerialDescriptor =
    buildClassSerialDescriptor("RowVerticalAlignment") {
    }

We need to remove the function indent when it collapses so that wraps are +2 and begin/end control flows can have their curly's flush with the function's visibility modifier indent level.

@JakeWharton
Copy link
Member Author

I made the second example a non-empty block and things got weirder:

  public override val descriptor: SerialDescriptor =
      buildClassSerialDescriptor("RowVerticalAlignment") {
    element<Int>("direction")
  }

Here's the code:

addProperty(PropertySpec.builder("descriptor", SerialDescriptor)
  .addModifiers(OVERRIDE)
  .initializer(CodeBlock.builder()
    .beginControlFlow("%M(%S)", buildClassSerialDescriptor, layoutModifierType.simpleName)
    .apply {
      for (property in layoutModifier.traits) {
        addStatement("%M<%T>(%S)", element, property.type.asTypeName(), property.name)
      }
    }
    .endControlFlow()
    .build())
  .build())

@JakeWharton
Copy link
Member Author

  public override fun equals(other: Any?): Boolean = other is AccessibilityDescription
  && other.`value` == `value`

Beginning to think expression body support was a mistake because it seems to be wrong more often than not.

@Egorand
Copy link
Collaborator

Egorand commented Jul 4, 2022

I dug a bit into how we emit PropertySpec.initializer, and the logic is that we'll wrap the entire CodeBlock into a statement («%L») unless it already includes statements. Emitting the CodeBlock as a single statement seems to produce expected results. Maybe we should just do a better job processing the CodeBlock before emitting it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants