Java Code Examples for org.eclipse.emf.common.util.URI#lastSegment()
The following examples show how to use
org.eclipse.emf.common.util.URI#lastSegment() .
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: N4jscTestLanguageClient.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override public void afterGenerate(URI source, URI generated) { super.afterGenerate(source, generated); if (generated.lastSegment().isBlank()) { generated = generated.trimSegments(1); } String fileName = generated.lastSegment(); if (!fileName.endsWith(N4JSGlobals.JS_FILE_EXTENSION) && !fileName.endsWith(N4JSGlobals.JSX_FILE_EXTENSION)) { return; } Path folder = URIUtils.toPath(generated.trimSegments(1)); URI relGenerated = lspBuilder.makeWorkspaceRelative(generated); File relFile = URIUtils.toFile(relGenerated); transpiledFiles.computeIfAbsent(folder, f -> Collections.synchronizedSet(new HashSet<File>())).add(relFile); if (!transpiledFiles.containsKey(folder)) { transpiledFiles.put(folder, new HashSet<File>()); } transpiledFiles.get(folder).add(relFile); }
Example 2
Source File: NavigatorActionProvider.java From statecharts with Eclipse Public License 1.0 | 6 votes |
private IEditorInput getEditorInput() { for (EObject nextEObject : myDiagram.eResource().getContents()) { if (nextEObject == myDiagram) { return new FileEditorInput( WorkspaceSynchronizer.getFile(myDiagram.eResource())); } if (nextEObject instanceof Diagram) { break; } } URI uri = EcoreUtil.getURI(myDiagram); String editorName = uri.lastSegment() + "#" + myDiagram.eResource().getContents().indexOf(myDiagram); //$NON-NLS-1$ IEditorInput editorInput = new URIEditorInput(uri, editorName); return editorInput; }
Example 3
Source File: LSPBuilder.java From n4js with Eclipse Public License 1.0 | 6 votes |
public void didChangeWatchedFiles(DidChangeWatchedFilesParams params) { // TODO: Set watched files to client. Note: Client may have performance issues with lots of folders to watch. final List<URI> dirtyFiles = new ArrayList<>(); final List<URI> deletedFiles = new ArrayList<>(); for (FileEvent fileEvent : params.getChanges()) { URI uri = uriExtensions.toUri(fileEvent.getUri()); String fileName = uri.lastSegment(); boolean skipFile = fileName.equals(ProjectStatePersister.FILENAME); if (!skipFile && isSourceFile(uri)) { FileChangeType changeType = fileEvent.getType(); if (changeType == FileChangeType.Deleted) { deletedFiles.add(uri); } else { dirtyFiles.add(uri); } } } if (!dirtyFiles.isEmpty() || !deletedFiles.isEmpty()) { runBuildable("didChangeWatchedFiles", () -> workspaceManager.didChangeFiles(dirtyFiles, deletedFiles)); } }
Example 4
Source File: ProcessNavigatorActionProvider.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
/** * @generated */ private static IEditorInput getEditorInput(Diagram diagram) { Resource diagramResource = diagram.eResource(); for (EObject nextEObject : diagramResource.getContents()) { if (nextEObject == diagram) { return new FileEditorInput(WorkspaceSynchronizer.getFile(diagramResource)); } if (nextEObject instanceof Diagram) { break; } } URI uri = EcoreUtil.getURI(diagram); String editorName = uri.lastSegment() + '#' + diagram.eResource().getContents().indexOf(diagram); IEditorInput editorInput = new URIEditorInput(uri, editorName); return editorInput; }
Example 5
Source File: N4JSProject.java From n4js with Eclipse Public License 1.0 | 6 votes |
private boolean isInNodeModulesFolderOrDefault(@SuppressWarnings("hiding") SafeURI<?> location, boolean defaultResult) { if (!defaultResult && location instanceof FileURI) { URI parent = location.getParent().toURI(); String lastSegment = parent.lastSegment(); if (parent.lastSegment() != null && parent.lastSegment().isBlank()) { parent = parent.trimSegments(1); lastSegment = parent.lastSegment(); } if (lastSegment != null && lastSegment.startsWith("@")) { parent = parent.trimSegments(1); lastSegment = parent.lastSegment(); } if (N4JSGlobals.NODE_MODULES.equals(lastSegment)) { return true; } } return defaultResult; }
Example 6
Source File: N4JSProjectConfig.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Projects are indexed but not transpiled if they have '.' as the output path or if they are located in * node_modules folders. * * @return true iff this project should be indexed only */ public boolean indexOnly() { String outputPath = delegate.getOutputPath(); if (".".equals(outputPath)) { return true; } URI projectBase = getPath(); String lastSegment = projectBase.lastSegment(); if (lastSegment == null || lastSegment.isBlank()) { projectBase = projectBase.trimSegments(1); } projectBase = projectBase.trimSegments(1); // trim the project name lastSegment = projectBase.lastSegment(); if (lastSegment != null && lastSegment.startsWith("@")) { projectBase = projectBase.trimSegments(1); lastSegment = projectBase.lastSegment(); } if (lastSegment != null && N4JSGlobals.NODE_MODULES.equals(lastSegment)) { // index only true for npm libraries return true; } return false; }
Example 7
Source File: OpenDiagramEditPolicy.java From scava with Eclipse Public License 2.0 | 6 votes |
/** * @generated */ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { try { Diagram diagram = getDiagramToOpen(); if (diagram == null) { diagram = intializeNewDiagram(); } URI uri = EcoreUtil.getURI(diagram); String editorName = uri.lastSegment() + '#' + diagram.eResource().getContents().indexOf(diagram); IEditorInput editorInput = new URIEditorInput(uri, editorName); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); page.openEditor(editorInput, getEditorID()); return CommandResult.newOKCommandResult(); } catch (Exception ex) { throw new ExecutionException("Can't open diagram", ex); } }
Example 8
Source File: ProcessNavigatorLinkHelper.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
/** * @generated */ private static IEditorInput getEditorInput(Diagram diagram) { Resource diagramResource = diagram.eResource(); for (EObject nextEObject : diagramResource.getContents()) { if (nextEObject == diagram) { return new FileEditorInput(WorkspaceSynchronizer.getFile(diagramResource)); } if (nextEObject instanceof Diagram) { break; } } URI uri = EcoreUtil.getURI(diagram); String editorName = uri.lastSegment() + '#' + diagram.eResource().getContents().indexOf(diagram); IEditorInput editorInput = new URIEditorInput(uri, editorName); return editorInput; }
Example 9
Source File: EclipseFileSystemSupportImpl.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
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 10
Source File: XPDLToProc.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public File createDiagram(URL sourceURL, IProgressMonitor progressMonitor) throws IOException { try { progressMonitor.beginTask(Messages.importFromXPDL, 3); builder = new ProcBuilder(progressMonitor); final ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xpdl", new Xpdl1ResourceFactoryImpl()); final URI sourceURI = URI.createFileURI(new File(URI.decode(sourceURL.getFile())).getAbsolutePath()); final Resource resource = resourceSet.getResource(sourceURI, true); final DocumentRoot docRoot = (DocumentRoot) resource.getContents().get(0); final PackageType xpdlPackage = docRoot.getPackage(); final String diagramName = sourceURI.lastSegment(); String version = "1.0"; if (xpdlPackage.getRedefinableHeader() != null && xpdlPackage.getRedefinableHeader().getVersion() != null) { version = xpdlPackage.getRedefinableHeader().getVersion(); } result = File.createTempFile(diagramName, ".proc"); result.deleteOnExit(); builder.createDiagram(diagramName, xpdlPackage.getName(), version, result); importFromXPDL(xpdlPackage); builder.done(); return result; } catch (final ProcBuilderException e) { BonitaStudioLog.error(e); } return null; }
Example 11
Source File: ClasspathTypeProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public URI normalize(URI uri) { if (URIHelperConstants.PROTOCOL.equals(uri.scheme())) { String qualifiedName = uri.lastSegment(); if (qualifiedName.lastIndexOf('$') != -1) { String outermostClassName = new BinaryClass(qualifiedName, classLoader).getOutermostClassName(); return URIHelperConstants.OBJECTS_URI.appendSegment(outermostClassName); } return uri; } return existing.normalize(uri); }
Example 12
Source File: EObjectDescriptionToNameWithPositionMapper.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Returns a string with name and position of the described object. The position is specified by line number (if * possible, otherwise the uri fragment of the proxy is used). If the object is a {@link SyntaxRelatedTElement}, a * "T" is used as a prefix of the line number. * * The following examples shows different mappings, depending on the described object: * <table> * <tr> * <th>Mapping</th> * <th>Described Object</th> * </tr> * <tr> * <td><code>bar - 42</code></td> * <td>Some element "bar", located in same resource on line 42</td> * </tr> * <tr> * <td><code>foo - T23</code></td> * <td>A type "foo" (or other syntax related element, a function is a type) which syntax related element (from which * the type is build) is located in same file on line 23</td> * </tr> * <tr> * <td><code>Infinity - global.n4ts:3</code></td> * <td>An element "Infinity", located in another resource "global.n4ts" on line 3.</td> * </tr> * <tr> * <td><code>decodeURI - global.n4ts:11</code></td> * <td>An element "decodeURI", located in another resource "global.n4ts" on line 11. Although the element may be a * type, there is no syntax related element because "n4ts" directly describes types.</td> * </tr> * </table> * * @param currentURI * the current resource's URI, if described object is in same resource, resource name is omitted * @param desc * the object descriptor */ public static String descriptionToNameWithPosition(URI currentURI, boolean withLineNumber, IEObjectDescription desc) { String name = desc.getName().toString(); EObject eobj = desc.getEObjectOrProxy(); if (eobj == null) { return "No EObject or proxy for " + name + " at URI " + desc.getEObjectURI(); } String location = ""; if (eobj instanceof SyntaxRelatedTElement) { EObject syntaxElement = ((SyntaxRelatedTElement) eobj).getAstElement(); if (syntaxElement != null) { location += "T"; eobj = syntaxElement; } } Resource eobjRes = eobj.eResource(); URI uri = eobjRes == null ? null : eobjRes.getURI(); if (uri != currentURI && uri != null) { location = uri.lastSegment(); if (eobj.eIsProxy() || withLineNumber) { location += ":"; } } if (eobj.eIsProxy()) { URI proxyUri = desc.getEObjectURI(); location += "proxy:" + simpleURIString(proxyUri); } else if (withLineNumber) { INode node = NodeModelUtils.findActualNodeFor(eobj); if (node == null) { location += "no node:" + simpleURIString(desc.getEObjectURI()); } else { location += node.getStartLine(); } } return name + SEPARATOR + location; }
Example 13
Source File: EObjectDescriptionToNameWithPositionMapper.java From n4js with Eclipse Public License 1.0 | 4 votes |
static String simpleURIString(URI uri) { if (uri == null) return "!!null!!"; return uri.lastSegment() + "#" + uri.fragment(); }
Example 14
Source File: DefaultDescriptionLabelProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.1 */ protected Object getImageForURI(URI uri) { String fileName = uri.lastSegment(); return imageUtil.getDefaultEditorImageDescriptor(fileName); }
Example 15
Source File: FileProjectConfig.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public FileProjectConfig(URI path, IWorkspaceConfig workspaceConfig) { this(path, path.lastSegment(), workspaceConfig); }
Example 16
Source File: NewGenerationWizard.java From M2Doc with Eclipse Public License 1.0 | 2 votes |
/** * Gets the template file name from the given genconf {@link URI}. * * @param genconfURI * the template {@link URI} * @return the validation file name from the given genconf {@link URI} */ private String getTemplateFileName(URI genconfURI) { final String lastSegment = genconfURI.lastSegment(); return URI.decode(lastSegment.substring(0, lastSegment.length() - GenconfUtils.GENCONF_EXTENSION_FILE.length()) + M2DocUtils.DOCX_EXTENSION_FILE); }
Example 17
Source File: NewGenerationWizard.java From M2Doc with Eclipse Public License 1.0 | 2 votes |
/** * Gets the result file name from the given genconf {@link URI}. * * @param genconfURI * the genconf {@link URI} * @return the result file name from the given genconf {@link URI} */ private String getResultFileName(URI genconfURI) { final String lastSegment = genconfURI.lastSegment(); return URI.decode(lastSegment.substring(0, lastSegment.length() - GenconfUtils.GENCONF_EXTENSION_FILE.length()) + "generated." + M2DocUtils.DOCX_EXTENSION_FILE); }
Example 18
Source File: EmfResourceUtil.java From dsl-devkit with Eclipse Public License 1.0 | 2 votes |
/** * Gets the file extension from the given URI. * * @param uri * the uri, may not be null * @return the file extension */ public static String getFileExtension(final URI uri) { String fileName = uri.lastSegment(); int dotIdx = fileName.lastIndexOf('.'); return URI.decode(dotIdx == -1 ? "" : fileName.substring(dotIdx + 1)); //$NON-NLS-1$ }
Example 19
Source File: EmfResourceUtil.java From dsl-devkit with Eclipse Public License 1.0 | 2 votes |
/** * Gets the file name without file extension from the given URI. * * @param uri * the uri, may not be null * @return the file name <em>excluding</em> file extension */ public static String getFileNameWithoutExtension(final URI uri) { String fileName = uri.lastSegment(); int dotIdx = fileName.lastIndexOf('.'); return URI.decode(dotIdx == -1 ? fileName : fileName.substring(0, dotIdx)); }
Example 20
Source File: NewGenerationWizard.java From M2Doc with Eclipse Public License 1.0 | 2 votes |
/** * Gets the validation file name from the given genconf {@link URI}. * * @param genconfURI * the genconf {@link URI} * @return the validation file name from the given genconf {@link URI} */ private String getValidationFileName(URI genconfURI) { final String lastSegment = genconfURI.lastSegment(); return URI.decode(lastSegment.substring(0, lastSegment.length() - GenconfUtils.GENCONF_EXTENSION_FILE.length()) + "validation." + M2DocUtils.DOCX_EXTENSION_FILE); }