diff options
| author | Noopur Gupta | 2019-02-01 09:12:30 +0000 |
|---|---|---|
| committer | Noopur Gupta | 2019-02-01 09:12:30 +0000 |
| commit | 62fbfc51e1a2a536536c5a790250226e89c62d6f (patch) | |
| tree | 5bec001af499c55ae448f980740eb27409cecfe0 | |
| parent | b823e82835414ca8e5e65074df4d53f946c64310 (diff) | |
| download | eclipse.jdt.ui-62fbfc51e1a2a536536c5a790250226e89c62d6f.tar.gz eclipse.jdt.ui-62fbfc51e1a2a536536c5a790250226e89c62d6f.tar.xz eclipse.jdt.ui-62fbfc51e1a2a536536c5a790250226e89c62d6f.zip | |
Bug 543668: [12][quick fix] Add quick fix to enable preview featuresY20190205-0115
Change-Id: I4f5e67f395cb7876222acf11869d55b3c43eaac8
9 files changed, 209 insertions, 9 deletions
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java index 9d60885a92..6b739c3ca7 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java @@ -239,7 +239,7 @@ public class ComplianceConfigurationBlock extends OptionsConfigurationBlock { }; } - private static Key[] getKeys(boolean projectSpecific) { + public static Key[] getKeys(boolean projectSpecific) { Key[] keys= new Key[] { PREF_LOCAL_VARIABLE_ATTR, PREF_LINE_NUMBER_ATTR, PREF_SOURCE_FILE_ATTR, PREF_CODEGEN_UNUSED_LOCAL, PREF_CODEGEN_INLINE_JSR_BYTECODE, INTR_DEFAULT_COMPLIANCE, PREF_COMPLIANCE, PREF_SOURCE_COMPATIBILITY, diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/CompliancePreferencePage.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/CompliancePreferencePage.java index 6c37396ea9..8cbcc72980 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/CompliancePreferencePage.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/CompliancePreferencePage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -7,12 +7,18 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.internal.ui.preferences; +import java.util.Map; + import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; @@ -38,6 +44,14 @@ public class CompliancePreferencePage extends PropertyAndPreferencePage { public static final String PREF_ID= "org.eclipse.jdt.ui.preferences.CompliancePreferencePage"; //$NON-NLS-1$ public static final String PROP_ID= JavaUI.ID_COMPILER_COMPLIANCE_PROPERTY_PAGE; + public static final String DATA_SELECT_OPTION_KEY= "select_option_key"; //$NON-NLS-1$ + public static final String DATA_SELECT_OPTION_QUALIFIER= "select_option_qualifier"; //$NON-NLS-1$ + + /** + * Key for a Boolean value defining if 'use project specific settings' should be enabled or not. + */ + public static final String USE_PROJECT_SPECIFIC_OPTIONS= "use_project_specific_key"; //$NON-NLS-1$ + private ComplianceConfigurationBlock fConfigurationBlock; public CompliancePreferencePage() { @@ -159,4 +173,24 @@ public class CompliancePreferencePage extends PropertyAndPreferencePage { setDescription(null); // no description for property page } + @Override + public void applyData(Object data) { + super.applyData(data); + if (data instanceof Map && fConfigurationBlock != null) { + @SuppressWarnings("unchecked") + Map<String, Object> map= (Map<String, Object>) data; + if (isProjectPreferencePage()) { + Boolean useProjectOptions= (Boolean) map.get(USE_PROJECT_SPECIFIC_OPTIONS); + if (useProjectOptions != null) { + enableProjectSpecificSettings(useProjectOptions.booleanValue()); + } + } + + Object key= map.get(DATA_SELECT_OPTION_KEY); + Object qualifier= map.get(DATA_SELECT_OPTION_QUALIFIER); + if (key instanceof String && qualifier instanceof String) { + fConfigurationBlock.selectOption((String) key, (String) qualifier); + } + } + } } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java index bee4cd4112..266aadcbd8 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -7,6 +7,10 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation @@ -437,4 +441,6 @@ public final class CorrectionMessages extends NLS { public static String VarargsWarningsSubProcessor_remove_safevarargs_label; public static String NullAnnotationsCorrectionProcessor_change_local_variable_to_nonNull; public static String NullAnnotationsCorrectionProcessor_create_packageInfo_with_defaultnullness; + public static String PreviewFeaturesSubProcessor_enable_preview_features; + public static String PreviewFeaturesSubProcessor_enable_preview_features_info; } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties index 4e2c69efae..ce176354fe 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2018 IBM Corporation and others. +# Copyright (c) 2000, 2019 IBM Corporation and others. # # This program and the accompanying materials # are made available under the terms of the Eclipse Public License 2.0 @@ -8,6 +8,10 @@ # # SPDX-License-Identifier: EPL-2.0 # +# This is an implementation of an early-draft specification developed under the Java +# Community Process (JCP) and is made available for testing and evaluation purposes +# only. The code is not compatible with any specification of the JCP. +# # Contributors: # IBM Corporation - initial API and implementation # Benjamin Muskalla <b.muskalla@gmx.net> - [quick fix] Quick fix for missing synchronized modifier - https://bugs.eclipse.org/bugs/show_bug.cgi?id=245250 @@ -472,3 +476,5 @@ VarargsWarningsSubProcessor_remove_safevarargs_label=Remove @SafeVarargs NullAnnotationsCorrectionProcessor_change_local_variable_to_nonNull=Declare ''{0}'' as ''@{1}'' to see the root problem NullAnnotationsCorrectionProcessor_create_packageInfo_with_defaultnullness=Add package-info.java with ''@{0}'' +PreviewFeaturesSubProcessor_enable_preview_features=Enable preview features +PreviewFeaturesSubProcessor_enable_preview_features_info=Open the Java > Compiler preference page to enable preview features diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java index 469f6f13bf..cf2328f711 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2018 IBM Corporation and others. + * Copyright (c) 2012, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -8,6 +8,10 @@ * * SPDX-License-Identifier: EPL-2.0 * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation * Billy Huang <billyhuang31@gmail.com> - [quick assist] concatenate/merge string literals - https://bugs.eclipse.org/77632 @@ -292,6 +296,7 @@ public interface IProposalRelevance { public static final int EXTRACT_LOCAL_ZERO_SELECTION= -1; public static final int MAKE_VARIABLE_DECLARATION_FINAL= -1; + public static final int ENABLE_PREVIEW_FEATURES= -2; public static final int ADD_SUPPRESSWARNINGS= -2; public static final int VARIABLE_TYPE_PROPOSAL_2= -2; public static final int EXTRACT_CONSTANT_ZERO_SELECTION= -2; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/PreviewFeaturesSubProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/PreviewFeaturesSubProcessor.java new file mode 100644 index 0000000000..00e39ee720 --- /dev/null +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/PreviewFeaturesSubProcessor.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.ui.text.correction; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.core.runtime.IProgressMonitor; + +import org.eclipse.core.resources.IProject; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; + +import org.eclipse.jface.text.IDocument; + +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.PreferencesUtil; + +import org.eclipse.jdt.core.IJavaProject; + +import org.eclipse.jdt.internal.corext.util.Messages; + +import org.eclipse.jdt.ui.JavaElementLabels; +import org.eclipse.jdt.ui.text.java.IInvocationContext; +import org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal; +import org.eclipse.jdt.ui.text.java.correction.ICommandAccess; + +import org.eclipse.jdt.internal.ui.JavaPluginImages; +import org.eclipse.jdt.internal.ui.dialogs.OptionalMessageDialog; +import org.eclipse.jdt.internal.ui.preferences.ComplianceConfigurationBlock; +import org.eclipse.jdt.internal.ui.preferences.CompliancePreferencePage; +import org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock; +import org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock.Key; +import org.eclipse.jdt.internal.ui.text.java.hover.JavaHoverMessages; + +public class PreviewFeaturesSubProcessor { + private static final String CONFIGURE_COMPILER_PROBLEM_SEVERITY_DIALOG_ID= "configure_compiler_settings_dialog_id"; //$NON-NLS-1$ + + public static void getEnablePreviewFeaturesProposal(IInvocationContext context, Collection<ICommandAccess> proposals) { + + ChangeCorrectionProposal proposal= new ChangeCorrectionProposal(CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features, null, IProposalRelevance.ENABLE_PREVIEW_FEATURES, + JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)) { + + @Override + public void apply(IDocument document) { + IProject project= null; + IJavaProject javaProject= context.getCompilationUnit().getJavaProject(); + if (javaProject != null) { + project= javaProject.getProject(); + } + Shell shell= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + + boolean usePropertyPage; + Key[] keys= ComplianceConfigurationBlock.getKeys(javaProject != null); + boolean hasProjectSpecificOptions= OptionsConfigurationBlock.hasProjectSpecificOptions(project, keys, null); + + if (!hasProjectSpecificOptions) { + String message= Messages.format( + JavaHoverMessages.ProblemHover_chooseCompilerSettingsTypeDialog_message, + new Object[] { JavaElementLabels.getElementLabel(javaProject, JavaElementLabels.ALL_DEFAULT) }); + + String[] buttons= new String[] { + JavaHoverMessages.ProblemHover_chooseSettingsTypeDialog_button_project, + JavaHoverMessages.ProblemHover_chooseSettingsTypeDialog_button_workspace, + IDialogConstants.CANCEL_LABEL }; + + int result= OptionalMessageDialog.open( + CONFIGURE_COMPILER_PROBLEM_SEVERITY_DIALOG_ID, shell, JavaHoverMessages.ProblemHover_chooseCompilerSettingsTypeDialog_title, null, message, MessageDialog.QUESTION, buttons, + 0, JavaHoverMessages.ProblemHover_chooseSettingsTypeDialog_checkBox_dontShowAgain); + + if (result == OptionalMessageDialog.NOT_SHOWN) { + usePropertyPage= false; + } else if (result == 2 || result == SWT.DEFAULT) { + return; + } else if (result == 0) { + usePropertyPage= true; + } else { + usePropertyPage= false; + } + } else { + usePropertyPage= true; + } + + String pageId; + Map<String, Object> data= new HashMap<>(); + + if (usePropertyPage) { + pageId= CompliancePreferencePage.PROP_ID; + data.put(CompliancePreferencePage.USE_PROJECT_SPECIFIC_OPTIONS, Boolean.TRUE); + } else { + pageId= CompliancePreferencePage.PREF_ID; + } + + if (usePropertyPage) { + PreferencesUtil.createPropertyDialogOn(shell, javaProject, pageId, null, data).open(); + } else { + PreferencesUtil.createPreferenceDialogOn(shell, pageId, null, data).open(); + } + } + + @Override + public String getAdditionalProposalInfo(IProgressMonitor monitor) { + return CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features_info; + } + }; + + proposals.add(proposal); + } +} diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java index e45e335048..84f52285a0 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -7,6 +7,10 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation @@ -294,6 +298,7 @@ public class QuickFixProcessor implements IQuickFixProcessor { case IProblem.MissingNonNullByDefaultAnnotationOnPackage: case IProblem.UndefinedModule: case IProblem.PackageDoesNotExistOrIsEmpty: + case IProblem.PreviewFeatureDisabled: return true; default: return SuppressWarningsSubProcessor.hasSuppressWarningsProposal(cu.getJavaProject(), problemId) @@ -825,6 +830,9 @@ public class QuickFixProcessor implements IQuickFixProcessor { case IProblem.PackageDoesNotExistOrIsEmpty: ModuleCorrectionsSubProcessor.getPackageDoesNotExistProposals(context, problem, proposals); break; + case IProblem.PreviewFeatureDisabled: + PreviewFeaturesSubProcessor.getEnablePreviewFeaturesProposal(context, proposals); + break; default: } if (JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) { diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.java index d8e0773fd3..48568d1eb0 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -8,6 +8,10 @@ * * SPDX-License-Identifier: EPL-2.0 * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -19,7 +23,7 @@ import org.eclipse.osgi.util.NLS; /** * Helper class to get NLSed messages. */ -final class JavaHoverMessages extends NLS { +public final class JavaHoverMessages extends NLS { private static final String BUNDLE_NAME= JavaHoverMessages.class.getName(); @@ -59,6 +63,8 @@ final class JavaHoverMessages extends NLS { public static String ProblemHover_chooseSettingsTypeDialog_checkBox_dontShowAgain; public static String ProblemHover_chooseSettingsTypeDialog_message; public static String ProblemHover_chooseSettingsTypeDialog_title; + public static String ProblemHover_chooseCompilerSettingsTypeDialog_message; + public static String ProblemHover_chooseCompilerSettingsTypeDialog_title; static { NLS.initializeMessages(BUNDLE_NAME, JavaHoverMessages.class); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.properties index a79f3e402a..bce629513c 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2013 IBM Corporation and others. +# Copyright (c) 2000, 2019 IBM Corporation and others. # # This program and the accompanying materials # are made available under the terms of the Eclipse Public License 2.0 @@ -8,6 +8,10 @@ # # SPDX-License-Identifier: EPL-2.0 # +# This is an implementation of an early-draft specification developed under the Java +# Community Process (JCP) and is made available for testing and evaluation purposes +# only. The code is not compatible with any specification of the JCP. +# # Contributors: # IBM Corporation - initial API and implementation ############################################################################### @@ -42,3 +46,5 @@ ProblemHover_chooseSettingsTypeDialog_button_workspace=Configure &Workspace ProblemHover_chooseSettingsTypeDialog_checkBox_dontShowAgain=&Always configure the workspace settings ProblemHover_chooseSettingsTypeDialog_message=The project ''{0}'' does not have any project specific problem severity settings yet.\n\nDo you want to create and configure the project settings or do you want to configure the workspace settings? ProblemHover_chooseSettingsTypeDialog_title=Configure Problem Severity +ProblemHover_chooseCompilerSettingsTypeDialog_message=The project ''{0}'' does not have any project specific compiler settings yet.\n\nDo you want to create and configure the project settings or do you want to configure the workspace settings? +ProblemHover_chooseCompilerSettingsTypeDialog_title=Configure Compiler Settings |
