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

SI-9057 - fix showCode to put backticks around names including dots #4234

Merged
merged 1 commit into from Jan 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/reflect/scala/reflect/internal/Printers.scala
Expand Up @@ -546,10 +546,11 @@ trait Printers extends api.Printers { self: SymbolTable =>
import Chars._
val decName = name.decoded
val bslash = '\\'
val isDot = (x: Char) => x == '.'
val brackets = List('[',']','(',')','{','}')

def addBackquotes(s: String) =
if (decoded && (decName.exists(ch => brackets.contains(ch) || isWhitespace(ch)) ||
if (decoded && (decName.exists(ch => brackets.contains(ch) || isWhitespace(ch) || isDot(ch)) ||
(name.isOperatorName && decName.exists(isOperatorPart) && decName.exists(isScalaLetter) && !decName.contains(bslash))))
s"`$s`" else s

Expand Down
2 changes: 2 additions & 0 deletions test/junit/scala/reflect/internal/PrintersTest.scala
Expand Up @@ -125,6 +125,8 @@ trait BasePrintTests {
@Test def testName19 = assertPrintedCode("""class `class`""")

@Test def testName20 = assertPrintedCode("""class `test name`""")

@Test def testName21 = assertPrintedCode("""class `test.name`""")

@Test def testIfExpr1 = assertResultCode(code = sm"""
|val a = 1
Expand Down