private static int execInProcess( File kotlinHome, VirtualFile outputDir, File scriptFile, PrintStream out, CompileContext context) { URLClassLoader loader = getOrCreateClassloader(kotlinHome, context); try { String compilerClassName = "org.jetbrains.jet.cli.KotlinCompiler"; Class<?> kompiler = Class.forName(compilerClassName, true, loader); Method exec = kompiler.getDeclaredMethod("exec", PrintStream.class, String[].class); String[] arguments = { "-module", scriptFile.getAbsolutePath(), "-output", path(outputDir), "-tags" }; context.addMessage(INFORMATION, "Using kotlinHome=" + kotlinHome, "", -1, -1); context.addMessage( INFORMATION, "Invoking in-process compiler " + compilerClassName + " with arguments " + Arrays.asList(arguments), "", -1, -1); Object rc = exec.invoke(null, out, arguments); if (rc instanceof Integer) { return ((Integer) rc).intValue(); } else { throw new IllegalStateException("Unexpected return: " + rc); } } catch (Throwable e) { LOG.error(e); return -1; } }
private PsiElement findElementUpstream(PsiElement startingElement, Class className) { PsiElement parent = startingElement.getParent(); if (parent == null) { return null; } PsiElement element = PsiTreeUtil.findChildOfType(parent, className); if (className.isInstance(element)) { return element; } else { try { return findElementUpstream(parent, className); } catch (Exception e) { return null; } } }
private static <T> T narrowImpl(Remote remote, Class<T> to) { //noinspection unchecked return (T) (to.isInstance(remote) ? remote : PortableRemoteObject.narrow(remote, to)); }