protected String canonicalName(LightweightTypeReference typeRef) { return (typeRef == null) ? "<null>" : typeRef.getHumanReadableName(); }
protected String referenceToString(LightweightTypeReference reference) { if (reference == null) { return "[null]"; } if (reference.isAny()) { return "Object"; } return reference.getHumanReadableName(); }
/** * Returns the resolved string representation of the type arguments. The simple names of * the types are used. The string representation includes the angle brackets. */ protected String getTypeArgumentsAsString(List<? extends LightweightTypeReference> typeArguments) { if(!typeArguments.isEmpty()) { StringBuilder b = new StringBuilder(); b.append("<"); for(int i=0; i<typeArguments.size(); ++i) { b.append(typeArguments.get(i).getHumanReadableName()); if(i < typeArguments.size()-1) b.append(", "); } b.append(">"); return b.toString(); } return ""; }
protected String getFeatureParameterTypesAsString(JvmExecutable executable) { ITypeReferenceOwner referenceOwner = getState().getReferenceOwner(); List<JvmFormalParameter> parameters = executable.getParameters(); StringBuilder b = new StringBuilder(); b.append("("); for(int i=0; i<parameters.size(); ++i) { JvmTypeReference parameterType = parameters.get(i).getParameterType(); LightweightTypeReference typeReference = referenceOwner.toLightweightTypeReference(parameterType); b.append(typeReference.getHumanReadableName()); if(i < parameters.size()-1) b.append(", "); } b.append(")"); return b.toString(); }
protected AbstractDiagnostic createTypeDiagnostic(XExpression expression, LightweightTypeReference actualType, LightweightTypeReference expectedType) { if (!expectedType.isAny()) { String actualName = actualType.getSimpleName(); String expectedName = expectedType.getSimpleName(); if (actualName.equals(expectedName)) { if (expectedType.isAssignableFrom(actualType)) { return null; } } if (expression.eContainingFeature() == XbasePackage.Literals.XABSTRACT_FEATURE_CALL__IMPLICIT_FIRST_ARGUMENT) { return new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.INCOMPATIBLE_TYPES, String.format( "Type mismatch: cannot convert implicit first argument from %s to %s", actualType.getHumanReadableName(), expectedType.getHumanReadableName()), expression, null, -1, null); } else { return new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.INCOMPATIBLE_TYPES, String.format( "Type mismatch: cannot convert from %s to %s", actualType.getHumanReadableName(), expectedType.getHumanReadableName()), expression, null, -1, null); } } else { return new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.INCOMPATIBLE_TYPES, String.format( "Type mismatch: type %s is not applicable at this location", actualType.getHumanReadableName()), expression, null, -1, null); } }
@Override protected String getSimpleFeatureName() { return getActualType(getFeature(), true).getHumanReadableName(); }
protected void checkValidExtensionType(JvmIdentifiableElement identifiable, EObject source, EStructuralFeature feature) { LightweightTypeReference type = getActualType(identifiable); if (type != null && type.isPrimitive()) { error(String.format("The primitive type %s is not a valid extension", type.getHumanReadableName()), source, feature, INVALID_EXTENSION_TYPE); } }
/** * Returns the resolved string representation of the argument types. The simple names of * the types are used. The string representation includes the parenthesis. */ protected String getArgumentTypesAsString() { if(!getArguments().isEmpty()) { StringBuilder b = new StringBuilder(); b.append("("); for(int i=0; i<getArguments().size(); ++i) { LightweightTypeReference actualType = getActualType(getArguments().get(i)); if(actualType != null) b.append(actualType.getHumanReadableName()); else b.append("null"); if(i < getArguments().size()-1) b.append(","); } b.append(")"); return b.toString(); } return ""; }
if (right > left) { StringBuilder message = new StringBuilder("The caught "); message.append(rightRef.getHumanReadableName()); message.append("is redundant"); error(message.toString(), references.get(right), null, IssueCodes.INVALID_MULTITYPE_PART); message.append(rightRef.getHumanReadableName()); message.append(" is already covered by the caught "); message.append(leftRef.getHumanReadableName()); error(message.toString(), references.get(right), null, IssueCodes.INVALID_MULTITYPE_PART);
if (((returnType != null) && (returnType.getSimpleName() != null))) { labelBuilder.append(" : "); labelBuilder.append(converter.toLightweightReference(returnType).getHumanReadableName()); descriptionBuilder.append(converter.toPlainTypeReference(((JvmOperation)feature).getDeclaringType()).getHumanReadableName()); if ((!withParents)) { descriptionBuilder.append("."); boolean _tripleNotEquals = (_type != null); if (_tripleNotEquals) { final String fieldType = converter.toLightweightReference(((JvmField)feature).getType()).getHumanReadableName(); if ((fieldType != null)) { labelBuilder.append(fieldType); descriptionBuilder.append(converter.toPlainTypeReference(((JvmField)feature).getDeclaringType()).getHumanReadableName()); } else { if ((feature instanceof JvmConstructor)) {
protected void appendParameters(final StringBuilder result, final JvmExecutable executable, final int insignificantParameters, final LightweightTypeReferenceFactory ownedConverter) { final EList<JvmFormalParameter> declaredParameters = executable.getParameters(); final List<JvmFormalParameter> relevantParameters = declaredParameters.subList(Math.min(insignificantParameters, declaredParameters.size()), declaredParameters.size()); for (int i = 0; (i < relevantParameters.size()); i++) { { final JvmFormalParameter parameter = relevantParameters.get(i); if ((i != 0)) { result.append(", "); } if ((((i == (relevantParameters.size() - 1)) && executable.isVarArgs()) && (parameter.getParameterType() instanceof JvmGenericArrayTypeReference))) { JvmTypeReference _parameterType = parameter.getParameterType(); final JvmGenericArrayTypeReference parameterType = ((JvmGenericArrayTypeReference) _parameterType); result.append(ownedConverter.toLightweightReference(parameterType.getComponentType()).getHumanReadableName()); result.append("..."); } else { JvmTypeReference _parameterType_1 = parameter.getParameterType(); boolean _tripleNotEquals = (_parameterType_1 != null); if (_tripleNotEquals) { final String simpleName = ownedConverter.toLightweightReference(parameter.getParameterType()).getHumanReadableName(); if ((simpleName != null)) { result.append(simpleName); } } } result.append(" "); result.append(String.valueOf(parameter.getName())); } } }
b.append(typeRef.getHumanReadableName());
@Check public void checkTypes(XCatchClause catchClause) { LightweightTypeReference parameterType = getActualType(catchClause, catchClause.getDeclaredParam()); if (parameterType != null && !parameterType.isSubtypeOf(Throwable.class)) { error("No exception of type " + parameterType.getHumanReadableName() + " can be thrown; an exception type must be a subclass of Throwable", catchClause.getDeclaredParam(), TypesPackage.Literals.JVM_FORMAL_PARAMETER__PARAMETER_TYPE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INCOMPATIBLE_TYPES); } }
@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); } } }
unhandledExceptions.get(count - 1)); } else { message = String.format("Unhandled exception type %s", unhandledExceptions.get(0).getHumanReadableName());
protected void _computeTypes(XInstanceOfExpression object, ITypeComputationState state) { ITypeComputationState expressionState = state.withExpectation(state.getReferenceOwner().newReferenceToObject()); expressionState.computeTypes(object.getExpression()); JvmTypeReference type = object.getType(); if (type != null && type.getType() instanceof JvmTypeParameter) { LightweightTypeReference lightweightReference = state.getReferenceOwner().toLightweightTypeReference(type); LightweightTypeReference rawTypeRef = lightweightReference.getRawTypeReference(); state.addDiagnostic(new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.INVALID_USE_OF_TYPE_PARAMETER, "Cannot perform instanceof check against type parameter "+lightweightReference.getHumanReadableName()+". Use its erasure "+rawTypeRef.getHumanReadableName()+" instead since further generic type information will be erased at runtime.", object.getType(), null, -1, new String[] { })); } LightweightTypeReference bool = getRawTypeForName(Boolean.TYPE, state); state.acceptActualType(bool); }
if(leftType != null) { if (leftType.isPrimitive()) { error("The operator '" + operatorSymbol + "' is undefined for the argument types " + leftType.getHumanReadableName() + " and null", binaryOperation, null, PRIMITIVE_COMPARED_TO_NULL); } else if (equalsComparison) { addIssue("The operator '" + operatorSymbol + "' should be replaced by '" + operatorSymbol + "=' when null is one of the arguments.", binaryOperation, XbasePackage.eINSTANCE.getXAbstractFeatureCall_Feature(), EQUALS_WITH_NULL, operatorSymbol); if(rightType != null) { if (rightType.isPrimitive()) { error("The operator '" + operatorSymbol + "' is undefined for the argument types null and " + rightType.getHumanReadableName(), binaryOperation, null, PRIMITIVE_COMPARED_TO_NULL); } else if (equalsComparison && !(right instanceof XNullLiteral)) { addIssue("The operator '" + operatorSymbol + "' should be replaced by '" + operatorSymbol + "=' when null is one of the arguments.", binaryOperation, XbasePackage.eINSTANCE.getXAbstractFeatureCall_Feature(), EQUALS_WITH_NULL, operatorSymbol); LightweightTypeReference leftType = getActualType(left); if(leftType.isPrimitive()) error("The operator '" + operatorSymbol + "' is undefined for arguments of type " + leftType.getHumanReadableName(), binaryOperation, null, PRIMITIVE_COMPARED_TO_NULL); error("The operator '" + operatorSymbol + "' is undefined for arguments of type " + leftType.getHumanReadableName(), binaryOperation, null, PRIMITIVE_COMPARED_TO_NULL);
@Check public void checkOperandTypesForTripleEquals(XBinaryOperation binaryOperation) { if(isTripleEqualsOperation(binaryOperation)){ LightweightTypeReference left = getActualType(binaryOperation.getLeftOperand()); LightweightTypeReference right = getActualType(binaryOperation.getRightOperand()); if(left.isArray() != right.isArray()) { if (left.isArray()) { if (right.isAny() || right.isType(Object.class) || right.isType(Serializable.class) || right.isType(Cloneable.class)) { return; } } else { if (left.isAny() || left.isType(Object.class) || left.isType(Serializable.class) || left.isType(Cloneable.class)) { return; } } error("Incompatible operand types " + left.getHumanReadableName() + " and " + right.getHumanReadableName(), null, INVALID_OPERAND_TYPES); } } }
protected void _computeTypes(XSynchronizedExpression expr, ITypeComputationState state) { ITypeComputationState paramState = state.withExpectation(state.getReferenceOwner().newReferenceToObject()); ITypeComputationResult paramType = paramState.computeTypes(expr.getParam()); LightweightTypeReference actualParamType = paramType.getActualExpressionType(); if (actualParamType != null && (actualParamType.isPrimitive() || actualParamType.isAny())) { state.addDiagnostic(new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.INCOMPATIBLE_TYPES, actualParamType.getHumanReadableName() + " is not a valid type's argument for the synchronized expression.", expr.getParam(), null, -1, new String[] { })); } state.computeTypes(expr.getExpression()); }
@Check public void checkReturn(XReturnExpression expr) { XExpression returnedExpression = expr.getExpression(); IResolvedTypes resolvedTypes = typeResolver.resolveTypes(expr); LightweightTypeReference expectedReturnType = resolvedTypes.getExpectedReturnType(expr); if (expectedReturnType == null) { return; } if (expectedReturnType.isPrimitiveVoid()) { if (returnedExpression != null) error("Void functions cannot return a value.", expr, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_RETURN); } else { if (returnedExpression == null) error("The function must return a result of type " + expectedReturnType.getHumanReadableName() + ".", expr, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_RETURN); else { LightweightTypeReference expressionType = getActualType(returnedExpression); if (expressionType.isPrimitiveVoid()) { error("Incompatible types. Expected " + getNameOfTypes(expectedReturnType) + " but was " + canonicalName(expressionType), returnedExpression, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INCOMPATIBLE_TYPES); } } } }