package org.eclipse.jdt.internal.core;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.*;
import org.eclipse.jdt.internal.core.util.Util;
class PackageFragmentRootInfo extends OpenableElementInfo {
protected SourceMapper sourceMapper = null;
protected int rootKind= IPackageFragmentRoot.K_SOURCE;
private boolean ignoreOptionalProblems;
private boolean initialized;
public PackageFragmentRootInfo() {
this.nonJavaResources = null;
this.initialized = false;
}
static Object[] computeFolderNonJavaResources(IPackageFragmentRoot root, IContainer folder, char[][] inclusionPatterns, char[][] exclusionPatterns) throws JavaModelException {
IResource[] nonJavaResources = new IResource[5];
int nonJavaResourcesCounter = 0;
try {
IResource[] members = folder.members();
int length = members.length;
if (length > 0) {
IJavaProject otherJavaProject = JavaCore.create(folder.getProject());
String sourceLevel = otherJavaProject.getOption(JavaCore.COMPILER_SOURCE, true);
String complianceLevel = otherJavaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
JavaProject javaProject = (JavaProject) root.getJavaProject();
IClasspathEntry[] classpath = javaProject.getResolvedClasspath();
nextResource: for (int i = 0; i < length; i++) {
IResource member = members[i];
switch (member.getType()) {
case IResource.FILE :
String fileName = member.getName();
if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel) && !Util.isExcluded(member, inclusionPatterns, exclusionPatterns))
continue nextResource;
if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel))
continue nextResource;
if (isClasspathEntry(member.getFullPath(), classpath))
continue nextResource;
break;
case IResource.FOLDER :
if (Util.isValidFolderNameForPackage(member.getName(), sourceLevel, complianceLevel)
&& (!Util.isExcluded(member, inclusionPatterns, exclusionPatterns)
|| isClasspathEntry(member.getFullPath(), classpath)))
continue nextResource;
break;
}
if (nonJavaResources.length == nonJavaResourcesCounter) {
System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]), 0, nonJavaResourcesCounter);
}
nonJavaResources[nonJavaResourcesCounter++] = member;
}
}
if (ExternalFoldersManager.isInternalPathForExternalFolder(folder.getFullPath())) {
IJarEntryResource[] jarEntryResources = new IJarEntryResource[nonJavaResourcesCounter];
for (int i = 0; i < nonJavaResourcesCounter; i++) {
jarEntryResources[i] = new NonJavaResource(root, nonJavaResources[i]);
}
return jarEntryResources;
} else if (nonJavaResources.length != nonJavaResourcesCounter) {
System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter]), 0, nonJavaResourcesCounter);
}
return nonJavaResources;
} catch (CoreException e) {
throw new JavaModelException(e);
}
}
private Object[] computeNonJavaResources(IResource underlyingResource, PackageFragmentRoot handle) {
Object[] resources = NO_NON_JAVA_RESOURCES;
try {
if (underlyingResource.getType() == IResource.FOLDER || underlyingResource.getType() == IResource.PROJECT) {
resources =
computeFolderNonJavaResources(
handle,
(IContainer) underlyingResource,
handle.fullInclusionPatternChars(),
handle.fullExclusionPatternChars());
}
} catch (JavaModelException e) {
}
return resources;
}
synchronized Object[] getNonJavaResources(IJavaProject project, IResource underlyingResource, PackageFragmentRoot handle) {
Object[] resources = this.nonJavaResources;
if (resources == null) {
resources = computeNonJavaResources(underlyingResource, handle);
this.nonJavaResources = resources;
}
return resources;
}
public int getRootKind() {
return this.rootKind;
}
protected SourceMapper getSourceMapper() {
return this.sourceMapper;
}
boolean ignoreOptionalProblems(PackageFragmentRoot packageFragmentRoot) throws JavaModelException {
if (this.initialized == false) {
this.ignoreOptionalProblems = ((ClasspathEntry) packageFragmentRoot.getRawClasspathEntry()).ignoreOptionalProblems();
this.initialized = true;
}
return this.ignoreOptionalProblems;
}
private static boolean isClasspathEntry(IPath path, IClasspathEntry[] resolvedClasspath) {
for (int i = 0, length = resolvedClasspath.length; i < length; i++) {
IClasspathEntry entry = resolvedClasspath[i];
if (entry.getPath().equals(path)) {
return true;
}
}
return false;
}
protected void setRootKind(int newRootKind) {
this.rootKind = newRootKind;
}
protected void setSourceMapper(SourceMapper mapper) {
this.sourceMapper= mapper;
}
}