Move JVM Intrinsics class to package "kotlin.jvm.internal"
Delete unused intrinsics, reformat code, rename some declarations for better readability
This commit is contained in:
@@ -412,7 +412,7 @@ public class AsmUtil {
|
||||
return StackValue.cmp(opToken, leftType);
|
||||
}
|
||||
else {
|
||||
v.invokestatic("jet/runtime/Intrinsics", "areEqual", "(Ljava/lang/Object;Ljava/lang/Object;)Z");
|
||||
v.invokestatic("kotlin/jvm/internal/Intrinsics", "areEqual", "(Ljava/lang/Object;Ljava/lang/Object;)Z");
|
||||
|
||||
if (opToken == JetTokens.EXCLEQ || opToken == JetTokens.EXCLEQEQEQ) {
|
||||
genInvertBoolean(v);
|
||||
@@ -488,7 +488,7 @@ public class AsmUtil {
|
||||
if (asmType.getSort() == Type.OBJECT || asmType.getSort() == Type.ARRAY) {
|
||||
v.load(index, asmType);
|
||||
v.visitLdcInsn(parameter.getName().asString());
|
||||
v.invokestatic("jet/runtime/Intrinsics", "checkParameterIsNotNull", "(Ljava/lang/Object;Ljava/lang/String;)V");
|
||||
v.invokestatic("kotlin/jvm/internal/Intrinsics", "checkParameterIsNotNull", "(Ljava/lang/Object;Ljava/lang/String;)V");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -530,7 +530,7 @@ public class AsmUtil {
|
||||
v.dup();
|
||||
v.visitLdcInsn(descriptor.getContainingDeclaration().getName().asString());
|
||||
v.visitLdcInsn(descriptor.getName().asString());
|
||||
v.invokestatic("jet/runtime/Intrinsics", assertMethodToCall, "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
v.invokestatic("kotlin/jvm/internal/Intrinsics", assertMethodToCall, "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2355,7 +2355,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
gen(arguments.get(0).getArgumentExpression(), type);
|
||||
}
|
||||
else {
|
||||
String owner = "jet/runtime/Intrinsics$SpreadBuilder";
|
||||
String owner = "kotlin/jvm/internal/SpreadBuilder";
|
||||
v.anew(Type.getObjectType(owner));
|
||||
v.dup();
|
||||
v.invokespecial(owner, "<init>", "()V");
|
||||
@@ -3047,7 +3047,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
v.dup();
|
||||
Label ok = new Label();
|
||||
v.ifnonnull(ok);
|
||||
v.invokestatic("jet/runtime/Intrinsics", "throwNpe", "()V");
|
||||
v.invokestatic("kotlin/jvm/internal/Intrinsics", "throwNpe", "()V");
|
||||
v.mark(ok);
|
||||
return StackValue.onStack(base.type);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class ArrayIndices extends IntrinsicMethod {
|
||||
) {
|
||||
receiver.put(receiver.type, v);
|
||||
v.arraylength();
|
||||
v.invokestatic("jet/runtime/Ranges", "arrayIndices", "(I)Ljet/IntRange;");
|
||||
v.invokestatic("kotlin/jvm/internal/Intrinsics", "arrayIndices", "(I)Ljet/IntRange;");
|
||||
return JET_INT_RANGE_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,10 +58,10 @@ public class CompareTo extends IntrinsicMethod {
|
||||
codegen.gen(argument, type);
|
||||
|
||||
if (type == Type.INT_TYPE) {
|
||||
v.invokestatic("jet/runtime/Intrinsics", "compare", "(II)I");
|
||||
v.invokestatic("kotlin/jvm/internal/Intrinsics", "compare", "(II)I");
|
||||
}
|
||||
else if (type == Type.LONG_TYPE) {
|
||||
v.invokestatic("jet/runtime/Intrinsics", "compare", "(JJ)I");
|
||||
v.invokestatic("kotlin/jvm/internal/Intrinsics", "compare", "(JJ)I");
|
||||
}
|
||||
else if (type == Type.FLOAT_TYPE) {
|
||||
v.invokestatic("java/lang/Float", "compare", "(FF)I");
|
||||
|
||||
@@ -48,7 +48,7 @@ public class StringPlus extends IntrinsicMethod {
|
||||
receiver.put(JAVA_STRING_TYPE, v);
|
||||
codegen.gen(arguments.get(0)).put(OBJECT_TYPE, v);
|
||||
}
|
||||
v.invokestatic("jet/runtime/Intrinsics", "stringPlus", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;");
|
||||
v.invokestatic("kotlin/jvm/internal/Intrinsics", "stringPlus", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;");
|
||||
return JAVA_STRING_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class StupidSync extends IntrinsicMethod {
|
||||
StackValue receiver
|
||||
) {
|
||||
codegen.pushMethodArguments((JetCallExpression) element, Arrays.asList(OBJECT_TYPE, JET_FUNCTION0_TYPE));
|
||||
v.invokestatic("jet/runtime/Intrinsics", "stupidSync", "(Ljava/lang/Object;Ljet/Function0;)Ljava/lang/Object;");
|
||||
v.invokestatic("kotlin/jvm/internal/Intrinsics", "stupidSync", "(Ljava/lang/Object;Ljet/Function0;)Ljava/lang/Object;");
|
||||
return OBJECT_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import jet.runtime.Intrinsics;
|
||||
import org.jetbrains.asm4.ClassReader;
|
||||
import org.jetbrains.asm4.ClassVisitor;
|
||||
import org.jetbrains.asm4.MethodVisitor;
|
||||
@@ -28,7 +27,6 @@ import org.jetbrains.jet.cli.common.output.outputUtils.OutputUtilsPackage;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
@@ -166,8 +164,6 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
||||
assertNotNull(file);
|
||||
ClassReader reader = new ClassReader(file.asByteArray());
|
||||
|
||||
final String intrinsics = JvmClassName.byFqNameWithoutInnerClasses(Intrinsics.class.getName()).getInternalName();
|
||||
|
||||
reader.accept(new ClassVisitor(Opcodes.ASM4) {
|
||||
@Override
|
||||
public MethodVisitor visitMethod(
|
||||
@@ -178,7 +174,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
|
||||
assertFalse(
|
||||
"Intrinsics method is called: " + name + desc + " Caller: " + callerName + callerDesc,
|
||||
intrinsics.equals(owner)
|
||||
"kotlin/jvm/internal/Intrinsics".equals(owner)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.jet.runtime;
|
||||
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import jet.runtime.Intrinsics;
|
||||
|
||||
public class JetNpeTest extends UsefulTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void testStackTrace () {
|
||||
try {
|
||||
Intrinsics.throwNpe();
|
||||
fail("No Sure thrown");
|
||||
}
|
||||
catch (NullPointerException e) {
|
||||
StackTraceElement stackTraceElement = e.getStackTrace()[0];
|
||||
assertEquals(stackTraceElement.getMethodName(), "testStackTrace");
|
||||
assertEquals(stackTraceElement.getClassName(), "org.jetbrains.jet.runtime.JetNpeTest");
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-7
@@ -14,14 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package jet.runtime;
|
||||
package kotlin;
|
||||
|
||||
import jet.IntRange;
|
||||
import kotlin.jvm.internal.Intrinsics;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Ranges {
|
||||
public static IntRange arrayIndices(int length) {
|
||||
return new IntRange(0, length - 1);
|
||||
public class KotlinNullPointerException extends NullPointerException {
|
||||
@Override
|
||||
public synchronized Throwable fillInStackTrace() {
|
||||
super.fillInStackTrace();
|
||||
return Intrinsics.sanitizeStackTrace(this);
|
||||
}
|
||||
|
||||
private Ranges() {}
|
||||
}
|
||||
+23
-60
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -14,11 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package jet.runtime;
|
||||
package kotlin.jvm.internal;
|
||||
|
||||
import jet.Function0;
|
||||
import jet.IntRange;
|
||||
import kotlin.KotlinNullPointerException;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class Intrinsics {
|
||||
@@ -26,11 +31,11 @@ public class Intrinsics {
|
||||
}
|
||||
|
||||
public static String stringPlus(String self, Object other) {
|
||||
return ((self == null) ? "null" : self) + ((other == null) ? "null" : other.toString());
|
||||
return String.valueOf(self) + String.valueOf(other);
|
||||
}
|
||||
|
||||
public static void throwNpe() {
|
||||
throw new JetNullPointerException();
|
||||
throw new KotlinNullPointerException();
|
||||
}
|
||||
|
||||
public static void checkReturnedValueIsNotNull(Object value, String className, String methodName) {
|
||||
@@ -66,22 +71,22 @@ public class Intrinsics {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Class<T> getJavaClass(T self) {
|
||||
return (Class<T>) self.getClass();
|
||||
}
|
||||
|
||||
public static int compare(long thisVal, long anotherVal) {
|
||||
return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
|
||||
return thisVal < anotherVal ? -1 : thisVal == anotherVal ? 0 : 1;
|
||||
}
|
||||
|
||||
public static int compare(int thisVal, int anotherVal) {
|
||||
return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
|
||||
return thisVal < anotherVal ? -1 : thisVal == anotherVal ? 0 : 1;
|
||||
}
|
||||
|
||||
public static boolean areEqual(Object first, Object second) {
|
||||
return first == null ? second == null : first.equals(second);
|
||||
}
|
||||
|
||||
public static IntRange arrayIndices(int length) {
|
||||
return new IntRange(0, length - 1);
|
||||
}
|
||||
|
||||
public static <R> R stupidSync(Object lock, Function0<R> block) {
|
||||
synchronized (lock) {
|
||||
return block.invoke();
|
||||
@@ -92,63 +97,21 @@ public class Intrinsics {
|
||||
"throwNpe", "checkReturnedValueIsNotNull", "checkFieldIsNotNull", "checkParameterIsNotNull"
|
||||
));
|
||||
|
||||
private static <T extends Throwable> T sanitizeStackTrace(T throwable) {
|
||||
public static <T extends Throwable> T sanitizeStackTrace(T throwable) {
|
||||
StackTraceElement[] stackTrace = throwable.getStackTrace();
|
||||
ArrayList<StackTraceElement> list = new ArrayList<StackTraceElement>();
|
||||
ArrayList<StackTraceElement> list = new ArrayList<StackTraceElement>(stackTrace.length);
|
||||
boolean skip = true;
|
||||
for(StackTraceElement ste : stackTrace) {
|
||||
for (StackTraceElement element : stackTrace) {
|
||||
if (!skip) {
|
||||
list.add(ste);
|
||||
list.add(element);
|
||||
}
|
||||
else {
|
||||
if ("jet.runtime.Intrinsics".equals(ste.getClassName())) {
|
||||
if (METHOD_NAMES_TO_SKIP.contains(ste.getMethodName())) {
|
||||
skip = false;
|
||||
}
|
||||
else if ("kotlin.jvm.internal.Intrinsics".equals(element.getClassName())) {
|
||||
if (METHOD_NAMES_TO_SKIP.contains(element.getMethodName())) {
|
||||
skip = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
throwable.setStackTrace(list.toArray(new StackTraceElement[list.size()]));
|
||||
return throwable;
|
||||
}
|
||||
|
||||
private static class JetNullPointerException extends NullPointerException {
|
||||
@Override
|
||||
public synchronized Throwable fillInStackTrace() {
|
||||
super.fillInStackTrace();
|
||||
return sanitizeStackTrace(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SpreadBuilder extends ArrayList {
|
||||
public void addSpread(Object array) {
|
||||
if (array != null) {
|
||||
if (array instanceof Object[]) {
|
||||
Object[] arr = (Object[]) array;
|
||||
if (arr.length > 0) {
|
||||
ensureCapacity(size() + arr.length);
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
add(arr[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (array instanceof Collection) {
|
||||
addAll((Collection) array);
|
||||
}
|
||||
else if (array instanceof Iterable) {
|
||||
for(Iterator iterator = ((Iterable) array).iterator(); iterator.hasNext(); ) {
|
||||
add(iterator.next());
|
||||
}
|
||||
}
|
||||
else if (array instanceof Iterator) {
|
||||
for(Iterator iterator = ((Iterator) array); iterator.hasNext(); ) {
|
||||
add(iterator.next());
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("Don't know how to spread " + array.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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 kotlin.jvm.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class SpreadBuilder extends ArrayList<Object> {
|
||||
public void addSpread(Object container) {
|
||||
if (container == null) return;
|
||||
|
||||
if (container instanceof Object[]) {
|
||||
Object[] array = (Object[]) container;
|
||||
if (array.length > 0) {
|
||||
ensureCapacity(size() + array.length);
|
||||
for (Object element : array) {
|
||||
add(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (container instanceof Collection) {
|
||||
addAll((Collection) container);
|
||||
}
|
||||
else if (container instanceof Iterable) {
|
||||
for (Object element : (Iterable) container) {
|
||||
add(element);
|
||||
}
|
||||
}
|
||||
else if (container instanceof Iterator) {
|
||||
for (Iterator iterator = (Iterator) container; iterator.hasNext(); ) {
|
||||
add(iterator.next());
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("Don't know how to spread " + container.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user