View | Details | Raw Unified | Return to bug 488748 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.ui/plugin.properties (+5 lines)
Lines 499-504 Link Here
499
GenerateJavadocAction.label= &Generate Javadoc...
499
GenerateJavadocAction.label= &Generate Javadoc...
500
500
501
##########################################################################
501
##########################################################################
502
# Module Support
503
##########################################################################
504
create.module.info.label= Create module-info.java
505
506
##########################################################################
502
# Java Working Set Support
507
# Java Working Set Support
503
##########################################################################
508
##########################################################################
504
JavaWorkingSetPage.name= Java
509
JavaWorkingSetPage.name= Java
(-)a/org.eclipse.jdt.ui/plugin.xml (+25 lines)
Lines 6932-6935 Link Here
6932
        </activeWhen>
6932
        </activeWhen>
6933
     </projectConfigurator>
6933
     </projectConfigurator>
6934
  </extension>
6934
  </extension>
6935
  <extension
6936
        point="org.eclipse.ui.popupMenus">
6937
      <objectContribution
6938
            objectClass="org.eclipse.core.resources.IProject"
6939
            adaptable="true"
6940
            id="org.eclipse.jdt.ui.create.module.info">
6941
       	 <visibility>
6942
        	<and>
6943
            <objectState 
6944
	            name="projectNature" 
6945
	            value="org.eclipse.jdt.core.javanature"/>
6946
	        <objectState
6947
	        	name="open"
6948
	        	value="true"/>
6949
            </and>
6950
       	 </visibility>
6951
         <action
6952
            label="%create.module.info.label"
6953
            class="org.eclipse.jdt.internal.ui.actions.CreateModuleInfoAction"
6954
            menubarPath="org.eclipse.ui.projectConfigure/additions"
6955
            enablesFor="1"
6956
            id="org.eclipse.jdt.ui.create.module.info.action">
6957
      	</action>
6958
      </objectContribution>
6959
  </extension>
6935
</plugin>
6960
</plugin>
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.java (-1 / +10 lines)
Lines 1-9 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2015 IBM Corporation and others.
2
 * Copyright (c) 2000, 2016 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
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
Lines 432-437 Link Here
432
	public static String CollapsAllAction_tooltip;
436
	public static String CollapsAllAction_tooltip;
433
	public static String CollapsAllAction_description;
437
	public static String CollapsAllAction_description;
434
438
439
	public static String CreateModuleInfoAction_error_message_compliance;
440
	public static String CreateModuleInfoAction_error_message_no_source_folder;
441
	public static String CreateModuleInfoAction_error_title;
442
	public static String CreateModuleInfoAction_question_message_overwrite_module_info;
443
435
	public static String GenerateToStringAction_label;
444
	public static String GenerateToStringAction_label;
436
	public static String GenerateToStringAction_description;
445
	public static String GenerateToStringAction_description;
437
	public static String GenerateToStringAction_tooltip;
446
	public static String GenerateToStringAction_tooltip;
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.properties (-1 / +10 lines)
Lines 1-9 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2013 IBM Corporation and others.
2
# Copyright (c) 2000, 2016 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
6
# http://www.eclipse.org/legal/epl-v10.html
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# This is an implementation of an early-draft specification developed under the Java
9
# Community Process (JCP) and is made available for testing and evaluation purposes
10
# only. The code is not compatible with any specification of the JCP.
7
#
11
#
8
# Contributors:
12
# Contributors:
9
#     IBM Corporation - initial API and implementation
13
#     IBM Corporation - initial API and implementation
Lines 461-466 Link Here
461
CollapsAllAction_tooltip= Collapse All
465
CollapsAllAction_tooltip= Collapse All
462
CollapsAllAction_description= Collapse All
466
CollapsAllAction_description= Collapse All
463
467
468
CreateModuleInfoAction_error_message_compliance=Project requires compliance level of 9 or above.
469
CreateModuleInfoAction_error_message_no_source_folder=No source folder exists in the project.
470
CreateModuleInfoAction_error_title=Create module-info.java
471
CreateModuleInfoAction_question_message_overwrite_module_info=The module-info.java file already exists in the source folder ''{0}''. Do you want to overwrite it?
472
464
473
465
# DO NOT REMOVE, used in a product, see https://bugs.eclipse.org/296836
474
# DO NOT REMOVE, used in a product, see https://bugs.eclipse.org/296836
466
OrganizeImportsAction_summary_added={0} import(s) added.
475
OrganizeImportsAction_summary_added={0} import(s) added.
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/CreateModuleInfoAction.java (+212 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2016 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 * 
12
 * Contributors:
13
 *     IBM Corporation - initial API and implementation
14
 *******************************************************************************/
15
package org.eclipse.jdt.internal.ui.actions;
16
17
import java.util.ArrayList;
18
import java.util.Arrays;
19
import java.util.List;
20
21
import org.eclipse.swt.widgets.Display;
22
23
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.NullProgressMonitor;
25
26
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.resources.IFolder;
28
import org.eclipse.core.resources.IProject;
29
import org.eclipse.core.resources.IResource;
30
31
import org.eclipse.jface.action.IAction;
32
import org.eclipse.jface.dialogs.MessageDialog;
33
import org.eclipse.jface.viewers.ISelection;
34
import org.eclipse.jface.viewers.IStructuredSelection;
35
36
import org.eclipse.ui.IObjectActionDelegate;
37
import org.eclipse.ui.IWorkbenchPage;
38
import org.eclipse.ui.IWorkbenchPart;
39
import org.eclipse.ui.PartInitException;
40
import org.eclipse.ui.ide.IDE;
41
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
42
43
import org.eclipse.jdt.core.IJavaProject;
44
import org.eclipse.jdt.core.IModuleDescription;
45
import org.eclipse.jdt.core.IModuleDescription.IModuleReference;
46
import org.eclipse.jdt.core.IModuleDescription.IPackageExport;
47
import org.eclipse.jdt.core.IPackageFragment;
48
import org.eclipse.jdt.core.IPackageFragmentRoot;
49
import org.eclipse.jdt.core.JavaCore;
50
51
import org.eclipse.jdt.internal.corext.util.InfoFilesUtil;
52
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
53
import org.eclipse.jdt.internal.corext.util.Messages;
54
55
import org.eclipse.jdt.internal.ui.JavaPlugin;
56
57
public class CreateModuleInfoAction implements IObjectActionDelegate {
58
59
	private static final String MODULE_INFO_JAVA_FILENAME= JavaModelUtil.MODULE_INFO_JAVA;
60
61
	private ISelection fSelection;
62
63
	@Override
64
	public void selectionChanged(IAction action, ISelection selection) {
65
		fSelection= selection;
66
	}
67
68
	@Override
69
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
70
		// not used
71
	}
72
73
	@Override
74
	public void run(IAction action) {
75
		IJavaProject javaProject= null;
76
77
		if (fSelection instanceof IStructuredSelection) {
78
			Object selectedElement= ((IStructuredSelection) fSelection).getFirstElement();
79
80
			if (selectedElement instanceof IProject) {
81
				javaProject= JavaCore.create((IProject) selectedElement);
82
			} else if (selectedElement instanceof IJavaProject) {
83
				javaProject= (IJavaProject) selectedElement;
84
			} else {
85
				return;
86
			}
87
88
			try {
89
				if (!JavaModelUtil.is9OrHigher(javaProject)) {
90
					MessageDialog.openError(getDisplay().getActiveShell(), ActionMessages.CreateModuleInfoAction_error_title, ActionMessages.CreateModuleInfoAction_error_message_compliance);
91
					return;
92
				}
93
94
				IPackageFragmentRoot[] packageFragmentRoots= javaProject.getPackageFragmentRoots();
95
				List<IPackageFragmentRoot> packageFragmentRootsAsList= new ArrayList<>(Arrays.asList(packageFragmentRoots));
96
				for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) {
97
					IResource res= packageFragmentRoot.getCorrespondingResource();
98
					if (res == null || res.getType() != IResource.FOLDER || packageFragmentRoot.getKind() != IPackageFragmentRoot.K_SOURCE) {
99
						packageFragmentRootsAsList.remove(packageFragmentRoot);
100
					}
101
				}
102
				packageFragmentRoots= packageFragmentRootsAsList.toArray(new IPackageFragmentRoot[packageFragmentRootsAsList.size()]);
103
104
				if (packageFragmentRoots.length == 0) {
105
					MessageDialog.openError(getDisplay().getActiveShell(), ActionMessages.CreateModuleInfoAction_error_title, ActionMessages.CreateModuleInfoAction_error_message_no_source_folder);
106
					return;
107
				}
108
109
				IPackageFragmentRoot targetPkgFragmentRoot= null;
110
111
				for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) {
112
					if (packageFragmentRoot.getPackageFragment("").getCompilationUnit(MODULE_INFO_JAVA_FILENAME).exists()) { //$NON-NLS-1$
113
						String message= Messages.format(ActionMessages.CreateModuleInfoAction_question_message_overwrite_module_info, packageFragmentRoot.getElementName());
114
						boolean overwrite= MessageDialog.openQuestion(getDisplay().getActiveShell(), ActionMessages.CreateModuleInfoAction_error_title, message);
115
						if (!overwrite) {
116
							return;
117
						}
118
						targetPkgFragmentRoot= packageFragmentRoot;
119
						break;
120
					}
121
				}
122
123
				if (targetPkgFragmentRoot == null) {
124
					targetPkgFragmentRoot= packageFragmentRoots[0];
125
				}
126
127
				createAndOpenFile(targetPkgFragmentRoot);
128
129
			} catch (CoreException e) {
130
				JavaPlugin.log(e);
131
			}
132
		}
133
	}
134
135
	private void createAndOpenFile(IPackageFragmentRoot pkgFragmentRoot) throws CoreException {
136
		createModuleInfoJava(pkgFragmentRoot);
137
138
		IFile file= ((IFolder) pkgFragmentRoot.getCorrespondingResource()).getFile(MODULE_INFO_JAVA_FILENAME);
139
		if (file.exists()) {
140
			BasicNewResourceWizard.selectAndReveal(file, JavaPlugin.getActiveWorkbenchWindow());
141
			openFile(file);
142
		}
143
	}
144
145
	private void createModuleInfoJava(IPackageFragmentRoot pkgFragmentRoot) throws CoreException {
146
		IModuleDescription module = JavaCore.createModuleFromPackageRoot(null, pkgFragmentRoot.getJavaProject());
147
		if (module != null) {
148
			StringBuilder fileContent= new StringBuilder();
149
			fileContent.append("module "); //$NON-NLS-1$
150
			fileContent.append(module.getElementName());
151
			fileContent.append(" {"); //$NON-NLS-1$
152
			fileContent.append('\n');
153
			IPackageExport[] exportedPackages= module.getExportedPackages();
154
			for (IPackageExport iPackageExport : exportedPackages) {
155
				fileContent.append('\t');
156
				fileContent.append("exports "); //$NON-NLS-1$
157
				fileContent.append(iPackageExport.getPackageName());
158
				String[] targets = iPackageExport.getTargetModules();
159
				if (targets != null && targets.length > 0) {
160
					fileContent.append(" to "); //$NON-NLS-1$
161
				}
162
				for (int i= 0; i < targets.length; i++) {
163
					fileContent.append(targets[i]);
164
					if (i < targets.length - 1) {
165
						fileContent.append(',');
166
					}
167
				}
168
				fileContent.append(";\n"); //$NON-NLS-1$
169
			}
170
			IModuleReference[] requiredModules= module.getRequiredModules();
171
			for (IModuleReference iModuleReference : requiredModules) {
172
				fileContent.append('\t');
173
				fileContent.append("requires "); //$NON-NLS-1$
174
				if (iModuleReference.isPublic()) {
175
					fileContent.append("public "); //$NON-NLS-1$
176
				}
177
				fileContent.append(iModuleReference.getModuleName());
178
				fileContent.append(';');
179
				fileContent.append('\n');
180
			}
181
			fileContent.append('}');
182
			IPackageFragment defaultPkg= pkgFragmentRoot.getPackageFragment(""); //$NON-NLS-1$
183
			InfoFilesUtil.createInfoJavaFile(MODULE_INFO_JAVA_FILENAME, fileContent.toString(), defaultPkg, new NullProgressMonitor());
184
		}
185
	}
186
187
	private void openFile(final IFile file) {
188
		final IWorkbenchPage activePage= JavaPlugin.getActivePage();
189
		if (activePage != null) {
190
			final Display display= getDisplay();
191
			if (display != null) {
192
				display.asyncExec(new Runnable() {
193
					@Override
194
					public void run() {
195
						try {
196
							IDE.openEditor(activePage, file, true);
197
						} catch (PartInitException e) {
198
							JavaPlugin.log(e);
199
						}
200
					}
201
				});
202
			}
203
		}
204
	}
205
206
	private Display getDisplay() {
207
		Display display= Display.getCurrent();
208
		if (display == null)
209
			display= Display.getDefault();
210
		return display;
211
	}
212
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewSourceFolderCreationWizard.java (-15 / +2 lines)
Lines 1-13 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2016 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 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
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 *
7
 *
12
 * Contributors:
8
 * Contributors:
13
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
Lines 17-28 Link Here
17
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IProgressMonitor;
19
15
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IResource;
22
23
import org.eclipse.jdt.core.IJavaElement;
16
import org.eclipse.jdt.core.IJavaElement;
24
25
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
26
17
27
import org.eclipse.jdt.internal.ui.JavaPlugin;
18
import org.eclipse.jdt.internal.ui.JavaPlugin;
28
import org.eclipse.jdt.internal.ui.JavaPluginImages;
19
import org.eclipse.jdt.internal.ui.JavaPluginImages;
Lines 59-69 Link Here
59
	public boolean performFinish() {
50
	public boolean performFinish() {
60
		boolean res= super.performFinish();
51
		boolean res= super.performFinish();
61
		if (res) {
52
		if (res) {
62
			IResource resource= fPage.getCorrespondingResource();
53
			selectAndReveal(fPage.getCorrespondingResource());
63
			selectAndReveal(resource);
64
			if (resource instanceof IFile && resource.getName().equals(JavaModelUtil.MODULE_INFO_JAVA)) {
65
				openResource((IFile) resource);
66
			}
67
		}
54
		}
68
		return res;
55
		return res;
69
	}
56
	}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewSourceFolderWizardPage.java (-104 / +23 lines)
Lines 1-13 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2016 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 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
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 *
7
 *
12
 * Contributors:
8
 * Contributors:
13
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
Lines 44-50 Link Here
44
import org.eclipse.core.resources.ResourcesPlugin;
40
import org.eclipse.core.resources.ResourcesPlugin;
45
41
46
import org.eclipse.jface.dialogs.Dialog;
42
import org.eclipse.jface.dialogs.Dialog;
47
import org.eclipse.jface.dialogs.IDialogSettings;
48
import org.eclipse.jface.util.BidiUtils;
43
import org.eclipse.jface.util.BidiUtils;
49
import org.eclipse.jface.viewers.ILabelProvider;
44
import org.eclipse.jface.viewers.ILabelProvider;
50
import org.eclipse.jface.viewers.IStructuredSelection;
45
import org.eclipse.jface.viewers.IStructuredSelection;
Lines 65-77 Link Here
65
import org.eclipse.jdt.core.IJavaElement;
60
import org.eclipse.jdt.core.IJavaElement;
66
import org.eclipse.jdt.core.IJavaModelStatus;
61
import org.eclipse.jdt.core.IJavaModelStatus;
67
import org.eclipse.jdt.core.IJavaProject;
62
import org.eclipse.jdt.core.IJavaProject;
68
import org.eclipse.jdt.core.IPackageFragment;
69
import org.eclipse.jdt.core.IPackageFragmentRoot;
63
import org.eclipse.jdt.core.IPackageFragmentRoot;
70
import org.eclipse.jdt.core.JavaConventions;
64
import org.eclipse.jdt.core.JavaConventions;
71
import org.eclipse.jdt.core.JavaCore;
65
import org.eclipse.jdt.core.JavaCore;
72
import org.eclipse.jdt.core.JavaModelException;
66
import org.eclipse.jdt.core.JavaModelException;
73
67
74
import org.eclipse.jdt.internal.corext.util.InfoFilesUtil;
75
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
68
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
76
import org.eclipse.jdt.internal.corext.util.Messages;
69
import org.eclipse.jdt.internal.corext.util.Messages;
77
70
Lines 107-116 Link Here
107
100
108
	private SelectionButtonDialogField fExcludeInOthersFields;
101
	private SelectionButtonDialogField fExcludeInOthersFields;
109
	private SelectionButtonDialogField fIgnoreOptionalProblemsField;
102
	private SelectionButtonDialogField fIgnoreOptionalProblemsField;
110
	private SelectionButtonDialogField fCreateModuleInfoJavaField;
111
112
	private static final String MODULE_INFO_JAVA_FILENAME= JavaModelUtil.MODULE_INFO_JAVA;
113
	private static final String SETTINGS_CREATE_MODULE_INFO_JAVA= "create_module_info_java"; //$NON-NLS-1$
114
103
115
	private IWorkspaceRoot fWorkspaceRoot;
104
	private IWorkspaceRoot fWorkspaceRoot;
116
105
Lines 155-165 Link Here
155
		fIgnoreOptionalProblemsField.setLabelText(NewWizardMessages.NewSourceFolderWizardPage_ignore_optional_problems_label);
144
		fIgnoreOptionalProblemsField.setLabelText(NewWizardMessages.NewSourceFolderWizardPage_ignore_optional_problems_label);
156
		fIgnoreOptionalProblemsField.setSelection(false);
145
		fIgnoreOptionalProblemsField.setSelection(false);
157
146
158
		fCreateModuleInfoJavaField= new SelectionButtonDialogField(SWT.CHECK);
159
		fCreateModuleInfoJavaField.setDialogFieldListener(adapter);
160
		fCreateModuleInfoJavaField.setLabelText(NewWizardMessages.NewSourceFolderWizardPage_create_module_info_java);
161
		fCreateModuleInfoJavaField.setSelection(false);
162
163
		fRootStatus= new StatusInfo();
147
		fRootStatus= new StatusInfo();
164
		fProjectStatus= new StatusInfo();
148
		fProjectStatus= new StatusInfo();
165
	}
149
	}
Lines 170-183 Link Here
170
		String projPath= getProjectPath(selection);
154
		String projPath= getProjectPath(selection);
171
		fProjectField.setText(projPath != null ? projPath : ""); //$NON-NLS-1$
155
		fProjectField.setText(projPath != null ? projPath : ""); //$NON-NLS-1$
172
		fRootDialogField.setText(""); //$NON-NLS-1$
156
		fRootDialogField.setText(""); //$NON-NLS-1$
173
174
		IDialogSettings dialogSettings= getDialogSettings();
175
		if (dialogSettings != null) {
176
			IDialogSettings section= dialogSettings.getSection(PAGE_NAME);
177
			if (section != null) {
178
				fCreateModuleInfoJavaField.setSelection(section.getBoolean(SETTINGS_CREATE_MODULE_INFO_JAVA));
179
			}
180
		}
181
	}
157
	}
182
158
183
	private String getProjectPath(IStructuredSelection selection) {
159
	private String getProjectPath(IStructuredSelection selection) {
Lines 222-228 Link Here
222
		fRootDialogField.doFillIntoGrid(composite, 3);
198
		fRootDialogField.doFillIntoGrid(composite, 3);
223
		fExcludeInOthersFields.doFillIntoGrid(composite, 3);
199
		fExcludeInOthersFields.doFillIntoGrid(composite, 3);
224
		fIgnoreOptionalProblemsField.doFillIntoGrid(composite, 3);
200
		fIgnoreOptionalProblemsField.doFillIntoGrid(composite, 3);
225
		fCreateModuleInfoJavaField.doFillIntoGrid(composite, 3);
226
201
227
		int maxFieldWidth= convertWidthInCharsToPixels(40);
202
		int maxFieldWidth= convertWidthInCharsToPixels(40);
228
		LayoutUtil.setWidthHint(fProjectField.getTextControl(null), maxFieldWidth);
203
		LayoutUtil.setWidthHint(fProjectField.getTextControl(null), maxFieldWidth);
Lines 291-298 Link Here
291
		} else if (field == fExcludeInOthersFields) {
266
		} else if (field == fExcludeInOthersFields) {
292
			updateRootStatus();
267
			updateRootStatus();
293
		} else if (field == fIgnoreOptionalProblemsField) {
268
		} else if (field == fIgnoreOptionalProblemsField) {
294
			updateRootStatus();
295
		} else if (field == fCreateModuleInfoJavaField) {
296
			updateRootStatus();
269
			updateRootStatus();
297
		}
270
		}
298
		updateStatus(new IStatus[] { fProjectStatus, fRootStatus });
271
		updateStatus(new IStatus[] { fProjectStatus, fRootStatus });
Lines 392-401 Link Here
392
					IClasspathEntry curr= fEntries[i];
365
					IClasspathEntry curr= fEntries[i];
393
					if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
366
					if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
394
						if (path.equals(curr.getPath())) {
367
						if (path.equals(curr.getPath())) {
395
							boolean createModuleInfoJava= isCreateModuleInfoJava() && !moduleInfoJavaAlreadyExists(fCurrJProject.getPackageFragmentRoot(res));
368
							fRootStatus.setError(NewWizardMessages.NewSourceFolderWizardPage_error_AlreadyExisting);
396
							if (!createModuleInfoJava) {
397
								fRootStatus.setError(NewWizardMessages.NewSourceFolderWizardPage_error_AlreadyExisting);
398
							}
399
							return;
369
							return;
400
						}
370
						}
401
						if (projPath.equals(curr.getPath())) {
371
						if (projPath.equals(curr.getPath())) {
Lines 461-487 Link Here
461
		}
431
		}
462
	}
432
	}
463
433
464
	/**
465
	 * Checks if the module-info.java file already exists in any package in the given package
466
	 * fragment root.
467
	 * 
468
	 * @param root the package fragment root
469
	 * @return <code>true</code> if module-info.java exists in any package in the given
470
	 *         <code>root</code>, <code>false</code> otherwise
471
	 */
472
	private boolean moduleInfoJavaAlreadyExists(IPackageFragmentRoot root) {
473
		try {
474
			for (IJavaElement pkgFragment : root.getChildren()) {
475
				if (((IPackageFragment) pkgFragment).getCompilationUnit(MODULE_INFO_JAVA_FILENAME).exists()) {
476
					return true;
477
				}
478
			}
479
		} catch (JavaModelException e) {
480
			// pretend that the file does not exist
481
		}
482
		return false;
483
	}
484
485
	private void insertAtEndOfCategory(IClasspathEntry entry, List<IClasspathEntry> entries) {
434
	private void insertAtEndOfCategory(IClasspathEntry entry, List<IClasspathEntry> entries) {
486
		int length= entries.size();
435
		int length= entries.size();
487
		IClasspathEntry[] elements= entries.toArray(new IClasspathEntry[length]);
436
		IClasspathEntry[] elements= entries.toArray(new IClasspathEntry[length]);
Lines 539-608 Link Here
539
		return fCreatedRoot;
488
		return fCreatedRoot;
540
	}
489
	}
541
490
542
	/**
543
	 * @return <code>true</code> if module-info.java should be created, <code>false</code> otherwise
544
	 */
545
	private boolean isCreateModuleInfoJava() {
546
		return JavaModelUtil.is9OrHigher(fCurrJProject) && fCreateModuleInfoJavaField.isSelected();
547
	}
548
549
	public IResource getCorrespondingResource() {
491
	public IResource getCorrespondingResource() {
550
		IFolder folder= fCurrJProject.getProject().getFolder(fRootDialogField.getText());
492
		return fCurrJProject.getProject().getFolder(fRootDialogField.getText());
551
		if (isCreateModuleInfoJava()) {
552
			return folder.getFile(MODULE_INFO_JAVA_FILENAME);
553
		}
554
		return folder;
555
	}
493
	}
556
494
557
	public void createPackageFragmentRoot(IProgressMonitor monitor) throws CoreException, InterruptedException {
495
	public void createPackageFragmentRoot(IProgressMonitor monitor) throws CoreException, InterruptedException {
558
		if (monitor == null) {
496
		if (monitor == null) {
559
			monitor= new NullProgressMonitor();
497
			monitor= new NullProgressMonitor();
560
		}
498
		}
561
		String relPath= fRootDialogField.getText();
499
		monitor.beginTask(NewWizardMessages.NewSourceFolderWizardPage_operation, 3);
562
		IFolder folder= fCurrJProject.getProject().getFolder(relPath);
500
		try {
563
		fCreatedRoot= fCurrJProject.getPackageFragmentRoot(folder);
501
			IPath projPath= fCurrJProject.getProject().getFullPath();
564
502
			if (fOutputLocation.equals(projPath) && !fNewOutputLocation.equals(projPath)) {
565
		if (!fCreatedRoot.exists()) {
503
				if (BuildPathsBlock.hasClassfiles(fCurrJProject.getProject())) {
566
			monitor.beginTask(NewWizardMessages.NewSourceFolderWizardPage_operation, 3);
504
					if (BuildPathsBlock.getRemoveOldBinariesQuery(getShell()).doQuery(false, projPath)) {
567
			try {
505
						BuildPathsBlock.removeOldClassfiles(fCurrJProject.getProject());
568
				IPath projPath= fCurrJProject.getProject().getFullPath();
569
				if (fOutputLocation.equals(projPath) && !fNewOutputLocation.equals(projPath)) {
570
					if (BuildPathsBlock.hasClassfiles(fCurrJProject.getProject())) {
571
						if (BuildPathsBlock.getRemoveOldBinariesQuery(getShell()).doQuery(false, projPath)) {
572
							BuildPathsBlock.removeOldClassfiles(fCurrJProject.getProject());
573
						}
574
					}
506
					}
575
				}
507
				}
576
577
				if (!folder.exists()) {
578
					CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
579
				}
580
				if (monitor.isCanceled()) {
581
					throw new InterruptedException();
582
				}
583
584
				fCurrJProject.setRawClasspath(fNewEntries, fNewOutputLocation, new SubProgressMonitor(monitor, 2));
585
586
			} finally {
587
				monitor.done();
588
			}
508
			}
589
		}
590
509
591
		if (isCreateModuleInfoJava()) {
510
			String relPath= fRootDialogField.getText();
592
			// default package always exists
593
			IPackageFragment pack= fCreatedRoot.getPackageFragment(""); //$NON-NLS-1$
594
			String fileContent= JavaCore.createModuleFromPackageRoot(null, fCreatedRoot);
595
			InfoFilesUtil.createInfoJavaFile(MODULE_INFO_JAVA_FILENAME, fileContent, pack, monitor);
596
		}
597
511
598
		// save dialog settings for create_module_info_java
512
			IFolder folder= fCurrJProject.getProject().getFolder(relPath);
599
		IDialogSettings dialogSettings= getDialogSettings();
513
			if (!folder.exists()) {
600
		if (dialogSettings != null) {
514
				CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
601
			IDialogSettings section= dialogSettings.getSection(PAGE_NAME);
602
			if (section == null) {
603
				section= dialogSettings.addNewSection(PAGE_NAME);
604
			}
515
			}
605
			section.put(SETTINGS_CREATE_MODULE_INFO_JAVA, fCreateModuleInfoJavaField.isSelected());
516
			if (monitor.isCanceled()) {
517
				throw new InterruptedException();
518
			}
519
520
			fCurrJProject.setRawClasspath(fNewEntries, fNewOutputLocation, new SubProgressMonitor(monitor, 2));
521
522
			fCreatedRoot= fCurrJProject.getPackageFragmentRoot(folder);
523
		} finally {
524
			monitor.done();
606
		}
525
		}
607
	}
526
	}
608
527
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java (-6 / +1 lines)
Lines 1-13 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2016 IBM Corporation and others.
2
 * Copyright (c) 2000, 2015 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
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 *
7
 *
12
 * Contributors:
8
 * Contributors:
13
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
Lines 268-274 Link Here
268
	public static String NewSourceFolderWizardPage_operation;
264
	public static String NewSourceFolderWizardPage_operation;
269
	public static String NewSourceFolderWizardPage_exclude_label;
265
	public static String NewSourceFolderWizardPage_exclude_label;
270
	public static String NewSourceFolderWizardPage_ignore_optional_problems_label;
266
	public static String NewSourceFolderWizardPage_ignore_optional_problems_label;
271
	public static String NewSourceFolderWizardPage_create_module_info_java;
272
	public static String NewSourceFolderWizardPage_ChooseExistingRootDialog_title;
267
	public static String NewSourceFolderWizardPage_ChooseExistingRootDialog_title;
273
	public static String NewSourceFolderWizardPage_ChooseExistingRootDialog_description;
268
	public static String NewSourceFolderWizardPage_ChooseExistingRootDialog_description;
274
	public static String NewSourceFolderWizardPage_ChooseProjectDialog_title;
269
	public static String NewSourceFolderWizardPage_ChooseProjectDialog_title;
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties (-6 / +1 lines)
Lines 1-13 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2016 IBM Corporation and others.
2
# Copyright (c) 2000, 2015 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
6
# http://www.eclipse.org/legal/epl-v10.html
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# This is an implementation of an early-draft specification developed under the Java
9
# Community Process (JCP) and is made available for testing and evaluation purposes
10
# only. The code is not compatible with any specification of the JCP.
11
#
7
#
12
# Contributors:
8
# Contributors:
13
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
Lines 243-249 Link Here
243
239
244
NewSourceFolderWizardPage_exclude_label=&Update exclusion filters in other source folders to solve nesting
240
NewSourceFolderWizardPage_exclude_label=&Update exclusion filters in other source folders to solve nesting
245
NewSourceFolderWizardPage_ignore_optional_problems_label=&Ignore optional compile problems
241
NewSourceFolderWizardPage_ignore_optional_problems_label=&Ignore optional compile problems
246
NewSourceFolderWizardPage_create_module_info_java=&Create module-info.java (9 or higher)
247
242
248
NewSourceFolderWizardPage_ChooseExistingRootDialog_title=Existing Folder Selection
243
NewSourceFolderWizardPage_ChooseExistingRootDialog_title=Existing Folder Selection
249
NewSourceFolderWizardPage_ChooseExistingRootDialog_description=&Choose folder as source folder:
244
NewSourceFolderWizardPage_ChooseExistingRootDialog_description=&Choose folder as source folder:

Return to bug 488748