From 6ee4c70f2f08c4fa076404488dc8565d822fb897 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 6 Feb 2015 17:15:32 +0300 Subject: [PATCH] Minor, extract OuterClassInfo --- .../kotlin/codegen/OuterClassGenTest.java | 72 +++++-------------- .../kotlin/codegen/OuterClassInfo.kt | 23 ++++++ 2 files changed, 42 insertions(+), 53 deletions(-) create mode 100644 compiler/tests/org/jetbrains/kotlin/codegen/OuterClassInfo.kt diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/OuterClassGenTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/OuterClassGenTest.java index 8e722d01aea..1ba041662e6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/OuterClassGenTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/OuterClassGenTest.java @@ -16,9 +16,11 @@ package org.jetbrains.kotlin.codegen; +import com.intellij.openapi.util.Ref; import com.intellij.util.lang.UrlClassLoader; import org.intellij.lang.annotations.Language; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.backend.common.output.OutputFile; import org.jetbrains.kotlin.backend.common.output.OutputFileCollection; import org.jetbrains.kotlin.test.ConfigurationKind; @@ -168,17 +170,17 @@ public class OuterClassGenTest extends CodegenTestCase { @NotNull String testDataFile ) { ClassReader kotlinReader = getKotlinClassReader(internalNameRegexp, testDataFile); - OuterClassInfo kotlinInfo = getOuterClassInfo(kotlinReader); + OuterClassInfo kotlinInfo = readOuterClassInfo(kotlinReader); String message = "Error in enclosingMethodInfo info for class: " + kotlinReader.getClassName(); - if (kotlinInfo.owner == null) { - assertNull(expectedInfo.owner); + if (kotlinInfo == null) { + assertNull(expectedInfo.getOwner()); } else { - assertTrue(message + "\n" + kotlinInfo.owner + " doesn't start with " + expectedInfo.owner, - kotlinInfo.owner.startsWith(expectedInfo.owner)); + assertTrue(message + "\n" + kotlinInfo.getOwner() + " doesn't start with " + expectedInfo.getOwner(), + kotlinInfo.getOwner().startsWith(expectedInfo.getOwner())); } - assertEquals(message, expectedInfo.method, kotlinInfo.method); - assertEquals(message, expectedInfo.descriptor, kotlinInfo.descriptor); + assertEquals(message, expectedInfo.getMethodName(), kotlinInfo.getMethodName()); + assertEquals(message, expectedInfo.getMethodDesc(), kotlinInfo.getMethodDesc()); } @NotNull @@ -194,64 +196,28 @@ public class OuterClassGenTest extends CodegenTestCase { } private static void checkInfo(@NotNull ClassReader kotlinReader, @NotNull ClassReader javaReader) { - OuterClassInfo kotlinInfo = getOuterClassInfo(kotlinReader); - OuterClassInfo javaInfo = getOuterClassInfo(javaReader); - //noinspection ConstantConditions + OuterClassInfo kotlinInfo = readOuterClassInfo(kotlinReader); + OuterClassInfo javaInfo = readOuterClassInfo(javaReader); compareInfo(kotlinReader.getClassName(), kotlinInfo, javaInfo); } private static void compareInfo( @NotNull String kotlinClassName, - @NotNull OuterClassInfo kotlinInfo, - @NotNull OuterClassInfo expectedJavaInfo + @Nullable OuterClassInfo kotlinInfo, + @Nullable OuterClassInfo expectedJavaInfo ) { assertEquals("Error in enclosingMethodInfo info for: " + kotlinClassName + " class", expectedJavaInfo, kotlinInfo); } - public static OuterClassInfo getOuterClassInfo(ClassReader reader) { - final OuterClassInfo info = new OuterClassInfo(); + @Nullable + private static OuterClassInfo readOuterClassInfo(@NotNull ClassReader reader) { + final Ref info = Ref.create(); reader.accept(new ClassVisitor(Opcodes.ASM5) { @Override - public void visitOuterClass(@NotNull String owner, String name, String desc) { - info.owner = owner; - info.method = name; - info.descriptor = desc; + public void visitOuterClass(@NotNull String owner, @Nullable String name, @Nullable String desc) { + info.set(new OuterClassInfo(owner, name, desc)); } }, 0); - return info; - } - - private static class OuterClassInfo { - private String owner; - private String method; - private String descriptor; - - private OuterClassInfo(String owner, String method, String descriptor) { - this.owner = owner; - this.method = method; - this.descriptor = descriptor; - } - - private OuterClassInfo() { - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof OuterClassInfo)) return false; - - OuterClassInfo info = (OuterClassInfo) o; - - if (descriptor != null ? !descriptor.equals(info.descriptor) : info.descriptor != null) return false; - if (method != null ? !method.equals(info.method) : info.method != null) return false; - if (owner != null ? !owner.equals(info.owner) : info.owner != null) return false; - - return true; - } - - @Override - public String toString() { - return "[owner=" + owner + ", method=" + method + ", descriptor="+ descriptor + "]"; - } + return info.get(); } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/OuterClassInfo.kt b/compiler/tests/org/jetbrains/kotlin/codegen/OuterClassInfo.kt new file mode 100644 index 00000000000..1d586a845bd --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/codegen/OuterClassInfo.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.codegen + +public data class OuterClassInfo( + public val owner: String, + public val methodName: String?, + public val methodDesc: String? +)