Skip to content

Commit

Permalink
naming things: CamelCase for scala, SNAKE_CASE for java (#221)
Browse files Browse the repository at this point in the history
* java constants should be uppercase (as per java convention and odb)

* CamelCaseNames for PropertyAccessors, Accessors etc.

* fmt
  • Loading branch information
mpollmeier authored Jul 4, 2024
1 parent 01563e9 commit 824d66e
Show file tree
Hide file tree
Showing 34 changed files with 183 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ class DomainClassesGenerator(schema: Schema) {
for (p <- relevantProperties) {
val funName = camelCase(p.name)
accessorsForConcreteStoredNodes.addOne(
s"""final class Access_Property_${p.name}(val node: nodes.StoredNode) extends AnyVal {
s"""final class ${propertyAccessorClassname(p.name)}(val node: nodes.StoredNode) extends AnyVal {
| def $funName: ${typeForProperty(p)} = ${p.cardinality match {
case Cardinality.ZeroOrOne =>
s"flatgraph.Accessors.getNodePropertyOption[${unpackTypeUnboxed(p.valueType, true, false)}](node.graph, node.nodeKind, ${propertyKindByProperty(p)}, node.seq)"
Expand All @@ -785,10 +785,12 @@ class DomainClassesGenerator(schema: Schema) {
|}""".stripMargin
)
concreteStoredConv.addOne(
s"""implicit def accessProperty${p.className}(node: nodes.StoredNode & nodes.StaticType[nodes.Has${p.className}EMT]): Access_Property_${p.name} = new Access_Property_${p.name}(node)""".stripMargin
s"""implicit def accessProperty${p.className}(node: nodes.StoredNode & nodes.StaticType[nodes.Has${p.className}EMT]): ${propertyAccessorClassname(
p.name
)} = new ${propertyAccessorClassname(p.name)}(node)""".stripMargin
)

val concreteNodeTravClassname = s"Traversal_Property_${p.name}"
val concreteNodeTravClassname = traversalPropertyClassname(p.name)
accessorsForConcreteNodeTraversals.addOne(
ClassnameAndSource(
concreteNodeTravClassname,
Expand All @@ -797,23 +799,26 @@ class DomainClassesGenerator(schema: Schema) {
)
)
concreteStoredConvTrav.addOne(
s"""implicit def accessProperty${p.className}Traversal[NodeType <: nodes.StoredNode & nodes.StaticType[nodes.Has${p.className}EMT]](traversal: IterableOnce[NodeType]): Traversal_Property_${p.name}[NodeType] = new Traversal_Property_${p.name}(traversal.iterator)""".stripMargin
s"""implicit def accessProperty${p.className}Traversal[NodeType <: nodes.StoredNode & nodes.StaticType[nodes.Has${p.className}EMT]](traversal: IterableOnce[NodeType]): ${traversalPropertyClassname(
p.name
)}[NodeType] = new ${traversalPropertyClassname(p.name)}(traversal.iterator)""".stripMargin
)
}

for ((convertForStage, stage) <- baseConvert.iterator.zip(Iterator(nodeTypes) ++ prioStages.iterator)) {
stage.foreach { baseType =>
val extensionClass = s"Access_${baseType.className}Base"
val extensionClass = s"${accessorClassname(baseType.className)}Base"
val implicitMethodName = camelCase(s"access_${baseType.className}Base")
convertForStage.addOne(
s"implicit def access_${baseType.className}Base(node: nodes.${baseType.className}Base): $extensionClass = new $extensionClass(node)"
s"implicit def $implicitMethodName(node: nodes.${baseType.className}Base): $extensionClass = new $extensionClass(node)"
)
val newName = if (baseType.isInstanceOf[NodeBaseType]) { baseType.className + "New" }
else { "New" + baseType.className }
val accessors = mutable.ArrayBuffer.empty[String]
for (p <- newPropsAtNodeList(baseType)) {
val funName = camelCase(p.name)
accessors.addOne(s"""def ${funName}: ${typeForProperty(p)} = node match {
| case stored: nodes.StoredNode => new Access_Property_${p.name}(stored).${funName}
| case stored: nodes.StoredNode => new ${propertyAccessorClassname(p.name)}(stored).${funName}
| case newNode: nodes.${newName} => newNode.${funName}
|}""".stripMargin)
}
Expand All @@ -825,9 +830,10 @@ class DomainClassesGenerator(schema: Schema) {

for ((convertForStage, stage) <- baseConvertTrav.iterator.zip(Iterator(nodeTypes) ++ prioStages.iterator)) {
stage.foreach { baseType =>
val extensionClass = s"Traversal_${baseType.className}Base"
val extensionClass = camelCaseCaps(s"Traversal_${baseType.className}_Base")
val implicitMethodName = camelCase(s"traversal_${baseType.className}_Base")
convertForStage.addOne(
s"implicit def traversal_${baseType.className}Base[NodeType <: nodes.${baseType.className}Base](traversal: IterableOnce[NodeType]): $extensionClass[NodeType] = new $extensionClass(traversal.iterator)"
s"implicit def $implicitMethodName[NodeType <: nodes.${baseType.className}Base](traversal: IterableOnce[NodeType]): $extensionClass[NodeType] = new $extensionClass(traversal.iterator)"
)
val elems = mutable.ArrayBuffer.empty[String]
for (p <- newPropsAtNodeList(baseType)) {
Expand Down Expand Up @@ -1138,19 +1144,31 @@ class DomainClassesGenerator(schema: Schema) {
writeConstants(
"PropertyNames",
schema.properties.map { property =>
ConstantContext(property.name, s"""public static final String ${property.name} = "${property.name}";""", property.comment)
ConstantContext(
property.name.toUpperCase,
s"""public static final String ${property.name.toUpperCase} = "${property.name}";""",
property.comment
)
}
)
writeConstants(
"NodeTypes",
schema.nodeTypes.map { nodeType =>
ConstantContext(nodeType.name, s"""public static final String ${nodeType.name} = "${nodeType.name}";""", nodeType.comment)
ConstantContext(
nodeType.name.toUpperCase,
s"""public static final String ${nodeType.name.toUpperCase} = "${nodeType.name}";""",
nodeType.comment
)
}
)
writeConstants(
"EdgeTypes",
schema.edgeTypes.map { edgeType =>
ConstantContext(edgeType.name, s"""public static final String ${edgeType.name} = "${edgeType.name}";""", edgeType.comment)
ConstantContext(
edgeType.name.toUpperCase,
s"""public static final String ${edgeType.name.toUpperCase} = "${edgeType.name}";""",
edgeType.comment
)
}
)
schema.constantsByCategory.foreach { case (category, constants) =>
Expand Down Expand Up @@ -1536,6 +1554,15 @@ class DomainClassesGenerator(schema: Schema) {
def edgeNeighborToMap(xs: Set[(String, String)]): Map[String, Set[String]] =
xs.groupBy(_._1).map { case (edge, edgeNeighbors) => edge -> edgeNeighbors.map(_._2) }

def accessorClassname(nodeType: String): String =
camelCaseCaps(s"Access_$nodeType")

def propertyAccessorClassname(propertyName: String): String =
camelCaseCaps(s"Access_Property_$propertyName")

def traversalPropertyClassname(propertyName: String): String =
camelCaseCaps(s"Traversal_Property_$propertyName")

/** Useful string extensions to avoid Scala version incompatible interpolations.
*/
implicit class StringHelper(s: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
public class EdgeTypes {


public static final String connected_to = "connected_to";
public static final String CONNECTED_TO = "connected_to";

public static Set<String> ALL = new HashSet<String>() {{
add(connected_to);
add(CONNECTED_TO);
}};

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
public class NodeTypes {


public static final String node_a = "node_a";
public static final String NODE_A = "node_a";


public static final String node_b = "node_b";
public static final String NODE_B = "node_b";

public static Set<String> ALL = new HashSet<String>() {{
add(node_a);
add(node_b);
add(NODE_A);
add(NODE_B);
}};

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
public class PropertyNames {


public static final String int_list = "int_list";
public static final String INT_LIST = "int_list";


public static final String int_mandatory = "int_mandatory";
public static final String INT_MANDATORY = "int_mandatory";


public static final String int_optional = "int_optional";
public static final String INT_OPTIONAL = "int_optional";


public static final String string_list = "string_list";
public static final String STRING_LIST = "string_list";


public static final String string_mandatory = "string_mandatory";
public static final String STRING_MANDATORY = "string_mandatory";


public static final String string_optional = "string_optional";
public static final String STRING_OPTIONAL = "string_optional";

public static Set<String> ALL = new HashSet<String>() {{
add(int_list);
add(int_mandatory);
add(int_optional);
add(string_list);
add(string_mandatory);
add(string_optional);
add(INT_LIST);
add(INT_MANDATORY);
add(INT_OPTIONAL);
add(STRING_LIST);
add(STRING_MANDATORY);
add(STRING_OPTIONAL);
}};

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,56 @@ object languagebootstrap extends ConcreteStoredConversions

object Accessors {
/* accessors for concrete stored nodes start */
final class Access_Property_int_list(val node: nodes.StoredNode) extends AnyVal {
final class AccessPropertyIntList(val node: nodes.StoredNode) extends AnyVal {
def intList: IndexedSeq[Int] = flatgraph.Accessors.getNodePropertyMulti[Int](node.graph, node.nodeKind, 0, node.seq)
}
final class Access_Property_int_mandatory(val node: nodes.StoredNode) extends AnyVal {
final class AccessPropertyIntMandatory(val node: nodes.StoredNode) extends AnyVal {
def intMandatory: Int = flatgraph.Accessors.getNodePropertySingle(node.graph, node.nodeKind, 1, node.seq(), 42: Int)
}
final class Access_Property_int_optional(val node: nodes.StoredNode) extends AnyVal {
final class AccessPropertyIntOptional(val node: nodes.StoredNode) extends AnyVal {
def intOptional: Option[Int] = flatgraph.Accessors.getNodePropertyOption[Int](node.graph, node.nodeKind, 2, node.seq)
}
final class Access_Property_string_list(val node: nodes.StoredNode) extends AnyVal {
final class AccessPropertyStringList(val node: nodes.StoredNode) extends AnyVal {
def stringList: IndexedSeq[String] = flatgraph.Accessors.getNodePropertyMulti[String](node.graph, node.nodeKind, 3, node.seq)
}
final class Access_Property_string_mandatory(val node: nodes.StoredNode) extends AnyVal {
final class AccessPropertyStringMandatory(val node: nodes.StoredNode) extends AnyVal {
def stringMandatory: String = flatgraph.Accessors.getNodePropertySingle(node.graph, node.nodeKind, 4, node.seq(), "<empty>": String)
}
final class Access_Property_string_optional(val node: nodes.StoredNode) extends AnyVal {
final class AccessPropertyStringOptional(val node: nodes.StoredNode) extends AnyVal {
def stringOptional: Option[String] = flatgraph.Accessors.getNodePropertyOption[String](node.graph, node.nodeKind, 5, node.seq)
}
/* accessors for concrete stored nodes end */

/* accessors for base nodes start */
final class Access_NodeABase(val node: nodes.NodeABase) extends AnyVal {
final class AccessNodeaBase(val node: nodes.NodeABase) extends AnyVal {
def intList: IndexedSeq[Int] = node match {
case stored: nodes.StoredNode => new Access_Property_int_list(stored).intList
case stored: nodes.StoredNode => new AccessPropertyIntList(stored).intList
case newNode: nodes.NewNodeA => newNode.intList
}
def intMandatory: Int = node match {
case stored: nodes.StoredNode => new Access_Property_int_mandatory(stored).intMandatory
case stored: nodes.StoredNode => new AccessPropertyIntMandatory(stored).intMandatory
case newNode: nodes.NewNodeA => newNode.intMandatory
}
def intOptional: Option[Int] = node match {
case stored: nodes.StoredNode => new Access_Property_int_optional(stored).intOptional
case stored: nodes.StoredNode => new AccessPropertyIntOptional(stored).intOptional
case newNode: nodes.NewNodeA => newNode.intOptional
}
def stringList: IndexedSeq[String] = node match {
case stored: nodes.StoredNode => new Access_Property_string_list(stored).stringList
case stored: nodes.StoredNode => new AccessPropertyStringList(stored).stringList
case newNode: nodes.NewNodeA => newNode.stringList
}
def stringMandatory: String = node match {
case stored: nodes.StoredNode => new Access_Property_string_mandatory(stored).stringMandatory
case stored: nodes.StoredNode => new AccessPropertyStringMandatory(stored).stringMandatory
case newNode: nodes.NewNodeA => newNode.stringMandatory
}
def stringOptional: Option[String] = node match {
case stored: nodes.StoredNode => new Access_Property_string_optional(stored).stringOptional
case stored: nodes.StoredNode => new AccessPropertyStringOptional(stored).stringOptional
case newNode: nodes.NewNodeA => newNode.stringOptional
}
}
final class Access_NodeBBase(val node: nodes.NodeBBase) extends AnyVal {
final class AccessNodebBase(val node: nodes.NodeBBase) extends AnyVal {
def stringOptional: Option[String] = node match {
case stored: nodes.StoredNode => new Access_Property_string_optional(stored).stringOptional
case stored: nodes.StoredNode => new AccessPropertyStringOptional(stored).stringOptional
case newNode: nodes.NewNodeB => newNode.stringOptional
}
}
Expand All @@ -65,24 +65,23 @@ object Accessors {

import Accessors.*
trait ConcreteStoredConversions extends ConcreteBaseConversions {
implicit def accessPropertyIntList(node: nodes.StoredNode & nodes.StaticType[nodes.HasIntListEMT]): Access_Property_int_list =
new Access_Property_int_list(node)
implicit def accessPropertyIntMandatory(
node: nodes.StoredNode & nodes.StaticType[nodes.HasIntMandatoryEMT]
): Access_Property_int_mandatory = new Access_Property_int_mandatory(node)
implicit def accessPropertyIntOptional(node: nodes.StoredNode & nodes.StaticType[nodes.HasIntOptionalEMT]): Access_Property_int_optional =
new Access_Property_int_optional(node)
implicit def accessPropertyStringList(node: nodes.StoredNode & nodes.StaticType[nodes.HasStringListEMT]): Access_Property_string_list =
new Access_Property_string_list(node)
implicit def accessPropertyIntList(node: nodes.StoredNode & nodes.StaticType[nodes.HasIntListEMT]): AccessPropertyIntList =
new AccessPropertyIntList(node)
implicit def accessPropertyIntMandatory(node: nodes.StoredNode & nodes.StaticType[nodes.HasIntMandatoryEMT]): AccessPropertyIntMandatory =
new AccessPropertyIntMandatory(node)
implicit def accessPropertyIntOptional(node: nodes.StoredNode & nodes.StaticType[nodes.HasIntOptionalEMT]): AccessPropertyIntOptional =
new AccessPropertyIntOptional(node)
implicit def accessPropertyStringList(node: nodes.StoredNode & nodes.StaticType[nodes.HasStringListEMT]): AccessPropertyStringList =
new AccessPropertyStringList(node)
implicit def accessPropertyStringMandatory(
node: nodes.StoredNode & nodes.StaticType[nodes.HasStringMandatoryEMT]
): Access_Property_string_mandatory = new Access_Property_string_mandatory(node)
): AccessPropertyStringMandatory = new AccessPropertyStringMandatory(node)
implicit def accessPropertyStringOptional(
node: nodes.StoredNode & nodes.StaticType[nodes.HasStringOptionalEMT]
): Access_Property_string_optional = new Access_Property_string_optional(node)
): AccessPropertyStringOptional = new AccessPropertyStringOptional(node)
}

trait ConcreteBaseConversions {
implicit def access_NodeABase(node: nodes.NodeABase): Access_NodeABase = new Access_NodeABase(node)
implicit def access_NodeBBase(node: nodes.NodeBBase): Access_NodeBBase = new Access_NodeBBase(node)
implicit def accessNodeabase(node: nodes.NodeABase): AccessNodeaBase = new AccessNodeaBase(node)
implicit def accessNodebbase(node: nodes.NodeBBase): AccessNodebBase = new AccessNodebBase(node)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package testdomains.generic.traversals
import testdomains.generic.nodes
import testdomains.generic.accessors.languagebootstrap.*

final class Traversal_NodeABase[NodeType <: nodes.NodeABase](val traversal: Iterator[NodeType]) extends AnyVal {
final class TraversalNodeaBase[NodeType <: nodes.NodeABase](val traversal: Iterator[NodeType]) extends AnyVal {

/** Traverse to intList property */
def intList: Iterator[Int] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package testdomains.generic.traversals
import testdomains.generic.nodes
import testdomains.generic.accessors.languagebootstrap.*

final class Traversal_NodeBBase[NodeType <: nodes.NodeBBase](val traversal: Iterator[NodeType]) extends AnyVal {
final class TraversalNodebBase[NodeType <: nodes.NodeBBase](val traversal: Iterator[NodeType]) extends AnyVal {

/** Traverse to stringOptional property */
def stringOptional: Iterator[String] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package testdomains.generic.traversals
import testdomains.generic.nodes
import testdomains.generic.accessors.languagebootstrap.*

final class Traversal_Property_int_list[NodeType <: nodes.StoredNode & nodes.StaticType[nodes.HasIntListEMT]](
final class TraversalPropertyIntList[NodeType <: nodes.StoredNode & nodes.StaticType[nodes.HasIntListEMT]](
val traversal: Iterator[NodeType]
) extends AnyVal {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package testdomains.generic.traversals
import testdomains.generic.nodes
import testdomains.generic.accessors.languagebootstrap.*

final class Traversal_Property_int_mandatory[NodeType <: nodes.StoredNode & nodes.StaticType[nodes.HasIntMandatoryEMT]](
final class TraversalPropertyIntMandatory[NodeType <: nodes.StoredNode & nodes.StaticType[nodes.HasIntMandatoryEMT]](
val traversal: Iterator[NodeType]
) extends AnyVal {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package testdomains.generic.traversals
import testdomains.generic.nodes
import testdomains.generic.accessors.languagebootstrap.*

final class Traversal_Property_int_optional[NodeType <: nodes.StoredNode & nodes.StaticType[nodes.HasIntOptionalEMT]](
final class TraversalPropertyIntOptional[NodeType <: nodes.StoredNode & nodes.StaticType[nodes.HasIntOptionalEMT]](
val traversal: Iterator[NodeType]
) extends AnyVal {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package testdomains.generic.traversals
import testdomains.generic.nodes
import testdomains.generic.accessors.languagebootstrap.*

final class Traversal_Property_string_list[NodeType <: nodes.StoredNode & nodes.StaticType[nodes.HasStringListEMT]](
final class TraversalPropertyStringList[NodeType <: nodes.StoredNode & nodes.StaticType[nodes.HasStringListEMT]](
val traversal: Iterator[NodeType]
) extends AnyVal {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package testdomains.generic.traversals
import testdomains.generic.nodes
import testdomains.generic.accessors.languagebootstrap.*

final class Traversal_Property_string_mandatory[NodeType <: nodes.StoredNode & nodes.StaticType[nodes.HasStringMandatoryEMT]](
final class TraversalPropertyStringMandatory[NodeType <: nodes.StoredNode & nodes.StaticType[nodes.HasStringMandatoryEMT]](
val traversal: Iterator[NodeType]
) extends AnyVal {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package testdomains.generic.traversals
import testdomains.generic.nodes
import testdomains.generic.accessors.languagebootstrap.*

final class Traversal_Property_string_optional[NodeType <: nodes.StoredNode & nodes.StaticType[nodes.HasStringOptionalEMT]](
final class TraversalPropertyStringOptional[NodeType <: nodes.StoredNode & nodes.StaticType[nodes.HasStringOptionalEMT]](
val traversal: Iterator[NodeType]
) extends AnyVal {

Expand Down
Loading

0 comments on commit 824d66e

Please sign in to comment.