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

The following examples show how to use org.eclipse.emf.common.util.URI#toString() . 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: ExternalLibraryBuilder.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Deletes all entries in the Xtext index that start with one of the given project URIs will be cleaned from the
 * index.
 *
 * @param toBeWiped
 *            URIs of project roots
 */
public void wipeURIsFromIndex(IProgressMonitor monitor, Collection<FileURI> toBeWiped) {
	Set<String> toBeWipedStrings = new HashSet<>();
	for (FileURI toWipe : toBeWiped) {
		toBeWipedStrings.add(toWipe.toString());
		N4JSProjectName projectName = toWipe.getProjectName();
		validatorExtension.clearAllMarkersOfExternalProject(projectName);
	}

	ResourceSet resourceSet = core.createResourceSet(Optional.absent());
	IResourceDescriptions index = core.getXtextIndex(resourceSet);

	Set<URI> toBeRemoved = new HashSet<>();
	for (IResourceDescription res : index.getAllResourceDescriptions()) {
		URI resUri = res.getURI();
		String resUriString = resUri.toString();
		for (String toWipeProject : toBeWipedStrings) {
			if (resUriString.startsWith(toWipeProject)) {
				toBeRemoved.add(resUri);
				break;
			}
		}
	}

	builderState.clean(toBeRemoved, monitor);
}
 
Example 2
Source File: DeserializationConversionContext.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void setGrammarIdToURIMap(String[] grammarIdToURIMap) {
	grammarIdToGrammarElementMap = new EObject[grammarIdToURIMap.length];

	ResourceSet grammarResourceSet = grammarAccess.getGrammar().eResource().getResourceSet();
	for (int grammarId = 0; grammarId < grammarIdToURIMap.length; ++grammarId) {
		URI uri = URI.createURI(grammarIdToURIMap[grammarId], true);
		EObject grammarElement = grammarResourceSet.getEObject(uri, true);

		if (grammarElement == null) {
			throw new IllegalStateException(
					"Apparently the grammar has changed so that it's no longer possible to identify the "
							+ "serialized grammar elements.  The following grammar element URI is no longer valid: "
							+ uri.toString());
		}

		grammarIdToGrammarElementMap[grammarId] = grammarElement;
	}
}
 
Example 3
Source File: AbstractFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Converts an EMF URI to a {@code java.net.URI}.
 */
protected java.net.URI toURI(final URI uri) {
  java.net.URI _xtrycatchfinallyexpression = null;
  try {
    String _string = uri.toString();
    _xtrycatchfinallyexpression = new URL(_string).toURI();
  } catch (final Throwable _t) {
    if (_t instanceof MalformedURLException) {
      final MalformedURLException e = (MalformedURLException)_t;
      String _message = e.getMessage();
      throw new IllegalArgumentException(_message, e);
    } else if (_t instanceof URISyntaxException) {
      final URISyntaxException e_1 = (URISyntaxException)_t;
      String _message_1 = e_1.getMessage();
      throw new IllegalArgumentException(_message_1, e_1);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
  return _xtrycatchfinallyexpression;
}
 
Example 4
Source File: M2DocMElementBuilder.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void link(Attributes attributes, String hrefOrHashName, String text) {
    final Context context = contexts.peek().copy();
    context.style.setForegroundColor(LINK_COLOR);
    final URI uri;
    if (hrefOrHashName != null) {
        if (hrefOrHashName.startsWith("#")) {
            uri = URI.createURI(hrefOrHashName);
        } else {
            uri = URI.createURI(hrefOrHashName).resolve(context.baseURI);
        }
    } else {
        uri = URI.createURI("", false);
    }
    final MHyperLink mLink = new MHyperLinkImpl(text, context.style, uri.toString());
    contexts.peek().parent.add(mLink);
}
 
Example 5
Source File: EcoreUtil2Test.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * This test assumes that an EPackage with indexed references is no longer available.
 */
@Test public void testExternalFormOfEReferenceNoNPE() throws Exception {
	EReference reference = EcorePackage.Literals.EATTRIBUTE__EATTRIBUTE_TYPE;
	URI uri = EcoreUtil.getURI(reference);
	String externalForm = uri.toString();
	EReference foundReference = EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, externalForm);
	assertSame(reference, foundReference);
	String brokenExternalFrom = makeInvalid(externalForm);
	assertNull(EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, brokenExternalFrom));
	String shortExternalForm = EcoreUtil2.toExternalForm(reference);
	foundReference = EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, shortExternalForm);
	assertSame(reference, foundReference);
	String brokenShortExternalFrom = makeInvalid(shortExternalForm);
	assertNull(EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, brokenShortExternalFrom));
	brokenShortExternalFrom = shortExternalForm.replace('A', 'a');
	assertNull(EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, brokenShortExternalFrom));
}
 
Example 6
Source File: ProjectCompareHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private ProjectComparisonEntry createEntries(
		ProjectComparison root,
		IN4JSProject api, IN4JSProject[] impls,
		ResourceSet resourceSet, IResourceDescriptions index) {

	final ProjectComparisonEntry entry = new ProjectComparisonEntry(root, api, impls);

	for (IN4JSSourceContainer currSrcConti : api.getSourceContainers()) {
		for (URI uri : currSrcConti) {
			final String uriStr = uri.toString();
			if (uriStr.endsWith("." + N4JSGlobals.N4JS_FILE_EXTENSION)
					|| uriStr.endsWith("." + N4JSGlobals.N4JSD_FILE_EXTENSION)) {
				final IResourceDescription resDesc = index.getResourceDescription(uri);
				final TModule moduleApi = getModuleFrom(resourceSet, resDesc);
				if (moduleApi != null) {
					final TModule[] moduleImpls = new TModule[impls.length];
					for (int idx = 0; idx < impls.length; idx++) {
						final IN4JSProject projectImpl = impls[idx];
						if (projectImpl != null)
							moduleImpls[idx] = findImplementation(moduleApi, projectImpl, resourceSet, index);
						else
							moduleImpls[idx] = null;
					}
					createEntries(entry, -1, moduleApi, moduleImpls, false);
				}
			}
		}
	}

	return entry;
}
 
Example 7
Source File: AbstractLaunchConfigurationMainTab.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * From the UI widgets to the configuration.
 *
 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
 */
@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
	final String wsRelativePath = txtResource.getText();
	final URI uri = wsRelativePath.trim().length() > 0 ? URI.createPlatformResourceURI(wsRelativePath, true) : null;
	final String uriStr = uri != null ? uri.toString() : null;
	configuration.setAttribute(getResourceRunConfigKey(), uriStr);

	final String implementationId = txtImplementationId.getText();
	final String actualImplId = implementationId.trim().length() > 0 ? implementationId.trim() : null;
	configuration.setAttribute(RunConfiguration.IMPLEMENTATION_ID, actualImplId);
}
 
Example 8
Source File: CompoundSummary.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private boolean matches(final URI summary, final URI query) {
	if (summary == null) { return false; }
	final String s = summary.toString();
	final String q = query.toString();
	return s.startsWith(q);

}
 
Example 9
Source File: AbstractJvmTypeProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public IMirror createMirror(URI resourceURI) {
	if (resourceURI.hasFragment())
		throw new IllegalArgumentException("Cannot create mirror for uri '" + resourceURI.toString() + "'");
	String name = resourceURI.path();
	if (URIHelperConstants.PRIMITIVES.equals(name))
		return new PrimitiveMirror(primitiveTypeFactory);
	if (!name.startsWith(URIHelperConstants.OBJECTS))
		throw new IllegalArgumentException("Invalid resource uri '" + resourceURI.toString() + "'");
	name = name.substring(URIHelperConstants.OBJECTS.length());
	return createMirrorForFQN(name);
}
 
Example 10
Source File: JarEntryLocator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected URI createJarURI(boolean isArchive, URI uriToRoot, URI pathToResourceInRoot) {
	if (isArchive) {
		String fullURI = "archive:" + uriToRoot.toString() + "!" + pathToResourceInRoot.toString();
		return URI.createURI(fullURI);
	} else {
		return null;
	}
}
 
Example 11
Source File: DotEObjectFormatter.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
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 12
Source File: LSPIssue.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see Externalizable#writeExternal(java.io.ObjectOutput)
 */
public void writeExternal(DataOutput out) throws IOException {
	out.writeInt(this.getOffset());
	out.writeInt(this.getLength());
	out.writeInt(this.getColumn());
	out.writeInt(this.getColumnEnd());
	out.writeInt(this.getLineNumber());
	out.writeInt(this.getLineNumberEnd());
	out.writeUTF(Strings.nullToEmpty(this.getCode()));
	out.writeUTF(Strings.nullToEmpty(this.getMessage()));

	URI uriToProblem = this.getUriToProblem();
	String uriToProblemStr = uriToProblem == null ? NULL : uriToProblem.toString();
	out.writeUTF(uriToProblemStr);

	Severity severity = this.getSeverity();
	int severityKey = severity == null ? 0 : severity.ordinal() + 1;
	out.writeInt(severityKey);

	CheckType checkType = this.getType();
	int checkTypeKey = checkType == null ? 0 : checkType.ordinal() + 1;
	out.writeInt(checkTypeKey);

	String[] data = getData();
	if (data == null) {
		out.writeInt(0);
	} else {
		out.writeInt(data.length);
		for (String s : data) {
			out.writeUTF(s);
		}
	}
}
 
Example 13
Source File: AbsoluteURI.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public AbsoluteURI(URI absoluteURI) {
	super(absoluteURI);
	if (absoluteURI.isRelative() || !absoluteURI.isHierarchical()) {
		throw new IllegalArgumentException(absoluteURI.toString());
	}
}
 
Example 14
Source File: Postgres.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public URL makeURL ( final String uriString ) throws MalformedURLException
{
    URI uri = URI.createURI ( uriString );
    uri = uri.resolve ( this.postgres.eResource ().getURI () );
    return new URL ( uri.toString () );
}
 
Example 15
Source File: DiagramEditorInputFactory.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
public static void saveState(IMemento memento, DiagramEditorInput input) {
	URI uri = EcoreUtil.getURI(input.getDiagram());
	String fileString = uri.toString();
	memento.putString(EMF_URI, fileString);
}
 
Example 16
Source File: SourceRelativeURI.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public static SourceRelativeURI fromAbsolute(URI uri) {
	if (uri.isRelative()) {
		throw new IllegalArgumentException(uri.toString());
	}
	return new SourceRelativeURI(uri.path().substring(1));
}
 
Example 17
Source File: ResourceUtil.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Finds the file corresponding to the specified URI, using a URI converter if necessary (and provided) to normalize
 * it.
 * 
 * @param uri
 *            a URI
 * @param converter
 *            an optional URI converter (may be <code>null</code>)
 * 
 * @return the file, if available in the workspace
 */
private static IFile getFile(URI uri, URIConverter converter, boolean considerArchives) {
	IFile result = null;

	if (considerArchives && uri.isArchive()) {
		class MyArchiveURLConnection extends ArchiveURLConnection {
			public MyArchiveURLConnection(String url) {
				super(url);
			}

			public String getNestedURI() {
				try {
					return getNestedURL();
				} catch (IOException exception) {
					return ""; //$NON-NLS-1$
				}
			}
		}
		MyArchiveURLConnection archiveURLConnection = new MyArchiveURLConnection(uri.toString());
		result = getFile(URI.createURI(archiveURLConnection.getNestedURI()), converter, considerArchives);
	} else if (uri.isPlatformResource()) {
		IPath path = new Path(uri.toPlatformString(true));
		result = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
	} else if (uri.isFile() && !uri.isRelative()) {
		result = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(uri.toFileString()));
	} else {
		// normalize, to see whether we can resolve it this time
		if (converter != null) {
			URI normalized = converter.normalize(uri);

			if (!uri.equals(normalized)) {
				// recurse on the new URI
				result = getFile(normalized, converter, considerArchives);
			}
		}
	}

	if ((result == null) && !uri.isRelative()) {
		try {
			IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(
					new java.net.URI(uri.toString()));
			if (files.length > 0) {
				// set the result to be the first file found
				result = files[0];
			}
		} catch (URISyntaxException e) {
			// won't get this because EMF provides a well-formed URI
		}
	}

	return result;
}
 
Example 18
Source File: ClasspathUriResolutionException.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public ClasspathUriResolutionException(URI unresolvedURI) {
	super(unresolvedURI.toString());
}
 
Example 19
Source File: URIUtils.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/** Converts the given {@link org.eclipse.emf.common.util.URI} to a {@link java.net.URI} */
static public java.net.URI toJavaURI(URI uri) throws URISyntaxException {
	return new java.net.URI(uri.toString());
}
 
Example 20
Source File: BuilderStateFactoryImpl.java    From xtext-eclipse with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public String convertEURIToString(EDataType eDataType, Object instanceValue) {
	URI uri = (URI) instanceValue;
	return uri.toString();
}