diff options
author | Janek Bogucki <janekdb@gmail.com> | 2015-11-26 22:27:19 +0000 |
---|---|---|
committer | Janek Bogucki <janekdb@gmail.com> | 2015-11-26 22:27:19 +0000 |
commit | 9d6cdf0066716da71b3d668628a25859b353ee5e (patch) | |
tree | c5d6ca766a609ad60b5e08da5e680746d07b53d0 /src/reflect/scala/reflect | |
parent | 2890f0b767948dd9a0953b1e669e85dbd45ec0a7 (diff) | |
download | scala-9d6cdf0066716da71b3d668628a25859b353ee5e.tar.gz scala-9d6cdf0066716da71b3d668628a25859b353ee5e.tar.bz2 scala-9d6cdf0066716da71b3d668628a25859b353ee5e.zip |
Apply some static code analysis recommendations
Fix a batch of code inspection recommendations generated by IntelliJ 14.1.5.
Categories of fix,
Unnecessary public modifier in interface
Replace filter+size with count
Replace filter+nonEmpty with exists
Replace filter+headOption with find
Replace `if (x != null) Some(x) else None` with Option(x)
Replace getOrElse null with orNull
Drop redundant semicolons
Replace anon fun with PF
Replace anon fun with method
Diffstat (limited to 'src/reflect/scala/reflect')
4 files changed, 8 insertions, 8 deletions
diff --git a/src/reflect/scala/reflect/internal/util/WeakHashSet.scala b/src/reflect/scala/reflect/internal/util/WeakHashSet.scala index 3a7a7626fb..83d2a3453b 100644 --- a/src/reflect/scala/reflect/internal/util/WeakHashSet.scala +++ b/src/reflect/scala/reflect/internal/util/WeakHashSet.scala @@ -41,7 +41,7 @@ final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: D * power of two equal to or greater than the specified initial capacity */ private def computeCapacity = { - if (initialCapacity < 0) throw new IllegalArgumentException("initial capacity cannot be less than 0"); + if (initialCapacity < 0) throw new IllegalArgumentException("initial capacity cannot be less than 0") var candidate = 1 while (candidate < initialCapacity) { candidate *= 2 @@ -372,13 +372,13 @@ final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: D * Number of buckets that hold collisions. Useful for diagnosing performance issues. */ def collisionBucketsCount: Int = - (table filter (entry => entry != null && entry.tail != null)).size + (table count (entry => entry != null && entry.tail != null)) /** * Number of buckets that are occupied in this hash table. */ def fullBucketsCount: Int = - (table filter (entry => entry != null)).size + (table count (entry => entry != null)) /** * Number of buckets in the table diff --git a/src/reflect/scala/reflect/macros/Attachments.scala b/src/reflect/scala/reflect/macros/Attachments.scala index b5c340645a..0b5360c004 100644 --- a/src/reflect/scala/reflect/macros/Attachments.scala +++ b/src/reflect/scala/reflect/macros/Attachments.scala @@ -39,7 +39,7 @@ abstract class Attachments { self => /** An underlying payload of the given class type `T`. */ def get[T: ClassTag]: Option[T] = - (all filter matchesTag[T]).headOption.asInstanceOf[Option[T]] + (all find matchesTag[T]).asInstanceOf[Option[T]] /** Check underlying payload contains an instance of type `T`. */ def contains[T: ClassTag]: Boolean = diff --git a/src/reflect/scala/reflect/runtime/ReflectionUtils.scala b/src/reflect/scala/reflect/runtime/ReflectionUtils.scala index a4bd698068..a278ed3fd7 100644 --- a/src/reflect/scala/reflect/runtime/ReflectionUtils.scala +++ b/src/reflect/scala/reflect/runtime/ReflectionUtils.scala @@ -72,7 +72,7 @@ object ReflectionUtils { def singletonAccessor(clazz: Class[_]): Option[Method] = if (clazz == null) None else { - val declaredAccessor = clazz.getDeclaredMethods.filter(_.getName == accessorName).headOption + val declaredAccessor = clazz.getDeclaredMethods.find(_.getName == accessorName) declaredAccessor orElse singletonAccessor(clazz.getSuperclass) } @@ -92,7 +92,7 @@ object ReflectionUtils { } class EnclosedIn[T](enclosure: jClass[_] => T) { - def unapply(jclazz: jClass[_]): Option[T] = if (enclosure(jclazz) != null) Some(enclosure(jclazz)) else None + def unapply(jclazz: jClass[_]): Option[T] = Option(enclosure(jclazz)) } object EnclosedInMethod extends EnclosedIn(_.getEnclosingMethod) diff --git a/src/reflect/scala/reflect/runtime/SynchronizedOps.scala b/src/reflect/scala/reflect/runtime/SynchronizedOps.scala index 4a8585d616..f0d96e0fd6 100644 --- a/src/reflect/scala/reflect/runtime/SynchronizedOps.scala +++ b/src/reflect/scala/reflect/runtime/SynchronizedOps.scala @@ -15,7 +15,7 @@ private[reflect] trait SynchronizedOps extends internal.SymbolTable override protected def newBaseTypeSeq(parents: List[Type], elems: Array[Type]) = // only need to synchronize BaseTypeSeqs if they contain refined types - if (elems.filter(_.isInstanceOf[RefinedType]).nonEmpty) new BaseTypeSeq(parents, elems) with SynchronizedBaseTypeSeq + if (elems.exists(_.isInstanceOf[RefinedType])) new BaseTypeSeq(parents, elems) with SynchronizedBaseTypeSeq else new BaseTypeSeq(parents, elems) trait SynchronizedBaseTypeSeq extends BaseTypeSeq { @@ -31,7 +31,7 @@ private[reflect] trait SynchronizedOps extends internal.SymbolTable override def lateMap(f: Type => Type): BaseTypeSeq = // only need to synchronize BaseTypeSeqs if they contain refined types - if (map(f).toList.filter(_.isInstanceOf[RefinedType]).nonEmpty) new MappedBaseTypeSeq(this, f) with SynchronizedBaseTypeSeq + if (map(f).toList.exists(_.isInstanceOf[RefinedType])) new MappedBaseTypeSeq(this, f) with SynchronizedBaseTypeSeq else new MappedBaseTypeSeq(this, f) } |