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

Format viewpoint test annotations #940

Merged
merged 4 commits into from
Oct 9, 2024

Conversation

Ao-senXiong
Copy link
Member

Fix #873

Copy link
Member

@wmdietl wmdietl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this!

build.gradle Outdated
@@ -300,7 +300,7 @@ allprojects {

googleJavaFormat().aosp()
importOrder('com', 'jdk', 'lib', 'lombok', 'org', 'java', 'javax')
formatAnnotations().addTypeAnnotation("PolyInitialized")
formatAnnotations().addTypeAnnotation("PolyInitialized").addTypeAnnotation("A").addTypeAnnotation("B").addTypeAnnotation("Bottom").addTypeAnnotation("PolyVP").addTypeAnnotation("ReceiverDependentQual").addTypeAnnotation("Top")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you turn this into two arrays: 1) regular type qualifiers that are not in spotless (yet) 2) test type qualifiers that never make sense to add to spotless.
For the second set, can you add a comment/script, that re-creates the array for future additions?
Then, turn the addTypeAnnotation into a functional style that passes each array element.

@wmdietl wmdietl assigned Ao-senXiong and unassigned wmdietl Oct 8, 2024
@Ao-senXiong
Copy link
Member Author

Ao-senXiong commented Oct 8, 2024

Looks like spotless does not allow addTypeAnnotation be used as a functional style.
The following code will throw this error, single annotation array is fine and multiple annotations array will cause this problem:

// Regular type qualifiers array that are not in Spotless yet
def regularTypeQualifiers = [
        "PolyInitialized"
]

// Test type qualifiers array
def testTypeQualifiers = [
        "PolyVP", "ReceiverDependentQual"
]

def allQualifiers = regularTypeQualifiers + testTypeQualifiers

// Add all type qualifiers to Spotless
allQualifiers.each { qualifier ->
    formatAnnotations().addTypeAnnotation(qualifier)
}
* What went wrong:
Could not create task ':checker:spotlessJavaCheck'.
Could not create task ':checker:spotlessJava'.
Multiple steps with name 'No line break between type annotation and type' for spotless format 'java'

However, I also notice spotless already support a few of our testannotations so I can simplify it.
https://github.com/diffplug/spotless/blob/85a0bebc71dcf59f56f0ac31b8b2507294cff78d/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java#L51

Also it is good to notice that they format the array in alphabetical order, I am wondering do they use automatical tool to do it or just do it manually.

@Ao-senXiong Ao-senXiong assigned wmdietl and unassigned Ao-senXiong Oct 8, 2024
Copy link
Member

@wmdietl wmdietl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@wmdietl wmdietl merged commit d5dceb5 into eisop:master Oct 9, 2024
74 checks passed
@Ao-senXiong Ao-senXiong deleted the format-test-annotations branch October 9, 2024 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Test qualifiers to type annotation formatting
2 participants