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;
}
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;
}
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;
}
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());
}
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());
}
Aggregations