public EObject loadModel(URI uri, URI root) {
// resolve the input uri, in case it is a relative path
URI absURI = uri.resolve(root);
if (! uri.equals(absURI)) {
// add this pair to URI converter so that others can get the URI by its relative path
resourceSet.getURIConverter().getURIMap().put(uri, absURI);
}
// load root model
Resource resource = null;
try {
resource = resourceSet.getResource(absURI, true);
resource.load(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
return null;
}
EObject model = resource.getContents().get(0);
// load all its imports recursively
for (Iterator<String> it = fileHandlerRegistry.get(absURI.fileExtension()).importsIterator(model); it.hasNext();) {
String importURIStr = it.next();
URI importURI = URI.createURI(importURIStr);
URI resolvedURI = importURI.resolve(absURI);
// add this pair to URI converter so that others can get the URI by its relative path
resourceSet.getURIConverter().getURIMap().put(importURI, resolvedURI);
loadModel(resolvedURI, root);
}
return model;
}
but when resource = resourceSet.getResource(absURI, true); error:
1) null returned by binding at com.google.eclipse.protobuf.ProtobufRuntimeModule.configureExtensionRegistry(ProtobufRuntimeModule.java:75)
but com.google.eclipse.protobuf.scoping.ProtoDescriptorProvider.registry is not @Nullable
while locating com.google.eclipse.protobuf.scoping.ExtensionRegistryProvider
while locating org.eclipse.core.runtime.IExtensionRegistry
for field at com.google.eclipse.protobuf.scoping.ProtoDescriptorProvider.registry(Unknown Source)
public Injector createInjectorAndDoEMFRegistration() {
// the FrancaPackage might not be registered because the EMF model is not part of the DSL
if (! EPackage.Registry.INSTANCE.containsKey(com.google.eclipse.protobuf.protobuf.ProtobufPackage.eNS_URI)) {
EPackage.Registry.INSTANCE.put(com.google.eclipse.protobuf.protobuf.ProtobufPackage.eNS_URI, com.google.eclipse.protobuf.protobuf.ProtobufPackage.eINSTANCE);
}
return super.createInjectorAndDoEMFRegistration();
}
@Singleton public class ExtensionRegistryProvider implements Provider<IExtensionRegistry> {
@Override public IExtensionRegistry get() {
return Platform.getExtensionRegistry();
}
}
@Singleton public class ProtoDescriptorProvider {
[...]
@Inject @Nullable private IExtensionRegistry registry;
...
@Target({ FIELD })
@Retention(RUNTIME)
@interface Nullable { }
private ProtoDescriptorInfo descriptorInfoFromExtensionPoint() {
// registry will be null if not running in the Eclipse IDE
if (registry == null) {
return null;
}
...