Java Code Examples for org.eclipse.emf.common.util.Diagnostic#getMessage()

The following examples show how to use org.eclipse.emf.common.util.Diagnostic#getMessage() . 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: ModbusExporterProcessor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Validates a ModbusExporterDevice instance using the EMF core validator
 * API. The
 * contained ModbusExporterItems are also validated.
 * 
 * @param device
 *            the ModbusExporterDevice to validate
 * @throws IllegalStateException
 *             if validation errors are encountered
 */
private void validateDevice ( final ModbusExporterDevice device )
{
    // Also validates contained ModbusExporterItems
    final Diagnostic diag = Diagnostician.INSTANCE.validate ( device );
    if ( diag.getSeverity () == Diagnostic.ERROR )
    {
        String msg = "Invalid Modbus Exporter Device";
        for ( final Diagnostic child : diag.getChildren () )
        {
            if ( child.getSeverity () == Diagnostic.ERROR )
            {
                msg += "\n" + child.getMessage (); //$NON-NLS-1$
            }
        }
        throw new IllegalStateException ( msg );
    }
}
 
Example 2
Source File: M2DocUtils.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the given {@link Diagnostic} {@link Diagnostic#getMessage() message} and {@link Diagnostic#getException() exception}.
 * 
 * @param diagnostic
 *            the {@link Diagnostic}
 * @return the given {@link Diagnostic} {@link Diagnostic#getMessage() message} and {@link Diagnostic#getException() exception}
 */
private static String getMessageWithException(Diagnostic diagnostic) {
    String res;

    final Throwable exception;
    if (diagnostic.getException() != null) {
        exception = diagnostic.getException().getCause();
    } else {
        exception = null;
    }
    if (exception != null) {
        try (ByteArrayOutputStream out = new ByteArrayOutputStream();
                PrintWriter printWriter = new PrintWriter(out);) {
            exception.printStackTrace(printWriter);
            printWriter.flush();
            out.flush();
            res = diagnostic.getMessage() + "\n" + new String(out.toByteArray());
        } catch (IOException e) {
            // nothing to do here
            res = diagnostic.getMessage();
        }
    } else {
        res = diagnostic.getMessage();
    }

    return res;
}
 
Example 3
Source File: AssertableDiagnostics.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean apply(Diagnostic d) {
	if (severity != null && d.getSeverity() != severity)
		return false;
	if (code != null && !code.equals(d.getCode()))
		return false;
	if (issueCode != null && d instanceof AbstractValidationDiagnostic
			&& !((AbstractValidationDiagnostic) d).getIssueCode().equals(issueCode))
		return false;
	if (msg != null && d.getMessage() != null && !d.getMessage().contains(msg))
		return false;
	return true;
}
 
Example 4
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public boolean createMessageForSource(Diagnostic diagnostic, EObject object, ValidationMessageAcceptor acceptor) {
	String code = XtextValidator.class.getName() + ".PackageValidation." + diagnostic.getCode();
	int severity = diagnostic.getSeverity();
	if (diagnostic.getCode() == EcoreValidator.UNIQUE_CLASSIFIER_NAMES || diagnostic.getCode() == EcoreValidator.UNIQUE_FEATURE_NAMES)
		severity = Diagnostic.ERROR;
	String message = diagnostic.getMessage();
	return createMessageForSource(message, code, severity, object, acceptor);
}
 
Example 5
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void doCreateMessage(Diagnostic diagnostic, EObject object, EStructuralFeature feature, ValidationMessageAcceptor acceptor) {
	String code = XtextValidator.class.getName() + ".PackageValidation." + diagnostic.getCode();
	int severity = diagnostic.getSeverity();
	if (diagnostic.getCode() == EcoreValidator.UNIQUE_CLASSIFIER_NAMES || diagnostic.getCode() == EcoreValidator.UNIQUE_FEATURE_NAMES)
		severity = Diagnostic.ERROR;
	String message = diagnostic.getMessage();
	doCreateMessage(message, code, severity, object, feature, acceptor);
}
 
Example 6
Source File: AssertableDiagnostics.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean apply(Diagnostic d) {
	if (severity != null && d.getSeverity() != severity)
		return false;
	if (code != null && !code.equals(d.getCode()))
		return false;
	if (issueCode != null && d instanceof AbstractValidationDiagnostic
			&& !((AbstractValidationDiagnostic) d).getIssueCode().equals(issueCode))
		return false;
	if (msg != null && d.getMessage() != null && !d.getMessage().contains(msg))
		return false;
	return true;
}