Minor Update
- Added getCallerClass() to SafeReflection to get caller class
This commit is contained in:
parent
5909e2ca0a
commit
a4d412c5ca
src/com/tofvesson
@ -268,11 +268,7 @@ public class ShiftingList<E> implements List<E> {
|
|||||||
private Object previous;
|
private Object previous;
|
||||||
public Iterator(ShiftingList ref){ this.ref = ref; }
|
public Iterator(ShiftingList ref){ this.ref = ref; }
|
||||||
public boolean hasNext() { return counter<ref.pop; }
|
public boolean hasNext() { return counter<ref.pop; }
|
||||||
public V next() {
|
public V next() { return (V)(previous=ref.entries[counter++]==empty?null:ref.entries[counter-1]); }
|
||||||
return (V)(previous=ref.entries[counter++]==empty?
|
|
||||||
null:
|
|
||||||
ref.entries[counter-1]);
|
|
||||||
}
|
|
||||||
public void remove(){ if(counter!=0){ ref.remove(previous); --counter; } }
|
public void remove(){ if(counter!=0){ ref.remove(previous); --counter; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,10 @@ import java.lang.reflect.Array;
|
|||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Safe tools to help simplify code when dealing with reflection.
|
* Safe tools to help simplify code when dealing with reflection.
|
||||||
@ -389,4 +392,22 @@ public class SafeReflection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Class<?> getCallerClass(){
|
||||||
|
ArrayList<StackTraceElement> s = new ArrayList<StackTraceElement>();
|
||||||
|
StackTraceElement[] s1 = new Exception().getStackTrace();
|
||||||
|
Collections.addAll(s, s1);
|
||||||
|
s.remove(0);
|
||||||
|
Iterator<StackTraceElement> i = s.iterator();
|
||||||
|
String s2;
|
||||||
|
while(i.hasNext()){
|
||||||
|
if((s2=i.next().toString()).contains("java.lang.reflect.Method.invoke")
|
||||||
|
|| s2.contains("sun.reflect.NativeMethodAccessorImpl.invoke")
|
||||||
|
|| s2.contains("sun.reflect.DelegatingMethodAccessorImpl.invoke"))
|
||||||
|
i.remove();
|
||||||
|
}
|
||||||
|
try { return Class.forName(s.get(s.size()==1?0:1).getClassName()); } catch (ClassNotFoundException e) { }
|
||||||
|
assert false:"Unreachable code reached";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user