Skip to content

Commit 0d51aaf

Browse files
authored
Static inner class returns false when isStatic is used #192 (#204)
* Static inner class returns false when isStatic is used #192 * fix tests
1 parent 00e2a3d commit 0d51aaf

File tree

5 files changed

+56
-22
lines changed

5 files changed

+56
-22
lines changed

jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcClassOrInterfaceImpl.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class JcClassOrInterfaceImpl(
9292

9393
override val innerClasses: List<JcClassOrInterface>
9494
get() {
95-
return info.innerClasses.map {
95+
return info.innerClasses.filter { it != name }.map {
9696
classpath.findClass(it)
9797
}
9898
}

jacodb-core/src/main/kotlin/org/jacodb/impl/fs/ByteCodeConverter.kt

+3-17
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,16 @@ package org.jacodb.impl.fs
1919
import kotlinx.collections.immutable.toImmutableList
2020
import org.jacodb.api.ClassSource
2121
import org.jacodb.impl.storage.AnnotationValueKind
22-
import org.jacodb.impl.types.AnnotationInfo
23-
import org.jacodb.impl.types.AnnotationValue
24-
import org.jacodb.impl.types.AnnotationValueList
25-
import org.jacodb.impl.types.ClassInfo
26-
import org.jacodb.impl.types.ClassRef
27-
import org.jacodb.impl.types.EnumRef
28-
import org.jacodb.impl.types.FieldInfo
29-
import org.jacodb.impl.types.MethodInfo
30-
import org.jacodb.impl.types.OuterClassRef
31-
import org.jacodb.impl.types.ParameterInfo
32-
import org.jacodb.impl.types.PrimitiveValue
22+
import org.jacodb.impl.types.*
3323
import org.objectweb.asm.ClassReader
3424
import org.objectweb.asm.Opcodes
3525
import org.objectweb.asm.Type
36-
import org.objectweb.asm.tree.AnnotationNode
37-
import org.objectweb.asm.tree.ClassNode
38-
import org.objectweb.asm.tree.FieldNode
39-
import org.objectweb.asm.tree.MethodNode
40-
import org.objectweb.asm.tree.TypeAnnotationNode
26+
import org.objectweb.asm.tree.*
4127

4228
fun ClassNode.asClassInfo(bytecode: ByteArray) = ClassInfo(
4329
name = Type.getObjectType(name).className,
4430
signature = signature,
45-
access = access,
31+
access = innerClasses?.firstOrNull { it.name == name }?.access ?: access,
4632

4733
outerClass = outerClassRef(),
4834
innerClasses = innerClasses.map {

jacodb-core/src/main/kotlin/org/jacodb/impl/types/TypeParameters.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ fun JcClassOrInterface.directTypeParameters(): List<JvmTypeParameterDeclaration>
4343
*/
4444
fun JcClassOrInterface.allVisibleTypeParameters(): Map<String, JvmTypeParameterDeclaration> {
4545
val direct = typeParameters.associateBy { it.symbol }
46+
val fromMethod = outerMethod?.allVisibleTypeParameters().orEmpty()
4647
if (!isStatic) {
47-
val fromOuter = outerClass?.allVisibleTypeParameters()
48-
val fromMethod = outerMethod?.allVisibleTypeParameters()
49-
return ((fromMethod ?: fromOuter).orEmpty() + direct).toPersistentMap()
48+
val fromOuter = outerClass?.allVisibleTypeParameters().orEmpty()
49+
return (direct + fromOuter + fromMethod).toPersistentMap()
5050
}
51-
return direct
51+
return (direct + fromMethod).toPersistentMap()
5252
}
5353

5454
fun JcMethod.allVisibleTypeParameters(): Map<String, JvmTypeParameterDeclaration> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2022 UnitTestBot contributors (utbot.org)
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jacodb.testing.types;
18+
19+
public class AAA {
20+
21+
public class BBB {
22+
23+
}
24+
25+
static public class CCC {
26+
27+
}
28+
}

jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/tests/DatabaseEnvTest.kt

+20
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import org.jacodb.testing.*
3232
import org.jacodb.testing.hierarchies.Creature
3333
import org.jacodb.testing.structure.FieldsAndMethods
3434
import org.jacodb.testing.structure.HiddenFieldSuperClass.HiddenFieldSuccClass
35+
import org.jacodb.testing.types.AAA
36+
import org.jacodb.testing.types.AAA.CCC
3537
import org.jacodb.testing.usages.Generics
3638
import org.jacodb.testing.usages.HelloWorldAnonymousClasses
3739
import org.jacodb.testing.usages.WithInner
@@ -601,6 +603,24 @@ abstract class DatabaseEnvTest {
601603
assertTrue(hiddenFieldSuccClass.toType().fields.size == hiddenFieldSuccClass.fields.size)
602604
}
603605

606+
@Test
607+
fun `static flag on classes`() {
608+
val aaa = cp.findClass<AAA>()
609+
610+
val bbb = cp.findClass<AAA.BBB>()
611+
val ccc = cp.findClass<CCC>()
612+
assertFalse(bbb.isStatic)
613+
assertTrue(ccc.isStatic)
614+
615+
assertTrue(ccc.innerClasses.isEmpty())
616+
assertTrue(bbb.innerClasses.isEmpty())
617+
618+
val inners = aaa.innerClasses.toList()
619+
assertEquals(2, inners.size)
620+
assertTrue(inners.first { it.name.contains("CCC") }.isStatic)
621+
assertFalse(inners.first { it.name.contains("BBB") }.isStatic)
622+
}
623+
604624
private inline fun <reified T> findSubClasses(allHierarchy: Boolean = false): Sequence<JcClassOrInterface> {
605625
return hierarchyExt.findSubClasses(T::class.java.name, allHierarchy)
606626
}

0 commit comments

Comments
 (0)