当前位置: 首页>>代码示例>>Java>>正文


Java IPath.segmentCount方法代码示例

本文整理汇总了Java中org.eclipse.core.runtime.IPath.segmentCount方法的典型用法代码示例。如果您正苦于以下问题:Java IPath.segmentCount方法的具体用法?Java IPath.segmentCount怎么用?Java IPath.segmentCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.core.runtime.IPath的用法示例。


在下文中一共展示了IPath.segmentCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getConflictingContainerNameFor

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
/**
 * Returns the name of a container with a location that encompasses targetDirectory. Returns null if there is no
 * conflict.
 *
 * @param targetDirectory
 *            the path of the directory to check.
 * @return the conflicting container name or <code>null</code>
 */
private String getConflictingContainerNameFor(String targetDirectory) {

	IPath rootPath = ResourcesPlugin.getWorkspace().getRoot().getLocation();
	IPath testPath = new Path(targetDirectory);
	// cannot export into workspace root
	if (testPath.equals(rootPath))
		return rootPath.lastSegment();

	// Are they the same?
	if (testPath.matchingFirstSegments(rootPath) == rootPath.segmentCount()) {
		String firstSegment = testPath.removeFirstSegments(rootPath.segmentCount()).segment(0);
		if (!Character.isLetterOrDigit(firstSegment.charAt(0)))
			return firstSegment;
	}

	return null;

}
 
开发者ID:eclipse,项目名称:n4js,代码行数:27,代码来源:AbstractExportToSingleFileWizardPage.java

示例2: ensureFolderPath

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
public static IResource ensureFolderPath(IPath path) throws CoreException {
	IPath p = path;
	List<IPath> list = new ArrayList<IPath>();
	while (p.segmentCount() > 0) {
		IResource resource = getWorkspaceRoot().findMember(p);
		if (resource == null) {
			list.add((IPath) p.clone());
		} else {
			break;
		}
		p = p.removeLastSegments(1);
	}
	for (int i = list.size() - 1; i >= 0; i--) {
		IFolder folder = (IFolder) getWorkspaceRoot().findMember(p);
		IPath pth = list.get(i);
		folder = folder.getFolder(pth.lastSegment());
		folder.create(true, true, new NullProgressMonitor());
		p = pth;
	}

	return getWorkspaceRoot().findMember(path);
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:23,代码来源:ResourceManager.java

示例3: createFile

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
public static IFile createFile(IProject project, IFile file, InputStream contentStream, IProgressMonitor monitor) throws CoreException {
	if (!file.exists()) 
	{
		IPath path = file.getProjectRelativePath();
		if (path.segmentCount() > 1) {
			IPath currentFolderPath = new Path("");
			for (int i=0; i<path.segmentCount()-1; i++) {
				currentFolderPath = currentFolderPath.append(path.segment(i));
				createFolder(project, currentFolderPath, monitor);
			}				
		}
		try
		{
			file.create(contentStream, true, monitor);
		}
		finally
		{
			try {
				contentStream.close();
			} catch (IOException e) {
				throw new CoreException(new Status(Status.ERROR, "", "Could not close stream for file " + file.getFullPath(), e));
			}
		}
	}
	return file;
}
 
开发者ID:eclipse,项目名称:gemoc-studio,代码行数:27,代码来源:IProjectUtils.java

示例4: containerForPath

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
/** Return the container with the given path */
private IContainer containerForPath(IPath path) {
	if (path.segmentCount() == 1) {
		return workspaceRoot.getProject(path.segment(0));
	} else {
		return workspaceRoot.getFolder(path);
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:9,代码来源:ModuleSpecifierSelectionDialog.java

示例5: isValid

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
@Override
public String isValid(String newText) {
	IPath path = new Path(newText);
	String fileExtension = path.getFileExtension();
	String moduleName = path.removeFileExtension().lastSegment();

	if (path.removeFileExtension().segmentCount() < 1 || moduleName.isEmpty()) {
		return "The module name must not be empty.";
	}

	if (!isValidFolderName(path.removeFileExtension().toString())) {
		return "The module name is not a valid file system name.";
	}

	if (fileExtension == null) {
		return "The module name needs to have a valid N4JS file extension.";
	}
	if (!(fileExtension.equals(N4JSGlobals.N4JS_FILE_EXTENSION) ||
			fileExtension.equals(N4JSGlobals.N4JSD_FILE_EXTENSION))) {
		return "Invalid file extension.";
	}
	if (!isModuleFileSpecifier(path)) {
		return "Invalid module file specifier.";
	}
	if (path.segmentCount() > 1) {
		return IPath.SEPARATOR + " is not allowed in a module file specifier.";
	}
	if (treeViewer.getStructuredSelection().getFirstElement() == null) {
		return "Please select a module container";
	}

	return null;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:34,代码来源:ModuleSpecifierSelectionDialog.java

示例6: updateProposalContext

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
/**
 * This method should be invoked whenever source folder or project value change, to update the proposal contexts for
 * the field source folder and module specifier
 */
private void updateProposalContext() {
	IPath projectPath = model.getProject();
	IPath sourceFolderPath = model.getSourceFolder();

	// Early exit for empty project value
	if (projectPath.isEmpty()) {
		sourceFolderContentProposalAdapter.setContentProposalProvider(null);
		moduleSpecifierContentProposalAdapter.setContentProposalProvider(null);
		return;
	}

	IProject project = ResourcesPlugin.getWorkspace().getRoot()
			.getProject(projectPath.toString());

	if (null == project || !project.exists()) {
		// Disable source folder and module specifier proposals
		sourceFolderContentProposalAdapter.setContentProposalProvider(null);
		moduleSpecifierContentProposalAdapter.setContentProposalProvider(null);
	} else {
		// Try to retrieve the source folder and if not specified set it to null
		IContainer sourceFolder = sourceFolderPath.segmentCount() != 0 ? project.getFolder(sourceFolderPath) : null;

		// If the project exists, enable source folder proposals
		sourceFolderContentProposalAdapter
				.setContentProposalProvider(sourceFolderContentProviderFactory.createProviderForProject(project));

		if (null != sourceFolder && sourceFolder.exists()) {
			// If source folder exists as well enable module specifier proposal
			moduleSpecifierContentProposalAdapter.setContentProposalProvider(
					moduleSpecifierContentProviderFactory.createProviderForPath(sourceFolder.getFullPath()));
		} else {
			// Otherwise disable module specifier proposals
			moduleSpecifierContentProposalAdapter.setContentProposalProvider(null);
		}
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:41,代码来源:WorkspaceWizardPage.java

示例7: pathStartsWithFolder

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
private boolean pathStartsWithFolder(IPath fullPath, IContainer container) {
	IPath containerPath = container.getFullPath();
	int maxSegments = containerPath.segmentCount();
	if (fullPath.segmentCount() >= maxSegments) {
		for (int j = 0; j < maxSegments; j++) {
			if (!fullPath.segment(j).equals(containerPath.segment(j))) {
				return false;
			}
		}
		return true;
	}
	return false;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:14,代码来源:N4JSEclipseModel.java

示例8: getParentProject

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
public IContainer getParentProject(IContainer project) {
    IPath location = project.getRawLocation();
    if (location != null && location.segmentCount() > 1) {
        String parentName = location.removeLastSegments(1).lastSegment();
        if (parentName != null && ! parentName.isEmpty()) {
            return Stream.of(ResourcesPlugin.getWorkspace().getRoot().getProjects())
                    .filter(p -> p.getName().equals(parentName))
                    .map(IContainer.class::cast)
                    .findFirst().orElse(null);
        }
        return null;
    }
    return null;
}
 
开发者ID:gluonhq,项目名称:ide-plugins,代码行数:15,代码来源:ProjectUtils.java

示例9: createFolder

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
public static IFolder createFolder(IPath parentPath, IPath folder) throws CoreException {
	IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot();
	IFolder pf = wroot.getFolder(parentPath);
	int max = folder.segmentCount();
	IFolder childFolder = pf;
	for (int i = 0; i < max; i++) {
		childFolder = childFolder.getFolder(folder.segment(i));
		childFolder.create(IResource.NONE, true, new NullProgressMonitor());
	}
	return childFolder;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:12,代码来源:ResourceManager.java

示例10: createFolder

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
/**
 * Create recursively folders in the project.
 * Do nothing if folder already exists.
 * @param project
 * @param path
 * @param monitor
 * @return
 * @throws CoreException
 */
public static IFolder createFolder(IProject project, IPath path, IProgressMonitor monitor) throws CoreException {
	IFolder folder = project.getFolder(path);
	if (!folder.exists()) {
		if (path.segmentCount() > 1) {
			IPath currentFolderPath = new Path("");
			for (int i=0; i<path.segmentCount()-1; i++) {
				currentFolderPath = currentFolderPath.append(path.segment(i));
				createFolder(project, currentFolderPath, monitor);
			}				
		}
		folder.create(true, true, monitor);
	}
	return folder;
}
 
开发者ID:eclipse,项目名称:gemoc-studio,代码行数:24,代码来源:IProjectUtils.java

示例11: getTemplateURI

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
/**
 * Finds the template in the plug-in. Returns the template plug-in URI.
 * 
 * @param bundleID
 *            is the plug-in ID
 * @param relativePath
 *            is the relative path of the template in the plug-in
 * @return the template URI
 * @throws IOException
 * @generated
 */
@SuppressWarnings("unchecked")
private URI getTemplateURI(String bundleID, IPath relativePath) throws IOException {
	Bundle bundle = Platform.getBundle(bundleID);
	if (bundle == null) {
		// no need to go any further
		return URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(), false);
	}
	URL url = bundle.getEntry(relativePath.toString());
	if (url == null && relativePath.segmentCount() > 1) {
		Enumeration<URL> entries = bundle.findEntries("/", "*.emtl", true);
		if (entries != null) {
			String[] segmentsRelativePath = relativePath.segments();
			while (url == null && entries.hasMoreElements()) {
				URL entry = entries.nextElement();
				IPath path = new Path(entry.getPath());
				if (path.segmentCount() > relativePath.segmentCount()) {
					path = path.removeFirstSegments(path.segmentCount() - relativePath.segmentCount());
				}
				String[] segmentsPath = path.segments();
				boolean equals = segmentsPath.length == segmentsRelativePath.length;
				for (int i = 0; equals && i < segmentsPath.length; i++) {
					equals = segmentsPath[i].equals(segmentsRelativePath[i]);
				}
				if (equals) {
					url = bundle.getEntry(entry.getPath());
				}
			}
		}
	}
	URI result;
	if (url != null) {
		result = URI.createPlatformPluginURI(new Path(bundleID).append(new Path(url.getPath())).toString(), false);
	} else {
		result = URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(), false);
	}
	return result;
}
 
开发者ID:occiware,项目名称:OCCI-Studio,代码行数:49,代码来源:GenerateAll.java

示例12: getProposals

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
@Override
public IContentProposal[] getProposals(String contents, int position) {
	IContainer proposalRootFolder;

	if (null == rootFolder) {
		return EMPTY_PROPOSAL;
	}

	if (rootFolder.isEmpty()) {
		proposalRootFolder = ResourcesPlugin.getWorkspace().getRoot();
	} else if (rootFolder.segmentCount() == 1) {
		proposalRootFolder = ResourcesPlugin.getWorkspace().getRoot().getProject(rootFolder.segment(0));
	} else {
		proposalRootFolder = findContainerForPath(rootFolder);
	}

	if (null == proposalRootFolder || !proposalRootFolder.exists()) {
		return EMPTY_PROPOSAL;
	}

	// The field content as path
	IPath contentsPath = new Path(contents);

	// The directory to look for prefix matches
	IPath workingDirectoryPath;

	// If the contents path has a trailing separator...
	if (contentsPath.hasTrailingSeparator()) {
		// Use the full content as working directory path
		workingDirectoryPath = contentsPath;
	} else {
		// Otherwise only use complete segments as working directory
		workingDirectoryPath = contentsPath.removeLastSegments(1);
	}

	IContainer workingDirectory;

	if (workingDirectoryPath.segmentCount() > 0) {
		workingDirectory = proposalRootFolder.getFolder(workingDirectoryPath);
	} else {
		workingDirectory = proposalRootFolder;
	}

	// Return an empty proposal list for non-existing working directories
	if (null == workingDirectory || !workingDirectory.exists()) {
		return EMPTY_PROPOSAL;
	}
	try {
		return Arrays.asList(workingDirectory.members()).stream()
				// Only work with files and folders
				.filter(r -> (r instanceof IFile || r instanceof IFolder))
				// Filter by prefix matching
				.filter(resource -> {
					IPath rootRelativePath = resource.getFullPath().makeRelativeTo(rootFolder);
					return rootRelativePath.toString().startsWith(contentsPath.toString());
				})
				// Transform to a ModuleSpecifierProposal
				.map(resource -> {
					// Create proposal path
					IPath proposalPath = resource.getFullPath()
							.makeRelativeTo(proposalRootFolder.getFullPath());
					// Set the proposal type
					ModuleSpecifierProposal.ModuleProposalType type = resource instanceof IFile
							? ModuleSpecifierProposal.ModuleProposalType.MODULE
							: ModuleSpecifierProposal.ModuleProposalType.FOLDER;
					// Create a new module specifier proposal
					return ModuleSpecifierProposal.createFromPath(proposalPath, type);
				})
				.toArray(IContentProposal[]::new);
	} catch (CoreException e) {
		return EMPTY_PROPOSAL;
	}

}
 
开发者ID:eclipse,项目名称:n4js,代码行数:75,代码来源:ModuleSpecifierContentProposalProviderFactory.java

示例13: queryOverwrite

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
/**
 * The default implementation of this <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 *
 * @param pathString
 *            the path of the archive
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>, <code>"ALL"</code>, or
 *         <code>"CANCEL"</code>
 */
@Override
public String queryOverwrite(String pathString) {

	IPath path = Path.fromOSString(pathString);

	String messageString;
	// Break the message up if there is a file name and a directory
	// and there are at least 2 segments.
	if (path.getFileExtension() == null || path.segmentCount() < 2) {
		messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
	} else {
		messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
				path.lastSegment(),
				path.removeLastSegments(1).toOSString());
	}

	final MessageDialog dialog = new MessageDialog(getContainer()
			.getShell(), IDEWorkbenchMessages.Question,
			null, messageString, MessageDialog.QUESTION, new String[] {
		IDialogConstants.YES_LABEL,
		IDialogConstants.YES_TO_ALL_LABEL,
		IDialogConstants.NO_LABEL,
		IDialogConstants.NO_TO_ALL_LABEL,
		IDialogConstants.CANCEL_LABEL }, 0) {
		@Override
		protected int getShellStyle() {
			return super.getShellStyle() | SWT.SHEET;
		}
	};
	String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
	// run in syncExec because callback is from an operation,
	// which is probably not running in the UI thread.
	getControl().getDisplay().syncExec(new Runnable() {
		@Override
		public void run() {
			dialog.open();
		}
	});
	return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:50,代码来源:AbstractExportToSingleFileWizardPage.java

示例14: getTemplateURI

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
/**
 * Finds the template in the plug-in. Returns the template plug-in URI.
 * 
 * @param bundleID
 *            is the plug-in ID
 * @param relativePath
 *            is the relative path of the template in the plug-in
 * @return the template URI
 * @throws IOException
 * @generated
 */
@SuppressWarnings ( "unused" )
private URI getTemplateURI ( final String bundleID, final IPath relativePath ) throws IOException
{
    final Bundle bundle = Platform.getBundle ( bundleID );
    if ( bundle == null )
    {
        // no need to go any further 
        return URI.createPlatformResourceURI ( new Path ( bundleID ).append ( relativePath ).toString (), false );
    }
    URL url = bundle.getEntry ( relativePath.toString () );
    if ( url == null && relativePath.segmentCount () > 1 )
    {
        final Enumeration<URL> entries = bundle.findEntries ( "/", "*.emtl", true );
        if ( entries != null )
        {
            final String[] segmentsRelativePath = relativePath.segments ();
            while ( url == null && entries.hasMoreElements () )
            {
                final URL entry = entries.nextElement ();
                IPath path = new Path ( entry.getPath () );
                if ( path.segmentCount () > relativePath.segmentCount () )
                {
                    path = path.removeFirstSegments ( path.segmentCount () - relativePath.segmentCount () );
                }
                final String[] segmentsPath = path.segments ();
                boolean equals = segmentsPath.length == segmentsRelativePath.length;
                for ( int i = 0; equals && i < segmentsPath.length; i++ )
                {
                    equals = segmentsPath[i].equals ( segmentsRelativePath[i] );
                }
                if ( equals )
                {
                    url = bundle.getEntry ( entry.getPath () );
                }
            }
        }
    }
    URI result;
    if ( url != null )
    {
        result = URI.createPlatformPluginURI ( new Path ( bundleID ).append ( new Path ( url.getPath () ) ).toString (), false );
    }
    else
    {
        result = URI.createPlatformResourceURI ( new Path ( bundleID ).append ( relativePath ).toString (), false );
    }
    return result;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:60,代码来源:GenerateAll.java

示例15: buildFiles

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
public static PgDatabase buildFiles(Collection<IFile> files, IProgressMonitor monitor,
        List<FunctionBodyContainer> funcBodies) throws InterruptedException, IOException, CoreException {
    SubMonitor mon = SubMonitor.convert(monitor, files.size());
    Set<String> schemaDirnamesLoaded = new HashSet<>();
    IPath schemasPath = new Path(WORK_DIR_NAMES.SCHEMA.name());
    PgDatabase db = new PgDatabase(false);
    db.setArguments(new PgDiffArguments());

    for (IFile file : files) {
        IPath filePath = file.getProjectRelativePath();
        if (!"sql".equals(file.getFileExtension()) || !isInProject(filePath)) { //$NON-NLS-1$
            // skip non-sql or non-project files
            // still report work
            mon.worked(1);
            continue;
        }

        if (schemasPath.isPrefixOf(filePath)) {
            IPath relSchemasPath = filePath.makeRelativeTo(schemasPath);
            String schemaDirname;
            boolean schemaDefSql = relSchemasPath.segmentCount() == 1;
            if (schemaDefSql) {
                // schema definition SQL-file
                schemaDirname = relSchemasPath.removeFileExtension().lastSegment();
            } else {
                // schema-contained object
                // preload its schema so that search_path parses normally
                schemaDirname = relSchemasPath.segment(0);
            }
            if (!schemaDirnamesLoaded.add(schemaDirname)) {
                // schema already loaded, skip
                if (schemaDefSql) {
                    // report schema pre-built if the same schema was to be built normally as well
                    mon.worked(1);
                }
                continue;
            } else if (!schemaDefSql) {
                // pre-load schema for object's search path
                // otherwise we're dealing with the schema file itself, allow it to load normally
                // don't pass progress monitor since this file isn't in the original load-set
                loadFile(file.getProject().getFile(schemasPath.append(schemaDirname + ".sql")), //$NON-NLS-1$
                        null, db, funcBodies, null);
            }
        }

        loadFile(file, mon, db, funcBodies, null);
    }
    return db;
}
 
开发者ID:pgcodekeeper,项目名称:pgcodekeeper,代码行数:50,代码来源:PgUIDumpLoader.java


注:本文中的org.eclipse.core.runtime.IPath.segmentCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。