Search in sources :

Example 31 with ILanguageComponent

use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.

the class LanguageServiceTest method nonExistentLanguage.

/**
 * Try to remove component that was not added to the language service. Assert that exception is thrown.
 */
@Test(expected = IllegalStateException.class)
public void nonExistentLanguage() throws Exception {
    final LanguageVersion version = version(0, 0, 1);
    final FileObject location = createDir("ram:///");
    final ILanguageComponent component = language(groupId, "org.metaborg.lang.entity", version, location, "Entity");
    languageService.remove(component);
    languageService.remove(component);
}
Also used : LanguageVersion(org.metaborg.core.language.LanguageVersion) FileObject(org.apache.commons.vfs2.FileObject) ILanguageComponent(org.metaborg.core.language.ILanguageComponent) Test(org.junit.Test) MetaborgTest(org.metaborg.core.test.MetaborgTest)

Example 32 with ILanguageComponent

use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.

the class DefaultDependencyService method getLanguages.

/**
 * Gets the language components with the specified identifiers.
 *
 * @param ids
 *            The language identifiers.
 * @return A collection of language components.
 */
private Collection<ILanguageComponent> getLanguages(Iterable<LanguageIdentifier> ids) throws MissingDependencyException {
    final Collection<ILanguageComponent> components = Lists.newLinkedList();
    for (LanguageIdentifier id : ids) {
        final ILanguageComponent component = this.languageService.getComponent(id);
        if (component == null) {
            throw new MissingDependencyException(logger.format("Language for dependency {} does not exist", id));
        }
        components.add(component);
    }
    return components;
}
Also used : LanguageIdentifier(org.metaborg.core.language.LanguageIdentifier) ILanguageComponent(org.metaborg.core.language.ILanguageComponent)

Example 33 with ILanguageComponent

use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.

the class DependencyPathProvider method includePaths.

@Override
public Iterable<FileObject> includePaths(IProject project, final String languageName) throws MetaborgException {
    final Iterable<ILanguageComponent> dependencies = dependencyService.sourceDeps(project);
    final Collection<FileObject> includes = Lists.newArrayList();
    for (final ILanguageComponent dependency : dependencies) {
        final Collection<IExportConfig> exports = dependency.config().exports();
        for (IExportConfig export : exports) {
            export.accept(new IExportVisitor() {

                @Override
                public void visit(LangDirExport export) {
                    if (languageName.equals(export.language)) {
                        resolve(dependency.location(), Iterables2.singleton(export.directory), includes);
                    }
                }

                @Override
                public void visit(LangFileExport export) {
                    if (languageName.equals(export.language)) {
                        resolve(dependency.location(), Iterables2.singleton(export.file), includes);
                    }
                }

                @Override
                public void visit(ResourceExport export) {
                // Ignore resource exports
                }
            });
        }
    }
    return includes;
}
Also used : LangFileExport(org.metaborg.core.config.LangFileExport) IExportConfig(org.metaborg.core.config.IExportConfig) IExportVisitor(org.metaborg.core.config.IExportVisitor) ResourceExport(org.metaborg.core.config.ResourceExport) LangDirExport(org.metaborg.core.config.LangDirExport) FileObject(org.apache.commons.vfs2.FileObject) ILanguageComponent(org.metaborg.core.language.ILanguageComponent)

Example 34 with ILanguageComponent

use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.

the class LanguageIdentitificationTest method identification.

@Test
public void identification() throws Exception {
    final LanguageVersion version = version(0, 0, 1);
    final FileObject location1 = createDir("ram:///Entity1");
    final FileObject location2 = createDir("ram:///Entity2");
    final ILanguageComponent component1 = language(groupId, "org.metaborg.lang.entity1", version, location1, "Entity1", "ent1");
    final ILanguageImpl impl1 = Iterables.get(component1.contributesTo(), 0);
    final ILanguageComponent component2 = language(groupId, "org.metaborg.lang.entity2", version, location2, "Entity2", "ent2");
    final ILanguageImpl impl2 = Iterables.get(component2.contributesTo(), 0);
    assertTrue(languageIdentifierService.identify(resourceService.resolve("ram:///Entity1/test.ent1"), impl1));
    assertFalse(languageIdentifierService.identify(resourceService.resolve("ram:///Entity2/test.ent2"), impl1));
    assertTrue(languageIdentifierService.identify(resourceService.resolve("ram:///Entity2/test.ent2"), impl2));
    assertFalse(languageIdentifierService.identify(resourceService.resolve("ram:///Entity1/test.ent1"), impl2));
}
Also used : ILanguageImpl(org.metaborg.core.language.ILanguageImpl) LanguageVersion(org.metaborg.core.language.LanguageVersion) FileObject(org.apache.commons.vfs2.FileObject) ILanguageComponent(org.metaborg.core.language.ILanguageComponent) Test(org.junit.Test) MetaborgTest(org.metaborg.core.test.MetaborgTest)

Example 35 with ILanguageComponent

use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.

the class JSGLRCompletionService method completionErroneousProgramsNested.

public Collection<? extends ICompletion> completionErroneousProgramsNested(int cursorPosition, Collection<IStrategoTerm> nestedCompletionTerms, ISpoofaxParseUnit completionParseResult) throws MetaborgException {
    final FileObject location = completionParseResult.source();
    final ILanguageImpl language = completionParseResult.input().langImpl();
    final String languageName = language.belongsTo().name();
    final Collection<ICompletion> completions = Lists.newLinkedList();
    IStrategoTerm completionAst = completionParseResult.ast();
    for (ILanguageComponent component : language.components()) {
        final ITermFactory termFactory = termFactoryService.get(component, null, false);
        for (IStrategoTerm nestedCompletionTerm : nestedCompletionTerms) {
            final HybridInterpreter runtime = strategoRuntimeService.runtime(component, location, false);
            Collection<IStrategoTerm> inputsStrategoNested = Lists.newLinkedList();
            // calculate direct proposals
            inputsStrategoNested.addAll(calculateDirectCompletionProposals(nestedCompletionTerm, termFactory, completionAst, languageName, runtime));
            // calculate inner nested proposals
            Collection<IStrategoTerm> innerNestedCompletionTerms = findNestedCompletionTerm((StrategoTerm) nestedCompletionTerm, true);
            for (IStrategoTerm innerNestedCompletionTerm : innerNestedCompletionTerms) {
                inputsStrategoNested.addAll(calculateNestedCompletionProposals(nestedCompletionTerm, innerNestedCompletionTerm, termFactory, completionAst, languageName, runtime));
            }
            for (IStrategoTerm inputStrategoNested : inputsStrategoNested) {
                final IStrategoTerm proposalTermNested = strategoCommon.invoke(runtime, inputStrategoNested, "get-proposals-incorrect-programs-nested-" + languageName);
                if (proposalTermNested == null) {
                    logger.error("Getting proposals for {} failed", inputStrategoNested);
                    continue;
                }
                final String name = Tools.asJavaString(proposalTermNested.getSubterm(0));
                final String text = Tools.asJavaString(proposalTermNested.getSubterm(1));
                final String additionalInfo = Tools.asJavaString(proposalTermNested.getSubterm(2));
                final StrategoAppl change = (StrategoAppl) proposalTermNested.getSubterm(3);
                final StrategoTerm completionTerm = (StrategoTerm) proposalTermNested.getSubterm(4);
                String prefix = calculatePrefix(cursorPosition, completionTerm);
                String suffix = calculateSuffix(cursorPosition, completionTerm);
                String completionKind = "recovery";
                // if the change is inserting at the end of a list
                if (change.getConstructor().getName().contains("INSERT_AT_END")) {
                    // calls a different method because now, the program has errors that should be fixed
                    final ICompletion completion = createCompletionInsertAtEndFixing(name, text, additionalInfo, prefix, suffix, change, completionKind);
                    if (completion == null) {
                        logger.error("Unexpected proposal term {}, skipping", proposalTermNested);
                        continue;
                    }
                    completions.add(completion);
                } else if (change.getConstructor().getName().contains("INSERT_BEFORE")) {
                    final ICompletion completion = createCompletionInsertBeforeFixing(name, text, additionalInfo, prefix, suffix, change, completionKind);
                    if (completion == null) {
                        logger.error("Unexpected proposal term {}, skipping", proposalTermNested);
                        continue;
                    }
                    completions.add(completion);
                } else if (change.getConstructor().getName().contains("INSERTION_TERM")) {
                    final ICompletion completion = createCompletionInsertionTermFixing(name, text, additionalInfo, prefix, suffix, change, completionKind);
                    if (completion == null) {
                        logger.error("Unexpected proposal term {}, skipping", proposalTermNested);
                        continue;
                    }
                    completions.add(completion);
                } else if (change.getConstructor().getName().contains("REPLACE_TERM")) {
                    final ICompletion completion = createCompletionReplaceTermFixing(name, text, additionalInfo, prefix, suffix, change, completionKind);
                    if (completion == null) {
                        logger.error("Unexpected proposal term {}, skipping", proposalTermNested);
                        continue;
                    }
                    completions.add(completion);
                }
            }
        }
    }
    return completions;
}
Also used : ICompletion(org.metaborg.core.completion.ICompletion) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) StrategoTerm(org.spoofax.terms.StrategoTerm) HybridInterpreter(org.strategoxt.HybridInterpreter) FileObject(org.apache.commons.vfs2.FileObject) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) ILanguageComponent(org.metaborg.core.language.ILanguageComponent) ITermFactory(org.spoofax.interpreter.terms.ITermFactory) IStrategoAppl(org.spoofax.interpreter.terms.IStrategoAppl) StrategoAppl(org.spoofax.terms.StrategoAppl)

Aggregations

ILanguageComponent (org.metaborg.core.language.ILanguageComponent)40 FileObject (org.apache.commons.vfs2.FileObject)26 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)24 Test (org.junit.Test)12 LanguageIdentifier (org.metaborg.core.language.LanguageIdentifier)11 LanguageVersion (org.metaborg.core.language.LanguageVersion)11 MetaborgTest (org.metaborg.core.test.MetaborgTest)11 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)9 ITermFactory (org.spoofax.interpreter.terms.ITermFactory)9 HybridInterpreter (org.strategoxt.HybridInterpreter)9 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)8 ILanguage (org.metaborg.core.language.ILanguage)7 MetaborgException (org.metaborg.core.MetaborgException)6 IContext (org.metaborg.core.context.IContext)5 Nullable (javax.annotation.Nullable)4 MetaborgRuntimeException (org.metaborg.core.MetaborgRuntimeException)4 ICompletion (org.metaborg.core.completion.ICompletion)4 IStrategoList (org.spoofax.interpreter.terms.IStrategoList)4 IOException (java.io.IOException)3 FileSystemException (org.apache.commons.vfs2.FileSystemException)3