use of com.intellij.openapi.projectRoots.JavaSdkVersion in project intellij-community by JetBrains.
the class JavaSuppressionUtil method canHave15Suppressions.
public static boolean canHave15Suppressions(@NotNull PsiElement file) {
final Module module = ModuleUtilCore.findModuleForPsiElement(file);
if (module == null)
return false;
final Sdk jdk = ModuleRootManager.getInstance(module).getSdk();
if (jdk == null)
return false;
JavaSdkVersion version = getVersion(jdk);
if (version == null)
return false;
final boolean is_1_5 = version.isAtLeast(JavaSdkVersion.JDK_1_5);
return DaemonCodeAnalyzerSettings.getInstance().isSuppressWarnings() && is_1_5 && PsiUtil.isLanguageLevel5OrHigher(file);
}
use of com.intellij.openapi.projectRoots.JavaSdkVersion in project intellij-community by JetBrains.
the class DebuggerManagerImpl method checkTargetJPDAInstalled.
/* Remoting */
private static void checkTargetJPDAInstalled(JavaParameters parameters) throws ExecutionException {
final Sdk jdk = parameters.getJdk();
if (jdk == null) {
throw new ExecutionException(DebuggerBundle.message("error.jdk.not.specified"));
}
final JavaSdkVersion version = JavaSdk.getInstance().getVersion(jdk);
String versionString = jdk.getVersionString();
if (version == JavaSdkVersion.JDK_1_0 || version == JavaSdkVersion.JDK_1_1) {
throw new ExecutionException(DebuggerBundle.message("error.unsupported.jdk.version", versionString));
}
if (SystemInfo.isWindows && version == JavaSdkVersion.JDK_1_2) {
final VirtualFile homeDirectory = jdk.getHomeDirectory();
if (homeDirectory == null || !homeDirectory.isValid()) {
throw new ExecutionException(DebuggerBundle.message("error.invalid.jdk.home", versionString));
}
//noinspection HardCodedStringLiteral
File dllFile = new File(homeDirectory.getPath().replace('/', File.separatorChar) + File.separator + "bin" + File.separator + "jdwp.dll");
if (!dllFile.exists()) {
GetJPDADialog dialog = new GetJPDADialog();
dialog.show();
throw new ExecutionException(DebuggerBundle.message("error.debug.libraries.missing"));
}
}
}
use of com.intellij.openapi.projectRoots.JavaSdkVersion in project intellij-community by JetBrains.
the class LanguageLevelCombo method sdkUpdated.
void sdkUpdated(Sdk sdk, boolean isDefaultProject) {
LanguageLevel newLevel = null;
if (sdk != null) {
JavaSdkVersion version = JavaSdk.getInstance().getVersion(sdk);
if (version != null) {
newLevel = version.getMaxLanguageLevel();
}
}
updateDefaultLevel(newLevel, isDefaultProject);
}
use of com.intellij.openapi.projectRoots.JavaSdkVersion in project intellij-community by JetBrains.
the class CompilingEvaluatorImpl method compile.
@Override
@NotNull
protected Collection<ClassObject> compile(@Nullable JavaSdkVersion debuggeeVersion) throws EvaluateException {
if (myCompiledClasses == null) {
Module module = ReadAction.compute(() -> ModuleUtilCore.findModuleForPsiElement(myPsiContext));
List<String> options = new ArrayList<>();
options.add("-encoding");
options.add("UTF-8");
List<File> platformClasspath = new ArrayList<>();
List<File> classpath = new ArrayList<>();
AnnotationProcessingConfiguration profile = null;
if (module != null) {
assert myProject.equals(module.getProject()) : module + " is from another project";
profile = CompilerConfiguration.getInstance(myProject).getAnnotationProcessingConfiguration(module);
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
for (String s : rootManager.orderEntries().compileOnly().recursively().exportedOnly().withoutSdk().getPathsList().getPathList()) {
classpath.add(new File(s));
}
for (String s : rootManager.orderEntries().compileOnly().sdkOnly().getPathsList().getPathList()) {
platformClasspath.add(new File(s));
}
}
JavaBuilder.addAnnotationProcessingOptions(options, profile);
Pair<Sdk, JavaSdkVersion> runtime = BuildManager.getJavacRuntimeSdk(myProject);
JavaSdkVersion buildRuntimeVersion = runtime.getSecond();
// if compiler or debuggee version or both are unknown, let source and target be the compiler's defaults
if (buildRuntimeVersion != null && debuggeeVersion != null) {
JavaSdkVersion minVersion = buildRuntimeVersion.ordinal() > debuggeeVersion.ordinal() ? debuggeeVersion : buildRuntimeVersion;
String sourceOption = getSourceOption(minVersion.getMaxLanguageLevel());
options.add("-source");
options.add(sourceOption);
options.add("-target");
options.add(sourceOption);
}
CompilerManager compilerManager = CompilerManager.getInstance(myProject);
File sourceFile = null;
try {
sourceFile = generateTempSourceFile(compilerManager.getJavacCompilerWorkingDir());
File srcDir = sourceFile.getParentFile();
List<File> sourcePath = Collections.emptyList();
Set<File> sources = Collections.singleton(sourceFile);
myCompiledClasses = compilerManager.compileJavaCode(options, platformClasspath, classpath, Collections.emptyList(), sourcePath, sources, srcDir);
} catch (CompilationException e) {
StringBuilder res = new StringBuilder("Compilation failed:\n");
for (CompilationException.Message m : e.getMessages()) {
if (m.getCategory() == CompilerMessageCategory.ERROR) {
res.append(m.getText()).append("\n");
}
}
throw new EvaluateException(res.toString());
} catch (Exception e) {
throw new EvaluateException(e.getMessage());
} finally {
if (sourceFile != null) {
FileUtil.delete(sourceFile);
}
}
}
return myCompiledClasses;
}
use of com.intellij.openapi.projectRoots.JavaSdkVersion in project intellij-community by JetBrains.
the class JavaProjectDataService method importData.
@Override
public void importData(@NotNull final Collection<DataNode<JavaProjectData>> toImport, @Nullable final ProjectData projectData, @NotNull final Project project, @NotNull final IdeModifiableModelsProvider modelsProvider) {
if (toImport.isEmpty() || projectData == null) {
return;
}
if (toImport.size() != 1) {
throw new IllegalArgumentException(String.format("Expected to get a single project but got %d: %s", toImport.size(), toImport));
}
final DataNode<JavaProjectData> javaProjectDataNode = toImport.iterator().next();
final DataNode<ProjectData> projectDataNode = ExternalSystemApiUtil.findParent(javaProjectDataNode, ProjectKeys.PROJECT);
assert projectDataNode != null;
if (!ExternalSystemApiUtil.isOneToOneMapping(project, projectDataNode.getData())) {
return;
}
JavaProjectData javaProjectData = javaProjectDataNode.getData();
// JDK.
JavaSdkVersion version = javaProjectData.getJdkVersion();
JavaSdk javaSdk = JavaSdk.getInstance();
ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
Sdk sdk = rootManager.getProjectSdk();
if (sdk != null) {
JavaSdkVersion currentVersion = javaSdk.getVersion(sdk);
if (currentVersion == null || !currentVersion.isAtLeast(version)) {
updateSdk(project, version);
}
} else {
updateSdk(project, version);
}
// Language level.
setLanguageLevel(javaProjectData.getLanguageLevel(), project);
}
Aggregations