From 5fcd66795e4fd9c8979e374e84b2c2b3ed130a5f Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Tue, 10 Jun 2014 11:24:46 +0400 Subject: [PATCH] Adds service retrieval support in metadata providers --- .../platform/metadata/MetadataGeneratorContext.java | 3 ++- .../plugin/DefaultMetadataGeneratorContext.java | 10 +++++++++- .../plugin/MetadataProviderNativeGenerator.java | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/teavm-platform/src/main/java/org/teavm/platform/metadata/MetadataGeneratorContext.java b/teavm-platform/src/main/java/org/teavm/platform/metadata/MetadataGeneratorContext.java index 88f1bca57..067b4fe26 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/metadata/MetadataGeneratorContext.java +++ b/teavm-platform/src/main/java/org/teavm/platform/metadata/MetadataGeneratorContext.java @@ -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 */ -public interface MetadataGeneratorContext { +public interface MetadataGeneratorContext extends ServiceRepository { /** * Gets the collection of all classes that were achieved by the dependency checker. */ diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/DefaultMetadataGeneratorContext.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/DefaultMetadataGeneratorContext.java index c68f69911..947202715 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/DefaultMetadataGeneratorContext.java +++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/DefaultMetadataGeneratorContext.java @@ -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 ResourceMap createResourceMap() { return new BuildTimeResourceMap<>(); } + + @Override + public T getService(Class type) { + return services.getService(type); + } } diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/MetadataProviderNativeGenerator.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/MetadataProviderNativeGenerator.java index d9801bece..da0dd8740 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/MetadataProviderNativeGenerator.java +++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/MetadataProviderNativeGenerator.java @@ -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);