Java Code Examples for org.eclipse.xtext.scoping.IScope#NULLSCOPE

The following examples show how to use org.eclipse.xtext.scoping.IScope#NULLSCOPE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XbaseWithAnnotationsBatchScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IScope getScope(EObject context, EReference reference) {
	if (reference == XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT) {
		XAnnotation annotation = EcoreUtil2.getContainerOfType(context, XAnnotation.class);
		JvmType annotationType = annotation.getAnnotationType();
		if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) {
			return IScope.NULLSCOPE;
		}
		Iterable<JvmOperation> operations = ((JvmAnnotationType) annotationType).getDeclaredOperations();
		Iterable<IEObjectDescription> descriptions = transform(operations, new Function<JvmOperation, IEObjectDescription>() {
			@Override
			public IEObjectDescription apply(JvmOperation from) {
				return EObjectDescription.create(QualifiedName.create(from.getSimpleName()), from);
			}
		});
		return MapBasedScope.createScope(IScope.NULLSCOPE, descriptions);
	}
	return super.getScope(context, reference);
}
 
Example 2
Source File: FeatureScopes.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: SerializerScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected IScope getExecutableScope(XAbstractFeatureCall call, JvmIdentifiableElement feature) {
	final String simpleName = feature.getSimpleName();
	QualifiedName name = QualifiedName.create(simpleName);
	if (call.isOperation()) {
		QualifiedName operator = getOperator(call, name);
		if (operator == null) {
			return IScope.NULLSCOPE;
		}
		return new SingletonScope(EObjectDescription.create(operator, feature), IScope.NULLSCOPE);
	}
	if (call instanceof XAssignment) {
		return getAccessorScope(simpleName, name, feature);
	}
	if (call.isExplicitOperationCallOrBuilderSyntax() || ((JvmExecutable) feature).getParameters().size() > 1
			|| (!call.isExtension() && ((JvmExecutable) feature).getParameters().size() == 1)) {
		return new SingletonScope(EObjectDescription.create(name, feature), IScope.NULLSCOPE);
	}

	return getAccessorScope(simpleName, name, feature);
}
 
Example 4
Source File: AbstractRecursiveScope.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * For debugging.
 *
 * @return A string representation of the scope useful for debugging.
 */
@SuppressWarnings("nls")
@Override
public String toString() {
  final StringBuilder result = new StringBuilder(getClass().getName());
  result.append('@');
  result.append(Integer.toHexString(hashCode()));

  result.append(" (id: ");
  result.append(getId());
  result.append(')');

  final IScope outerScope = getParent();
  if (outerScope != IScope.NULLSCOPE) {
    result.append("\n  >> ");
    result.append(outerScope.toString().replaceAll("\\\n", "\n  "));
  }
  return result.toString();
}
 
Example 5
Source File: ExpressionScope.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected Iterable<IEObjectDescription> getAllLocalElements() {
	if (containedElements == null) {
		if (getParent() != IScope.NULLSCOPE) {
			Iterable<IEObjectDescription> result = delegate.getAllElements();
			List<IEObjectDescription> list = Lists.newArrayList(result);
			Set<String> keys = Sets.newHashSet();
			for(IEObjectDescription desc: result) {
				list.add(desc);
				keys.add(getShadowingKey(desc));
			}
			containedKeys = keys;
			containedElements = list;
			return list;
		} else {
			return delegate.getAllElements();
		}
	}
	return containedElements;
}
 
Example 6
Source File: AbstractTypeScope.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected AbstractTypeScope(IJvmTypeProvider typeProvider, IQualifiedNameConverter qualifiedNameConverter,
		Predicate<IEObjectDescription> filter) {
	super(IScope.NULLSCOPE, false);
	this.typeProvider = typeProvider;
	this.qualifiedNameConverter = qualifiedNameConverter;
	this.filter = filter;
}
 
Example 7
Source File: XtextScopeProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected IScope createClassifierScope(Iterable<EClassifier> classifiers) {
	return new SimpleScope(
			IScope.NULLSCOPE,Iterables.transform(classifiers, new Function<EClassifier, IEObjectDescription>() {
				@Override
				public IEObjectDescription apply(EClassifier param) {
					return EObjectDescription.create(QualifiedName.create(param.getName()), param);
				}
			}));
}
 
Example 8
Source File: LazyLinkingTestLanguageScopeProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public IScope scope_Property(Type t, EReference ref) {
	return new SimpleScope(IScope.NULLSCOPE, Iterables.transform(t.getExtends().getProperties(), new Function<Property, IEObjectDescription>(){
		@Override
		public IEObjectDescription apply(Property param) {
			return EObjectDescription.create(QualifiedName.create(param.getName()), param);
		}
	}));
}
 
Example 9
Source File: ExportScopeProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create a scope of all the structural features of the type of an Export.
 * 
 * @param context
 *          The FeatureList
 * @param reference
 *          The EReference
 * @return The scope
 */
// CHECKSTYLE:OFF (MethodName)
public IScope scope_EStructuralFeature(final DeclarationForType context, final EReference reference) {
  // CHECKSTYLE:ON
  final EClass type = context.getType();
  if (type != null) {
    return createENamedElementScope(type.getEAllStructuralFeatures());
  }
  return IScope.NULLSCOPE;
}
 
Example 10
Source File: CastScopeSession.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** create a scope for cast operator.
 *
 * @param context the context.
 * @param reference the reference to the internal feature.
 * @param resolvedTypes the resolved types.
 * @return the scope.
 */
protected IScope createCastOperatorScope(EObject context, EReference reference, IResolvedTypes resolvedTypes) {
	if (!(context instanceof SarlCastedExpression)) {
		return IScope.NULLSCOPE;
	}
	final SarlCastedExpression call = (SarlCastedExpression) context;
	final XExpression receiver = call.getTarget();
	if (receiver == null) {
		return IScope.NULLSCOPE;
	}
	return getFeatureScopes().createFeatureCallScopeForReceiver(call, receiver, getParent(), resolvedTypes);
}
 
Example 11
Source File: ComposedMemberScope.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates union type scope, passed subScopes are expected to be fully configured (i.e., including required filters
 * etc.)
 */
public ComposedMemberScope(ComposedTypeRef composedTypeRef, MemberScopeRequest request, List<IScope> subScopes,
		N4JSTypeSystem ts) {

	super(IScope.NULLSCOPE, false);

	this.composedTypeRef = composedTypeRef;
	this.subScopes = subScopes.toArray(new IScope[subScopes.size()]);
	this.ts = ts;
	this.request = request;
	this.writeAccess = ExpressionExtensions.isLeftHandSide(request.context);
}
 
Example 12
Source File: ValidScopeProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Scope provider for EStructuralFeature (all "attributes" of an EClas in a native context.
 * 
 * @param nativeContext
 *          the valid model
 * @param reference
 *          context reference
 * @return the i scope
 */
// CHECKSTYLE:OFF
public IScope scope_EStructuralFeature(final NativeContext nativeContext, final EReference reference) {
  // CHECKSTYLE:ON
  switch (reference.getFeatureID()) {
  case ValidPackage.NATIVE_CONTEXT__CONTEXT_FEATURE:
    return createENamedElementScope(nativeContext.getContextType().getEAllStructuralFeatures());
  case ValidPackage.NATIVE_CONTEXT__MARKER_FEATURE:
    return createENamedElementScope(nativeContext.getMarkerType().getEAllStructuralFeatures());
  default:
    return IScope.NULLSCOPE; // To keep Java happy. This should not happen.
  }
}
 
Example 13
Source File: DelegatingScopeProviderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
TestableDelegatingScopeProvider() {
	this(new IScopeProvider() {
		@Override
		public IScope getScope(EObject context, EReference reference) {
			return IScope.NULLSCOPE;
		}
	});
}
 
Example 14
Source File: ExportScopeProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create a scope of all the EReferences of the type of a FingerPrint.
 * 
 * @param context
 *          The FingerPrintNavigation
 * @param reference
 *          The EReference
 * @return The scope
 */
// CHECKSTYLE:OFF (MethodName)
public IScope scope_InterfaceNavigation_ref(final Interface context, final EReference reference) {
  // CHECKSTYLE:ON
  final EClass type = context.getType();
  if (type != null) {
    return createENamedElementScope(type.getEAllReferences());
  }
  return IScope.NULLSCOPE;
}
 
Example 15
Source File: CompositeScope.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new {@link CompositeScope}; if no scopes are given, {@link IScope#NULLSCOPE} is returned.
 */
public static final IScope create(IScope... scopes) {
	if (scopes.length == 0) {
		return IScope.NULLSCOPE;
	}
	return new CompositeScope(scopes);
}
 
Example 16
Source File: IExpressionScope.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public IScope getFeatureScope() {
	return IScope.NULLSCOPE;
}
 
Example 17
Source File: AbstractConstructorScope.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected AbstractConstructorScope(AbstractTypeScope typeScope) {
	super(IScope.NULLSCOPE, false);
	this.typeScope = typeScope;
}
 
Example 18
Source File: FeatureScopes.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * This method serves as an entry point for the content assist scoping for features.
 * @param featureCall the context provides access to the resource set. If it is an assignment, it 
 *   will be used to restrict scoping.
 * @param receiver the receiver of the feature call.
 * @param resolvedTypes TODO
 * @param session TODO
 */
public IScope createFeatureCallScopeForReceiver(final XExpression featureCall, final XExpression receiver, IFeatureScopeSession session, IResolvedTypes resolvedTypes) {
	if (receiver == null || receiver.eIsProxy())
		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()) {
                   return root;
               }
			typeLiteral = true;
		} else {
			root = IScope.NULLSCOPE;
		}
		// check if 'super' was used as receiver which renders extension features and static features invalid
		if (typeLiteral || isValidFeatureCallArgument(receiver, linkedReceiver, session)) {
			// static members that are invoked on a receiver, e.g. myString.CASE_INSENSITIVE_ORDER
			IScope staticScope = createStaticScope(asAbstractFeatureCall(featureCall), receiver, receiverType, root, session, resolvedTypes);
			
			// static extensions, if any, e.g. iterable.map [], or things that have been imported by means of import static extension MyType
			IScope staticExtensionScope = createStaticExtensionsScope(receiver, receiverType, featureCall, staticScope, session, resolvedTypes);
			
			// instance extensions, e.g. extension ReflectionUtils with myObject.get('privateField')
			IScope extensionScope = createDynamicExtensionsScope(receiver, receiverType, featureCall, staticExtensionScope, session, resolvedTypes);
			
			// instance members, e.g. this.toString
			return createFeatureScopeForTypeRef(receiver, receiverType, false, featureCall, session, linkedReceiver, extensionScope, true);
		} else {
			// put only instance members into the scope
			return createFeatureScopeForTypeRef(receiver, receiverType, false, featureCall, session, linkedReceiver, IScope.NULLSCOPE, true);
		}
	} else if (typeLiteralHelper.isPotentialTypeLiteral(featureCall, resolvedTypes)) {
		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 {
		return createFollowUpErrorScope(receiverType);
	}
}
 
Example 19
Source File: AbstractPolymorphicScopeProvider.java    From dsl-devkit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Special delegate scope for scopeof (this), skipping the delegate, if possible.
 *
 * @param id
 *          Human-readable name of the scope, typically used to identify where the scope was created. Useful for debugging.
 * @param parent
 *          The parent scope
 * @param context
 *          The context resource
 * @param type
 *          The type
 * @param scopeName
 *          The scope name
 * @param originalResource
 *          The original resource
 * @return a scope for the context object
 */
protected IScope newSameScope(final String id, final IScope parent, final Resource context, final EClass type, final String scopeName, final Resource originalResource) {
  if (context == null) {
    return parent;
  }
  if (parent == IScope.NULLSCOPE) {
    return getScope(context.getContents().get(0), type, scopeName, originalResource);
  } else {
    return newDelegateScope(id, parent, context, type, scopeName, originalResource);
  }
}
 
Example 20
Source File: AbstractPolymorphicScopeProvider.java    From dsl-devkit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Special delegate scope for scopeof (this), skipping the delegate, if possible.
 *
 * @param id
 *          Human-readable name of the scope, typically used to identify where the scope was created. Useful for debugging.
 * @param parent
 *          The parent scope
 * @param context
 *          The context resource
 * @param ref
 *          The reference
 * @param scopeName
 *          The scope name
 * @param originalResource
 *          The original resource
 * @return a scope for the context object
 */
protected IScope newSameScope(final String id, final IScope parent, final Resource context, final EReference ref, final String scopeName, final Resource originalResource) {
  if (context == null) {
    return parent;
  }
  if (parent == IScope.NULLSCOPE) {
    return getScope(context.getContents().get(0), ref, scopeName, originalResource);
  } else {
    return newDelegateScope(id, parent, context, ref, scopeName, originalResource);
  }
}