GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Sealed classes - error: expected token: 'sealed'; generated class instead · Issue #603 · google/google-java-format

Sealed classes - error: expected token: 'sealed'; generated class instead #603

New issue
Copy link
New issue
Copy link
Closed
Closed
Sealed classes - error: expected token: 'sealed'; generated class instead#603
Copy link

Description

@ZacSweers
ZacSweers
opened on May 2, 2021
Issue body actions

When trying to use GJF with JDK 16, I get the following error

Caused by: com.google.googlejavaformat.java.FormatterException: 8:52: error: expected token: 'sealed'; generated class instead
        at com.google.googlejavaformat.java.Formatter.getFormatReplacements(Formatter.java:293)
        at com.google.googlejavaformat.java.Formatter.formatSource(Formatter.java:267)
        at com.google.googlejavaformat.java.Formatter.formatSource(Formatter.java:233)
        ... 135 more

With this source code

package dev.zacsweers.moshix.sealed.sample.java;

import com.squareup.moshi.JsonClass;

import dev.zacsweers.moshix.sealed.annotations.TypeLabel;

public interface FailureTestCases {
  @JsonClass(generateAdapter = false, generator = "sealed:type")
  sealed class DuplicateLabels permits DuplicateLabels.TypeA, DuplicateLabels.TypeB {
    @TypeLabel(label = "a")
    static final class TypeA extends DuplicateLabels {}

    @TypeLabel(label = "a")
    static final class TypeB extends DuplicateLabels {}
  }

  @JsonClass(generateAdapter = false, generator = "sealed:type")
  sealed class DuplicateAlternateLabels permits DuplicateAlternateLabels.TypeA, DuplicateAlternateLabels.TypeB {
    @TypeLabel(label = "a", alternateLabels = {"aa"})
    static final class TypeA extends DuplicateAlternateLabels {}

    @TypeLabel(label = "b", alternateLabels = {"aa"})
    static final class TypeB extends DuplicateAlternateLabels {}
  }

  @JsonClass(generateAdapter = false, generator = "sealed:type")
  sealed class GenericSubtypes<T> permits GenericSubtypes.TypeA, GenericSubtypes.TypeB {
    // This form is ok
    @TypeLabel(label = "a", alternateLabels = {"aa"})
    static final class TypeA extends GenericSubtypes<String> {}

    // This form is not ok
    @TypeLabel(label = "b", alternateLabels = {"aa"})
    static final class TypeB<T> extends GenericSubtypes<T> {}
  }
}

I know sealed classes are still in preview though, so understand if this isn't expected to be supported yet. The error message is a little surprising though

Activity

  1. kevinb9n commented on Jun 14, 2021

    @kevinb9n
    kevinb9n
    on Jun 14, 2021
    Contributor
    More actions

    We'd like to support preview features -- if not by formatting them well, that at least through the magic of not crashing.

    If for some reason this is a nontrivial fix (?), we might at least fix the error message first.

  2. now
    added a commit that references this issue on Jul 23, 2021

    Support sealed classes

    This issue will close once commit c186e3d is merged into the 'master' branch.
    c186e3d
  3. copybara-service
    closed this as completedin cc8b96fon Jul 27, 2021
  4. bsdcat
    added a commit that references this issue on Sep 13, 2024

    Support sealed classes

    This issue will close once commit cc8b96f is merged into the 'master' branch.
    cc8b96f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.