FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Missing file from last commit. · hispangle/drjava@add3962 · GitHub

Repository navigation

Commit add3962

Browse files
dlsmith
committed
Missing file from last commit.
git-svn-id: file:///tmp/test-svn/trunk@5169 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 99741e8 commit add3962

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package edu.rice.cs.dynamicjava.symbol;
2+
3+
import static edu.rice.cs.plt.debug.DebugUtil.debug;
4+
5+
import java.lang.reflect.InvocationTargetException;
6+
import java.lang.reflect.Method;
7+
8+
import edu.rice.cs.plt.iter.IterUtil;
9+
import edu.rice.cs.plt.lambda.WrappedException;
10+
import edu.rice.cs.dynamicjava.Options;
11+
import edu.rice.cs.dynamicjava.interpreter.EvaluatorException;
12+
import edu.rice.cs.dynamicjava.interpreter.RuntimeBindings;
13+
import edu.rice.cs.dynamicjava.symbol.type.ArrayType;
14+
import edu.rice.cs.dynamicjava.symbol.type.Type;
15+
import edu.rice.cs.dynamicjava.symbol.type.VariableType;
16+
17+
/**
18+
* Provides a DJMethod interface for accessing an array's implicit "clone" method.
19+
* This overrides {@link Object#clone}, giving it public access, eliminating the
20+
* CloneNotSupported {@code throws} clause, and refining the return type.
21+
*/
22+
public class ArrayCloneMethod implements DJMethod {
23+
24+
private final ArrayType _type;
25+
26+
public ArrayCloneMethod(ArrayType t) {_type = t; }
27+
28+
public String declaredName() { return "clone"; }
29+
public DJClass declaringClass() { return null; }
30+
31+
public Iterable<VariableType> typeParameters() { return IterUtil.empty(); }
32+
public Iterable<LocalVariable> parameters() { return IterUtil.empty(); }
33+
public Type returnType() { return _type; }
34+
public Iterable<Type> thrownTypes() { return IterUtil.empty(); }
35+
36+
public boolean isStatic() { return false; }
37+
public boolean isAbstract() { return false; }
38+
public boolean isFinal() { return false; }
39+
public Access accessibility() { return Access.PUBLIC; }
40+
public Access.Module accessModule() { return new TopLevelAccessModule("java.lang"); }
41+
42+
public DJMethod declaredSignature() { return this; }
43+
public Object evaluate(Object receiver, Iterable<Object> args, RuntimeBindings bindings,
44+
Options options) throws EvaluatorException {
45+
if (receiver == null) {
46+
throw new WrappedException(new EvaluatorException(new NullPointerException()));
47+
}
48+
try {
49+
Method clone = Object.class.getDeclaredMethod("clone");
50+
try { clone.setAccessible(true); /* override protected access */ }
51+
catch (SecurityException e) { debug.log(e); /* ignore -- we can't relax accessibility */ }
52+
return clone.invoke(receiver, IterUtil.toArray(args, Object.class));
53+
}
54+
catch (NoSuchMethodException e) { throw new RuntimeException(e); }
55+
catch (InvocationTargetException e) { throw new EvaluatorException(e.getCause(), EXTRA_STACK); }
56+
catch (IllegalAccessException e) { throw new RuntimeException(e); }
57+
}
58+
59+
private static final String[] EXTRA_STACK =
60+
new String[] { "java.lang.reflect.Method.invoke",
61+
"sun.reflect.DelegatingMethodAccessorImpl.invoke",
62+
"sun.reflect.NativeMethodAccessorImpl.invoke",
63+
"sun.reflect.NativeMethodAccessorImpl.invoke0" };
64+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL