1 11 package org.eclipse.jdt.internal.ui.preferences; 12 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import java.util.HashMap ; 16 import java.util.Map ; 17 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IStatus; 20 21 import org.eclipse.core.resources.IProject; 22 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.events.SelectionEvent; 25 import org.eclipse.swt.events.SelectionListener; 26 import org.eclipse.swt.layout.GridData; 27 import org.eclipse.swt.layout.GridLayout; 28 import org.eclipse.swt.widgets.Button; 29 import org.eclipse.swt.widgets.Combo; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.swt.widgets.Control; 32 import org.eclipse.swt.widgets.Group; 33 import org.eclipse.swt.widgets.Link; 34 35 import org.eclipse.jface.dialogs.ControlEnableState; 36 37 import org.eclipse.ui.dialogs.PreferencesUtil; 38 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; 39 40 import org.eclipse.jdt.core.JavaCore; 41 42 import org.eclipse.jdt.internal.corext.util.JavaModelUtil; 43 import org.eclipse.jdt.internal.corext.util.Messages; 44 45 import org.eclipse.jdt.launching.IVMInstall; 46 import org.eclipse.jdt.launching.IVMInstall2; 47 import org.eclipse.jdt.launching.JavaRuntime; 48 49 import org.eclipse.jdt.internal.ui.JavaPlugin; 50 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; 51 import org.eclipse.jdt.internal.ui.util.PixelConverter; 52 import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener; 53 import org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathSupport; 54 55 57 public class ComplianceConfigurationBlock extends OptionsConfigurationBlock { 58 59 private static final Key PREF_LOCAL_VARIABLE_ATTR= getJDTCoreKey(JavaCore.COMPILER_LOCAL_VARIABLE_ATTR); 61 private static final Key PREF_LINE_NUMBER_ATTR= getJDTCoreKey(JavaCore.COMPILER_LINE_NUMBER_ATTR); 62 private static final Key PREF_SOURCE_FILE_ATTR= getJDTCoreKey(JavaCore.COMPILER_SOURCE_FILE_ATTR); 63 private static final Key PREF_CODEGEN_UNUSED_LOCAL= getJDTCoreKey(JavaCore.COMPILER_CODEGEN_UNUSED_LOCAL); 64 private static final Key PREF_CODEGEN_TARGET_PLATFORM= getJDTCoreKey(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM); 65 private static final Key PREF_CODEGEN_INLINE_JSR_BYTECODE= getJDTCoreKey(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE); 66 67 private static final Key PREF_SOURCE_COMPATIBILITY= getJDTCoreKey(JavaCore.COMPILER_SOURCE); 68 private static final Key PREF_COMPLIANCE= getJDTCoreKey(JavaCore.COMPILER_COMPLIANCE); 69 private static final Key PREF_PB_ASSERT_AS_IDENTIFIER= getJDTCoreKey(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER); 70 private static final Key PREF_PB_ENUM_AS_IDENTIFIER= getJDTCoreKey(JavaCore.COMPILER_PB_ENUM_IDENTIFIER); 71 72 private static final Key INTR_DEFAULT_COMPLIANCE= getJDTUIKey("internal.default.compliance"); 74 private static final String GENERATE= JavaCore.GENERATE; 76 private static final String DO_NOT_GENERATE= JavaCore.DO_NOT_GENERATE; 77 78 private static final String PRESERVE= JavaCore.PRESERVE; 79 private static final String OPTIMIZE_OUT= JavaCore.OPTIMIZE_OUT; 80 81 private static final String VERSION_1_1= JavaCore.VERSION_1_1; 82 private static final String VERSION_1_2= JavaCore.VERSION_1_2; 83 private static final String VERSION_1_3= JavaCore.VERSION_1_3; 84 private static final String VERSION_1_4= JavaCore.VERSION_1_4; 85 private static final String VERSION_1_5= JavaCore.VERSION_1_5; 86 private static final String VERSION_1_6= JavaCore.VERSION_1_6; 87 88 private static final String ERROR= JavaCore.ERROR; 89 private static final String WARNING= JavaCore.WARNING; 90 private static final String IGNORE= JavaCore.IGNORE; 91 92 private static final String ENABLED= JavaCore.ENABLED; 93 private static final String DISABLED= JavaCore.DISABLED; 94 95 96 private static final String DEFAULT_CONF= "default"; private static final String USER_CONF= "user"; 99 private ArrayList fComplianceControls; 100 private PixelConverter fPixelConverter; 101 102 private String [] fRememberedUserCompliance; 103 104 private static final int IDX_ASSERT_AS_IDENTIFIER= 0; 105 private static final int IDX_ENUM_AS_IDENTIFIER= 1; 106 private static final int IDX_SOURCE_COMPATIBILITY= 2; 107 private static final int IDX_CODEGEN_TARGET_PLATFORM= 3; 108 private static final int IDX_COMPLIANCE= 4; 109 private static final int IDX_INLINE_JSR_BYTECODE= 5; 110 111 private IStatus fComplianceStatus; 112 113 private Link fJRE50InfoText; 114 private Composite fControlsComposite; 115 private ControlEnableState fBlockEnableState; 116 117 public ComplianceConfigurationBlock(IStatusChangeListener context, IProject project, IWorkbenchPreferenceContainer container) { 118 super(context, project, getKeys(), container); 119 120 fBlockEnableState= null; 121 fComplianceControls= new ArrayList (); 122 123 fComplianceStatus= new StatusInfo(); 124 125 fRememberedUserCompliance= new String [] { getValue(PREF_PB_ASSERT_AS_IDENTIFIER), 127 getValue(PREF_PB_ENUM_AS_IDENTIFIER), 128 getValue(PREF_SOURCE_COMPATIBILITY), 129 getValue(PREF_CODEGEN_TARGET_PLATFORM), 130 getValue(PREF_COMPLIANCE), 131 getValue(PREF_CODEGEN_INLINE_JSR_BYTECODE), 132 }; 133 } 134 135 private static Key[] getKeys() { 136 return new Key[] { 137 PREF_LOCAL_VARIABLE_ATTR, PREF_LINE_NUMBER_ATTR, PREF_SOURCE_FILE_ATTR, PREF_CODEGEN_UNUSED_LOCAL, 138 PREF_CODEGEN_INLINE_JSR_BYTECODE, 139 PREF_COMPLIANCE, PREF_SOURCE_COMPATIBILITY, 140 PREF_CODEGEN_TARGET_PLATFORM, PREF_PB_ASSERT_AS_IDENTIFIER, PREF_PB_ENUM_AS_IDENTIFIER 141 }; 142 } 143 144 147 protected void settingsUpdated() { 148 setValue(INTR_DEFAULT_COMPLIANCE, getCurrentCompliance()); 149 super.settingsUpdated(); 150 } 151 152 153 156 protected Control createContents(Composite parent) { 157 fPixelConverter= new PixelConverter(parent); 158 setShell(parent.getShell()); 159 160 Composite complianceComposite= createComplianceTabContent(parent); 161 162 validateSettings(null, null, null); 163 164 return complianceComposite; 165 } 166 167 public void enablePreferenceContent(boolean enable) { 168 if (fControlsComposite != null && !fControlsComposite.isDisposed()) { 169 if (enable) { 170 if (fBlockEnableState != null) { 171 fBlockEnableState.restore(); 172 fBlockEnableState= null; 173 } 174 } else { 175 if (fBlockEnableState == null) { 176 fBlockEnableState= ControlEnableState.disable(fControlsComposite); 177 } 178 } 179 } 180 } 181 182 private Composite createComplianceTabContent(Composite folder) { 183 184 185 String [] values3456= new String [] { VERSION_1_3, VERSION_1_4, VERSION_1_5, VERSION_1_6 }; 186 String [] values3456Labels= new String [] { 187 PreferencesMessages.ComplianceConfigurationBlock_version13, 188 PreferencesMessages.ComplianceConfigurationBlock_version14, 189 PreferencesMessages.ComplianceConfigurationBlock_version15, 190 PreferencesMessages.ComplianceConfigurationBlock_version16 191 }; 192 193 final ScrolledPageContent sc1 = new ScrolledPageContent(folder); 194 Composite composite= sc1.getBody(); 195 GridLayout layout= new GridLayout(); 196 layout.marginHeight= 0; 197 layout.marginWidth= 0; 198 composite.setLayout(layout); 199 200 fControlsComposite= new Composite(composite, SWT.NONE); 201 fControlsComposite.setFont(composite.getFont()); 202 fControlsComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); 203 204 layout= new GridLayout(); 205 layout.marginHeight= 0; 206 layout.marginWidth= 0; 207 layout.numColumns= 1; 208 fControlsComposite.setLayout(layout); 209 210 int nColumns= 3; 211 212 layout= new GridLayout(); 213 layout.numColumns= nColumns; 214 215 Group group= new Group(fControlsComposite, SWT.NONE); 216 group.setFont(fControlsComposite.getFont()); 217 group.setText(PreferencesMessages.ComplianceConfigurationBlock_compliance_group_label); 218 group.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); 219 group.setLayout(layout); 220 221 String label= PreferencesMessages.ComplianceConfigurationBlock_compiler_compliance_label; 222 addComboBox(group, label, PREF_COMPLIANCE, values3456, values3456Labels, 0); 223 224 label= PreferencesMessages.ComplianceConfigurationBlock_default_settings_label; 225 addCheckBox(group, label, INTR_DEFAULT_COMPLIANCE, new String [] { DEFAULT_CONF, USER_CONF }, 0); 226 227 int indent= fPixelConverter.convertWidthInCharsToPixels(2); 228 Control[] otherChildren= group.getChildren(); 229 230 String [] versions= new String [] { VERSION_1_1, VERSION_1_2, VERSION_1_3, VERSION_1_4, VERSION_1_5, VERSION_1_6 }; 231 String [] versionsLabels= new String [] { 232 PreferencesMessages.ComplianceConfigurationBlock_version11, 233 PreferencesMessages.ComplianceConfigurationBlock_version12, 234 PreferencesMessages.ComplianceConfigurationBlock_version13, 235 PreferencesMessages.ComplianceConfigurationBlock_version14, 236 PreferencesMessages.ComplianceConfigurationBlock_version15, 237 PreferencesMessages.ComplianceConfigurationBlock_version16 238 }; 239 240 label= PreferencesMessages.ComplianceConfigurationBlock_codegen_targetplatform_label; 241 addComboBox(group, label, PREF_CODEGEN_TARGET_PLATFORM, versions, versionsLabels, indent); 242 243 label= PreferencesMessages.ComplianceConfigurationBlock_source_compatibility_label; 244 addComboBox(group, label, PREF_SOURCE_COMPATIBILITY, values3456, values3456Labels, indent); 245 246 String [] errorWarningIgnore= new String [] { ERROR, WARNING, IGNORE }; 247 248 String [] errorWarningIgnoreLabels= new String [] { 249 PreferencesMessages.ComplianceConfigurationBlock_error, 250 PreferencesMessages.ComplianceConfigurationBlock_warning, 251 PreferencesMessages.ComplianceConfigurationBlock_ignore 252 }; 253 254 label= PreferencesMessages.ComplianceConfigurationBlock_pb_assert_as_identifier_label; 255 addComboBox(group, label, PREF_PB_ASSERT_AS_IDENTIFIER, errorWarningIgnore, errorWarningIgnoreLabels, indent); 256 257 label= PreferencesMessages.ComplianceConfigurationBlock_pb_enum_as_identifier_label; 258 addComboBox(group, label, PREF_PB_ENUM_AS_IDENTIFIER, errorWarningIgnore, errorWarningIgnoreLabels, indent); 259 260 261 Control[] allChildren= group.getChildren(); 262 fComplianceControls.addAll(Arrays.asList(allChildren)); 263 fComplianceControls.removeAll(Arrays.asList(otherChildren)); 264 265 layout= new GridLayout(); 266 layout.numColumns= nColumns; 267 268 group= new Group(fControlsComposite, SWT.NONE); 269 group.setFont(fControlsComposite.getFont()); 270 group.setText(PreferencesMessages.ComplianceConfigurationBlock_classfiles_group_label); 271 group.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); 272 group.setLayout(layout); 273 274 String [] generateValues= new String [] { GENERATE, DO_NOT_GENERATE }; 275 String [] enableDisableValues= new String [] { ENABLED, DISABLED }; 276 277 label= PreferencesMessages.ComplianceConfigurationBlock_variable_attr_label; 278 addCheckBox(group, label, PREF_LOCAL_VARIABLE_ATTR, generateValues, 0); 279 280 label= PreferencesMessages.ComplianceConfigurationBlock_line_number_attr_label; 281 addCheckBox(group, label, PREF_LINE_NUMBER_ATTR, generateValues, 0); 282 283 label= PreferencesMessages.ComplianceConfigurationBlock_source_file_attr_label; 284 addCheckBox(group, label, PREF_SOURCE_FILE_ATTR, generateValues, 0); 285 286 label= PreferencesMessages.ComplianceConfigurationBlock_codegen_unused_local_label; 287 addCheckBox(group, label, PREF_CODEGEN_UNUSED_LOCAL, new String [] { PRESERVE, OPTIMIZE_OUT }, 0); 288 289 label= PreferencesMessages.ComplianceConfigurationBlock_codegen_inline_jsr_bytecode_label; 290 addCheckBox(group, label, PREF_CODEGEN_INLINE_JSR_BYTECODE, enableDisableValues, 0); 291 292 fJRE50InfoText= new Link(composite, SWT.WRAP); 293 fJRE50InfoText.setFont(composite.getFont()); 294 fJRE50InfoText.setText(Messages.format(PreferencesMessages.ComplianceConfigurationBlock_jrecompliance_info_project, new String [] { VERSION_1_3, VERSION_1_3 })); 296 fJRE50InfoText.setVisible(false); 297 fJRE50InfoText.addSelectionListener(new SelectionListener() { 298 public void widgetDefaultSelected(SelectionEvent e) { 299 if ("1".equals(e.text)) { openJREInstallPreferencePage(); 301 } else { 302 openBuildPathPropertyPage(); 303 } 304 } 305 public void widgetSelected(SelectionEvent e) { 306 widgetDefaultSelected(e); 307 } 308 }); 309 GridData gd= new GridData(GridData.FILL, GridData.FILL, true, true); 310 gd.widthHint= fPixelConverter.convertWidthInCharsToPixels(50); 311 fJRE50InfoText.setLayoutData(gd); 312 validateJRE50Status(); 313 314 return sc1; 315 } 316 317 protected final void openBuildPathPropertyPage() { 318 if (getPreferenceContainer() != null) { 319 Map data= new HashMap (); 320 data.put(BuildPathsPropertyPage.DATA_REVEAL_ENTRY, JavaRuntime.getDefaultJREContainerEntry()); 321 getPreferenceContainer().openPage(BuildPathsPropertyPage.PROP_ID, data); 322 } 323 validateJRE50Status(); 324 } 325 326 protected final void openJREInstallPreferencePage() { 327 String jreID= BuildPathSupport.JRE_PREF_PAGE_ID; 328 if (fProject == null && getPreferenceContainer() != null) { 329 getPreferenceContainer().openPage(jreID, null); 330 } else { 331 PreferencesUtil.createPreferenceDialogOn(getShell(), jreID, new String [] { jreID }, null).open(); 332 } 333 validateJRE50Status(); 334 } 335 336 340 protected void validateSettings(Key changedKey, String oldValue, String newValue) { 341 if (!areSettingsEnabled()) { 342 return; 343 } 344 if (changedKey != null) { 345 if (INTR_DEFAULT_COMPLIANCE.equals(changedKey)) { 346 updateComplianceEnableState(); 347 updateComplianceDefaultSettings(true, null); 348 fComplianceStatus= validateCompliance(); 349 } else if (PREF_COMPLIANCE.equals(changedKey)) { 350 Object oldDefault= setValue(INTR_DEFAULT_COMPLIANCE, DEFAULT_CONF); 352 updateComplianceEnableState(); 353 updateComplianceDefaultSettings(USER_CONF.equals(oldDefault), oldValue); 354 fComplianceStatus= validateCompliance(); 355 validateJRE50Status(); 356 } else if (PREF_SOURCE_COMPATIBILITY.equals(changedKey)) { 357 updateAssertEnumAsIdentifierEnableState(); 358 fComplianceStatus= validateCompliance(); 359 } else if (PREF_CODEGEN_TARGET_PLATFORM.equals(changedKey)) { 360 updateInlineJSREnableState(); 361 fComplianceStatus= validateCompliance(); 362 } else if (PREF_PB_ENUM_AS_IDENTIFIER.equals(changedKey) || 363 PREF_PB_ASSERT_AS_IDENTIFIER.equals(changedKey)) { 364 fComplianceStatus= validateCompliance(); 365 } else { 366 return; 367 } 368 } else { 369 updateComplianceEnableState(); 370 updateAssertEnumAsIdentifierEnableState(); 371 updateInlineJSREnableState(); 372 fComplianceStatus= validateCompliance(); 373 validateJRE50Status(); 374 } 375 fContext.statusChanged(fComplianceStatus); 376 } 377 378 private void validateJRE50Status() { 379 if (fJRE50InfoText != null && !fJRE50InfoText.isDisposed()) { 380 boolean isVisible= false; 381 String compliance= getStoredValue(PREF_COMPLIANCE); IVMInstall install= null; 383 if (fProject != null) { try { 385 install= JavaRuntime.getVMInstall(JavaCore.create(fProject)); 386 } catch (CoreException e) { 387 JavaPlugin.log(e); 388 } 389 } else { 390 install= JavaRuntime.getDefaultVMInstall(); 391 } 392 if (install instanceof IVMInstall2) { 393 String compilerCompliance= JavaModelUtil.getCompilerCompliance((IVMInstall2) install, compliance); 394 if (JavaModelUtil.isVersionLessThan(compilerCompliance, compliance)) { String [] args= { getVersionLabel(compliance), getVersionLabel(compilerCompliance) }; 396 if (fProject == null) { 397 fJRE50InfoText.setText(Messages.format(PreferencesMessages.ComplianceConfigurationBlock_jrecompliance_info, args)); 398 } else { 399 fJRE50InfoText.setText(Messages.format(PreferencesMessages.ComplianceConfigurationBlock_jrecompliance_info_project, args)); 400 } 401 isVisible= true; 402 } 403 } 404 fJRE50InfoText.setVisible(isVisible); 405 } 406 } 407 408 private String getVersionLabel(String version) { 409 if (JavaModelUtil.isVersionLessThan(version, VERSION_1_5)) { 410 return version; } 412 if (VERSION_1_5.equals(version)) 413 return PreferencesMessages.ComplianceConfigurationBlock_version15; 414 return PreferencesMessages.ComplianceConfigurationBlock_version16; 415 } 416 417 418 private IStatus validateCompliance() { 419 StatusInfo status= new StatusInfo(); 420 String compliance= getValue(PREF_COMPLIANCE); 421 String source= getValue(PREF_SOURCE_COMPATIBILITY); 422 String target= getValue(PREF_CODEGEN_TARGET_PLATFORM); 423 424 if (JavaModelUtil.isVersionLessThan(compliance, source)) { 426 status.setError(PreferencesMessages.ComplianceConfigurationBlock_src_greater_compliance); 427 return status; 428 } 429 430 if (JavaModelUtil.isVersionLessThan(compliance, target)) { 431 status.setError(PreferencesMessages.ComplianceConfigurationBlock_classfile_greater_compliance); 432 return status; 433 } 434 435 if (!VERSION_1_3.equals(source) && JavaModelUtil.isVersionLessThan(target, source)) { 437 status.setError(PreferencesMessages.ComplianceConfigurationBlock_classfile_greater_source); 438 return status; 439 } 440 441 return status; 442 } 443 444 445 448 public void useProjectSpecificSettings(boolean enable) { 449 super.useProjectSpecificSettings(enable); 450 validateJRE50Status(); 451 } 452 453 456 private void updateComplianceEnableState() { 457 boolean enabled= checkValue(INTR_DEFAULT_COMPLIANCE, USER_CONF); 458 for (int i= fComplianceControls.size() - 1; i >= 0; i--) { 459 Control curr= (Control) fComplianceControls.get(i); 460 curr.setEnabled(enabled); 461 } 462 } 463 464 private void updateAssertEnumAsIdentifierEnableState() { 465 if (checkValue(INTR_DEFAULT_COMPLIANCE, USER_CONF)) { 466 String compatibility= getValue(PREF_SOURCE_COMPATIBILITY); 467 468 boolean isLessThan14= VERSION_1_3.equals(compatibility); 469 updateRememberedComplianceOption(PREF_PB_ASSERT_AS_IDENTIFIER, IDX_ASSERT_AS_IDENTIFIER, isLessThan14); 470 471 boolean isLessThan15= isLessThan14 || VERSION_1_4.equals(compatibility); 472 updateRememberedComplianceOption(PREF_PB_ENUM_AS_IDENTIFIER, IDX_ENUM_AS_IDENTIFIER, isLessThan15); 473 } 474 } 475 476 private void updateRememberedComplianceOption(Key prefKey, int idx, boolean enabled) { 477 Combo combo= getComboBox(prefKey); 478 combo.setEnabled(enabled); 479 480 if (!enabled) { 481 String val= getValue(prefKey); 482 if (!ERROR.equals(val)) { 483 setValue(prefKey, ERROR); 484 updateCombo(combo); 485 fRememberedUserCompliance[idx]= val; 486 } 487 } else { 488 String val= fRememberedUserCompliance[idx]; 489 if (!ERROR.equals(val)) { 490 setValue(prefKey, val); 491 updateCombo(combo); 492 } 493 } 494 } 495 496 private void updateInlineJSREnableState() { 497 String target= getValue(PREF_CODEGEN_TARGET_PLATFORM); 498 499 boolean enabled= JavaModelUtil.isVersionLessThan(target, VERSION_1_5); 500 Button checkBox= getCheckBox(PREF_CODEGEN_INLINE_JSR_BYTECODE); 501 checkBox.setEnabled(enabled); 502 503 if (!enabled) { 504 String val= getValue(PREF_CODEGEN_INLINE_JSR_BYTECODE); 505 fRememberedUserCompliance[IDX_INLINE_JSR_BYTECODE]= val; 506 507 if (!ENABLED.equals(val)) { 508 setValue(PREF_CODEGEN_INLINE_JSR_BYTECODE, ENABLED); 509 updateCheckBox(checkBox); 510 } 511 } else { 512 String val= fRememberedUserCompliance[IDX_INLINE_JSR_BYTECODE]; 513 if (!ENABLED.equals(val)) { 514 setValue(PREF_CODEGEN_INLINE_JSR_BYTECODE, val); 515 updateCheckBox(checkBox); 516 } 517 } 518 } 519 520 523 private void updateComplianceDefaultSettings(boolean rememberOld, String oldComplianceLevel) { 524 String assertAsId, enumAsId, source, target; 525 boolean isDefault= checkValue(INTR_DEFAULT_COMPLIANCE, DEFAULT_CONF); 526 String complianceLevel= getValue(PREF_COMPLIANCE); 527 528 if (isDefault) { 529 if (rememberOld) { 530 if (oldComplianceLevel == null) { 531 oldComplianceLevel= complianceLevel; 532 } 533 534 fRememberedUserCompliance[IDX_ASSERT_AS_IDENTIFIER]= getValue(PREF_PB_ASSERT_AS_IDENTIFIER); 535 fRememberedUserCompliance[IDX_ENUM_AS_IDENTIFIER]= getValue(PREF_PB_ENUM_AS_IDENTIFIER); 536 fRememberedUserCompliance[IDX_SOURCE_COMPATIBILITY]= getValue(PREF_SOURCE_COMPATIBILITY); 537 fRememberedUserCompliance[IDX_CODEGEN_TARGET_PLATFORM]= getValue(PREF_CODEGEN_TARGET_PLATFORM); 538 fRememberedUserCompliance[IDX_COMPLIANCE]= oldComplianceLevel; 539 } 540 541 if (VERSION_1_4.equals(complianceLevel)) { 542 assertAsId= WARNING; 543 enumAsId= WARNING; 544 source= VERSION_1_3; 545 target= VERSION_1_2; 546 } else if (VERSION_1_5.equals(complianceLevel)) { 547 assertAsId= ERROR; 548 enumAsId= ERROR; 549 source= VERSION_1_5; 550 target= VERSION_1_5; 551 } else if (VERSION_1_6.equals(complianceLevel)) { 552 assertAsId= ERROR; 553 enumAsId= ERROR; 554 source= VERSION_1_6; 555 target= VERSION_1_6; 556 } else { 557 assertAsId= IGNORE; 558 enumAsId= IGNORE; 559 source= VERSION_1_3; 560 target= VERSION_1_1; 561 } 562 } else { 563 if (rememberOld && complianceLevel.equals(fRememberedUserCompliance[IDX_COMPLIANCE])) { 564 assertAsId= fRememberedUserCompliance[IDX_ASSERT_AS_IDENTIFIER]; 565 enumAsId= fRememberedUserCompliance[IDX_ENUM_AS_IDENTIFIER]; 566 source= fRememberedUserCompliance[IDX_SOURCE_COMPATIBILITY]; 567 target= fRememberedUserCompliance[IDX_CODEGEN_TARGET_PLATFORM]; 568 } else { 569 updateInlineJSREnableState(); 570 updateAssertEnumAsIdentifierEnableState(); 571 return; 572 } 573 } 574 setValue(PREF_PB_ASSERT_AS_IDENTIFIER, assertAsId); 575 setValue(PREF_PB_ENUM_AS_IDENTIFIER, enumAsId); 576 setValue(PREF_SOURCE_COMPATIBILITY, source); 577 setValue(PREF_CODEGEN_TARGET_PLATFORM, target); 578 updateControls(); 579 updateInlineJSREnableState(); 580 updateAssertEnumAsIdentifierEnableState(); 581 } 582 583 586 private String getCurrentCompliance() { 587 Object complianceLevel= getValue(PREF_COMPLIANCE); 588 if ((VERSION_1_3.equals(complianceLevel) 589 && IGNORE.equals(getValue(PREF_PB_ASSERT_AS_IDENTIFIER)) 590 && IGNORE.equals(getValue(PREF_PB_ENUM_AS_IDENTIFIER)) 591 && VERSION_1_3.equals(getValue(PREF_SOURCE_COMPATIBILITY)) 592 && VERSION_1_1.equals(getValue(PREF_CODEGEN_TARGET_PLATFORM))) 593 || (VERSION_1_4.equals(complianceLevel) 594 && WARNING.equals(getValue(PREF_PB_ASSERT_AS_IDENTIFIER)) 595 && WARNING.equals(getValue(PREF_PB_ENUM_AS_IDENTIFIER)) 596 && VERSION_1_3.equals(getValue(PREF_SOURCE_COMPATIBILITY)) 597 && VERSION_1_2.equals(getValue(PREF_CODEGEN_TARGET_PLATFORM))) 598 || (VERSION_1_5.equals(complianceLevel) 599 && ERROR.equals(getValue(PREF_PB_ASSERT_AS_IDENTIFIER)) 600 && ERROR.equals(getValue(PREF_PB_ENUM_AS_IDENTIFIER)) 601 && VERSION_1_5.equals(getValue(PREF_SOURCE_COMPATIBILITY)) 602 && VERSION_1_5.equals(getValue(PREF_CODEGEN_TARGET_PLATFORM))) 603 || (VERSION_1_6.equals(complianceLevel) 604 && ERROR.equals(getValue(PREF_PB_ASSERT_AS_IDENTIFIER)) 605 && ERROR.equals(getValue(PREF_PB_ENUM_AS_IDENTIFIER)) 606 && VERSION_1_6.equals(getValue(PREF_SOURCE_COMPATIBILITY)) 607 && VERSION_1_6.equals(getValue(PREF_CODEGEN_TARGET_PLATFORM)))) { 608 return DEFAULT_CONF; 609 } 610 return USER_CONF; 611 } 612 613 614 protected String [] getFullBuildDialogStrings(boolean workspaceSettings) { 615 String title= PreferencesMessages.ComplianceConfigurationBlock_needsbuild_title; 616 String message; 617 if (workspaceSettings) { 618 message= PreferencesMessages.ComplianceConfigurationBlock_needsfullbuild_message; 619 } else { 620 message= PreferencesMessages.ComplianceConfigurationBlock_needsprojectbuild_message; 621 } 622 return new String [] { title, message }; 623 } 624 625 628 public boolean performOk() { 629 setValue(INTR_DEFAULT_COMPLIANCE, null); 630 return super.performOk(); 631 } 632 633 636 public boolean performApply() { 637 setValue(INTR_DEFAULT_COMPLIANCE, null); 638 boolean result= super.performApply(); 639 setValue(INTR_DEFAULT_COMPLIANCE, getCurrentCompliance()); 640 return result; 641 } 642 643 } 644 | Popular Tags |