]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "(refs #7586) Allow always conversion to Object in SCL-Java interface"
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 30 Oct 2017 18:21:38 +0000 (20:21 +0200)
committerGerrit Code Review <gerrit2@www.simantics.org>
Mon, 30 Oct 2017 18:21:38 +0000 (20:21 +0200)
bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java
bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java

index 286cae2728c9f12660c71e5fe2dc38b934dd0568..7283cf26b36a5786c1212f6bc7d6405042cae882 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.document.server.request;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -27,6 +28,8 @@ import org.simantics.scl.compiler.environment.specification.EnvironmentSpecifica
 import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
 import org.simantics.scl.compiler.top.SCLExpressionCompilationException;
 import org.simantics.scl.compiler.types.TCon;
+import org.simantics.scl.compiler.types.TMetaVar;
+import org.simantics.scl.compiler.types.TVar;
 import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.kinds.Kinds;
@@ -232,7 +235,9 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR
     protected Type getExpectedType(ReadGraph graph, CompilationContext context) throws DatabaseException {
         if(possibleExpectedValueType != null) {
             try {
-                return Environments.getType(context.runtimeEnvironment.getEnvironment(), possibleExpectedValueType);
+                Type type = Environments.getType(context.runtimeEnvironment.getEnvironment(), possibleExpectedValueType);
+                type = Types.instantiate(Types.forAll(Types.freeVars(type).toArray(new TVar[0]), type), new ArrayList<TMetaVar>());
+                return type;
             } catch (SCLExpressionCompilationException e) {
                 LOGGER.error("Could not get type for " + String.valueOf(possibleExpectedValueType), e);
             }
index 5013f88146bbb232d48d8f27e8883df40fd81421..e6cdf6ff5b43712b098594d172a91b7595de63cb 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.document.server.request;
 
+import java.util.ArrayList;
 import java.util.Map;
 
 import org.simantics.databoard.Bindings;
@@ -28,6 +29,8 @@ import org.simantics.scl.compiler.environment.Environments;
 import org.simantics.scl.compiler.environment.specification.EnvironmentSpecification;
 import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
 import org.simantics.scl.compiler.top.SCLExpressionCompilationException;
+import org.simantics.scl.compiler.types.TMetaVar;
+import org.simantics.scl.compiler.types.TVar;
 import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.kinds.Kinds;
@@ -205,7 +208,9 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<
     protected Type getExpectedType(ReadGraph graph, CompilationContext context) throws DatabaseException {
         if(possibleExpectedValueType != null) {
             try {
-                return Environments.getType(context.runtimeEnvironment.getEnvironment(), possibleExpectedValueType);
+                Type type = Environments.getType(context.runtimeEnvironment.getEnvironment(), possibleExpectedValueType);
+                type = Types.instantiate(Types.forAll(Types.freeVars(type).toArray(new TVar[0]), type), new ArrayList<TMetaVar>());
+                return type;
             } catch (SCLExpressionCompilationException e) {
                 LOGGER.error("Could not get type for " + String.valueOf(possibleExpectedValueType), e);
             }
index dadc13aa7ee3e926a894d7cfbbe846c69d82c7b9..552c93f6464f0e61e8baea3fe1e6ceec6db29f7e 100644 (file)
@@ -4,6 +4,7 @@ import org.cojen.classfile.TypeDesc;
 import org.osgi.service.component.annotations.Component;
 import org.simantics.scl.compiler.commands.CommandSession;
 import org.simantics.scl.compiler.common.names.Name;
+import org.simantics.scl.compiler.compilation.CompilationContext;
 import org.simantics.scl.compiler.constants.JavaMethod;
 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
 import org.simantics.scl.compiler.elaboration.expressions.EApply;
@@ -63,12 +64,7 @@ public class LoggingModule extends ConcreteModule {
                 value.setMacroRule(new MacroRule() {
                     @Override
                     public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
-                        ConcreteModule module = context.getCompilationContext().module;
-                        String identifier;
-                        if (module != null)
-                            identifier = module.getName().replaceAll("/", ".");
-                        else
-                            identifier = CommandSession.class.getName();
+                        String identifier = resolveModuleIdentifier(context.getCompilationContext());
                         apply.set(new ELiteral(javaMethod), new Expression[] {
                                 new EExternalConstant(LoggerFactory.getLogger(identifier), Logger)
                         });
@@ -84,12 +80,7 @@ public class LoggingModule extends ConcreteModule {
                 value.setMacroRule(new MacroRule() {
                     @Override
                     public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
-                        ConcreteModule module = context.getCompilationContext().module;
-                        String identifier;
-                        if (module != null)
-                            identifier = module.getName().replaceAll("/", ".");
-                        else
-                            identifier = CommandSession.class.getName();
+                        String identifier = resolveModuleIdentifier(context.getCompilationContext());
                         apply.set(new ELiteral(javaMethod), new Expression[] {
                                 new EExternalConstant(LoggerFactory.getLogger(identifier), Logger),
                                 apply.parameters[0]
@@ -106,12 +97,7 @@ public class LoggingModule extends ConcreteModule {
                 value.setMacroRule(new MacroRule() {
                     @Override
                     public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
-                        ConcreteModule module = context.getCompilationContext().module;
-                        String identifier;
-                        if (module != null)
-                            identifier = module.getName().replaceAll("/", ".");
-                        else
-                            identifier = CommandSession.class.getName();
+                        String identifier = resolveModuleIdentifier(context.getCompilationContext());
                         apply.set(new ELiteral(javaMethod), new Expression[] {
                                 new EExternalConstant(LoggerFactory.getLogger(identifier), Logger),
                                 apply.parameters[0],
@@ -129,12 +115,7 @@ public class LoggingModule extends ConcreteModule {
                 value.setMacroRule(new MacroRule() {
                     @Override
                     public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
-                        ConcreteModule module = context.getCompilationContext().module;
-                        String identifier;
-                        if (module != null)
-                            identifier = module.getName().replaceAll("/", ".");
-                        else
-                            identifier = CommandSession.class.getName();
+                        String identifier = resolveModuleIdentifier(context.getCompilationContext());
                         apply.set(new ELiteral(javaMethod), new Expression[] {
                                 new EExternalConstant(LoggerFactory.getLogger(identifier), Logger),
                                 apply.parameters[0],
@@ -152,12 +133,7 @@ public class LoggingModule extends ConcreteModule {
                 value.setMacroRule(new MacroRule() {
                     @Override
                     public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
-                        ConcreteModule module = context.getCompilationContext().module;
-                        String identifier;
-                        if (module != null)
-                            identifier = module.getName().replaceAll("/", ".");
-                        else
-                            identifier = CommandSession.class.getName();
+                        String identifier = resolveModuleIdentifier(context.getCompilationContext());
                         apply.set(new ELiteral(javaMethod), new Expression[] {
                                 new EExternalConstant(LoggerFactory.getLogger(identifier), Logger),
                                 apply.parameters[0],
@@ -181,4 +157,19 @@ public class LoggingModule extends ConcreteModule {
     private static String capitalizeFirstCharacter(String input) {
         return input.substring(0, 1).toUpperCase() + input.substring(1);
     }
+    
+    private static String resolveModuleIdentifier(CompilationContext context) {
+        ConcreteModule module = context.module;
+        String identifier;
+        if (module != null) {
+            String moduleName = module.getName();
+            if (moduleName.startsWith("http://")) {
+                moduleName = moduleName.substring("http://".length());
+            }
+            identifier = moduleName.replaceAll("/", ".");
+        } else {
+            identifier = CommandSession.class.getName();
+        }
+        return identifier;
+    }
 }