@Signature public void addFile(Environment env, File file, @Nullable @Optional("null") Memory localName, @Optional("null") Invoker progressHandler, @Optional("8192") int bufferSize ) throws Throwable { PArchiveEntry entry = fetchOutput(env).createEntry(env, file, localName.isNull() ? file.getName() : localName.toString()); env.invokeMethod(output, "putEntry", ObjectMemory.valueOf(entry)); try (InputStream inputStream = new FileInputStream(file)) { FsUtils.copy(inputStream, outputStream, progressHandler, bufferSize); env.invokeMethod(output, "closeEntry"); } }
if (arg.optional().exists() || !arg.optional().value().isEmpty() || (arg.type() != HintType.STRING && !arg.optional().value().isEmpty())){ param.setDefaultValue(MemoryUtils.valueOf(arg.optional().value(), arg.optional().type())); param.setDefaultValue(MemoryUtils.valueOf(optAnn.value(), optAnn.type()));
@Signature public PMarkdownOptions addWikiLinkExtension(@Arg(type = HintType.ARRAY) @Optional("null") Memory options) { parserExtensions.add(WikiLinkExtension.create());
@Signature public PMarkdownOptions addEmojiExtension(@Arg(type = HintType.ARRAY) @Optional("null") Memory options) { parserExtensions.add(EmojiExtension.create()); Memory imageType = options.valueOfIndex("imageType"); if (!imageType.isNull()) { this.options.set(EmojiExtension.USE_IMAGE_TYPE, EmojiImageType.valueOf(imageType.toString())); } Memory shortcutType = options.valueOfIndex("shortcutType"); if (!shortcutType.isNull()) { this.options.set(EmojiExtension.USE_SHORTCUT_TYPE, EmojiShortcutType.valueOf(shortcutType.toString())); } Memory imagePath = options.valueOfIndex("imagePath"); if (!shortcutType.isNull()) { this.options.set(EmojiExtension.ROOT_IMAGE_PATH, imagePath.toString()); } Memory imageClass = options.valueOfIndex("imageClass"); if (!shortcutType.isNull()) { this.options.set(EmojiExtension.ATTR_IMAGE_CLASS, imageClass.toString()); } Memory imageSize = options.valueOfIndex("imageSize"); if (!shortcutType.isNull()) { this.options.set(EmojiExtension.ATTR_IMAGE_SIZE, imageSize.toString()); } return this; }
@Signature({ @Arg("className"), @Arg(value = "args", type = HintType.ARRAY, optional = @Optional("null")), @Arg(value = "withConstruct", optional = @Optional("true")) }) public static Memory newInstance(Environment env, Memory... args) throws Throwable { ClassEntity entity = env.fetchClass(args[0].toString(), true); if (entity == null) { env.exception(env.trace(), Messages.ERR_CLASS_NOT_FOUND.fetch(args[0])); return Memory.NULL; } else { return new ObjectMemory(entity.newObject( env, env.trace(), args[2].toBoolean(), args[1].isNull() ? null : args[1].toValue(ArrayMemory.class).values(true) )); } } }
@Signature public PArchiveEntry read(Environment env, String path, @Nullable @Reflection.Optional("null") final Invoker callback) throws Throwable { PArchiveInput input = createInput(env); try { PArchiveEntry entry; while ((entry = env.invokeMethod(input, "nextEntry").toObject(PArchiveEntry.class)) != null) { String name = entry.getName(); if (name.equals(path)) { read(env, input.stream(), entry, callback); return entry; } } return null; } finally { input.getWrappedObject().close(); } }
protected void onWrapArgument(ParameterEntity param, Reflection.Arg arg) { param.setReference(arg.reference()); param.setType(arg.type()); param.setName(arg.value()); param.setNullable(arg.nullable()); if (arg.typeEnum() != Enum.class) { param.setTypeEnum(arg.typeEnum()); } param.setDefaultValue(null); if (arg.optional().exists() || !arg.optional().value().isEmpty() || (arg.type() != HintType.STRING && !arg.optional().value().isEmpty())){ param.setDefaultValue(MemoryUtils.valueOf(arg.optional().value(), arg.optional().type())); } if (!arg.typeClass().isEmpty()) param.setTypeClass(arg.typeClass()); else if (arg.nativeType() != IObject.class) { param.setTypeClass(ReflectionUtils.getClassName(arg.nativeType())); } }
@Signature public Memory readAll(Environment env, @Nullable @Reflection.Optional("null") final Invoker callback) throws Throwable { ArrayMemory result = ArrayMemory.createHashed(); PArchiveInput input = createInput(env); try { PArchiveEntry entry; while ((entry = env.invokeMethod(input, "nextEntry").toObject(PArchiveEntry.class)) != null) { if (read(env, input.stream(), entry, callback).toBoolean()) { break; } result.put(entry.getName(), entry); } } finally { input.getWrappedObject().close(); } return result; } }
@Signature public WrapPromise then(Environment env, @Nullable @Optional("null") Invoker onFulfilled, @Nullable @Optional("null") Invoker onRejected) throws Exception { WrapPromise subPromise = new WrapPromise(env); switch (this.state) { case PENDING: this.subscribers.add(new Subscriber(subPromise, onFulfilled, onRejected)); break; case FULFILLED: this.invokeCallback(env, subPromise, onFulfilled); break; case REJECTED: this.invokeCallback(env, subPromise, onRejected); break; } return subPromise; }
@Signature public void addEntry(Environment env, PArchiveEntry entry, @Nullable InputStream source, @Optional("null") Invoker progressHandler, @Optional("8192") int bufferSize ) throws Throwable { fetchOutput(env); env.invokeMethod(output, "putEntry", ObjectMemory.valueOf(entry)); if (source != null) { FsUtils.copy(source, outputStream, progressHandler, bufferSize); } env.invokeMethod(output, "closeEntry"); }
@Signature public PMarkdownOptions addSubscriptExtension(@Arg(type = HintType.ARRAY) @Optional("null") Memory options) { parserExtensions.add(SubscriptExtension.create()); Memory htmlOpen = options.valueOfIndex("htmlOpen"); if (htmlOpen.isNotNull()) { this.options.set(SubscriptExtension.SUBSCRIPT_STYLE_HTML_OPEN, htmlOpen.toString()); } Memory htmlClose = options.valueOfIndex("htmlClose"); if (htmlOpen.isNotNull()) { this.options.set(SubscriptExtension.SUBSCRIPT_STYLE_HTML_CLOSE, htmlClose.toString()); } return this; }
@Signature(@Arg(value = "flags", optional = @Optional("0"))) public Memory __construct(Environment env, Memory... args) { DumperOptions options = new DumperOptions(); int flags = args[0].toInteger(); options.setPrettyFlow((flags & SERIALIZE_PRETTY_FLOW) == SERIALIZE_PRETTY_FLOW); options.setDefaultFlowStyle((flags & SERIALIZE_PRETTY_FLOW) == SERIALIZE_PRETTY_FLOW ? DumperOptions.FlowStyle.BLOCK : DumperOptions.FlowStyle.AUTO); options.setCanonical((flags & SERIALIZE_CANONICAL) == SERIALIZE_CANONICAL); options.setExplicitStart((flags & SERIALIZE_EXPLICIT_START) == SERIALIZE_EXPLICIT_START); options.setExplicitEnd((flags & SERIALIZE_EXPLICIT_END) == SERIALIZE_EXPLICIT_END); options.setSplitLines(!((flags & SERIALIZE_NOT_SPLIT_LINES) == SERIALIZE_NOT_SPLIT_LINES)); yaml = new Yaml(options); return Memory.NULL; }
@FastMethod @Signature({ @Arg("object"), @Arg(value = "toLower", optional = @Optional("false")) }) public static Memory typeOf(Environment env, Memory... args) { if (args[0].isObject()) { ClassEntity entity = args[0].toValue(ObjectMemory.class).getReflection(); return StringMemory.valueOf(args[1].toBoolean() ? entity.getLowerName() : entity.getName()); } else { return Memory.FALSE; } }
@Signature public PTextWord uncapitalize(Environment env, @Optional(type = HintType.STRING) String delimiters) { return new PTextWord(env, WordUtils.uncapitalize(text, delimiters.isEmpty() ? null : delimiters.toCharArray())); }
@Signature public PTextWord capitalize(Environment env, @Optional(type = HintType.STRING) String delimiters) { return new PTextWord(env, WordUtils.capitalize(text, delimiters.isEmpty() ? null : delimiters.toCharArray())); }
@Signature public PTextWord capitalizeFully(Environment env, @Optional(type = HintType.STRING) String delimiters) { return new PTextWord(env, WordUtils.capitalizeFully(text, delimiters.isEmpty() ? null : delimiters.toCharArray())); }
@Signature(@Arg(value = "flags", optional = @Optional("0"))) public Memory __construct(Environment env, Memory... args) { return Memory.NULL; }
@Signature public Integer levenshteinDistance(Environment env, Memory other, @Optional("null") Memory threshold) { LevenshteinDistance distance = new LevenshteinDistance( threshold.isNull() ? null : threshold.toInteger() ); return distance.apply(text, other.toString()); }
protected void onWrapProperty(ClassEntity classEntity, Reflection.Arg arg) { PropertyEntity entity = new PropertyEntity(classEntity.getContext()); entity.setClazz(classEntity); entity.setModifier(arg.modifier()); entity.setName(arg.value()); entity.setStatic(false); if (arg.optional().exists()){ entity.setDefaultValue(MemoryUtils.valueOf(arg.optional().value(), arg.optional().type())); } else { entity.setDefaultValue(null); } classEntity.addProperty(entity); }