/** * This method serves as an entry point for the content assist scoping for simple feature calls. * @param context the context e.g. a for loop expression, a block or a catch clause */ public IScope createSimpleFeatureCallScope(EObject context, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { IScope root = IScope.NULLSCOPE; if (context instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) context; if (!featureCall.isExplicitOperationCallOrBuilderSyntax()) { root = createTypeLiteralScope(context, QualifiedName.EMPTY, root, session, resolvedTypes); if (isDefiniteTypeLiteral(featureCall)) { return root; } } } IScope staticImports = createStaticFeaturesScope(context, root, session); IScope staticMembers = createStaticScope(asAbstractFeatureCall(context), null, null, staticImports, session, resolvedTypes); IScope staticExtensions = createStaticExtensionsScope(null, null, context, staticMembers, session, resolvedTypes); // we don't want to use captured instances of 'IT' as dynamic extension implicit argument // thus the dynamic extension scope only works for the *real* local variables IScope dynamicExtensions = createDynamicExtensionsScope(null, null, context, staticExtensions, session, resolvedTypes); IScope localVariables = createImplicitFeatureCallAndLocalVariableScope(context, dynamicExtensions, session, resolvedTypes); return localVariables; }
protected IScope createDynamicExtensionsScope(QualifiedName implicitFirstArgumentName, EObject featureCall, IFeatureScopeSession captureLayer, IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent, boolean all) { if (all) { List<IEObjectDescription> firstArguments = getDeepLocalElements(session, implicitFirstArgumentName); switch(firstArguments.size()) { case 0: return createDynamicExtensionsScope(featureCall, null, null, true, parent, captureLayer); case 1: return createDynamicExtensionsScope(implicitFirstArgumentName, firstArguments.get(0), featureCall, captureLayer, session, resolvedTypes, parent); default: CompositeScope result = createCompositeScope(featureCall, parent, session); for(IEObjectDescription firstArgumentDescription: firstArguments) { IScope extensionsScope = createDynamicExtensionsScope(implicitFirstArgumentName, firstArgumentDescription, featureCall, captureLayer, session, resolvedTypes, IScope.NULLSCOPE); if (IScope.NULLSCOPE != extensionsScope) { IEObjectDescription firstArgumentDescription = getDeepLocalElement(session, implicitFirstArgumentName); if (firstArgumentDescription != null) { return createDynamicExtensionsScope(implicitFirstArgumentName, firstArgumentDescription, featureCall, captureLayer, session, resolvedTypes, parent); } else { return createDynamicExtensionsScope(featureCall, null, null, true, parent, captureLayer);
protected IScope createImplicitFeatureCallAndLocalVariableScope(EObject context, IScope parent, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { IFeatureScopeSession nextCaptureLayer = session.getNextCaptureLayer(); if (nextCaptureLayer != null) { parent = createImplicitFeatureCallAndLocalVariableScope(context, parent, nextCaptureLayer, resolvedTypes); } IScope implicitReceivers = createImplicitFeatureCallScope(context, parent, session, resolvedTypes); IScope constructors = createConstructorDelegates(context, implicitReceivers, session, resolvedTypes); IScope localVariables = createLocalVariableScope(context, constructors, session, resolvedTypes); return localVariables; }
protected IScope createTypeLiteralScope(XExpression featureCall, XExpression receiver, IFeatureScopeSession session, IResolvedTypes resolvedTypes, LightweightTypeReference receiverType, JvmIdentifiableElement linkedReceiver) { if (linkedReceiver instanceof JvmDeclaredType) { IFeatureLinkingCandidate candidate = resolvedTypes.getLinkingCandidate(asAbstractFeatureCall(receiver)); if (candidate != null && candidate.isTypeLiteral()) { JvmDeclaredType declaringType = (JvmDeclaredType) linkedReceiver; IScope result = createNestedTypeLiteralScope(featureCall, receiverType, declaringType, IScope.NULLSCOPE, session); result = createStaticFeatureOnTypeLiteralScope(asAbstractFeatureCall(featureCall), declaringType, receiver, receiverType, result, session); return result; } } return null; }
return IScope.NULLSCOPE; LightweightTypeReference receiverType = resolvedTypes.getActualType(receiver); if (receiverType != null && !isUnknownReceiverType(receiverType)) { JvmIdentifiableElement linkedReceiver = resolvedTypes.getLinkedFeature(asAbstractFeatureCall(receiver)); boolean typeLiteral = false; IScope root = createTypeLiteralScope(featureCall, receiver, session, resolvedTypes, receiverType, linkedReceiver); if (root != null) { if (featureCall instanceof XMemberFeatureCall && ((XMemberFeatureCall) featureCall).isExplicitStatic()) { if (typeLiteral || isValidFeatureCallArgument(receiver, linkedReceiver, session)) { IScope staticScope = createStaticScope(asAbstractFeatureCall(featureCall), receiver, receiverType, root, session, resolvedTypes); IScope staticExtensionScope = createStaticExtensionsScope(receiver, receiverType, featureCall, staticScope, session, resolvedTypes); IScope extensionScope = createDynamicExtensionsScope(receiver, receiverType, featureCall, staticExtensionScope, session, resolvedTypes); return createFeatureScopeForTypeRef(receiver, receiverType, false, featureCall, session, linkedReceiver, extensionScope, true); } else { return createFeatureScopeForTypeRef(receiver, receiverType, false, featureCall, session, linkedReceiver, IScope.NULLSCOPE, true); IScope errorScope = createFollowUpErrorScope(receiverType); List<String> prefix = typeLiteralHelper.getTypeNameSegmentsFromConcreteSyntax((XMemberFeatureCall) featureCall); if (prefix == null) { return errorScope; return createTypeLiteralScope(featureCall, QualifiedName.create(prefix), errorScope, session, resolvedTypes); } else {
/** * creates the feature scope for {@link XAbstractFeatureCall}, including the local variables in case it is a feature * call without receiver (XFeatureCall). * @param session the currently available session data */ public IScope createFeatureCallScope(EObject context, EReference reference, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { if (!isFeatureCallScope(reference)) { throw new IllegalArgumentException(String.valueOf(reference)); } if (!(context instanceof XAbstractFeatureCall)) { return IScope.NULLSCOPE; } XAbstractFeatureCall call = (XAbstractFeatureCall) context; final XExpression syntacticalReceiver = getSyntacticalReceiver(call); if (syntacticalReceiver == null) { IScope result = createSimpleFeatureCallScope(call, session, resolvedTypes); return result; } IScope result = createFeatureCallScopeForReceiver(call, syntacticalReceiver, session, resolvedTypes); return result; }
/** * Creates a scope for the local variables that have been registered in the given session. * * @param featureCall the feature call that is currently processed by the scoping infrastructure * @param parent the parent scope. Is never null. * @param session the currently known scope session. Is never null. * @param resolvedTypes may be used by inheritors. */ protected IScope createLocalVariableScope(EObject featureCall, IScope parent, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { return new LocalVariableScope(parent, session, asAbstractFeatureCall(featureCall)); }
protected IScope createStaticExtensionsScope(XExpression receiver, LightweightTypeReference receiverType, EObject featureCall, IScope parent, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { IFeatureScopeSession nextCaptureLayer = session.getNextCaptureLayer(); if (nextCaptureLayer != null) { parent = createStaticExtensionsScope(receiver, receiverType, featureCall, parent, nextCaptureLayer, resolvedTypes); } IScope result = parent; if (receiver == null) { // 'this' is a valid implicit first argument, e.g. implementations of Iterable may use #filter on themselves result = createImplicitExtensionScope(THIS, featureCall, session, resolvedTypes, result); // 'it' has a higher priority than 'this' as implicit first argument result = createImplicitExtensionScope(IT, featureCall, session, resolvedTypes, result); return result; } else { if (receiverType == null) { throw new IllegalStateException("Unknown receiver type"); } result = createStaticExtensionsScope(featureCall, receiver, receiverType, false, parent, session); } return result; }
protected IScope createDynamicExtensionsScope(XExpression firstArgument, LightweightTypeReference firstArgumentType, EObject featureCall, IScope parent, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { return createDynamicExtensionsScope(firstArgument, firstArgumentType, featureCall, parent, session, session, resolvedTypes); }
protected IScope createFeatureCallScope(EObject context, EReference reference, IResolvedTypes resolvedTypes) { return getFeatureScopes().createFeatureCallScope(context, reference, this, resolvedTypes); }
IScope result = new Scope(featureScopes.createFeatureCallScopeForReceiver(receiver, (XExpression) context, single.getSession(), single.getTypes()), owner); return result; } else { for(int i = dataToUse.size() - 1; i >= 0; i--) { FeatureScopeSessionToResolvedTypes f = dataToUse.get(i); result = new DelegateScope(result, featureScopes.createFeatureCallScopeForReceiver(receiver, (XExpression) context, f.getSession(), f.getTypes()));
protected IScope createConstructorDelegates(EObject context, IScope parent, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { if (session.isConstructorContext()) { IEObjectDescription thisDescription = session.getLocalElement(THIS); if (thisDescription != null) { JvmIdentifiableElement thisElement = (JvmIdentifiableElement) thisDescription.getEObjectOrProxy(); LightweightTypeReference type = resolvedTypes.getActualType(thisElement); if (type != null && !type.isUnknown()) { return createConstructorDelegateScope(context, type, parent, session); } } } return parent; }
protected IScope createImplicitFeatureCallScope(QualifiedName implicitName, EObject featureCall, IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) { IEObjectDescription thisDescription = session.getLocalElement(implicitName); if (thisDescription != null) { JvmIdentifiableElement thisElement = (JvmIdentifiableElement) thisDescription.getEObjectOrProxy(); boolean validStaticScope = true; if (thisElement instanceof JvmType && THIS.equals(implicitName) && !session.isInstanceContext()) { validStaticScope = false; } LightweightTypeReference type = resolvedTypes.getActualType(thisElement); if (type !=null && !type.isUnknown()) { XFeatureCall implicitReceiver = xbaseFactory.createXFeatureCall(); implicitReceiver.setFeature(thisElement); return createFeatureScopeForTypeRef(implicitReceiver, type, true, featureCall, session, thisElement, parent, validStaticScope); } } return parent; }
/** * Create a composite scope that returns description from multiple other scopes without applying shadowing semantics to then. */ protected CompositeScope createCompositeScope(EObject featureCall, IScope parent, IFeatureScopeSession session) { return new CompositeScope(parent, session, asAbstractFeatureCall(featureCall)); }
protected IScope createDynamicExtensionsScope(XExpression firstArgument, LightweightTypeReference firstArgumentType, EObject featureCall, IScope parent, IFeatureScopeSession captureLayer, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { IFeatureScopeSession nextCaptureLayer = captureLayer.getNextCaptureLayer(); if (nextCaptureLayer != null) { parent = createDynamicExtensionsScope(firstArgument, firstArgumentType, featureCall, parent, nextCaptureLayer, session, resolvedTypes); } List<ExpressionBucket> extensionProviders = captureLayer.getExtensionProviders(); if (extensionProviders.isEmpty()) { return parent; } IScope result = parent; if (firstArgument == null) { result = createDynamicExtensionsScope(THIS, featureCall, captureLayer, session, resolvedTypes, result, true); result = createDynamicExtensionsScope(IT, featureCall, captureLayer, session, resolvedTypes, result, false); return result; } else { result = createDynamicExtensionsScope(featureCall, firstArgument, firstArgumentType, false, parent, captureLayer); } return result; }
/** * Creates a scope for the statically imported features. * * @param featureCall the feature call that is currently processed by the scoping infrastructure * @param parent the parent scope. Is never null. * @param session the currently known scope session. Is never null. */ protected IScope createStaticFeaturesScope(EObject featureCall, IScope parent, IFeatureScopeSession session) { return new StaticImportsScope(parent, session, asAbstractFeatureCall(featureCall)); }
protected IScope createDynamicExtensionsScope(QualifiedName implicitFirstArgumentName, IEObjectDescription firstArgumentDescription, EObject featureCall, IFeatureScopeSession captureLayer, IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) { JvmIdentifiableElement feature = (JvmIdentifiableElement) firstArgumentDescription.getEObjectOrProxy(); if (feature instanceof JvmType && THIS.equals(implicitFirstArgumentName) && !session.isInstanceContext()) { return parent; } LightweightTypeReference type = resolvedTypes.getActualType(feature); if (type != null && !type.isUnknown()) { XFeatureCall implicitArgument = xbaseFactory.createXFeatureCall(); implicitArgument.setFeature(feature); return createDynamicExtensionsScope(featureCall, implicitArgument, type, true, parent, captureLayer); } return parent; }
/** * Create a scope that returns types, e.g. for member feature calls that are actually type references like * {@code java.lang.String}. * * @param featureCall the feature call that is currently processed by the scoping infrastructure * @param parentSegments the segments of the fully qualified type name that are already known. The queried element name will be appended to them. * @param parent the parent scope. Is never null. * @param session the currently known scope session. Is never null. */ protected IScope createTypeLiteralScope(EObject featureCall, QualifiedName parentSegments, IScope parent, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { return new TypeLiteralScope(parent, session, asAbstractFeatureCall(featureCall), resolvedTypes, parentSegments); }
/** * A constructor delegate scope provides the descriptions for {@code this()} and {@code super()} * calls in a constructor body. */ protected IScope createConstructorDelegateScope(EObject featureCall, LightweightTypeReference type, IScope parent, IFeatureScopeSession session) { return new ConstructorDelegateScope(parent, type, session, asAbstractFeatureCall(featureCall)); }
/** * Create a scope that returns nested types. * * @param featureCall the feature call that is currently processed by the scoping infrastructure * @param enclosingType the enclosing type including type parameters for the nested type literal scope. * @param rawEnclosingType the raw type that is used to query the nested types. * @param parent the parent scope. Is never null. * @param session the currently known scope session. Is never null. */ protected IScope createNestedTypeLiteralScope( EObject featureCall, LightweightTypeReference enclosingType, JvmDeclaredType rawEnclosingType, IScope parent, IFeatureScopeSession session) { return new NestedTypeLiteralScope(parent, session, asAbstractFeatureCall(featureCall), enclosingType, rawEnclosingType); }