Java Code Examples for org.eclipse.core.filesystem.URIUtil#toURI()

The following examples show how to use org.eclipse.core.filesystem.URIUtil#toURI() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EclipseFileSystemSupportImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected java.net.URI toURI(final URI uri, final List<String> trailingSegments) {
  java.net.URI _xblockexpression = null;
  {
    final IResource resource = this.findMember(uri);
    if ((resource == null)) {
      String _lastSegment = uri.lastSegment();
      trailingSegments.add(_lastSegment);
      return this.toURI(uri.trimSegments(1), trailingSegments);
    }
    final Function2<IPath, String, IPath> _function = (IPath $0, String $1) -> {
      return $0.append($1);
    };
    _xblockexpression = URIUtil.toURI(IterableExtensions.<String, IPath>fold(ListExtensions.<String>reverse(trailingSegments), resource.getLocation(), _function));
  }
  return _xblockexpression;
}
 
Example 2
Source File: WebAppProjectCreator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
protected IProject createProject(IProgressMonitor monitor) throws CoreException {
  IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
  IProject project = workspaceRoot.getProject(projectName);
  if (!project.exists()) {
    URI uri;
    if (isWorkspaceRootLocationURI(locationURI)) {
      // If you want to put a project in the workspace root then the location
      // needs to be null...
      uri = null;
    } else {
      // Non-default paths need to include the project name
      IPath path = URIUtil.toPath(locationURI).append(projectName);
      uri = URIUtil.toURI(path);
    }

    BuildPathsBlock.createProject(project, uri, monitor);
  }
  return project;
}
 
Example 3
Source File: FileUtils.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private static IFile createLinkedFile(final String path, final IFile file) {
	java.net.URI resolvedURI = null;
	final java.net.URI javaURI = URIUtil.toURI(path);// new java.io.File(path).toURI();

	try {
		resolvedURI = ROOT.getPathVariableManager().convertToRelative(javaURI, true, null);
	} catch (final CoreException e1) {
		resolvedURI = javaURI;
	}
	try {
		file.createLink(resolvedURI, IResource.NONE, null);
	} catch (final CoreException e) {
		e.printStackTrace();
		return null;
	}
	return file;
}
 
Example 4
Source File: UIUtils.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the URI for the specific editor input.
 * 
 * @param input
 *            the editor input
 * @return the URI, or null if none could be determined
 */
public static URI getURI(IEditorInput input)
{
	if (input instanceof IFileEditorInput)
	{
		return ((IFileEditorInput) input).getFile().getLocationURI();
	}
	if (input instanceof IURIEditorInput)
	{
		return ((IURIEditorInput) input).getURI();
	}
	if (input instanceof IPathEditorInput)
	{
		return URIUtil.toURI(((IPathEditorInput) input).getPath());
	}
	return null;
}
 
Example 5
Source File: JReFrameworker.java    From JReFrameworker with MIT License 5 votes vote down vote up
private static URI getProjectLocation(String projectName, IPath projectPath) {
	URI location = null;
	if (projectPath != null){
		location = URIUtil.toURI(projectPath);
	}
	if (location != null && ResourcesPlugin.getWorkspace().getRoot().getLocationURI().equals(location)) {
		location = null;
	} else {
		location = URIUtil.toURI(URIUtil.toPath(location) + File.separator + projectName);
	}
	return location;
}
 
Example 6
Source File: WebAppProjectCreator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
protected WebAppProjectCreator() {
  // Always a java project
  natureIds.add(JavaCore.NATURE_ID);

  // Initialize location URI to the workspace
  IPath workspaceLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation();
  if (workspaceLoc != null) {
    locationURI = URIUtil.toURI(workspaceLoc);
  }
}
 
Example 7
Source File: BinaryRefactoringHistoryWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the location URI of the classpath entry
 *
 * @param entry
 *            the classpath entry
 * @return the location URI
 */
public static URI getLocationURI(final IClasspathEntry entry) {
	IPath path= null;
	if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE)
		path= JavaCore.getResolvedVariablePath(entry.getPath());
	else
		path= entry.getPath();
	final IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
	URI location= null;
	if (root.exists(path)) {
		location= root.getFile(path).getRawLocationURI();
	} else
		location= URIUtil.toURI(path);
	return location;
}
 
Example 8
Source File: NewJavaProjectWizardPageOne.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the current project location path as entered by the user, or <code>null</code>
 * if the project should be created in the workspace.

 * @return the project location path or its anticipated initial value.
 */
public URI getProjectLocationURI() {
	if (fLocationGroup.isUseDefaultSelected()) {
		return null;
	}
	return URIUtil.toURI(fLocationGroup.getLocation());
}
 
Example 9
Source File: MainProjectWizardPage.java    From sarl with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the current project location path as entered by the user, or {@code null} if
 * the project should be created in the workspace.
 *
 * @return the project location path or its anticipated initial value.
 */
public URI getProjectLocationURI() {
	if (this.locationGroup.isUseDefaultSelected()) {
		return null;
	}
	return URIUtil.toURI(this.locationGroup.getLocation());
}
 
Example 10
Source File: EditorUtil.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets the URI associated with the editor.
 * 
 * @param editor
 * @return
 */
public static URI getURI(IEditorPart editor)
{
	// NOTE: Moved from CommonContentAssistProcessor
	if (editor != null)
	{
		IEditorInput editorInput = editor.getEditorInput();

		if (editorInput instanceof IURIEditorInput)
		{
			IURIEditorInput uriEditorInput = (IURIEditorInput) editorInput;
			return uriEditorInput.getURI();
		}
		if (editorInput instanceof IPathEditorInput)
		{
			IPathEditorInput pathEditorInput = (IPathEditorInput) editorInput;
			return URIUtil.toURI(pathEditorInput.getPath());
		}
		if (editorInput instanceof IFileEditorInput)
		{
			IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
			return fileEditorInput.getFile().getLocationURI();
		}
		try
		{
			if (editorInput instanceof IStorageEditorInput)
			{
				IStorageEditorInput storageEditorInput = (IStorageEditorInput) editorInput;
				IStorage storage = storageEditorInput.getStorage();
				if (storage != null)
				{
					IPath path = storage.getFullPath();
					if (path != null)
					{
						return URIUtil.toURI(path);
					}
				}
			}
		}
		catch (CoreException e)
		{
			IdeLog.logError(CommonEditorPlugin.getDefault(), e);
		}
		if (editorInput instanceof ILocationProviderExtension)
		{
			ILocationProviderExtension lpe = (ILocationProviderExtension) editorInput;
			return lpe.getURI(null);
		}
		if (editorInput instanceof ILocationProvider)
		{
			ILocationProvider lp = (ILocationProvider) editorInput;
			return URIUtil.toURI(lp.getPath(null));
		}
	}

	return null;
}
 
Example 11
Source File: CpplintChecker.java    From CppStyle with MIT License 4 votes vote down vote up
private ErrorParserManager createErrorParserManager(InvocationParameters parameters) {
	IProject project = parameters.getActualFile().getProject();
	URI workingDirectory = URIUtil.toURI(parameters.getWorkingDirectory());
	return new ErrorParserManager(project, workingDirectory, this, getParserIDs());
}