Skip to content

Commit

Permalink
Enable scalafmt in Source: Part 3
Browse files Browse the repository at this point in the history
Scalafmt is being enabled in Source: please see http://go/scalafmt for more information.

RB_ID=920362
TBR=true
NO_USER_HOOK=1
  • Loading branch information
Stu Hood authored and jenkins committed Aug 4, 2017
1 parent cf5f7f8 commit 9ab0579
Show file tree
Hide file tree
Showing 51 changed files with 1,438 additions and 923 deletions.
@@ -1,6 +1,5 @@
package com.twitter.scrooge.ast


sealed abstract class Definition extends DefinitionNode {
val sid: SimpleID
}
Expand Down
Expand Up @@ -5,19 +5,19 @@ case class Document(headers: Seq[Header], defs: Seq[Definition]) extends Documen
(headers collect {
// first try to find language specific namespace scope
case Namespace(l, x) if l == language => x
}).headOption orElse(headers collect {
}).headOption orElse (headers collect {
// then see if universal namespace scope is defined
case Namespace(l, x) if l == "*" => x
}).headOption
}

def mapNamespaces(namespaceMap: Map[String,String]): Document = {
def mapNamespaces(namespaceMap: Map[String, String]): Document = {
copy(
headers = headers map {
case header @ Namespace(_, ns) => {
namespaceMap.get(ns.fullName) map {
newNs => header.copy(id = Identifier(newNs))
} getOrElse(header)
namespaceMap.get(ns.fullName) map { newNs =>
header.copy(id = Identifier(newNs))
} getOrElse (header)
}
case include @ Include(_, doc) => {
include.copy(document = doc.mapNamespaces(namespaceMap))
Expand All @@ -31,4 +31,4 @@ case class Document(headers: Seq[Header], defs: Seq[Definition]) extends Documen
def enums: Seq[Enum] = defs.collect { case e: Enum => e }
def structs: Seq[StructLike] = defs.collect { case s: StructLike => s }
def services: Seq[Service] = defs.collect { case s: Service => s }
}
}
Expand Up @@ -9,6 +9,7 @@ sealed abstract class Header extends HeaderNode
* @param document the content of the file to be included.
*/
case class Include(filePath: String, document: Document) extends Header {

/**
* The definitions in the included file must be used with a prefix.
* For example, if it says
Expand Down
Expand Up @@ -55,16 +55,20 @@ object Identifier {
* (_genHtmlReport, _genHtmlReport, _GenHtmlReport)
*/
def toCamelCase(str: String, firstCharUp: Boolean = false): String = {
str.takeWhile(_ == '_') + str.
split('_').
filterNot(_.isEmpty).
zipWithIndex.map { case (part, ind) =>
val first = if (ind == 0 && !firstCharUp) part(0).toLower else part(0).toUpper
val isAllUpperCase = part.forall { c => c.isUpper || !c.isLetter }
val rest = if (isAllUpperCase) part.drop(1).toLowerCase else part.drop(1)
new mutable.StringBuilder(part.size).append(first).append(rest)
}.
mkString
str.takeWhile(_ == '_') + str
.split('_')
.filterNot(_.isEmpty)
.zipWithIndex
.map {
case (part, ind) =>
val first = if (ind == 0 && !firstCharUp) part(0).toLower else part(0).toUpper
val isAllUpperCase = part.forall { c =>
c.isUpper || !c.isLetter
}
val rest = if (isAllUpperCase) part.drop(1).toLowerCase else part.drop(1)
new mutable.StringBuilder(part.size).append(first).append(rest)
}
.mkString
}
}

Expand Down Expand Up @@ -119,4 +123,4 @@ case class QualifiedID(names: Seq[String]) extends Identifier {

def qualifier: Identifier = Identifier(names.dropRight(1).mkString("."))
def name: SimpleID = SimpleID(names.last)
}
}
40 changes: 20 additions & 20 deletions scrooge-generator/src/main/scala/com/twitter/scrooge/AST/Node.scala
Expand Up @@ -26,6 +26,7 @@ abstract class DefinitionNode extends Node
abstract class IdNode extends Node

sealed abstract class Requiredness extends Node {

/**
* Indicates that the field is marked as optional in the IDL
* and does not have a default value defined.
Expand All @@ -45,6 +46,7 @@ sealed abstract class Requiredness extends Node {
}

object Requiredness {

/** @see [[Requiredness.isOptional]] */
case object Optional extends Requiredness

Expand All @@ -56,25 +58,23 @@ object Requiredness {
}

case class Field(
index: Int,
sid: SimpleID,
originalName: String,
fieldType: FieldType,
default: Option[RHS] = None,
requiredness: Requiredness = Requiredness.Default,
typeAnnotations: Map[String, String] = Map.empty,
fieldAnnotations: Map[String, String] = Map.empty,
docstring: Option[String] = None)
extends Node
index: Int,
sid: SimpleID,
originalName: String,
fieldType: FieldType,
default: Option[RHS] = None,
requiredness: Requiredness = Requiredness.Default,
typeAnnotations: Map[String, String] = Map.empty,
fieldAnnotations: Map[String, String] = Map.empty,
docstring: Option[String] = None
) extends Node

case class Function(
funcName: SimpleID,
originalName: String,
funcType: FunctionType,
args: Seq[Field],
throws: Seq[Field],
docstring: Option[String],
annotations: Map[String, String] = Map.empty
)
extends Node

funcName: SimpleID,
originalName: String,
funcType: FunctionType,
args: Seq[Field],
throws: Seq[Field],
docstring: Option[String],
annotations: Map[String, String] = Map.empty
) extends Node
Expand Up @@ -23,6 +23,7 @@ case class ReferenceType(id: Identifier) extends FieldType

sealed trait NamedType extends FieldType {
def sid: SimpleID

/** Filename of the containing file if the type is included from another file */
def scopePrefix: Option[SimpleID]
}
Expand All @@ -39,10 +40,8 @@ case class EnumType(enum: Enum, scopePrefix: Option[SimpleID] = None) extends Na

sealed abstract class ContainerType(cppType: Option[String]) extends FieldType

case class MapType(
keyType: FieldType,
valueType: FieldType,
cppType: Option[String]) extends ContainerType(cppType) {
case class MapType(keyType: FieldType, valueType: FieldType, cppType: Option[String])
extends ContainerType(cppType) {

override def toString: String = s"Map($keyType, $valueType)"
}
Expand Down
Expand Up @@ -23,7 +23,6 @@ import java.io.{File, FileWriter}
import scala.collection.concurrent.TrieMap
import scala.collection.mutable


object CompilerDefaults {
var language: String = "scala"
var defaultNamespace: String = "thrift"
Expand Down Expand Up @@ -81,11 +80,7 @@ class Compiler {

if (verbose) println("+ Compiling %s".format(inputFile))
val resolvedDoc = TypeResolver()(doc)
val generator = GeneratorFactory(
language,
resolvedDoc,
defaultNamespace,
experimentFlags)
val generator = GeneratorFactory(language, resolvedDoc, defaultNamespace, experimentFlags)

generator match {
case g: ScalaGenerator => g.warnOnJavaNamespaceFallback = scalaWarnOnJavaNSFallback
Expand Down

0 comments on commit 9ab0579

Please sign in to comment.