Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thesave committed Jun 11, 2021
1 parent 4d4ff6e commit e9fc742
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 116 deletions.
Binary file modified .gradle/7.0/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/checksums/checksums.lock
Binary file not shown.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ dependencies {
app "org.antlr:antlr4:4.9.2"
app 'com.github.javaparser:javaparser-core:3.22.1'
app 'info.picocli:picocli:4.6.1'
core fileTree( dir: libDir, include: '*.jar' )
core 'org.jolie-lang:jolie:1.10.4'
core 'org.jolie-lang:libjolie:1.10.4'
core 'org.jolie-lang:jolie-cli:1.10.4'
}

sourceSets {
Expand Down
Binary file removed lib/jolie-1.10.0.jar
Binary file not shown.
Binary file removed lib/jolie-cli-1.10.2-rc1.jar
Binary file not shown.
Binary file removed lib/libjolie-1.10.0.jar
Binary file not shown.
66 changes: 51 additions & 15 deletions src/app/java/jsdt/JSDTVisitor/JSDTVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ public static List< CompilationUnit > generateInterfaceClass( InterfaceDefinitio
return jsdt.compilationUnits;
}

public static List< CompilationUnit > generateInterfaceAndTypeClasses( InterfaceDefinition ctx, String packageName ){
public static List< CompilationUnit > generateInterfaceAndTypeClasses( InterfaceDefinition ctx, String packageName ) {
JSDTVisitor jsdt = new JSDTVisitor( packageName );
jsdt.visit( ctx, null );
jsdt.collectedInterfaceTypes.forEach( td -> {
jsdt.compilationUnits.addAll( generateTypeClasses( td, packageName ) );
});
} );
return jsdt.compilationUnits;
}

Expand Down Expand Up @@ -422,6 +422,9 @@ public Void visit( VariablePathNode variablePathNode, Void unused ) {

@Override
public Void visit( TypeInlineDefinition typeInlineDefinition, Void unused ) {
if ( typeInlineDefinition.name().equals( "undefined" ) ) {
return null;
}
visitedTypes.add( typeInlineDefinition.name() );
BasicTypeDefinition basicTypeDefinition = typeInlineDefinition.basicType();
Set< Map.Entry< String, TypeDefinition > > subNodes = typeInlineDefinition.subTypes();
Expand All @@ -433,6 +436,9 @@ public Void visit( TypeInlineDefinition typeInlineDefinition, Void unused ) {
compilationUnit.addImport( "jolie.runtime.Value" );

String javaNativeType = jolieToJavaType( basicTypeDefinition.nativeType() );
if ( javaNativeType.equals( "ByteArray" ) ) {
compilationUnit.addImport( "jolie.runtime.ByteArray" );
}

ClassOrInterfaceDeclaration theClass = compilationUnit.addClass( getLineage() )
.setModifier( Modifier.Keyword.PUBLIC, true )
Expand Down Expand Up @@ -488,6 +494,11 @@ public Void visit( TypeInlineDefinition typeInlineDefinition, Void unused ) {
compilationUnit.addImport( "java.util.stream.Collectors" );
}
String fieldTypeName = node instanceof TypeDefinitionLink ? ( ( TypeDefinitionLink ) node ).linkedTypeName() : getLineage();
switch ( fieldTypeName ) {
case "undefined":
case "any":
fieldTypeName = "Value";
}
FieldDeclaration field = theClass.addField(
cardinalityClass + "<" + fieldTypeName + ">",
nodeName,
Expand All @@ -502,19 +513,29 @@ public Void visit( TypeInlineDefinition typeInlineDefinition, Void unused ) {
.add( nodeName )
.add( "=" )
.add( cardinalityClass + ".of( value.getChildren(" )
.add( "\"" + nodeName + "\"" )
.add( ").stream().map(" )
.add( fieldTypeName + "::parse" )
.add( ").collect( Collectors.toList() ) );" );
.add( "\"" + nodeName + "\"" );
if ( !fieldTypeName.equals( "Value" ) ) {
s.add( ").stream().map(" )
.add( fieldTypeName + "::parse" );
} else {
s.add( ").stream(" );
}
s.add( ").collect( Collectors.toList() ) );" );
} else {
s.add( cardinalityClass + "<" + fieldTypeName + ">" )
.add( nodeName )
.add( "=" )
.add( cardinalityClass + ".of(" )
.add( fieldTypeName + ".parse(" )
.add( "value.getChildren(" )
.add( "\"" + nodeName + "\"" )
.add( ").get( 0 ) ) );" );
.add( cardinalityClass + ".of(" );
if ( fieldTypeName.equals( "Value" ) ) {
s.add( "value.getChildren(" )
.add( "\"" + nodeName + "\"" )
.add( ").get( 0 ) );" );
} else {
s.add( fieldTypeName + ".parse(" )
.add( "value.getChildren(" )
.add( "\"" + nodeName + "\"" )
.add( ").get( 0 ) ) );" );
}
}
ifBranch.addStatement( s.toString() );
parseReturnParameters.add( nodeName );
Expand Down Expand Up @@ -576,19 +597,34 @@ public Void visit( InterfaceDefinition interfaceDefinition, Void unused ) {
case "string":
methodBody.addStatement( "String request = value." + jolieToGetValue( requestType.name() ) + "();" );
break;
case "byte":
case "raw":
compilationUnit.addImport( "jolie.runtime.ByteArray" );
methodBody.addStatement( "ByteArray request = value." + jolieToGetValue( requestType.name() ) + "();" );
break;
default:
collectedInterfaceTypes.add( requestType );
methodBody.addStatement( requestType.name() + " request = " + requestType.name() + ".parse( value );" );
switch ( requestType.name() ) {
case "any":
case "undefined":
break;
default:
collectedInterfaceTypes.add( requestType );
methodBody.addStatement( requestType.name() + " request = " + requestType.name() + ".parse( value );" );
}
}
if ( operation instanceof RequestResponseOperationDeclaration ) {
compilationUnit.addImport( "jolie.runtime.embedding.RequestResponse" );
methodDeclaration.addAnnotation( "RequestResponse" );
TypeDefinition responseType = ( ( RequestResponseOperationDeclaration ) operation ).responseType();
switch ( responseType.name() ) {
case "void": case "bool": case "int": case "double": case "long": case "string": case "byte":
case "void":
case "bool":
case "int":
case "double":
case "long":
case "string":
case "raw":
case "any":
case "undefined":
break;
default:
collectedInterfaceTypes.add( responseType );
Expand Down
8 changes: 4 additions & 4 deletions src/app/java/jsdt/JSDTVisitor/JSDTVisitorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static String jolieToJavaType( NativeType ctx ) {
return "Double";
case RAW:
return "ByteArray";
default: // "any"
default: // "any" or "undefined"
return "Value";
}
}
Expand All @@ -71,7 +71,7 @@ static Optional< String > jolieToIsValue( NativeType ctx ) {
case RAW:
checker = "isByteArray";
break;
default: // "any" or "void"
default: // "void", "any" or "undefined"
}
return Optional.ofNullable( checker );
}
Expand Down Expand Up @@ -124,10 +124,10 @@ static String jolieToGetValue( String basicTypeName ) {
case "string":
getter = "strValue";
break;
case "byte":
case "raw":
getter = "byteArrayValue";
break;
default: // "void" or "any"
default: // "void", "any" or "undefined"
;
}
return getter;
Expand Down
96 changes: 0 additions & 96 deletions src/test/java/Test.java

This file was deleted.

Loading

0 comments on commit e9fc742

Please sign in to comment.