use of org.eclipse.xtext.common.types.access.TypeResource in project xtext-eclipse by eclipse.
the class JdtTypeProviderTest method testGetResource_01.
@Test
public void testGetResource_01() {
URI primitivesURI = URI.createURI("java:/Primitives");
TypeResource resource = (TypeResource) resourceSet.getResource(primitivesURI, true);
assertNotNull(resource);
assertTrue(resource.isLoaded());
assertEquals(9, resource.getContents().size());
}
use of org.eclipse.xtext.common.types.access.TypeResource in project xtext-eclipse by eclipse.
the class JdtTypeProviderTest method testCreateResource_01.
@Test
public void testCreateResource_01() {
URI primitivesURI = URI.createURI("java:/Primitives");
TypeResource resource = typeProvider.createResource(primitivesURI);
assertNotNull(resource);
assertFalse(resource.isLoaded());
assertTrue(resource.getContents().isEmpty());
}
use of org.eclipse.xtext.common.types.access.TypeResource in project xtext-eclipse by eclipse.
the class JdtTypeProviderTest method testGetResource_03.
@Test
public void testGetResource_03() {
URI primitivesURI = URI.createURI("java:/Primitives");
TypeResource createdResource = (TypeResource) resourceSet.createResource(primitivesURI);
TypeResource resource = (TypeResource) resourceSet.getResource(primitivesURI, false);
assertSame(createdResource, resource);
assertFalse(resource.isLoaded());
assertTrue(resource.getContents().isEmpty());
}
use of org.eclipse.xtext.common.types.access.TypeResource in project xtext-eclipse by eclipse.
the class JvmOutlineNodeElementOpener method openEObject.
@Override
protected void openEObject(EObject state) {
try {
if (state instanceof JvmIdentifiableElement && state.eResource() instanceof TypeResource) {
IJavaElement javaElement = javaElementFinder.findElementFor((JvmIdentifiableElement) state);
if (javaElement instanceof IMember) {
IResource resource = javaElement.getResource();
if (resource instanceof IStorage) {
ITrace traceToSource = traceInformation.getTraceToSource((IStorage) resource);
if (traceToSource != null) {
ISourceRange sourceRange = ((IMember) javaElement).getSourceRange();
ILocationInResource sourceInformation = traceToSource.getBestAssociatedLocation(new TextRegion(sourceRange.getOffset(), sourceRange.getLength()));
if (sourceInformation != null) {
globalURIEditorOpener.open(sourceInformation.getAbsoluteResourceURI().getURI(), javaElement, true);
return;
}
}
}
globalURIEditorOpener.open(null, javaElement, true);
return;
}
}
} catch (Exception exc) {
LOG.error("Error opening java editor", exc);
}
super.openEObject(state);
}
use of org.eclipse.xtext.common.types.access.TypeResource in project n4js by eclipse.
the class LinkingXpectMethod method linkedPathname.
/**
* Similar to {@link #linkedName(IStringExpectation, ICrossEReferenceAndEObject)} but concatenating the fully
* qualified name again instead of using the qualified name provider, as the latter may not create a valid name for
* non-globally available elements.
* <p>
* The qualified name created by retrieving all "name" properties of the target and its containers, using '/' as
* separator.
*/
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public void linkedPathname(@StringExpectation IStringExpectation expectation, ICrossEReferenceAndEObject arg1) {
EObject targetObject = (EObject) arg1.getEObject().eGet(arg1.getCrossEReference());
if (targetObject == null) {
Assert.fail("Reference is null");
// to avoid warnings in the following
return;
}
if (targetObject.eIsProxy())
Assert.fail("Reference is a Proxy: " + ((InternalEObject) targetObject).eProxyURI());
Resource targetResource = targetObject.eResource();
if (targetResource instanceof TypeResource)
targetResource = arg1.getEObject().eResource();
if (!(targetResource instanceof XtextResource))
Assert.fail("Referenced EObject is not in an XtextResource.");
Deque<String> segments = new ArrayDeque<>();
do {
EStructuralFeature nameFeature = targetObject.eClass().getEStructuralFeature("name");
if (nameFeature != null) {
Object obj = targetObject.eGet(nameFeature);
if (obj instanceof String) {
segments.push((String) obj);
}
} else {
if (targetObject instanceof NamedElement) {
segments.push(((NamedElement) targetObject).getName());
}
}
targetObject = targetObject.eContainer();
} while (targetObject != null);
String pathname = Joiner.on('/').join(segments);
expectation.assertEquals(pathname);
}
Aggregations