org.eclipse.xtext.xbase.typesystem.internal.TypeData Java Examples

The following examples show how to use org.eclipse.xtext.xbase.typesystem.internal.TypeData. 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: TypeComputationStateTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testTypeOnlyRegisteredOnce_01() throws Exception {
	resolver.setTypeComputer(this);
	XExpression expression = expression("{ null }");
	resolver.initializeFrom(expression);
	PublicResolvedTypes resolution = new PublicResolvedTypes(resolver);
	AnyTypeReference any = resolution.getReferenceOwner().newAnyTypeReference();
	new ExpressionBasedRootTypeComputationState(resolution, resolver.getBatchScopeProvider().newSession(expression.eResource()),
			expression, any).computeTypes();
	Map<XExpression, List<TypeData>> expressionTypes = resolution.basicGetExpressionTypes();
	List<TypeData> typesForNullLiteral = expressionTypes.get(getFirst(((XBlockExpression) expression).getExpressions(), null));
	assertEquals(typesForNullLiteral.toString(), 1, size(filter(typesForNullLiteral, it -> it.isReturnType())));
	assertEquals(typesForNullLiteral.toString(), 1, size(filter(typesForNullLiteral, it -> !it.isReturnType())));
	List<TypeData> typesForBlock = expressionTypes.get(expression);
	assertEquals(typesForBlock.toString(), 1, size(filter(typesForBlock, it -> it.isReturnType())));
	assertEquals(typesForBlock.toString(), 1, size(filter(typesForBlock, it -> !it.isReturnType())));
}
 
Example #2
Source File: TypeComputationStateTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testTypeOnlyRegisteredOnce_02() throws Exception {
	XMemberFeatureCall expression = ((XMemberFeatureCall) expression("1.toString"));
	resolver.initializeFrom(expression);
	PublicResolvedTypes resolution = new PublicResolvedTypes(resolver);
	AnyTypeReference any = resolution.getReferenceOwner().newAnyTypeReference();
	new ExpressionBasedRootTypeComputationState(resolution, resolver.getBatchScopeProvider().newSession(expression.eResource()),
			expression, any).computeTypes();
	Map<XExpression, List<TypeData>> expressionTypes = resolution.basicGetExpressionTypes();
	TreeIterator<EObject> allContents = expression.eAllContents();
	while (allContents.hasNext()) {
		EObject o = allContents.next();
		List<TypeData> types = expressionTypes.get(o);
		assertEquals(types.toString(), 1, size(filter(types, it -> !it.isReturnType())));
	}
}
 
Example #3
Source File: TypeComputationStateTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Ignore("TODO FixMe")
@Test
public void testTypeOnlyRegisteredOnce_03() throws Exception {
	XMemberFeatureCall expression = ((XMemberFeatureCall) expression("<String>newArrayList.map[toUpperCase]"));
	resolver.initializeFrom(expression);
	PublicResolvedTypes resolution = new PublicResolvedTypes(resolver);
	AnyTypeReference any = resolution.getReferenceOwner().newAnyTypeReference();
	new ExpressionBasedRootTypeComputationState(resolution, resolver.getBatchScopeProvider().newSession(expression.eResource()),
			expression, any).computeTypes();
	Map<XExpression, List<TypeData>> expressionTypes = resolution.basicGetExpressionTypes();
	TreeIterator<EObject> allContents = expression.eAllContents();
	while (allContents.hasNext()) {
		EObject o = allContents.next();
		List<TypeData> typesForMemberFeatureCall = expressionTypes.get((o));
		assertEquals(o + " " + typesForMemberFeatureCall.toString(), 1,
				IterableExtensions.size(filter(typesForMemberFeatureCall, it -> it.isReturnType())));
		assertEquals(typesForMemberFeatureCall.toString(), 1,
				IterableExtensions.size(filter(typesForMemberFeatureCall, it -> !it.isReturnType())));
	}
}
 
Example #4
Source File: TypeComputationStateTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testTypeOnlyRegisteredOnce_04() throws Exception {
	XNumberLiteral expression = ((XNumberLiteral) expression("1"));
	resolver.initializeFrom(expression);
	PublicResolvedTypes resolution = new PublicResolvedTypes(resolver);
	AnyTypeReference any = resolution.getReferenceOwner().newAnyTypeReference();
	new ExpressionBasedRootTypeComputationState(resolution, resolver.getBatchScopeProvider().newSession(expression.eResource()),
			expression, any).computeTypes();
	Map<XExpression, List<TypeData>> expressionTypes = resolution.basicGetExpressionTypes();
	TreeIterator<EObject> allContents = expression.eAllContents();
	while (allContents.hasNext()) {
		EObject o = allContents.next();
		List<TypeData> types = expressionTypes.get((o));
		assertEquals(types.toString(), 1, size(filter(types, it -> !it.isReturnType())));
	}
}
 
Example #5
Source File: ValidatingReassigningResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public TypeData mergeTypeData(XExpression expression, List<TypeData> allValues, boolean returnType, boolean nullIfEmpty) {
	for (TypeData it : allValues) {
		if (!it.isOwnedBy(getReferenceOwner())) {
			throw new IllegalArgumentException("result is not owned by this resolved types");
		}
	}
	TypeData result = super.mergeTypeData(expression, allValues, returnType, nullIfEmpty);
	if (!result.isOwnedBy(getReferenceOwner())) {
		throw new IllegalArgumentException("result is not owned by this resolved types");
	}
	return result;
}
 
Example #6
Source File: ValidatingRootResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public TypeData mergeTypeData(XExpression expression, List<TypeData> allValues, boolean returnType, boolean nullIfEmpty) {
	for (TypeData it : allValues) {
		if (!it.isOwnedBy(getReferenceOwner())) {
			throw new IllegalArgumentException("result is not owned by this resolved types");
		}
	}
	TypeData result = super.mergeTypeData(expression, allValues, returnType, nullIfEmpty);
	if (!result.isOwnedBy(getReferenceOwner())) {
		throw new IllegalArgumentException("result is not owned by this resolved types");
	}
	return result;
}
 
Example #7
Source File: ValidatingRootResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void acceptType(XExpression expression, TypeData typeData) {
	if (!typeData.isOwnedBy(getReferenceOwner())) {
		throw new IllegalArgumentException("typeData is not owned by this resolved types");
	}
	super.acceptType(expression, typeData);
}
 
Example #8
Source File: ValidatingRootResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<TypeData> doGetTypeData(XExpression expression) {
	List<TypeData> result = super.doGetTypeData(expression);
	if (result != null) {
		for (TypeData it : result) {
			if (!it.isOwnedBy(getReferenceOwner())) {
				throw new IllegalArgumentException("result is not owned by this resolved types");
			}
		}
	}
	return result;
}
 
Example #9
Source File: ValidatingExpressionAwareResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public TypeData mergeTypeData(XExpression expression, List<TypeData> allValues, boolean returnType, boolean nullIfEmpty) {
	for (TypeData it : allValues) {
		if (!it.isOwnedBy(getReferenceOwner())) {
			throw new IllegalArgumentException("result is not owned by this resolved types");
		}
	}
	TypeData result = super.mergeTypeData(expression, allValues, returnType, nullIfEmpty);
	if (result != null && !result.isOwnedBy(getReferenceOwner())) {
		throw new IllegalArgumentException("result is not owned by this resolved types");
	}
	return result;
}
 
Example #10
Source File: ValidatingStackedResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public TypeData mergeTypeData(XExpression expression, List<TypeData> allValues, boolean returnType, boolean nullIfEmpty) {
	for (TypeData it : allValues) {
		if (!it.isOwnedBy(getReferenceOwner())) {
			throw new IllegalArgumentException("result is not owned by this resolved types");
		}
	}
	TypeData result = super.mergeTypeData(expression, allValues, returnType, nullIfEmpty);
	if (!result.isOwnedBy(getReferenceOwner())) {
		throw new IllegalArgumentException("result is not owned by this resolved types");
	}
	return result;
}
 
Example #11
Source File: PublicResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Map<XExpression, List<TypeData>> basicGetExpressionTypes() {
	return super.basicGetExpressionTypes();
}
 
Example #12
Source File: PublicResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Map<XExpression, List<TypeData>> basicGetExpressionTypes() {
	return super.basicGetExpressionTypes();
}
 
Example #13
Source File: PublicResolvedTypes.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Map<XExpression, List<TypeData>> basicGetExpressionTypes() {
	return super.basicGetExpressionTypes();
}
 
Example #14
Source File: PublicResolvedTypes.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Map<XExpression, List<TypeData>> basicGetExpressionTypes() {
  return super.basicGetExpressionTypes();
}