Skip to content

Conversation

@johannescoetzee
Copy link
Contributor

This PR includes a few changes to generated code:

  • remove all node type specific NodeType.Properties, NodeType.PropertyNames, and NodeType.PropertyDefaults objects
  • Add a common <basepackage>.PropertyDefaults object defining constants for all property defaults
  • Move PropertyNames.java to PropertyNames.scala with scala constants
  • Generate a comment above each node type class describing the available properties

}
val containedNodeNames = nodeType.containedNodes match {
case containedNodes if containedNodes.nonEmpty =>
containedNodes.map(n => camelCaseCaps(n.nodeType.name)).toList
Copy link
Contributor

Choose a reason for hiding this comment

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

should this also have a prefix like above?
e.g. "Contained nodes:" ::

"Node properties:" :: properties.map(property => camelCaseCaps(property.name)).toList
case _ => Nil
}
val containedNodeNames = nodeType.containedNodes match {
Copy link
Contributor

Choose a reason for hiding this comment

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

there's a lot of spaghetti code in this class, maybe it's worth extracting things like this into something like

def commentForProperty[A](prefix: String, propertyNames: Seq[String]): String = ???

and then

val nodePropertiesComments = 
  commentForProperty("Node properties:", noteType.properties.map(_.property.name) ++ 
  commentForProperty("Contained properties:", containedNodeNames.map(_.nodeType.name)

or so..

results.addOne(file)
results.addOne(propertiesFile)
val propertyNamesSource = schema.properties
.map { property =>
Copy link
Contributor

Choose a reason for hiding this comment

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

did scalafmt format it like that? please confirm, I'd prefer to have the .map on the same line...

Copy link
Contributor

Choose a reason for hiding this comment

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

similar cases below. likely a separate scalafmt pr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is indeed a scalafmt change

results.addOne(propertiesFile)
val propertyNamesSource = schema.properties
.map { property =>
property.comment.map(comment => "/**" ++ comment ++ "*/\n").getOrElse("") ++ s"""val ${camelCaseCaps(
Copy link
Contributor

Choose a reason for hiding this comment

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

this is also formatted in a way that makes it hard to read

case p if p.hasDefault =>
s"""val ${camelCaseCaps(p.name)} = ${Helpers.defaultValueImpl(p.default.get)}"""
}
.mkString("\n\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.mkString("\n\n")
.mkString("\n")

|val ${camelCaseCaps(containedNode.nodeType.name)}: String = "${containedNode.nodeType.name}"""".stripMargin
}
.toSet
.mkString("\n\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.mkString("\n\n")
.mkString("\n")

}

/** Node properties:
* - DispatchType
Copy link
Contributor

Choose a reason for hiding this comment

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

please also add valueType and comment of the properties, and all information from the contained node as well

@johannescoetzee johannescoetzee force-pushed the johannes/reduce-property-duplication branch from 9ce7ed4 to 20806ce Compare July 3, 2025 13:20
@johannescoetzee
Copy link
Contributor Author

johannescoetzee commented Jul 3, 2025

I've updated the PR with changes that I think address all of the comments on the PR, but please let me know if I missed something. I'm not a huge fan of the format of the generated comments, but this was the best I've found that isn't messed up by scalafmt.

Edit: This also breaks CPG due to a double definition

@johannescoetzee
Copy link
Contributor Author

The CPG break is now fixed (I forgot a toSet during refactoring) and the comment output format is now stable through multiple scalafmt runs.

@mpollmeier
Copy link
Contributor

we'll configure scalafmt in a followup PR :)

@mpollmeier mpollmeier self-requested a review July 4, 2025 06:51
@mpollmeier
Copy link
Contributor

@johannescoetzee if you're happy with the changes I pushed re scaladoc feel free to merge
Releases happen on request only now, do you have permissions to start one?

@johannescoetzee
Copy link
Contributor Author

The new comment format is much nicer :)

@johannescoetzee johannescoetzee merged commit 43fb84d into master Jul 4, 2025
1 check passed
@johannescoetzee johannescoetzee deleted the johannes/reduce-property-duplication branch July 4, 2025 08:21
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.

3 participants