You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jt...@apache.org on 2018/09/02 16:18:50 UTC
[incubator-netbeans-html4j] branch master updated: Properly
construct delegating visitor to make sure all annotations are copied
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 85cb22a Properly construct delegating visitor to make sure all annotations are copied
85cb22a is described below
commit 85cb22a4dec996bf0d4bb2b1f0d12e6a695b5ee2
Author: Jaroslav Tulach <ja...@apidesign.org>
AuthorDate: Sun Sep 2 18:17:32 2018 +0200
Properly construct delegating visitor to make sure all annotations are copied
---
.../java/org/netbeans/html/boot/impl/FnUtils.java | 17 ++-
json-tck/pom.xml | 6 +
.../net/java/html/js/tests/ResourceOrderTest.java | 133 +++++++++++++++++++++
pom.xml | 1 +
4 files changed, 148 insertions(+), 9 deletions(-)
diff --git a/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java b/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java
index 3a42327..9d47b06 100644
--- a/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java
+++ b/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java
@@ -49,7 +49,6 @@ import org.objectweb.asm.signature.SignatureWriter;
* @author Jaroslav Tulach
*/
public final class FnUtils {
-
private FnUtils() {
}
@@ -121,7 +120,7 @@ public final class FnUtils {
private final String[] resources = new String[256];
public FindInClass(ClassLoader l, ClassVisitor cv) {
- super(Opcodes.ASM4, cv);
+ super(Opcodes.ASM5, cv);
}
@Override
@@ -170,7 +169,7 @@ public final class FnUtils {
private boolean bodyGenerated;
public FindInMethod(int access, String name, String desc, MethodVisitor mv) {
- super(Opcodes.ASM4, mv);
+ super(Opcodes.ASM5, mv);
this.access = access;
this.name = name;
this.desc = desc;
@@ -306,7 +305,7 @@ public final class FnUtils {
private int loadIndex = offset;
public SV() {
- super(Opcodes.ASM4);
+ super(Opcodes.ASM5);
}
@Override
@@ -359,7 +358,7 @@ public final class FnUtils {
@Override
public SignatureVisitor visitArrayType() {
if (nowReturn) {
- return new SignatureVisitor(Opcodes.ASM4) {
+ return new SignatureVisitor(Opcodes.ASM5) {
@Override
public void visitClassType(String name) {
returnType = Type.getType("[" + Type.getObjectType(name).getDescriptor());
@@ -493,7 +492,7 @@ public final class FnUtils {
boolean keepAlive = true;
public FindInAnno() {
- super(Opcodes.ASM4);
+ super(Opcodes.ASM5);
}
@Override
@@ -534,7 +533,7 @@ public final class FnUtils {
private final class LoadResource extends AnnotationVisitor {
public LoadResource(AnnotationVisitor av) {
- super(Opcodes.ASM4, av);
+ super(Opcodes.ASM5, av);
}
@Override
@@ -552,12 +551,12 @@ public final class FnUtils {
@Override
public AnnotationVisitor visitArray(String name) {
- return this;
+ return new LoadResource(super.visitArray(name));
}
@Override
public AnnotationVisitor visitAnnotation(String name, String desc) {
- return this;
+ return new LoadResource(super.visitAnnotation(name, desc));
}
}
}
diff --git a/json-tck/pom.xml b/json-tck/pom.xml
index 862de7e..20e5612 100644
--- a/json-tck/pom.xml
+++ b/json-tck/pom.xml
@@ -95,6 +95,12 @@
<artifactId>net.java.html.boot</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.ow2.asm</groupId>
+ <artifactId>asm</artifactId>
+ <type>jar</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<description>Test Compatibility Kit for anyone who wants to consume the net.java.html.json APIs and
render their objects using own technology (e.g. own browser, MVVC, etc.).</description>
diff --git a/json-tck/src/test/java/net/java/html/js/tests/ResourceOrderTest.java b/json-tck/src/test/java/net/java/html/js/tests/ResourceOrderTest.java
new file mode 100644
index 0000000..59fbec8
--- /dev/null
+++ b/json-tck/src/test/java/net/java/html/js/tests/ResourceOrderTest.java
@@ -0,0 +1,133 @@
+/**
+ * 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 net.java.html.js.tests;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.Opcodes;
+import org.testng.Assert;
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.Test;
+
+public class ResourceOrderTest {
+
+ public ResourceOrderTest() {
+ }
+
+ @Test
+ public void testLoadData() throws Exception {
+ InputStream is = ResourceOrder.class.getResourceAsStream("ResourceOrder.class");
+
+ int[] valueCount = { 0 };
+ List<String> values = new ArrayList<>();
+
+ ClassReader r = new ClassReader(is);
+ r.accept(new ClassVisitor(Opcodes.ASM5) {
+ @Override
+ public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
+ return new AnnotationVisitor(api) {
+ @Override
+ public void visit(String name, Object value) {
+ Assert.fail("No values at level one: " + name + " value: " + value);
+ }
+
+ @Override
+ public AnnotationVisitor visitAnnotation(String name, String desc) {
+ Assert.fail("visitAnnotation: " + name);
+ return null;
+ }
+
+ @Override
+ public AnnotationVisitor visitArray(String name) {
+ Assert.assertEquals(name, "value");
+ valueCount[0]++;
+ return new AnnotationVisitor(api) {
+ @Override
+ public void visitEnd() {
+ }
+
+ @Override
+ public AnnotationVisitor visitArray(String name) {
+ Assert.fail("visitArray: " + name);
+ return null;
+ }
+
+ @Override
+ public AnnotationVisitor visitAnnotation(String name, String desc) {
+ Assert.assertEquals(desc, "Lnet/java/html/js/JavaScriptResource;");
+ return new AnnotationVisitor(api) {
+ @Override
+ public void visitEnd() {
+ }
+
+ @Override
+ public AnnotationVisitor visitArray(String name) {
+ Assert.fail("visitArray: " + name);
+ return null;
+ }
+
+ @Override
+ public AnnotationVisitor visitAnnotation(String name, String desc) {
+ Assert.fail("visitAnnotation: " + name + " desc: " + desc);
+ return null;
+ }
+
+ @Override
+ public void visitEnum(String name, String desc, String value) {
+ Assert.fail("visitEnum " + name + " desc: " + desc + " value: " + value);
+ }
+
+ @Override
+ public void visit(String name, Object value) {
+ Assert.assertEquals(name, "value");
+ Assert.assertTrue(value instanceof String, "It is a string: " + value);
+ values.add((String) value);
+ }
+ };
+ }
+
+ @Override
+ public void visitEnum(String name, String desc, String value) {
+ Assert.fail("visitEnum");
+ }
+
+ @Override
+ public void visit(String name, Object value) {
+ Assert.fail(name);
+ }
+ };
+ }
+
+ @Override
+ public void visitEnd() {
+ }
+ };
+ }
+ }, 0);
+
+ assertEquals(values.size(), 3, "There are there elements: " + values);
+ assertEquals(values.get(0), "initArray.js");
+ assertEquals(values.get(1), "addHello.js");
+ assertEquals(values.get(2), "addWorld.js");
+ }
+}
diff --git a/pom.xml b/pom.xml
index 783eb2a..78502d9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -191,6 +191,7 @@ org.netbeans.html.boot.impl:org.netbeans.html.boot.fx:org.netbeans.html.context.
<includes>
<include>org.testng:*:*:jar:test</include>
<include>org.ow2.asm:*:*:jar:provided</include>
+ <include>org.ow2.asm:*:*:jar:test</include>
</includes>
</bannedDependencies>
</rules>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists