mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-136336 Cannot compile project after changing JDK version
This commit is contained in:
@@ -225,9 +225,8 @@ public class NewProjectUtil {
|
||||
if (version != null) {
|
||||
LanguageLevel maxLevel = version.getMaxLanguageLevel();
|
||||
LanguageLevelProjectExtension extension = LanguageLevelProjectExtension.getInstance(ProjectManager.getInstance().getDefaultProject());
|
||||
Boolean aDefault = extension.isDefault();
|
||||
LanguageLevelProjectExtension ext = LanguageLevelProjectExtension.getInstance(project);
|
||||
if (aDefault != null && aDefault || maxLevel.compareTo(ext.getLanguageLevel()) < 0) {
|
||||
if (extension.isDefault() || maxLevel.compareTo(ext.getLanguageLevel()) < 0) {
|
||||
ext.setLanguageLevel(maxLevel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.openapi.roots.ui.configuration;
|
||||
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.roots.LanguageLevelModuleExtensionImpl;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -52,6 +53,7 @@ public class ContentEntriesEditor extends JavaContentEntriesEditor {
|
||||
return getModel().getModuleExtension(LanguageLevelModuleExtensionImpl.class);
|
||||
}
|
||||
};
|
||||
myLanguageLevelConfigurable.addProjectDefault(LanguageLevelProjectExtension.getInstance(myProject).getLanguageLevel());
|
||||
mainPanel.add(myLanguageLevelConfigurable.createComponent(), BorderLayout.NORTH);
|
||||
myLanguageLevelConfigurable.reset();
|
||||
}
|
||||
|
||||
+28
-19
@@ -16,16 +16,18 @@
|
||||
package com.intellij.openapi.roots.ui.configuration;
|
||||
|
||||
import com.intellij.core.JavaCoreBundle;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ex.ProjectRootManagerEx;
|
||||
import com.intellij.ui.ListCellRendererWrapper;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.roots.ex.ProjectRootManagerEx;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.ui.ColoredListCellRendererWrapper;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -33,24 +35,30 @@ import javax.swing.*;
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class LanguageLevelCombo extends ComboBox {
|
||||
|
||||
public static final String USE_PROJECT_LANGUAGE_LEVEL = ProjectBundle.message("project.language.level.combo.item");
|
||||
/** Default from current SDK */
|
||||
@Nullable
|
||||
private LanguageLevel myDefaultLevel;
|
||||
private Pair<String, String> myProjectDefault;
|
||||
|
||||
public LanguageLevelCombo() {
|
||||
for (LanguageLevel level : LanguageLevel.values()) {
|
||||
addItem(level);
|
||||
}
|
||||
setRenderer(new ListCellRendererWrapper() {
|
||||
setRenderer(new ColoredListCellRendererWrapper() {
|
||||
@Override
|
||||
public void customize(final JList list, final Object value, final int index, final boolean selected, final boolean hasFocus) {
|
||||
protected void doCustomize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
|
||||
if (value instanceof LanguageLevel) {
|
||||
setText(((LanguageLevel)value).getPresentableText());
|
||||
append(((LanguageLevel)value).getPresentableText());
|
||||
}
|
||||
else if (value instanceof String) {
|
||||
setText((String)value);
|
||||
else if (value instanceof Pair) {
|
||||
Pair<String, String> pair = (Pair<String, String>)value;
|
||||
append(pair.first);
|
||||
if (pair.second != null) {
|
||||
append(" (" + pair.second + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -69,20 +77,19 @@ public class LanguageLevelCombo extends ComboBox {
|
||||
myDefaultLevel = version.getMaxLanguageLevel();
|
||||
}
|
||||
}
|
||||
String item = null;
|
||||
Pair<String, String> item = null;
|
||||
if (myDefaultLevel != null) {
|
||||
item = JavaCoreBundle.message("default.jdk.level.description", myDefaultLevel.getPresentableText());
|
||||
item = Pair.create(JavaCoreBundle.message("default.language.level.description"), myDefaultLevel.getPresentableText());
|
||||
addItem(item);
|
||||
}
|
||||
else if (project.isDefault()) {
|
||||
item = JavaCoreBundle.message("default.language.level.description");
|
||||
item = Pair.create(JavaCoreBundle.message("default.language.level.description"), null);
|
||||
addItem(item);
|
||||
myDefaultLevel = LanguageLevelProjectExtension.getInstance(project).getLanguageLevel();
|
||||
}
|
||||
|
||||
LanguageLevelProjectExtension extension = LanguageLevelProjectExtension.getInstance(project);
|
||||
Boolean aDefault = extension.isDefault();
|
||||
if (item != null && aDefault != null && aDefault) {
|
||||
if (item != null && extension.isDefault()) {
|
||||
setSelectedItem(item);
|
||||
}
|
||||
else {
|
||||
@@ -102,9 +109,11 @@ public class LanguageLevelCombo extends ComboBox {
|
||||
|
||||
@Override
|
||||
public void setSelectedItem(Object anObject) {
|
||||
if (anObject == null) {
|
||||
anObject = USE_PROJECT_LANGUAGE_LEVEL;
|
||||
}
|
||||
super.setSelectedItem(anObject);
|
||||
super.setSelectedItem(anObject == null ? myProjectDefault : anObject);
|
||||
}
|
||||
|
||||
void addProjectDefault(String projectLevel) {
|
||||
myProjectDefault = Pair.create(ProjectBundle.message("project.language.level.combo.item"), projectLevel);
|
||||
insertItemAt(myProjectDefault, 0);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-1
@@ -21,6 +21,7 @@ import com.intellij.openapi.options.UnnamedConfigurable;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.LanguageLevelModuleExtensionImpl;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -44,7 +45,6 @@ public abstract class LanguageLevelConfigurable implements UnnamedConfigurable {
|
||||
getLanguageLevelExtension().setLanguageLevel(languageLevel instanceof LanguageLevel ? (LanguageLevel)languageLevel : null);
|
||||
}
|
||||
});
|
||||
myLanguageLevelCombo.insertItemAt(LanguageLevelCombo.USE_PROJECT_LANGUAGE_LEVEL, 0);
|
||||
|
||||
JLabel label = new JLabel(ProjectBundle.message("module.module.language.level"));
|
||||
label.setLabelFor(myLanguageLevelCombo);
|
||||
@@ -54,6 +54,7 @@ public abstract class LanguageLevelConfigurable implements UnnamedConfigurable {
|
||||
new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(6, 6, 12, 0), 0, 0));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
return myPanel;
|
||||
@@ -81,4 +82,8 @@ public abstract class LanguageLevelConfigurable implements UnnamedConfigurable {
|
||||
}
|
||||
|
||||
public abstract LanguageLevelModuleExtensionImpl getLanguageLevelExtension();
|
||||
|
||||
public void addProjectDefault(LanguageLevel projectDefault) {
|
||||
myLanguageLevelCombo.addProjectDefault(projectDefault.getPresentableText());
|
||||
}
|
||||
}
|
||||
|
||||
+24
-6
@@ -22,6 +22,9 @@ package com.intellij.openapi.roots.impl;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.roots.ProjectExtension;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
@@ -30,6 +33,7 @@ import com.intellij.pom.java.LanguageLevel;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class LanguageLevelProjectExtensionImpl extends LanguageLevelProjectExtension {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.LanguageLevelProjectExtensionImpl");
|
||||
@@ -76,7 +80,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
private void writeExternal(final Element element) {
|
||||
element.setAttribute(LANGUAGE_LEVEL, myLanguageLevel.name());
|
||||
Boolean aBoolean = isDefault();
|
||||
Boolean aBoolean = getDefault();
|
||||
if (aBoolean != null) {
|
||||
element.setAttribute(DEFAULT_ATTRIBUTE, Boolean.toString(aBoolean));
|
||||
}
|
||||
@@ -116,21 +120,35 @@ import org.jetbrains.annotations.NotNull;
|
||||
LOG.warn("Calling deprecated LanguageLevelProjectExtensionImpl.reloadProjectOnLanguageLevelChange, while project reloading is not needed on language level changes");
|
||||
}
|
||||
|
||||
private void projectSdkChanged(@Nullable Sdk sdk) {
|
||||
if (isDefault() && sdk != null) {
|
||||
JavaSdkVersion version = JavaSdk.getInstance().getVersion(sdk);
|
||||
if (version != null) {
|
||||
setLanguageLevel(version.getMaxLanguageLevel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyProjectExtension extends ProjectExtension {
|
||||
private final Project myProject;
|
||||
private final LanguageLevelProjectExtensionImpl myInstance;
|
||||
|
||||
public MyProjectExtension(final Project project) {
|
||||
myProject = project;
|
||||
myInstance = ((LanguageLevelProjectExtensionImpl)getInstance(project));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(final Element element) throws InvalidDataException {
|
||||
((LanguageLevelProjectExtensionImpl)getInstance(myProject)).readExternal(element);
|
||||
myInstance.readExternal(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(final Element element) throws WriteExternalException {
|
||||
((LanguageLevelProjectExtensionImpl)getInstance(myProject)).writeExternal(element);
|
||||
myInstance.writeExternal(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectSdkChanged(@Nullable Sdk sdk) {
|
||||
myInstance.projectSdkChanged(sdk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public abstract class LanguageLevelProjectExtension {
|
||||
* @return null if the property is not set yet (e.g. after migration).
|
||||
*/
|
||||
@Nullable
|
||||
public Boolean isDefault() {
|
||||
public Boolean getDefault() {
|
||||
return myDefault;
|
||||
}
|
||||
|
||||
@@ -50,6 +50,10 @@ public abstract class LanguageLevelProjectExtension {
|
||||
myDefault = value;
|
||||
}
|
||||
|
||||
public boolean isDefault() {
|
||||
return myDefault != null && myDefault;
|
||||
}
|
||||
|
||||
public abstract void languageLevelsChanged();
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
psi.error.attempt.to.edit.class.file=Cannot modify compiled element
|
||||
|
||||
default.language.level.description=SDK default
|
||||
default.jdk.level.description=SDK default ({0})
|
||||
jdk.1.3.language.level.description=1.3 - Plain old Java
|
||||
jdk.1.4.language.level.description=1.4 - 'assert' keyword
|
||||
jdk.1.5.language.level.description=5.0 - 'enum' keyword, generics, autoboxing etc.
|
||||
|
||||
@@ -155,7 +155,7 @@ public class JavaModuleBuilder extends ModuleBuilder implements SourcePathsBuild
|
||||
@Override
|
||||
public List<Module> commit(@NotNull Project project, ModifiableModuleModel model, ModulesProvider modulesProvider) {
|
||||
LanguageLevelProjectExtension extension = LanguageLevelProjectExtension.getInstance(ProjectManager.getInstance().getDefaultProject());
|
||||
Boolean aDefault = extension.isDefault();
|
||||
Boolean aDefault = extension.getDefault();
|
||||
LanguageLevelProjectExtension instance = LanguageLevelProjectExtension.getInstance(project);
|
||||
if (aDefault != null && !aDefault) {
|
||||
instance.setLanguageLevel(extension.getLanguageLevel());
|
||||
|
||||
@@ -21,8 +21,12 @@
|
||||
package com.intellij.openapi.roots;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.JDOMExternalizable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class ProjectExtension implements JDOMExternalizable{
|
||||
public static final ExtensionPointName<ProjectExtension> EP_NAME = ExtensionPointName.create("com.intellij.projectExtension");
|
||||
|
||||
public void projectSdkChanged(@Nullable Sdk sdk) {}
|
||||
}
|
||||
+9
-6
@@ -231,12 +231,20 @@ public class ProjectRootManagerImpl extends ProjectRootManagerEx implements Proj
|
||||
myProjectSdkName = sdk.getName();
|
||||
myProjectSdkType = sdk.getSdkType().getName();
|
||||
}
|
||||
projectJdkChanged();
|
||||
}
|
||||
|
||||
private void projectJdkChanged() {
|
||||
mergeRootsChangesDuring(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myProjectJdkEventDispatcher.getMulticaster().projectJdkChanged();
|
||||
}
|
||||
});
|
||||
Sdk sdk = getProjectSdk();
|
||||
for (ProjectExtension extension : Extensions.getExtensions(ProjectExtension.EP_NAME, myProject)) {
|
||||
extension.projectSdkChanged(sdk);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -244,12 +252,7 @@ public class ProjectRootManagerImpl extends ProjectRootManagerEx implements Proj
|
||||
ApplicationManager.getApplication().assertWriteAccessAllowed();
|
||||
myProjectSdkName = name;
|
||||
|
||||
mergeRootsChangesDuring(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myProjectJdkEventDispatcher.getMulticaster().projectJdkChanged();
|
||||
}
|
||||
});
|
||||
projectJdkChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -246,7 +246,7 @@ libraries.node.text.module=Libraries contain classes that add up various functio
|
||||
\
|
||||
To attach a library to a module, select that module, click the Dependencies tab, click Add and specify the library location.
|
||||
jdks.node.display.name=SDKs
|
||||
project.language.level.combo.item=<Use project language level>
|
||||
project.language.level.combo.item=Project default
|
||||
add.action.name=Add new ...
|
||||
add.new.jdk.text=Add New SDK
|
||||
add.new.global.library.text=New Global Library
|
||||
|
||||
Reference in New Issue
Block a user