List of usage examples for org.eclipse.jdt.internal.core PackageFragmentRoot isArchive
@Override public boolean isArchive()
From source file:com.codenvy.ide.ext.java.server.internal.core.ClassFile.java
License:Open Source License
public IPath getPath() { PackageFragmentRoot root = getPackageFragmentRoot(); if (root.isArchive()) { return root.getPath(); } else {/*from w w w .ja va 2 s . c o m*/ return getParent().getPath().append(getElementName()); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnit.java
License:Open Source License
/** * A compilation unit has a corresponding resource unless it is contained * in a jar.//ww w . j a va2 s.c om * * @see org.eclipse.jdt.core.IJavaElement#getCorrespondingResource() */ public IResource getCorrespondingResource() throws JavaModelException { PackageFragmentRoot root = getPackageFragmentRoot(); if (root == null || root.isArchive()) { return null; } else { return getUnderlyingResource(); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnit.java
License:Open Source License
/** * @see org.eclipse.jdt.core.IJavaElement#getPath() *///from w w w . ja va2 s . c om public IPath getPath() { PackageFragmentRoot root = getPackageFragmentRoot(); if (root == null) return new Path(getElementName()); // working copy not in workspace if (root.isArchive()) { return root.getPath(); } else { return getParent().getPath().append(getElementName()); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.NameLookup.java
License:Open Source License
private ICompilationUnit findCompilationUnit(String[] pkgName, String cuName, PackageFragmentRoot root) { if (!root.isArchive()) { IPackageFragment pkg = root.getPackageFragment(pkgName); try {//w w w . j ava 2 s.c om ICompilationUnit[] cus = pkg.getCompilationUnits(); for (int j = 0, length = cus.length; j < length; j++) { ICompilationUnit cu = cus[j]; if (Util.equalsIgnoreJavaLikeExtension(cu.getElementName(), cuName)) return cu; } } catch (JavaModelException e) { // pkg does not exist // -> try next package } } return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.PackageFragment.java
License:Open Source License
/** * @see org.eclipse.jdt.core.IJavaElement#getPath() *//* w w w .j av a2 s . c om*/ public IPath getPath() { PackageFragmentRoot root = getPackageFragmentRoot(); if (root.isArchive()) { return root.getPath(); } else { IPath path = root.getPath(); for (int i = 0, length = this.names.length; i < length; i++) { String name = this.names[i]; path = path.append(name); } return path; } }
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 va 2s .com*/ * 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:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
protected IBinaryType getBinaryInfo(ClassFile classFile, IResource resource) throws CoreException { BinaryType binaryType = (BinaryType) classFile.getType(); if (classFile.isOpen()) return (IBinaryType) binaryType.getElementInfo(); // reuse the info from the java model cache // create a temporary info IBinaryType info;/*from ww w . java2 s.c o m*/ try { PackageFragment pkg = (PackageFragment) classFile.getParent(); PackageFragmentRoot root = (PackageFragmentRoot) pkg.getParent(); if (root.isArchive()) { // class file in a jar String classFileName = classFile.getElementName(); String classFilePath = Util.concatWith(pkg.names, classFileName, '/'); ZipFile zipFile = null; try { zipFile = ((JarPackageFragmentRoot) root).getJar(); info = ClassFileReader.read(zipFile, classFilePath); } finally { JavaModelManager.getJavaModelManager().closeZipFile(zipFile); } } else { // class file in a directory info = Util.newClassFileReader(resource); } if (info == null) throw binaryType.newNotPresentException(); return info; } catch (ClassFormatException e) { //e.printStackTrace(); return null; } catch (IOException e) { throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); } }
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
/** * @see IJavaElement// w ww . ja v a 2s. c o m */ public boolean exists() { if (manager.getInfo(this) != null) return true; switch (getElementType()) { case IJavaElement.PACKAGE_FRAGMENT: PackageFragmentRoot root = getPackageFragmentRoot(); if (root.isArchive()) { // pkg in a jar -> need to open root to know if this pkg exists JarPackageFragmentRootInfo rootInfo; try { rootInfo = (JarPackageFragmentRootInfo) root.getElementInfo(); } catch (JavaModelException e) { return false; } return rootInfo.rawPackageInfo.containsKey(((PackageFragment) this).names); } break; case IJavaElement.CLASS_FILE: if (getPackageFragmentRoot().isArchive()) { // class file in a jar -> need to open this class file to know if it exists return super.exists(); } break; } return validateExistence(resource()).isOK(); }
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); }