Skip to content

Commit 9a7db7d

Browse files
author
dmitry.naydanov
committed
Breadcrumbs for anonymous classes shortened; also code cleanup; #SCL-11831 fixed
1 parent 477377e commit 9a7db7d

File tree

1 file changed

+26
-38
lines changed

1 file changed

+26
-38
lines changed

src/org/jetbrains/plugins/scala/lang/breadcrumbs/ScalaBreadcrumbsInfoProvider.scala

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,16 @@ class ScalaBreadcrumbsInfoProvider extends BreadcrumbsInfoProvider {
6868
}
6969

7070
object ScalaBreadcrumbsInfoProvider {
71+
private val PAR_HOLDER = "(...)"
72+
7173
val SCALA_LANG: Array[Language] = Array[Language](ScalaLanguage.INSTANCE)
7274

7375
val MAX_TEXT_LENGTH = 150
7476
val MAX_STRING_LENGTH = 25
7577

7678
object MyTextRepresentationUtil {
77-
private def limitString(s: String, stub: String = "(...)") = if (s == null) "" else if (s.length < MAX_STRING_LENGTH) s else stub
78-
private def limitText(txt: String, stub: String = "...") = {
79+
private def limitString(s: String, stub: String = PAR_HOLDER) = if (s == null) "" else if (s.length < MAX_STRING_LENGTH) s else stub
80+
private def limitText(txt: String, stub: String = "...", limit: Int = MAX_TEXT_LENGTH) = {
7981
if (txt == null) "" else if (txt.length < MAX_TEXT_LENGTH) txt else txt.substring(0, MAX_TEXT_LENGTH - 1 - stub.length) + stub
8082
}
8183

@@ -88,51 +90,41 @@ object ScalaBreadcrumbsInfoProvider {
8890

8991
def getSignature(fun: ScFunctionExpr): String = getSignature(None, fun.parameters, None)
9092

91-
def getConstructorSignature(constr: ScFunction): String = {
92-
if (!constr.isConstructor) return ""
93-
94-
val signature = getSignature(None, constr.parameters, None)
95-
"this" + limitString(signature)
96-
}
93+
def getConstructorSignature(constr: ScFunction): String =
94+
if (!constr.isConstructor) "" else "this" + limitString(getSignature(None, constr.parameters, None))
9795

98-
def getPrimaryConstructorSignature(constr: ScPrimaryConstructor): String = {
99-
val signature = getSignature(None, constr.parameters, None)
100-
"this" + limitString(signature)
101-
}
96+
def getPrimaryConstructorSignature(constr: ScPrimaryConstructor): String =
97+
"this" + limitString(getSignature(None, constr.parameters, None))
10298

10399
def describeFunction(fun: ScFunction): String = if (fun.isConstructor) getConstructorSignature(fun) else getSignature(fun)
104100

105101
def describeFunction(fun: ScFunctionExpr): String = "λ" + getSignature(fun)
106102

107103
def describeTemplateDef(td: ScTemplateDefinition): String = td match {
108104
case newDef: ScNewTemplateDefinition if Option(newDef.extendsBlock).exists(_.isAnonymousClass) =>
109-
val s = "new " + newDef.extendsBlock.templateParents.map(_.getText).getOrElse("Any")
110-
if (s.length < MAX_STRING_LENGTH * 2) s else s.substring(0, MAX_STRING_LENGTH * 2 - 4) + "..."
105+
val txt = StringBuilder.newBuilder.append("new ").append(newDef.supers.map(_.getName).mkString("", " with ", ""))
106+
if (newDef.constructor.exists(_.args.isDefined)) txt.append(PAR_HOLDER)
107+
108+
limitText(txt.result(), limit = MAX_STRING_LENGTH*2)
111109
case other => other.name
112110
}
113111

114-
def describeMember(mb: ScMember): String = {
115-
mb match {
116-
case pattern: ScPatternDefinition =>
117-
val vs = pattern.bindings.map(b => b.name)
118-
"val " + limitString(if (vs.length == 1) vs.head else vs.mkString("(", ", ", ""))
119-
case other => other.getName
120-
}
112+
def describeMember(mb: ScMember): String = mb match {
113+
case pattern: ScPatternDefinition =>
114+
val vs = pattern.bindings.map(b => b.name)
115+
"val " + limitString(if (vs.length == 1) vs.head else vs.mkString("(", ", ", ""))
116+
case other => other.getName
121117
}
122118

123-
def describeExpression(expr: ScExpression): String = {
124-
expr match {
125-
case ifSt: ScIfStmt => s"if (${limitString(ifSt.condition.map(_.getText).getOrElse(""))}) {...}"
126-
case whileSt: ScWhileStmt => s"while(${limitString(whileSt.condition.map(_.getText).getOrElse(""), "...")})"
127-
case doWhileSt: ScDoStmt => s"do ... while(${limitString(doWhileSt.condition.map(_.getText).getOrElse(""), "...")})"
128-
case matchSt: ScMatchStmt => limitString(matchSt.expr.map(_.getText).getOrElse("(...)")) + " match {...}"
129-
case _ => "Expr"
130-
}
119+
def describeExpression(expr: ScExpression): String = expr match {
120+
case ifSt: ScIfStmt => s"if (${limitString(ifSt.condition.map(_.getText).getOrElse(""))}) {...}"
121+
case whileSt: ScWhileStmt => s"while(${limitString(whileSt.condition.map(_.getText).getOrElse(""), "...")})"
122+
case doWhileSt: ScDoStmt => s"do ... while(${limitString(doWhileSt.condition.map(_.getText).getOrElse(""), "...")})"
123+
case matchSt: ScMatchStmt => limitString(matchSt.expr.map(_.getText).getOrElse(PAR_HOLDER)) + " match {...}"
124+
case _ => "Expr"
131125
}
132126

133-
def describeCaseClause(clause: ScCaseClause): String = {
134-
s"case ${limitString(clause.pattern.map(_.getText).getOrElse(""))} =>"
135-
}
127+
def describeCaseClause(clause: ScCaseClause): String = s"case ${limitString(clause.pattern.map(_.getText).getOrElse(""))} =>"
136128

137129
def getTemplateDefTooltip(td: ScTemplateDefinition): String = {
138130
(td match {
@@ -143,13 +135,9 @@ object ScalaBreadcrumbsInfoProvider {
143135
}) + " " + describeTemplateDef(td)
144136
}
145137

146-
def getFunctionTooltip(fun: ScFunction): String = {
147-
describeFunction(fun) + (if (fun.getBody != null) limitText(fun.getBody.getText) else "")
148-
}
138+
def getFunctionTooltip(fun: ScFunction): String = describeFunction(fun) + (if (fun.getBody != null) limitText(fun.getBody.getText) else "")
149139

150-
def getFunctionTooltip(funExpr: ScFunctionExpr): String = {
151-
limitText(funExpr.getText)
152-
}
140+
def getFunctionTooltip(funExpr: ScFunctionExpr): String = limitText(funExpr.getText)
153141

154142
def getMemberTooltip(member: ScMember): String = limitText(member.getText)
155143

0 commit comments

Comments
 (0)