Adds service retrieval support in metadata providers

This commit is contained in:
konsoletyper 2014-06-10 11:24:46 +04:00
parent 8e521c457f
commit 5fcd66795e
3 changed files with 12 additions and 3 deletions

View File

@ -16,6 +16,7 @@
package org.teavm.platform.metadata;
import java.util.Properties;
import org.teavm.common.ServiceRepository;
import org.teavm.model.ListableClassReaderSource;
import org.teavm.vm.TeaVM;
@ -25,7 +26,7 @@ import org.teavm.vm.TeaVM;
*
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
public interface MetadataGeneratorContext {
public interface MetadataGeneratorContext extends ServiceRepository {
/**
* Gets the collection of all classes that were achieved by the dependency checker.
*/

View File

@ -17,6 +17,7 @@ package org.teavm.platform.plugin;
import java.lang.reflect.Proxy;
import java.util.Properties;
import org.teavm.common.ServiceRepository;
import org.teavm.model.ListableClassReaderSource;
import org.teavm.platform.metadata.MetadataGeneratorContext;
import org.teavm.platform.metadata.Resource;
@ -32,12 +33,14 @@ class DefaultMetadataGeneratorContext implements MetadataGeneratorContext {
private ClassLoader classLoader;
private Properties properties;
private BuildTimeResourceProxyBuilder proxyBuilder = new BuildTimeResourceProxyBuilder();
private ServiceRepository services;
public DefaultMetadataGeneratorContext(ListableClassReaderSource classSource, ClassLoader classLoader,
Properties properties) {
Properties properties, ServiceRepository services) {
this.classSource = classSource;
this.classLoader = classLoader;
this.properties = properties;
this.services = services;
}
@Override
@ -71,4 +74,9 @@ class DefaultMetadataGeneratorContext implements MetadataGeneratorContext {
public <T extends Resource> ResourceMap<T> createResourceMap() {
return new BuildTimeResourceMap<>();
}
@Override
public <T> T getService(Class<T> type) {
return services.getService(type);
}
}

View File

@ -71,7 +71,7 @@ public class MetadataProviderNativeGenerator implements Generator {
e.getTargetException());
}
DefaultMetadataGeneratorContext metadataContext = new DefaultMetadataGeneratorContext(context.getClassSource(),
context.getClassLoader(), context.getProperties());
context.getClassLoader(), context.getProperties(), context);
// Generate resource loader
Resource resource = generator.generateMetadata(metadataContext, methodRef);