Search in sources :

Example 1 with TypeResource

use of org.eclipse.xtext.common.types.access.TypeResource in project xtext-eclipse by eclipse.

the class JdtTypeProvider method findPrimitiveType.

private JvmType findPrimitiveType(/* @NonNull */
String signature, /* @NonNull */
URI resourceURI) {
    TypeResource resource = (TypeResource) getResourceForJavaURI(resourceURI, true);
    JvmType result = findTypeBySignature(signature, resource, false);
    return result;
}
Also used : TypeResource(org.eclipse.xtext.common.types.access.TypeResource) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 2 with TypeResource

use of org.eclipse.xtext.common.types.access.TypeResource in project xtext-eclipse by eclipse.

the class JdtTypeProvider method canLink.

private boolean canLink(JvmType type) {
    Resource resource = type.eResource();
    if (resource instanceof TypeResource) {
        IMirror mirror = ((TypeResource) resource).getMirror();
        if (mirror instanceof JdtTypeMirror) {
            try {
                return canLink(((JdtTypeMirror) mirror).getMirroredType());
            } catch (JavaModelException e) {
                return false;
            }
        } else {
            return true;
        }
    }
    URI resourceURI = resource.getURI();
    if (resourceURI.isPlatformResource() && resourceURI.segment(1).equals(javaProject.getProject().getName())) {
        IndexedJvmTypeAccess indexedJvmTypeAccess = this.getIndexedJvmTypeAccess();
        if (indexedJvmTypeAccess != null && indexedJvmTypeAccess.isIndexingPhase(getResourceSet())) {
            return false;
        }
    }
    return true;
}
Also used : IMirror(org.eclipse.xtext.common.types.access.IMirror) TypeResource(org.eclipse.xtext.common.types.access.TypeResource) JavaModelException(org.eclipse.jdt.core.JavaModelException) IndexedJvmTypeAccess(org.eclipse.xtext.common.types.access.impl.IndexedJvmTypeAccess) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) TypeResource(org.eclipse.xtext.common.types.access.TypeResource) URI(org.eclipse.emf.common.util.URI)

Example 3 with TypeResource

use of org.eclipse.xtext.common.types.access.TypeResource in project xtext-eclipse by eclipse.

the class JvmMemberRenameStrategy method setName.

protected JvmMember setName(URI targetURI, ResourceSet resourceSet, final String newName) {
    final JvmMember member = (JvmMember) resourceSet.getEObject(targetURI, true);
    // clear all cached identifiers of contained members
    for (JvmMember containedMember : EcoreUtil2.eAllOfType(member, JvmMember.class)) containedMember.internalSetIdentifier(null);
    member.setSimpleName(newName);
    if (member instanceof JvmDeclaredType && ((InternalEObject) member).eDirectResource() != null) {
        Resource typeResource = member.eResource();
        if (typeResource instanceof TypeResource) {
            // rename the resource
            String originalURI = typeResource.getURI().toString();
            int lastIndexOf = Math.max(originalURI.lastIndexOf('.'), originalURI.lastIndexOf('/')) + 1;
            URI typeResourceNewURI = URI.createURI(originalURI.substring(0, lastIndexOf) + newName);
            typeResource.setURI(typeResourceNewURI);
            // disconnect the mirrored IJavaElement as it is invalid now
            ((TypeResource) typeResource).setMirror(new AbstractClassMirror() {

                @Override
                public boolean isSealed() {
                    return false;
                }

                @Override
                public void initialize(TypeResource typeResource) {
                }

                @Override
                protected String getTypeName() {
                    return member.getIdentifier();
                }
            });
        }
    }
    return member;
}
Also used : TypeResource(org.eclipse.xtext.common.types.access.TypeResource) AbstractClassMirror(org.eclipse.xtext.common.types.access.impl.AbstractClassMirror) Resource(org.eclipse.emf.ecore.resource.Resource) TypeResource(org.eclipse.xtext.common.types.access.TypeResource) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember) URI(org.eclipse.emf.common.util.URI) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 4 with TypeResource

use of org.eclipse.xtext.common.types.access.TypeResource in project xtext-eclipse by eclipse.

the class JdtTypeProviderTest method testCreateResource_02.

@Test
public void testCreateResource_02() {
    URI primitivesURI = URI.createURI("java:/Primitives");
    TypeResource resource = (TypeResource) resourceSet.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 5 with TypeResource

use of org.eclipse.xtext.common.types.access.TypeResource in project xtext-eclipse by eclipse.

the class JdtTypeProviderTest method testGetResource_04.

@Test
public void testGetResource_04() {
    URI primitivesURI = URI.createURI("java:/Primitives");
    TypeResource createdResource = (TypeResource) resourceSet.createResource(primitivesURI);
    TypeResource resource = (TypeResource) resourceSet.getResource(primitivesURI, true);
    assertSame(createdResource, 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)

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