Skip to content

Commit 9d6cdf0

Browse files
committed
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
1 parent 2890f0b commit 9d6cdf0

File tree

14 files changed

+31
-31
lines changed

14 files changed

+31
-31
lines changed

src/library/scala/reflect/ScalaLongSignature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
@Retention(RetentionPolicy.RUNTIME)
99
@Target(ElementType.TYPE)
1010
public @interface ScalaLongSignature {
11-
public String[] bytes();
11+
String[] bytes();
1212
}

src/library/scala/reflect/ScalaSignature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
@Retention(RetentionPolicy.RUNTIME)
99
@Target(ElementType.TYPE)
1010
public @interface ScalaSignature {
11-
public String bytes();
11+
String bytes();
1212
}

src/reflect/scala/reflect/internal/util/WeakHashSet.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: D
4141
* power of two equal to or greater than the specified initial capacity
4242
*/
4343
private def computeCapacity = {
44-
if (initialCapacity < 0) throw new IllegalArgumentException("initial capacity cannot be less than 0");
44+
if (initialCapacity < 0) throw new IllegalArgumentException("initial capacity cannot be less than 0")
4545
var candidate = 1
4646
while (candidate < initialCapacity) {
4747
candidate *= 2
@@ -372,13 +372,13 @@ final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: D
372372
* Number of buckets that hold collisions. Useful for diagnosing performance issues.
373373
*/
374374
def collisionBucketsCount: Int =
375-
(table filter (entry => entry != null && entry.tail != null)).size
375+
(table count (entry => entry != null && entry.tail != null))
376376

377377
/**
378378
* Number of buckets that are occupied in this hash table.
379379
*/
380380
def fullBucketsCount: Int =
381-
(table filter (entry => entry != null)).size
381+
(table count (entry => entry != null))
382382

383383
/**
384384
* Number of buckets in the table

src/reflect/scala/reflect/macros/Attachments.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ abstract class Attachments { self =>
3939

4040
/** An underlying payload of the given class type `T`. */
4141
def get[T: ClassTag]: Option[T] =
42-
(all filter matchesTag[T]).headOption.asInstanceOf[Option[T]]
42+
(all find matchesTag[T]).asInstanceOf[Option[T]]
4343

4444
/** Check underlying payload contains an instance of type `T`. */
4545
def contains[T: ClassTag]: Boolean =

src/reflect/scala/reflect/runtime/ReflectionUtils.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ object ReflectionUtils {
7272
def singletonAccessor(clazz: Class[_]): Option[Method] =
7373
if (clazz == null) None
7474
else {
75-
val declaredAccessor = clazz.getDeclaredMethods.filter(_.getName == accessorName).headOption
75+
val declaredAccessor = clazz.getDeclaredMethods.find(_.getName == accessorName)
7676
declaredAccessor orElse singletonAccessor(clazz.getSuperclass)
7777
}
7878

@@ -92,7 +92,7 @@ object ReflectionUtils {
9292
}
9393

9494
class EnclosedIn[T](enclosure: jClass[_] => T) {
95-
def unapply(jclazz: jClass[_]): Option[T] = if (enclosure(jclazz) != null) Some(enclosure(jclazz)) else None
95+
def unapply(jclazz: jClass[_]): Option[T] = Option(enclosure(jclazz))
9696
}
9797

9898
object EnclosedInMethod extends EnclosedIn(_.getEnclosingMethod)

src/reflect/scala/reflect/runtime/SynchronizedOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private[reflect] trait SynchronizedOps extends internal.SymbolTable
1515

1616
override protected def newBaseTypeSeq(parents: List[Type], elems: Array[Type]) =
1717
// only need to synchronize BaseTypeSeqs if they contain refined types
18-
if (elems.filter(_.isInstanceOf[RefinedType]).nonEmpty) new BaseTypeSeq(parents, elems) with SynchronizedBaseTypeSeq
18+
if (elems.exists(_.isInstanceOf[RefinedType])) new BaseTypeSeq(parents, elems) with SynchronizedBaseTypeSeq
1919
else new BaseTypeSeq(parents, elems)
2020

2121
trait SynchronizedBaseTypeSeq extends BaseTypeSeq {
@@ -31,7 +31,7 @@ private[reflect] trait SynchronizedOps extends internal.SymbolTable
3131

3232
override def lateMap(f: Type => Type): BaseTypeSeq =
3333
// only need to synchronize BaseTypeSeqs if they contain refined types
34-
if (map(f).toList.filter(_.isInstanceOf[RefinedType]).nonEmpty) new MappedBaseTypeSeq(this, f) with SynchronizedBaseTypeSeq
34+
if (map(f).toList.exists(_.isInstanceOf[RefinedType])) new MappedBaseTypeSeq(this, f) with SynchronizedBaseTypeSeq
3535
else new MappedBaseTypeSeq(this, f)
3636
}
3737

src/repl/scala/tools/nsc/interpreter/JLineCompletion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class JLineCompletion(val intp: IMain) extends Completion with CompletionOutput
175175
case Some((clazz, runtimeType)) =>
176176
val sym = intp.symbolOfTerm(id)
177177
if (sym.isStable) {
178-
val param = new NamedParam.Untyped(id, intp valueOfTerm id getOrElse null)
178+
val param = new NamedParam.Untyped(id, intp valueOfTerm id orNull)
179179
Some(TypeMemberCompletion(tpe, runtimeType, param))
180180
}
181181
else default

src/repl/scala/tools/nsc/interpreter/JavapClass.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,11 +600,11 @@ object JavapClass {
600600
def parents: List[ClassLoader] = parentsOf(loader)
601601
/* all file locations */
602602
def locations = {
603-
def alldirs = parents flatMap (_ match {
603+
def alldirs = parents flatMap {
604604
case ucl: ScalaClassLoader.URLClassLoader => ucl.classPathURLs
605605
case jcl: java.net.URLClassLoader => jcl.getURLs
606606
case _ => Nil
607-
})
607+
}
608608
val dirs = for (d <- alldirs; if d.getProtocol == "file") yield Path(new JFile(d.toURI))
609609
dirs
610610
}

src/scalap/scala/tools/scalap/CodeWriter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CodeWriter(writer: Writer) {
3535
def setIndentWidth(width: Int): CodeWriter =
3636
setIndentString(List.fill(width)(' ').mkString)
3737

38-
def getIndentString = step;
38+
def getIndentString = step
3939

4040
def setIndentString(step: String): CodeWriter = {
4141
this.step = step

src/scalap/scala/tools/scalap/Decode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ object Decode {
4949
import classFile._
5050

5151
classFile annotation SCALA_SIG_ANNOTATION map { case Annotation(_, els) =>
52-
val bytesElem = els find (x => constant(x.elementNameIndex) == BYTES_VALUE) getOrElse null
52+
val bytesElem = els find (x => constant(x.elementNameIndex) == BYTES_VALUE) orNull
5353
val _bytes = bytesElem.elementValue match { case ConstValueIndex(x) => constantWrapped(x) }
5454
val bytes = _bytes.asInstanceOf[StringBytesPair].bytes
5555
val length = ByteCodecs.decode(bytes)

0 commit comments

Comments
 (0)