Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
[eclipse/xtext-core#1909] solve circular proxy problems
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Dietrich <[email protected]>
  • Loading branch information
cdietrich committed Jun 7, 2022
1 parent 53caa7c commit 396500e
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.google.inject.Inject;
import com.google.inject.Provider;

/**
* @author Jan Koehnlein - Initial contribution and API
Expand Down Expand Up @@ -67,7 +68,7 @@ public boolean isAdapterForType(Object type) {

public static class Factory implements IElementIssueProvider.Factory {

@Inject IJvmModelAssociations associations;
@Inject Provider<IJvmModelAssociations> associations;

@Inject IResourceValidator resourceValidator;

Expand All @@ -84,7 +85,7 @@ public void attachData(Resource resource) {
if (uriToProblem != null && uriToProblem.trimFragment().equals(resource.getURI())) {
EObject erroneousElement = resource.getEObject(uriToProblem.fragment());
adapter.addIssue(erroneousElement, issue);
for(EObject jvmElement: associations.getJvmElements(erroneousElement)) {
for(EObject jvmElement: associations.get().getJvmElements(erroneousElement)) {
adapter.addIssue(jvmElement, issue);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices;

import com.google.inject.Inject;
import com.google.inject.Provider;

/**
* @author Sven Efftinge - Initial contribution and API
Expand All @@ -52,7 +53,7 @@ public class TypeReferenceSerializer {
private Primitives primitives;

@Inject
private ILogicalContainerProvider contextProvider;
private Provider<ILogicalContainerProvider> contextProvider;

@Inject
private ILocationInFileProvider locationProvider;
Expand All @@ -67,7 +68,7 @@ public boolean isLocalTypeParameter(EObject context, JvmTypeParameter parameter)
return false;
if (context instanceof JvmDeclaredType && ((JvmDeclaredType) context).isStatic())
return false;
JvmIdentifiableElement jvmElement = contextProvider.getNearestLogicalContainer(context);
JvmIdentifiableElement jvmElement = contextProvider.get().getNearestLogicalContainer(context);
if (jvmElement != null) {
return isLocalTypeParameter(jvmElement, parameter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public String toValue(String string, INode node) throws ValueConverterException
if(getWildcardLiteral().equals(segment)) {
buffer.append(getWildcardLiteral());
} else {
buffer.append((String) valueConverterService.toValue(segment, getDelegateRuleName(), null));
buffer.append((String) valueConverterService.get().toValue(segment, getDelegateRuleName(), null));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.eclipse.xtext.xtype.XtypePackage;

import com.google.inject.Inject;
import com.google.inject.Provider;

/**
* Language dependent configuration for the 'import' related things.
Expand All @@ -55,13 +56,13 @@
public class DefaultImportsConfiguration implements IImportsConfiguration {

@Inject
private IJvmModelAssociations associations;
private Provider<IJvmModelAssociations> associations;

@Inject
private IGrammarAccess grammarAccess;

@Inject
private ILogicalContainerProvider logicalContainerProvider;
private Provider<ILogicalContainerProvider> logicalContainerProvider;

@Override
public XImportSection getImportSection(XtextResource resource) {
Expand Down Expand Up @@ -103,12 +104,12 @@ public void accept(JvmDeclaredType t) {
@Override
public JvmDeclaredType getContextJvmDeclaredType(EObject model) {
if(model != null) {
JvmIdentifiableElement logicalContainer = logicalContainerProvider.getNearestLogicalContainer(model);
JvmIdentifiableElement logicalContainer = logicalContainerProvider.get().getNearestLogicalContainer(model);
if(logicalContainer != null)
return EcoreUtil2.getContainerOfType(logicalContainer, JvmDeclaredType.class);
EObject currentElement = model;
do {
for(EObject jvmElement: associations.getJvmElements(currentElement)) {
for(EObject jvmElement: associations.get().getJvmElements(currentElement)) {
if(jvmElement instanceof JvmDeclaredType)
return (JvmDeclaredType) jvmElement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import com.google.common.base.Strings;
import com.google.inject.Inject;
import com.google.inject.Provider;

/**
* Adds expected default values to a created JvmModel.
Expand Down Expand Up @@ -71,10 +72,10 @@ public class JvmModelCompleter {
private JvmTypeExtensions typeExtensions;

@Inject
private IJvmModelAssociations associations;
private Provider<IJvmModelAssociations> associations;

@Inject
private IJvmModelAssociator associator;
private Provider<IJvmModelAssociator> associator;

@Inject
private JvmAnnotationReferenceBuilder.Factory annotationRefBuilderFactory;
Expand All @@ -87,7 +88,7 @@ public class JvmModelCompleter {

/** The generator is used to fill information of the <code>@Generated</code> annotation. */
@Inject
private JvmModelGenerator generator;
private Provider<JvmModelGenerator> generator;

private DateFormat dateFormat;

Expand Down Expand Up @@ -127,15 +128,15 @@ protected void completeJvmEnumerationType(JvmEnumerationType element) {
element.getSuperTypes().add(objectType);
}
addAnnotations(element);
EObject primarySourceElement = associations.getPrimarySourceElement(element);
EObject primarySourceElement = associations.get().getPrimarySourceElement(element);
JvmOperation values = typesFactory.createJvmOperation();
values.setVisibility(JvmVisibility.PUBLIC);
values.setStatic(true);
values.setSimpleName("values");
values.setReturnType(references.createArrayType(references.createTypeRef(element)));
typeExtensions.setSynthetic(values, true);
if (primarySourceElement != null) {
associator.associate(primarySourceElement, values);
associator.get().associate(primarySourceElement, values);
}
element.getMembers().add(values);

Expand All @@ -150,7 +151,7 @@ protected void completeJvmEnumerationType(JvmEnumerationType element) {
valueOf.getParameters().add(param);
typeExtensions.setSynthetic(valueOf, true);
if (primarySourceElement != null) {
associator.associate(primarySourceElement, valueOf);
associator.get().associate(primarySourceElement, valueOf);
}
element.getMembers().add(valueOf);
}
Expand Down Expand Up @@ -194,9 +195,9 @@ protected void completeJvmGenericType(JvmGenericType element) {
constructor.setSimpleName(element.getSimpleName());
constructor.setVisibility(JvmVisibility.PUBLIC);
typeExtensions.setSynthetic(constructor, true);
EObject primarySourceElement = associations.getPrimarySourceElement(element);
EObject primarySourceElement = associations.get().getPrimarySourceElement(element);
if (primarySourceElement != null) {
associator.associate(primarySourceElement, constructor);
associator.get().associate(primarySourceElement, constructor);
}
element.getMembers().add(constructor);
}
Expand Down Expand Up @@ -234,7 +235,7 @@ protected void addAnnotations(JvmDeclaredType jvmType) {
JvmAnnotationType generatedAnnotationType = (JvmAnnotationType) generatedJvmType;
JvmAnnotationReference annotationRef = annotationRefBuilder.annotationRef(JAVAX_ANNOTATION_GENERATED);
JvmStringAnnotationValue annotationValue = typesFactory.createJvmStringAnnotationValue();
annotationValue.getValues().add(generator.getClass().getName());
annotationValue.getValues().add(generator.get().getClass().getName());
annotationRef.getExplicitValues().add(annotationValue);
if (generatorConfig.isIncludeDateInGeneratedAnnotation()) {
if (dateFormat == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.google.common.collect.Iterables;
import com.google.inject.Inject;
import com.google.inject.Provider;

/**
* @noextend This class is not intended to be subclassed by clients.
Expand All @@ -31,7 +32,7 @@
*/
public class JvmTypeExtensions {
@Inject
private ILogicalContainerProvider logicalContainerProvider;
private Provider<ILogicalContainerProvider> logicalContainerProvider;

public Procedure1<? super ITreeAppendable> getCompilationStrategy(JvmIdentifiableElement it) {
CompilationStrategyAdapter adapter = Iterables
Expand All @@ -52,7 +53,7 @@ public StringConcatenationClient getCompilationTemplate(JvmIdentifiableElement i
}

public boolean isSingleSyntheticDefaultConstructor(JvmConstructor it) {
return it.getParameters().isEmpty() && logicalContainerProvider.getAssociatedExpression(it) == null
return it.getParameters().isEmpty() && logicalContainerProvider.get().getAssociatedExpression(it) == null
&& getCompilationStrategy(it) == null && getCompilationTemplate(it) == null && IterableExtensions
.size(Iterables.filter(it.getDeclaringType().getMembers(), JvmConstructor.class)) == 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class XImportSectionNamespaceScopeProvider extends AbstractGlobalScopeDel
public static final QualifiedName JAVA_LANG = QualifiedName.create("java","lang");
public static final QualifiedName XBASE_LIB = QualifiedName.create("org","eclipse","xtext","xbase","lib");

@Inject private IJvmModelAssociations associations;
@Inject private Provider<IJvmModelAssociations> associations;
@Inject private IResourceScopeCache cache;
@Inject private IQualifiedNameProvider qualifiedNameProvider;
@Inject private IQualifiedNameConverter qualifiedNameConverter;
Expand Down Expand Up @@ -125,7 +125,7 @@ protected IScope getLocalElementsScope(IScope parent, IScope globalScope, EObjec
}

// scope for jvm elements
Set<EObject> elements = associations.getJvmElements(context);
Set<EObject> elements = associations.get().getJvmElements(context);
for (EObject derivedJvmElement : elements) {
// scope for JvmDeclaredTypes
if (derivedJvmElement instanceof JvmDeclaredType) {
Expand Down Expand Up @@ -293,6 +293,6 @@ public String getWildcard() {
}

protected IJvmModelAssociations getAssociations() {
return associations;
return associations.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.xtext.xbase.typesystem.util.IVisibilityHelper;

import com.google.inject.Inject;
import com.google.inject.Provider;

/**
* The root session. It is save to be used by various child sessions
Expand All @@ -43,7 +44,7 @@ public class RootFeatureScopeSession extends AbstractFeatureScopeSession {
private TypeScopes typeScopes;

@Inject
private IScopeProvider scopeProvider;
private Provider<IScopeProvider> scopeProviderProvider;

@Inject
private IVisibilityHelper visibilityHelper;
Expand All @@ -70,7 +71,7 @@ protected ConstructorScopes getConstructorScopes() {

@Override
protected IScopeProvider getDefaultScopeProvider() {
return scopeProvider;
return scopeProviderProvider.get();
}

/* @Nullable */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.xtext.xtype.XImportSection;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.name.Named;

/**
Expand All @@ -53,6 +54,8 @@ public class XbaseBatchScopeProvider implements IBatchScopeProvider, IDelegating

@Inject
@Named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)
private Provider<IScopeProvider> delegateProvider;

private IScopeProvider delegate;

@Inject
Expand All @@ -71,6 +74,9 @@ public void setDelegate(IScopeProvider delegate) {

@Override
public IScopeProvider getDelegate() {
if (delegate == null) {
delegate = delegateProvider.get();
}
return delegate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices;

import com.google.inject.Inject;
import com.google.inject.Provider;

/**
* @author Sebastian Zarnekow - Initial contribution and API
Expand All @@ -35,7 +36,7 @@ public abstract class AbstractBatchTypeResolver implements IBatchTypeResolver {
private static Logger LOG = Logger.getLogger(AbstractBatchTypeResolver.class);

@Inject
private IBatchScopeProvider scopeProvider;
private Provider<IBatchScopeProvider> scopeProvider;
@Inject
private FeatureScopes featureScopes;
@Inject
Expand Down Expand Up @@ -85,7 +86,7 @@ public IResolvedTypes resolveTypes(/* @NonNull */ Resource resource, /* @Nullabl
validateResourceState(resource);
List<EObject> resourceContents = resource.getContents();
if (resourceContents.isEmpty()) {
IFeatureScopeSession session = scopeProvider.newSession(resource);
IFeatureScopeSession session = scopeProvider.get().newSession(resource);
return new EmptyResolvedTypes(session, featureScopes, new StandardTypeReferenceOwner(services, resource));
} else {
return resolveTypes(resourceContents.get(0), monitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.xtext.xtype.XtypeFactory;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;

/**
Expand Down Expand Up @@ -60,6 +61,8 @@ public class CommonTypeComputationServices {
private SynonymTypesProvider synonymTypesProvider;

@Inject
private Provider<IJvmModelAssociations> jvmModelAssociationsProvider;

private IJvmModelAssociations jvmModelAssociations;

@Inject
Expand Down Expand Up @@ -155,6 +158,9 @@ public void setSynonymTypesProvider(SynonymTypesProvider synonymTypesProvider) {
}

public IJvmModelAssociations getJvmModelAssociations() {
if (jvmModelAssociations == null) {
jvmModelAssociations = jvmModelAssociationsProvider.get();
}
return jvmModelAssociations;
}

Expand Down

0 comments on commit 396500e

Please sign in to comment.