From 7c916043118c980bdfd3a97df744f0431827fdb3 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 4 May 2015 11:42:07 +0300 Subject: [PATCH] Add StackTraceElement stub to run Kotlin --- .../java/lang/TStackTraceElement.java | 94 +++++++++++++++++++ .../org/teavm/classlib/java/lang/TThread.java | 4 + .../teavm/classlib/java/lang/TThrowable.java | 9 ++ 3 files changed, 107 insertions(+) create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStackTraceElement.java diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStackTraceElement.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStackTraceElement.java new file mode 100644 index 000000000..2ae62814a --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStackTraceElement.java @@ -0,0 +1,94 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * 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.teavm.classlib.java.lang; + +import java.util.Objects; +import org.teavm.classlib.java.io.TSerializable; +import org.teavm.classlib.java.util.TObjects; + +/** + * + * @author Alexey Andreev + */ +public final class TStackTraceElement extends TObject implements TSerializable { + private TString declaringClass; + private TString methodName; + private TString fileName; + private int lineNumber; + + public TStackTraceElement(TString declaringClass, TString methodName, TString fileName, int lineNumber) { + if (declaringClass == null || methodName == null) { + throw new TNullPointerException(); + } + this.declaringClass = declaringClass; + this.methodName = methodName; + this.fileName = fileName; + this.lineNumber = lineNumber; + } + + public TString getClassName() { + return declaringClass; + } + + public TString getMethodName() { + return methodName; + } + + public TString getFileName() { + return fileName; + } + + public int getLineNumber() { + return lineNumber; + } + + public boolean isNativeMethod() { + return fileName == null; + } + + @Override + public int hashCode() { + return Objects.hash(declaringClass, methodName, fileName, lineNumber); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof TStackTraceElement)) { + return false; + } + TStackTraceElement other = (TStackTraceElement)obj; + return TObjects.equals(declaringClass, other.declaringClass) && + TObjects.equals(methodName, other.methodName) && + TObjects.equals(fileName, other.fileName) && + lineNumber == other.lineNumber; + } + + @Override + public String toString() { + TStringBuilder sb = new TStringBuilder(); + int index = declaringClass.lastIndexOf('.'); + sb.append(declaringClass.substring(index + 1)).append('.').append(methodName).append('('); + if (fileName != null) { + sb.append(fileName).append(':').append(lineNumber); + } else { + sb.append(TString.wrap("Unknown Source")); + } + return sb.toString(); + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java index 4b98842c1..c4de1d645 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java @@ -167,4 +167,8 @@ public class TThread extends TObject implements TRunnable { public final int getPriority(){ return this.priority; } + + public TStackTraceElement[] getStackTrace() { + return new TStackTraceElement[0]; + } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThrowable.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThrowable.java index 6471e8440..70ab398d6 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThrowable.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThrowable.java @@ -146,6 +146,15 @@ public class TThrowable extends RuntimeException { stream.println(TString.wrap(getClass().getName() + ": " + getMessage())); } + @Rename("getStackTrace") + public TStackTraceElement[] getStackTrace0() { + return new TStackTraceElement[0]; + } + + public void setStackTrace(@SuppressWarnings("unused") TStackTraceElement[] stackTrace) { + // do nothing + } + @Rename("getSuppressed") public final TThrowable[] getSuppressed0() { return TArrays.copyOf(suppressed, suppressed.length);