use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class XtendTypeComputer method _computeTypes.
protected void _computeTypes(RichStringIf object, ITypeComputationState state) {
LightweightTypeReference charSequence = getRawTypeForName(CharSequence.class, state);
LightweightTypeReference booleanType = getRawTypeForName(Boolean.TYPE, state);
ITypeComputationState conditionExpectation = state.withExpectation(booleanType);
XExpression condition = object.getIf();
conditionExpectation.computeTypes(condition);
XExpression thenExpression = object.getThen();
ITypeComputationState thenState = reassignCheckedType(condition, thenExpression, state);
thenState.withExpectation(charSequence).computeTypes(thenExpression);
for (RichStringElseIf elseIf : object.getElseIfs()) {
state.withExpectation(booleanType).computeTypes(elseIf.getIf());
ITypeComputationState elseState = reassignCheckedType(elseIf.getIf(), elseIf.getThen(), state);
elseState.withExpectation(charSequence).computeTypes(elseIf.getThen());
}
state.withExpectation(charSequence).computeTypes(object.getElse());
state.acceptActualType(charSequence);
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class XtendTypeComputer method _computeTypes.
protected void _computeTypes(RichString object, ITypeComputationState state) {
List<XExpression> expressions = object.getExpressions();
if (!expressions.isEmpty()) {
for (XExpression expression : expressions) {
ITypeComputationState expressionState = state.withoutExpectation();
expressionState.computeTypes(expression);
if (expression instanceof XVariableDeclaration) {
addLocalToCurrentScope((XVariableDeclaration) expression, state);
}
}
}
for (ITypeExpectation expectation : state.getExpectations()) {
LightweightTypeReference expectedType = expectation.getExpectedType();
if (expectedType != null && expectedType.isType(StringConcatenation.class)) {
expectation.acceptActualType(expectedType, ConformanceFlags.CHECKED_SUCCESS | ConformanceFlags.DEMAND_CONVERSION);
} else if (expectedType != null && expectedType.isType(StringConcatenationClient.class)) {
expectation.acceptActualType(expectedType, ConformanceFlags.CHECKED_SUCCESS | ConformanceFlags.DEMAND_CONVERSION);
} else if (expectedType != null && expectedType.isType(String.class)) {
expectation.acceptActualType(expectedType, ConformanceFlags.CHECKED_SUCCESS | ConformanceFlags.DEMAND_CONVERSION);
// TODO this special treatment here should become obsolete as soon as the expectations are properly propagated
} else if (!(object.eContainer() instanceof XCastedExpression) && object.eContainingFeature() != XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET && (expectedType != null && !expectedType.isResolved() || expectedType == null && !expectation.isVoidTypeAllowed())) {
LightweightTypeReference type = getRawTypeForName(String.class, state);
expectation.acceptActualType(type, ConformanceFlags.UNCHECKED | ConformanceFlags.DEMAND_CONVERSION);
} else {
LightweightTypeReference type = getRawTypeForName(CharSequence.class, state);
expectation.acceptActualType(type, ConformanceFlags.UNCHECKED);
}
}
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class XtendTypeComputer method _computeTypes.
protected void _computeTypes(RichStringLiteral object, ITypeComputationState state) {
LightweightTypeReference type = getRawTypeForName(CharSequence.class, state);
state.acceptActualType(type);
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class XtendValidator method getParamTypes.
protected List<JvmType> getParamTypes(JvmOperation jvmOperation, boolean wrapPrimitives) {
List<JvmType> types = newArrayList();
for (JvmFormalParameter p : jvmOperation.getParameters()) {
LightweightTypeReference typeReference = toLightweightTypeReference(p.getParameterType());
if (wrapPrimitives) {
typeReference = typeReference.getWrapperTypeIfPrimitive();
}
types.add(typeReference.getType());
}
return types;
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class XtendValidator method doCheckDuplicateExecutables.
protected <Executable extends IResolvedExecutable> void doCheckDuplicateExecutables(JvmGenericType inferredType, List<Executable> declaredOperations, Function<String, List<Executable>> bySignature, Set<EObject> flaggedOperations) {
Set<Executable> processed = Sets.newHashSet();
for (Executable declaredExecutable : declaredOperations) {
if (!processed.contains(declaredExecutable)) {
List<Executable> sameErasure = bySignature.apply(declaredExecutable.getResolvedErasureSignature());
if (sameErasure.size() > 1) {
Multimap<String, Executable> perSignature = HashMultimap.create(sameErasure.size(), 2);
outer: for (Executable executable : sameErasure) {
for (LightweightTypeReference parameterType : executable.getResolvedParameterTypes()) {
if (parameterType.isUnknown())
continue outer;
}
perSignature.put(executable.getResolvedSignature(), executable);
}
if (perSignature.size() > 1) {
for (Collection<Executable> sameSignature : perSignature.asMap().values()) {
for (Executable operationWithSameSignature : sameSignature) {
JvmExecutable executable = operationWithSameSignature.getDeclaration();
EObject otherSource = associations.getPrimarySourceElement(executable);
if (flaggedOperations.add(otherSource)) {
if (sameSignature.size() > 1) {
error("Duplicate " + typeLabel(executable) + " " + operationWithSameSignature.getSimpleSignature() + " in type " + inferredType.getSimpleName(), otherSource, nameFeature(otherSource), DUPLICATE_METHOD);
} else {
error("The " + typeLabel(executable) + " " + operationWithSameSignature.getSimpleSignature() + " has the same erasure " + operationWithSameSignature.getResolvedErasureSignature() + " as another " + typeLabel(executable) + " in type " + inferredType.getSimpleName(), otherSource, nameFeature(otherSource), DUPLICATE_METHOD);
}
}
}
}
}
}
}
}
}
Aggregations