Java Code Examples for org.eclipse.emf.common.util.URI#trimSegments()
The following examples show how to use
org.eclipse.emf.common.util.URI#trimSegments() .
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: 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 3
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 4
Source File: EclipseProjectPropertiesEncodingProvider.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected String getFromProperties(URI uri) throws IOException { if (!uri.isHierarchical()) return null; URI projectURI = uri; boolean projectFound = false; do { projectURI = projectURI.trimSegments(1); if (new File(projectURI.path(), ".project").exists()) { projectFound = true; } if (!projectFound && projectURI.segmentCount() == 0) // The resource is not contained in a project return null; } while (!projectFound); Properties properties = loadProperties(projectURI); URI resourceUri = URI.createHierarchicalURI(Arrays.copyOfRange(uri.segments(), projectURI.segmentCount(), uri.segmentCount()), null, null); return getValue(properties, resourceUri, ENCODING_PREFIX); }
Example 5
Source File: GamlSyntacticConverter.java From gama with GNU General Public License v3.0 | 6 votes |
public static String getAbsoluteContainerFolderPathOf(final Resource r) { URI uri = r.getURI(); if (uri.isFile()) { uri = uri.trimSegments(1); return uri.toFileString(); } else if (uri.isPlatform()) { final IPath path = GamlResourceServices.getPathOf(r); final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); final IContainer folder = file.getParent(); return folder.getLocation().toString(); } return URI.decode(uri.toString()); // final IPath fullPath = file.getLocation(); // path = fullPath; // toOSString ? // if (path == null) { return null; } // return path.uptoSegment(path.segmentCount() - 1); }
Example 6
Source File: PlatformResourceURI.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override public PlatformResourceURI getParent() { URI uri = toURI(); if (uri.segmentCount() > 2) { return new PlatformResourceURI(uri.trimSegments(1)); } return null; }
Example 7
Source File: SolidityHyperlinkHelper.java From solidity-ide with Eclipse Public License 1.0 | 5 votes |
protected URI getFileURIOfImport (ImportDirective importElement) { URI fileURI = importElement.eResource().getURI().trimSegments(1); String importURI = importElement.getImportedNamespace(); while (importURI.startsWith("../")) { fileURI = fileURI.trimSegments(1); importURI = importURI.replaceFirst("../", ""); } String[] segments = importURI.split("/"); for (String segment : segments) { fileURI = fileURI.appendSegment(segment); } return fileURI; }
Example 8
Source File: FormatLinkingService.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Creates a URI for given format name (equivalent to the grammar name). * * @param formatName * for which URI should be crated * @return URI of the {@code .format} file */ private URI buildExtendedFormatConfigurationURI(final String formatName) { URI formatURI = URI.createPlatformResourceURI(formatName, true); String[] formatSegments = formatName.split("\\."); formatURI = formatURI.trimFileExtension(); formatURI = formatURI.appendFileExtension("core"); formatURI = formatURI.appendSegment("src"); formatURI = formatURI.appendSegments(formatSegments); formatURI = formatURI.trimSegments(1); formatURI = formatURI.appendSegment("formatting"); formatURI = formatURI.appendSegment(formatSegments[formatSegments.length - 1]); formatURI = formatURI.appendFileExtension("format"); return formatURI; }
Example 9
Source File: Repository.java From textuml with Eclipse Public License 1.0 | 5 votes |
/** * Creates a model set. * * @param baseURI * @throws CoreException */ public Repository(URI baseURI, boolean systemPackages) throws CoreException { Assert.isTrue(!baseURI.isRelative(), "Repository base URI must be absolute: " + baseURI); // it seems trailing slash causes cross-references to become relative // URIs preserving parent paths (/common/parent/../sibling/foo.uml // instead of ../sibling/foo.uml) if (baseURI.hasTrailingPathSeparator()) baseURI = baseURI.trimSegments(1); @SuppressWarnings("unused") UMLPackage umlPackage = UMLPackage.eINSTANCE; this.baseURI = baseURI; properties = MDDUtil.loadRepositoryProperties(this.baseURI); init(systemPackages); load(); }