Commit 1962851c authored by René Schöne's avatar René Schöne
Browse files

WIP: Choose protocol at runtime (not in DSL).

- changed semantics of ViaTest slightly (setting same value for inputBoth does not change to newly send value as the "FromMqtt-" and "FromRest-" part is not prepended, and therefore it stays the same)
parent 14fa0734
Pipeline #7561 passed with stages
in 4 minutes and 55 seconds
......@@ -24,44 +24,37 @@ aspect Analysis {
}
// --- isAlreadyDefined ---
syn boolean TokenEndpointDefinition.isAlreadyDefined() {
java.util.List<TokenEndpointDefinition> definitions = lookupTokenEndpointDefinitions(getToken());
java.util.Set<String> protocols = definitions
.stream()
.map(TokenEndpointDefinition::protocol)
.collect(java.util.stream.Collectors.toSet());
return definitions.size() > protocols.size();
}
syn boolean TokenEndpointDefinition.isAlreadyDefined() = lookupTokenEndpointDefinitions(getToken()).size() > 1;
syn boolean DependencyDefinition.isAlreadyDefined() = lookupDependencyDefinition(getSource().containingTypeDecl(), getID()) != this;
// --- protocol ---
syn String TokenEndpointDefinition.protocol();
eq ReceiveFromMqttDefinition.protocol() = "mqtt";
eq SendToMqttDefinition.protocol() = "mqtt";
eq ReceiveFromRestDefinition.protocol() = "rest";
eq SendToRestDefinition.protocol() = "rest";
// --- usesPROTOCOL ---
syn boolean RagConnect.usesMqtt() = !mqttEndpointDefinitions().isEmpty();
syn boolean RagConnect.usesRest() = !restEndpointDefinitions().isEmpty();
// // --- protocol ---
// syn String TokenEndpointDefinition.protocol();
// eq ReceiveFromMqttDefinition.protocol() = "mqtt";
// eq SendToMqttDefinition.protocol() = "mqtt";
// eq ReceiveFromRestDefinition.protocol() = "rest";
// eq SendToRestDefinition.protocol() = "rest";
// --- mqttEndpointDefinitions ---
coll java.util.List<TokenEndpointDefinition> RagConnect.mqttEndpointDefinitions() [new java.util.ArrayList<>()] root RagConnect;
ReceiveFromMqttDefinition contributes this
to RagConnect.mqttEndpointDefinitions()
for ragconnect();
SendToMqttDefinition contributes this
to RagConnect.mqttEndpointDefinitions()
for ragconnect();
// // --- usesPROTOCOL ---
// syn boolean RagConnect.usesMqtt() = !mqttEndpointDefinitions().isEmpty();
// syn boolean RagConnect.usesRest() = !restEndpointDefinitions().isEmpty();
// --- restEndpointDefinitions ---
coll java.util.List<TokenEndpointDefinition> RagConnect.restEndpointDefinitions() [new java.util.ArrayList<>()] root RagConnect;
ReceiveFromRestDefinition contributes this
to RagConnect.restEndpointDefinitions()
for ragconnect();
SendToRestDefinition contributes this
to RagConnect.restEndpointDefinitions()
for ragconnect();
// // --- mqttEndpointDefinitions ---
// coll java.util.List<TokenEndpointDefinition> RagConnect.mqttEndpointDefinitions() [new java.util.ArrayList<>()] root RagConnect;
// ReceiveFromMqttDefinition contributes this
// to RagConnect.mqttEndpointDefinitions()
// for ragconnect();
// SendToMqttDefinition contributes this
// to RagConnect.mqttEndpointDefinitions()
// for ragconnect();
//
// // --- restEndpointDefinitions ---
// coll java.util.List<TokenEndpointDefinition> RagConnect.restEndpointDefinitions() [new java.util.ArrayList<>()] root RagConnect;
// ReceiveFromRestDefinition contributes this
// to RagConnect.restEndpointDefinitions()
// for ragconnect();
// SendToRestDefinition contributes this
// to RagConnect.restEndpointDefinitions()
// for ragconnect();
syn boolean MappingDefinitionType.assignableTo(JavaTypeUse target);
eq JavaMappingDefinitionType.assignableTo(JavaTypeUse target) = getType().assignableTo(target);
......
//TypeComponentMustache ;
//rel TypeComponentMustache.TypeComponent -> TypeComponent ;
MRagConnect ::= ReceiveDefinition:MReceiveDefinition* PushSendDefinition:MSendDefinition* PullSendDefinition:MSendDefinition* MappingDefinition:MMappingDefinition* DependencyDefinition:MDependencyDefinition* RootTypeComponent:MTypeComponent* TokenComponent:MTokenComponent*;
MRagConnect ::= ReceiveDefinition:MReceiveDefinition* SendDefinition:MSendDefinition* MappingDefinition:MMappingDefinition* DependencyDefinition:MDependencyDefinition* RootTypeComponent:MTypeComponent* TokenComponent:MTokenComponent*;
abstract MEndpointDefinition ::= InnerMappingDefinition:MInnerMappingDefinition*;
MReceiveDefinition : MEndpointDefinition;
MSendDefinition : MEndpointDefinition;
......
......@@ -7,13 +7,8 @@ rel EndpointDefinition.Mapping* <-> MappingDefinition.UsedAt*;
abstract TokenEndpointDefinition : EndpointDefinition;
rel TokenEndpointDefinition.Token -> TokenComponent;
abstract ReceiveTokenEndpointDefinition : TokenEndpointDefinition;
abstract SendTokenEndpointDefinition : TokenEndpointDefinition;
ReceiveFromMqttDefinition : ReceiveTokenEndpointDefinition;
SendToMqttDefinition : SendTokenEndpointDefinition;
ReceiveFromRestDefinition : ReceiveTokenEndpointDefinition;
SendToRestDefinition : SendTokenEndpointDefinition;
ReceiveTokenEndpointDefinition : TokenEndpointDefinition;
SendTokenEndpointDefinition : TokenEndpointDefinition;
DependencyDefinition ::= <ID>;
rel DependencyDefinition.Source <-> TokenComponent.DependencySourceDefinition*;
......
......@@ -2,4 +2,6 @@ aspect Configuration {
public static boolean ASTNode.loggingEnabledForReads = false;
public static boolean ASTNode.loggingEnabledForWrites = false;
public static TypeDecl ASTNode.rootNode;
public static boolean ASTNode.usesMqtt;
public static boolean ASTNode.usesRest;
}
......@@ -34,25 +34,24 @@ aspect AttributesForMustache {
eq MRagConnect.getChild().mqttHandlerField() = mqttHandlerField();
eq MRagConnect.getRootTypeComponent(int i).isFirst() = i == 0;
syn boolean MRagConnect.usesMqtt() = getRagConnect().usesMqtt();
syn String MRagConnect.closeMethod() = "ragconnectCloseConnections";
// syn boolean MRagConnect.usesMqtt() = getRagConnect().usesMqtt();
syn String MRagConnect.mqttHandlerAttribute() = "_mqttHandler";
syn String MRagConnect.mqttHandlerField() = "_mqttHandler";
syn String MRagConnect.mqttSetHostMethod() = "MqttSetHost";
syn String MRagConnect.mqttWaitUntilReadyMethod() = "MqttWaitUntilReady";
syn String MRagConnect.mqttCloseMethod() = "MqttCloseConnections";
// syn String MRagConnect.mqttSetHostMethod() = "MqttSetHost";
syn String MRagConnect.mqttSetupWaitUntilReadyMethod() = "ragconnectSetupMqttWaitUntilReady";
syn boolean MRagConnect.usesRest() = getRagConnect().usesRest();
// syn boolean MRagConnect.usesRest() = getRagConnect().usesRest();
syn String MRagConnect.restHandlerAttribute() = "_restHandler";
syn String MRagConnect.restHandlerField() = "_restHandler";
syn String MRagConnect.restSetPortMethod() = "RestSetPort";
syn String MRagConnect.restCloseMethod() = "RestCloseConnections";
// syn String MRagConnect.restSetPortMethod() = "RestSetPort";
// --- MEndpointDefinition ---
syn String MEndpointDefinition.preemptiveExpectedValue();
syn String MEndpointDefinition.preemptiveReturn();
syn TokenEndpointDefinition MEndpointDefinition.endpointDef();
syn String MEndpointDefinition.firstInputVarName();
syn String MEndpointDefinition.newConnectionMethod();
// syn String MEndpointDefinition.newConnectionMethod();
eq MEndpointDefinition.getInnerMappingDefinition(int i).isLast() = i == getNumInnerMappingDefinition() - 1;
eq MEndpointDefinition.getInnerMappingDefinition().resultVarPrefix() = resultVarPrefix();
......@@ -61,21 +60,21 @@ aspect AttributesForMustache {
inh String MEndpointDefinition.mqttHandlerAttribute();
inh String MEndpointDefinition.restHandlerAttribute();
syn String MEndpointDefinition.connectParameterName() {
switch (endpointDef().protocol()) {
case "mqtt": return "topic";
case "rest": return "path";
default: return null;
}
}
syn String MEndpointDefinition.handlerAttribute() {
switch (endpointDef().protocol()) {
case "mqtt": return mqttHandlerAttribute();
case "rest": return restHandlerAttribute();
default: return null;
}
}
syn String MEndpointDefinition.connectMethod() = "connect" + tokenName() + (ragconnect().lookupTokenEndpointDefinitions(token()).size() > 1 ? "Via" + capitalize(endpointDef().protocol()) : "");
syn String MEndpointDefinition.connectParameterName() = "uriString";
// switch (endpointDef().protocol()) {
// case "mqtt": return "topic";
// case "rest": return "path";
// default: return null;
// }
// }
// syn String MEndpointDefinition.handlerAttribute() {
// switch (endpointDef().protocol()) {
// case "mqtt": return mqttHandlerAttribute();
// case "rest": return restHandlerAttribute();
// default: return null;
// }
// }
syn String MEndpointDefinition.connectMethod() = "connect" + tokenName();
syn TokenComponent MEndpointDefinition.token() = endpointDef().getToken();
syn boolean MEndpointDefinition.alwaysApply() = endpointDef().getAlwaysApply();
syn String MEndpointDefinition.resultVarPrefix() = "result"; // we do not need "_" here, because methodName begins with one
......@@ -112,39 +111,39 @@ aspect AttributesForMustache {
eq MReceiveDefinition.endpointDef() = getReceiveTokenEndpointDefinition();
eq MReceiveDefinition.firstInputVarName() = "message";
syn String MReceiveDefinition.newConnectionMethod() {
switch (endpointDef().protocol()) {
case "mqtt": return "newConnection";
case "rest": return "newPUTConnection";
default: return null;
}
}
// syn String MReceiveDefinition.newConnectionMethod() {
// switch (endpointDef().protocol()) {
// case "mqtt": return "newConnection";
// case "rest": return "newPUTConnection";
// default: return null;
// }
// }
// --- MSendDefinition ---
eq MSendDefinition.preemptiveExpectedValue() = lastValue();
eq MSendDefinition.preemptiveReturn() {
switch (endpointDef().protocol()) {
case "mqtt": return "return false;";
case "rest": return "throw e;"; // e is Exception variable
default: return null;
}
}
eq MSendDefinition.preemptiveReturn() = "return false;";
// switch (endpointDef().protocol()) {
// case "mqtt": return "return false;";
// case "rest": return "throw e;"; // e is Exception variable
// default: return null;
// }
// }
eq MSendDefinition.endpointDef() = getSendTokenEndpointDefinition();
eq MSendDefinition.firstInputVarName() = "get" + tokenName() + "()";
syn String MSendDefinition.sendTopic() = "_topic_" + tokenName();
syn String MSendDefinition.sender() = "_sender_" + tokenName();
syn String MSendDefinition.lastValue() = "_lastValue" + tokenName();
syn String MSendDefinition.updateMethod() = "_update_" + tokenName();
syn String MSendDefinition.writeMethod() = "_writeLastValue_" + tokenName();
syn String MSendDefinition.tokenResetMethod() = "get" + tokenName() + "_reset";
syn boolean MSendDefinition.isPush() = getSendTokenEndpointDefinition().isPush();
syn String MSendDefinition.newConnectionMethod() {
switch (endpointDef().protocol()) {
case "mqtt": return null;
case "rest": return "newGETConnection";
default: return null;
}
}
// syn boolean MSendDefinition.isPush() = getSendTokenEndpointDefinition().isPush();
// syn String MSendDefinition.newConnectionMethod() {
// switch (endpointDef().protocol()) {
// case "mqtt": return null;
// case "rest": return "newGETConnection";
// default: return null;
// }
// }
// --- MMappingDefinition ---
syn String MMappingDefinition.toType() = getMappingDefinition().getToType().prettyPrint();
......@@ -182,11 +181,7 @@ aspect AttributesForMustache {
for (EndpointDefinition def : getEndpointDefinitionList()) {
if (def.isSendTokenEndpointDefinition()) {
SendTokenEndpointDefinition sendDef = def.asSendTokenEndpointDefinition();
if (sendDef.isPush()) {
result.addPushSendDefinition(sendDef.toMustache());
} else {
result.addPullSendDefinition(sendDef.toMustache());
}
result.addSendDefinition(sendDef.toMustache());
} else {
result.addReceiveDefinition(def.asReceiveTokenEndpointDefinition().toMustache());
}
......@@ -257,9 +252,9 @@ aspect AttributesForMustache {
aspect AspectGeneration {
syn boolean SendTokenEndpointDefinition.isPush();
eq SendToMqttDefinition.isPush() = true;
eq SendToRestDefinition.isPush() = false;
// syn boolean SendTokenEndpointDefinition.isPush();
// eq SendToMqttDefinition.isPush() = true;
// eq SendToRestDefinition.isPush() = false;
// --- rootNodeName ---
syn String ASTNode.rootNodeName() = rootNode.getName();
......
......@@ -116,10 +116,8 @@ aspect Mappings {
// --- isSuitableEdgeMapping(def) ---
syn boolean TokenEndpointDefinition.isSuitableEdgeMapping(MappingDefinition def);
eq ReceiveFromMqttDefinition.isSuitableEdgeMapping(MappingDefinition def) = def.getFromType().isByteArray();
eq SendToMqttDefinition.isSuitableEdgeMapping(MappingDefinition def) = def.getToType().isByteArray();
eq ReceiveFromRestDefinition.isSuitableEdgeMapping(MappingDefinition def) = def.getFromType().isString();
eq SendToRestDefinition.isSuitableEdgeMapping(MappingDefinition def) = def.getToType().isString();
eq ReceiveTokenEndpointDefinition.isSuitableEdgeMapping(MappingDefinition def) = def.getFromType().isByteArray();
eq SendTokenEndpointDefinition.isSuitableEdgeMapping(MappingDefinition def) = def.getToType().isByteArray();
// --- isPrimitiveType ---
syn boolean TokenComponent.isPrimitiveType() = effectiveJavaTypeUse().isPrimitiveType();
......@@ -145,9 +143,9 @@ aspect Mappings {
// --- suitableDefaultMapping ---
syn DefaultMappingDefinition EndpointDefinition.suitableDefaultMapping();
eq ReceiveFromMqttDefinition.suitableDefaultMapping() {
eq ReceiveTokenEndpointDefinition.suitableDefaultMapping() {
String typeName = getMappingList().isEmpty() ?
getToken().getJavaTypeUse().getName() :
getToken().effectiveJavaTypeUse().getName() :
getMappingList().get(0).getFromType().prettyPrint();
switch(typeName) {
case "int":
......@@ -166,9 +164,9 @@ aspect Mappings {
default: return null;
}
}
eq SendToMqttDefinition.suitableDefaultMapping() {
eq SendTokenEndpointDefinition.suitableDefaultMapping() {
String typeName = getMappingList().isEmpty() ?
getToken().getJavaTypeUse().getName() :
getToken().effectiveJavaTypeUse().getName() :
getMappingList().get(getMappingList().size() - 1).getFromType().prettyPrint();
switch(typeName) {
case "int":
......@@ -187,54 +185,54 @@ aspect Mappings {
default: return null;
}
}
eq ReceiveFromRestDefinition.suitableDefaultMapping() {
String typeName = getMappingList().isEmpty() ?
getToken().getJavaTypeUse().getName() :
getMappingList().get(0).getFromType().prettyPrint();
switch(typeName) {
case "int":
case "Integer": return ragconnect().defaultStringToIntMapping();
case "short":
case "Short": return ragconnect().defaultStringToShortMapping();
case "long":
case "Long": return ragconnect().defaultStringToLongMapping();
case "float":
case "Float": return ragconnect().defaultStringToFloatMapping();
case "double":
case "Double": return ragconnect().defaultStringToDoubleMapping();
case "char":
case "Character": return ragconnect().defaultStringToCharMapping();
default: return null;
}
}
eq SendToRestDefinition.suitableDefaultMapping() {
String typeName = getMappingList().isEmpty() ?
getToken().getJavaTypeUse().getName() :
getMappingList().get(getMappingList().size() - 1).getFromType().prettyPrint();
switch(typeName) {
case "int":
case "Integer": return ragconnect().defaultIntToStringMapping();
case "short":
case "Short": return ragconnect().defaultShortToStringMapping();
case "long":
case "Long": return ragconnect().defaultLongToStringMapping();
case "float":
case "Float": return ragconnect().defaultFloatToStringMapping();
case "double":
case "Double": return ragconnect().defaultDoubleToStringMapping();
case "char":
case "Character": return ragconnect().defaultCharToStringMapping();
default: return null;
}
}
// eq ReceiveFromRestDefinition.suitableDefaultMapping() {
// String typeName = getMappingList().isEmpty() ?
// getToken().getJavaTypeUse().getName() :
// getMappingList().get(0).getFromType().prettyPrint();
// switch(typeName) {
// case "int":
// case "Integer": return ragconnect().defaultStringToIntMapping();
// case "short":
// case "Short": return ragconnect().defaultStringToShortMapping();
// case "long":
// case "Long": return ragconnect().defaultStringToLongMapping();
// case "float":
// case "Float": return ragconnect().defaultStringToFloatMapping();
// case "double":
// case "Double": return ragconnect().defaultStringToDoubleMapping();
// case "char":
// case "Character": return ragconnect().defaultStringToCharMapping();
// default: return null;
// }
// }
// eq SendToRestDefinition.suitableDefaultMapping() {
// String typeName = getMappingList().isEmpty() ?
// getToken().getJavaTypeUse().getName() :
// getMappingList().get(getMappingList().size() - 1).getFromType().prettyPrint();
// switch(typeName) {
// case "int":
// case "Integer": return ragconnect().defaultIntToStringMapping();
// case "short":
// case "Short": return ragconnect().defaultShortToStringMapping();
// case "long":
// case "Long": return ragconnect().defaultLongToStringMapping();
// case "float":
// case "Float": return ragconnect().defaultFloatToStringMapping();
// case "double":
// case "Double": return ragconnect().defaultDoubleToStringMapping();
// case "char":
// case "Character": return ragconnect().defaultCharToStringMapping();
// default: return null;
// }
// }
// --- isByteArray ---
syn boolean MappingDefinitionType.isByteArray() = false;
eq JavaArrayMappingDefinitionType.isByteArray() = getType().getName().equals("byte");
// --- isString ---
syn boolean MappingDefinitionType.isString() = false;
eq JavaMappingDefinitionType.isString() = getType().getName().equals("String");
// // --- isString ---
// syn boolean MappingDefinitionType.isString() = false;
// eq JavaMappingDefinitionType.isString() = getType().getName().equals("String");
// --- allMappingDefinitions ---
syn java.util.List<MappingDefinition> RagConnect.allMappingDefinitions() {
......@@ -255,19 +253,19 @@ aspect Mappings {
result.add(defaultDoubleToBytesMapping());
result.add(defaultCharToBytesMapping());
result.add(defaultStringToBytesMapping());
// string conversion
result.add(defaultStringToIntMapping());
result.add(defaultStringToShortMapping());
result.add(defaultStringToLongMapping());
result.add(defaultStringToFloatMapping());
result.add(defaultStringToDoubleMapping());
result.add(defaultStringToCharMapping());
result.add(defaultIntToStringMapping());
result.add(defaultShortToStringMapping());
result.add(defaultLongToStringMapping());
result.add(defaultFloatToStringMapping());
result.add(defaultDoubleToStringMapping());
result.add(defaultCharToStringMapping());
// // string conversion
// result.add(defaultStringToIntMapping());
// result.add(defaultStringToShortMapping());
// result.add(defaultStringToLongMapping());
// result.add(defaultStringToFloatMapping());
// result.add(defaultStringToDoubleMapping());
// result.add(defaultStringToCharMapping());
// result.add(defaultIntToStringMapping());
// result.add(defaultShortToStringMapping());
// result.add(defaultLongToStringMapping());
// result.add(defaultFloatToStringMapping());
// result.add(defaultDoubleToStringMapping());
// result.add(defaultCharToStringMapping());
return result;
}
}
......@@ -31,12 +31,8 @@ EndpointDefinition endpoint_definition
;
EndpointDefinition endpoint_definition_type
= RECEIVE token_ref {: return new ReceiveFromMqttDefinition().setToken(token_ref); :}
| RECEIVE token_ref VIA MQTT {: return new ReceiveFromMqttDefinition().setToken(token_ref); :}
| RECEIVE token_ref VIA REST {: return enableAlwaysApply(new ReceiveFromRestDefinition()).setToken(token_ref); :}
| SEND token_ref {: return new SendToMqttDefinition().setToken(token_ref); :}
| SEND token_ref VIA MQTT {: return new SendToMqttDefinition().setToken(token_ref); :}
| SEND token_ref VIA REST {: return enableAlwaysApply(new SendToRestDefinition()).setToken(token_ref); :}
= RECEIVE token_ref {: return new ReceiveTokenEndpointDefinition().setToken(token_ref); :}
| SEND token_ref {: return new SendTokenEndpointDefinition().setToken(token_ref); :}
;
TokenComponent token_ref
......
......@@ -5,6 +5,3 @@
"maps" { return sym(Terminals.MAPS); }
"to" { return sym(Terminals.TO); }
"as" { return sym(Terminals.AS); }
"via" { return sym(Terminals.VIA); }
"mqtt" { return sym(Terminals.MQTT); }
"rest" { return sym(Terminals.REST); }
......@@ -20,10 +20,14 @@ public class Compiler extends AbstractCompiler {
// private ValueOption optionOutputDir;
private ValueOption optionRootNode;
private ValueOption optionProtocols;
private BooleanOption optionVerbose;
private BooleanOption optionLogReads;
private BooleanOption optionLogWrites;
private static final String OPTION_PROTOCOL_MQTT = "mqtt";
private static final String OPTION_PROTOCOL_REST = "rest";
public Compiler() {
super("ragconnect", true);
}
......@@ -61,10 +65,10 @@ public class Compiler extends AbstractCompiler {
printMessage("Writing output files");
final List<String> handlers = new ArrayList<>();
if (ragConnect.usesMqtt()) {
if (ASTNode.usesMqtt) {
handlers.add("MqttHandler.jadd");
}
if (ragConnect.usesRest()) {
if (ASTNode.usesRest) {
handlers.add("RestHandler.jadd");
}
// copy handlers into outputDir
......@@ -138,6 +142,12 @@ public class Compiler extends AbstractCompiler {
new ValueOption("rootNode", "root node in the base grammar.")
.acceptAnyValue()
.needsValue(true));
optionProtocols = addOption(
new ValueOption("protocols", "Protocols to enable")
.acceptMultipleValues(true)
.addDefaultValue(OPTION_PROTOCOL_MQTT, "Enable MQTT")
.addAcceptedValue(OPTION_PROTOCOL_REST, "Enable REST")
);
optionVerbose = addOption(
new BooleanOption("verbose", "Print more messages while compiling.")
.defaultValue(false));
......@@ -181,6 +191,8 @@ public class Compiler extends AbstractCompiler {
ragConnect.additionalRelations().forEach(ragConnectGrammarPart::addDeclaration);
ASTNode.loggingEnabledForReads = optionLogReads.value();
ASTNode.loggingEnabledForWrites = optionLogWrites.value();
ASTNode.usesMqtt = optionProtocols.hasValue(OPTION_PROTOCOL_MQTT);
ASTNode.usesRest = optionProtocols.hasValue(OPTION_PROTOCOL_REST);
return ragConnect;
}
......
package org.jastadd.ragconnect.compiler;
import beaver.Parser;
import org.jastadd.ragconnect.ast.*;
import org.jastadd.ragconnect.parser.RagConnectParser;
import org.jastadd.ragconnect.scanner.RagConnectScanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* Testing Ros2Rag without parser.
*
* @author rschoene - Initial contribution
*/
public class SimpleMain {
// --- just testing byte[] conversion ---
public static void testing() {
System.out.println("---");
try {
Class<?> clazz = Class.forName("java.util.List");
System.out.println("clazz.getName() = " + clazz.getName());
System.out.println(Integer.class.isAssignableFrom(Integer.class));
System.out.println(new SimpleJavaTypeUse("int").assignableTo(new SimpleJavaTypeUse("Integer")));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
System.out.println("---");
byte[] bytes;
int i = 1;
double d = 2.3d;
float f = 4.2f;
short sh = 13;
long l = 7L;
String s = "Hello";
char c = 'a';
Integer ii = Integer.valueOf(1);
if (!ii.equals(i)) throw new AssertionError("Ints not equal");
// int to byte
ByteBuffer i2b = ByteBuffer.allocate(4);
i2b.putInt(i);
bytes = i2b.array();
// byte to int
ByteBuffer b2i = ByteBuffer.wrap(bytes);
int actual_i = b2i.getInt();
if (i != actual_i) throw new AssertionError("Ints not equal");
// double to byte
ByteBuffer d2b = ByteBuffer.allocate(8);
d2b.putDouble(d);
bytes = d2b.array();
// byte to double
ByteBuffer b2d = ByteBuffer.wrap(bytes);
double actual_d = b2d.getDouble();
if (d != actual_d) throw new AssertionError("Doubles not equal");
// float to byte
ByteBuffer f2b = ByteBuffer.allocate(4);
f2b.putFloat(f);
bytes = f2b.array();
// byte to float
ByteBuffer b2f = ByteBuffer.wrap(bytes);
float actual_f = b2f.getFloat();
if (f != actual_f) throw new AssertionError("Floats not equal");
// short to byte
ByteBuffer sh2b = ByteBuffer.allocate(2);
sh2b.putShort(sh);
bytes = sh2b.array();
// byte to short
ByteBuffer b2sh = ByteBuffer.wrap(bytes);
short actual_sh = b2sh.getShort();
if (sh != actual_sh) throw new AssertionError("Shorts not equal");
// long to byte
ByteBuffer l2b = ByteBuffer.allocate(8);
l2b.putLong(l);
bytes = l2b.array();
// byte to long
ByteBuffer b2l = ByteBuffer.wrap(bytes);
long actual_l = b2l.getLong();
if (l != actual_l) throw new AssertionError("Longs not equal");
// String to byte
bytes = s.getBytes();
// byte to String
String actual_s = new String(bytes);