public static void compileKotlinWithJava( @NotNull List<File> javaFiles, @NotNull List<File> ktFiles, @NotNull File outDir, @NotNull Disposable disposable, @Nullable File javaErrorFile) throws IOException { if (!ktFiles.isEmpty()) { compileKotlinToDirAndGetAnalysisResult(ktFiles, outDir, disposable, ALL, false); } else { boolean mkdirs = outDir.mkdirs(); assert mkdirs : "Not created: " + outDir; } if (!javaFiles.isEmpty()) { compileJavaFiles( javaFiles, Arrays.asList( "-classpath", outDir.getPath() + File.pathSeparator + ForTestCompileRuntime.runtimeJarForTests(), "-d", outDir.getPath()), javaErrorFile); } }
@NotNull public static List<String> getLastCommentsInFile( @NotNull KtFile file, CommentType commentType, boolean assertMustExist) { PsiElement lastChild = file.getLastChild(); if (lastChild != null && lastChild.getNode().getElementType().equals(KtTokens.WHITE_SPACE)) { lastChild = lastChild.getPrevSibling(); } assert lastChild != null; List<String> comments = ContainerUtil.newArrayList(); while (true) { if (lastChild.getNode().getElementType().equals(KtTokens.BLOCK_COMMENT)) { if (commentType == CommentType.ALL || commentType == CommentType.BLOCK_COMMENT) { String lastChildText = lastChild.getText(); comments.add(lastChildText.substring(2, lastChildText.length() - 2).trim()); } } else if (lastChild.getNode().getElementType().equals(KtTokens.EOL_COMMENT)) { if (commentType == CommentType.ALL || commentType == CommentType.LINE_COMMENT) { comments.add(lastChild.getText().substring(2).trim()); } } else { break; } lastChild = lastChild.getPrevSibling(); } if (comments.isEmpty() && assertMustExist) { throw new AssertionError( String.format( "Test file '%s' should end in a comment of type %s; last node was: %s", file.getName(), commentType, lastChild)); } return comments; }
public static void deleteOnShutdown(File file) { if (filesToDelete.isEmpty()) { ShutDownTracker.getInstance() .registerShutdownTask( new Runnable() { @Override public void run() { ShutDownTracker.invokeAndWait( true, true, new Runnable() { @Override public void run() { for (File victim : filesToDelete) { FileUtil.delete(victim); } } }); } }); } filesToDelete.add(file); }