From 396500e2a3463e9b1a7b12cb117dc6862095f0c6 Mon Sep 17 00:00:00 2001 From: Christian Dietrich Date: Tue, 7 Jun 2022 09:30:43 +0200 Subject: [PATCH] [eclipse/xtext-core#1909] solve circular proxy problems Signed-off-by: Christian Dietrich --- .../xbase/compiler/ElementIssueProvider.java | 5 +++-- .../compiler/TypeReferenceSerializer.java | 5 +++-- .../XbaseQualifiedNameValueConverter.java | 2 +- .../imports/DefaultImportsConfiguration.java | 9 +++++---- .../xbase/jvmmodel/JvmModelCompleter.java | 19 ++++++++++--------- .../xbase/jvmmodel/JvmTypeExtensions.java | 5 +++-- .../XImportSectionNamespaceScopeProvider.java | 6 +++--- .../batch/RootFeatureScopeSession.java | 5 +++-- .../batch/XbaseBatchScopeProvider.java | 6 ++++++ .../internal/AbstractBatchTypeResolver.java | 5 +++-- .../util/CommonTypeComputationServices.java | 6 ++++++ 11 files changed, 46 insertions(+), 27 deletions(-) diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/compiler/ElementIssueProvider.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/compiler/ElementIssueProvider.java index e4d1283f89..0b48a33d42 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/compiler/ElementIssueProvider.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/compiler/ElementIssueProvider.java @@ -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 @@ -67,7 +68,7 @@ public boolean isAdapterForType(Object type) { public static class Factory implements IElementIssueProvider.Factory { - @Inject IJvmModelAssociations associations; + @Inject Provider associations; @Inject IResourceValidator resourceValidator; @@ -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); } } diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/compiler/TypeReferenceSerializer.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/compiler/TypeReferenceSerializer.java index f93fcc768a..b5847b87b2 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/compiler/TypeReferenceSerializer.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/compiler/TypeReferenceSerializer.java @@ -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 @@ -52,7 +53,7 @@ public class TypeReferenceSerializer { private Primitives primitives; @Inject - private ILogicalContainerProvider contextProvider; + private Provider contextProvider; @Inject private ILocationInFileProvider locationProvider; @@ -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); } diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/conversion/XbaseQualifiedNameValueConverter.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/conversion/XbaseQualifiedNameValueConverter.java index b0dd453114..8b56b3c557 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/conversion/XbaseQualifiedNameValueConverter.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/conversion/XbaseQualifiedNameValueConverter.java @@ -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)); } } } diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/imports/DefaultImportsConfiguration.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/imports/DefaultImportsConfiguration.java index cf3b28a860..22cfddc3a8 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/imports/DefaultImportsConfiguration.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/imports/DefaultImportsConfiguration.java @@ -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. @@ -55,13 +56,13 @@ public class DefaultImportsConfiguration implements IImportsConfiguration { @Inject - private IJvmModelAssociations associations; + private Provider associations; @Inject private IGrammarAccess grammarAccess; @Inject - private ILogicalContainerProvider logicalContainerProvider; + private Provider logicalContainerProvider; @Override public XImportSection getImportSection(XtextResource resource) { @@ -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; } diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/jvmmodel/JvmModelCompleter.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/jvmmodel/JvmModelCompleter.java index b9c9776f72..a8730d6b8c 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/jvmmodel/JvmModelCompleter.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/jvmmodel/JvmModelCompleter.java @@ -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. @@ -71,10 +72,10 @@ public class JvmModelCompleter { private JvmTypeExtensions typeExtensions; @Inject - private IJvmModelAssociations associations; + private Provider associations; @Inject - private IJvmModelAssociator associator; + private Provider associator; @Inject private JvmAnnotationReferenceBuilder.Factory annotationRefBuilderFactory; @@ -87,7 +88,7 @@ public class JvmModelCompleter { /** The generator is used to fill information of the @Generated annotation. */ @Inject - private JvmModelGenerator generator; + private Provider generator; private DateFormat dateFormat; @@ -127,7 +128,7 @@ 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); @@ -135,7 +136,7 @@ protected void completeJvmEnumerationType(JvmEnumerationType element) { 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); @@ -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); } @@ -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); } @@ -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) { diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/jvmmodel/JvmTypeExtensions.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/jvmmodel/JvmTypeExtensions.java index 8816cd172c..e856d32555 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/jvmmodel/JvmTypeExtensions.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/jvmmodel/JvmTypeExtensions.java @@ -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. @@ -31,7 +32,7 @@ */ public class JvmTypeExtensions { @Inject - private ILogicalContainerProvider logicalContainerProvider; + private Provider logicalContainerProvider; public Procedure1 getCompilationStrategy(JvmIdentifiableElement it) { CompilationStrategyAdapter adapter = Iterables @@ -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; } diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/scoping/XImportSectionNamespaceScopeProvider.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/scoping/XImportSectionNamespaceScopeProvider.java index 2428c1e4cd..5d5d5e290f 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/scoping/XImportSectionNamespaceScopeProvider.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/scoping/XImportSectionNamespaceScopeProvider.java @@ -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 associations; @Inject private IResourceScopeCache cache; @Inject private IQualifiedNameProvider qualifiedNameProvider; @Inject private IQualifiedNameConverter qualifiedNameConverter; @@ -125,7 +125,7 @@ protected IScope getLocalElementsScope(IScope parent, IScope globalScope, EObjec } // scope for jvm elements - Set elements = associations.getJvmElements(context); + Set elements = associations.get().getJvmElements(context); for (EObject derivedJvmElement : elements) { // scope for JvmDeclaredTypes if (derivedJvmElement instanceof JvmDeclaredType) { @@ -293,6 +293,6 @@ public String getWildcard() { } protected IJvmModelAssociations getAssociations() { - return associations; + return associations.get(); } } diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/scoping/batch/RootFeatureScopeSession.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/scoping/batch/RootFeatureScopeSession.java index 30c0a73b2a..c5a7f9547c 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/scoping/batch/RootFeatureScopeSession.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/scoping/batch/RootFeatureScopeSession.java @@ -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 @@ -43,7 +44,7 @@ public class RootFeatureScopeSession extends AbstractFeatureScopeSession { private TypeScopes typeScopes; @Inject - private IScopeProvider scopeProvider; + private Provider scopeProviderProvider; @Inject private IVisibilityHelper visibilityHelper; @@ -70,7 +71,7 @@ protected ConstructorScopes getConstructorScopes() { @Override protected IScopeProvider getDefaultScopeProvider() { - return scopeProvider; + return scopeProviderProvider.get(); } /* @Nullable */ diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/scoping/batch/XbaseBatchScopeProvider.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/scoping/batch/XbaseBatchScopeProvider.java index c6531ddb11..c9cec01307 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/scoping/batch/XbaseBatchScopeProvider.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/scoping/batch/XbaseBatchScopeProvider.java @@ -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; /** @@ -53,6 +54,8 @@ public class XbaseBatchScopeProvider implements IBatchScopeProvider, IDelegating @Inject @Named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE) + private Provider delegateProvider; + private IScopeProvider delegate; @Inject @@ -71,6 +74,9 @@ public void setDelegate(IScopeProvider delegate) { @Override public IScopeProvider getDelegate() { + if (delegate == null) { + delegate = delegateProvider.get(); + } return delegate; } diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/internal/AbstractBatchTypeResolver.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/internal/AbstractBatchTypeResolver.java index ed010a8d2b..3d1ce510db 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/internal/AbstractBatchTypeResolver.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/internal/AbstractBatchTypeResolver.java @@ -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 @@ -35,7 +36,7 @@ public abstract class AbstractBatchTypeResolver implements IBatchTypeResolver { private static Logger LOG = Logger.getLogger(AbstractBatchTypeResolver.class); @Inject - private IBatchScopeProvider scopeProvider; + private Provider scopeProvider; @Inject private FeatureScopes featureScopes; @Inject @@ -85,7 +86,7 @@ public IResolvedTypes resolveTypes(/* @NonNull */ Resource resource, /* @Nullabl validateResourceState(resource); List 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); diff --git a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/util/CommonTypeComputationServices.java b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/util/CommonTypeComputationServices.java index 55834f682b..348a6e2d3f 100644 --- a/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/util/CommonTypeComputationServices.java +++ b/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/util/CommonTypeComputationServices.java @@ -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; /** @@ -60,6 +61,8 @@ public class CommonTypeComputationServices { private SynonymTypesProvider synonymTypesProvider; @Inject + private Provider jvmModelAssociationsProvider; + private IJvmModelAssociations jvmModelAssociations; @Inject @@ -155,6 +158,9 @@ public void setSynonymTypesProvider(SynonymTypesProvider synonymTypesProvider) { } public IJvmModelAssociations getJvmModelAssociations() { + if (jvmModelAssociations == null) { + jvmModelAssociations = jvmModelAssociationsProvider.get(); + } return jvmModelAssociations; }