use of org.spoofax.terms.typesmart.TypesmartContext in project spoofax by metaborg.
the class TermFactoryService method getTypesmartContext.
private TypesmartContext getTypesmartContext(ILanguageImpl impl) {
TypesmartContext context = implMergedTypesmartContexts.get(impl);
if (context == null) {
context = TypesmartContext.empty();
for (ILanguageComponent component : impl.components()) {
context = context.merge(getTypesmartContext(component));
}
implMergedTypesmartContexts.put(impl, context);
}
return context;
}
use of org.spoofax.terms.typesmart.TypesmartContext in project spoofax by metaborg.
the class TermFactoryService method get.
@Override
public ITermFactory get(ILanguageComponent component, @Nullable IProject project, boolean supportsTypesmart) {
if (!supportsTypesmart || project == null) {
return genericFactory;
}
ISpoofaxProjectConfig config = configService.get(project);
if (config == null || !config.typesmart()) {
return genericFactory;
}
TypesmartContext context = getTypesmartContext(component);
if (!context.isEmpty()) {
return new TypesmartTermFactory(genericFactory, typesmartLogger, context);
} else {
return genericFactory;
}
}
use of org.spoofax.terms.typesmart.TypesmartContext in project spoofax by metaborg.
the class Typesmart method build.
@Override
public None build(Input input) throws IOException {
processMainStrategoFile(input.strFile, input.strjIncludeDirs);
constructorSignatures = Collections.unmodifiableMap(constructorSignatures);
lexicals = Collections.unmodifiableSet(lexicals);
injections = Collections.unmodifiableSet(injections);
TypesmartContext typesmartContext = new TypesmartContext(constructorSignatures, lexicals, injections);
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(input.typesmartExportedFile))) {
oos.writeObject(typesmartContext);
}
provide(input.typesmartExportedFile);
return None.val;
}
use of org.spoofax.terms.typesmart.TypesmartContext in project spoofax by metaborg.
the class TermFactoryService method get.
@Override
public ITermFactory get(ILanguageImpl impl, @Nullable IProject project, boolean supportsTypesmart) {
if (!supportsTypesmart || project == null) {
return genericFactory;
}
ISpoofaxProjectConfig config = configService.get(project);
if (config == null || !config.typesmart()) {
return genericFactory;
}
TypesmartContext context = getTypesmartContext(impl);
if (!context.isEmpty()) {
return new TypesmartTermFactory(genericFactory, typesmartLogger, context);
} else {
return genericFactory;
}
}
use of org.spoofax.terms.typesmart.TypesmartContext in project spoofax by metaborg.
the class TermFactoryService method getTypesmartContext.
private TypesmartContext getTypesmartContext(ILanguageComponent component) {
TypesmartContext context = mergedTypesmartContexts.get(component);
if (context == null) {
FileObject localContextFile = new SpoofaxCommonPaths(component.location()).strTypesmartExportedFile();
context = TypesmartContext.load(localContextFile, typesmartLogger);
try {
for (ILanguageComponent other : dependencyService.sourceDeps(component)) {
FileObject otherContextFile = new SpoofaxCommonPaths(other.location()).strTypesmartExportedFile();
TypesmartContext otherContext = TypesmartContext.load(otherContextFile, typesmartLogger);
context = context.merge(otherContext);
}
} catch (MissingDependencyException e) {
typesmartLogger.error("Could not load source dependencies of " + component + " to resolve typesmart contexts.", e);
}
mergedTypesmartContexts.put(component, context);
}
return context;
}
Aggregations