Search in sources :

Example 6 with TypeResource

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());
}
Also used : TypeResource(org.eclipse.xtext.common.types.access.TypeResource) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 7 with TypeResource

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());
}
Also used : TypeResource(org.eclipse.xtext.common.types.access.TypeResource) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 8 with TypeResource

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());
}
Also used : TypeResource(org.eclipse.xtext.common.types.access.TypeResource) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 9 with TypeResource

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);
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) TypeResource(org.eclipse.xtext.common.types.access.TypeResource) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) TextRegion(org.eclipse.xtext.util.TextRegion) ITrace(org.eclipse.xtext.generator.trace.ITrace) IStorage(org.eclipse.core.resources.IStorage) IMember(org.eclipse.jdt.core.IMember) IResource(org.eclipse.core.resources.IResource) ILocationInResource(org.eclipse.xtext.generator.trace.ILocationInResource) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Example 10 with TypeResource

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);
}
Also used : TypeResource(org.eclipse.xtext.common.types.access.TypeResource) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) ICrossEReferenceAndEObject(org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) TypeResource(org.eclipse.xtext.common.types.access.TypeResource) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) XtextResource(org.eclipse.xtext.resource.XtextResource) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) ICrossEReferenceAndEObject(org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject) NamedElement(org.eclipse.n4js.n4JS.NamedElement) ArrayDeque(java.util.ArrayDeque) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Aggregations

TypeResource (org.eclipse.xtext.common.types.access.TypeResource)14 URI (org.eclipse.emf.common.util.URI)8 Test (org.junit.Test)6 Resource (org.eclipse.emf.ecore.resource.Resource)3 IResource (org.eclipse.core.resources.IResource)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)2 IMirror (org.eclipse.xtext.common.types.access.IMirror)2 ArrayDeque (java.util.ArrayDeque)1 IStorage (org.eclipse.core.resources.IStorage)1 EObject (org.eclipse.emf.ecore.EObject)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IMember (org.eclipse.jdt.core.IMember)1 ISourceRange (org.eclipse.jdt.core.ISourceRange)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 NamedElement (org.eclipse.n4js.n4JS.NamedElement)1 ParameterParser (org.eclipse.xpect.parameter.ParameterParser)1 Xpect (org.eclipse.xpect.runner.Xpect)1 ICrossEReferenceAndEObject (org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject)1