@@ -68,14 +68,16 @@ class ScalaBreadcrumbsInfoProvider extends BreadcrumbsInfoProvider {
68
68
}
69
69
70
70
object ScalaBreadcrumbsInfoProvider {
71
+ private val PAR_HOLDER = " (...)"
72
+
71
73
val SCALA_LANG : Array [Language ] = Array [Language ](ScalaLanguage .INSTANCE )
72
74
73
75
val MAX_TEXT_LENGTH = 150
74
76
val MAX_STRING_LENGTH = 25
75
77
76
78
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 ) = {
79
81
if (txt == null ) " " else if (txt.length < MAX_TEXT_LENGTH ) txt else txt.substring(0 , MAX_TEXT_LENGTH - 1 - stub.length) + stub
80
82
}
81
83
@@ -88,51 +90,41 @@ object ScalaBreadcrumbsInfoProvider {
88
90
89
91
def getSignature (fun : ScFunctionExpr ): String = getSignature(None , fun.parameters, None )
90
92
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 ))
97
95
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 ))
102
98
103
99
def describeFunction (fun : ScFunction ): String = if (fun.isConstructor) getConstructorSignature(fun) else getSignature(fun)
104
100
105
101
def describeFunction (fun : ScFunctionExpr ): String = " λ" + getSignature(fun)
106
102
107
103
def describeTemplateDef (td : ScTemplateDefinition ): String = td match {
108
104
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 )
111
109
case other => other.name
112
110
}
113
111
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
121
117
}
122
118
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"
131
125
}
132
126
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(" " ))} => "
136
128
137
129
def getTemplateDefTooltip (td : ScTemplateDefinition ): String = {
138
130
(td match {
@@ -143,13 +135,9 @@ object ScalaBreadcrumbsInfoProvider {
143
135
}) + " " + describeTemplateDef(td)
144
136
}
145
137
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 " " )
149
139
150
- def getFunctionTooltip (funExpr : ScFunctionExpr ): String = {
151
- limitText(funExpr.getText)
152
- }
140
+ def getFunctionTooltip (funExpr : ScFunctionExpr ): String = limitText(funExpr.getText)
153
141
154
142
def getMemberTooltip (member : ScMember ): String = limitText(member.getText)
155
143
0 commit comments