diff --git a/org.eclipse.jdt.junit/META-INF/MANIFEST.MF b/org.eclipse.jdt.junit/META-INF/MANIFEST.MF index b20dd415e9b..f7d8448b227 100644 --- a/org.eclipse.jdt.junit/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.junit/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.junit Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jdt.junit;singleton:=true -Bundle-Version: 3.17.200.qualifier +Bundle-Version: 3.18.0.qualifier Bundle-Activator: org.eclipse.jdt.internal.junit.ui.JUnitPlugin Bundle-ActivationPolicy: lazy Bundle-Vendor: %providerName diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/wizards/NewTestSuiteWizardPage.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/wizards/NewTestSuiteWizardPage.java index 11491ecfc23..14034066e40 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/wizards/NewTestSuiteWizardPage.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/wizards/NewTestSuiteWizardPage.java @@ -380,12 +380,12 @@ private String getUpdatableString() { } @Override - public void createType(IProgressMonitor monitor) throws CoreException, InterruptedException { + public void createTypes(IProgressMonitor monitor) throws CoreException, InterruptedException { IPackageFragment pack= getPackageFragment(); ICompilationUnit cu= pack.getCompilationUnit(getTypeName() + ".java"); //$NON-NLS-1$ if (!cu.exists()) { - super.createType(monitor); + super.createTypes(monitor); fUpdatedExistingClassButton= false; } else { updateExistingType(cu, monitor); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewTypeWizardTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewTypeWizardTest.java index 3b63084094f..358f5867d24 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewTypeWizardTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewTypeWizardTest.java @@ -134,7 +134,7 @@ public void testCreateClass1() throws Exception { wizardPage.enableCommentControl(true); FussyProgressMonitor testMonitor= new FussyProgressMonitor(); - wizardPage.createType(testMonitor); + wizardPage.createTypes(testMonitor); testMonitor.assertUsedUp(); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -176,7 +176,7 @@ public void testCreateClass2() throws Exception { wizardPage.enableCommentControl(true); FussyProgressMonitor testMonitor= new FussyProgressMonitor(); - wizardPage.createType(testMonitor); + wizardPage.createTypes(testMonitor); testMonitor.assertUsedUp(); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -230,7 +230,7 @@ public class A { wizardPage.enableCommentControl(true); FussyProgressMonitor testMonitor= new FussyProgressMonitor(); - wizardPage.createType(testMonitor); + wizardPage.createTypes(testMonitor); testMonitor.assertUsedUp(); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -292,7 +292,7 @@ public class A { wizardPage.enableCommentControl(true); FussyProgressMonitor testMonitor= new FussyProgressMonitor(); - wizardPage.createType(testMonitor); + wizardPage.createTypes(testMonitor); testMonitor.assertUsedUp(); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -362,7 +362,7 @@ public class A { wizardPage.enableCommentControl(true); FussyProgressMonitor testMonitor= new FussyProgressMonitor(); - wizardPage.createType(testMonitor); + wizardPage.createTypes(testMonitor); testMonitor.assertUsedUp(); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -412,7 +412,7 @@ public void testCreateClassExtraImports1() throws Exception { wizardPage.enableCommentControl(true); FussyProgressMonitor testMonitor= new FussyProgressMonitor(); - wizardPage.createType(testMonitor); + wizardPage.createTypes(testMonitor); testMonitor.assertUsedUp(); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -475,7 +475,7 @@ public static class Inner { wizardPage.enableCommentControl(true); FussyProgressMonitor testMonitor= new FussyProgressMonitor(); - wizardPage.createType(testMonitor); + wizardPage.createTypes(testMonitor); testMonitor.assertUsedUp(); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -550,7 +550,7 @@ public class B { wizardPage.enableCommentControl(true); FussyProgressMonitor testMonitor= new FussyProgressMonitor(); - wizardPage.createType(testMonitor); + wizardPage.createTypes(testMonitor); testMonitor.assertUsedUp(); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -601,7 +601,7 @@ public void testCreateInterface() throws Exception { wizardPage.enableCommentControl(true); FussyProgressMonitor testMonitor= new FussyProgressMonitor(); - wizardPage.createType(testMonitor); + wizardPage.createTypes(testMonitor); testMonitor.assertUsedUp(); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -641,7 +641,7 @@ public void testCreateEnum() throws Exception { wizardPage.enableCommentControl(true); FussyProgressMonitor testMonitor= new FussyProgressMonitor(); - wizardPage.createType(testMonitor); + wizardPage.createTypes(testMonitor); testMonitor.assertUsedUp(); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -679,7 +679,7 @@ public void testCreateAnnotation() throws Exception { wizardPage.enableCommentControl(true); FussyProgressMonitor testMonitor= new FussyProgressMonitor(); - wizardPage.createType(testMonitor); + wizardPage.createTypes(testMonitor); testMonitor.assertUsedUp(); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -723,7 +723,7 @@ public void typeBodyTest( NewTypeWizardPage wizardPage, String templateID, Strin wizardPage.enableCommentControl(true); FussyProgressMonitor testMonitor= new FussyProgressMonitor(); - wizardPage.createType(testMonitor); + wizardPage.createTypes(testMonitor); testMonitor.assertUsedUp(); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -835,7 +835,7 @@ public class Foo3 { NewClassWizardPage wizardPage= new NewClassWizardPage(); wizardPage.init(new StructuredSelection(cu)); FussyProgressMonitor testMonitor= new FussyProgressMonitor(); - wizardPage.createType(testMonitor); + wizardPage.createTypes(testMonitor); testMonitor.assertUsedUp(); // Foo3.java can still be unique in test1 diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewTypeWizardTest17.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewTypeWizardTest17.java index ed08713fe11..ef20e7bb069 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewTypeWizardTest17.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewTypeWizardTest17.java @@ -14,8 +14,8 @@ package org.eclipse.jdt.ui.tests.wizardapi; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.util.ArrayList; import java.util.Hashtable; @@ -362,7 +362,7 @@ public void testNonModularCreateClassSuccess1() throws Exception { assertNotNull(status); assertEquals(IStatus.OK, status.getSeverity()); - wizardPage.createType(null); + wizardPage.createTypes(null); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -426,7 +426,7 @@ public void testNonModularCreateClassSuccess2() throws Exception { assertNotNull(status); assertEquals(IStatus.OK, status.getSeverity()); - wizardPage.createType(null); + wizardPage.createTypes(null); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -491,7 +491,7 @@ public void testNonModularCreateClassSuccess3() throws Exception { assertNotNull(status); assertEquals(IStatus.OK, status.getSeverity()); - wizardPage.createType(null); + wizardPage.createTypes(null); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -555,7 +555,7 @@ public void testNonModularCreateClassSuccess4() throws Exception { assertNotNull(status); assertEquals(IStatus.OK, status.getSeverity()); - wizardPage.createType(null); + wizardPage.createTypes(null); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -618,7 +618,7 @@ public void testNonModularCreateInterfaceSuccess1() throws Exception { assertNotNull(status); assertEquals(IStatus.OK, status.getSeverity()); - wizardPage.createType(null); + wizardPage.createTypes(null); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -773,7 +773,7 @@ public void testModularCreateClassSuccess1() throws Exception { assertNotNull(status); assertEquals(IStatus.OK, status.getSeverity()); - wizardPage.createType(null); + wizardPage.createTypes(null); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -844,7 +844,7 @@ public void testModularCreateClassSuccess2() throws Exception { assertNotNull(status); assertEquals(IStatus.OK, status.getSeverity()); - wizardPage.createType(null); + wizardPage.createTypes(null); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -916,7 +916,7 @@ public void testModularCreateClassSuccess3() throws Exception { assertNotNull(status); assertEquals(IStatus.OK, status.getSeverity()); - wizardPage.createType(null); + wizardPage.createTypes(null); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -987,7 +987,7 @@ public void testModularCreateClassSuccess4() throws Exception { assertNotNull(status); assertEquals(IStatus.OK, status.getSeverity()); - wizardPage.createType(null); + wizardPage.createTypes(null); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -1057,7 +1057,7 @@ public void testModularCreateInterfaceSuccess1() throws Exception { assertNotNull(status); assertEquals(IStatus.OK, status.getSeverity()); - wizardPage.createType(null); + wizardPage.createTypes(null); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -1233,7 +1233,7 @@ public void testCreateRecordWithAbstractMethodStubs() throws Exception { wizardPage.setAddComments(true, true); wizardPage.enableCommentControl(true); - wizardPage.createType(null); + wizardPage.createTypes(null); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -1297,7 +1297,7 @@ public void testCreateRecordWithOutAbstractMethodStubsAndMain() throws Exception wizardPage.setAddComments(true, true); wizardPage.enableCommentControl(true); - wizardPage.createType(null); + wizardPage.createTypes(null); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -1337,7 +1337,7 @@ public void testCreateRecordWithMain() throws Exception { wizardPage.setAddComments(true, true); wizardPage.enableCommentControl(true); - wizardPage.createType(null); + wizardPage.createTypes(null); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); @@ -1384,7 +1384,7 @@ public void testCreateRecordWithAbstractMethodStubsAndMain() throws Exception { wizardPage.setAddComments(true, true); wizardPage.enableCommentControl(true); - wizardPage.createType(null); + wizardPage.createTypes(null); String actual= wizardPage.getCreatedType().getCompilationUnit().getSource(); diff --git a/org.eclipse.jdt.ui/.options b/org.eclipse.jdt.ui/.options index 97cbafd2934..ec6397c1afe 100644 --- a/org.eclipse.jdt.ui/.options +++ b/org.eclipse.jdt.ui/.options @@ -29,4 +29,4 @@ org.eclipse.jdt.ui/perf/search/participants=300 org.eclipse.jdt.ui/perf/content_assist/extensions=1000 #Reports the time for a single completion proposal sorter -org.eclipse.jdt.ui/perf/content_assist_sorters/extensions \ No newline at end of file +org.eclipse.jdt.ui/perf/content_assist_sorters/extensions diff --git a/org.eclipse.jdt.ui/META-INF/MANIFEST.MF b/org.eclipse.jdt.ui/META-INF/MANIFEST.MF index 71155ba5bc0..b281165dc63 100644 --- a/org.eclipse.jdt.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.ui/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.ui Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jdt.ui; singleton:=true -Bundle-Version: 3.35.200.qualifier +Bundle-Version: 3.36.0.qualifier Bundle-Activator: org.eclipse.jdt.internal.ui.JavaPlugin Bundle-ActivationPolicy: lazy Bundle-Vendor: %providerName diff --git a/org.eclipse.jdt.ui/pom.xml b/org.eclipse.jdt.ui/pom.xml index fa432d58f4d..c01ac9c2a72 100644 --- a/org.eclipse.jdt.ui/pom.xml +++ b/org.eclipse.jdt.ui/pom.xml @@ -18,7 +18,7 @@ org.eclipse.jdt org.eclipse.jdt.ui - 3.35.200-SNAPSHOT + 3.36.0-SNAPSHOT eclipse-plugin diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/proposals/NewCUUsingWizardProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/proposals/NewCUUsingWizardProposal.java index af81c8a9075..0368daec8c0 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/proposals/NewCUUsingWizardProposal.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/proposals/NewCUUsingWizardProposal.java @@ -317,7 +317,7 @@ public void apply(IDocument document) { wizard.addPages(); try { NewTypeWizardPage page= getPage(wizard); - page.createType(null); + page.createTypes(null); createdType= page.getCreatedType(); } catch (CoreException e) { JavaPlugin.log(e); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewAnnotationCreationWizard.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewAnnotationCreationWizard.java index cee06780cdc..bd5767b9394 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewAnnotationCreationWizard.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewAnnotationCreationWizard.java @@ -67,7 +67,7 @@ protected boolean canRunForked() { @Override protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException { - fPage.createType(monitor); // use the full progress monitor + fPage.createTypes(monitor); // use the full progress monitor } @Override diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewClassCreationWizard.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewClassCreationWizard.java index 3cd9f1ee1ca..b711d6c99b4 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewClassCreationWizard.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewClassCreationWizard.java @@ -65,7 +65,7 @@ protected boolean canRunForked() { @Override protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException { - fPage.createType(monitor); // use the full progress monitor + fPage.createTypes(monitor); // use the full progress monitor } @Override diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewEnumCreationWizard.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewEnumCreationWizard.java index 0dea26d25ea..b5e64a3dfa4 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewEnumCreationWizard.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewEnumCreationWizard.java @@ -64,7 +64,7 @@ protected boolean canRunForked() { @Override protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException { - fPage.createType(monitor); // use the full progress monitor + fPage.createTypes(monitor); // use the full progress monitor } @Override diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewInterfaceCreationWizard.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewInterfaceCreationWizard.java index 90fc241a036..5634f887dda 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewInterfaceCreationWizard.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewInterfaceCreationWizard.java @@ -64,7 +64,7 @@ protected boolean canRunForked() { @Override protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException { - fPage.createType(monitor); // use the full progress monitor + fPage.createTypes(monitor); // use the full progress monitor } @Override diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewRecordCreationWizard.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewRecordCreationWizard.java index 1556d9a7f3c..5eba63a502a 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewRecordCreationWizard.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewRecordCreationWizard.java @@ -65,7 +65,7 @@ protected boolean canRunForked() { @Override protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException { - fPage.createType(monitor); // use the full progress monitor + fPage.createTypes(monitor); // use the full progress monitor } @Override diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java index d9d6b978e98..f03f36f1e70 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java @@ -965,6 +965,8 @@ private NewWizardMessages() { public static String NewModuleInfoWizardPage_warning_DiscouragedModuleName; public static String NewModuleInfoWizardPage_error_EnterName; + public static String NewTypeWizardPage_info_CreateMultipleTypes; + public static String ReleaseAttributeConfiguration_defaultReleaseName; public static String ReleaseAttributeConfiguration_dialogTitle; public static String ReleaseAttributeConfiguration_nameLabel; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties index 8f1baea7820..f2e8b698aea 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties @@ -140,6 +140,8 @@ NewTypeWizardPage_error_QualifiedName=Type name must not be qualified. NewTypeWizardPage_info_FileExtensionNotRequired=The file extension '.java' will not be part of the type name. NewTypeWizardPage_warning_TypeNameDiscouraged=Type name is discouraged. {0} +NewTypeWizardPage_info_CreateMultipleTypes=Values separated by semicolons will create multiple types. + NewTypeWizardPage_error_InvalidSuperClassName=Superclass type is not valid. NewTypeWizardPage_error_InvalidSuperInterfaceName=Extended interface ''{0}'' is not valid. NewTypeWizardPage_error_InvalidSuperClassRecord=Record ''{0}'' cannot be superclass. A record is final. diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewTypeWizardPage.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewTypeWizardPage.java index df62e9e18d5..b777cce9578 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewTypeWizardPage.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewTypeWizardPage.java @@ -12,6 +12,7 @@ * IBM Corporation - initial API and implementation * John Kaplan, johnkaplantech@gmail.com - 108071 [code templates] template for body of newly created class * Microsoft Corporation - [templates][content assist] - Extract the UI related code - https://bugs.eclipse.org/549989 + * Alex Coover, alexcoover@live.com - [wizard] - Added support for multiple type creation - https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/1251 *******************************************************************************/ package org.eclipse.jdt.ui.wizards; @@ -860,7 +861,16 @@ private static IStatus validateJavaTypeName(String text, IJavaProject project) { if (project == null || !project.exists()) { return JavaConventions.validateJavaTypeName(text, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8, null); } - return JavaConventionsUtil.validateJavaTypeName(text, project); + + String[] typeNamesGroup = text.split(";"); //$NON-NLS-1$ + + IStatus typeNamesStatus = JavaConventionsUtil.validateJavaTypeName(typeNamesGroup[0].trim(), project); + + for (String typeName : typeNamesGroup) { + typeNamesStatus = JavaConventionsUtil.validateJavaTypeName(typeName.trim(), project); + if (!typeNamesStatus.isOK()) return typeNamesStatus; + } + return typeNamesStatus; } private static IStatus validatePackageName(String text, IJavaProject project) { @@ -1817,7 +1827,8 @@ public IResource getModifiedResource() { } IPackageFragment pack= getPackageFragment(); if (pack != null) { - String cuName= getCompilationUnitName(getTypeNameWithoutParameters()); + String[] typeNames= getTypeNameWithoutParameters().split(";"); //$NON-NLS-1$ + String cuName= getCompilationUnitName(typeNames[0]); return pack.getCompilationUnit(cuName).getResource(); } return null; @@ -2080,80 +2091,93 @@ protected IStatus typeNameChanged() { return status; } + if (typeNameWithExtension.indexOf(';') != -1) { + status.setInfo(NewWizardMessages.NewTypeWizardPage_info_CreateMultipleTypes); + } + if (typeNameWithExtension.endsWith(JavaModelUtil.DEFAULT_CU_SUFFIX)) { status.setInfo(NewWizardMessages.NewTypeWizardPage_info_FileExtensionNotRequired); } - String typeNameWithParameters= getTypeName(); - String typeName= getTypeNameWithoutParameters(); - if (typeName.indexOf('.') != -1) { - status.setError(NewWizardMessages.NewTypeWizardPage_error_QualifiedName); - return status; - } - IJavaProject project= getJavaProject(); - IStatus val= validateJavaTypeName(typeName, project); - if (val.getSeverity() == IStatus.ERROR) { - status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, val.getMessage())); - return status; - } else if (val.getSeverity() == IStatus.WARNING) { - status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_TypeNameDiscouraged, val.getMessage())); - // continue checking - } + String typeNameGroup= getTypeName(); - // must not exist - if (!isEnclosingTypeSelected()) { - IPackageFragment pack= getPackageFragment(); - if (pack != null) { - ICompilationUnit cu= pack.getCompilationUnit(getCompilationUnitName(typeName)); - fCurrType= cu.getType(typeName); - IResource resource= cu.getResource(); + String[] typesArray = typeNameGroup.split(";"); //$NON-NLS-1$ + for (String typeNameChild : typesArray) { - if (resource.exists()) { - status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists); - return status; - } - if (!ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) { - status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameFiltered); - return status; - } - URI location= resource.getLocationURI(); - if (location != null) { - try { - IFileStore store= EFS.getStore(location); - if (store.fetchInfo().exists()) { - status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExistsDifferentCase); - return status; + String typeName = getTypeNameWithoutParameters(typeNameChild.trim()); + + String typeNameWithParameters= typeNameChild; + + if (typeName.indexOf('.') != -1) { + status.setError(NewWizardMessages.NewTypeWizardPage_error_QualifiedName); + return status; + } + + IJavaProject project= getJavaProject(); + IStatus val= validateJavaTypeName(typeName, project); + if (val.getSeverity() == IStatus.ERROR) { + status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, val.getMessage())); + return status; + } else if (val.getSeverity() == IStatus.WARNING) { + status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_TypeNameDiscouraged, val.getMessage())); + // continue checking + } + + // must not exist + if (!isEnclosingTypeSelected()) { + IPackageFragment pack= getPackageFragment(); + if (pack != null) { + ICompilationUnit cu= pack.getCompilationUnit(getCompilationUnitName(typeName)); + fCurrType= cu.getType(typeName); + IResource resource= cu.getResource(); + + if (resource.exists()) { + status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists); + return status; + } + if (!ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) { + status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameFiltered); + return status; + } + URI location= resource.getLocationURI(); + if (location != null) { + try { + IFileStore store= EFS.getStore(location); + if (store.fetchInfo().exists()) { + status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExistsDifferentCase); + return status; + } + } catch (CoreException e) { + status.setError(Messages.format( + NewWizardMessages.NewTypeWizardPage_error_uri_location_unkown, + BasicElementLabels.getURLPart(Resources.getLocationString(resource)))); } - } catch (CoreException e) { - status.setError(Messages.format( - NewWizardMessages.NewTypeWizardPage_error_uri_location_unkown, - BasicElementLabels.getURLPart(Resources.getLocationString(resource)))); } } - } - } else { - IType type= getEnclosingType(); - if (type != null) { - fCurrType= type.getType(typeName); - if (fCurrType.exists()) { - status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists); - return status; + } else { + IType type= getEnclosingType(); + if (type != null) { + fCurrType= type.getType(typeName); + if (fCurrType.exists()) { + status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists); + return status; + } } } - } - if (!typeNameWithParameters.equals(typeName) && project != null) { - String typeDeclaration= "class " + typeNameWithParameters + " {}"; //$NON-NLS-1$//$NON-NLS-2$ - ASTParser parser= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL); - parser.setSource(typeDeclaration.toCharArray()); - parser.setProject(project); - CompilationUnit compilationUnit= (CompilationUnit) parser.createAST(null); - IProblem[] problems= compilationUnit.getProblems(); - if (problems.length > 0) { - status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, problems[0].getMessage())); - return status; + if (!typeNameWithParameters.equals(typeName) && project != null) { + String typeDeclaration= "class " + typeNameWithParameters + " {}"; //$NON-NLS-1$//$NON-NLS-2$ + ASTParser parser= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL); + parser.setSource(typeDeclaration.toCharArray()); + parser.setProject(project); + CompilationUnit compilationUnit= (CompilationUnit) parser.createAST(null); + IProblem[] problems= compilationUnit.getProblems(); + if (problems.length > 0) { + status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, problems[0].getMessage())); + return status; + } } } return status; @@ -2699,13 +2723,226 @@ private String getInterfaceDialogTitle() { // ---- creation ---------------- + /** - * Creates the new type using the entered field values. + * Handles multiple types using the entered field values. * + * @since 3.36 * @param monitor a progress monitor to report progress. * @throws CoreException Thrown when the creation failed. * @throws InterruptedException Thrown when the operation was canceled. */ + public void createTypes(IProgressMonitor monitor) throws CoreException, InterruptedException { + String[] names = getTypeName().split(";"); //$NON-NLS-1$ + SubMonitor subMonitor = SubMonitor.convert(monitor, names.length); + + for (String name : names) { + String typeName = name; + + if (typeName.isEmpty()) continue; + createType(subMonitor.split(1), typeName); + } + } + + /** + * Creates the new type using the passed type name. + * + * @since 3.36 + * @param monitor a progress monitor to report progress. + * @param name the type name. + * @throws CoreException Thrown when the creation failed. + * @throws InterruptedException Thrown when the operation was canceled. + */ + public void createType(IProgressMonitor monitor, String name) throws CoreException, InterruptedException { + if (monitor == null) { + monitor= new NullProgressMonitor(); + } + + monitor.beginTask(NewWizardMessages.NewTypeWizardPage_operationdesc, 8); + + IPackageFragmentRoot root= getPackageFragmentRoot(); + IPackageFragment pack= getPackageFragment(); + if (pack == null) { + pack= root.getPackageFragment(""); //$NON-NLS-1$ + } + + if (!pack.exists()) { + String packName= pack.getElementName(); + pack= root.createPackageFragment(packName, true, Progress.subMonitor(monitor, 1)); + } else { + monitor.worked(1); + } + + boolean needsSave; + ICompilationUnit connectedCU= null; + + String typeNameWithParameters = name.trim(); + + String typeName = getTypeNameWithoutParameters(typeNameWithParameters); + + try { + boolean isInnerClass= isEnclosingTypeSelected(); + + IType createdType; + ImportsManager imports; + int indent= 0; + + Set existingImports; + + String lineDelimiter= null; + if (!isInnerClass) { + lineDelimiter= StubUtility.getLineDelimiterUsed(pack.getJavaProject()); + + String cuName= getCompilationUnitName(typeName); + ICompilationUnit parentCU= pack.createCompilationUnit(cuName, "", false, Progress.subMonitor(monitor, 2)); //$NON-NLS-1$ + // create a working copy with a new owner + + needsSave= true; + parentCU.becomeWorkingCopy(Progress.subMonitor(monitor, 1)); // cu is now a (primary) working copy + connectedCU= parentCU; + + IBuffer buffer= parentCU.getBuffer(); + + String simpleTypeStub= constructSimpleTypeStub(typeNameWithParameters); + String cuContent= constructCUContent(parentCU, simpleTypeStub, lineDelimiter); + buffer.setContents(cuContent); + + CompilationUnit astRoot= createASTForImports(parentCU); + existingImports= getExistingImports(astRoot); + + imports= new ImportsManager(astRoot); + // add an import that will be removed again. Having this import solves 14661 + imports.addImport(JavaModelUtil.concatenateName(pack.getElementName(), typeName)); + + String typeContent= constructTypeStub(parentCU, imports, lineDelimiter, typeNameWithParameters); + + int index= cuContent.lastIndexOf(simpleTypeStub); + if (index == -1) { + AbstractTypeDeclaration typeNode= (AbstractTypeDeclaration) astRoot.types().get(0); + int start= ((ASTNode) typeNode.modifiers().get(0)).getStartPosition(); + int end= typeNode.getStartPosition() + typeNode.getLength(); + buffer.replace(start, end - start, typeContent); + } else { + buffer.replace(index, simpleTypeStub.length(), typeContent); + } + + createdType= parentCU.getType(typeName); + } else { + IType enclosingType= getEnclosingType(); + + ICompilationUnit parentCU= enclosingType.getCompilationUnit(); + + needsSave= !parentCU.isWorkingCopy(); + parentCU.becomeWorkingCopy(Progress.subMonitor(monitor, 1)); // cu is now for sure (primary) a working copy + connectedCU= parentCU; + + CompilationUnit astRoot= createASTForImports(parentCU); + imports= new ImportsManager(astRoot); + existingImports= getExistingImports(astRoot); + + + // add imports that will be removed again. Having the imports solves 14661 + for (IType topLevelType : parentCU.getTypes()) { + imports.addImport(topLevelType.getFullyQualifiedName('.')); + } + + lineDelimiter= StubUtility.getLineDelimiterUsed(enclosingType); + StringBuilder content= new StringBuilder(); + + String comment= getTypeComment(parentCU, lineDelimiter); + if (comment != null) { + content.append(comment); + content.append(lineDelimiter); + } + + content.append(constructTypeStub(parentCU, imports, lineDelimiter, typeNameWithParameters)); + IJavaElement sibling= null; + if (enclosingType.isEnum()) { + IField[] fields = enclosingType.getFields(); + if (fields.length > 0) { + for (IField field : fields) { + if (!field.isEnumConstant()) { + sibling = field; + break; + } + } + } + } else { + IJavaElement[] elems= enclosingType.getChildren(); + sibling = elems.length > 0 ? elems[0] : null; + } + + createdType= enclosingType.createType(content.toString(), sibling, false, Progress.subMonitor(monitor, 2)); + + indent= StubUtility.getIndentUsed(enclosingType) + 1; + } + if (monitor.isCanceled()) { + throw new InterruptedException(); + } + + // add imports for superclass/interfaces, so types can be resolved correctly + + ICompilationUnit cu= createdType.getCompilationUnit(); + + imports.create(false, Progress.subMonitor(monitor, 1)); + + JavaModelUtil.reconcile(cu); + + if (monitor.isCanceled()) { + throw new InterruptedException(); + } + + // set up again + CompilationUnit astRoot= createASTForImports(imports.getCompilationUnit()); + imports= new ImportsManager(astRoot); + + createTypeMembers(createdType, imports, Progress.subMonitor(monitor, 1)); + + // add imports + imports.create(false, Progress.subMonitor(monitor, 1)); + + removeUnusedImports(cu, existingImports, false); + + JavaModelUtil.reconcile(cu); + + ISourceRange range= createdType.getSourceRange(); + + IBuffer buf= cu.getBuffer(); + String originalContent= buf.getText(range.getOffset(), range.getLength()); + + String formattedContent= CodeFormatterUtil.format(CodeFormatter.K_CLASS_BODY_DECLARATIONS, originalContent, indent, lineDelimiter, + FormatterProfileManager.getProjectSettings(pack.getJavaProject())); + formattedContent= Strings.trimLeadingTabsAndSpaces(formattedContent); + buf.replace(range.getOffset(), range.getLength(), formattedContent); + if (!isInnerClass) { + String fileComment= getFileComment(cu); + if (fileComment != null && fileComment.length() > 0) { + buf.replace(0, 0, fileComment + lineDelimiter); + } + } + fCreatedType= createdType; + + if (needsSave) { + cu.commitWorkingCopy(true, Progress.subMonitor(monitor, 1)); + } else { + monitor.worked(1); + } + + updateSealedSuperTypes(); + + } finally { + if (connectedCU != null) { + connectedCU.discardWorkingCopy(); + } + monitor.done(); + } + } + + + /** + * @deprecated Use {@link #createTypes(IProgressMonitor)} instead. + */ + @Deprecated public void createType(IProgressMonitor monitor) throws CoreException, InterruptedException { if (monitor == null) { monitor= new NullProgressMonitor(); @@ -3052,7 +3289,6 @@ private void writeSuperInterfaces(StringBuffer buf, ImportsManager imports) { } } - private String constructSimpleTypeStub() { StringBuilder buf= new StringBuilder("public class "); //$NON-NLS-1$ buf.append(getTypeName()); @@ -3060,6 +3296,82 @@ private String constructSimpleTypeStub() { return buf.toString(); } + /** + * Constructs the type stub using the provided type name. + * + * @param typeName the name of the type to use in the stub + * @return the generated type stub as a string + * @since 3.36.0 + */ + private String constructSimpleTypeStub(String typeName) { + StringBuilder buf= new StringBuilder("public class "); //$NON-NLS-1$ + buf.append(typeName); + buf.append("{ }"); //$NON-NLS-1$ + return buf.toString(); + } + + /** + * Constructs the type stub source for the given type name. + * + * @param parentCU the parent compilation unit + * @param imports the imports manager to use + * @param lineDelimiter the line delimiter to use + * @param typeName the name of the type to generate + * @return the generated source code for the type stub + * @throws CoreException if an error occurs while generating the stub + * @since 3.36.0 + */ + private String constructTypeStub(ICompilationUnit parentCU, ImportsManager imports, String lineDelimiter, String typeName) throws CoreException { + StringBuffer buf= new StringBuffer(); + + int modifiers= getModifiers(); + buf.append(Flags.toString(modifiers)); + if (modifiers != 0) { + buf.append(' '); + } + String type= ""; //$NON-NLS-1$ + String templateID= ""; //$NON-NLS-1$ + switch (fTypeKind) { + case CLASS_TYPE: + type= "class "; //$NON-NLS-1$ + templateID= CodeGeneration.CLASS_BODY_TEMPLATE_ID; + break; + case INTERFACE_TYPE: + type= "interface "; //$NON-NLS-1$ + templateID= CodeGeneration.INTERFACE_BODY_TEMPLATE_ID; + break; + case ENUM_TYPE: + type= "enum "; //$NON-NLS-1$ + templateID= CodeGeneration.ENUM_BODY_TEMPLATE_ID; + break; + case ANNOTATION_TYPE: + type= "@interface "; //$NON-NLS-1$ + templateID= CodeGeneration.ANNOTATION_BODY_TEMPLATE_ID; + break; + case RECORD_TYPE: + type= "record "; //$NON-NLS-1$ + templateID= CodeGeneration.RECORD_BODY_TEMPLATE_ID; + break; + } + buf.append(type); + buf.append(typeName); + if (fTypeKind == RECORD_TYPE) { + buf.append("()"); //$NON-NLS-1$ + } + writeSuperClass(buf, imports); + writeSuperInterfaces(buf, imports); + + buf.append(" {").append(lineDelimiter); //$NON-NLS-1$ + String typeBody= CodeGeneration.getTypeBody(templateID, parentCU, getTypeName(), lineDelimiter); + if (typeBody != null) { + buf.append(typeBody); + } else { + buf.append(lineDelimiter); + } + buf.append('}').append(lineDelimiter); + return buf.toString(); + } + /* * Called from createType to construct the source for this type */ @@ -3483,7 +3795,7 @@ public IRunnableWithProgress getRunnable() { if (monitor == null) { monitor= new NullProgressMonitor(); } - createType(monitor); + createTypes(monitor); } catch (CoreException e) { throw new InvocationTargetException(e); }