diff --git a/teavm-platform/src/main/java/org/teavm/platform/metadata/MetadataGenerator.java b/teavm-platform/src/main/java/org/teavm/platform/metadata/MetadataGenerator.java
index bf7302399..8a5a0e918 100644
--- a/teavm-platform/src/main/java/org/teavm/platform/metadata/MetadataGenerator.java
+++ b/teavm-platform/src/main/java/org/teavm/platform/metadata/MetadataGenerator.java
@@ -1,11 +1,65 @@
+/*
+ * Copyright 2014 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.teavm.platform.metadata;
import org.teavm.model.MethodReference;
/**
+ *
Represents a generator, that produces resources during compilation phase. User must implement this
+ * interface and bind this implementation to a method that would read resources at runtime.
+ *
+ * Here is the full workflow:
+ *
+ *
+ * - Compiler finds a method that is marked with the {@link MetadataProvider} annotation.
+ * This method must be declared as
native
, otherwise compiler should throw an exception.
+ * - Compiler instantiates the {@link MetadataGenerator} instance with the no-arg constructor
+ * If no such constructor exists, compiler throws exception.
+ * - Compiler runs the {@link #generateMetadata(MetadataGeneratorContext, MethodReference)} method
+ * ands gets the produced resource.
+ * - Compiler generates implementation of the method marked with {@link MetadataProvider}, that
+ * will return the generated resource in run time.
+ *
+ *
+ * Therefore, the type of the value, returned by the
+ * {@link #generateMetadata(MetadataGeneratorContext, MethodReference)}
+ * method must match the returning type of the appropriate method, marked with {@link MetadataProvider}.
+ *
+ * The valid resource types are the following:
+ *
+ *
+ * - Valid interfaces, marked with the {@link Resource} annotation. Read the description of this annotation
+ * for detailed description about valid resources interfaces.
+ * - {@link ResourceArray} of valid resources.
+ * - {@link ResourceMap} of valid resources.
+ * - {@link String}, {@link Integer}, {@link Byte}, {@link Short}, {@link Float}, {@link Double},
+ * {@link Boolean}.
+ * - The
null
value.
+ *
+ *
+ * All other types are not considered to be resources and therefore are not accepted.
*
* @author Alexey Andreev
*/
public interface MetadataGenerator {
+ /**
+ * Generates resources, that will be available at runtime.
+ *
+ * @param context context that contains useful compile-time information.
+ * @param method method which will be used to access the generated resources at run time.
+ */
Object generateMetadata(MetadataGeneratorContext context, MethodReference method);
}
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 c172938d9..7003d9344 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
@@ -1,13 +1,59 @@
+/*
+ * Copyright 2014 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.teavm.platform.metadata;
+import java.util.Properties;
import org.teavm.model.ListableClassReaderSource;
+import org.teavm.vm.TeaVM;
/**
+ * Represents context with compile-time information, that is useful for {@link MetadataGenerator}.
+ * This context is provided by the compiler infrastructure.
*
* @author Alexey Andreev
*/
public interface MetadataGeneratorContext {
+ /**
+ * Gets the collection of all classes that were achieved by the dependency checker.
+ */
ListableClassReaderSource getClassSource();
+ /**
+ * Gets the class loader that is used by the compiler.
+ */
+ ClassLoader getClassLoader();
+
+ /**
+ * Gets properties that were specified to {@link TeaVM}.
+ */
+ Properties getProperties();
+
+ /**
+ * Creates a new resource of the given type. The description of valid resources
+ * is available in documentation for {@link Resource}.
+ */
T createResource(Class resourceType);
+
+ /**
+ * Creates a new resource array.
+ */
+ ResourceArray createResourceArray();
+
+ /**
+ * Creates a new resource map.
+ */
+ ResourceMap createResourceMap();
}
diff --git a/teavm-platform/src/main/java/org/teavm/platform/metadata/MetadataProvider.java b/teavm-platform/src/main/java/org/teavm/platform/metadata/MetadataProvider.java
index aed053db3..7065725d0 100644
--- a/teavm-platform/src/main/java/org/teavm/platform/metadata/MetadataProvider.java
+++ b/teavm-platform/src/main/java/org/teavm/platform/metadata/MetadataProvider.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2014 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.teavm.platform.metadata;
import java.lang.annotation.ElementType;
@@ -6,6 +21,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
+ * Binds a {@link MetadataGenerator} to a native method.
*
* @author Alexey Andreev
*/
diff --git a/teavm-platform/src/main/java/org/teavm/platform/metadata/Resource.java b/teavm-platform/src/main/java/org/teavm/platform/metadata/Resource.java
index 64755a4d6..f47ac1747 100644
--- a/teavm-platform/src/main/java/org/teavm/platform/metadata/Resource.java
+++ b/teavm-platform/src/main/java/org/teavm/platform/metadata/Resource.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2014 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.teavm.platform.metadata;
import java.lang.annotation.ElementType;
@@ -6,6 +21,13 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
+ * Marks a valid resource interface. Resource interface is an interface, that has get* and set* methods,
+ * according the default convention for JavaBeans. Each property must have both getter and setter.
+ * Also each property's must be either primitive value, except for long
or valid resource.
+ *
+ * @see MetadataGenerator
+ * @see ResourceArray
+ * @see ResourceMap
*
* @author Alexey Andreev
*/
diff --git a/teavm-platform/src/main/java/org/teavm/platform/metadata/ResourceArray.java b/teavm-platform/src/main/java/org/teavm/platform/metadata/ResourceArray.java
index 43bd6a7d0..98a85ca2a 100644
--- a/teavm-platform/src/main/java/org/teavm/platform/metadata/ResourceArray.java
+++ b/teavm-platform/src/main/java/org/teavm/platform/metadata/ResourceArray.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2014 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.teavm.platform.metadata;
/**
diff --git a/teavm-platform/src/main/java/org/teavm/platform/metadata/ResourceMap.java b/teavm-platform/src/main/java/org/teavm/platform/metadata/ResourceMap.java
index eddd2e28c..599467059 100644
--- a/teavm-platform/src/main/java/org/teavm/platform/metadata/ResourceMap.java
+++ b/teavm-platform/src/main/java/org/teavm/platform/metadata/ResourceMap.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2014 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.teavm.platform.metadata;
/**
diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformPlugin.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformPlugin.java
index 09f41abc6..327e6f66f 100644
--- a/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformPlugin.java
+++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformPlugin.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2014 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.teavm.platform.plugin;
import org.teavm.vm.spi.TeaVMHost;
diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceProxy.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceProxy.java
new file mode 100644
index 000000000..5260ba845
--- /dev/null
+++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/ResourceProxy.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2014 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.teavm.platform.plugin;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+/**
+ *
+ * @author Alexey Andreev
+ */
+class ResourceProxy implements InvocationHandler {
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ return null;
+ }
+}