diff options
author | Kalyan Prasad Tatavarthi | 2021-02-05 09:52:37 +0000 |
---|---|---|
committer | Kalyan Prasad Tatavarthi | 2021-02-05 10:04:10 +0000 |
commit | 77baaf4bc3d7de436e7b5437a9d677f96293c290 (patch) | |
tree | 48b6dde7e36839da5e3ba84a73c304b9b964a0a9 | |
parent | 7ef049db13e0f8472232b322c00b7d2c5156d599 (diff) | |
download | eclipse.jdt.ui-77baaf4bc3d7de436e7b5437a9d677f96293c290.tar.gz eclipse.jdt.ui-77baaf4bc3d7de436e7b5437a9d677f96293c290.tar.xz eclipse.jdt.ui-77baaf4bc3d7de436e7b5437a9d677f96293c290.zip |
comment to the end of constructor
Change-Id: Ibd02889cadad815c70c8f88f134eff67678be706
Signed-off-by: Kalyan Prasad Tatavarthi <kalyan_prasad@in.ibm.com>
4 files changed, 27 insertions, 7 deletions
diff --git a/org.eclipse.jdt.ui/.settings/.api_filters b/org.eclipse.jdt.ui/.settings/.api_filters index f6bf6a0ca0..aad5889c98 100644 --- a/org.eclipse.jdt.ui/.settings/.api_filters +++ b/org.eclipse.jdt.ui/.settings/.api_filters @@ -539,6 +539,15 @@ </message_arguments> </filter> </resource> + <resource path="ui/org/eclipse/jdt/ui/actions/GenerateNewConstructorUsingFieldsAction.java" type="org.eclipse.jdt.ui.actions.GenerateNewConstructorUsingFieldsAction"> + <filter comment="This is a Java15 preview feature" id="640712815"> + <message_arguments> + <message_argument value="IType"/> + <message_argument value="GenerateNewConstructorUsingFieldsAction"/> + <message_argument value="isRecord()"/> + </message_arguments> + </filter> + </resource> <resource path="ui/org/eclipse/jdt/ui/actions/IJavaEditorActionDefinitionIds.java" type="org.eclipse.jdt.ui.actions.IJavaEditorActionDefinitionIds"> <filter id="571473929"> <message_arguments> diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.java index bc5de306d3..07bad14b89 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.java @@ -220,6 +220,7 @@ public final class ActionMessages extends NLS { public static String GenerateConstructorUsingFieldsAction_tooltip; public static String GenerateConstructorUsingFieldsAction_error_title; public static String GenerateConstructorUsingFieldsAction_not_applicable; + public static String GenerateConstructorUsingFieldsAction_record_not_applicable; public static String GenerateConstructorUsingFieldsAction_fields_selected; public static String GenerateConstructorUsingFieldsAction_error_duplicate_constructor; public static String GenerateConstructorUsingFieldsAction_error_nothing_found; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.properties index f0c2fc3393..05fcac9c5c 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.properties @@ -175,6 +175,7 @@ GenerateConstructorUsingFieldsAction_dialog_label=&Select fields to initialize: GenerateConstructorUsingFieldsAction_interface_not_applicable=The Generate Constructor using Fields operation is not applicable to interfaces. GenerateConstructorUsingFieldsAction_enum_not_applicable=The Generate Constructor using Fields operation is not applicable to enums. GenerateConstructorUsingFieldsAction_annotation_not_applicable=The Generate Constructor using Fields operation is not applicable to annotations. +GenerateConstructorUsingFieldsAction_record_not_applicable=The Generate Constructor using Fields operation is not applicable to records. GenerateConstructorUsingFieldsAction_typeContainsNoFields_message=The selected type contains no fields which may be initialized in a constructor. GenerateConstructorUsingFieldsAction_error_actionfailed=Unexpected error while creating constructors. See log for details. GenerateConstructorUsingFieldsAction_error_anonymous_class=Anonymous classes cannot contain explicitly declared constructors. diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/GenerateNewConstructorUsingFieldsAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/GenerateNewConstructorUsingFieldsAction.java index 7c2b25be1b..c46893868e 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/GenerateNewConstructorUsingFieldsAction.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/GenerateNewConstructorUsingFieldsAction.java @@ -134,7 +134,7 @@ public class GenerateNewConstructorUsingFieldsAction extends SelectionDispatchAc if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) { IType type= (IType) selection.getFirstElement(); - return type.getCompilationUnit() != null && !type.isInterface() && !type.isAnnotation() && !type.isAnonymous(); + return type.getCompilationUnit() != null && !type.isInterface() && !type.isAnnotation() && !type.isAnonymous() && !type.isRecord(); } if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit)) @@ -236,20 +236,27 @@ public class GenerateNewConstructorUsingFieldsAction extends SelectionDispatchAc } Object firstElement= selection.getFirstElement(); + IType typeToProcess= null; if (firstElement instanceof IType) { - run((IType) firstElement, new IField[0], false); + typeToProcess= (IType)firstElement; } else if (firstElement instanceof ICompilationUnit) { - IType type= ((ICompilationUnit) firstElement).findPrimaryType(); - if (type.isAnnotation()) { + typeToProcess= ((ICompilationUnit) firstElement).findPrimaryType(); + } + if (typeToProcess != null) { + if (typeToProcess.isAnnotation()) { MessageDialog.openInformation(getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_annotation_not_applicable); notifyResult(false); return; - } else if (type.isInterface()) { + } else if (typeToProcess.isInterface()) { MessageDialog.openInformation(getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_interface_not_applicable); notifyResult(false); return; + } else if (typeToProcess.isRecord()) { + MessageDialog.openInformation(getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_record_not_applicable); + notifyResult(false); + return; } else - run(((ICompilationUnit) firstElement).findPrimaryType(), new IField[0], false); + run(typeToProcess, new IField[0], false); } } catch (CoreException exception) { ExceptionHandler.handle(exception, getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_error_actionfailed); @@ -273,7 +280,9 @@ public class GenerateNewConstructorUsingFieldsAction extends SelectionDispatchAc if (element != null) { IType type= (IType) element.getAncestor(IJavaElement.TYPE); if (type != null) { - if (type.getFields().length > 0) { + if (type.isRecord()) { + MessageDialog.openInformation(getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_record_not_applicable); + } else if (type.getFields().length > 0) { run(type, new IField[0], true); } else { MessageDialog.openInformation(getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_typeContainsNoFields_message); |