Java Code Examples for org.eclipse.emf.common.util.URI#appendSegments()

The following examples show how to use org.eclipse.emf.common.util.URI#appendSegments() . 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: SourceAttachmentPackageFragmentRootWalker.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Converts the physical URI to a logic URI based on the bundle symbolic name.
 */
protected URI getLogicalURI(URI uri, IStorage storage, TraversalState state) {
	if (bundleSymbolicName != null) {
		URI logicalURI = URI.createPlatformResourceURI(bundleSymbolicName, false);
		List<?> parents = state.getParents();
		for (int i = 1; i < parents.size(); i++) {
			Object obj = parents.get(i);
			if (obj instanceof IPackageFragment) {
				logicalURI = logicalURI.appendSegments(((IPackageFragment) obj).getElementName().split("\\."));
			} else if (obj instanceof IJarEntryResource) {
				logicalURI = logicalURI.appendSegment(((IJarEntryResource) obj).getName());
			} else if (obj instanceof IFolder) {
				logicalURI = logicalURI.appendSegment(((IFolder) obj).getName());
			}
		}
		return logicalURI.appendSegment(uri.lastSegment());
	}
	return uri;
}
 
Example 2
Source File: ProjectDescriptionLoader.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adjust the path value of the "main" property of the given package.json document as follows (in-place change of
 * the given JSON document):
 * <ol>
 * <li>if the path points to a folder, then "/index.js" will be appended,
 * <li>if neither a folder nor a file exist at the location the path points to and the path does not end in ".js",
 * then ".js" will be appended.
 * </ol>
 */
private void adjustMainPath(URI location, JSONDocument packageJSON) {
	JSONValue content = packageJSON.getContent();
	if (!(content instanceof JSONObject))
		return;
	JSONObject contentCasted = (JSONObject) content;
	NameValuePair mainProperty = JSONModelUtils.getNameValuePair(contentCasted, MAIN.name).orElse(null);
	if (mainProperty == null) {
		return;
	}
	String main = asNonEmptyStringOrNull(mainProperty.getValue());
	if (main == null) {
		return;
	}
	String[] mainSegments;
	if (File.separatorChar == '/') {
		List<String> splitted = Strings.split(main, '/');
		mainSegments = splitted.toArray(String[]::new);
	} else {
		mainSegments = windowsPattern.split(main);
	}

	URI locationWithMain = location.appendSegments(mainSegments);

	if (!main.endsWith(".js") && isFile(URIConverter.INSTANCE, locationWithMain.appendFileExtension("js"))) {
		main += ".js";
		mainProperty.setValue(JSONModelUtils.createStringLiteral(main));
	} else if (isDirectory(URIConverter.INSTANCE, locationWithMain)) {
		if (!(main.endsWith("/") || main.endsWith(File.separator))) {
			main += "/";
		}
		main += "index.js";
		mainProperty.setValue(JSONModelUtils.createStringLiteral(main));
	}
}
 
Example 3
Source File: AbstractTraceForURIProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected SomeFile asFile(SourceRelativeURI srcRelativeDerivedResource, IProjectConfig project) {
	String[] pathSegments = srcRelativeDerivedResource.getURI().segments();
	Set<? extends ISourceFolder> sourceFolders = project.getSourceFolders();
	for(ISourceFolder folder: sourceFolders) {
		URI srcFolderPath = folder.getPath();
		URI absoluteURI = srcFolderPath.appendSegments(pathSegments);
		SomeFile result = asFile(new AbsoluteURI(absoluteURI), project);
		if (result != null) {
			return result;
		}
	}
	URI fromRoot = project.getPath().appendSegments(pathSegments);
	return asFile(new AbsoluteURI(fromRoot), project);
}
 
Example 4
Source File: FormatLinkingService.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
}