/** * Returns an array of non-java resources contained in the receiver. */ Object[] getNonJavaResources(IResource underlyingResource, PackageFragmentRoot rootHandle) { if (this.nonJavaResources == null) { try { this.nonJavaResources = PackageFragmentRootInfo.computeFolderNonJavaResources( rootHandle, (IContainer)underlyingResource, rootHandle.fullInclusionPatternChars(), rootHandle.fullExclusionPatternChars()); } catch (JavaModelException e) { // root doesn't exist: consider package has no nonJavaResources this.nonJavaResources = NO_NON_JAVA_RESOURCES; } } return this.nonJavaResources; } /**
/** * @see IPackageFragmentRoot */ @Override public IPackageFragment getPackageFragment(String packageName) { // tolerate package names with spaces (e.g. 'x . y') (http://bugs.eclipse.org/bugs/show_bug.cgi?id=21957) String[] pkgName = Util.getTrimmedSimpleNames(packageName); return getPackageFragment(pkgName); } public PackageFragment getPackageFragment(String[] pkgName) {
/** * @see IJavaElement */ @Override public IPath getPath() { return internalPath(); }
/** * @see Openable */ protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { ((PackageFragmentRootInfo) info).setRootKind(determineKind(underlyingResource)); return computeChildren(info, underlyingResource); }
/** * @see JavaElement */ @Override public SourceMapper getSourceMapper() { SourceMapper mapper; try { PackageFragmentRootInfo rootInfo = (PackageFragmentRootInfo) getElementInfo(); mapper = rootInfo.getSourceMapper(); if (mapper == null) { // first call to this method IPath sourcePath= getSourceAttachmentPath(); IPath rootPath= getSourceAttachmentRootPath(); if (sourcePath == null) mapper = createSourceMapper(getPath(), rootPath); // attach root to itself else mapper = createSourceMapper(sourcePath, rootPath); rootInfo.setSourceMapper(mapper); } } catch (JavaModelException e) { // no source can be attached mapper = null; } return mapper; }
public void attachSource(IPath sourcePath, IPath rootPath, IProgressMonitor monitor) throws JavaModelException { try { verifyAttachSource(sourcePath); if (monitor != null) { monitor.beginTask(Messages.element_attachingSource, 2); SourceMapper oldMapper= getSourceMapper(); boolean rootNeedsToBeClosed= false; setSourceMapper(null); IPath storedSourcePath= getSourceAttachmentPath(); IPath storedRootPath= getSourceAttachmentRootPath(); if (monitor != null) { monitor.worked(1); SourceMapper mapper = createSourceMapper(sourcePath, rootPath); if (rootPath == null && mapper.rootPath != null) { setSourceMapper(mapper); Util.setSourceAttachmentProperty(getPath(), null); //remove the property } else { getPath(), sourcePath.toString() + (rootPath == null ? "" : (ATTACHMENT_PROPERTY_DELIMITER + rootPath.toString()))); //$NON-NLS-1$ IBuffer buffer= (IBuffer) openBuffers.nextElement();
/** * Compute the package fragment children of this package fragment root. * * @exception JavaModelException The resource associated with this package fragment root does not exist */ protected boolean computeChildren(OpenableElementInfo info, IResource underlyingResource) throws JavaModelException { // Note the children are not opened (so not added to newElements) for a regular package fragment root // However they are opened for a Jar package fragment root (see JarPackageFragmentRoot#computeChildren) try { // the underlying resource may be a folder or a project (in the case that the project folder // is actually the package fragment root) if (underlyingResource.getType() == IResource.FOLDER || underlyingResource.getType() == IResource.PROJECT) { ArrayList vChildren = new ArrayList(5); IContainer rootFolder = (IContainer) underlyingResource; char[][] inclusionPatterns = fullInclusionPatternChars(); char[][] exclusionPatterns = fullExclusionPatternChars(); computeFolderChildren(rootFolder, !Util.isExcluded(rootFolder, inclusionPatterns, exclusionPatterns), CharOperation.NO_STRINGS, vChildren, inclusionPatterns, exclusionPatterns); IJavaElement[] children = new IJavaElement[vChildren.size()]; vChildren.toArray(children); info.setChildren(children); } } catch (JavaModelException e) { //problem resolving children; structure remains unknown info.setChildren(new IJavaElement[]{}); throw e; } return true; }
/** * Returns the package fragment root that contains the given resource path. */ private PackageFragmentRoot getPkgFragmentRoot(String pathString) { IPath path= new Path(pathString); IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (int i= 0, max= projects.length; i < max; i++) { try { IProject project = projects[i]; if (!project.isAccessible() || !project.hasNature(JavaCore.NATURE_ID)) continue; IJavaProject javaProject= this.javaModel.getJavaProject(project); IPackageFragmentRoot[] roots= javaProject.getPackageFragmentRoots(); for (int j= 0, rootCount= roots.length; j < rootCount; j++) { PackageFragmentRoot root= (PackageFragmentRoot)roots[j]; if (root.internalPath().isPrefixOf(path) && !Util.isExcluded(path, root.fullInclusionPatternChars(), root.fullExclusionPatternChars(), false)) { return root; } } } catch (CoreException e) { // CoreException from hasNature - should not happen since we check that the project is accessible // JavaModelException from getPackageFragmentRoots - a problem occured while accessing project: nothing we can do, ignore } } return null; }
IPackageFragment pkg = getPackageFragment(pkgName); vChildren.add(pkg); JavaProject javaProject = (JavaProject)getJavaProject(); JavaModelManager manager = JavaModelManager.getJavaModelManager(); IResource[] members = folder.members(); String[] newNames = Util.arrayConcat(pkgName, manager.intern(memberName)); boolean isMemberIncluded = !Util.isExcluded(member, inclusionPatterns, exclusionPatterns); computeFolderChildren((IFolder) member, isMemberIncluded, newNames, vChildren, inclusionPatterns, exclusionPatterns); && !Util.isExcluded(member, inclusionPatterns, exclusionPatterns)) { hasIncluded = true; IPackageFragment pkg = getPackageFragment(pkgName); vChildren.add(pkg);
int internalKind() throws JavaModelException { JavaModelManager manager = JavaModelManager.getJavaModelManager(); PackageFragmentRootInfo info = (PackageFragmentRootInfo) manager.peekAtInfo(this); if (info == null) { info = (PackageFragmentRootInfo) openWhenClosed(createElementInfo(), false, null); } return info.getRootKind(); }
IPackageFragmentRoot getPackageFragmentRoot(IResource resource, IPath entryPath) { switch (resource.getType()) { case IResource.FILE: return new JarPackageFragmentRoot(resource, this); case IResource.FOLDER: if (ExternalFoldersManager.isInternalPathForExternalFolder(resource.getFullPath())) return new ExternalPackageFragmentRoot(resource, entryPath, this); return new PackageFragmentRoot(resource, this); case IResource.PROJECT: return new PackageFragmentRoot(resource, this); default: return null; } }
private void initializePackageNames(IPackageFragmentRoot root, HashSetOfArray fragmentsCache) { IJavaElement[] frags = null; try { if (!root.isOpen()) { PackageFragmentRootInfo info = root.isArchive() ? new JarPackageFragmentRootInfo() : new PackageFragmentRootInfo(); ((PackageFragmentRoot) root).computeChildren(info, ((JavaElement) root).resource()); frags = info.children; } else frags = root.getChildren(); } catch (JavaModelException e) { // root doesn't exist: ignore return; } for (int j = 0, length = frags.length; j < length; j++) { if (frags[j] instanceof PackageFragment) fragmentsCache.add(((PackageFragment) frags[j]).names); } }
verifyAttachSource(sourcePath); if (monitor != null) { monitor.beginTask(Messages.element_attachingSource, 2); SourceMapper oldMapper= getSourceMapper(); boolean rootNeedsToBeClosed= false; setSourceMapper(null); IPath storedSourcePath= getSourceAttachmentPath(); IPath storedRootPath= getSourceAttachmentRootPath(); if (monitor != null) { monitor.worked(1); SourceMapper mapper = createSourceMapper(sourcePath, rootPath); if (rootPath == null && mapper.rootPath != null) { setSourceMapper(mapper); Util.setSourceAttachmentProperty(getPath(), null); //remove the property } else { getPath(), sourcePath.toString() + (rootPath == null ? "" : (ATTACHMENT_PROPERTY_DELIMITER + rootPath.toString()))); //$NON-NLS-1$ IBuffer buffer= (IBuffer) openBuffers.nextElement(); IOpenable possibleMember= buffer.getOwner(); if (isAncestorOf((IJavaElement) possibleMember)) {
/** * @see JavaElement */ public SourceMapper getSourceMapper() { SourceMapper mapper; try { PackageFragmentRootInfo rootInfo = (PackageFragmentRootInfo) getElementInfo(); mapper = rootInfo.getSourceMapper(); if (mapper == null) { // first call to this method IPath sourcePath= getSourceAttachmentPath(); IPath rootPath= getSourceAttachmentRootPath(); if (sourcePath == null) mapper = createSourceMapper(getPath(), rootPath); // attach root to itself else mapper = createSourceMapper(sourcePath, rootPath); rootInfo.setSourceMapper(mapper); } } catch (JavaModelException e) { // no source can be attached mapper = null; } return mapper; }
/** * Compute the package fragment children of this package fragment root. * * @exception JavaModelException The resource associated with this package fragment root does not exist */ protected boolean computeChildren(OpenableElementInfo info, IResource underlyingResource) throws JavaModelException { // Note the children are not opened (so not added to newElements) for a regular package fragment root // However they are opened for a Jar package fragment root (see JarPackageFragmentRoot#computeChildren) try { // the underlying resource may be a folder or a project (in the case that the project folder // is actually the package fragment root) if (underlyingResource.getType() == IResource.FOLDER || underlyingResource.getType() == IResource.PROJECT) { ArrayList vChildren = new ArrayList(5); IContainer rootFolder = (IContainer) underlyingResource; char[][] inclusionPatterns = fullInclusionPatternChars(); char[][] exclusionPatterns = fullExclusionPatternChars(); computeFolderChildren(rootFolder, !Util.isExcluded(rootFolder, inclusionPatterns, exclusionPatterns), CharOperation.NO_STRINGS, vChildren, inclusionPatterns, exclusionPatterns); IJavaElement[] children = new IJavaElement[vChildren.size()]; vChildren.toArray(children); info.setChildren(children); } } catch (JavaModelException e) { //problem resolving children; structure remains unknown info.setChildren(new IJavaElement[]{}); throw e; } return true; }
/** * Returns the package fragment root that contains the given resource path. */ private PackageFragmentRoot getPkgFragmentRoot(String pathString) { IPath path= new Path(pathString); IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (int i= 0, max= projects.length; i < max; i++) { try { IProject project = projects[i]; if (!project.isAccessible() || !project.hasNature(JavaCore.NATURE_ID)) continue; IJavaProject javaProject= this.javaModel.getJavaProject(project); IPackageFragmentRoot[] roots= javaProject.getPackageFragmentRoots(); for (int j= 0, rootCount= roots.length; j < rootCount; j++) { PackageFragmentRoot root= (PackageFragmentRoot)roots[j]; if (root.internalPath().isPrefixOf(path) && !Util.isExcluded(path, root.fullInclusionPatternChars(), root.fullExclusionPatternChars(), false)) { return root; } } } catch (CoreException e) { // CoreException from hasNature - should not happen since we check that the project is accessible // JavaModelException from getPackageFragmentRoots - a problem occured while accessing project: nothing we can do, ignore } } return null; }
IPackageFragment pkg = getPackageFragment(pkgName); vChildren.add(pkg); String sourceLevel = otherJavaProject.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = otherJavaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true); JavaProject javaProject = (JavaProject) getJavaProject(); JavaModelManager manager = JavaModelManager.getJavaModelManager(); for (int i = 0; i < length; i++) { String[] newNames = Util.arrayConcat(pkgName, manager.intern(memberName)); boolean isMemberIncluded = !Util.isExcluded(member, inclusionPatterns, exclusionPatterns); computeFolderChildren((IFolder) member, isMemberIncluded, newNames, vChildren, inclusionPatterns, exclusionPatterns); && !Util.isExcluded(member, inclusionPatterns, exclusionPatterns)) { hasIncluded = true; IPackageFragment pkg = getPackageFragment(pkgName); vChildren.add(pkg);
/** * @see Openable */ @Override protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { ((PackageFragmentRootInfo) info).setRootKind(determineKind(underlyingResource)); return computeChildren(info, underlyingResource); }
int internalKind() throws JavaModelException { JavaModelManager manager = JavaModelManager.getJavaModelManager(); PackageFragmentRootInfo info = (PackageFragmentRootInfo) manager.peekAtInfo(this); if (info == null) { info = (PackageFragmentRootInfo) openWhenClosed(createElementInfo(), false, null); } return info.getRootKind(); }
private IPackageFragmentRoot getPackageFragmentRoot(IResource resource, IPath entryPath) { switch (resource.getType()) { case IResource.FILE: return new JarPackageFragmentRoot(resource, this); case IResource.FOLDER: if (ExternalFoldersManager.isInternalPathForExternalFolder(resource.getFullPath())) return new ExternalPackageFragmentRoot(resource, entryPath, this); return new PackageFragmentRoot(resource, this); case IResource.PROJECT: return new PackageFragmentRoot(resource, this); default: return null; } }