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);
}
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;
}
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;
}
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));
}
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;
}
Aggregations