Skip to content

Commit

Permalink
Inject TermFactory instance directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Apanatshka committed May 18, 2020
1 parent fa72589 commit 24858a8
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.metaborg.spoofax.core.style.ISpoofaxCategorizerService;
import org.metaborg.spoofax.core.style.ISpoofaxStylerService;
import org.metaborg.spoofax.core.syntax.ISpoofaxSyntaxService;
import org.metaborg.spoofax.core.terms.ITermFactoryService;
import org.metaborg.spoofax.core.tracing.ISpoofaxHoverService;
import org.metaborg.spoofax.core.tracing.ISpoofaxResolverService;
import org.metaborg.spoofax.core.tracing.ISpoofaxTracingService;
Expand All @@ -27,6 +26,7 @@
import org.metaborg.spoofax.core.unit.ISpoofaxTransformUnit;
import org.metaborg.spoofax.core.unit.ISpoofaxUnitService;
import org.spoofax.interpreter.terms.IStrategoTerm;
import org.spoofax.interpreter.terms.ITermFactory;

import com.google.inject.Module;
import com.google.inject.util.Types;
Expand Down Expand Up @@ -58,7 +58,7 @@ public class Spoofax extends
public final ISpoofaxOutlineService outlineService;
public final ISpoofaxCompletionService completionService;

public final ITermFactoryService termFactoryService;
public final ITermFactory termFactory;
public final IStrategoRuntimeService strategoRuntimeService;
public final IStrategoCommon strategoCommon;

Expand Down Expand Up @@ -106,7 +106,7 @@ public Spoofax(IModulePluginLoader loader, SpoofaxModule module, Module... addit
this.outlineService = injector.getInstance(ISpoofaxOutlineService.class);
this.completionService = injector.getInstance(ISpoofaxCompletionService.class);

this.termFactoryService = injector.getInstance(ITermFactoryService.class);
this.termFactory = injector.getInstance(ITermFactory.class);
this.strategoRuntimeService = injector.getInstance(IStrategoRuntimeService.class);
this.strategoCommon = injector.getInstance(IStrategoCommon.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@
import org.metaborg.spoofax.core.syntax.JSGLRParseService;
import org.metaborg.spoofax.core.syntax.JSGLRParserConfiguration;
import org.metaborg.spoofax.core.syntax.SpoofaxSyntaxService;
import org.metaborg.spoofax.core.terms.ITermFactoryService;
import org.metaborg.spoofax.core.terms.TermFactoryService;
import org.metaborg.spoofax.core.tracing.HoverService;
import org.metaborg.spoofax.core.tracing.ISpoofaxHoverService;
import org.metaborg.spoofax.core.tracing.ISpoofaxResolverService;
Expand All @@ -148,6 +146,9 @@
import org.spoofax.interpreter.library.IOperatorRegistry;
import org.spoofax.interpreter.library.index.primitives.legacy.LegacyIndexLibrary;
import org.spoofax.interpreter.terms.IStrategoTerm;
import org.spoofax.interpreter.terms.ITermFactory;
import org.spoofax.jsglr.client.imploder.ImploderOriginTermFactory;
import org.spoofax.terms.TermFactory;

import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
Expand Down Expand Up @@ -322,8 +323,7 @@ protected void bindSyntax() {
bind(new TypeLiteral<ISyntaxService<?, ?>>() {}).to(SpoofaxSyntaxService.class);
bind(ISyntaxService.class).to(SpoofaxSyntaxService.class);

bind(TermFactoryService.class).in(Singleton.class);
bind(ITermFactoryService.class).to(TermFactoryService.class);
bind(ITermFactory.class).toInstance(new ImploderOriginTermFactory(new TermFactory()));
}

protected void bindParsers(MapBinder<String, IParser<ISpoofaxInputUnit, ISpoofaxParseUnit>> parserBinder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.metaborg.spoofax.core.context.constraint.IConstraintContext;
import org.metaborg.spoofax.core.stratego.IStrategoCommon;
import org.metaborg.spoofax.core.stratego.IStrategoRuntimeService;
import org.metaborg.spoofax.core.terms.ITermFactoryService;
import org.metaborg.spoofax.core.tracing.ISpoofaxTracingService;
import org.metaborg.spoofax.core.unit.AnalyzeContrib;
import org.metaborg.spoofax.core.unit.AnalyzeUpdateData;
Expand Down Expand Up @@ -74,15 +73,15 @@ public abstract class AbstractConstraintAnalyzer implements ISpoofaxAnalyzer {

public AbstractConstraintAnalyzer(final AnalysisCommon analysisCommon, final IResourceService resourceService,
final IStrategoRuntimeService runtimeService, final IStrategoCommon strategoCommon,
final ITermFactoryService termFactoryService, final ISpoofaxTracingService tracingService,
final ITermFactory termFactory, final ISpoofaxTracingService tracingService,
final ISpoofaxUnitService unitService) {
this.analysisCommon = analysisCommon;
this.resourceService = resourceService;
this.runtimeService = runtimeService;
this.strategoCommon = strategoCommon;
this.tracingService = tracingService;
this.unitService = unitService;
this.termFactory = termFactoryService.getGeneric();
this.termFactory = termFactory;
}

protected abstract boolean multifile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import org.metaborg.spoofax.core.analysis.AnalysisCommon;
import org.metaborg.spoofax.core.stratego.IStrategoCommon;
import org.metaborg.spoofax.core.stratego.IStrategoRuntimeService;
import org.metaborg.spoofax.core.terms.ITermFactoryService;
import org.metaborg.spoofax.core.tracing.ISpoofaxTracingService;
import org.metaborg.spoofax.core.unit.ISpoofaxUnitService;
import org.spoofax.interpreter.terms.ITermFactory;

import com.google.inject.Inject;

Expand All @@ -16,9 +16,9 @@ public class MultiFileConstraintAnalyzer extends AbstractConstraintAnalyzer {

@Inject public MultiFileConstraintAnalyzer(AnalysisCommon analysisCommon, IResourceService resourceService,
IStrategoRuntimeService runtimeService, IStrategoCommon strategoCommon,
ITermFactoryService termFactoryService, ISpoofaxTracingService tracingService,
ITermFactory termFactory, ISpoofaxTracingService tracingService,
ISpoofaxUnitService unitService) {
super(analysisCommon, resourceService, runtimeService, strategoCommon, termFactoryService, tracingService,
super(analysisCommon, resourceService, runtimeService, strategoCommon, termFactory, tracingService,
unitService);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import org.metaborg.spoofax.core.analysis.AnalysisCommon;
import org.metaborg.spoofax.core.stratego.IStrategoCommon;
import org.metaborg.spoofax.core.stratego.IStrategoRuntimeService;
import org.metaborg.spoofax.core.terms.ITermFactoryService;
import org.metaborg.spoofax.core.tracing.ISpoofaxTracingService;
import org.metaborg.spoofax.core.unit.ISpoofaxUnitService;
import org.spoofax.interpreter.terms.ITermFactory;

import com.google.inject.Inject;

Expand All @@ -16,9 +16,9 @@ public class SingleFileConstraintAnalyzer extends AbstractConstraintAnalyzer {

@Inject public SingleFileConstraintAnalyzer(AnalysisCommon analysisCommon, IResourceService resourceService,
IStrategoRuntimeService runtimeService, IStrategoCommon strategoCommon,
ITermFactoryService termFactoryService, ISpoofaxTracingService tracingService,
ITermFactory termFactory, ISpoofaxTracingService tracingService,
ISpoofaxUnitService unitService) {
super(analysisCommon, resourceService, runtimeService, strategoCommon, termFactoryService, tracingService,
super(analysisCommon, resourceService, runtimeService, strategoCommon, termFactory, tracingService,
unitService);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.metaborg.spoofax.core.analysis.SpoofaxAnalyzeResults;
import org.metaborg.spoofax.core.stratego.IStrategoCommon;
import org.metaborg.spoofax.core.stratego.IStrategoRuntimeService;
import org.metaborg.spoofax.core.terms.ITermFactoryService;
import org.metaborg.spoofax.core.unit.AnalyzeContrib;
import org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnit;
import org.metaborg.spoofax.core.unit.ISpoofaxParseUnit;
Expand Down Expand Up @@ -51,18 +50,18 @@ public class StrategoAnalyzer implements ISpoofaxAnalyzer {
private static final ILogger logger = LoggerUtils.logger(StrategoAnalyzer.class);

private final ISpoofaxUnitService unitService;
private final ITermFactoryService termFactoryService;
private final ITermFactory termFactory;
private final IStrategoRuntimeService runtimeService;

private final IStrategoCommon strategoCommon;
private final AnalysisCommon analysisCommon;


@Inject public StrategoAnalyzer(ISpoofaxUnitService unitService, ITermFactoryService termFactoryService,
@Inject public StrategoAnalyzer(ISpoofaxUnitService unitService, ITermFactory termFactory,
IStrategoRuntimeService runtimeService, IStrategoCommon strategoCommon,
AnalysisCommon analysisCommon) {
this.unitService = unitService;
this.termFactoryService = termFactoryService;
this.termFactory = termFactory;
this.runtimeService = runtimeService;
this.strategoCommon = strategoCommon;
this.analysisCommon = analysisCommon;
Expand All @@ -79,7 +78,6 @@ public class StrategoAnalyzer implements ISpoofaxAnalyzer {
}

final ILanguageImpl language = context.language();
final ITermFactory termFactory = termFactoryService.getGeneric();

final FacetContribution<AnalysisFacet> facetContribution = language.facetContribution(AnalysisFacet.class);
if(facetContribution == null) {
Expand Down Expand Up @@ -107,7 +105,6 @@ public class StrategoAnalyzer implements ISpoofaxAnalyzer {
cancel.throwIfCancelled();

final ILanguageImpl language = context.language();
final ITermFactory termFactory = termFactoryService.getGeneric();

final FacetContribution<AnalysisFacet> facetContribution = language.facetContribution(AnalysisFacet.class);
if(facetContribution == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.metaborg.spoofax.core.analysis.SpoofaxAnalyzeResults;
import org.metaborg.spoofax.core.stratego.IStrategoCommon;
import org.metaborg.spoofax.core.stratego.IStrategoRuntimeService;
import org.metaborg.spoofax.core.terms.ITermFactoryService;
import org.metaborg.spoofax.core.unit.AnalyzeContrib;
import org.metaborg.spoofax.core.unit.AnalyzeUpdateData;
import org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnit;
Expand Down Expand Up @@ -59,7 +58,7 @@ public class TaskEngineAnalyzer implements ISpoofaxAnalyzer {

private final IResourceService resourceService;
private final ISpoofaxUnitService unitService;
private final ITermFactoryService termFactoryService;
private final ITermFactory termFactory;
private final IStrategoRuntimeService runtimeService;

private final IStrategoCommon strategoCommon;
Expand All @@ -68,16 +67,16 @@ public class TaskEngineAnalyzer implements ISpoofaxAnalyzer {


@Inject public TaskEngineAnalyzer(IResourceService resourceService, ISpoofaxUnitService unitService,
ITermFactoryService termFactoryService, IStrategoRuntimeService runtimeService, IStrategoCommon strategoCommon,
ITermFactory termFactory, IStrategoRuntimeService runtimeService, IStrategoCommon strategoCommon,
AnalysisCommon analysisCommon) {
this.resourceService = resourceService;
this.unitService = unitService;
this.termFactoryService = termFactoryService;
this.termFactory = termFactory;
this.runtimeService = runtimeService;
this.strategoCommon = strategoCommon;
this.analysisCommon = analysisCommon;

this.fileCons = termFactoryService.getGeneric().makeConstructor("File", 3);
this.fileCons = termFactory.makeConstructor("File", 3);
}


Expand All @@ -98,7 +97,6 @@ public class TaskEngineAnalyzer implements ISpoofaxAnalyzer {
cancel.throwIfCancelled();

final ILanguageImpl langImpl = context.language();
final ITermFactory termFactory = termFactoryService.getGeneric();

final FacetContribution<AnalysisFacet> facetContribution = langImpl.facetContribution(AnalysisFacet.class);
if(facetContribution == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.metaborg.spoofax.core.syntax.JSGLRSourceRegionFactory;
import org.metaborg.spoofax.core.syntax.SourceAttachment;
import org.metaborg.spoofax.core.syntax.SyntaxFacet;
import org.metaborg.spoofax.core.terms.ITermFactoryService;
import org.metaborg.spoofax.core.unit.ISpoofaxInputUnit;
import org.metaborg.spoofax.core.unit.ISpoofaxParseUnit;
import org.metaborg.spoofax.core.unit.ISpoofaxUnitService;
Expand Down Expand Up @@ -62,7 +61,7 @@
public class JSGLRCompletionService implements ISpoofaxCompletionService {
private static final Logger logger = LoggerFactory.getLogger(JSGLRCompletionService.class);

private final ITermFactoryService termFactoryService;
private final ITermFactory termFactory;
private final IStrategoRuntimeService strategoRuntimeService;
private final IStrategoCommon strategoCommon;
private final IResourceService resourceService;
Expand All @@ -71,10 +70,10 @@ public class JSGLRCompletionService implements ISpoofaxCompletionService {



@Inject public JSGLRCompletionService(ITermFactoryService termFactoryService,
@Inject public JSGLRCompletionService(ITermFactory termFactory,
IStrategoRuntimeService strategoRuntimeService, IStrategoCommon strategoCommon,
IResourceService resourceService, ISpoofaxUnitService unitService, ISpoofaxSyntaxService syntaxService) {
this.termFactoryService = termFactoryService;
this.termFactory = termFactory;
this.strategoRuntimeService = strategoRuntimeService;
this.strategoCommon = strategoCommon;
this.resourceService = resourceService;
Expand Down Expand Up @@ -140,7 +139,6 @@ 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
Expand Down Expand Up @@ -219,7 +217,6 @@ 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);
Expand Down Expand Up @@ -266,7 +263,6 @@ 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.getGeneric();

for(IStrategoTerm term : leftRecursive) {
IStrategoTerm sort = termFactory.makeString(ImploderAttachment.getSort(term));
Expand Down Expand Up @@ -375,7 +371,6 @@ 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.getGeneric();

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

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

final ITermFactory termFactory = termFactoryService.getGeneric();

for(IStrategoTerm optional : optionals) {

ImploderAttachment attachment = optional.getAttachment(ImploderAttachment.TYPE);
Expand Down Expand Up @@ -507,8 +500,6 @@ public Collection<ICompletion> listsCompletions(int position, boolean blankLineC

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

final ITermFactory termFactory = termFactoryService.getGeneric();

for(IStrategoList list : lists) {
ListImploderAttachment attachment = list.getAttachment(null);
String sort = attachment.getSort().substring(0, attachment.getSort().length() - 1);
Expand Down Expand Up @@ -798,7 +789,6 @@ 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()) {
for(IStrategoTerm completionTerm : completionTerms) {
Expand Down Expand Up @@ -1166,7 +1156,6 @@ 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()) {
for(IStrategoTerm nestedCompletionTerm : nestedCompletionTerms) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.metaborg.core.project.IProject;
import org.metaborg.runtime.task.engine.ITaskEngine;
import org.metaborg.runtime.task.engine.TaskManager;
import org.metaborg.spoofax.core.terms.ITermFactoryService;
import org.metaborg.util.concurrent.ClosableLock;
import org.metaborg.util.concurrent.IClosableLock;
import org.metaborg.util.file.FileUtils;
Expand All @@ -44,10 +43,10 @@ public class IndexTaskContext implements IContext, IContextInternal, IIndexTaskC
private ITaskEngine taskEngine;


public IndexTaskContext(Injector injector, ITermFactoryService termFactoryService, ContextIdentifier identifier) {
public IndexTaskContext(Injector injector, ITermFactory termFactory, ContextIdentifier identifier) {
this.injector = injector;

this.termFactory = termFactoryService.getGeneric();
this.termFactory = termFactory;
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 @@ -2,7 +2,7 @@

import org.metaborg.core.context.ContextIdentifier;
import org.metaborg.core.context.IContextFactory;
import org.metaborg.spoofax.core.terms.ITermFactoryService;
import org.spoofax.interpreter.terms.ITermFactory;

import com.google.inject.Inject;
import com.google.inject.Injector;
Expand All @@ -11,17 +11,17 @@ public class IndexTaskContextFactory implements IContextFactory {
public static final String name = "index-task";

private final Injector injector;
private final ITermFactoryService termFactoryService;
private final ITermFactory termFactory;


@Inject public IndexTaskContextFactory(Injector injector, ITermFactoryService termFactoryService) {
@Inject public IndexTaskContextFactory(Injector injector, ITermFactory termFactory) {
this.injector = injector;
this.termFactoryService = termFactoryService;
this.termFactory = termFactory;
}


@Override public IndexTaskContext create(ContextIdentifier identifier) {
return new IndexTaskContext(injector, termFactoryService, identifier);
return new IndexTaskContext(injector, termFactory, identifier);
}

@Override public IndexTaskTemporaryContext createTemporary(ContextIdentifier identifier) {
Expand Down
Loading

0 comments on commit 24858a8

Please sign in to comment.