TruffleMap<K, V> cloneInternal(boolean includeInternalKeys) { return new TruffleMap<>(this, includeInternalKeys); }
/** * Get a view of map created by * {@link #asJavaObject(java.lang.Class, com.oracle.truffle.api.interop.TruffleObject)} with * <code>{@link java.util.Map}.class</code> as an argument. The view includes or excludes * {@link KeyInfo#isInternal(int) internal} elements based on <code>includeInternal</code> * parameter. * * @param map a map obtained by * {@link #asJavaObject(java.lang.Class, com.oracle.truffle.api.interop.TruffleObject)} * @param includeInternal <code>true</code> to include internal elements in the map, * <code>false</code> to exclude them. * @return a view of the original map with a possibly changed set of elements depending on the * <code>includeInternal</code> argument. * @throws IllegalArgumentException when the Map was not created by * {@link #asJavaObject(java.lang.Class, com.oracle.truffle.api.interop.TruffleObject)} * . * @since 0.26 */ public static <K, V> Map<K, V> getMapView(Map<K, V> map, boolean includeInternal) throws IllegalArgumentException { if (!(map instanceof TruffleMap)) { throw new IllegalArgumentException(map.getClass().getCanonicalName()); } TruffleMap<K, V> tmap = (TruffleMap<K, V>) map; return tmap.cloneInternal(includeInternal); }
if (hasKeys || hasSize) { boolean implementsFunction = shouldImplementFunction(truffleObject); obj = TruffleMap.create(languageContext, truffleObject, implementsFunction, keyClazz, valueType.clazz, valueType.type); } else { throw JavaInteropErrors.cannotConvert(languageContext, truffleObject, targetType, "Value must have members or array elements.");
static <K, V> Map<K, V> create(Object languageContext, TruffleObject foreignObject, boolean implementsFunction, Class<K> keyClass, Class<V> valueClass, Type valueType) { if (implementsFunction) { return new FunctionTruffleMap<>(languageContext, foreignObject, keyClass, valueClass, valueType); } else { return new TruffleMap<>(languageContext, foreignObject, keyClass, valueClass, valueType); } }