Skip to content

Commit e196264

Browse files
authored
Merge pull request #236 from marcus-h/fix_opal_getClasses
Make the behavior of OpalWrappedClass.getMethods consistent
2 parents ac35971 + f35d3e9 commit e196264

File tree

3 files changed

+71
-9
lines changed

3 files changed

+71
-9
lines changed

boomerangScope-Opal/src/main/scala/boomerang/scope/opal/tac/OpalWrappedClass.scala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,17 @@ import org.opalj.br.analyses.Project
2525
class OpalWrappedClass(val delegate: ClassType, project: Project[_]) extends WrappedClass {
2626

2727
override def getMethods: util.Set[Method] = {
28+
val methods = new util.HashSet[Method]
2829
val classFile = project.classFile(delegate)
2930

3031
if (classFile.isDefined) {
31-
val methods = new util.HashSet[Method]
32-
33-
classFile.get.methods.foreach(method => {
34-
methods.add(OpalMethod.of(method, project))
35-
})
36-
37-
return methods
32+
classFile.get.methods
33+
.filter(!_.body.isEmpty)
34+
.foreach(method => {
35+
methods.add(OpalMethod.of(method, project))
36+
})
3837
}
39-
40-
throw new RuntimeException("Class file of class not available: " + delegate.fqn)
38+
return methods
4139
}
4240

4341
override def hasSuperclass: Boolean = {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* *****************************************************************************
3+
* Copyright (c) 2018 Fraunhofer IEM, Paderborn, Germany
4+
* <p>
5+
* This program and the accompanying materials are made available under the
6+
* terms of the Eclipse Public License 2.0 which is available at
7+
* http://www.eclipse.org/legal/epl-2.0.
8+
* <p>
9+
* SPDX-License-Identifier: EPL-2.0
10+
* <p>
11+
* Contributors:
12+
* Johannes Spaeth - initial API and implementation
13+
* *****************************************************************************
14+
*/
15+
package boomerang.scope.opal
16+
17+
import boomerang.scope.opal.tac.OpalWrappedClass
18+
import boomerang.scope.test.targets.AbstractClass
19+
import org.junit.jupiter.api.Assertions
20+
import org.junit.jupiter.api.Test
21+
import org.opalj.br.ClassType
22+
23+
class OpalWrappedClassTest {
24+
25+
@Test
26+
def testGetMethodsAbstractClass(): Unit = {
27+
val opalSetup = new OpalSetup
28+
opalSetup.setupOpal(classOf[AbstractClass].getName)
29+
val wrappedClass = new OpalWrappedClass(opalSetup.targetClass.get.thisType, opalSetup.project.get)
30+
Assertions.assertEquals(2, wrappedClass.getMethods.size)
31+
}
32+
33+
@Test
34+
def testGetMethodsForClassTypeThatIsNotPartOfTheProject(): Unit = {
35+
val opalSetup = new OpalSetup
36+
opalSetup.setupOpal("Some Dummy Value")
37+
val wrappedClass = new OpalWrappedClass(ClassType.Object, opalSetup.project.get)
38+
Assertions.assertEquals(0, wrappedClass.getMethods.size)
39+
}
40+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* *****************************************************************************
3+
* Copyright (c) 2018 Fraunhofer IEM, Paderborn, Germany
4+
* <p>
5+
* This program and the accompanying materials are made available under the
6+
* terms of the Eclipse Public License 2.0 which is available at
7+
* http://www.eclipse.org/legal/epl-2.0.
8+
* <p>
9+
* SPDX-License-Identifier: EPL-2.0
10+
* <p>
11+
* Contributors:
12+
* Johannes Spaeth - initial API and implementation
13+
* *****************************************************************************
14+
*/
15+
package boomerang.scope.test.targets;
16+
17+
public abstract class AbstractClass {
18+
19+
public AbstractClass() {}
20+
21+
public abstract void foo();
22+
23+
public void bar() {}
24+
}

0 commit comments

Comments
 (0)