org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices Java Examples

The following examples show how to use org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices. 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: AbstractPendingLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns false if the argument expression is a lambda and the expected type
 * of the argument is not a function type or {@link Object}.
 * Returns true in all other cases.
 * 
 * This serves as a shortcut to rule out decision path's where a method is overloaded
 * and one of the overloads accepts a function type but the other doesn't. In those cases
 * it is not necessary to compute the type of the lamdba expression twice.
 * 
 * An example for this pattern is {@link IterableExtensions#filter(Iterable, Class)} vs
 * {@link IterableExtensions#filter(Iterable, org.eclipse.xtext.xbase.lib.Functions.Function1)}.
 */
protected boolean isPossibleFunctionType(int idx) {
	if (idx < arguments.getArgumentCount()) {
		XExpression argument = arguments.getArgument(idx);
		if (argument instanceof XClosure) {
			XClosure closure = (XClosure) argument;
			LightweightTypeReference declaredType = arguments.getDeclaredTypeForLambda(idx);
			if (declaredType != null && !declaredType.isType(Object.class)) {
				CommonTypeComputationServices services = getState().getReferenceOwner().getServices();
				JvmOperation operation = services.getFunctionTypes().findImplementingOperation(declaredType);
				if (operation == null) {
					return false;
				}
				if (closure.isExplicitSyntax() && closure.getDeclaredFormalParameters().size() != operation.getParameters().size()) {
					return false;
				}
			}
		}
	}
	return true;
}
 
Example #2
Source File: RawResolvedFeatures.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns an existing instance of {@link RawResolvedFeatures} or creates a new one that
 * will be cached on the type. It will not add itself as {@link EContentAdapter} but use
 * the {@link JvmTypeChangeDispatcher} instead.
 */
static RawResolvedFeatures getResolvedFeatures(JvmDeclaredType type, CommonTypeComputationServices services) {
	final List<Adapter> adapterList = type.eAdapters();
	RawResolvedFeatures adapter = (RawResolvedFeatures) EcoreUtil.getAdapter(adapterList, RawResolvedFeatures.class);
	if (adapter != null) {
		return adapter;
	}
	final RawResolvedFeatures newAdapter = new RawResolvedFeatures(type, services);
	requestNotificationOnChange(type, new Runnable() {
		@Override
		public void run() {
			newAdapter.clear();
			adapterList.remove(newAdapter);
		}
	});
	adapterList.add(newAdapter);
	return newAdapter;
}
 
Example #3
Source File: Utils.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Convert a type to a lightweight type reference.
 *
 * @param type - type to convert.
 * @param services - services used for the conversion
 * @param keepUnboundWildcardInformation - indicates if the unbound wild card
 *        information must be keeped in the lightweight reference.
 * @return the lightweight type reference.
 */
public static LightweightTypeReference toLightweightTypeReference(
		JvmType type, CommonTypeComputationServices services,
		boolean keepUnboundWildcardInformation) {
	if (type == null) {
		return null;
	}
	final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, type);
	final LightweightTypeReferenceFactory factory = new LightweightTypeReferenceFactory(owner,
			keepUnboundWildcardInformation);
	final LightweightTypeReference reference = factory.toLightweightReference(type);
	return reference;
}
 
Example #4
Source File: Utils.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Convert a type reference to a lightweight type reference.
 *
 * @param typeRef - reference to convert.
 * @param services - services used for the conversion
 * @param keepUnboundWildcardInformation - indicates if the unbound wild card
 *        information must be keeped in the lightweight reference.
 * @return the lightweight type reference.
 */
public static LightweightTypeReference toLightweightTypeReference(
		JvmTypeReference typeRef, CommonTypeComputationServices services,
		boolean keepUnboundWildcardInformation) {
	if (typeRef == null) {
		return null;
	}
	final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, typeRef);
	final LightweightTypeReferenceFactory factory = new LightweightTypeReferenceFactory(owner,
			keepUnboundWildcardInformation);
	final LightweightTypeReference reference = factory.toLightweightReference(typeRef);
	return reference;
}
 
Example #5
Source File: SarlProcessorInstanceForJvmTypeProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Filter the type in order to create the correct processor.
 *
 * @param type the type of the processor specified into the {@code @Active} annotation.
 * @param services the type services of the framework.
 * @return the real type of the processor to instance.
 */
public static JvmType filterActiveProcessorType(JvmType type, CommonTypeComputationServices services) {
	if (AccessorsProcessor.class.getName().equals(type.getQualifiedName())) {
		final JvmType filteredType = services.getTypeReferences().findDeclaredType(SarlAccessorsProcessor.class, type);
		if (filteredType != null) {
			return filteredType;
		}
	}
	return type;
}
 
Example #6
Source File: ResolvedFeature.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> getDeclaratorParameterMapping() {
	final Wrapper<Map<JvmTypeParameter, LightweightMergedBoundTypeArgument>> receiverTypeParameterMapping = Wrapper.wrap(Collections.<JvmTypeParameter, LightweightMergedBoundTypeArgument>emptyMap());
	XExpression receiver = getReceiver();
	if (receiver != null) {
		LightweightTypeReference receiverType = getReceiverType();
		if (receiverType == null) {
			throw new IllegalStateException("Cannot determine type of receiver "+ getReceiver());
		}
		JvmIdentifiableElement feature = getFeature();
		if (feature instanceof JvmFeature) {
			JvmDeclaredType declaringType = ((JvmFeature) feature).getDeclaringType();
			final LightweightTypeReference declaringTypeReference = receiverType.getOwner().newParameterizedTypeReference(declaringType);
			final TypeConformanceComputationArgument rawConformanceCheck = new TypeConformanceComputationArgument(true, false, false, false, false, false);
			if (declaringTypeReference.isAssignableFrom(receiverType, rawConformanceCheck)) {
				receiverTypeParameterMapping.set(new DeclaratorTypeArgumentCollector().getTypeParameterMapping(receiverType));
			} else {
				CommonTypeComputationServices services = receiverType.getOwner().getServices();
				SynonymTypesProvider synonymProvider = services.getSynonymTypesProvider();
				synonymProvider.collectSynonymTypes(receiverType, new SynonymTypesProvider.Acceptor() {
					
					@Override
					protected boolean accept(LightweightTypeReference synonym, int hints) {
						if (declaringTypeReference.isAssignableFrom(synonym, rawConformanceCheck)) {
							receiverTypeParameterMapping.set(new DeclaratorTypeArgumentCollector().getTypeParameterMapping(synonym));
							return false;
						}
						return true;
					}
				});
			}
			
		} else {
			receiverTypeParameterMapping.set(new DeclaratorTypeArgumentCollector().getTypeParameterMapping(receiverType));
		}
	}
	return receiverTypeParameterMapping.get();
}
 
Example #7
Source File: StandardTypeReferenceOwner.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public CommonTypeComputationServices getServices() {
	return services;
}
 
Example #8
Source File: AbstractExtraLanguageGenerator.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Change the common type service.
 *
 * @param services the service.
 */
@Inject
public void setCommonTypeComputationServices(CommonTypeComputationServices services) {
	this.services = services;
}
 
Example #9
Source File: AbstractTestingTypeReferenceOwner.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Pure
protected CommonTypeComputationServices getServices() {
  return this.services;
}
 
Example #10
Source File: ClosureTypeComputerUnitTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public CommonTypeComputationServices getServices() {
	return services;
}
 
Example #11
Source File: AbstractXbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected CommonTypeComputationServices getTypeComputationServices() {
	return services;
}
 
Example #12
Source File: RawResolvedFeatures.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected RawResolvedFeatures(JvmDeclaredType type, CommonTypeComputationServices services) {
	this(createTypeReference(type, services), new OverrideTester());
}
 
Example #13
Source File: RawResolvedFeatures.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Static helper method that is used from within the super call in the constructor of
 * {@link RawResolvedFeatures}.
 */
private static LightweightTypeReference createTypeReference(JvmDeclaredType type, CommonTypeComputationServices services) {
	StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, type);
	return owner.newParameterizedTypeReference(type);
}
 
Example #14
Source File: LightweightTypeReference.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected CommonTypeComputationServices getServices() {
	return getOwner().getServices();
}
 
Example #15
Source File: StandardTypeReferenceOwner.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public StandardTypeReferenceOwner(CommonTypeComputationServices services, EObject context) {
	super(services, context);
}
 
Example #16
Source File: StandardTypeReferenceOwner.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public StandardTypeReferenceOwner(CommonTypeComputationServices services, Resource context) {
	this(services, context.getResourceSet());
}
 
Example #17
Source File: StandardTypeReferenceOwner.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public StandardTypeReferenceOwner(CommonTypeComputationServices services, EObject context) {
	this(services, context.eResource());
}
 
Example #18
Source File: StandardTypeReferenceOwner.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public StandardTypeReferenceOwner(CommonTypeComputationServices services, /* @Nullable */ ResourceSet context) {
	this.services = services;
	this.context = context;
	this.factory = new LightweightTypeReferenceFactory(this);
}
 
Example #19
Source File: ResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public CommonTypeComputationServices getServices() {
	return owner.getServices();
}
 
Example #20
Source File: ResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Owner(CommonTypeComputationServices services, ResourceSet context) {
	super(services, context);
}
 
Example #21
Source File: AbstractPendingLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean isDefiniteEarlyExit(XExpression expression) {
	CommonTypeComputationServices services = getState().getReferenceOwner().getServices();
	return services.getEarlyExitComputer().isDefiniteEarlyExit(expression);
}
 
Example #22
Source File: DefaultReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected CommonTypeComputationServices getServices() {
	return services;
}
 
Example #23
Source File: AbstractClosureTypeHelper.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected CommonTypeComputationServices getServices() {
	return services;
}
 
Example #24
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected CommonTypeComputationServices getServices() {
	return services;
}
 
Example #25
Source File: StandardTypeReferenceOwner.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public StandardTypeReferenceOwner(CommonTypeComputationServices services, ResourceSet context) {
	super(services, context);
}
 
Example #26
Source File: StandardTypeReferenceOwner.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public StandardTypeReferenceOwner(CommonTypeComputationServices services, Resource context) {
	super(services, context);
}
 
Example #27
Source File: ITypeReferenceOwner.java    From xtext-extras with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Access to commonly used services for type references.
 */
CommonTypeComputationServices getServices();
 
Example #28
Source File: SARLQuickfixProvider.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Replies the type services.
 *
 * @return the type services.
 */
public CommonTypeComputationServices getTypeServices() {
	return this.services;
}
 
Example #29
Source File: Utils.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Convert a type reference to a lightweight type reference.
 *
 * @param typeRef - reference to convert.
 * @param services - services used for the conversion
 * @return the lightweight type reference.
 */
public static LightweightTypeReference toLightweightTypeReference(
		JvmTypeReference typeRef, CommonTypeComputationServices services) {
	return toLightweightTypeReference(typeRef, services, false);
}
 
Example #30
Source File: Utils.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Convert a type reference to a lightweight type reference.
 *
 * @param type - type to convert.
 * @param services - services used for the conversion
 * @return the lightweight type reference.
 */
public static LightweightTypeReference toLightweightTypeReference(
		JvmType type, CommonTypeComputationServices services) {
	return toLightweightTypeReference(type, services, false);
}