List of usage examples for org.eclipse.jdt.internal.core PackageFragmentRoot resource
IResource resource
To view the source code for org.eclipse.jdt.internal.core PackageFragmentRoot resource.
Click Source Link
From source file:com.codenvy.ide.ext.java.server.internal.core.PackageFragment.java
License:Open Source License
/** * @see JavaElement#resource()/*ww w . j a v a2 s.c om*/ */ public File resource(PackageFragmentRoot root) { int length = this.names.length; if (length == 0) { return root.resource(root); } else { IPath path = new Path(this.names[0]); for (int i = 1; i < length; i++) path = path.append(this.names[i]); return new File(root.resource(root), path.toOSString()); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaSearchScope.java
License:Open Source License
/** * Add an element to the java search scope. * * @param element//from ww w . ja v a 2s . co m * The element we want to add to current java search scope * @throws org.eclipse.jdt.core.JavaModelException * May happen if some Java Model info are not available */ public void add(IJavaElement element) throws JavaModelException { IPath containerPath = null; String containerPathToString = null; PackageFragmentRoot root = null; int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES; switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: // a workspace sope should be used break; case IJavaElement.JAVA_PROJECT: add((JavaProject) element, null, includeMask, new HashSet(2), new HashSet(2), null); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: root = (PackageFragmentRoot) element; IPath rootPath = root.internalPath(); containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath; containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); IResource rootResource = root.resource(); String projectPath = root.getJavaProject().getPath().toString(); if (rootResource != null && rootResource.isAccessible()) { String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount()); add(projectPath, relativePath, containerPathToString, false/*not a package*/, null); } else { add(projectPath, "", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$ } break; case IJavaElement.PACKAGE_FRAGMENT: root = (PackageFragmentRoot) element.getParent(); projectPath = root.getJavaProject().getPath().toString(); if (root.isArchive()) { String relativePath = Util.concatWith(((PackageFragment) element).names, '/'); containerPath = root.getPath(); containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); add(projectPath, relativePath, containerPathToString, true/*package*/, null); } else { IResource resource = ((JavaElement) element).resource(); if (resource != null) { if (resource.isAccessible()) { containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.internalPath(); } else { // for working copies, get resource container full path containerPath = resource.getParent().getFullPath(); } containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount()); add(projectPath, relativePath, containerPathToString, true/*package*/, null); } } break; default: // remember sub-cu (or sub-class file) java elements if (element instanceof IMember) { if (this.elements == null) { this.elements = new ArrayList(); } this.elements.add(element); } root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); projectPath = root.getJavaProject().getPath().toString(); String relativePath; if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { containerPath = root.getParent().getPath(); relativePath = Util.relativePath(getPath(element, false/*full path*/), 1/*remove project segment*/); } else { containerPath = root.internalPath(); relativePath = getPath(element, true/*relative path*/).toString(); } containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); add(projectPath, relativePath, containerPathToString, false/*not a package*/, null); } if (root != null) addEnclosingProjectOrJar( root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath()); }
From source file:org.codehaus.jdt.groovy.model.GroovyClassFileWorkingCopy.java
License:Open Source License
public IResource resource(PackageFragmentRoot root) { if (root.isArchive()) return root.resource(root); return this.classFile.resource(root); }
From source file:org.eclipse.che.jdt.internal.core.Openable.java
License:Open Source License
public File resource() { PackageFragmentRoot root = getPackageFragmentRoot(); if (root != null && root.isArchive()) return root.resource(root); return resource(root); }
From source file:org.eclipse.jdt.internal.core.CopyResourceElementsOperation.java
License:Open Source License
/** * Creates any destination package fragment(s) which do not exists yet. * Return true if a read-only package fragment has been found among package fragments, false otherwise *//* ww w. j a va 2s . c o m*/ private boolean createNeededPackageFragments(IContainer sourceFolder, PackageFragmentRoot root, String[] newFragName, boolean moveFolder) throws JavaModelException { boolean containsReadOnlyPackageFragment = false; IContainer parentFolder = (IContainer) root.resource(); JavaElementDelta projectDelta = null; String[] sideEffectPackageName = null; char[][] inclusionPatterns = root.fullInclusionPatternChars(); char[][] exclusionPatterns = root.fullExclusionPatternChars(); for (int i = 0; i < newFragName.length; i++) { String subFolderName = newFragName[i]; sideEffectPackageName = Util.arrayConcat(sideEffectPackageName, subFolderName); IResource subFolder = parentFolder.findMember(subFolderName); if (subFolder == null) { // create deepest folder only if not a move (folder will be moved in processPackageFragmentResource) if (!(moveFolder && i == newFragName.length - 1)) { createFolder(parentFolder, subFolderName, this.force); } parentFolder = parentFolder.getFolder(new Path(subFolderName)); sourceFolder = sourceFolder.getFolder(new Path(subFolderName)); if (Util.isReadOnly(sourceFolder)) { containsReadOnlyPackageFragment = true; } IPackageFragment sideEffectPackage = root.getPackageFragment(sideEffectPackageName); if (i < newFragName.length - 1 // all but the last one are side effect packages && !Util.isExcluded(parentFolder, inclusionPatterns, exclusionPatterns)) { if (projectDelta == null) { projectDelta = getDeltaFor(root.getJavaProject()); } projectDelta.added(sideEffectPackage); } this.createdElements.add(sideEffectPackage); } else { parentFolder = (IContainer) subFolder; } } return containsReadOnlyPackageFragment; }
From source file:org.eclipse.jdt.internal.core.CopyResourceElementsOperation.java
License:Open Source License
private void updateReadOnlyPackageFragmentsForCopy(IContainer sourceFolder, PackageFragmentRoot root, String[] newFragName) {// www . java 2 s . co m IContainer parentFolder = (IContainer) root.resource(); for (int i = 0, length = newFragName.length; i < length; i++) { String subFolderName = newFragName[i]; parentFolder = parentFolder.getFolder(new Path(subFolderName)); sourceFolder = sourceFolder.getFolder(new Path(subFolderName)); if (sourceFolder.exists() && Util.isReadOnly(sourceFolder)) { Util.setReadOnly(parentFolder, true); } } }
From source file:org.eclipse.jdt.internal.core.CopyResourceElementsOperation.java
License:Open Source License
private void updateReadOnlyPackageFragmentsForMove(IContainer sourceFolder, PackageFragmentRoot root, String[] newFragName, boolean sourceFolderIsReadOnly) { IContainer parentFolder = (IContainer) root.resource(); for (int i = 0, length = newFragName.length; i < length; i++) { String subFolderName = newFragName[i]; parentFolder = parentFolder.getFolder(new Path(subFolderName)); sourceFolder = sourceFolder.getFolder(new Path(subFolderName)); if ((sourceFolder.exists() && Util.isReadOnly(sourceFolder)) || (i == length - 1 && sourceFolderIsReadOnly)) { Util.setReadOnly(parentFolder, true); // the source folder will be deleted anyway (move operation) Util.setReadOnly(sourceFolder, false); }//w ww .ja v a2 s.c o m } }
From source file:org.eclipse.jdt.internal.core.PackageFragment.java
License:Open Source License
/** * @see JavaElement#resource()//from www . j a v a2s. com */ public IResource resource(PackageFragmentRoot root) { int length = this.names.length; if (length == 0) { return root.resource(root); } else { IPath path = new Path(this.names[0]); for (int i = 1; i < length; i++) path = path.append(this.names[i]); return ((IContainer) root.resource(root)).getFolder(path); } }