protected boolean allPrimitiveVoid(final List<LightweightTypeReference> types) { boolean allVoid = true; for(LightweightTypeReference type: types) { if (!type.isPrimitiveVoid()) { allVoid = false; break; } } return allVoid; }
@Override public LightweightTypeReference setExpectedExpressionType(LightweightTypeReference expectedType) { final LightweightTypeReference old = this.expectedExpressionType; if (expectedType != null && expectedType.isPrimitiveVoid()) { this.expectedExpressionType = null; } else { this.expectedExpressionType = expectedType; } return old; }
/** * Primitive {@code void}, {@link AnyTypeReference any} and {@link UnknownTypeReference unknown} * types are not valid hints for {@link UnboundTypeReference#acceptHint(LightweightBoundTypeArgument) unbound references}. */ public boolean isValidHint() { return !isAny() && !isPrimitiveVoid(); }
protected LightweightTypeReference findConformsToAllOrVoid(final List<LightweightTypeReference> types) { for(LightweightTypeReference type: types) { LightweightTypeReference conformantType = conformsToAll(type, types); if (conformantType != null) return conformantType; if (type.isPrimitiveVoid()) { // we saw void but was not all were void return type; } } return null; }
@Override public boolean isVoid() { return this.getDelegate().isPrimitiveVoid(); }
protected boolean isPrimitiveVoid(XExpression xExpression) { LightweightTypeReference type = getLightweightType(xExpression); return type != null && type.isPrimitiveVoid(); }
@Override public boolean isPrimitiveVoid() { for(LightweightTypeReference component: expose(components)) { if (component.isPrimitiveVoid()) return true; } return false; }
@Override public boolean isPrimitiveVoid() { if (internalIsResolved()) { return resolvedTo.isPrimitiveVoid(); } return false; }
@Override public ITreeAppendable compile(XExpression expr, ITreeAppendable parentAppendable, LightweightTypeReference expectedReturnType, Set<JvmTypeReference> declaredExceptions) { // This function is redefined in order to take care about the SARL early exit statements // that are not Java early exit statements. // In this case, a Java "return" statement must be applied. final boolean isPrimitiveVoidExpected = expectedReturnType.isPrimitiveVoid(); if (!isPrimitiveVoidExpected && expr instanceof XBlockExpression) { this.isOnJavaEarlyExit = true; } return super.compile(expr, parentAppendable, expectedReturnType, declaredExceptions); }
protected LightweightTypeReference _internalFindReferencedInvalidType(final JvmField field) { final LightweightTypeReference type = this.toLightweightTypeReference(field.getType()); boolean _isPrimitiveVoid = type.isPrimitiveVoid(); if (_isPrimitiveVoid) { return type; } return this.findUnknownType(type); }
protected void accept(ObservableTypeExpectation expectation, LightweightTypeReference actual) { LightweightTypeReference expectedType = expectation.getExpectedType(); if (expectedType == null || actual instanceof AnyTypeReference || actual.isPrimitiveVoid()) { return; } resolveAgainstActualType(expectedType, actual, expectation.getState()); }
protected LightweightTypeReference getTypeForVariableDeclaration(XExpression expr) { IResolvedTypes resolvedTypes = getResolvedTypes(expr); LightweightTypeReference actualType = resolvedTypes.getActualType(expr); if (actualType.isPrimitiveVoid()) { LightweightTypeReference expectedType = resolvedTypes.getExpectedType(expr); if (expectedType == null) { expectedType = resolvedTypes.getExpectedReturnType(expr); if (expectedType == null) { expectedType = resolvedTypes.getReturnType(expr); } } if (expectedType != null && !expectedType.isPrimitiveVoid()) { actualType = expectedType; } } return actualType; }
@Override public LightweightTypeReference enhance(ParameterizedTypeReference reference) { LightweightTypeReference argumentType = owner.newParameterizedTypeReference((JvmType) feature); if (argumentType.isPrimitiveVoid()) { argumentType = owner.newReferenceTo(Void.class); } else { argumentType = argumentType.getWrapperTypeIfPrimitive(); } reference.addTypeArgument(argumentType); return reference; } });
@Override public boolean isImmutable(LightweightTypeReference type) { assert type != null; final LightweightTypeReference ref = type.getPrimitiveIfWrapperType(); if (ref.isArray()) { return false; } if (ref.isPrimitive() || ref.isPrimitiveVoid()) { return true; } for (final Class<?> jvmType : IMMUTABLE_TYPES) { if (type.isSubtypeOf(jvmType)) { return true; } } return false; }
@Check public void checkTypeReferenceIsNotVoid(XCasePart expression) { if (expression.getTypeGuard() != null) { if (toLightweightTypeReference(expression.getTypeGuard()).isPrimitiveVoid()) { error("Primitive void cannot be used here.", expression.getTypeGuard(), null, INVALID_USE_OF_TYPE); } } }
protected void initializeConstraintMapping(JvmTypeParameter typeParameter, UnboundTypeParameterPreservingSubstitutor substitutor, UnboundTypeReference typeReference) { if (!typeReference.internalIsResolved()) { List<JvmTypeConstraint> constraints = typeParameter.getConstraints(); for(JvmTypeConstraint constraint: constraints) { JvmTypeReference constraintReference = constraint.getTypeReference(); if (constraintReference != null) { LightweightTypeReference substitute = substitutor.substitute(constraintReference); if (!substitute.isType(Object.class) && !substitute.isPrimitiveVoid()) { typeReference.acceptHint(substitute, BoundTypeArgumentSource.CONSTRAINT, constraint, VarianceInfo.OUT, VarianceInfo.OUT); } } } } }
@Check public void checkVariableIsNotInferredAsVoid(XVariableDeclaration declaration) { if (declaration.getType() != null) return; LightweightTypeReference variableType = typeResolver.resolveTypes(declaration).getActualType((JvmIdentifiableElement) declaration); // TODO move to type resolver if (variableType != null && variableType.isPrimitiveVoid()) { error("void is an invalid type for the variable " + declaration.getName(), declaration, XbasePackage.Literals.XVARIABLE_DECLARATION__NAME, INVALID_USE_OF_TYPE); } }
@Check public void checkJUnitMethodReturnType(XtendFunction function) { JvmOperation operation = associations.getDirectlyInferredOperation(function); /* * Active annotations could also change the return type. * Checking that the JvmOperation really has a JUnit annotation. */ if(hasJUnitAnnotation(operation)) { LightweightTypeReference actualType = determineReturnType(operation); if(actualType !=null && !actualType.isUnknown() && !actualType.isPrimitiveVoid()) { String message = String.format("JUnit method %s() must be void but is %s.", function.getName(), actualType.getHumanReadableName()); EAttribute location = XTEND_FUNCTION__NAME; error(message, function, location, INVALID_RETURN_TYPE_IN_CASE_OF_JUNIT_ANNOTATION); } } }
protected LightweightTypeReference getResolvedReference(/* @Nullable */ JvmTypeReference unresolved) { ITypeReferenceOwner owner = getContextType().getOwner(); if (unresolved == null) { return owner.newReferenceToObject(); } LightweightTypeReference unresolvedLightweight = owner.toLightweightTypeReference(unresolved); if (unresolvedLightweight.isPrimitive() || unresolvedLightweight.isPrimitiveVoid()) return unresolvedLightweight; TypeParameterSubstitutor<?> substitutor = getSubstitutor(); LightweightTypeReference result = substitutor.substitute(unresolvedLightweight); return result; }
@Check protected void checkImplicitReturn(final XtendFunction method) { if (isIgnored(IMPLICIT_RETURN)) return; JvmOperation jvmOperation = associations.getDirectlyInferredOperation(method); IResolvedTypes types = batchTypeResolver.resolveTypes(method); if (jvmOperation != null && types.getActualType(jvmOperation).isPrimitiveVoid()) return; implicitReturnFinder.findImplicitReturns(method.getExpression(), new Acceptor() { @Override public void accept(XExpression implicitReturn) { if (method.getExpression() == implicitReturn) return; addIssue("Implicit return", implicitReturn, IMPLICIT_RETURN); } }); }