Java Code Examples for org.eclipse.emf.common.util.URI#deresolve()
The following examples show how to use
org.eclipse.emf.common.util.URI#deresolve() .
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: PackageJsonValidatorExtension.java From n4js with Eclipse Public License 1.0 | 6 votes |
private boolean isContainedOrEqual(URI uri, URI container) { if (uri.equals(container)) { return true; } if (!container.hasTrailingPathSeparator()) { container = container.appendSegment(""); } URI relative = uri.deresolve(container, true, true, false); if (relative != uri) { if (relative.isEmpty()) { return true; } if ("..".equals(relative.segment(0))) { return false; } return true; } return false; }
Example 2
Source File: Bpmn2ResourceImpl.java From fixflow with Apache License 2.0 | 6 votes |
/** * This is called on save to convert from a file-based URI to a namespace prefix. * It might be necessary to add a new namespace declaration to the file, if the * namespace was not known to far. * @param referenced Absolute or relative to current working directory. * @return */ public String getNsPrefix(URI referenced) { String ns = null; String prefix = ""; URI referencedAbs = ImportHelper.makeURICanonical(referenced); URI thisAbs = ImportHelper.makeURICanonical(getResource().getURI()); URI relativeToThis = referencedAbs.deresolve(thisAbs); if (relativeToThis.isEmpty()) // reference to local element ns = getDefinitions().getTargetNamespace(); else { Import impForRef = ImportHelper.findImportForLocation(getDefinitions(), referenced); if (impForRef != null) ns = impForRef.getNamespace(); } if (ns != null) { prefix = getPrefixDuringSave(ns); } return prefix; }
Example 3
Source File: EMFGeneratorFragment.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
private List<Object> getParameters(Grammar grammar, XpandExecutionContext ctx) { try { File projectRootFile = new File(ctx.getOutput().getOutlet(org.eclipse.xtext.generator.Generator.PLUGIN_RT).getPath()); String projectRoot = projectRootFile.getCanonicalPath(); URI genmodelURI = getGenModelUri(grammar, ctx); if (genmodelURI.toFileString().startsWith(projectRoot)) { URI relative = genmodelURI.deresolve(URI.createFileURI(projectRoot).appendSegment("")); String genModelPath = relative.toString(); return Lists.<Object>newArrayList(getBasePackage(grammar), genModelPath); } throw new ConfigurationException("Invalid configuration of genmodel location: " + genmodelURI + " and project root: " + projectRoot); } catch(IOException e) { throw new RuntimeException(e); } }
Example 4
Source File: SelectTemplatePage.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
/** * Sets the template {@link URI}. * * @param templateURI * the template {@link URI} to set */ public void setTemplateURI(URI templateURI) { this.templateURI = templateURI.deresolve(getBaseURI(page)); for (IWizardPage currentPage : getWizard().getPages()) { if (currentPage instanceof TemplateURISettable) { ((TemplateURISettable) getNextPage()).setTemplateURI(templateURI); } } setPageComplete(templateURI != null); }
Example 5
Source File: DotEObjectFormatter.java From gef with Eclipse Public License 2.0 | 5 votes |
protected String formatCrossRefValue(EObject object, EReference feature, EObject value) { if (value == null) return "null"; if (value.eIsProxy()) return "proxy (URI: " + ((InternalEObject) value).eProxyURI() + ")"; if (value.eResource() == object.eResource()) return value.eClass().getName() + " " + object.eResource().getURIFragment(value); URI uri = EcoreUtil.getURI(value); uri = uri.deresolve(object.eResource().getURI()); return value.eClass().getName() + " " + uri.toString(); }
Example 6
Source File: AbstractFileSystemSupport.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected Path getPath(final URI absoluteURI, final URI baseURI, final Path basePath) { Path _xblockexpression = null; { URI _xifexpression = null; if ((baseURI.isPlatformResource() && absoluteURI.isPlatformResource())) { URI _xifexpression_1 = null; String _segment = baseURI.segment(1); String _segment_1 = absoluteURI.segment(1); boolean _notEquals = (!Objects.equal(_segment, _segment_1)); if (_notEquals) { URI _xblockexpression_1 = null; { String _platformString = absoluteURI.toPlatformString(true); final org.eclipse.core.runtime.Path p = new org.eclipse.core.runtime.Path(_platformString); String _string = p.toString(); String _plus = (".." + _string); _xblockexpression_1 = URI.createURI(_plus); } _xifexpression_1 = _xblockexpression_1; } else { _xifexpression_1 = absoluteURI.deresolve(baseURI); } _xifexpression = _xifexpression_1; } else { _xifexpression = absoluteURI.deresolve(baseURI); } final URI relativeURI = _xifexpression; if ((relativeURI.isEmpty() || Objects.equal(relativeURI, absoluteURI))) { return null; } _xblockexpression = basePath.getAbsolutePath(relativeURI.toString()); } return _xblockexpression; }
Example 7
Source File: SafeURIFileCollector.java From n4js with Eclipse Public License 1.0 | 4 votes |
@Override public URI deresolveToProject(URI uri) { return uri.deresolve(uriExtensions.withEmptyAuthority(getBundle().getRootURI())); }
Example 8
Source File: LSPBuilder.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** @return a workspace relative URI for a given URI */ public URI makeWorkspaceRelative(URI uri) { URI withEmptyAuthority = uriExtensions.withEmptyAuthority(uri); URI relativeUri = withEmptyAuthority.deresolve(getBaseDir()); return relativeUri; }
Example 9
Source File: PackageJsonValidatorExtension.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Checks whether the given {@code pathLiteral} represents an existing relative path to the currently validated * {@link Resource}. * * Returns {@code false} and adds issues to {@code pathLiteral} otherwise. */ private boolean holdsExistingDirectoryPath(JSONStringLiteral pathLiteral) { final URI resourceURI = pathLiteral.eResource().getURI(); final Optional<? extends IN4JSProject> n4jsProject = n4jsCore.findProject(resourceURI); if (!n4jsProject.isPresent()) { // container project cannot be determined, fail gracefully (validation running on non-N4JS project?) return true; } final URI projectLocation = n4jsProject.get().getLocation().toURI(); // resolve against project uri with trailing slash final URI projectRelativeResourceURI = resourceURI.deresolve(projectLocation.appendSegment("")); final Path absoluteProjectPath = n4jsProject.get().getLocation().toFileSystemPath(); if (absoluteProjectPath == null) { throw new IllegalStateException( "Failed to compute project path for package.json at " + resourceURI.toString()); } // compute the path of the folder that contains the currently validated package.json file final Path baseResourcePath = new File( absoluteProjectPath.toFile(), projectRelativeResourceURI.trimSegments(1).toFileString()).toPath(); final String relativePath = pathLiteral.getValue(); final File file = new File(baseResourcePath.toString(), relativePath); if (!file.exists()) { addIssue(IssueCodes.getMessageForPKGJ_NON_EXISTING_SOURCE_PATH(relativePath), pathLiteral, IssueCodes.PKGJ_NON_EXISTING_SOURCE_PATH); return false; } if (!file.isDirectory()) { addIssue(IssueCodes.getMessageForPKGJ_EXPECTED_DIRECTORY_PATH(relativePath), pathLiteral, IssueCodes.PKGJ_EXPECTED_DIRECTORY_PATH); return false; } return true; }