All Downloads are FREE. Search and download functionalities are using the official Maven repository.

elide.runtime.plugins.java.Extensions.kt Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2024 Elide Technologies, Inc.
 *
 * Licensed under the MIT license (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *   https://opensource.org/license/mit/
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under the License.
 */

package elide.runtime.plugins.java

import org.graalvm.polyglot.Source
import elide.runtime.core.DelicateElideApi
import elide.runtime.core.PolyglotContext
import elide.runtime.core.PolyglotValue
import elide.runtime.core.evaluate

/**
 * Execute the given Java [source] code as an interactive snippet, returning the result. This is equivalent to
 * calling [PolyglotContext.evaluate] and selecting [Java] as source language with an interactive source.
 *
 * @param source The Java snippet to be evaluated.
 * @return The result of the invocation.
 */
@DelicateElideApi public fun PolyglotContext.java(source: String, name: String? = null): PolyglotValue = evaluate(
  Source.newBuilder(Java.languageId, source, name ?: "snippet.java")
    .interactive(true)
    .build(),
)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy