This is an automated email from the ASF dual-hosted git repository.
jtulach pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans-html4j.git
The following commit(s) were added to refs/heads/master by this push:
new 4e6570f Dynamically instantiate ModelTypes implementation to avoid
confusion of AOT compilers
4e6570f is described below
commit 4e6570f698dc3f66373d5cf183687788e67ff762
Author: Jaroslav Tulach <[email protected]>
AuthorDate: Thu Nov 2 20:48:44 2017 +0100
Dynamically instantiate ModelTypes implementation to avoid confusion of AOT
compilers
---
.../netbeans/html/json/impl/ClassValueTypes.java | 35 +++++++++++++
.../java/org/netbeans/html/json/impl/JSON.java | 59 +++-------------------
.../netbeans/html/json/impl/LinkedListTypes.java | 53 +++++++++++++++++++
.../org/netbeans/html/json/impl/ModelTypes.java | 29 +++++++++++
4 files changed, 124 insertions(+), 52 deletions(-)
diff --git
a/json/src/main/java/org/netbeans/html/json/impl/ClassValueTypes.java
b/json/src/main/java/org/netbeans/html/json/impl/ClassValueTypes.java
new file mode 100644
index 0000000..5c8addc
--- /dev/null
+++ b/json/src/main/java/org/netbeans/html/json/impl/ClassValueTypes.java
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.netbeans.html.json.impl;
+
+import org.netbeans.html.json.spi.Proto;
+
+final class ClassValueTypes extends ClassValue<Proto.Type[]> implements
ModelTypes {
+
+ @Override
+ protected Proto.Type[] computeValue(Class<?> type) {
+ return new Proto.Type<?>[1];
+ }
+
+ @Override
+ public Proto.Type[] find(Class<?> type) {
+ return get(type);
+ }
+
+}
diff --git a/json/src/main/java/org/netbeans/html/json/impl/JSON.java
b/json/src/main/java/org/netbeans/html/json/impl/JSON.java
index 09c691f..0f148c6 100644
--- a/json/src/main/java/org/netbeans/html/json/impl/JSON.java
+++ b/json/src/main/java/org/netbeans/html/json/impl/JSON.java
@@ -342,63 +342,18 @@ public final class JSON {
}
- private static interface ModelTypes {
- public Proto.Type[] get(Class<?> type);
- static final ModelTypes MODELS = initModelTypes();
- }
-
- static ModelTypes initModelTypes() {
+ static ModelTypes initModelTypes(String implName) {
try {
- return initClassValueTypes();
- } catch (LinkageError err) {
+ Class<?> clazz = Class.forName(implName);
+ return (ModelTypes) clazz.newInstance();
+ } catch (Exception ex) {
return new LinkedListTypes();
}
}
- private static ModelTypes initClassValueTypes() {
- return new ClassValueTypes();
- }
-
- private static final class ClassValueTypes extends ClassValue<Proto.Type[]>
- implements ModelTypes {
-
- @Override
- protected Proto.Type[] computeValue(Class<?> type) {
- return new Proto.Type<?>[1];
- }
- }
-
- private static final class LinkedListTypes implements ModelTypes {
- private Item items;
- private static final class Item {
- final Item next;
- final Class<?> clazz;
- final Proto.Type<?>[] type = { null };
-
- Item(Item next, Class<?> clazz) {
- this.next = next;
- this.clazz = clazz;
- }
- }
-
- @Override
- public synchronized Proto.Type[] get(Class<?> clazz) {
- Item it = items;
- while (it != null) {
- if (it.clazz == clazz) {
- return it.type;
- }
- it = it.next;
- }
- it = new Item(items, clazz);
- items = it;
- return it.type;
- }
- }
-
public static void register(Class c, Proto.Type<?> type) {
- ModelTypes.MODELS.get(c)[0] = type;
+ ModelTypes.MODELS.find(c)[0] = type;
}
public static boolean isModel(Class<?> clazz) {
@@ -407,7 +362,7 @@ public final class JSON {
static Proto.Type<?> findType(Class<?> clazz) {
for (int i = 0; i < 2; i++) {
- Proto.Type<?> from = ModelTypes.MODELS.get(clazz)[0];
+ Proto.Type<?> from = ModelTypes.MODELS.find(clazz)[0];
if (from == null) {
initClass(clazz);
} else {
@@ -456,7 +411,7 @@ public final class JSON {
return modelClazz.cast(data.toString());
}
for (int i = 0; i < 2; i++) {
- Proto.Type<?> from = ModelTypes.MODELS.get(modelClazz)[0];
+ Proto.Type<?> from = ModelTypes.MODELS.find(modelClazz)[0];
if (from == null) {
initClass(modelClazz);
} else {
diff --git
a/json/src/main/java/org/netbeans/html/json/impl/LinkedListTypes.java
b/json/src/main/java/org/netbeans/html/json/impl/LinkedListTypes.java
new file mode 100644
index 0000000..8279c18
--- /dev/null
+++ b/json/src/main/java/org/netbeans/html/json/impl/LinkedListTypes.java
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.netbeans.html.json.impl;
+
+import org.netbeans.html.json.spi.Proto;
+
+final class LinkedListTypes implements ModelTypes {
+
+ private Item items;
+
+ private static final class Item {
+
+ final Item next;
+ final Class<?> clazz;
+ final Proto.Type<?>[] type = {null};
+
+ Item(Item next, Class<?> clazz) {
+ this.next = next;
+ this.clazz = clazz;
+ }
+ }
+
+ @Override
+ public synchronized Proto.Type[] find(Class<?> clazz) {
+ Item it = items;
+ while (it != null) {
+ if (it.clazz == clazz) {
+ return it.type;
+ }
+ it = it.next;
+ }
+ it = new Item(items, clazz);
+ items = it;
+ return it.type;
+ }
+
+}
diff --git a/json/src/main/java/org/netbeans/html/json/impl/ModelTypes.java
b/json/src/main/java/org/netbeans/html/json/impl/ModelTypes.java
new file mode 100644
index 0000000..a85b2d4
--- /dev/null
+++ b/json/src/main/java/org/netbeans/html/json/impl/ModelTypes.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.netbeans.html.json.impl;
+
+import org.netbeans.html.json.spi.Proto;
+
+interface ModelTypes {
+ Proto.Type[] find(Class<?> type);
+
+ static final ModelTypes MODELS = JSON.initModelTypes(
+ "org.netbeans.html.json.impl.ClassValueTypes"
+ );
+}
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].