diff --git a/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/CustomizerSources.form b/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/CustomizerSources.form index 9b64d244fd61..a61bf2dd0f19 100644 --- a/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/CustomizerSources.form +++ b/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/CustomizerSources.form @@ -72,6 +72,9 @@ + + + diff --git a/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/CustomizerSources.java b/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/CustomizerSources.java index 5eee85a0c127..4e92148bf3fc 100644 --- a/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/CustomizerSources.java +++ b/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/CustomizerSources.java @@ -54,7 +54,7 @@ public void actionPerformed(ActionEvent e) { if (srcLevelValueBeingUpdated) { return; } - final String oldLevel = getProperty(getJavacLanguageLevelKey()); + final String oldLevel = getEffectiveJavacTarget(); final String newLevel = (String) srcLevelValue.getSelectedItem(); SpecificationVersion jdk5 = new SpecificationVersion("1.5"); // NOI18N if (new SpecificationVersion(oldLevel).compareTo(jdk5) < 0 && new SpecificationVersion(newLevel).compareTo(jdk5) >= 0) { @@ -99,7 +99,7 @@ protected void refresh() { for (String level : levels) { srcLevelValue.addItem(level); } - srcLevelValue.setSelectedItem(getProperty(getJavacLanguageLevelKey())); + srcLevelValue.setSelectedItem(getEffectiveJavacTarget()); } finally { srcLevelValueBeingUpdated = false; } @@ -108,25 +108,43 @@ protected void refresh() { @Override public void store() { - setProperty(getJavacLanguageLevelKey(), (String) srcLevelValue.getSelectedItem()); + String selected = (String) srcLevelValue.getSelectedItem(); + if (!selected.equals(getEffectiveJavacTarget())) { + setProperty(getJavacLanguageLevelKey(), selected); + } } private String getJavacLanguageLevelKey() { return containsProperty(JAVAC_RELEASE) ? JAVAC_RELEASE : JAVAC_SOURCE; } - + + private String getEffectiveJavacTarget() { + String release = props.getEvaluator().getProperty(JAVAC_RELEASE); + return isInteger(release) ? release : props.getEvaluator().getProperty(JAVAC_SOURCE); + } + + @SuppressWarnings("UnnecessaryTemporaryOnConversionFromString") + private static boolean isInteger(String release) { + try { + Integer.parseInt(release); + return true; + } catch (IllegalArgumentException ex) { + return false; + } + } + /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ - // //GEN-BEGIN:initComponents + // //GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; prjFolder = new javax.swing.JLabel(); srcLevel = new javax.swing.JLabel(); - srcLevelValue = new javax.swing.JComboBox(); + srcLevelValue = new javax.swing.JComboBox<>(); filler = new javax.swing.JLabel(); prjFolderValue = new javax.swing.JTextField(); moduleSuite = new javax.swing.JLabel(); @@ -193,9 +211,7 @@ private void initComponents() { gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0); add(moduleSuiteValue, gridBagConstraints); - - } - // //GEN-END:initComponents + }// //GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel filler; @@ -204,7 +220,7 @@ private void initComponents() { private javax.swing.JLabel prjFolder; private javax.swing.JTextField prjFolderValue; private javax.swing.JLabel srcLevel; - private javax.swing.JComboBox srcLevelValue; + private javax.swing.JComboBox srcLevelValue; // End of variables declaration//GEN-END:variables private static String getMessage(String key) { @@ -233,7 +249,7 @@ private String[] sourceLevels(JavaPlatform platform) { } catch (Exception ex) { Exceptions.printStackTrace(ex); } - return levels.toArray(new String[0]); + return levels.toArray(String[]::new); } }