Search in sources :

Example 1 with TypesmartContext

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;
}
Also used : ILanguageComponent(org.metaborg.core.language.ILanguageComponent) TypesmartContext(org.spoofax.terms.typesmart.TypesmartContext)

Example 2 with TypesmartContext

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;
    }
}
Also used : TypesmartTermFactory(org.spoofax.terms.typesmart.TypesmartTermFactory) ISpoofaxProjectConfig(org.metaborg.spoofax.core.config.ISpoofaxProjectConfig) TypesmartContext(org.spoofax.terms.typesmart.TypesmartContext)

Example 3 with TypesmartContext

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;
}
Also used : FileOutputStream(java.io.FileOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) TypesmartContext(org.spoofax.terms.typesmart.TypesmartContext)

Example 4 with TypesmartContext

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;
    }
}
Also used : TypesmartTermFactory(org.spoofax.terms.typesmart.TypesmartTermFactory) ISpoofaxProjectConfig(org.metaborg.spoofax.core.config.ISpoofaxProjectConfig) TypesmartContext(org.spoofax.terms.typesmart.TypesmartContext)

Example 5 with TypesmartContext

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;
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) ILanguageComponent(org.metaborg.core.language.ILanguageComponent) TypesmartContext(org.spoofax.terms.typesmart.TypesmartContext) SpoofaxCommonPaths(org.metaborg.spoofax.core.build.SpoofaxCommonPaths) MissingDependencyException(org.metaborg.core.build.dependency.MissingDependencyException)

Aggregations

TypesmartContext (org.spoofax.terms.typesmart.TypesmartContext)5 ILanguageComponent (org.metaborg.core.language.ILanguageComponent)2 ISpoofaxProjectConfig (org.metaborg.spoofax.core.config.ISpoofaxProjectConfig)2 TypesmartTermFactory (org.spoofax.terms.typesmart.TypesmartTermFactory)2 FileOutputStream (java.io.FileOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 FileObject (org.apache.commons.vfs2.FileObject)1 MissingDependencyException (org.metaborg.core.build.dependency.MissingDependencyException)1 SpoofaxCommonPaths (org.metaborg.spoofax.core.build.SpoofaxCommonPaths)1