use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class MultiProjectTest method setup.
@Before
public void setup() {
ServerModule _serverModule = new ServerModule();
final Injector injector = Guice.createInjector(Modules2.mixin(_serverModule, new AbstractModule() {
@Override
protected void configure() {
this.<IWorkspaceConfigFactory>bind(IWorkspaceConfigFactory.class).to(MultiProjectWorkspaceConfigFactory.class);
}
}));
injector.injectMembers(this);
final File workspaceRoot = this.getRoot("test-data");
File _file = new File(workspaceRoot, "test-project0");
this.project0 = _file;
File _file_1 = new File(workspaceRoot, "test-project1");
this.project1 = _file_1;
this.project0.mkdir();
this.project1.mkdir();
final Procedure2<URI, Iterable<Issue>> _function = (URI $0, Iterable<Issue> $1) -> {
this.diagnostics.put($0, IterableExtensions.<Issue>toList($1));
};
this.workspaceManager.initialize(URI.createFileURI(workspaceRoot.getAbsolutePath()), _function, null);
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class UriExtensionsTest method testFolderIsPrefixWithWhitespace.
@Test
public void testFolderIsPrefixWithWhitespace() {
File directory = this.createTempDir("some name with whitespaces").toFile();
Assert.assertTrue(directory.exists());
Assert.assertTrue(directory.isDirectory());
Assert.assertTrue(CharMatcher.WHITESPACE.matchesAnyOf(directory.getName()));
String _absolutePath = directory.getAbsolutePath();
String _plus = (_absolutePath + "/");
URI uri = this._uriExtensions.toUri(this._uriExtensions.toUriString(URI.createFileURI(_plus)));
Assert.assertTrue(uri.isPrefix());
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class AbstractIncrementalBuilderTest method operator_minus.
protected URI operator_minus(final String path, final String content) {
try {
final URI uri = this.uri(path);
OutputStream _createOutputStream = this.inMemoryURIHandler.createOutputStream(uri, CollectionLiterals.<Object, Object>emptyMap());
final Procedure1<OutputStream> _function = (OutputStream it) -> {
try {
it.write(content.getBytes());
it.close();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
ObjectExtensions.<OutputStream>operator_doubleArrow(_createOutputStream, _function);
return uri;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class XtextLinkingService method getUsedGrammar.
private List<EObject> getUsedGrammar(Grammar grammar, INode node) {
try {
String grammarName = (String) valueConverterService.toValue("", "GrammarID", node);
if (grammarName != null) {
final ResourceSet resourceSet = grammar.eResource().getResourceSet();
List<Resource> resources = resourceSet.getResources();
for (int i = 0; i < resources.size(); i++) {
Resource resource = resources.get(i);
EObject rootElement = null;
if (resource instanceof XtextResource) {
IParseResult parseResult = ((XtextResource) resource).getParseResult();
if (parseResult != null)
rootElement = parseResult.getRootASTElement();
} else if (!resource.getContents().isEmpty()) {
rootElement = resource.getContents().get(0);
}
if (rootElement instanceof Grammar) {
Grammar otherGrammar = (Grammar) rootElement;
if (grammarName.equals(otherGrammar.getName())) {
if (resource instanceof DerivedStateAwareResource)
resource.getContents();
return Collections.<EObject>singletonList(otherGrammar);
}
}
}
URI classpathURI = URI.createURI(ClasspathUriUtil.CLASSPATH_SCHEME + ":/" + grammarName.replace('.', '/') + "." + fileExtension);
URI normalizedURI = null;
if (resourceSet instanceof XtextResourceSet) {
XtextResourceSet set = (XtextResourceSet) resourceSet;
normalizedURI = set.getClasspathUriResolver().resolve(set.getClasspathURIContext(), classpathURI);
} else {
normalizedURI = resourceSet.getURIConverter().normalize(classpathURI);
}
final Resource resource = resourceSet.getResource(normalizedURI, true);
if (!resource.getContents().isEmpty()) {
final Grammar usedGrammar = (Grammar) resource.getContents().get(0);
if (grammarName.equals(usedGrammar.getName()))
return Collections.<EObject>singletonList(usedGrammar);
}
}
return Collections.emptyList();
} catch (ClasspathUriResolutionException e) {
log.debug("Cannot load used grammar.", e);
return Collections.emptyList();
} catch (ValueConverterException e) {
log.debug("Cannot load used grammar.", e);
return Collections.emptyList();
}
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class XtextReferableElementsUnloader method caseEPackage.
private void caseEPackage(EPackage ePackage) {
// guard against infinite recursion
// EPackage.eSetProxyURI and friends tries to be smart thus
// we have to make sure to compute all URIs before they are
// set
Resource resource = ePackage.eResource();
URI resourceURI = resource.getURI();
List<EClassifier> classifiers = ePackage.getEClassifiers();
List<URI> uris = new ArrayList<URI>(classifiers.size());
for (int i = 0, size = classifiers.size(); i < size; i++) {
uris.add(resourceURI.appendFragment(resource.getURIFragment(classifiers.get(i))));
}
// and we have to set them in a proper order
unload(ePackage);
for (int i = 0, size = classifiers.size(); i < size; i++) {
InternalEObject classifier = (InternalEObject) classifiers.get(i);
classifier.eSetProxyURI(uris.get(i));
}
}
Aggregations