Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
add javaStackTrace() function
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Jul 26, 2015
1 parent 8ccfb95 commit 7f712c9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
28 changes: 19 additions & 9 deletions source/ceylon/interop/java/internal/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,30 @@ public java.lang.String javaString(
@SuppressWarnings("unchecked")
public <T> java.lang.Class<T>
javaClass(@Ignore TypeDescriptor $reifiedT) {
if ($reifiedT instanceof TypeDescriptor.Class){
TypeDescriptor.Class klass = (TypeDescriptor.Class) $reifiedT;
if ($reifiedT instanceof TypeDescriptor.Class) {
TypeDescriptor.Class klass =
(TypeDescriptor.Class) $reifiedT;
if (klass.getTypeArguments().length > 0)
throw new RuntimeException("given type has type arguments");
return (java.lang.Class<T>) klass.getKlass();
}
else if($reifiedT instanceof TypeDescriptor.Member
&& ((TypeDescriptor.Member)$reifiedT).getMember() instanceof TypeDescriptor.Class) {
TypeDescriptor.Member.Class klass = (TypeDescriptor.Class)((TypeDescriptor.Member)$reifiedT).getMember();
if (klass.getTypeArguments().length > 0)
throw new RuntimeException("given type has type arguments");
return (java.lang.Class<T>) klass.getKlass();
else if ($reifiedT instanceof TypeDescriptor.Member) {
TypeDescriptor.Member member =
(TypeDescriptor.Member) $reifiedT;
TypeDescriptor m = member.getMember();
if (m instanceof TypeDescriptor.Class) {
TypeDescriptor.Member.Class klass =
(TypeDescriptor.Class) m;
if (klass.getTypeArguments().length > 0)
throw new RuntimeException("given type has type arguments");
return (java.lang.Class<T>) klass.getKlass();
}
}
throw new RuntimeException("unsupported type");
}


public StackTraceElement[] javaStackTrace(Throwable t) {
return t.getStackTrace();
}

}
16 changes: 15 additions & 1 deletion source/ceylon/interop/java/misc.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import ceylon.interop.java.internal {

import java.lang {
JavaString=String,
Class
Class,
StackTraceElement
}

"The [[java.lang::String]] underling the given Ceylon
Expand All @@ -24,4 +25,17 @@ shared Class<out Type> javaClassFromInstance<Type>(Type instance)
given Type satisfies Object
=> util.javaClassFromInstance(instance);

"The stack trace information for the given [[Throwable]] as
a sequence of Java [[StackTraceElement]]s, or the empty
sequence if no stack trace information is available. The
first element of the sequence is the top of the stack, that
is, the most deeply nested stack frame. This is usually the
stack frame in which the given `Throwable` was created
and thrown."
shared StackTraceElement[] javaStackTrace(Throwable throwable)
=> [ for (stackElement in
util.javaStackTrace(throwable).iterable)
if (exists stackElement)
stackElement ];

Util util = Util();

0 comments on commit 7f712c9

Please sign in to comment.