private DirectoryNode getAnnotationBase(DirectoryNode current, IPath annotationBase, int baseDepth, int nextDepth) { IPath nextHead = annotationBase.uptoSegment(nextDepth); Map<IPath, DirectoryNode> children = current.getChildren(); // create if necessary DirectoryNode nextHeadNode = children.get(nextHead); if (nextHeadNode == null) children.put(nextHead, nextHeadNode = new DirectoryNode(current, nextHead)); if (baseDepth == nextDepth) return nextHeadNode; return getAnnotationBase(nextHeadNode, annotationBase, baseDepth, nextDepth+1); }
private DirectoryNode getAnnotationBase(DirectoryNode current, IPath annotationBase, int baseDepth, int nextDepth) { IPath nextHead = annotationBase.uptoSegment(nextDepth); Map<IPath, DirectoryNode> children = current.getChildren(); // create if necessary DirectoryNode nextHeadNode = children.get(nextHead); if (nextHeadNode == null) children.put(nextHead, nextHeadNode = new DirectoryNode(current, nextHead)); if (baseDepth == nextDepth) return nextHeadNode; return getAnnotationBase(nextHeadNode, annotationBase, baseDepth, nextDepth+1); }
private DirectoryNode getAnnotationBase(DirectoryNode current, IPath annotationBase, int baseDepth, int nextDepth) { IPath nextHead = annotationBase.uptoSegment(nextDepth); Map<IPath, DirectoryNode> children = current.getChildren(); // create if necessary DirectoryNode nextHeadNode = children.get(nextHead); if (nextHeadNode == null) children.put(nextHead, nextHeadNode = new DirectoryNode(current, nextHead)); if (baseDepth == nextDepth) return nextHeadNode; return getAnnotationBase(nextHeadNode, annotationBase, baseDepth, nextDepth+1); }
/** * Replace the current JRE container classpath with the given entry. * * @param cp * @param entry */ public static void replaceJREContainer(List cp, IRuntimeClasspathEntry entry) { int size = cp.size(); for (int i = 0; i < size; i++) { IRuntimeClasspathEntry entry2 = (IRuntimeClasspathEntry) cp.get(i); if (entry2.getPath().uptoSegment(2).isPrefixOf(entry.getPath())) { cp.set(i, entry); return; } } cp.add(0, entry); }
/** * Initializes this object's children table based on the contents of * the specified source file. */ protected void initialize() { children = new HashMap(1000); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); if (!entry.isDirectory()) { IPath path = new Path(entry.getName()).addTrailingSeparator(); int pathSegmentCount = path.segmentCount(); for (int i = 1; i < pathSegmentCount; i++) { createContainer(path.uptoSegment(i)); } createFile(entry); } } }
/** * Initializes this object's children table based on the contents of the * specified source file. */ protected void initialize() { children = new HashMap(1000); children.put(root, new ArrayList()); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); IPath path = new Path(entry.getName()).addTrailingSeparator(); if (entry.isDirectory()) { createContainer(path); } else { // Ensure the container structure for all levels above this is initialized // Once we hit a higher-level container that's already added we need go no further int pathSegmentCount = path.segmentCount(); if (pathSegmentCount > 1) { createContainer(path.uptoSegment(pathSegmentCount - 1)); } createFile(entry); } } }
/** * @see AbstractJavaSearchScope#packageFragmentRoot(String, int, String) */ @Override public IPackageFragmentRoot packageFragmentRoot(String resourcePathString, int jarSeparatorIndex, String jarPath) { Map<IPath, RootInfo> rootInfos = JavaModelManager.getDeltaState().roots; DeltaProcessor.RootInfo rootInfo = null; if (jarPath != null) { IPath path = new Path(jarPath); rootInfo = rootInfos.get(path); } else { IPath path = new Path(resourcePathString); if (ExternalFoldersManager.isInternalPathForExternalFolder(path)) { IResource resource = JavaModel.getWorkspaceTarget(path.uptoSegment(2/*linked folders for external folders are always of size 2*/)); if (resource != null) rootInfo = rootInfos.get(resource.getLocation()); } else { rootInfo = rootInfos.get(path); while (rootInfo == null && path.segmentCount() > 0) { path = path.removeLastSegments(1); rootInfo = rootInfos.get(path); } } } if (rootInfo == null) return null; return rootInfo.getPackageFragmentRoot(null/*no resource hint*/); }
/** * @see AbstractJavaSearchScope#packageFragmentRoot(String, int, String) */ public IPackageFragmentRoot packageFragmentRoot(String resourcePathString, int jarSeparatorIndex, String jarPath) { HashMap rootInfos = JavaModelManager.getDeltaState().roots; DeltaProcessor.RootInfo rootInfo = null; if (jarPath != null) { IPath path = new Path(jarPath); rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path); } else { IPath path = new Path(resourcePathString); if (ExternalFoldersManager.isInternalPathForExternalFolder(path)) { IResource resource = JavaModel.getWorkspaceTarget(path.uptoSegment(2/*linked folders for external folders are always of size 2*/)); if (resource != null) rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(resource.getLocation()); } else { rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path); while (rootInfo == null && path.segmentCount() > 0) { path = path.removeLastSegments(1); rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path); } } } if (rootInfo == null) return null; return rootInfo.getPackageFragmentRoot(null/*no resource hint*/); }
/** * @see AbstractJavaSearchScope#packageFragmentRoot(String, int, String) */ public IPackageFragmentRoot packageFragmentRoot(String resourcePathString, int jarSeparatorIndex, String jarPath) { HashMap rootInfos = JavaModelManager.getDeltaState().roots; DeltaProcessor.RootInfo rootInfo = null; if (jarPath != null) { IPath path = new Path(jarPath); rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path); } else { IPath path = new Path(resourcePathString); if (ExternalFoldersManager.isInternalPathForExternalFolder(path)) { IResource resource = JavaModel.getWorkspaceTarget(path.uptoSegment(2/*linked folders for external folders are always of size 2*/)); if (resource != null) rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(resource.getLocation()); } else { rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path); while (rootInfo == null && path.segmentCount() > 0) { path = path.removeLastSegments(1); rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path); } } } if (rootInfo == null) return null; return rootInfo.getPackageFragmentRoot(null/*no resource hint*/); }
private IPath getFolderPath(IPath packPath, IPath relpath) { int remainingSegments= packPath.segmentCount() - relpath.segmentCount(); if (remainingSegments >= 0) { IPath common= packPath.removeFirstSegments(remainingSegments); if (common.equals(relpath)) { return packPath.uptoSegment(remainingSegments); } } return null; }
/** * @see AbstractJavaSearchScope#packageFragmentRoot(String, int, String) */ public IPackageFragmentRoot packageFragmentRoot(String resourcePathString, int jarSeparatorIndex, String jarPath) { HashMap rootInfos = JavaModelManager.getDeltaState().roots; DeltaProcessor.RootInfo rootInfo = null; if (jarPath != null) { IPath path = new Path(jarPath); rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path); } else { IPath path = new Path(resourcePathString); if (ExternalFoldersManager.isInternalPathForExternalFolder(path)) { IResource resource = JavaModel.getWorkspaceTarget(path.uptoSegment(2/*linked folders for external folders are always of size 2*/)); if (resource != null) rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(resource.getLocation()); } else { rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path); while (rootInfo == null && path.segmentCount() > 0) { path = path.removeLastSegments(1); rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path); } } } if (rootInfo == null) return null; return rootInfo.getPackageFragmentRoot(null/*no resource hint*/); }
private IPath getFolderPath(IPath packPath, IPath relpath) { int remainingSegments= packPath.segmentCount() - relpath.segmentCount(); if (remainingSegments >= 0) { IPath common= packPath.removeFirstSegments(remainingSegments); if (common.equals(relpath)) { return packPath.uptoSegment(remainingSegments); } } return null; }
/** * Initializes this object's children table based on the contents of the * specified source file. */ protected void initialize() { children = new HashMap(1000); children.put(root, new ArrayList()); Enumeration entries = tarFile.entries(); while (entries.hasMoreElements()) { TarEntry entry = (TarEntry) entries.nextElement(); IPath path = new Path(entry.getName()).addTrailingSeparator(); if (entry.getFileType() == TarEntry.DIRECTORY) { createContainer(path); } else { // Ensure the container structure for all levels above this is initialized // Once we hit a higher-level container that's already added we need go no further int pathSegmentCount = path.segmentCount(); if (pathSegmentCount > 1) { createContainer(path.uptoSegment(pathSegmentCount - 1)); } createFile(entry); } } }
private IPath getFolderPath(IPath packPath, IPath relpath) { int remainingSegments= packPath.segmentCount() - relpath.segmentCount(); if (remainingSegments >= 0) { IPath common= packPath.removeFirstSegments(remainingSegments); if (common.equals(relpath)) { return packPath.uptoSegment(remainingSegments); } } return null; }
private IFolder generateJavaSourceFolder(IFolder sourceFolder, IProgressMonitor monitor) throws CoreException { Object packageValue = getValue(KEY_PACKAGE_NAME); String packageName = packageValue != null ? packageValue.toString() : null; if (packageName == null) packageName = model.getPluginBase().getId(); IPath path = new Path(packageName.replace('.', File.separatorChar)); if (sourceFolder != null) path = sourceFolder.getProjectRelativePath().append(path); for (int i = 1; i <= path.segmentCount(); i++) { IPath subpath = path.uptoSegment(i); IFolder subfolder = project.getFolder(subpath); if (subfolder.exists() == false) subfolder.create(true, true, monitor); } return project.getFolder(path); }
public static boolean ensureProjectExists(String workspacePath, Object object, Object projectType, boolean force, Monitor monitor) { try { IPath path = new Path(workspacePath); if (path.isAbsolute()) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = workspace.getRoot().getProject(path.segment(0)); if (!project.exists() || force) { IPath javaSource = path.uptoSegment(1).append("src"); org.eclipse.emf.codegen.ecore.Generator.createEMFProject (javaSource, null, Collections.<IProject>emptyList(), monitor, org.eclipse.emf.codegen.ecore.Generator.EMF_PLUGIN_PROJECT_STYLE); } return workspace.getRoot().getProject(path.segment(0)).exists(); } } catch (Exception exception) { CodeGenEcorePlugin.INSTANCE.log(exception); } return false; }
private IFolder generateJavaSourceFolder(IFolder sourceFolder, IProgressMonitor monitor) throws CoreException { Object packageValue = getValue(KEY_PACKAGE_NAME); // String packageName = packageValue != null ? packageValue.toString() : null; if (packageName == null) packageName = fModel.getPluginBase().getId(); IPath path = new Path(packageName.replace('.', File.separatorChar)); if (sourceFolder != null) path = sourceFolder.getProjectRelativePath().append(path); for (int i = 1; i <= path.segmentCount(); i++) { IPath subpath = path.uptoSegment(i); IFolder subfolder = fProject.getFolder(subpath); if (subfolder.exists() == false) subfolder.create(true, true, monitor); } return fProject.getFolder(path); }
@Override public String getText(Object obj) { IClasspathEntry entry = (IClasspathEntry) obj; int kind = entry.getEntryKind(); if (kind == IClasspathEntry.CPE_PROJECT) return entry.getPath().segment(0); IPath path = entry.getPath(); String name = path.lastSegment(); return name + " - " //$NON-NLS-1$ + path.uptoSegment(path.segmentCount() - 1).toOSString(); }
protected IFile createPath(IContainer container, IPath path) throws CoreException { if (path.segmentCount() > 1) { IContainer childContainer; if (container instanceof IWorkspaceRoot) { IProject project = ((IWorkspaceRoot)container).getProject(path.segment(0)); if (!project.exists()) project.create(null); if (!project.isOpen()) project.open(null); childContainer = project; } else { IFolder f= container.getFolder(path.uptoSegment(1)); if (!f.exists()) f.create(false, true, null); childContainer = f; } return createPath(childContainer, path.removeFirstSegments(1)); } // a leaf return container.getFile(path); }
protected IFile createPath(IContainer container, IPath path) throws CoreException { if (path.segmentCount() > 1) { IContainer childContainer; if (container instanceof IWorkspaceRoot) { IProject project = ((IWorkspaceRoot)container).getProject(path.segment(0)); if (!project.exists()) project.create(null); if (!project.isOpen()) project.open(null); childContainer = project; } else { IFolder f= container.getFolder(path.uptoSegment(1)); if (!f.exists()) f.create(false, true, null); childContainer = f; } return createPath(childContainer, path.removeFirstSegments(1)); } // a leaf return container.getFile(path); }