Minor, extract OuterClassInfo
This commit is contained in:
@@ -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<OuterClassInfo> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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?
|
||||
)
|
||||
Reference in New Issue
Block a user