use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class EClassifierInfos method getSuperTypeInfos.
public List<EClassInfo> getSuperTypeInfos(EClassInfo subTypeInfo) throws UnexpectedClassInfoException {
List<EClassInfo> result = new ArrayList<EClassInfo>();
List<EClass> superTypes = subTypeInfo.getEClass().getESuperTypes();
for (int i = 0; i < superTypes.size(); i++) {
EClass superType = superTypes.get(i);
if (superType.eIsProxy()) {
URI proxyURI = EcoreUtil.getURI(superType);
if (proxyURI.isPlatformResource()) {
String platformString = proxyURI.toPlatformString(true);
URI platformPluginURI = URI.createPlatformPluginURI(platformString, true).appendFragment(proxyURI.fragment());
EObject secondAttempt = subTypeInfo.getEClass().eResource().getResourceSet().getEObject(platformPluginURI, true);
if (secondAttempt instanceof EClass) {
superType = (EClass) secondAttempt;
superTypes.set(i, superType);
}
}
}
EClassifierInfo info = getInfoOrNull(superType);
if (info != null) {
if (info instanceof EClassInfo) {
result.add((EClassInfo) info);
} else {
throw new UnexpectedClassInfoException(TransformationErrorCode.InvalidSupertype, subTypeInfo, info, null);
}
} else {
if (superType.eIsProxy()) {
throw new UnexpectedClassInfoException(TransformationErrorCode.InvalidSupertype, subTypeInfo, null, "Cannot load all supertypes of '" + subTypeInfo.getEClass().getName() + "'");
} else if (isPackageKnown(superType.getEPackage().getNsURI())) {
throw new UnexpectedClassInfoException(TransformationErrorCode.InvalidSupertype, subTypeInfo, null, "Cannot find info for type '" + superType.getName() + "'");
}
}
}
return result;
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class XtendXtext2EcorePostProcessor method getXtendFileLocation.
protected URI getXtendFileLocation(GeneratedMetamodel metamodel) {
URI uri = metamodel.eResource().getURI();
// check if uri can be used for resolve
if (!uri.isHierarchical() || uri.isRelative())
return null;
uri = URI.createURI(Strings.lastToken(getExtensionName(metamodel), "::")).appendFileExtension(XtendFile.FILE_EXTENSION).resolve(uri);
return uri;
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class XtendXtext2EcorePostProcessor method loadXtendFile.
/**
* Expects an Xtend file named <code>MyDsl</code>PostProcessor.ext with an extension with signature
* process(xtext::GeneratedMetamodel) in the same folder as the grammar file.
*
* @param metamodel
* the metamodel to augment
* @return the xtendFile to execute
*/
protected Resource loadXtendFile(GeneratedMetamodel metamodel) {
if (xtendFile == null) {
final String extension = getExtensionName(metamodel);
try {
URI uri = getXtendFileLocation(metamodel);
if (uri != null) {
URIConverter uriConverter = metamodel.eResource().getResourceSet().getURIConverter();
if (uriConverter.exists(uri, null)) {
InputStream in = uriConverter.createInputStream(uri);
try {
XtendResourceParser parser = new XtendResourceParser();
xtendFile = parser.parse(new InputStreamReader(in), extension + '.' + XtendFile.FILE_EXTENSION);
fireXtendFileLoaded();
} finally {
if (in != null)
in.close();
}
}
}
} catch (ClasspathUriResolutionException ignored) {
// no xtend file found
} catch (Exception e) {
logger.error("Could not parse " + extension, e);
}
}
return xtendFile;
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class EcoreUtil2Test method testExternalFormOfEReferenceNoNPE.
/**
* This test assumes that an EPackage with indexed references is no longer available.
*/
@Test
public void testExternalFormOfEReferenceNoNPE() throws Exception {
EReference reference = EcorePackage.Literals.EATTRIBUTE__EATTRIBUTE_TYPE;
URI uri = EcoreUtil.getURI(reference);
String externalForm = uri.toString();
EReference foundReference = EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, externalForm);
assertSame(reference, foundReference);
String brokenExternalFrom = makeInvalid(externalForm);
assertNull(EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, brokenExternalFrom));
String shortExternalForm = EcoreUtil2.toExternalForm(reference);
foundReference = EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, shortExternalForm);
assertSame(reference, foundReference);
String brokenShortExternalFrom = makeInvalid(shortExternalForm);
assertNull(EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, brokenShortExternalFrom));
brokenShortExternalFrom = shortExternalForm.replace('A', 'a');
assertNull(EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, brokenShortExternalFrom));
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class JavaIoFileSystemAccessTest method testEncoding.
@Test
public void testEncoding() throws Exception {
File file = null;
FileInputStream fileInputStream = null;
try {
JavaIoFileSystemAccess fileSystemAccess = new JavaIoFileSystemAccess(IResourceServiceProvider.Registry.INSTANCE, new IEncodingProvider() {
@Override
public String getEncoding(URI uri) {
return "ISO-8859-1";
}
});
File tmpDir = configureFileSystemAccess(fileSystemAccess);
String contents = "g�rkenbr�d";
fileSystemAccess.generateFile("test.txt", contents);
file = new File(tmpDir, "test.txt");
assertTrue(file.exists());
fileInputStream = new FileInputStream(file);
byte[] buffer = new byte[512];
int read = fileInputStream.read(buffer);
String utfString = new String(buffer, 0, read, "UTF-8");
assertFalse(equal(contents, utfString));
String isoString = new String(buffer, 0, read, "ISO-8859-1");
assertEquals(contents, isoString);
} finally {
if (fileInputStream != null)
fileInputStream.close();
if (file != null)
file.delete();
}
}
Aggregations