(LinkRequest linkRequest, LinkerServices linkerServices)
| 40 | |
| 41 | |
| 42 | @Override |
| 43 | public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest, LinkerServices linkerServices) throws Exception { |
| 44 | if (disabled) return null; |
| 45 | if (debug) { |
| 46 | System.err.println("LINKER getGuardedInvocation :" + linkRequest + " " + linkerServices); |
| 47 | System.err.println(" " + Arrays.asList(linkRequest.getArguments()) + " .length =" + linkRequest.getArguments().length); |
| 48 | System.err.println(" " + linkRequest.getCallSiteDescriptor()); |
| 49 | System.err.println(" " + linkRequest.getCallSiteDescriptor().getOperation()); |
| 50 | System.err.println(" " + linkRequest.getReceiver()); |
| 51 | } |
| 52 | if (linkRequest.getCallSiteDescriptor().getOperation() |
| 53 | .toString().startsWith("GET:PROPERTY|ELEMENT|METHOD:")) { |
| 54 | |
| 55 | Object rec = linkRequest.getReceiver(); |
| 56 | String propertyName = linkRequest.getCallSiteDescriptor().getOperation().toString().replace("GET:PROPERTY|ELEMENT|METHOD:", ""); |
| 57 | |
| 58 | if (debug) { |
| 59 | System.err.println(" rec is of type " + (rec == null ? null : rec.getClass()) + " / " + (rec instanceof AsMap)); |
| 60 | if (rec instanceof AsMap) |
| 61 | System.err.println(" rec admits to having property :" + ((AsMap) rec).asMap_isProperty(propertyName)); |
| 62 | } |
| 63 | |
| 64 | if (rec instanceof AsMap && ((AsMap) rec).asMap_isProperty(propertyName)) { |
| 65 | |
| 66 | if (debug) |
| 67 | System.err.println(" linking AsMap.java/get 2" + rec); |
| 68 | MethodHandle get = MethodHandles.lookup() |
| 69 | .findVirtual(rec.getClass(), "asMap_get", MethodType.methodType(Object.class, String.class)); |
| 70 | |
| 71 | get = MethodHandles.insertArguments(get, 1, propertyName); |
| 72 | |
| 73 | return new GuardedInvocation(get, Guards.isInstance(rec.getClass(), MethodType.methodType(Boolean.TYPE, Object.class))); |
| 74 | } |
| 75 | } else if (linkRequest.getCallSiteDescriptor() |
| 76 | .getOperation().toString().startsWith("CALL") && linkRequest.getArguments().length == 3) { |
| 77 | |
| 78 | Object rec = linkRequest.getReceiver(); |
| 79 | |
| 80 | if (rec instanceof AsMap) { |
| 81 | |
| 82 | if (debug) |
| 83 | System.err.println(" linking AsMap.java/call " + rec); |
| 84 | MethodHandle get = MethodHandles.lookup() |
| 85 | .findVirtual(rec.getClass(), "asMap_call", MethodType.methodType(Object.class, Object.class, Object.class)); |
| 86 | return new GuardedInvocation(get, Guards.isInstance(rec.getClass(), MethodType.methodType(Boolean.TYPE, Object.class))); |
| 87 | } else if (rec instanceof AsMap_callable) { |
| 88 | if (debug) |
| 89 | System.err.println(" linking AsMap_callable/call " + rec); |
| 90 | MethodHandle get = MethodHandles.lookup() |
| 91 | .findVirtual(rec.getClass(), "asMap_call", MethodType.methodType(Object.class, Object.class, Object.class)); |
| 92 | return new GuardedInvocation(get, Guards.isInstance(rec.getClass(), MethodType.methodType(Boolean.TYPE, Object.class))); |
| 93 | |
| 94 | } |
| 95 | } else if (linkRequest.getCallSiteDescriptor() |
| 96 | .getOperation().toString().startsWith("CALL") && linkRequest.getArguments().length == 2) { |
| 97 | |
| 98 | Object rec = linkRequest.getReceiver(); |
| 99 |
nothing calls this directly
no test coverage detected