private void selectSdk(@NotNull final Project project) { Validate.notNull(project); final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project); final Sdk projectSdk = projectRootManager.getProjectSdk(); if (null == projectSdk) { return; } if (StringUtils.isNotBlank(projectSdk.getVersionString())) { final JavaSdkVersion sdkVersion = JdkVersionUtil.getVersion(projectSdk.getVersionString()); final LanguageLevelProjectExtension languageLevelExt = LanguageLevelProjectExtension.getInstance(project); if (sdkVersion.getMaxLanguageLevel() != languageLevelExt.getLanguageLevel()) { languageLevelExt.setLanguageLevel(sdkVersion.getMaxLanguageLevel()); } } }
@Override public Value evaluate(final EvaluationContext evaluationContext) throws EvaluateException { DebugProcess process = evaluationContext.getDebugProcess(); ClassLoaderReference classLoader = ClassLoadingUtils.getClassLoader(evaluationContext, process); String version = ((VirtualMachineProxyImpl)process.getVirtualMachineProxy()).version(); Collection<ClassObject> classes = compile(JdkVersionUtil.getVersion(version)); defineClasses(classes, evaluationContext, process, classLoader); try { // invoke base evaluator on call code final Project project = ApplicationManager.getApplication().runReadAction(new Computable<Project>() { @Override public Project compute() { return myPsiContext.getProject(); } }); ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(project, new EvaluatingComputable<ExpressionEvaluator>() { @Override public ExpressionEvaluator compute() throws EvaluateException { final TextWithImports callCode = getCallCode(); PsiElement copyContext = myData.getAnchor(); final CodeFragmentFactory factory = DebuggerUtilsEx.findAppropriateCodeFragmentFactory(callCode, copyContext); return factory.getEvaluatorBuilder(). build(factory.createCodeFragment(callCode, copyContext, project), ContextUtil.getSourcePosition(evaluationContext)); } }); ((EvaluationContextImpl)evaluationContext).setClassLoader(classLoader); return evaluator.evaluate(evaluationContext); } catch (Exception e) { throw new EvaluateException("Error during generated code invocation " + e, e); } }
@Nullable private static JavaSdkVersion getVersion(@NotNull Sdk sdk) { String version = sdk.getVersionString(); if (version == null) return null; return JdkVersionUtil.getVersion(version); }
private static boolean isJdkSupportsLevel(@Nullable final Sdk jdk, @NotNull LanguageLevel level) { if (jdk == null) return true; String versionString = jdk.getVersionString(); JavaSdkVersion version = versionString == null ? null : JdkVersionUtil.getVersion(versionString); return version != null && version.getMaxLanguageLevel().isAtLeast(level); }