JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) root;
IJavaProject project = jarPackageFragmentRoot.getJavaProject();
String sourceLevel = null;
String complianceLevel = null;
JavaModelManager manager = JavaModelManager.getJavaModelManager();
ZipFile zip = null;
try {
zip = manager.getZipFile(jarPackageFragmentRoot.getPath());
for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) entries.nextElement();
String entryName = entry.getName();
if (!entry.isDirectory()) {
int index = entryName.indexOf('/');
if (index != -1 && Util.isClassFileName(entryName)) {
String firstLevelPackageName = entryName.substring(0, index);
if (!firstLevelPackageNames.contains(firstLevelPackageName)) {
if (sourceLevel == null) {
sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
}
IStatus status = JavaConventions.validatePackageName(firstLevelPackageName, sourceLevel, complianceLevel);
if (status.isOK() || status.getSeverity() == IStatus.WARNING) {
firstLevelPackageNames.add(firstLevelPackageName);
}
}
} else if (Util.isClassFileName(entryName)) {
containsADefaultPackage = true;
}
}
}
} catch (CoreException e) {
// ignore
} finally {
manager.closeZipFile(zip); // handle null case
}
} else {
Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), root.getPath(), true);
if (target instanceof IResource) {
IResource resource = (IResource) target;
if (resource instanceof IContainer) {
try {
IResource[] members = ((IContainer) resource).members();
for (int i = 0, max = members.length; i < max; i++) {
IResource member = members[i];
if (member.getType() == IResource.FOLDER) {
firstLevelPackageNames.add(member.getName());
} else if (Util.isClassFileName(member.getName())) {
containsADefaultPackage = true;
}
}
} catch (CoreException e) {
// ignore
}
}
} else if (target instanceof File) {
File file = (File)target;
if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0, max = files.length; i < max; i++) {
File currentFile = files[i];
if (currentFile.isDirectory()) {
firstLevelPackageNames.add(currentFile.getName());
} else if (Util.isClassFileName(currentFile.getName())) {
containsADefaultPackage = true;
}
}
}
}
}
if (Util.isArchiveFileName(this.sourcePath.lastSegment())) {
JavaModelManager manager = JavaModelManager.getJavaModelManager();
ZipFile zip = null;
try {
zip = manager.getZipFile(this.sourcePath);
for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) entries.nextElement();
String entryName;
if (!entry.isDirectory() && org.aspectj.org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(entryName = entry.getName())) {
IPath path = new Path(entryName);
int segmentCount = path.segmentCount();