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

The following examples show how to use org.eclipse.core.filesystem.URIUtil#toPath() . 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: FilenameDifferentiator.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private IPath getPath(IEditorPart otherEditor)
{
	IEditorInput input = otherEditor.getEditorInput();
	try
	{
		if (input instanceof IPathEditorInput)
		{
			return ((IPathEditorInput) input).getPath();
		}

		URI uri = (URI) input.getAdapter(URI.class);
		if (uri != null)
		{
			return new Path(uri.getHost() + Path.SEPARATOR + uri.getPath());
		}
		if (input instanceof IURIEditorInput)
		{
			return URIUtil.toPath(((IURIEditorInput) input).getURI());
		}
	}
	catch (Exception e)
	{
	}
	return null;
}
 
Example 2
Source File: JarImportWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the target path to be used for the updated classpath entry.
 *
 * @param entry
 *            the classpath entry
 * @return the target path, or <code>null</code>
 * @throws CoreException
 *             if an error occurs
 */
private IPath getTargetPath(final IClasspathEntry entry) throws CoreException {
	final URI location= getLocationURI(entry);
	if (location != null) {
		final URI target= getTargetURI(location);
		if (target != null) {
			IPath path= URIUtil.toPath(target);
			if (path != null) {
				final IPath workspace= ResourcesPlugin.getWorkspace().getRoot().getLocation();
				if (workspace.isPrefixOf(path)) {
					path= path.removeFirstSegments(workspace.segmentCount());
					path= path.setDevice(null);
					path= path.makeAbsolute();
				}
			}
			return path;
		}
	}
	return null;
}
 
Example 3
Source File: StandardSREInstallTest.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	this.preferences = new EclipsePreferences();
	this.plugin = spy(new SARLEclipsePlugin());
	SARLEclipsePlugin.setDefault(this.plugin);
	when(this.plugin.getPreferences()).thenReturn(this.preferences);
	this.bundle = mock(Bundle.class);
	when(this.bundle.getSymbolicName()).thenReturn(SARLEclipsePlugin.PLUGIN_ID);
	this.bundleContext = mock(BundleContext.class);
	when(this.bundleContext.getBundle()).thenReturn(this.bundle);
	when(this.bundle.getBundleContext()).thenReturn(this.bundleContext);
	SARLRuntime.setCurrentPreferenceKey(TESTING_PREFERENCE_KEY);
	this.plugin.start(this.bundleContext);
	//
	this.jarFile = Resources.getResource(Foo.class, "/foo/foo2.jar");
	Assume.assumeNotNull(this.jarFile);
	this.id = UUID.randomUUID().toString();
	this.sre = new StandardSREInstall(this.id);
	this.jarFile = FileLocator.toFileURL(this.jarFile);
	URI uri = this.jarFile.toURI();
	this.path = URIUtil.toPath(uri);
	this.sre.setJarFile(this.path);
}
 
Example 4
Source File: ClangFormatFormatter.java    From CppStyle with MIT License 6 votes vote down vote up
private static IPath getSourceFilePathFromEditorInput(IEditorInput editorInput) {
	if (editorInput instanceof IURIEditorInput) {
		URI uri = ((IURIEditorInput) editorInput).getURI();
		if (uri != null) {
			IPath path = URIUtil.toPath(uri);
			if (path != null) {
				  return path;
			}
		}
	}

	if (editorInput instanceof IFileEditorInput) {
		IFile file = ((IFileEditorInput) editorInput).getFile();
		if (file != null) {
			return file.getLocation();
		}
	}

	if (editorInput instanceof ILocationProvider) {
		return ((ILocationProvider) editorInput).getPath(editorInput);
	}

	return null;
}
 
Example 5
Source File: IDEFileReportProvider.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public IPath getInputPath( IEditorInput input )
{
	if ( input instanceof IURIEditorInput )
	{
		//return new Path( ( (IURIEditorInput) input ).getURI( ).getPath( ) );
		URI uri = ( (IURIEditorInput) input ).getURI( );
		if(uri == null && input instanceof IFileEditorInput)
			return ((IFileEditorInput)input).getFile( ).getFullPath( );
		IPath localPath = URIUtil.toPath( uri );
		String host = uri.getHost( );
		if ( host != null && localPath == null )
		{
			return new Path( host + uri.getPath( ) ).makeUNC( true );
		}
		return localPath;
	}
	if ( input instanceof IFileEditorInput )
	{
		return ( (IFileEditorInput) input ).getFile( ).getLocation( );
	}
	return null;
}
 
Example 6
Source File: GWTProjectsRuntime.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IStatus validate() {
  IWorkspace workspace = ResourcesPlugin.getWorkspace();
  IPathVariableManager pathVariableManager = workspace.getPathVariableManager();
  URI gwtUri = pathVariableManager.getURIValue("GWT_ROOT");
  if (gwtUri == null) {
    return new Status(IStatus.ERROR, GWTPlugin.PLUGIN_ID,
        "Path variable 'GWT_ROOT' is not defined");
  }

  IPath gwtRoot = URIUtil.toPath(gwtUri);
  if (gwtRoot == null) {
    return new Status(IStatus.ERROR, GWTPlugin.PLUGIN_ID,
        "Path variable 'GWT_ROOT' is not defined");
  }

  if (!gwtRoot.toFile().exists()) {
    return new Status(IStatus.ERROR, GWTPlugin.PLUGIN_ID,
        "Path variable 'GWT_ROOT' points to an invalid location");
  }

  if (findDevProject() == null) {
    return new Status(IStatus.ERROR, GWTPlugin.PLUGIN_ID, "Could not find and gwt-dev-* project");
  }

  if (findUserProject() == null) {
    return new Status(IStatus.ERROR, GWTPlugin.PLUGIN_ID, "Could not find the gwt-user project");
  }

  return getGwtDevJarStatus(this);
}
 
Example 7
Source File: UntitledFileStorageEditorInput.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public IStorage getStorage() throws CoreException
{
	return new IStorage()
	{

		public Object getAdapter(Class adapter)
		{
			return null;
		}

		public InputStream getContents() throws CoreException
		{
			return input;
		}

		public IPath getFullPath()
		{
			return URIUtil.toPath(uri);
		}

		public String getName()
		{
			return UntitledFileStorageEditorInput.this.getName();
		}

		public boolean isReadOnly()
		{
			return false;
		}
	};
}
 
Example 8
Source File: CompilationUnitDocumentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a fake compilation unit.
 *
 * @param editorInput the URI editor input
 * @return the fake compilation unit
 * @since 3.3
 */
private ICompilationUnit createFakeCompiltationUnit(IURIEditorInput editorInput) {
	try {
		final URI uri= editorInput.getURI();
		final IFileStore fileStore= EFS.getStore(uri);
		final IPath path= URIUtil.toPath(uri);
		String fileStoreName= fileStore.getName();
		if (fileStoreName == null || path == null)
			return null;

		WorkingCopyOwner woc= new WorkingCopyOwner() {
			/*
			 * @see org.eclipse.jdt.core.WorkingCopyOwner#createBuffer(org.eclipse.jdt.core.ICompilationUnit)
			 * @since 3.2
			 */
			@Override
			public IBuffer createBuffer(ICompilationUnit workingCopy) {
				return new DocumentAdapter(workingCopy, fileStore, path);
			}
		};

		IClasspathEntry[] cpEntries= null;
		IJavaProject jp= findJavaProject(path);
		if (jp != null)
			cpEntries= jp.getResolvedClasspath(true);

		if (cpEntries == null || cpEntries.length == 0)
			cpEntries= new IClasspathEntry[] { JavaRuntime.getDefaultJREContainerEntry() };

		final ICompilationUnit cu= woc.newWorkingCopy(fileStoreName, cpEntries, getProgressMonitor());

		if (!isModifiable(editorInput))
			JavaModelUtil.reconcile(cu);

		return cu;
	} catch (CoreException ex) {
		return null;
	}
}
 
Example 9
Source File: UntitledFileStorageEditorInput.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public IPath getPath(Object element)
{
	return URIUtil.toPath(uri);
}
 
Example 10
Source File: NewJavaProjectWizardPageOne.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Sets the project location of the new project or <code>null</code> if the project
 * should be created in the workspace
 *
 * @param uri the new project location
 */
public void setProjectLocationURI(URI uri) {
	IPath path= uri != null ? URIUtil.toPath(uri) : null;
	fLocationGroup.setLocation(path);
}
 
Example 11
Source File: MainProjectWizardPage.java    From sarl with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the project location of the new project or {@code null} if the project should be created in the workspace.
 *
 * @param uri the new project location.
 */
public void setProjectLocationURI(URI uri) {
	final IPath path = uri != null ? URIUtil.toPath(uri) : null;
	this.locationGroup.setLocation(path);
}