@Override public void reportError(Resource file, String message, String errorCode, Severity severity, String markerType) { EList<Diagnostic> errors = file.getErrors(); errors.add(new EObjectDiagnosticImpl(Severity.ERROR, markerType, message, null, null, -1, null)); }
/** * Added error indication to import declaration URI * * @param resource * zen model * @param importDeclaration * import declaration statement * @param message * error message */ private void addError(Resource resource, EObject importDeclaration, String message) { resource.getErrors().add(new EObjectDiagnosticImpl(Severity.ERROR, "", //$NON-NLS-1$ message, importDeclaration, RapidmlPackage.Literals.IMPORT_DECLARATION__IMPORT_URI, -1, null)); } }
@Override public void reportError(EObject ctx, String message, String errorCode, Severity severity, String markerType) { Resource resource = ctx.eResource(); if (resource != null) { EList<Diagnostic> errors = resource.getErrors(); errors.add(new EObjectDiagnosticImpl(Severity.ERROR, markerType, message, ctx, null, -1, null)); } }
private void checkTypeParameterNotAllowedAsLiteral(EObject ctx, JvmType type, ITypeComputationState state) { if (type instanceof JvmTypeParameter) { state.addDiagnostic(new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.INVALID_USE_OF_TYPE_PARAMETER, "Illegal class literal for the type parameter " + type.getSimpleName()+".", ctx, null, -1, new String[] { })); } }
@Override public void reportErrorNoLocation(EObject ctx, String message, String errorCode, Severity severity, String markerType) { Resource resource = ctx.eResource(); if (resource != null) { EList<Diagnostic> errors = resource.getErrors(); errors.add(new EObjectDiagnosticImpl(Severity.ERROR, markerType, message, resource.getContents().get(0), null, -1, null)); } }
@Override public boolean validate(IAcceptor<? super AbstractDiagnostic> result) { if (chosenCandidate.validate(result)) { StringBuilder messageBuilder = new StringBuilder("Suspiciously overloaded method.\n"); messageBuilder.append("The ").append(getFeatureTypeName()).append("\n\t"); appendCandidate(chosenCandidate, messageBuilder); messageBuilder.append("\noverloads the ").append(getFeatureTypeName()).append("\n\t"); appendCandidate(rejectedCandidate, messageBuilder); messageBuilder.append("."); AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(chosenCandidate.getSeverity(IssueCodes.SUSPICIOUSLY_OVERLOADED_FEATURE), IssueCodes.SUSPICIOUSLY_OVERLOADED_FEATURE, messageBuilder.toString(), getExpression(), XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, -1, null); result.accept(diagnostic); } return false; }
@Override protected JvmTypeReference handleReentrantInvocation(XComputedTypeReferenceImplCustom context) { resolvedTypes.addDiagnostic(new EObjectDiagnosticImpl( Severity.WARNING, IssueCodes.TOO_LITTLE_TYPE_INFORMATION, "Cannot infer type from recursive usage. Type 'Object' is used.", typeResolver.getSourceElement(operation), null, -1, null)); AnyTypeReference result = resolvedTypes.getReferenceOwner().newAnyTypeReference(); return typeResolver.toJavaCompliantTypeReference(result, session); } }
protected void checkValidReturn(XReturnExpression object, ITypeComputationState state) { // if the expectation comes from a method's return type // then it is legal, thus we must check if the return is // contained in a throw expression if (hasThrowableExpectation(state) && EcoreUtil2.getContainerOfType(object, XThrowExpression.class) != null) { state.addDiagnostic(new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.INVALID_RETURN, "Invalid return inside throw.", object, null, -1, new String[] { })); } }
public Object evaluate(final XExpression expression, final JvmTypeReference expectedType) { try { final Object result = this.interpreter.evaluate(expression, expectedType); return this.translate(result); } catch (final Throwable _t) { if (_t instanceof ConstantExpressionEvaluationException) { final ConstantExpressionEvaluationException e = (ConstantExpressionEvaluationException)_t; String _message = e.getMessage(); final EObjectDiagnosticImpl error = new EObjectDiagnosticImpl(Severity.ERROR, "constant_expression_evaluation_problem", _message, expression, null, (-1), null); expression.eResource().getErrors().add(error); return null; } else { throw Exceptions.sneakyThrow(_t); } } }
@Override protected JvmTypeReference handleReentrantInvocation(XComputedTypeReferenceImplCustom context) { EObject sourceElement = getSourceElement(member); EStructuralFeature feature = sourceElement.eClass().getEStructuralFeature("name"); resolvedTypes.addDiagnostic(new EObjectDiagnosticImpl( Severity.WARNING, IssueCodes.TOO_LITTLE_TYPE_INFORMATION, "Cannot infer type from recursive usage. Type 'Object' is used.", sourceElement, feature, -1, null)); AnyTypeReference result = resolvedTypes.getReferenceOwner().newAnyTypeReference(); return toJavaCompliantTypeReference(result, session); }
@Override /* @Nullable */ protected JvmTypeReference doGetTypeReference(XComputedTypeReferenceImplCustom context) { try { resolvedTypes.addDiagnostic(new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.TOO_LITTLE_TYPE_INFORMATION, "Cannot infer type", typeResolver.getSourceElement(member), null, -1, null)); return TypesFactory.eINSTANCE.createJvmAnyTypeReference(); } finally { context.unsetTypeProviderWithoutNotification(); } } }
@Override public void addError(final Element element, final String message) { this.checkCanceled(); this.checkValidationAllowed(); final Pair<Resource, EObject> resAndObj = this.getResourceAndEObject(element); EList<Resource.Diagnostic> _errors = resAndObj.getKey().getErrors(); EObject _value = resAndObj.getValue(); EStructuralFeature _significantFeature = this.getSignificantFeature(resAndObj.getValue()); EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.ERROR, "user.issue", message, _value, _significantFeature, (-1), null); _errors.add(_eObjectDiagnosticImpl); }
@Override public void addWarning(final Element element, final String message) { this.checkCanceled(); this.checkValidationAllowed(); final Pair<Resource, EObject> resAndObj = this.getResourceAndEObject(element); EList<Resource.Diagnostic> _warnings = resAndObj.getKey().getWarnings(); EObject _value = resAndObj.getValue(); EStructuralFeature _significantFeature = this.getSignificantFeature(resAndObj.getValue()); EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.WARNING, "user.issue", message, _value, _significantFeature, (-1), null); _warnings.add(_eObjectDiagnosticImpl); }
protected boolean validateVisibility(IAcceptor<? super AbstractDiagnostic> result) { if (!isVisible()) { String message = String.format("The %1$s %2$s%3$s is not visible", getFeatureTypeName(), getSimpleFeatureName(), getFeatureParameterTypesAsString()); AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.FEATURE_NOT_VISIBLE, message, getExpression(), getDefaultValidationFeature(), -1, null); result.accept(diagnostic); return false; } return true; }
protected boolean validateArity(IAcceptor<? super AbstractDiagnostic> result) { if (getArityMismatch() != 0) { String message; if (getArguments().isEmpty()) { message = String.format("Invalid number of arguments. The %1$s %2$s%3$s is not applicable without arguments" , getFeatureTypeName(), getSimpleFeatureName(), getFeatureParameterTypesAsString()); } else { message = String.format("Invalid number of arguments. The %1$s %2$s%3$s is not applicable for the arguments %4$s" , getFeatureTypeName(), getSimpleFeatureName(), getFeatureParameterTypesAsString(), getArgumentTypesAsString()); } AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.INVALID_NUMBER_OF_ARGUMENTS, message, getExpression(), getInvalidArgumentsValidationFeature(), -1, null); result.accept(diagnostic); return false; } return true; }
protected boolean validateTypeArity(IAcceptor<? super AbstractDiagnostic> result) { if (getTypeArityMismatch() != 0) { String message = String.format("Invalid number of type arguments. The %1$s %2$s%3$s is not applicable for the type arguments %4$s", getFeatureTypeName(), getSimpleFeatureName(), getFeatureTypeParametersAsString(true), getTypeArgumentsAsString(getSyntacticTypeArguments())); AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.INVALID_NUMBER_OF_TYPE_ARGUMENTS, message, getExpression(), getDefaultValidationFeature(), -1, null); result.accept(diagnostic); return false; } return true; }
@Override public boolean validate(IAcceptor<? super AbstractDiagnostic> result) { JvmDeclaredType declaringType = getConstructor().getDeclaringType(); if (declaringType.isAbstract()) { String message = "Cannot instantiate the abstract type " + declaringType.getSimpleName(); AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.ABSTRACT_CLASS_INSTANTIATION, message, getExpression(), getDefaultValidationFeature(), -1, null); result.accept(diagnostic); return false; } return super.validate(result); }
@Override public boolean validate(IAcceptor<? super AbstractDiagnostic> result) { if (!getState().isInstanceContext()) { JvmIdentifiableElement implicitFeature = getFeature(); if (implicitFeature instanceof JvmType) { JvmIdentifiableElement feature = getState().getResolvedTypes().getLinkedFeature(getOwner()); if (feature == null || feature.eIsProxy() || !(feature instanceof JvmFeature)) return true; String message = "Cannot make an implicit reference to this from a static context"; AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.STATIC_ACCESS_TO_INSTANCE_MEMBER, message, getOwner(), XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, -1, null); result.accept(diagnostic); return false; } } return super.validate(result); }
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()); }
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); }