Skip to content

Commit 7aadbcb

Browse files
author
Dominik Helm
committed
Scala fixes
1 parent 91b9202 commit 7aadbcb

File tree

189 files changed

+621
-637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+621
-637
lines changed

DEVELOPING_OPAL/demos/src/main/scala/org/opalj/ai/InfiniteRecursions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ object InfiniteRecursions extends ProjectsAnalysisApplication {
117117
nextCallOperands: domain.Operands = operandsArray(pc).take(parametersCount)
118118
} {
119119
// IntegerRangeValues and ReferenceValues have useable equals semantics
120-
if (!callOperandsList.exists { _ == nextCallOperands })
120+
if (!callOperandsList.contains(nextCallOperands))
121121
callOperandsList = nextCallOperands :: callOperandsList
122122
}
123123
callOperandsList

DEVELOPING_OPAL/demos/src/main/scala/org/opalj/ai/domain/l1/IfNullParameterAnalysis.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ object IfNullParameterAnalysis extends ProjectsAnalysisApplication {
122122
domain1,
123123
// We need to keep the original location, otherwise
124124
// the correlation analysis would miserably fail!
125-
ex.asInstanceOf[domain2.DomainSingleOriginReferenceValue].origin
125+
ex.asInstanceOf[domain2.DomainSingleOriginReferenceValue]
126+
.origin
126127
).asInstanceOf[domain1.ExceptionValue]
127-
).toSet[domain1.DomainReferenceValue]
128+
)
128129
val diff =
129130
d1thrownException.diff(adaptedD2ThrownException) ++
130131
adaptedD2ThrownException.diff(d1thrownException)

DEVELOPING_OPAL/demos/src/main/scala/org/opalj/ai/domain/l1/MethodReturnValuesAnalysis.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ object MethodReturnValuesAnalysis extends ProjectsAnalysisApplication {
146146

147147
case class RefinedReturnType(method: Method, refinedType: Option[Domain#DomainValue]) {
148148

149-
override def toString(): String = {
149+
override def toString: String = {
150150
import Console.*
151151
"Refined the return type of " + BOLD + BLUE + method.toJava + " => " +
152152
GREEN + refinedType.getOrElse("\"NONE\" (the method does not return normally)") + RESET

DEVELOPING_OPAL/demos/src/main/scala/org/opalj/ba/SimpleInstrumentationDemo.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ class SimpleInstrumentationDemo {
1010
}
1111

1212
def callsToString(): Unit = {
13-
println("the length of the toString representation is: " + this.toString().length())
13+
println("the length of the toString representation is: " + this.toString.length())
1414
}
1515

1616
def returnsValue(i: Int): Int = {
1717
if (i % 2 == 0)
18-
return -1;
18+
-1
1919
else
20-
return 2;
20+
2
2121
}
2222

2323
def playingWithTypes(a: AnyRef): Unit = {

DEVELOPING_OPAL/demos/src/main/scala/org/opalj/bc/HelloWorldClass.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,5 @@ object HelloWorldClass extends App {
206206
attributes = ArraySeq(SourceFile_attribute(32, 33))
207207
)
208208

209-
println("Created class file: " + Files.write(Paths.get("Test.class"), Assembler(cf)).toAbsolutePath())
209+
println("Created class file: " + Files.write(Paths.get("Test.class"), Assembler(cf)).toAbsolutePath)
210210
}

DEVELOPING_OPAL/demos/src/main/scala/org/opalj/br/analyses/MoreCheckers.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ object MoreCheckers {
127127
field <- classFile.fields if field.isProtected
128128
} yield (classFile, field)
129129
} { t => collect("CI_CONFUSED_INHERITANCE", t /*nsToSecs(t)*/ ) }
130-
println(", " /*"\tViolations: "*/ + protectedFields.size)
130+
println(", " /*"\tViolations: "*/ + protectedFields.length)
131131

132132
// FINDBUGS: CN: Class implements Cloneable but does not define or use clone method (CN_IDIOM)
133133
val cloneableNoClone = time {
@@ -174,7 +174,7 @@ object MoreCheckers {
174174
if classHierarchy.isASubtypeOf(classFile.thisType, ClassType.Cloneable).isYesOrUnknown
175175
} yield (classFile.thisType.fqn, method.name)
176176
}(t => collect("CN_IMPLEMENTS_CLONE_BUT_NOT_CLONEABLE", t /*nsToSecs(t)*/ ))
177-
println(", " /*"\tViolations: "*/ /*+cloneButNotCloneable.mkString(", ")*/ + cloneButNotCloneable.size)
177+
println(", " /*"\tViolations: "*/ /*+cloneButNotCloneable.mkString(", ")*/ + cloneButNotCloneable.length)
178178

179179
// FINDBUGS: Co: Abstract class defines covariant compareTo() method (CO_ABSTRACT_SELF)
180180
// FINDBUGS: Co: Covariant compareTo() method defined (CO_SELF_NO_OBJECT)
@@ -201,7 +201,7 @@ object MoreCheckers {
201201
for { // we don't care about gc calls in java.lang and also about gc calls that happen inside of methods related to garbage collection (heuristic)
202202
classFile <- classFiles if !classFile.thisType.fqn.startsWith("java/lang");
203203
method <- classFile.methods
204-
if method.body.isDefined && !"(^gc)|(gc$)".r.findFirstIn(method.name).isDefined;
204+
if method.body.isDefined && "(^gc)|(gc$)".r.findFirstIn(method.name).isEmpty;
205205
instruction <- method.body.get.instructions
206206
} {
207207
instruction match {
@@ -255,7 +255,7 @@ object MoreCheckers {
255255
) <- classFile.methods if method.isAbstract
256256
} yield (classFile, method);
257257
}(t => collect("EQ_ABSTRACT_SELF", t /*nsToSecs(t)*/ ))
258-
println(", " /*"\tViolations: "*/ + abstractCovariantEquals.size)
258+
println(", " /*"\tViolations: "*/ + abstractCovariantEquals.length)
259259

260260
// FINDBUGS: FI: Finalizer should be protected, not public (FI_PUBLIC_SHOULD_BE_PROTECTED)
261261
val classesWithPublicFinalizeMethods = time {
@@ -292,7 +292,7 @@ object MoreCheckers {
292292
if getClassFile.isDefinedAt(superclass) // the class file of some supertypes (defined in libraries, which we do not analyze) may not be available
293293
superClassFile = getClassFile(superclass)
294294
if !superClassFile.isInterfaceDeclaration
295-
if !superClassFile.constructors.exists(_.descriptor.parameterTypes.length == 0)
295+
if !superClassFile.constructors.exists(_.descriptor.parameterTypes.isEmpty)
296296
} yield superclass // there can be at most one method
297297
}(t => collect("SE_NO_SUITABLE_CONSTRUCTOR", t /*nsToSecs(t)*/ ))
298298
println(", " /*"\tViolations: "*/ + classesWithoutDefaultConstructor.size);
@@ -313,7 +313,7 @@ object MoreCheckers {
313313
case _ =>
314314
}
315315
}
316-
if (privateFields.size > 0)
316+
if (privateFields.nonEmpty)
317317
unusedFields = (classFile, privateFields) :: unusedFields
318318
}
319319
}(t => collect("UUF_UNUSED_FIELD", t /*nsToSecs(t)*/ ))
@@ -354,9 +354,9 @@ object MoreCheckers {
354354
classFile <- classFiles if classFile.isClassDeclaration
355355
case method @ MethodWithBody(body) <- classFile.methods
356356
exceptionHandler <- body.exceptionHandlers
357-
if exceptionHandler.catchType == Some(IllegalMonitorStateExceptionType)
357+
if exceptionHandler.catchType.contains(IllegalMonitorStateExceptionType)
358358
} yield (classFile, method)
359359
}(t => collect("IMSE_DONT_CATCH_IMSE", t /*nsToSecs(t)*/ ))
360-
println(", " /*"\tViolations: "*/ + catchesIllegalMonitorStateException.size)
360+
println(", " /*"\tViolations: "*/ + catchesIllegalMonitorStateException.length)
361361
}
362362
}

DEVELOPING_OPAL/demos/src/main/scala/org/opalj/br/analyses/SimpleProjectStatistics.scala

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,17 @@ object SimpleProjectStatistics extends ProjectsAnalysisApplication {
4242
(group, es.size)
4343
}
4444

45-
val maxInstanceFieldsInAClass =
46-
project.allClassFiles.map(_.fields.filter(f => !f.isStatic).size).max
47-
val classWithMaxInstanceFields =
48-
project.allClassFiles.find(
49-
_.fields.filter(f => !f.isStatic).size == maxInstanceFieldsInAClass
50-
).map(_.thisType.toJava)
51-
52-
val maxClassFieldsInAClass =
53-
project.allClassFiles.map(_.fields.filter(f => f.isStatic).size).max
54-
val classWithMaxClassFields =
55-
project.allClassFiles.find(
56-
_.fields.filter(f => f.isStatic).size == maxClassFieldsInAClass
57-
).map(_.thisType.toJava)
58-
59-
val maxMethodsInAClass =
60-
project.allClassFiles.map(_.methods.size).max
61-
val classWithMaxMethods =
62-
project.allClassFiles.find(
63-
_.methods.size == maxMethodsInAClass
64-
).map(_.thisType.toJava)
45+
val maxInstanceFieldsInAClass = project.allClassFiles.map(_.fields.count(f => !f.isStatic)).max
46+
val classWithMaxInstanceFields = project.allClassFiles
47+
.find(_.fields.count(f => !f.isStatic) == maxInstanceFieldsInAClass).map(_.thisType.toJava)
48+
49+
val maxClassFieldsInAClass = project.allClassFiles.map(_.fields.count(f => f.isStatic)).max
50+
val classWithMaxClassFields = project.allClassFiles
51+
.find(_.fields.count(f => f.isStatic) == maxClassFieldsInAClass).map(_.thisType.toJava)
52+
53+
val maxMethodsInAClass = project.allClassFiles.map(_.methods.size).max
54+
val classWithMaxMethods = project.allClassFiles
55+
.find(_.methods.size == maxMethodsInAClass).map(_.thisType.toJava)
6556

6657
val (longestMethodInAClass, theLongestMethod) = {
6758
var max = 0

DEVELOPING_OPAL/demos/src/main/scala/org/opalj/br/analyses/observers/ObserverPatternUsage.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ object ObserverPatternUsage extends ProjectsAnalysisApplication {
3838
val appClassFiles = project.allProjectClassFiles
3939
val libClassFiles = project.allLibraryClassFiles
4040
println("Application:\n\tClasses:" + appClassFiles.size)
41-
println("\tMethods:" + appClassFiles.foldLeft(0)(_ + _.methods.filter(!_.isSynthetic).size))
42-
println("\tNon-final Fields:" + appClassFiles.foldLeft(0)(_ + _.fields.filter(!_.isFinal).size))
41+
println("\tMethods:" + appClassFiles.foldLeft(0)(_ + _.methods.count(!_.isSynthetic)))
42+
println("\tNon-final Fields:" + appClassFiles.foldLeft(0)(_ + _.fields.count(!_.isFinal)))
4343
println("Library:\n\tClasses:" + libClassFiles.size)
4444
println("Overall " + project.statistics)
4545

DEVELOPING_OPAL/tools/src/main/scala/org/opalj/support/debug/ClassHierarchyVisualizer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ object ClassHierarchyVisualizer extends ProjectsAnalysisApplication {
3434

3535
val (project, _) = analysisConfig.setupProject(cp)
3636

37-
val dotGraph = toDot(Set(project.classHierarchy.toGraph()), "back")
37+
val dotGraph = toDot(Set(project.classHierarchy.toGraph), "back")
38+
3839
val file = writeAndOpen(dotGraph, "ClassHierarchy", ".gv")
3940
println(s"Wrote class hierarchy graph to: $file.")
4041
}

DEVELOPING_OPAL/tools/src/main/scala/org/opalj/support/debug/ConsoleTracer.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import org.opalj.ai.Domain
99
import org.opalj.ai.NoUpdate
1010
import org.opalj.ai.SomeUpdate
1111
import org.opalj.ai.Update
12-
import org.opalj.ai.domain
1312
import org.opalj.ai.domain.TheCode
13+
import org.opalj.ai.domain.l1.ReferenceValues
1414
import org.opalj.br.Code
1515
import org.opalj.br.instructions.Instruction
1616
import org.opalj.collection.mutable.IntArrayStack
@@ -68,10 +68,10 @@ trait ConsoleTracer extends AITracer { tracer =>
6868
case rv: IsReferenceValue if rv.allValues.size > 1 =>
6969
val values = rv.allValues
7070
val t =
71-
if (rv.isInstanceOf[domain.l1.ReferenceValues#TheReferenceValue])
72-
s";refId=${rv.asInstanceOf[org.opalj.ai.domain.l1.ReferenceValues#TheReferenceValue].refId}"
73-
else
74-
""
71+
rv match {
72+
case value1: ReferenceValues#TheReferenceValue => s";refId=${value1.refId}"
73+
case _ => ""
74+
}
7575
values.map(toStringWithOID(_)).mkString("OneOf[" + values.size + "](", ",", ")") +
7676
rv.upperTypeBound.map(_.toJava).mkString(";lutb=", " with ", ";") +
7777
s"isPrecise=${rv.isPrecise};isNull=${rv.isNull}$t " +
@@ -115,7 +115,7 @@ trait ConsoleTracer extends AITracer { tracer =>
115115

116116
val ps = {
117117
val ps = domain.properties(pc)
118-
if ((ps eq null) || ps == None)
118+
if ((ps eq null) || ps.isEmpty)
119119
""
120120
else {
121121
s"\tproperties: ${ps.get}\n"
@@ -173,7 +173,7 @@ trait ConsoleTracer extends AITracer { tracer =>
173173

174174
override def deadLocalVariable(domain: Domain)(pc: Int, lvIndex: Int): Unit = {
175175
println(
176-
pc.toString + line(domain, pc).toString + ":" +
176+
pc.toString + line(domain, pc) + ":" +
177177
Console.BLACK_B + Console.WHITE + s"local variable $lvIndex is dead"
178178
)
179179
}
@@ -382,7 +382,7 @@ trait ConsoleTracer extends AITracer { tracer =>
382382
): Unit = {
383383
val loc = pc.map(pc => s"$pc:").getOrElse("<NO PC>")
384384
println(
385-
s"$loc[Domain:${source.getSimpleName().split('$')(0)} - $typeID] $message"
385+
s"$loc[Domain:${source.getSimpleName.split('$')(0)} - $typeID] $message"
386386
)
387387
}
388388
}

0 commit comments

Comments
 (0)