Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 225201 Details for
Bug 393161
[type wizards] Pre-fill package name in the new class dialog
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch
Bug-393161--type-wizards-Prefill-package-name.patch (text/plain), 6.29 KB, created by
Noopur Gupta
on 2013-01-04 02:54:32 EST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Noopur Gupta
Created:
2013-01-04 02:54:32 EST
Size:
6.29 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewPackageWizardPage.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewPackageWizardPage.java >index c74f410..40faf05 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewPackageWizardPage.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewPackageWizardPage.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2012 IBM Corporation and others. >+ * Copyright (c) 2000, 2013 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -161,8 +161,20 @@ > String pName= ""; //$NON-NLS-1$ > if (jelem != null) { > IPackageFragment pf= (IPackageFragment) jelem.getAncestor(IJavaElement.PACKAGE_FRAGMENT); >- if (pf != null && !pf.isDefaultPackage()) >+ if (pf != null && !pf.isDefaultPackage()) { > pName= pf.getElementName(); >+ } else { >+ IJavaProject project= jelem.getJavaProject(); >+ if (project != null) { >+ String prName= project.getElementName(); >+ fPackageStatus= updatePackageStatus(prName); >+ if (fPackageStatus.getSeverity() == IStatus.ERROR || fPackageStatus.getSeverity() == IStatus.WARNING) { >+ fPackageStatus= new StatusInfo(); >+ } else { >+ pName= prName; >+ } >+ } >+ } > } > setPackageText(pName, true); > >@@ -282,8 +294,20 @@ > * Verifies the input for the package field. > */ > private IStatus packageChanged() { >- StatusInfo status= new StatusInfo(); > String packName= getPackageText(); >+ return updatePackageStatus(packName); >+ } >+ >+ /* >+ * The method validates the package name and returns the status of the validation. The >+ * validation also updates the package fragment model. >+ * >+ * @param packName the package name >+ * >+ * @return the status of the validation >+ */ >+ private IStatus updatePackageStatus(String packName) { >+ StatusInfo status= new StatusInfo(); > if (packName.length() > 0) { > IStatus val= validatePackageName(packName); > if (val.getSeverity() == IStatus.ERROR) { >@@ -504,7 +528,7 @@ > if (fileComment != null) { > content.append(fileComment); > content.append(lineDelimiter); >- } >+ } > > if (typeComment != null) { > content.append(typeComment); >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 df804dc..15d6ef0 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 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2012 IBM Corporation and others. >+ * Copyright (c) 2000, 2013 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -569,8 +569,19 @@ > > if (elem != null) { > // evaluate the enclosing type >- project= elem.getJavaProject(); > pack= (IPackageFragment) elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT); >+ if (pack == null) { >+ String packName= getPackageName(elem); >+ if (packName != null) { >+ fPackageStatus= updatePackageStatus(packName); >+ if (fPackageStatus.getSeverity() == IStatus.ERROR || fPackageStatus.getSeverity() == IStatus.WARNING) { >+ fCurrPackage= null; >+ fPackageStatus= new StatusInfo(); >+ } else { >+ pack= fCurrPackage; >+ } >+ } >+ } > IType typeInCU= (IType) elem.getAncestor(IJavaElement.TYPE); > if (typeInCU != null) { > if (typeInCU.getCompilationUnit() != null) { >@@ -623,8 +634,35 @@ > setAddComments(StubUtility.doAddComments(project), true); // from project or workspace > } > >- >- >+ private String getPackageName(IJavaElement elem) { >+ String packName= null; >+ boolean useProjectName= false; >+ // if the source folder contains exactly one package then use that package name >+ final IPackageFragmentRoot froot= getPackageFragmentRoot(); >+ IJavaElement[] packages= null; >+ try { >+ if (froot != null && froot.exists()) { >+ packages= froot.getChildren(); >+ if (packages != null) { >+ if (packages.length == 1) { // length is 1 -> only default package -> use Project name >+ useProjectName= true; >+ } else if (packages.length == 2) { // length is 2 -> default package + exactly 1 more package >+ for (final IJavaElement pkg : packages) { >+ if (!((IPackageFragment) pkg).isDefaultPackage()) { >+ packName= pkg.getElementName(); >+ } >+ } >+ } >+ } >+ } >+ } catch (JavaModelException e) { >+ // fall through >+ } >+ if (useProjectName && elem.getJavaProject() != null) { >+ packName= elem.getJavaProject().getElementName(); >+ } >+ return packName; >+ } > > private static IStatus validateJavaTypeName(String text, IJavaProject project) { > if (project == null || !project.exists()) { >@@ -1463,13 +1501,25 @@ > * @return the status of the validation > */ > protected IStatus packageChanged() { >+ String packName= getPackageText(); >+ return updatePackageStatus(packName); >+ } >+ >+ /* >+ * The method validates the package name and returns the status of the validation. The >+ * validation also updates the package fragment model. >+ * >+ * @param packName the package name >+ * >+ * @return the status of the validation >+ */ >+ private IStatus updatePackageStatus(String packName) { > StatusInfo status= new StatusInfo(); > IPackageFragmentRoot root= getPackageFragmentRoot(); > fPackageDialogField.enableButton(root != null); > > IJavaProject project= root != null ? root.getJavaProject() : null; > >- String packName= getPackageText(); > if (packName.length() > 0) { > IStatus val= validatePackageName(packName, project); > if (val.getSeverity() == IStatus.ERROR) { >@@ -1509,7 +1559,7 @@ > if (resource.isVirtual()){ > status.setError(NewWizardMessages.NewTypeWizardPage_error_PackageIsVirtual); > return status; >- } >+ } > if (!ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) { > status.setError(NewWizardMessages.NewTypeWizardPage_error_PackageNameFiltered); > return status;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 393161
:
225201
|
225368
|
225410
|
225551
|
225558