---
title: "LanguageProvider"
description: "The LanguageProvider provides factory methods for language data types, expressions, statements and scripts used for testing language inter-operability."
kind: "interface"
id: "org.graalvm.polyglot.tck.LanguageProvider"
module: "polyglot-tck"
version: "25.6.0-elide.4"
canonical: "https://graalvm.elide.help/25.6.0-elide.4/api/polyglot-tck/org/graalvm/polyglot/tck/LanguageProvider.html"
---

# ◇ LanguageProvider

[polyglot-tck](../../../../index.md) › [org.graalvm.polyglot.tck](index.md) · Every page: [llms.txt](../../../../llms.txt)

Interface in [`org.graalvm.polyglot.tck`](index.md). Since 0.30.

```java
public interface LanguageProvider
```

The [`LanguageProvider`](LanguageProvider.md) provides factory methods for language data types, expressions, statements and scripts used for testing language inter-operability. The [`LanguageProvider`](LanguageProvider.md) implementations are loaded by the [`ServiceLoader`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/ServiceLoader.html) and should be registered in the 'META-INF/services/org.graalvm.polyglot.tck.LanguageProvider'. See [Test Compatibility Kit](https://github.com/oracle/graal/blob/master/truffle/docs/TCK.md) for details how to add a new language provider and execute tests.

## Methods

### getId()
<a id="getId()"></a>`String getId()`. Since 0.30. Returns an identification of a provider. The common pattern is to use the identification of the tested language. Returns `String`: the language identification. Cite: `org/graalvm/polyglot/tck/LanguageProvider.html#getId()`

### additionalOptions()
<a id="additionalOptions()"></a>`default Map<String, String> additionalOptions()`. Since 22.3. Allows language providers to provide language options during the creation of the test context. `LanguageProviders` are only allowed to set options of the language they represent (Options starting with `getId()`). Attempts to set options other than their own language will throw [`IllegalArgumentException`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) on test context creation. Returns `Map<String, String>`: The `(key, value)` pairs of language option to add to the context. Cite: `org/graalvm/polyglot/tck/LanguageProvider.html#additionalOptions()`

### createIdentityFunction(Context)
<a id="createIdentityFunction(org.graalvm.polyglot.Context)"></a>`Value createIdentityFunction(Context context)`. Since 0.30. Creates an identity function. The identity function just returns its argument. The JavaScript sample implementation: The R sample implementation: Parameters: `context` `Context`: the context for a guest language code literal evaluation. Returns `Value`: the [`Value`](https://graalvm.elide.help/25.6.0-elide.4/api/polyglot/org/graalvm/polyglot/Value.html) representing the identity function. Cite: `org/graalvm/polyglot/tck/LanguageProvider.html#createIdentityFunction(org.graalvm.polyglot.Context)`

```java
@Override
public Value createIdentityFunction(Context context) {
    return context.eval("js", "(function (a){ return a; })");
}
```

```java
@Override
public Value createIdentityFunction(Context context) {
    return context.eval("R", "function (a){ a }");
}
```

### createIdentityFunctionSnippet(Context)
<a id="createIdentityFunctionSnippet(org.graalvm.polyglot.Context)"></a>`default Snippet createIdentityFunctionSnippet(Context context)`. Since 19.1.0. Creates a `Snippet` for an identity function. The identity function just returns its argument. This method allows an implementor to override the default identity function verification. In most cases it's not needed to implement this method and it's enough to implement `createIdentityFunction`. The implementor can delegate to the default identity function verifier obtained by `ResultVerifier.getIdentityFunctionDefaultResultVerifier()`. Parameters: `context` `Context`: the context for a guest language code literal evaluation. Returns `Snippet`: the `Snippet` representing the identity function. Cite: `org/graalvm/polyglot/tck/LanguageProvider.html#createIdentityFunctionSnippet(org.graalvm.polyglot.Context)`

### createValueConstructors(Context)
<a id="createValueConstructors(org.graalvm.polyglot.Context)"></a>`Collection<? extends Snippet> createValueConstructors(Context context)`. Since 0.30. Creates a collection of functions creating language data types. For each language data type create a function returning a value of given type and assign a correct `TypeDescriptor` to it. The `TypeDescriptor` can be one of the predefined `TypeDescriptor`s, an array with component type, an executable with required parameter types or an intersection type. The JavaScript sample implementation creating a boolean type: Parameters: `context` `Context`: the context for a guest language code literal evaluation. Returns `Collection<? extends Snippet>`: factories creating the language data types. Cite: `org/graalvm/polyglot/tck/LanguageProvider.html#createValueConstructors(org.graalvm.polyglot.Context)`

```java

```

### createExpressions(Context)
<a id="createExpressions(org.graalvm.polyglot.Context)"></a>`Collection<? extends Snippet> createExpressions(Context context)`. Since 0.30. Creates a collection of functions representing language expressions to test. For each language operator create a function performing given operator and assign a correct `TypeDescriptor`s to its parameters and return type. The parameter types and return type can be one of the predefined `TypeDescriptor`s, an array with component type, an executable with required parameter types or an union type. The JavaScript sample implementation creating a plus operator: The R sample implementation creating a plus operator: Parameters: `context` `Context`: the context for a guest language code literal evaluation. Returns `Collection<? extends Snippet>`: factories creating the language expressions. Cite: `org/graalvm/polyglot/tck/LanguageProvider.html#createExpressions(org.graalvm.polyglot.Context)`

```java
@Override
public Collection<? extends Snippet> createExpressions(Context context) {
    final Collection<Snippet> expressions = new ArrayList<>();
    final TypeDescriptor numeric = TypeDescriptor.union(
                    TypeDescriptor.NUMBER,
                    TypeDescriptor.BOOLEAN);
    final TypeDescriptor nonNumeric = TypeDescriptor.union(
                    TypeDescriptor.STRING,
                    TypeDescriptor.OBJECT,
                    TypeDescriptor.ARRAY,
                    TypeDescriptor.EXECUTABLE_ANY);
    Snippet.Builder builder = Snippet.newBuilder(
                    "+",
                    context.eval("js",
                                    "(function (a, b){ return a + b;})"),
                    TypeDescriptor.NUMBER).parameterTypes(numeric, numeric);
    expressions.add(builder.build());
    builder = Snippet.newBuilder(
                    "+",
                    context.eval("js",
                                    "(function (a, b){ return a + b;})"),
                    TypeDescriptor.STRING).parameterTypes(nonNumeric, TypeDescriptor.ANY);
    expressions.add(builder.build());
    builder = Snippet.newBuilder(
                    "+",
                    context.eval("js",
                                    "(function (a, b){ return a + b;})"),
                    TypeDescriptor.STRING).parameterTypes(TypeDescriptor.ANY, nonNumeric);
    expressions.add(builder.build());
    return expressions;
}
```

```java
@Override
public Collection<? extends Snippet> createExpressions(Context context) {
    final Collection<Snippet> expressions = new ArrayList<>();
    final TypeDescriptor numOrBool = TypeDescriptor.union(
                    TypeDescriptor.NUMBER,
                    TypeDescriptor.BOOLEAN);
    final TypeDescriptor arrNumOrBool = TypeDescriptor.array(
                    numOrBool);
    final TypeDescriptor numeric = TypeDescriptor.union(
                    numOrBool,
                    arrNumOrBool);
    Snippet.Builder builder = Snippet.newBuilder(
                    "+",
                    context.eval("R",
                                    "function (a, b){ a + b}"),
                    numeric).parameterTypes(numeric, numeric);
    expressions.add(builder.build());
    return expressions;
}
```

### createStatements(Context)
<a id="createStatements(org.graalvm.polyglot.Context)"></a>`Collection<? extends Snippet> createStatements(Context context)`. Since 0.30. Creates a collection of functions representing language statements to test. For each control flow statement create a function performing given statement and assign a correct `TypeDescriptor`s to its parameters and return type. The parameter types and return type can be one of the predefined `TypeDescriptor`s, an array with component type, an executable with required parameter types or an union type. The JavaScript sample implementation creating the `if` statement: The R sample implementation creating the `if` statement: Parameters: `context` `Context`: the context for a guest language code literal evaluation. Returns `Collection<? extends Snippet>`: factories creating the language statements. Cite: `org/graalvm/polyglot/tck/LanguageProvider.html#createStatements(org.graalvm.polyglot.Context)`

```java
@Override
public Collection<? extends Snippet> createStatements(Context context) {
    final Collection<Snippet> statements = new ArrayList<>();
    Snippet.Builder builder = Snippet.newBuilder(
                    "if",
                    context.eval("js",
                                    "(function (p){\n" +
                                                    "  if (p) return true ; else  return false;\n" +
                                                    "})"),
                    TypeDescriptor.BOOLEAN).parameterTypes(
                                    TypeDescriptor.union(
                                                    TypeDescriptor.STRING,
                                                    TypeDescriptor.OBJECT,
                                                    TypeDescriptor.NUMBER,
                                                    TypeDescriptor.BOOLEAN));
    statements.add(builder.build());
    return statements;
}
```

```java
@Override
public Collection<? extends Snippet> createStatements(Context context) {
    final Collection<Snippet> statements = new ArrayList<>();
    final TypeDescriptor numberOrBoolean = TypeDescriptor.union(
                    TypeDescriptor.NUMBER,
                    TypeDescriptor.BOOLEAN);
    final TypeDescriptor arrayNumberOrBoolean = TypeDescriptor.array(
                    numberOrBoolean);
    Snippet.Builder builder = Snippet.newBuilder(
                    "if",
                    context.eval("R",
                                    "function(p){\n" +
                                                    "  if (p) { return (TRUE) } else { return (FALSE) }\n" +
                                                    "}"),
                    TypeDescriptor.BOOLEAN).parameterTypes(
                                    TypeDescriptor.union(
                                                    numberOrBoolean,
                                                    arrayNumberOrBoolean));
    statements.add(builder.build());
    return statements;
}
```

### createScripts(Context)
<a id="createScripts(org.graalvm.polyglot.Context)"></a>`Collection<? extends Snippet> createScripts(Context context)`. Since 0.30. Creates a collection of simple scripts used for instrumentation testing. Each script is represented as a function performing the script. The function must have no formal parameters but may return a result which can be asserted by `ResultVerifier`. The JavaScript sample implementation: Parameters: `context` `Context`: the context for a guest language code literal evaluation. Returns `Collection<? extends Snippet>`: the language scripts. Cite: `org/graalvm/polyglot/tck/LanguageProvider.html#createScripts(org.graalvm.polyglot.Context)`

```java
@Override
public Collection<? extends Snippet> createScripts(Context context) {
    try {
        final Collection<Snippet> scripts = new ArrayList<>();
        Reader reader = new InputStreamReader(
                        getClass().getResourceAsStream("sample.js"),
                        "UTF-8");
        Source source = Source.newBuilder(
                        "js",
                        reader,
                        "sample.js").build();
        Snippet.Builder builder = Snippet.newBuilder(
                        source.getName(),
                        context.eval(source),
                        TypeDescriptor.NULL);
        scripts.add(builder.build());
        return scripts;
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
```

### createInvalidSyntaxScripts(Context)
<a id="createInvalidSyntaxScripts(org.graalvm.polyglot.Context)"></a>`Collection<? extends Source> createInvalidSyntaxScripts(Context context)`. Since 0.30. Creates a collection of scripts containing a syntax error. The JavaScript sample implementation: Parameters: `context` `Context`: the context for a guest language code literal evaluation. Returns `Collection<? extends Source>`: the scripts. Cite: `org/graalvm/polyglot/tck/LanguageProvider.html#createInvalidSyntaxScripts(org.graalvm.polyglot.Context)`

```java
@Override
public Collection<? extends Source> createInvalidSyntaxScripts(Context ctx) {
    try {
        final Collection scripts = new ArrayList<>();
        Reader reader = new InputStreamReader(
                        getClass().getResourceAsStream("invalidSyntax.js"),
                        "UTF-8");
        scripts.add(Source.newBuilder(
                        "js",
                        reader,
                        "invalidSyntax.js").build());
        return scripts;
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
```

### createInlineScripts(Context)
<a id="createInlineScripts(org.graalvm.polyglot.Context)"></a>`default Collection<? extends InlineSnippet> createInlineScripts(Context context)`. Since 0.32. Creates a collection of inline code snippets. This method is optional, it should be implemented if `TruffleLanguage.parse(InlineParsingRequest)` is implemented. It returns an empty list by default. The JavaScript sample implementation creating inline code snippets: Parameters: `context` `Context`: the context for a guest language code literal evaluation. Returns `Collection<? extends InlineSnippet>`: A collection of inline code snippets. Cite: `org/graalvm/polyglot/tck/LanguageProvider.html#createInlineScripts(org.graalvm.polyglot.Context)`

```java
@Override
public Collection<? extends InlineSnippet> createInlineScripts(Context context) {
    final Collection<InlineSnippet> inlineScripts = new ArrayList<>();
    Snippet.Builder scriptBuilder = Snippet.newBuilder(
                    "factorial",
                    context.eval("js",
                                    "(function (){\n" +
                                                    "  let factorial = function(n) {\n" +
                                                    "    let f = 1;\n" +
                                                    "    for (let i = 2; i <= n; i++) {\n" +
                                                    "      f *= i;\n" +
                                                    "    }\n" +
                                                    "  };\n" +
                                                    "  return factorial(10);\n" +
                                                    "})"),
                    TypeDescriptor.NUMBER);
    InlineSnippet.Builder builder = InlineSnippet.newBuilder(
                    scriptBuilder.build(),
                    "n * n").locationPredicate((SourceSection section) -> {
                        int line = section.getStartLine();
                        return 3 <= line && line <= 6;
                    });
    inlineScripts.add(builder.build());
    builder = InlineSnippet.newBuilder(
                    scriptBuilder.build(),
                    "Math.sin(Math.PI)");
    inlineScripts.add(builder.build());
    return inlineScripts;
}
```
