use of org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec in project spoofax by metaborg.
the class LegacyLanguageSpecNamePrimitive method call.
@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) throws MetaborgException {
final FileObject location = context.location();
final IProject project = projectService.get(location);
if (project == null) {
return null;
}
if (languageSpecServiceProvider == null) {
// Indicates that meta-Spoofax is not available (ISpoofaxLanguageSpecService cannot be injected), but this
// should never happen because this primitive is inside meta-Spoofax. Check for null just in case.
logger.debug("Language specification service is not available; static injection failed");
return null;
}
final ISpoofaxLanguageSpecService languageSpecService = languageSpecServiceProvider.get();
if (!languageSpecService.available(project)) {
return null;
}
final ISpoofaxLanguageSpec languageSpec;
try {
languageSpec = languageSpecService.get(project);
} catch (ConfigException e) {
throw new MetaborgException("Unable to get language specification name for " + location, e);
}
if (languageSpec == null) {
return null;
}
return factory.makeString(languageSpec.config().name());
}
use of org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec in project spoofax by metaborg.
the class PlaceholderCharsPrimitive method call.
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
org.metaborg.core.context.IContext context = (org.metaborg.core.context.IContext) env.contextObject();
final FileObject location = context.location();
final IProject project = projectService.get(location);
if (project == null) {
return false;
}
if (languageSpecServiceProvider == null) {
// Indicates that meta-Spoofax is not available (ISpoofaxLanguageSpecService cannot be injected), but this
// should never happen because this primitive is inside meta-Spoofax. Check for null just in case.
logger.error("Language specification service is not available; static injection failed");
return false;
}
final ISpoofaxLanguageSpecService languageSpecService = languageSpecServiceProvider.get();
if (!languageSpecService.available(project)) {
return false;
}
final ISpoofaxLanguageSpec languageSpec;
try {
languageSpec = languageSpecService.get(project);
} catch (ConfigException e) {
throw new InterpreterException("Unable to get language specification name for " + location, e);
}
if (languageSpec == null) {
return false;
}
PlaceholderCharacters placeholderChars = languageSpec.config().placeholderChars();
IStrategoString prefix = env.getFactory().makeString(placeholderChars.prefix);
IStrategoString suffix = null;
if (placeholderChars.suffix != null) {
suffix = env.getFactory().makeString(placeholderChars.suffix);
} else {
suffix = env.getFactory().makeString("");
}
env.setCurrent(env.getFactory().makeTuple(prefix, suffix));
return true;
}
use of org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec in project spoofax by metaborg.
the class LanguageSpecPpNamePrimitive method call.
@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) throws MetaborgException {
final FileObject location = context.location();
final IProject project = projectService.get(location);
if (project == null) {
return null;
}
if (languageSpecServiceProvider == null) {
// Indicates that meta-Spoofax is not available (ISpoofaxLanguageSpecService cannot be injected), but this
// should never happen because this primitive is inside meta-Spoofax. Check for null just in case.
logger.error("Language specification service is not available; static injection failed");
return null;
}
final ISpoofaxLanguageSpecService languageSpecService = languageSpecServiceProvider.get();
if (!languageSpecService.available(project)) {
return null;
}
final ISpoofaxLanguageSpec languageSpec;
try {
languageSpec = languageSpecService.get(project);
} catch (ConfigException e) {
throw new MetaborgException("Unable to get language specification name for " + location, e);
}
if (languageSpec == null) {
return null;
}
return factory.makeString(languageSpec.config().prettyPrintLanguage());
}
use of org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec in project spoofax by metaborg.
the class LanguageSpecBuilder method packageBuilderInput.
private PackageBuilder.Input packageBuilderInput(LanguageSpecBuildInput input, Origin origin) throws FileSystemException {
final ISpoofaxLanguageSpec languageSpec = input.languageSpec();
final ISpoofaxLanguageSpecConfig config = languageSpec.config();
final FileObject baseLoc = input.languageSpec().location();
final SpoofaxLangSpecCommonPaths paths = new SpoofaxLangSpecCommonPaths(baseLoc);
final FileObject buildInfoLoc = paths.plutoBuildInfoDir();
final SpoofaxContext context = new SpoofaxContext(baseLoc, buildInfoLoc);
final StrategoFormat strFormat = config.strFormat();
final FileObject strJavaStratFileCandidate = paths.strMainJavaStratFile(config.identifier().id);
@Nullable final File strJavaStratFile;
if (strJavaStratFileCandidate.exists()) {
strJavaStratFile = resourceService.localPath(strJavaStratFileCandidate);
} else {
strJavaStratFile = null;
}
final File javaStratClassesDir = resourceService.localPath(paths.strTargetClassesJavaStratDir(config.identifier().id));
final File dsGeneratedClassesDir = resourceService.localPath(paths.dsTargetClassesGenerateDir());
final File dsManualClassesDir = resourceService.localPath(paths.dsTargetClassesManualDir());
final List<File> strJavaStratIncludeDirs = Lists.newArrayList(javaStratClassesDir, dsGeneratedClassesDir, dsManualClassesDir);
return new PackageBuilder.Input(context, config.identifier().id, origin, strFormat, strJavaStratFile, strJavaStratIncludeDirs);
}
Aggregations