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; package org.teavm.platform.metadata;
import java.util.Properties; import java.util.Properties;
import org.teavm.common.ServiceRepository;
import org.teavm.model.ListableClassReaderSource; import org.teavm.model.ListableClassReaderSource;
import org.teavm.vm.TeaVM; import org.teavm.vm.TeaVM;
@ -25,7 +26,7 @@ import org.teavm.vm.TeaVM;
* *
* @author Alexey Andreev <konsoletyper@gmail.com> * @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. * 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.lang.reflect.Proxy;
import java.util.Properties; import java.util.Properties;
import org.teavm.common.ServiceRepository;
import org.teavm.model.ListableClassReaderSource; import org.teavm.model.ListableClassReaderSource;
import org.teavm.platform.metadata.MetadataGeneratorContext; import org.teavm.platform.metadata.MetadataGeneratorContext;
import org.teavm.platform.metadata.Resource; import org.teavm.platform.metadata.Resource;
@ -32,12 +33,14 @@ class DefaultMetadataGeneratorContext implements MetadataGeneratorContext {
private ClassLoader classLoader; private ClassLoader classLoader;
private Properties properties; private Properties properties;
private BuildTimeResourceProxyBuilder proxyBuilder = new BuildTimeResourceProxyBuilder(); private BuildTimeResourceProxyBuilder proxyBuilder = new BuildTimeResourceProxyBuilder();
private ServiceRepository services;
public DefaultMetadataGeneratorContext(ListableClassReaderSource classSource, ClassLoader classLoader, public DefaultMetadataGeneratorContext(ListableClassReaderSource classSource, ClassLoader classLoader,
Properties properties) { Properties properties, ServiceRepository services) {
this.classSource = classSource; this.classSource = classSource;
this.classLoader = classLoader; this.classLoader = classLoader;
this.properties = properties; this.properties = properties;
this.services = services;
} }
@Override @Override
@ -71,4 +74,9 @@ class DefaultMetadataGeneratorContext implements MetadataGeneratorContext {
public <T extends Resource> ResourceMap<T> createResourceMap() { public <T extends Resource> ResourceMap<T> createResourceMap() {
return new BuildTimeResourceMap<>(); 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()); e.getTargetException());
} }
DefaultMetadataGeneratorContext metadataContext = new DefaultMetadataGeneratorContext(context.getClassSource(), DefaultMetadataGeneratorContext metadataContext = new DefaultMetadataGeneratorContext(context.getClassSource(),
context.getClassLoader(), context.getProperties()); context.getClassLoader(), context.getProperties(), context);
// Generate resource loader // Generate resource loader
Resource resource = generator.generateMetadata(metadataContext, methodRef); Resource resource = generator.generateMetadata(metadataContext, methodRef);