Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 13-21
Link Here
|
13 |
import java.util.ArrayList; |
13 |
import java.util.ArrayList; |
14 |
import java.util.Arrays; |
14 |
import java.util.Arrays; |
15 |
import java.util.HashMap; |
15 |
import java.util.HashMap; |
|
|
16 |
import java.util.List; |
16 |
import java.util.Map; |
17 |
import java.util.Map; |
17 |
|
18 |
|
18 |
import org.eclipse.swt.SWT; |
19 |
import org.eclipse.swt.SWT; |
|
|
20 |
import org.eclipse.swt.events.SelectionAdapter; |
19 |
import org.eclipse.swt.events.SelectionEvent; |
21 |
import org.eclipse.swt.events.SelectionEvent; |
20 |
import org.eclipse.swt.events.SelectionListener; |
22 |
import org.eclipse.swt.events.SelectionListener; |
21 |
import org.eclipse.swt.layout.GridData; |
23 |
import org.eclipse.swt.layout.GridData; |
Lines 37-42
Link Here
|
37 |
import org.eclipse.ui.dialogs.PreferencesUtil; |
39 |
import org.eclipse.ui.dialogs.PreferencesUtil; |
38 |
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; |
40 |
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; |
39 |
|
41 |
|
|
|
42 |
import org.eclipse.jdt.core.IClasspathEntry; |
40 |
import org.eclipse.jdt.core.JavaCore; |
43 |
import org.eclipse.jdt.core.JavaCore; |
41 |
|
44 |
|
42 |
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; |
45 |
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; |
Lines 45-50
Link Here
|
45 |
import org.eclipse.jdt.launching.IVMInstall; |
48 |
import org.eclipse.jdt.launching.IVMInstall; |
46 |
import org.eclipse.jdt.launching.IVMInstall2; |
49 |
import org.eclipse.jdt.launching.IVMInstall2; |
47 |
import org.eclipse.jdt.launching.JavaRuntime; |
50 |
import org.eclipse.jdt.launching.JavaRuntime; |
|
|
51 |
import org.eclipse.jdt.launching.environments.IExecutionEnvironment; |
48 |
|
52 |
|
49 |
import org.eclipse.jdt.internal.ui.JavaPlugin; |
53 |
import org.eclipse.jdt.internal.ui.JavaPlugin; |
50 |
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; |
54 |
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; |
Lines 54-77
Link Here
|
54 |
import org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathSupport; |
58 |
import org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathSupport; |
55 |
|
59 |
|
56 |
/** |
60 |
/** |
57 |
*/ |
61 |
* Configuration block for the 'Java Compiler' page. |
|
|
62 |
*/ |
58 |
public class ComplianceConfigurationBlock extends OptionsConfigurationBlock { |
63 |
public class ComplianceConfigurationBlock extends OptionsConfigurationBlock { |
59 |
|
64 |
|
|
|
65 |
/** |
66 |
* Key for the "Compiler compliance follows EE" setting. |
67 |
* <br>Only applicable if <code>fProject != null</code>. |
68 |
* <p>Values are { {@link #DEFAULT_CONF}, {@link #USER_CONF}, or {@link #DISABLED} }. |
69 |
*/ |
70 |
private static final Key INTR_COMPLIANCE_FOLLOWS_EE= getLocalKey("internal.compliance.follows.ee"); //$NON-NLS-1$ |
71 |
|
72 |
/** |
73 |
* Key for the "Use default compliance" setting. |
74 |
* <p>Values are { {@link #DEFAULT_CONF}, {@link #USER_CONF} }. |
75 |
*/ |
76 |
private static final Key INTR_DEFAULT_COMPLIANCE= getLocalKey("internal.default.compliance"); //$NON-NLS-1$ |
77 |
|
60 |
// Preference store keys, see JavaCore.getOptions |
78 |
// Preference store keys, see JavaCore.getOptions |
|
|
79 |
private static final Key PREF_PB_ASSERT_AS_IDENTIFIER= getJDTCoreKey(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER); |
80 |
private static final Key PREF_PB_ENUM_AS_IDENTIFIER= getJDTCoreKey(JavaCore.COMPILER_PB_ENUM_IDENTIFIER); |
81 |
private static final Key PREF_SOURCE_COMPATIBILITY= getJDTCoreKey(JavaCore.COMPILER_SOURCE); |
82 |
private static final Key PREF_CODEGEN_TARGET_PLATFORM= getJDTCoreKey(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM); |
83 |
private static final Key PREF_COMPLIANCE= getJDTCoreKey(JavaCore.COMPILER_COMPLIANCE); |
84 |
|
85 |
/* see also BuildPathSupport#PREFS_COMPLIANCE */ |
86 |
private static final Key[] PREFS_COMPLIANCE= new Key[] { PREF_COMPLIANCE, |
87 |
PREF_PB_ASSERT_AS_IDENTIFIER, PREF_PB_ENUM_AS_IDENTIFIER, |
88 |
PREF_SOURCE_COMPATIBILITY, PREF_CODEGEN_TARGET_PLATFORM }; |
89 |
|
90 |
private static final Key PREF_CODEGEN_INLINE_JSR_BYTECODE= getJDTCoreKey(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE); |
91 |
|
61 |
private static final Key PREF_LOCAL_VARIABLE_ATTR= getJDTCoreKey(JavaCore.COMPILER_LOCAL_VARIABLE_ATTR); |
92 |
private static final Key PREF_LOCAL_VARIABLE_ATTR= getJDTCoreKey(JavaCore.COMPILER_LOCAL_VARIABLE_ATTR); |
62 |
private static final Key PREF_LINE_NUMBER_ATTR= getJDTCoreKey(JavaCore.COMPILER_LINE_NUMBER_ATTR); |
93 |
private static final Key PREF_LINE_NUMBER_ATTR= getJDTCoreKey(JavaCore.COMPILER_LINE_NUMBER_ATTR); |
63 |
private static final Key PREF_SOURCE_FILE_ATTR= getJDTCoreKey(JavaCore.COMPILER_SOURCE_FILE_ATTR); |
94 |
private static final Key PREF_SOURCE_FILE_ATTR= getJDTCoreKey(JavaCore.COMPILER_SOURCE_FILE_ATTR); |
64 |
private static final Key PREF_CODEGEN_UNUSED_LOCAL= getJDTCoreKey(JavaCore.COMPILER_CODEGEN_UNUSED_LOCAL); |
95 |
private static final Key PREF_CODEGEN_UNUSED_LOCAL= getJDTCoreKey(JavaCore.COMPILER_CODEGEN_UNUSED_LOCAL); |
65 |
private static final Key PREF_CODEGEN_TARGET_PLATFORM= getJDTCoreKey(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM); |
96 |
|
66 |
private static final Key PREF_CODEGEN_INLINE_JSR_BYTECODE= getJDTCoreKey(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE); |
|
|
67 |
|
68 |
private static final Key PREF_SOURCE_COMPATIBILITY= getJDTCoreKey(JavaCore.COMPILER_SOURCE); |
69 |
private static final Key PREF_COMPLIANCE= getJDTCoreKey(JavaCore.COMPILER_COMPLIANCE); |
70 |
private static final Key PREF_PB_ASSERT_AS_IDENTIFIER= getJDTCoreKey(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER); |
71 |
private static final Key PREF_PB_ENUM_AS_IDENTIFIER= getJDTCoreKey(JavaCore.COMPILER_PB_ENUM_IDENTIFIER); |
72 |
|
73 |
private static final Key INTR_DEFAULT_COMPLIANCE= getLocalKey("internal.default.compliance"); //$NON-NLS-1$ |
74 |
|
75 |
// values |
97 |
// values |
76 |
private static final String GENERATE= JavaCore.GENERATE; |
98 |
private static final String GENERATE= JavaCore.GENERATE; |
77 |
private static final String DO_NOT_GENERATE= JavaCore.DO_NOT_GENERATE; |
99 |
private static final String DO_NOT_GENERATE= JavaCore.DO_NOT_GENERATE; |
Lines 94-107
Link Here
|
94 |
private static final String ENABLED= JavaCore.ENABLED; |
116 |
private static final String ENABLED= JavaCore.ENABLED; |
95 |
private static final String DISABLED= JavaCore.DISABLED; |
117 |
private static final String DISABLED= JavaCore.DISABLED; |
96 |
|
118 |
|
97 |
|
|
|
98 |
private static final String DEFAULT_CONF= "default"; //$NON-NLS-1$ |
119 |
private static final String DEFAULT_CONF= "default"; //$NON-NLS-1$ |
99 |
private static final String USER_CONF= "user"; //$NON-NLS-1$ |
120 |
private static final String USER_CONF= "user"; //$NON-NLS-1$ |
100 |
|
121 |
|
|
|
122 |
private ArrayList fComplianceFollowsEEControls; |
101 |
private ArrayList fComplianceControls; |
123 |
private ArrayList fComplianceControls; |
|
|
124 |
private ArrayList fComplianceChildControls; |
102 |
private PixelConverter fPixelConverter; |
125 |
private PixelConverter fPixelConverter; |
103 |
|
126 |
|
|
|
127 |
/** |
128 |
* Remembered user compliance (stored when {@link #INTR_DEFAULT_COMPLIANCE} is switched to {@link #DEFAULT_CONF}). |
129 |
* Elements are identified by <code>IDX_*</code> constants. |
130 |
* @see #IDX_ASSERT_AS_IDENTIFIER |
131 |
* @see #IDX_ENUM_AS_IDENTIFIER |
132 |
* @see #IDX_SOURCE_COMPATIBILITY |
133 |
* @see #IDX_CODEGEN_TARGET_PLATFORM |
134 |
* @see #IDX_COMPLIANCE |
135 |
* @see #IDX_INLINE_JSR_BYTECODE |
136 |
*/ |
104 |
private String[] fRememberedUserCompliance; |
137 |
private String[] fRememberedUserCompliance; |
|
|
138 |
|
139 |
/** |
140 |
* Stored compliance settings that were active when the page was first shown. May be <code>null</code>. |
141 |
* Elements are identified by <code>IDX_*</code> constants. |
142 |
* @see #IDX_ASSERT_AS_IDENTIFIER |
143 |
* @see #IDX_ENUM_AS_IDENTIFIER |
144 |
* @see #IDX_SOURCE_COMPATIBILITY |
145 |
* @see #IDX_CODEGEN_TARGET_PLATFORM |
146 |
* @see #IDX_COMPLIANCE |
147 |
* @see #IDX_INLINE_JSR_BYTECODE |
148 |
*/ |
149 |
private String[] fOriginalStoredCompliance; |
105 |
|
150 |
|
106 |
private static final int IDX_ASSERT_AS_IDENTIFIER= 0; |
151 |
private static final int IDX_ASSERT_AS_IDENTIFIER= 0; |
107 |
private static final int IDX_ENUM_AS_IDENTIFIER= 1; |
152 |
private static final int IDX_ENUM_AS_IDENTIFIER= 1; |
Lines 117-127
Link Here
|
117 |
private ControlEnableState fBlockEnableState; |
162 |
private ControlEnableState fBlockEnableState; |
118 |
|
163 |
|
119 |
public ComplianceConfigurationBlock(IStatusChangeListener context, IProject project, IWorkbenchPreferenceContainer container) { |
164 |
public ComplianceConfigurationBlock(IStatusChangeListener context, IProject project, IWorkbenchPreferenceContainer container) { |
120 |
super(context, project, getKeys(), container); |
165 |
super(context, project, getKeys(project != null), container); |
121 |
setDefaultCompilerComplianceValues(); |
166 |
setDefaultCompilerComplianceValues(); |
122 |
|
167 |
|
123 |
fBlockEnableState= null; |
168 |
fBlockEnableState= null; |
|
|
169 |
fComplianceFollowsEEControls= new ArrayList(); |
124 |
fComplianceControls= new ArrayList(); |
170 |
fComplianceControls= new ArrayList(); |
|
|
171 |
fComplianceChildControls= new ArrayList(); |
125 |
|
172 |
|
126 |
fComplianceStatus= new StatusInfo(); |
173 |
fComplianceStatus= new StatusInfo(); |
127 |
|
174 |
|
Lines 135-146
Link Here
|
135 |
}; |
182 |
}; |
136 |
} |
183 |
} |
137 |
|
184 |
|
138 |
private static Key[] getKeys() { |
185 |
private static Key[] getKeys(boolean projectSpecific) { |
139 |
return new Key[] { |
186 |
Key[] keys= new Key[] { |
140 |
PREF_LOCAL_VARIABLE_ATTR, PREF_LINE_NUMBER_ATTR, PREF_SOURCE_FILE_ATTR, PREF_CODEGEN_UNUSED_LOCAL, PREF_CODEGEN_INLINE_JSR_BYTECODE, INTR_DEFAULT_COMPLIANCE, |
187 |
PREF_LOCAL_VARIABLE_ATTR, PREF_LINE_NUMBER_ATTR, PREF_SOURCE_FILE_ATTR, PREF_CODEGEN_UNUSED_LOCAL, PREF_CODEGEN_INLINE_JSR_BYTECODE, INTR_DEFAULT_COMPLIANCE, |
141 |
PREF_COMPLIANCE, PREF_SOURCE_COMPATIBILITY, |
188 |
PREF_COMPLIANCE, PREF_SOURCE_COMPATIBILITY, |
142 |
PREF_CODEGEN_TARGET_PLATFORM, PREF_PB_ASSERT_AS_IDENTIFIER, PREF_PB_ENUM_AS_IDENTIFIER |
189 |
PREF_CODEGEN_TARGET_PLATFORM, PREF_PB_ASSERT_AS_IDENTIFIER, PREF_PB_ENUM_AS_IDENTIFIER |
143 |
}; |
190 |
}; |
|
|
191 |
|
192 |
if (projectSpecific) { |
193 |
Key[] allKeys = new Key[keys.length + 1]; |
194 |
System.arraycopy(keys, 0, allKeys, 0, keys.length); |
195 |
allKeys[keys.length]= INTR_COMPLIANCE_FOLLOWS_EE; |
196 |
return allKeys; |
197 |
} |
198 |
|
199 |
return keys; |
144 |
} |
200 |
} |
145 |
|
201 |
|
146 |
/* (non-Javadoc) |
202 |
/* (non-Javadoc) |
Lines 148-153
Link Here
|
148 |
*/ |
204 |
*/ |
149 |
protected void settingsUpdated() { |
205 |
protected void settingsUpdated() { |
150 |
setValue(INTR_DEFAULT_COMPLIANCE, getCurrentCompliance()); |
206 |
setValue(INTR_DEFAULT_COMPLIANCE, getCurrentCompliance()); |
|
|
207 |
updateComplianceFollowsEE(); |
151 |
super.settingsUpdated(); |
208 |
super.settingsUpdated(); |
152 |
} |
209 |
} |
153 |
|
210 |
|
Lines 220-233
Link Here
|
220 |
group.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
277 |
group.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
221 |
group.setLayout(layout); |
278 |
group.setLayout(layout); |
222 |
|
279 |
|
|
|
280 |
String[] defaultUserValues= new String[] { DEFAULT_CONF, USER_CONF }; |
281 |
|
282 |
Control[] otherChildren= group.getChildren(); |
283 |
if (fProject != null) { |
284 |
String label= PreferencesMessages.ComplianceConfigurationBlock_compliance_follows_EE_label; |
285 |
int widthHint= fPixelConverter.convertWidthInCharsToPixels(40); |
286 |
addCheckBoxWithLink(group, label, INTR_COMPLIANCE_FOLLOWS_EE, defaultUserValues, 0, widthHint, new SelectionAdapter() { |
287 |
public void widgetSelected(SelectionEvent e) { |
288 |
openBuildPathPropertyPage(); |
289 |
} |
290 |
}); |
291 |
} |
292 |
|
293 |
Control[] allChildren= group.getChildren(); |
294 |
fComplianceFollowsEEControls.addAll(Arrays.asList(allChildren)); |
295 |
fComplianceFollowsEEControls.removeAll(Arrays.asList(otherChildren)); |
296 |
otherChildren= allChildren; |
297 |
|
298 |
|
223 |
String label= PreferencesMessages.ComplianceConfigurationBlock_compiler_compliance_label; |
299 |
String label= PreferencesMessages.ComplianceConfigurationBlock_compiler_compliance_label; |
224 |
addComboBox(group, label, PREF_COMPLIANCE, values3456, values3456Labels, 0); |
300 |
addComboBox(group, label, PREF_COMPLIANCE, values3456, values3456Labels, 0); |
225 |
|
301 |
|
226 |
label= PreferencesMessages.ComplianceConfigurationBlock_default_settings_label; |
302 |
label= PreferencesMessages.ComplianceConfigurationBlock_default_settings_label; |
227 |
addCheckBox(group, label, INTR_DEFAULT_COMPLIANCE, new String[] { DEFAULT_CONF, USER_CONF }, 0); |
303 |
addCheckBox(group, label, INTR_DEFAULT_COMPLIANCE, defaultUserValues, 0); |
228 |
|
304 |
|
|
|
305 |
allChildren= group.getChildren(); |
306 |
fComplianceControls.addAll(Arrays.asList(allChildren)); |
307 |
fComplianceControls.removeAll(Arrays.asList(otherChildren)); |
308 |
otherChildren= allChildren; |
309 |
|
310 |
|
229 |
int indent= fPixelConverter.convertWidthInCharsToPixels(2); |
311 |
int indent= fPixelConverter.convertWidthInCharsToPixels(2); |
230 |
Control[] otherChildren= group.getChildren(); |
|
|
231 |
|
312 |
|
232 |
String[] versions= new String[] { VERSION_CLDC_1_1, VERSION_1_1, VERSION_1_2, VERSION_1_3, VERSION_1_4, VERSION_1_5, VERSION_1_6 }; |
313 |
String[] versions= new String[] { VERSION_CLDC_1_1, VERSION_1_1, VERSION_1_2, VERSION_1_3, VERSION_1_4, VERSION_1_5, VERSION_1_6 }; |
233 |
String[] versionsLabels= new String[] { |
314 |
String[] versionsLabels= new String[] { |
Lines 260-269
Link Here
|
260 |
label= PreferencesMessages.ComplianceConfigurationBlock_pb_enum_as_identifier_label; |
341 |
label= PreferencesMessages.ComplianceConfigurationBlock_pb_enum_as_identifier_label; |
261 |
addComboBox(group, label, PREF_PB_ENUM_AS_IDENTIFIER, errorWarningIgnore, errorWarningIgnoreLabels, indent); |
342 |
addComboBox(group, label, PREF_PB_ENUM_AS_IDENTIFIER, errorWarningIgnore, errorWarningIgnoreLabels, indent); |
262 |
|
343 |
|
263 |
|
344 |
allChildren= group.getChildren(); |
264 |
Control[] allChildren= group.getChildren(); |
345 |
fComplianceChildControls.addAll(Arrays.asList(allChildren)); |
265 |
fComplianceControls.addAll(Arrays.asList(allChildren)); |
346 |
fComplianceChildControls.removeAll(Arrays.asList(otherChildren)); |
266 |
fComplianceControls.removeAll(Arrays.asList(otherChildren)); |
347 |
|
267 |
|
348 |
|
268 |
layout= new GridLayout(); |
349 |
layout= new GridLayout(); |
269 |
layout.numColumns= nColumns; |
350 |
layout.numColumns= nColumns; |
Lines 300-306
Link Here
|
300 |
fJRE50InfoText.addSelectionListener(new SelectionListener() { |
381 |
fJRE50InfoText.addSelectionListener(new SelectionListener() { |
301 |
public void widgetDefaultSelected(SelectionEvent e) { |
382 |
public void widgetDefaultSelected(SelectionEvent e) { |
302 |
if ("1".equals(e.text)) { //$NON-NLS-1$ |
383 |
if ("1".equals(e.text)) { //$NON-NLS-1$ |
303 |
openJREInstallPreferencePage(); |
384 |
openJREInstallPreferencePage(false); |
|
|
385 |
} else if ("2".equals(e.text)) { //$NON-NLS-1$ |
386 |
openJREInstallPreferencePage(true); |
304 |
} else { |
387 |
} else { |
305 |
openBuildPathPropertyPage(); |
388 |
openBuildPathPropertyPage(); |
306 |
} |
389 |
} |
Lines 326-344
Link Here
|
326 |
validateComplianceStatus(); |
409 |
validateComplianceStatus(); |
327 |
} |
410 |
} |
328 |
|
411 |
|
329 |
protected final void openJREInstallPreferencePage() { |
412 |
protected final void openJREInstallPreferencePage(boolean openEE) { |
330 |
String jreID= BuildPathSupport.JRE_PREF_PAGE_ID; |
413 |
String jreID= BuildPathSupport.JRE_PREF_PAGE_ID; |
|
|
414 |
String eeID= BuildPathSupport.EE_PREF_PAGE_ID; |
415 |
String pageId= openEE ? eeID : jreID; |
331 |
if (fProject == null && getPreferenceContainer() != null) { |
416 |
if (fProject == null && getPreferenceContainer() != null) { |
332 |
getPreferenceContainer().openPage(jreID, null); |
417 |
getPreferenceContainer().openPage(pageId, null); |
333 |
} else { |
418 |
} else { |
334 |
PreferencesUtil.createPreferenceDialogOn(getShell(), jreID, new String[] { jreID }, null).open(); |
419 |
PreferencesUtil.createPreferenceDialogOn(getShell(), pageId, new String[] { jreID, eeID }, null).open(); |
335 |
} |
420 |
} |
336 |
validateComplianceStatus(); |
421 |
validateComplianceStatus(); |
337 |
} |
422 |
} |
338 |
|
423 |
|
339 |
/* (non-javadoc) |
424 |
/** |
340 |
* Update fields and validate. |
425 |
* {@inheritDoc} |
341 |
* @param changedKey Key that changed, or null, if all changed. |
|
|
342 |
*/ |
426 |
*/ |
343 |
protected void validateSettings(Key changedKey, String oldValue, String newValue) { |
427 |
protected void validateSettings(Key changedKey, String oldValue, String newValue) { |
344 |
if (!areSettingsEnabled()) { |
428 |
if (!areSettingsEnabled()) { |
Lines 349-365
Link Here
|
349 |
updateComplianceEnableState(); |
433 |
updateComplianceEnableState(); |
350 |
updateComplianceDefaultSettings(true, null); |
434 |
updateComplianceDefaultSettings(true, null); |
351 |
fComplianceStatus= validateCompliance(); |
435 |
fComplianceStatus= validateCompliance(); |
|
|
436 |
} else if (INTR_COMPLIANCE_FOLLOWS_EE.equals(changedKey)) { |
437 |
setValue(INTR_DEFAULT_COMPLIANCE, DEFAULT_CONF); |
438 |
updateComplianceEnableState(); |
439 |
updateComplianceDefaultSettings(true, null); |
440 |
updateControls(); |
441 |
fComplianceStatus= validateCompliance(); |
442 |
validateComplianceStatus(); |
352 |
} else if (PREF_COMPLIANCE.equals(changedKey)) { |
443 |
} else if (PREF_COMPLIANCE.equals(changedKey)) { |
353 |
// set compliance settings to default |
444 |
// set compliance settings to default |
354 |
Object oldDefault= getValue(INTR_DEFAULT_COMPLIANCE); |
445 |
Object oldDefault= getValue(INTR_DEFAULT_COMPLIANCE); |
355 |
updateComplianceDefaultSettings(USER_CONF.equals(oldDefault), oldValue); |
446 |
boolean rememberOld= USER_CONF.equals(oldDefault); |
|
|
447 |
updateComplianceDefaultSettings(rememberOld, oldValue); |
356 |
fComplianceStatus= validateCompliance(); |
448 |
fComplianceStatus= validateCompliance(); |
357 |
validateComplianceStatus(); |
449 |
validateComplianceStatus(); |
358 |
} else if (PREF_SOURCE_COMPATIBILITY.equals(changedKey)) { |
450 |
} else if (PREF_SOURCE_COMPATIBILITY.equals(changedKey)) { |
359 |
updateAssertEnumAsIdentifierEnableState(); |
451 |
updateAssertEnumAsIdentifierEnableState(); |
360 |
fComplianceStatus= validateCompliance(); |
452 |
fComplianceStatus= validateCompliance(); |
361 |
} else if (PREF_CODEGEN_TARGET_PLATFORM.equals(changedKey)) { |
453 |
} else if (PREF_CODEGEN_TARGET_PLATFORM.equals(changedKey)) { |
362 |
updateInlineJSREnableState(); |
|
|
363 |
if (VERSION_CLDC_1_1.equals(newValue) && !oldValue.equals(newValue)) { |
454 |
if (VERSION_CLDC_1_1.equals(newValue) && !oldValue.equals(newValue)) { |
364 |
String compliance= getValue(PREF_COMPLIANCE); |
455 |
String compliance= getValue(PREF_COMPLIANCE); |
365 |
String source= getValue(PREF_SOURCE_COMPATIBILITY); |
456 |
String source= getValue(PREF_SOURCE_COMPATIBILITY); |
Lines 381-386
Link Here
|
381 |
return; |
472 |
return; |
382 |
} |
473 |
} |
383 |
} else { |
474 |
} else { |
|
|
475 |
updateComplianceFollowsEE(); |
476 |
updateControls(); |
384 |
updateComplianceEnableState(); |
477 |
updateComplianceEnableState(); |
385 |
updateAssertEnumAsIdentifierEnableState(); |
478 |
updateAssertEnumAsIdentifierEnableState(); |
386 |
updateInlineJSREnableState(); |
479 |
updateInlineJSREnableState(); |
Lines 389-396
Link Here
|
389 |
} |
482 |
} |
390 |
fContext.statusChanged(fComplianceStatus); |
483 |
fContext.statusChanged(fComplianceStatus); |
391 |
} |
484 |
} |
|
|
485 |
|
486 |
public void refreshComplianceSettings() { |
487 |
if (fProject != null) { |
488 |
if (fOriginalStoredCompliance == null) { |
489 |
fOriginalStoredCompliance= new String[] { // caution: order depends on IDX_* constants |
490 |
getOriginalStoredValue(PREF_PB_ASSERT_AS_IDENTIFIER), |
491 |
getOriginalStoredValue(PREF_PB_ENUM_AS_IDENTIFIER), |
492 |
getOriginalStoredValue(PREF_SOURCE_COMPATIBILITY), |
493 |
getOriginalStoredValue(PREF_CODEGEN_TARGET_PLATFORM), |
494 |
getOriginalStoredValue(PREF_COMPLIANCE), |
495 |
getOriginalStoredValue(PREF_CODEGEN_INLINE_JSR_BYTECODE), |
496 |
}; |
497 |
|
498 |
} else { |
499 |
String[] storedCompliance= new String[] { |
500 |
getOriginalStoredValue(PREF_PB_ASSERT_AS_IDENTIFIER), |
501 |
getOriginalStoredValue(PREF_PB_ENUM_AS_IDENTIFIER), |
502 |
getOriginalStoredValue(PREF_SOURCE_COMPATIBILITY), |
503 |
getOriginalStoredValue(PREF_CODEGEN_TARGET_PLATFORM), |
504 |
getOriginalStoredValue(PREF_COMPLIANCE), |
505 |
getOriginalStoredValue(PREF_CODEGEN_INLINE_JSR_BYTECODE), |
506 |
}; |
507 |
if (!Arrays.equals(fOriginalStoredCompliance, storedCompliance)) { |
508 |
// compliance changed on disk -> override user modifications |
509 |
|
510 |
fOriginalStoredCompliance= storedCompliance; |
511 |
|
512 |
setValue(PREF_PB_ASSERT_AS_IDENTIFIER, storedCompliance[IDX_ASSERT_AS_IDENTIFIER]); |
513 |
setValue(PREF_PB_ENUM_AS_IDENTIFIER, storedCompliance[IDX_ENUM_AS_IDENTIFIER]); |
514 |
setValue(PREF_SOURCE_COMPATIBILITY, storedCompliance[IDX_SOURCE_COMPATIBILITY]); |
515 |
setValue(PREF_CODEGEN_TARGET_PLATFORM, storedCompliance[IDX_CODEGEN_TARGET_PLATFORM]); |
516 |
setValue(PREF_COMPLIANCE, storedCompliance[IDX_COMPLIANCE]); |
517 |
setValue(PREF_CODEGEN_INLINE_JSR_BYTECODE, storedCompliance[IDX_INLINE_JSR_BYTECODE]); |
518 |
|
519 |
} |
520 |
|
521 |
updateComplianceFollowsEE(); |
522 |
updateControls(); |
523 |
updateComplianceEnableState(); |
524 |
validateComplianceStatus(); |
525 |
} |
526 |
} |
527 |
} |
392 |
|
528 |
|
393 |
private void validateComplianceStatus() { |
529 |
private void validateComplianceStatus() { |
|
|
530 |
//TODO: updated VM in .classpath is not resolved yet! |
394 |
if (fJRE50InfoText != null && !fJRE50InfoText.isDisposed()) { |
531 |
if (fJRE50InfoText != null && !fJRE50InfoText.isDisposed()) { |
395 |
boolean isVisible= false; |
532 |
boolean isVisible= false; |
396 |
String compliance= getStoredValue(PREF_COMPLIANCE); // get actual value |
533 |
String compliance= getStoredValue(PREF_COMPLIANCE); // get actual value |
Lines 467-480
Link Here
|
467 |
validateComplianceStatus(); |
604 |
validateComplianceStatus(); |
468 |
} |
605 |
} |
469 |
|
606 |
|
470 |
/* |
607 |
private void updateComplianceFollowsEE() { |
471 |
* Update the compliance controls' enable state |
608 |
if (fProject != null) { |
472 |
*/ |
609 |
String complianceFollowsEE= DISABLED; |
|
|
610 |
IExecutionEnvironment ee= getEE(); |
611 |
if (ee != null) { |
612 |
complianceFollowsEE= getComplianceFollowsEE(ee); |
613 |
} |
614 |
setValue(INTR_COMPLIANCE_FOLLOWS_EE, complianceFollowsEE); |
615 |
} |
616 |
} |
617 |
|
473 |
private void updateComplianceEnableState() { |
618 |
private void updateComplianceEnableState() { |
474 |
boolean enabled= checkValue(INTR_DEFAULT_COMPLIANCE, USER_CONF); |
619 |
boolean enableComplianceControls= true; |
475 |
for (int i= fComplianceControls.size() - 1; i >= 0; i--) { |
620 |
if (fProject != null) { |
476 |
Control curr= (Control) fComplianceControls.get(i); |
621 |
String complianceFollowsEE= getValue(INTR_COMPLIANCE_FOLLOWS_EE); |
477 |
curr.setEnabled(enabled); |
622 |
updateCheckBox(getCheckBox(INTR_COMPLIANCE_FOLLOWS_EE)); |
|
|
623 |
boolean enableComplianceFollowsEE= ! DISABLED.equals(complianceFollowsEE); // is default or user |
624 |
updateControlsEnableState(fComplianceFollowsEEControls, enableComplianceFollowsEE); |
625 |
|
626 |
enableComplianceControls= ! DEFAULT_CONF.equals(complianceFollowsEE); // is disabled or user |
627 |
updateControlsEnableState(fComplianceControls, enableComplianceControls); |
628 |
} |
629 |
|
630 |
boolean enableComplianceChildren= enableComplianceControls && checkValue(INTR_DEFAULT_COMPLIANCE, USER_CONF); |
631 |
updateControlsEnableState(fComplianceChildControls, enableComplianceChildren); |
632 |
} |
633 |
|
634 |
private void updateControlsEnableState(List controls, boolean enable) { |
635 |
for (int i= controls.size() - 1; i >= 0; i--) { |
636 |
Control curr= (Control) controls.get(i); |
637 |
if (curr instanceof Composite) { |
638 |
updateControlsEnableState(Arrays.asList(((Composite)curr).getChildren()), enable); |
639 |
} |
640 |
curr.setEnabled(enable); |
478 |
} |
641 |
} |
479 |
} |
642 |
} |
480 |
|
643 |
|
Lines 534-548
Link Here
|
534 |
} |
697 |
} |
535 |
} |
698 |
} |
536 |
|
699 |
|
537 |
/* |
700 |
/** |
538 |
* Set the default compliance values derived from the chosen level |
701 |
* Sets the default compliance values derived from the chosen level or restores the user |
|
|
702 |
* compliance settings. |
703 |
* |
704 |
* @param rememberOld if <code>true</code>, the current compliance settings are remembered as |
705 |
* user settings. If <code>false</code>, overwrite the current settings. |
706 |
* @param oldComplianceLevel the previous compliance level |
539 |
*/ |
707 |
*/ |
540 |
private void updateComplianceDefaultSettings(boolean rememberOld, String oldComplianceLevel) { |
708 |
private void updateComplianceDefaultSettings(boolean rememberOld, String oldComplianceLevel) { |
541 |
String assertAsId, enumAsId, source, target; |
709 |
String assertAsId, enumAsId, source, target; |
542 |
boolean isDefault= checkValue(INTR_DEFAULT_COMPLIANCE, DEFAULT_CONF); |
710 |
boolean isDefault= checkValue(INTR_DEFAULT_COMPLIANCE, DEFAULT_CONF); |
|
|
711 |
boolean isFollowEE= checkValue(INTR_COMPLIANCE_FOLLOWS_EE, DEFAULT_CONF); |
543 |
String complianceLevel= getValue(PREF_COMPLIANCE); |
712 |
String complianceLevel= getValue(PREF_COMPLIANCE); |
544 |
|
713 |
|
545 |
if (isDefault) { |
714 |
if (isDefault || isFollowEE) { |
546 |
if (rememberOld) { |
715 |
if (rememberOld) { |
547 |
if (oldComplianceLevel == null) { |
716 |
if (oldComplianceLevel == null) { |
548 |
oldComplianceLevel= complianceLevel; |
717 |
oldComplianceLevel= complianceLevel; |
Lines 554-580
Link Here
|
554 |
fRememberedUserCompliance[IDX_CODEGEN_TARGET_PLATFORM]= getValue(PREF_CODEGEN_TARGET_PLATFORM); |
723 |
fRememberedUserCompliance[IDX_CODEGEN_TARGET_PLATFORM]= getValue(PREF_CODEGEN_TARGET_PLATFORM); |
555 |
fRememberedUserCompliance[IDX_COMPLIANCE]= oldComplianceLevel; |
724 |
fRememberedUserCompliance[IDX_COMPLIANCE]= oldComplianceLevel; |
556 |
} |
725 |
} |
557 |
|
726 |
|
558 |
if (VERSION_1_4.equals(complianceLevel)) { |
727 |
if (isFollowEE) { |
559 |
assertAsId= WARNING; |
728 |
IExecutionEnvironment ee= getEE(); |
560 |
enumAsId= WARNING; |
729 |
Map eeOptions= BuildPathSupport.getEEOptions(ee); |
561 |
source= VERSION_1_3; |
730 |
if (eeOptions == null) |
562 |
target= VERSION_1_2; |
731 |
return; |
563 |
} else if (VERSION_1_5.equals(complianceLevel)) { |
732 |
|
564 |
assertAsId= ERROR; |
733 |
assertAsId= (String)eeOptions.get(PREF_PB_ASSERT_AS_IDENTIFIER.getName()); |
565 |
enumAsId= ERROR; |
734 |
enumAsId= (String)eeOptions.get(PREF_PB_ENUM_AS_IDENTIFIER.getName()); |
566 |
source= VERSION_1_5; |
735 |
source= (String)eeOptions.get(PREF_SOURCE_COMPATIBILITY.getName()); |
567 |
target= VERSION_1_5; |
736 |
target= (String)eeOptions.get(PREF_CODEGEN_TARGET_PLATFORM.getName()); |
568 |
} else if (VERSION_1_6.equals(complianceLevel)) { |
737 |
|
569 |
assertAsId= ERROR; |
738 |
setValue(PREF_COMPLIANCE, (String)eeOptions.get(PREF_COMPLIANCE.getName())); |
570 |
enumAsId= ERROR; |
739 |
String inlineJSR= (String)eeOptions.get(PREF_CODEGEN_INLINE_JSR_BYTECODE.getName()); |
571 |
source= VERSION_1_6; |
740 |
if (inlineJSR != null) { |
572 |
target= VERSION_1_6; |
741 |
setValue(PREF_CODEGEN_INLINE_JSR_BYTECODE, inlineJSR); |
|
|
742 |
} |
743 |
|
573 |
} else { |
744 |
} else { |
574 |
assertAsId= IGNORE; |
745 |
//TODO: use JavaModelUtil.setComplianceOptions(new HashMap(), complianceLevel); |
575 |
enumAsId= IGNORE; |
746 |
if (VERSION_1_4.equals(complianceLevel)) { |
576 |
source= VERSION_1_3; |
747 |
assertAsId= WARNING; |
577 |
target= VERSION_1_1; |
748 |
enumAsId= WARNING; |
|
|
749 |
source= VERSION_1_3; |
750 |
target= VERSION_1_2; |
751 |
} else if (VERSION_1_5.equals(complianceLevel)) { |
752 |
assertAsId= ERROR; |
753 |
enumAsId= ERROR; |
754 |
source= VERSION_1_5; |
755 |
target= VERSION_1_5; |
756 |
} else if (VERSION_1_6.equals(complianceLevel)) { |
757 |
assertAsId= ERROR; |
758 |
enumAsId= ERROR; |
759 |
source= VERSION_1_6; |
760 |
target= VERSION_1_6; |
761 |
} else { |
762 |
assertAsId= IGNORE; |
763 |
enumAsId= IGNORE; |
764 |
source= VERSION_1_3; |
765 |
target= VERSION_1_1; |
766 |
} |
578 |
} |
767 |
} |
579 |
} else { |
768 |
} else { |
580 |
if (rememberOld && complianceLevel.equals(fRememberedUserCompliance[IDX_COMPLIANCE])) { |
769 |
if (rememberOld && complianceLevel.equals(fRememberedUserCompliance[IDX_COMPLIANCE])) { |
Lines 597-607
Link Here
|
597 |
updateAssertEnumAsIdentifierEnableState(); |
786 |
updateAssertEnumAsIdentifierEnableState(); |
598 |
} |
787 |
} |
599 |
|
788 |
|
600 |
/* |
789 |
/** |
601 |
* Evaluate if the current compliance setting correspond to a default setting |
790 |
* Evaluate if the current compliance setting correspond to a default setting. |
|
|
791 |
* |
792 |
* @return {@link #DEFAULT_CONF} or {@link #USER_CONF} |
602 |
*/ |
793 |
*/ |
603 |
private String getCurrentCompliance() { |
794 |
private String getCurrentCompliance() { |
604 |
Object complianceLevel= getValue(PREF_COMPLIANCE); |
795 |
Object complianceLevel= getValue(PREF_COMPLIANCE); |
|
|
796 |
//TODO: use JavaModelUtil.setComplianceOptions(new HashMap(), complianceLevel); |
605 |
if ((VERSION_1_3.equals(complianceLevel) |
797 |
if ((VERSION_1_3.equals(complianceLevel) |
606 |
&& IGNORE.equals(getValue(PREF_PB_ASSERT_AS_IDENTIFIER)) |
798 |
&& IGNORE.equals(getValue(PREF_PB_ASSERT_AS_IDENTIFIER)) |
607 |
&& IGNORE.equals(getValue(PREF_PB_ENUM_AS_IDENTIFIER)) |
799 |
&& IGNORE.equals(getValue(PREF_PB_ENUM_AS_IDENTIFIER)) |
Lines 627-633
Link Here
|
627 |
return USER_CONF; |
819 |
return USER_CONF; |
628 |
} |
820 |
} |
629 |
|
821 |
|
|
|
822 |
private IExecutionEnvironment getEE() { |
823 |
if (fProject == null) |
824 |
return null; |
825 |
|
826 |
try { |
827 |
IClasspathEntry[] entries= JavaCore.create(fProject).getRawClasspath(); |
828 |
for (int i= 0; i < entries.length; i++) { |
829 |
IClasspathEntry entry= entries[i]; |
830 |
if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { |
831 |
String eeId= JavaRuntime.getExecutionEnvironmentId(entry.getPath()); |
832 |
if (eeId != null) { |
833 |
return JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(eeId); |
834 |
} |
835 |
} |
836 |
} |
837 |
} catch (CoreException e) { |
838 |
JavaPlugin.log(e); |
839 |
} |
840 |
return null; |
841 |
} |
630 |
|
842 |
|
|
|
843 |
/** |
844 |
* Evaluate if the builds path contains an execution environment and the current compliance |
845 |
* settings follow the EE options. |
846 |
* |
847 |
* @param ee the EE, or <code>null</code> if none available |
848 |
* @return {@link #DEFAULT_CONF} if the compliance follows the EE, or {@link #USER_CONF} if the |
849 |
* settings differ, or {@link #DISABLED} if there's no EE at all |
850 |
*/ |
851 |
private String getComplianceFollowsEE(IExecutionEnvironment ee) { |
852 |
Map options= BuildPathSupport.getEEOptions(ee); |
853 |
if (options == null) |
854 |
return DISABLED; |
855 |
|
856 |
return checkDefaults(PREFS_COMPLIANCE, options); |
857 |
} |
858 |
|
859 |
private String checkDefaults(Key[] keys, Map options) { |
860 |
for (int i= 0; i < keys.length; i++) { |
861 |
Key key= keys[i]; |
862 |
Object option= options.get(key.getName()); |
863 |
if (!checkValue(key, (String)option)) |
864 |
return USER_CONF; |
865 |
} |
866 |
return DEFAULT_CONF; |
867 |
} |
868 |
|
631 |
protected String[] getFullBuildDialogStrings(boolean workspaceSettings) { |
869 |
protected String[] getFullBuildDialogStrings(boolean workspaceSettings) { |
632 |
String title= PreferencesMessages.ComplianceConfigurationBlock_needsbuild_title; |
870 |
String title= PreferencesMessages.ComplianceConfigurationBlock_needsbuild_title; |
633 |
String message; |
871 |
String message; |
Lines 639-644
Link Here
|
639 |
return new String[] { title, message }; |
877 |
return new String[] { title, message }; |
640 |
} |
878 |
} |
641 |
|
879 |
|
|
|
880 |
/** |
881 |
* Sets the default compiler compliance options based on the current default JRE in the workspace. |
882 |
* |
883 |
* @since 3.5 |
884 |
*/ |
642 |
private void setDefaultCompilerComplianceValues() { |
885 |
private void setDefaultCompilerComplianceValues() { |
643 |
IVMInstall defaultVMInstall= JavaRuntime.getDefaultVMInstall(); |
886 |
IVMInstall defaultVMInstall= JavaRuntime.getDefaultVMInstall(); |
644 |
if (defaultVMInstall instanceof IVMInstall2) { |
887 |
if (defaultVMInstall instanceof IVMInstall2) { |
Lines 647-653
Link Here
|
647 |
JavaModelUtil.setComplianceOptions(complianceOptions, complianceLevel); |
890 |
JavaModelUtil.setComplianceOptions(complianceOptions, complianceLevel); |
648 |
setDefaultValue(PREF_COMPLIANCE, (String)complianceOptions.get(PREF_COMPLIANCE.getName())); |
891 |
setDefaultValue(PREF_COMPLIANCE, (String)complianceOptions.get(PREF_COMPLIANCE.getName())); |
649 |
setDefaultValue(PREF_PB_ASSERT_AS_IDENTIFIER, (String)complianceOptions.get(PREF_PB_ASSERT_AS_IDENTIFIER.getName())); |
892 |
setDefaultValue(PREF_PB_ASSERT_AS_IDENTIFIER, (String)complianceOptions.get(PREF_PB_ASSERT_AS_IDENTIFIER.getName())); |
650 |
setDefaultValue(PREF_PB_ENUM_AS_IDENTIFIER, (String)complianceOptions.get(PREF_PB_ASSERT_AS_IDENTIFIER.getName())); |
893 |
setDefaultValue(PREF_PB_ENUM_AS_IDENTIFIER, (String)complianceOptions.get(PREF_PB_ENUM_AS_IDENTIFIER.getName())); |
651 |
setDefaultValue(PREF_SOURCE_COMPATIBILITY, (String)complianceOptions.get(PREF_SOURCE_COMPATIBILITY.getName())); |
894 |
setDefaultValue(PREF_SOURCE_COMPATIBILITY, (String)complianceOptions.get(PREF_SOURCE_COMPATIBILITY.getName())); |
652 |
setDefaultValue(PREF_CODEGEN_TARGET_PLATFORM, (String)complianceOptions.get(PREF_CODEGEN_TARGET_PLATFORM.getName())); |
895 |
setDefaultValue(PREF_CODEGEN_TARGET_PLATFORM, (String)complianceOptions.get(PREF_CODEGEN_TARGET_PLATFORM.getName())); |
653 |
} |
896 |
} |