package org.simantics.document.server.request;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
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;
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);
}
package org.simantics.document.server.request;
+import java.util.ArrayList;
import java.util.Map;
import org.simantics.databoard.Bindings;
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;
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);
}
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;
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)
});
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]
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],
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],
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],
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;
+ }
}