Skip to content

Commit

Permalink
Remove get methods from ITermFactoryService
Browse files Browse the repository at this point in the history
  • Loading branch information
Apanatshka committed May 18, 2020
1 parent c2ed0fd commit fa72589
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ public Collection<? extends ICompletion> completionEmptyProgram(Iterable<String>
Collection<ICompletion> completions = Lists.newLinkedList();

final String languageName = language.belongsTo().name();
final ITermFactory termFactory = termFactoryService.getGeneric();

for(ILanguageComponent component : language.components()) {
// call Stratego part of the framework to compute change
final HybridInterpreter runtime = strategoRuntimeService.runtime(component, location);
final ITermFactory termFactory = termFactoryService.get(component, null);

for(String startSymbol : startSymbols) {
String placeholderName = startSymbol + "-Plhdr";
Expand Down Expand Up @@ -219,12 +219,10 @@ public Collection<ICompletion> completionCorrectPrograms(int position, boolean b
final FileObject location = parseResult.source();
final ILanguageImpl language = parseResult.input().langImpl();
final String languageName = language.belongsTo().name();
final ITermFactory termFactory = termFactoryService.getGeneric();

for(ILanguageComponent component : language.components()) {


final HybridInterpreter runtime = strategoRuntimeService.runtime(component, location);
final ITermFactory termFactory = termFactoryService.get(component, null);

final Map<IStrategoTerm, Boolean> leftRecursiveTerms = new HashMap<IStrategoTerm, Boolean>();
final Map<IStrategoTerm, Boolean> rightRecursiveTerms = new HashMap<IStrategoTerm, Boolean>();
Expand Down Expand Up @@ -268,7 +266,7 @@ private Collection<? extends ICompletion> recursiveCompletions(Iterable<IStrateg

// call Stratego part of the framework to compute change
final HybridInterpreter runtime = strategoRuntimeService.runtime(component, location);
final ITermFactory termFactory = termFactoryService.get(component, null);
final ITermFactory termFactory = termFactoryService.getGeneric();

for(IStrategoTerm term : leftRecursive) {
IStrategoTerm sort = termFactory.makeString(ImploderAttachment.getSort(term));
Expand Down Expand Up @@ -377,7 +375,7 @@ public Collection<ICompletion> placeholderCompletions(IStrategoAppl placeholder,

// call Stratego part of the framework to compute change
final HybridInterpreter runtime = strategoRuntimeService.runtime(component, location);
final ITermFactory termFactory = termFactoryService.get(component, null);
final ITermFactory termFactory = termFactoryService.getGeneric();

IStrategoTerm placeholderParent = ParentAttachment.getParent(placeholder);
if(placeholderParent == null) {
Expand Down Expand Up @@ -444,7 +442,7 @@ public Collection<ICompletion> optionalCompletions(Iterable<IStrategoTerm> optio

Collection<ICompletion> completions = Lists.newLinkedList();

final ITermFactory termFactory = termFactoryService.get(component, null);
final ITermFactory termFactory = termFactoryService.getGeneric();

for(IStrategoTerm optional : optionals) {

Expand Down Expand Up @@ -509,7 +507,7 @@ public Collection<ICompletion> listsCompletions(int position, boolean blankLineC

Collection<ICompletion> completions = Lists.newLinkedList();

final ITermFactory termFactory = termFactoryService.get(component, null);
final ITermFactory termFactory = termFactoryService.getGeneric();

for(IStrategoList list : lists) {
ListImploderAttachment attachment = list.getAttachment(null);
Expand Down Expand Up @@ -800,9 +798,9 @@ public Collection<ICompletion> completionErroneousPrograms(int cursorPosition,
final String languageName = language.belongsTo().name();
final Collection<ICompletion> completions = Lists.newLinkedList();
final Collection<IStrategoTerm> proposalsTerm = Lists.newLinkedList();
final ITermFactory termFactory = termFactoryService.getGeneric();

for(ILanguageComponent component : language.components()) {
final ITermFactory termFactory = termFactoryService.get(component, null);
for(IStrategoTerm completionTerm : completionTerms) {
IStrategoTerm completionAst = completionParseResult.ast();
final IStrategoTerm topMostAmb = findTopMostAmbNode(completionTerm);
Expand Down Expand Up @@ -1168,9 +1166,9 @@ public Collection<? extends ICompletion> completionErroneousProgramsNested(int c
final String languageName = language.belongsTo().name();
final Collection<ICompletion> completions = Lists.newLinkedList();
IStrategoTerm completionAst = completionParseResult.ast();
final ITermFactory termFactory = termFactoryService.getGeneric();

for(ILanguageComponent component : language.components()) {
final ITermFactory termFactory = termFactoryService.get(component, null);
for(IStrategoTerm nestedCompletionTerm : nestedCompletionTerms) {
final HybridInterpreter runtime = strategoRuntimeService.runtime(component, location);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class IndexTaskContext implements IContext, IContextInternal, IIndexTaskC
public IndexTaskContext(Injector injector, ITermFactoryService termFactoryService, ContextIdentifier identifier) {
this.injector = injector;

this.termFactory = termFactoryService.get(identifier.language, null);
this.termFactory = termFactoryService.getGeneric();
this.lock = new ReentrantReadWriteLock(true);
this.persistentIdentifier = FileUtils.sanitize(identifier.language.id().toString());
this.identifier = identifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private Tuple2<Spec, IConstraint> loadSpec(FileObject resource) throws MetaborgE
}

final StrategoTerms strategoTerms =
new StrategoTerms(S.termFactoryService.get(statixLang, context.project()));
new StrategoTerms(S.termFactoryService.getGeneric());
final IConstraint constraint =
StatixTerms.constraint().match(strategoTerms.fromStratego(evalPair.getSubterm(0)))
.orElseThrow(() -> new MetaborgException("Expected constraint"));
Expand All @@ -136,7 +136,7 @@ public static TermFormatter pretty(Spoofax S, IContext context, String strategy)
final ITermFactory tf;
final HybridInterpreter runtime;
try {
tf = S.termFactoryService.get(lc, context.project());
tf = S.termFactoryService.getGeneric();
runtime = S.strategoRuntimeService.runtime(lc, context);
} catch(MetaborgException e) {
throw new MetaborgRuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,18 @@ public class StrategoRuntimeService implements IStrategoRuntimeService, AutoClos
private final ITermFactoryService termFactoryService;
private final Set<IOperatorRegistry> strategoLibraries;
private final ParseStrategoFileStrategy parseStrategoFileStrategy;
private final IProjectService projectService;
private final Set<ClassLoader> additionalClassLoaders;

private final Map<ILanguageComponent, HybridInterpreter> prototypes = new HashMap<>();


@Inject public StrategoRuntimeService(IResourceService resourceService, ITermFactoryService termFactoryService,
Set<IOperatorRegistry> strategoLibraries, ParseStrategoFileStrategy parseStrategoFileStrategy,
IProjectService projectService, Set<ClassLoader> additionalClassLoaders) {
Set<ClassLoader> additionalClassLoaders) {
this.resourceService = resourceService;
this.termFactoryService = termFactoryService;
this.strategoLibraries = strategoLibraries;
this.parseStrategoFileStrategy = parseStrategoFileStrategy;
this.projectService = projectService;
this.additionalClassLoaders = additionalClassLoaders;
}

Expand All @@ -78,7 +76,7 @@ public class StrategoRuntimeService implements IStrategoRuntimeService, AutoClos
prototype = createPrototype(component);
}

final HybridInterpreter runtime = clone(prototype, context.location(), component, context.project());
final HybridInterpreter runtime = clone(prototype, context.location(), component);
runtime.getContext().setContextObject(context);
runtime.getCompiledContext().setContextObject(context);
return runtime;
Expand All @@ -91,8 +89,7 @@ public class StrategoRuntimeService implements IStrategoRuntimeService, AutoClos
prototype = createPrototype(component);
}

final IProject project = projectService.get(location);
final HybridInterpreter runtime = clone(prototype, location, component, project);
final HybridInterpreter runtime = clone(prototype, location, component);
return runtime;
}

Expand Down Expand Up @@ -122,7 +119,7 @@ public class StrategoRuntimeService implements IStrategoRuntimeService, AutoClos


private HybridInterpreter clone(HybridInterpreter prototype, FileObject workingLocation,
ILanguageComponent component, @Nullable IProject project) {
ILanguageComponent component) {
// TODO: this seems to copy operator registries, but they should be recreated to isolate interpreters?
final HybridInterpreter runtime = new HybridInterpreter(prototype);

Expand All @@ -138,7 +135,7 @@ private HybridInterpreter clone(HybridInterpreter prototype, FileObject workingL
runtime.getCompiledContext().addOperatorRegistry(library);
}

final ITermFactory termFactory = termFactoryService.get(component, project);
final ITermFactory termFactory = termFactoryService.getGeneric();
runtime.getContext().setFactory(termFactory);
runtime.getCompiledContext().setFactory(termFactory);

Expand All @@ -165,7 +162,7 @@ private HybridInterpreter createNew(ITermFactory termFactory) {

private HybridInterpreter createPrototype(ILanguageComponent component) throws MetaborgException {
logger.debug("Creating prototype runtime for {}", component);
final ITermFactory termFactory = termFactoryService.get(component, null);
final ITermFactory termFactory = termFactoryService.getGeneric();
final HybridInterpreter runtime = createNew(termFactory);
loadFiles(runtime, component);
prototypes.put(component, runtime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private JSGLRI<?> getParser(ISpoofaxInputUnit input, JSGLRParserConfiguration pa

if(!parserMap.containsKey(langImpl) || overrideImploder != null || overrideJSGLRVersion != null) {
final IParserConfig config = getParserConfig(langImpl, input, parserConfig.completion, overrideJSGLRVersion, overrideImploder);
final ITermFactory termFactory = termFactoryService.get(langImpl, null);
final ITermFactory termFactory = termFactoryService.getGeneric();
final JSGLRVersion version = jsglrVersion(input, overrideJSGLRVersion);

final JSGLRI<?> parser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,9 @@
import org.spoofax.interpreter.terms.ITermFactory;

/**
* Interface for retrieving term factories for languages and generic use.
* Interface for retrieving term factories for generic use.
*/
public interface ITermFactoryService {
/**
* Return the term factory to be used when constructing new terms for given language implementation.
*
* @param impl
* Implementation to get the term factory for.
* @param project
* The current project.
* @return Language-specific term factory.
*/
ITermFactory get(ILanguageImpl impl, @Nullable IProject project);

/**
* Return the term factory to be used when constructing new terms for given language component.
*
* @param component
* Component to get the term factory for.
* @param project
* The current project.
* @return Language-specific term factory.
*/
ITermFactory get(ILanguageComponent component, @Nullable IProject project);

/**
* Returns the generic term factory.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ public class TermFactoryService implements ITermFactoryService {

private final ITermFactory genericFactory = new ImploderOriginTermFactory(new TermFactory());

@Override public ITermFactory get(ILanguageImpl impl, @Nullable IProject project) {
return genericFactory;
}

@Override public ITermFactory get(ILanguageComponent component, @Nullable IProject project) {
return genericFactory;
}

@Override public ITermFactory getGeneric() {
return genericFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class HoverService implements ISpoofaxHoverService {
final String strategy = facet.strategyName;

try {
final ITermFactory termFactory = termFactoryService.get(contributor, project);
final ITermFactory termFactory = termFactoryService.getGeneric();
final HybridInterpreter interpreter;
if(context == null) {
interpreter = strategoRuntimeService.runtime(contributor, source);
Expand Down Expand Up @@ -115,7 +115,7 @@ public class HoverService implements ISpoofaxHoverService {

try {
final IProject project = context.project();
final ITermFactory termFactory = termFactoryService.get(facetContrib.contributor, project);
final ITermFactory termFactory = termFactoryService.getGeneric();
final HybridInterpreter interpreter =
strategoRuntimeService.runtime(facetContrib.contributor, context);
final Iterable<IStrategoTerm> inRegion = tracingService.fragments(result, new SourceRegion(offset));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class ResolverService implements ISpoofaxResolverService {
final String strategy = facet.strategyName;

try {
final ITermFactory termFactory = termFactoryService.get(contributor, project);
final ITermFactory termFactory = termFactoryService.getGeneric();
final HybridInterpreter interpreter;
if(context == null) {
interpreter = strategoRuntimeService.runtime(contributor, source);
Expand Down Expand Up @@ -120,7 +120,7 @@ public class ResolverService implements ISpoofaxResolverService {
final String strategy = facet.strategyName;

try {
final ITermFactory termFactory = termFactoryService.get(facetContrib.contributor, project);
final ITermFactory termFactory = termFactoryService.getGeneric();
final HybridInterpreter interpreter =
strategoRuntimeService.runtime(facetContrib.contributor, context);
final Iterable<IStrategoTerm> inRegion = tracingService.fragments(result, new SourceRegion(offset));
Expand Down

0 comments on commit fa72589

Please sign in to comment.