Skip to content

Commit 67153b0

Browse files
committed
Code cleanup
1 parent 524e60e commit 67153b0

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

src/org/jetbrains/plugins/scala/lang/psi/types/ScExistentialType.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ case class ScExistentialType(quantified : ScType,
5252
case a: ScTypeAlias if a.getContext.isInstanceOf[ScExistentialClause] =>
5353
if (!rejected.contains(a.name)) {
5454
wildcards.find(_.name == a.name) match {
55-
case Some(arg) => (true, unpacked.get(arg).getOrElse(tp), rejected)
55+
case Some(arg) => (true, unpacked.getOrElse(arg, tp), rejected)
5656
case _ => (true, tp, rejected)
5757
}
5858
} else (true, tp, rejected)
@@ -61,7 +61,7 @@ case class ScExistentialType(quantified : ScType,
6161
case ScTypeVariable(name) =>
6262
if (!rejected.contains(name)) {
6363
wildcards.find(_.name == name) match {
64-
case Some(arg) => (true, unpacked.get(arg).getOrElse(tp), rejected)
64+
case Some(arg) => (true, unpacked.getOrElse(arg, tp), rejected)
6565
case _ => (true, tp, rejected)
6666
}
6767
} else (true, tp, rejected)
@@ -214,10 +214,11 @@ case class ScExistentialType(quantified : ScType,
214214
})
215215
case ScDesignatorType(elem) =>
216216
elem match {
217-
case ta: ScTypeAlias if ta.getContext.isInstanceOf[ScExistentialClause] =>
218-
wildcards.foreach(arg => if (arg.name == ta.name && !rejected.contains(arg.name)) {
219-
res.update(arg, res.getOrElse(arg, Seq.empty[ScType]) ++ Seq(tp))
220-
})
217+
case ta: ScTypeAlias if ta.isExistentialTypeAlias =>
218+
wildcards.foreach(arg =>
219+
if (arg.name == ta.name && !rejected.contains(arg.name)) {
220+
res.update(arg, res.getOrElse(arg, Seq.empty[ScType]) ++ Seq(tp))
221+
})
221222
case _ =>
222223
}
223224
case ScTypeVariable(name) =>
@@ -345,7 +346,7 @@ case class ScExistentialType(quantified : ScType,
345346
updateRecursive(arg.lowerBound, newSet, -variance), updateRecursive(arg.upperBound, newSet, variance))))
346347
case ScThisType(clazz) => tp
347348
case ScDesignatorType(element) => element match {
348-
case a: ScTypeAlias if a.getContext.isInstanceOf[ScExistentialClause] =>
349+
case a: ScTypeAlias if a.isExistentialTypeAlias =>
349350
if (!rejected.contains(a.name)) {
350351
wildcards.find(_.name == a.name) match {
351352
case Some(arg) => update(variance, arg, tp)

src/org/jetbrains/plugins/scala/lang/psi/types/ScSubstitutor.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import com.intellij.psi._
88
import org.jetbrains.plugins.scala.lang.psi.api.base.ScFieldId
99
import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScBindingPattern
1010
import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction
11-
import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScParameter
11+
import org.jetbrains.plugins.scala.lang.psi.api.statements.params.{ScTypeParam, ScParameter}
1212
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition
1313
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScTemplateDefinition, ScTypeDefinition}
1414
import org.jetbrains.plugins.scala.lang.psi.types.nonvalue.{Parameter, ScMethodType, ScTypePolymorphicType, TypeParameter}
1515
import org.jetbrains.plugins.scala.lang.psi.types.result.TypingContext
1616

17+
import scala.annotation.tailrec
1718
import scala.collection.immutable.{HashMap, HashSet, Map}
1819

1920
/**
@@ -110,8 +111,8 @@ class ScSubstitutor(val tvMap: Map[(String, String), ScType],
110111
private def followed(s: ScSubstitutor, level: Int): ScSubstitutor = {
111112
if (level > ScSubstitutor.followLimit)
112113
throw new RuntimeException("Too much followers for substitutor: " + this.toString)
113-
if (follower == null && tvMap.size + aliasesMap.size == 0 && updateThisType == None && !myDependentMethodTypesFunDefined) s
114-
else if (s.getFollower == null && s.tvMap.size + s.aliasesMap.size == 0 && s.updateThisType == None && !s.myDependentMethodTypesFunDefined) this
114+
if (follower == null && tvMap.size + aliasesMap.size == 0 && updateThisType.isEmpty && !myDependentMethodTypesFunDefined) s
115+
else if (s.getFollower == null && s.tvMap.size + s.aliasesMap.size == 0 && s.updateThisType.isEmpty && !s.myDependentMethodTypesFunDefined) this
115116
else {
116117
val res = new ScSubstitutor(tvMap, aliasesMap, updateThisType,
117118
if (follower != null) follower followed (s, level + 1) else s)
@@ -130,7 +131,7 @@ class ScSubstitutor(val tvMap: Map[(String, String), ScType],
130131
}
131132

132133
private def extractTpt(tpt: ScTypeParameterType, t: ScType): ScType = {
133-
if (tpt.args.length == 0) t
134+
if (tpt.args.isEmpty) t
134135
else t match {
135136
case ScParameterizedType(designator, _) => designator
136137
case _ => t
@@ -330,7 +331,7 @@ class ScSubstitutor(val tvMap: Map[(String, String), ScType],
330331
case tpt: ScTypeParameterType =>
331332
tvMap.get((tpt.name, tpt.getId)) match {
332333
case Some(param: ScParameterizedType) if pt != param =>
333-
if (tpt.args.length == 0) {
334+
if (tpt.args.isEmpty) {
334335
substInternal(param) //to prevent types like T[A][A]
335336
} else {
336337
ScParameterizedType(param.designator, typeArgs.map(substInternal))
@@ -344,7 +345,7 @@ class ScSubstitutor(val tvMap: Map[(String, String), ScType],
344345
case u: ScUndefinedType =>
345346
tvMap.get((u.tpt.name, u.tpt.getId)) match {
346347
case Some(param: ScParameterizedType) if pt != param =>
347-
if (u.tpt.args.length == 0) {
348+
if (u.tpt.args.isEmpty) {
348349
substInternal(param) //to prevent types like T[A][A]
349350
} else {
350351
ScParameterizedType(param.designator, typeArgs map substInternal)
@@ -358,7 +359,7 @@ class ScSubstitutor(val tvMap: Map[(String, String), ScType],
358359
case u: ScAbstractType =>
359360
tvMap.get((u.tpt.name, u.tpt.getId)) match {
360361
case Some(param: ScParameterizedType) if pt != param =>
361-
if (u.tpt.args.length == 0) {
362+
if (u.tpt.args.isEmpty) {
362363
substInternal(param) //to prevent types like T[A][A]
363364
} else {
364365
ScParameterizedType(param.designator, typeArgs map substInternal)
@@ -714,7 +715,7 @@ class ScUndefinedSubstitutor(val upperMap: Map[(String, String), HashSet[ScType]
714715
case None =>
715716
}
716717

717-
if (tvMap.get(name) == None) {
718+
if (tvMap.get(name).isEmpty) {
718719
tvMap += ((name, Nothing))
719720
}
720721
tvMap.get(name)

src/org/jetbrains/plugins/scala/lang/psi/types/ScType.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ trait ScType {
6767
(true, ScTypeVariable(s.name))
6868
case t => (false, t)
6969
})
70-
if (wildcards.length > 0) {
70+
if (wildcards.nonEmpty) {
7171
ScExistentialType(quantified, wildcards.toList).simplify()
7272
} else quantified
7373
}
@@ -210,6 +210,7 @@ object ScType extends ScTypePresentation with ScTypePsiTypeBridge {
210210
"scala.AnyVal" -> AnyVal
211211
)
212212

213+
@tailrec
213214
def extractClass(t: ScType, project: Option[Project] = None): Option[PsiClass] = {
214215
t match {
215216
case p@ScParameterizedType(t1, _) => extractClass(t1, project) //performance improvement
@@ -402,6 +403,7 @@ object ScType extends ScTypePresentation with ScTypePsiTypeBridge {
402403
*
403404
* nested(foo.methodType(...), 1) => MethodType(retType = Boolean, params = Seq(String))
404405
*/
406+
@tailrec
405407
def nested(tpe: ScType, n: Int): Option[ScType] = {
406408
if (n == 0) Some(tpe)
407409
else tpe match {

0 commit comments

Comments
 (0)