Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Utility class for instrumenting classes at runtime.
Expand All @@ -57,6 +59,8 @@
*/
final class ClassInstrumentationUtil {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

private final int version;

private final Map<ClassLoader, InstrumentedClassLoader> classLoaderCache = new WeakHashMap<>();
Expand Down Expand Up @@ -115,6 +119,7 @@ public <T extends Component> Class<? extends T> instrumentClass(Class<T> parent)
}

if (!needsInstrumentation(parent)) {
logger.info("{} no instrumentation needed", parent);
return parent;
}

Expand Down Expand Up @@ -248,7 +253,8 @@ private byte[] generateBytecode(String className, Class<?> parent) {

ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);

cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, internalClassName, null, internalParentName, null);
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL,
internalClassName, null, internalParentName, null);

generateConstructor(cw, internalParentName);
generateClientCallableOverrides(cw, parent, internalClassName, internalParentName);
Expand Down Expand Up @@ -361,12 +367,14 @@ private void createLookupHelper(ClassWriter cw, Method method) {
}

private void generateMethodOverride(ClassWriter cw, Method method, String internalClassName, String internalParentName) {
logger.info("Override {}", method);

boolean hasJsonValueReturn = !hasLegacyVaadin() && JsonValue.class.isAssignableFrom(method.getReturnType());
boolean hasJsonValueParams = !hasLegacyVaadin() && hasJsonValueParameters(method);

String overrideDescriptor = getMethodDescriptor(method, hasJsonValueParams);
String superDescriptor = getMethodDescriptor(method, false);
int access = method.getModifiers() & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED);
int access = method.getModifiers() & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE);

MethodVisitor mv = cw.visitMethod(access, method.getName(), overrideDescriptor, null,
getExceptionInternalNames(method.getExceptionTypes()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.flowingcode.vaadin.jsonmigration;

import elemental.json.JsonArray;
import elemental.json.JsonType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -49,5 +50,10 @@ private static List<JsonNode> children(JsonArray a) {
}
}

@Override
public JsonType getType() {
return JsonType.ARRAY;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.flowingcode.vaadin.jsonmigration;

import elemental.json.JsonType;
import tools.jackson.databind.node.BooleanNode;

@SuppressWarnings("serial")
Expand All @@ -28,6 +29,11 @@ public ElementalBooleanNode(boolean value) {
super(value);
}

@Override
public JsonType getType() {
return JsonType.BOOLEAN;
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.flowingcode.vaadin.jsonmigration;

import elemental.json.JsonType;
import tools.jackson.databind.node.NullNode;

@SuppressWarnings("serial")
Expand All @@ -33,5 +34,10 @@ public String toJson() {
return null;
}

@Override
public JsonType getType() {
return JsonType.NULL;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.flowingcode.vaadin.jsonmigration;

import elemental.json.JsonType;
import tools.jackson.databind.node.DoubleNode;

@SuppressWarnings("serial")
Expand All @@ -37,5 +38,11 @@ public String toJson() {
return UnsupportedJsonValueImpl.super.toJson();
}
}

@Override
public JsonType getType() {
return JsonType.NUMBER;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import static com.flowingcode.vaadin.jsonmigration.JsonMigrationHelper25.convertToJsonNode;
import elemental.json.JsonObject;
import elemental.json.JsonType;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -51,6 +52,11 @@ private static Map<String, JsonNode> children(JsonObject o) {
}
}

@Override
public JsonType getType() {
return JsonType.OBJECT;
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.flowingcode.vaadin.jsonmigration;

import elemental.json.JsonType;
import tools.jackson.databind.node.StringNode;

@SuppressWarnings("serial")
Expand All @@ -28,4 +29,9 @@ public ElementalStringNode(String value) {
super(value);
}

@Override
public JsonType getType() {
return JsonType.STRING;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.vaadin.flow.component.Component;
import com.vaadin.flow.router.RouteConfiguration;
import com.vaadin.flow.server.VaadinServiceInitListener;
import com.vaadin.flow.server.Version;

/**
* Abstract base class for Vaadin service initializers that register instrumented views. Subclasses
Expand Down Expand Up @@ -54,9 +53,7 @@ protected final void registerInstrumentedRoute(Class<? extends Component> naviga
}

String route = annotation.value();
if (Version.getMajorVersion() > 24) {
navigationTarget = JsonMigration.instrumentClass(navigationTarget);
}
navigationTarget = JsonMigration.instrumentClass(navigationTarget);
RouteConfiguration.forApplicationScope().setRoute(route, navigationTarget);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public JsonValue convertToJsonValue(Object object) {
@SuppressWarnings("unchecked")
@Override
public JsonValue convertToClientCallableResult(JsonValue object) {
if (object == null) {
return null;
if (object == null || object instanceof JsonNode) {
return object;
} else {
switch (object.getType()) {
case OBJECT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package com.flowingcode.vaadin.jsonmigration;

import elemental.json.JsonType;
import elemental.json.JsonValue;
import tools.jackson.databind.JsonNode;

Expand All @@ -40,11 +39,6 @@ default String asString() {
throw new UnsupportedOperationException();
}

@Override
default JsonType getType() {
throw new UnsupportedOperationException();
}

@Override
default String toJson() {
return ((JsonNode) this).toString();
Expand Down