Search in sources :

Example 1 with Pair

use of kotlin.Pair in project kotlin by JetBrains.

the class AbstractLineNumberTest method createPsiFile.

@NotNull
private Pair<KtFile, KotlinCoreEnvironment> createPsiFile(@NotNull String filename) {
    File file = new File(filename);
    KotlinCoreEnvironment environment = createEnvironment();
    String text;
    try {
        text = FileUtil.loadFile(file, true);
    } catch (IOException e) {
        throw ExceptionUtilsKt.rethrow(e);
    }
    return new Pair<KtFile, KotlinCoreEnvironment>(KotlinTestUtils.createFile(file.getName(), text, environment.getProject()), environment);
}
Also used : KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) IOException(java.io.IOException) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) OutputFile(org.jetbrains.kotlin.backend.common.output.OutputFile) Pair(kotlin.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Pair

use of kotlin.Pair in project kotlin by JetBrains.

the class AbstractCliTest method executeCompilerGrabOutput.

@NotNull
public static Pair<String, ExitCode> executeCompilerGrabOutput(@NotNull CLICompiler<?> compiler, @NotNull List<String> args) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    PrintStream origErr = System.err;
    try {
        System.setErr(new PrintStream(bytes));
        ExitCode exitCode = CLICompiler.doMainNoExit(compiler, ArrayUtil.toStringArray(args));
        return new Pair<String, ExitCode>(bytes.toString("utf-8"), exitCode);
    } catch (Exception e) {
        throw ExceptionUtilsKt.rethrow(e);
    } finally {
        System.setErr(origErr);
    }
}
Also used : PrintStream(java.io.PrintStream) ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Pair(kotlin.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Pair

use of kotlin.Pair in project Ardent by adamint.

the class Command method dispatchInteractiveEvent.

private static boolean dispatchInteractiveEvent(OffsetDateTime creationTime, TextChannel channel, Message message, User user, Consumer<Message> function, int time, boolean sendMessage) {
    final boolean[] success = { false };
    Pair<String, Triplet<String, String, Consumer<Message>>> p = new Pair<>(channel.getId(), new Triplet<>(user.getId(), message.getId(), function));
    InteractiveEvent e = GuildUtils.getShard(channel.getJDA()).interactiveEvent;
    e.getMessageInteractivesQueue().add(p);
    ex.schedule(() -> {
        if (e.getMessageInteractivesQueue().contains(p)) {
            e.getMessageInteractivesQueue().remove(p);
            if (sendMessage) {
                if (time >= 15) {
                    channel.sendMessage("Cancelled your interactive operation because you didn't respond within " + time + " seconds!").queue();
                } else {
                    channel.sendMessage("Cancelled your reaction event because you didn't respond within **" + String.valueOf(time / 1000) + "** seconds").queue();
                }
            }
        }
        return success[0];
    }, time, TimeUnit.SECONDS);
    return success[0];
}
Also used : Triplet(tk.ardentbot.utils.javaAdditions.Triplet) InteractiveEvent(tk.ardentbot.core.events.InteractiveEvent) Pair(kotlin.Pair)

Example 4 with Pair

use of kotlin.Pair in project kotlin by JetBrains.

the class CheckerTestUtil method getDiagnosticsIncludingSyntaxErrors.

@NotNull
public static List<ActualDiagnostic> getDiagnosticsIncludingSyntaxErrors(@NotNull BindingContext bindingContext, @NotNull List<Pair<MultiTargetPlatform, BindingContext>> implementingModulesBindings, @NotNull PsiElement root, boolean markDynamicCalls, @Nullable List<DeclarationDescriptor> dynamicCallDescriptors) {
    List<ActualDiagnostic> result = getDiagnosticsIncludingSyntaxErrors(bindingContext, root, markDynamicCalls, dynamicCallDescriptors, null);
    List<Pair<MultiTargetPlatform, BindingContext>> sortedBindings = CollectionsKt.sortedWith(implementingModulesBindings, new Comparator<Pair<MultiTargetPlatform, BindingContext>>() {

        @Override
        public int compare(Pair<MultiTargetPlatform, BindingContext> o1, Pair<MultiTargetPlatform, BindingContext> o2) {
            return o1.getFirst().compareTo(o2.getFirst());
        }
    });
    for (Pair<MultiTargetPlatform, BindingContext> binding : sortedBindings) {
        MultiTargetPlatform platform = binding.getFirst();
        assert platform instanceof MultiTargetPlatform.Specific : "Implementing module must have a specific platform: " + platform;
        result.addAll(getDiagnosticsIncludingSyntaxErrors(binding.getSecond(), root, markDynamicCalls, dynamicCallDescriptors, ((MultiTargetPlatform.Specific) platform).getPlatform()));
    }
    return result;
}
Also used : MultiTargetPlatform(org.jetbrains.kotlin.resolve.MultiTargetPlatform) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) Pair(kotlin.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with Pair

use of kotlin.Pair in project kotlin by JetBrains.

the class AbstractCompileKotlinAgainstKotlinTest method doTwoFileTest.

@NotNull
protected Pair<ClassFileFactory, ClassFileFactory> doTwoFileTest(@NotNull List<TestFile> files) throws Exception {
    // Note that it may be beneficial to improve this test to handle many files, compiling them successively against all previous
    assert files.size() == 2 : "There should be exactly two files in this test";
    TestFile fileA = files.get(0);
    TestFile fileB = files.get(1);
    ClassFileFactory factoryA = compileA(fileA, files);
    ClassFileFactory factoryB = null;
    try {
        factoryB = compileB(fileB, files);
        invokeBox(PackagePartClassUtils.getFilePartShortName(new File(fileB.name).getName()));
    } catch (Throwable e) {
        String result = "FIRST: \n\n" + factoryA.createText();
        if (factoryB != null) {
            result += "\n\nSECOND: \n\n" + factoryB.createText();
        }
        System.out.println(result);
        throw ExceptionUtilsKt.rethrow(e);
    }
    return new Pair<ClassFileFactory, ClassFileFactory>(factoryA, factoryB);
}
Also used : KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) Pair(kotlin.Pair) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Pair (kotlin.Pair)8 NotNull (org.jetbrains.annotations.NotNull)4 InteractiveEvent (tk.ardentbot.core.events.InteractiveEvent)3 Triplet (tk.ardentbot.utils.javaAdditions.Triplet)3 File (java.io.File)2 IOException (java.io.IOException)2 KtFile (org.jetbrains.kotlin.psi.KtFile)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 OutputFile (org.jetbrains.kotlin.backend.common.output.OutputFile)1 ExitCode (org.jetbrains.kotlin.cli.common.ExitCode)1 KotlinCoreEnvironment (org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment)1 FqName (org.jetbrains.kotlin.name.FqName)1 Name (org.jetbrains.kotlin.name.Name)1 BindingContext (org.jetbrains.kotlin.resolve.BindingContext)1 MultiTargetPlatform (org.jetbrains.kotlin.resolve.MultiTargetPlatform)1