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

The following examples show how to use org.eclipse.emf.common.util.Diagnostic#getChildren() . 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: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void diagnose(Diagnostic diagnostic, URI[] expectedUnresolvedProxies) {
	if (diagnostic.getChildren().isEmpty()) {
		if (diagnostic.getSeverity() != Diagnostic.OK) {
			if (diagnostic.getCode() == EObjectValidator.EOBJECT__EVERY_PROXY_RESOLVES) {
				EObject proxy = (EObject) diagnostic.getData().get(2); // magic number ...
				if (org.eclipse.xtext.util.Arrays.contains(expectedUnresolvedProxies, EcoreUtil.getURI(proxy))) {
					return;
				}
			}
			assertEquals(String.valueOf(diagnostic), diagnostic.getSeverity() == Diagnostic.OK);
		}
	} else {
		for (Diagnostic child : diagnostic.getChildren()) {
			diagnose(child, expectedUnresolvedProxies);
		}
	}
}
 
Example 2
Source File: ExporterProcessor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Validates a object instance and its children using the EMF core validator
 * API.
 *
 * @param element
 *            the element to validate
 * @param label
 *            the type label of the element
 * @throws IllegalStateException
 *             if validation errors are encountered
 */
protected static void validateDevice ( final EObject object, final String label )
{
    final Diagnostic diag = Diagnostician.INSTANCE.validate ( object );
    if ( diag.getSeverity () == Diagnostic.ERROR )
    {
        final StringBuilder sb = new StringBuilder ( "Invalid " + label );
        for ( final Diagnostic child : diag.getChildren () )
        {
            if ( child.getSeverity () == Diagnostic.ERROR )
            {
                sb.append ( System.lineSeparator () );
                sb.append ( child.getMessage () );
            }
        }
        throw new IllegalStateException ( sb.toString () );
    }
}
 
Example 3
Source File: AssertableDiagnostics.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected void printDiagnostic(StringBuffer out, String prefix, Diagnostic d) {
	final String indent = "  ";
	out.append(prefix);
	out.append(d);
	if (d.getChildren().size() > 0 || d.getException() != null) {
		out.append(" {\n");
		String prefix2 = prefix + indent;
		if (d.getException() != null) {
			out.append(prefix2);
			ByteArrayOutputStream s = new ByteArrayOutputStream();
			PrintWriter pw = new PrintWriter(s);
			d.getException().printStackTrace(pw);
			pw.flush();
			out.append(s.toString());
			out.append("\n");
		}
		for (Diagnostic c : d.getChildren())
			printDiagnostic(out, prefix2, c);
		out.append(prefix);
		out.append("}\n");
	} else
		out.append("\n");
}
 
Example 4
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void propageValidationResult(Diagnostic diagnostic, GeneratedMetamodel metamodel, ValidationMessageAcceptor acceptor) {
	if (diagnostic.getSeverity() != Diagnostic.OK) {
		if (diagnostic.getCode() != 0) {
			List<?> data = diagnostic.getData();
			if (!data.isEmpty() && data.get(0) instanceof EObject) {
				doPropagateValidationResult(diagnostic, metamodel, acceptor);
			}
		}
		for(Diagnostic child: diagnostic.getChildren())
			propageValidationResult(child, metamodel, acceptor);
	}
}
 
Example 5
Source File: ArduinoExample.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * Prints diagnostics with indentation.
 * <!-- end-user-doc -->
 * @param diagnostic the diagnostic to print.
 * @param indent the indentation for printing.
 * @generated
 */
protected static void printDiagnostic ( Diagnostic diagnostic, String indent )
{
    System.out.print ( indent );
    System.out.println ( diagnostic.getMessage () );
    for ( Diagnostic child : diagnostic.getChildren () )
    {
        printDiagnostic ( child, indent + "  " ); //$NON-NLS-1$
    }
}
 
Example 6
Source File: SecurityExample.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * Prints diagnostics with indentation.
 * <!-- end-user-doc -->
 * @param diagnostic the diagnostic to print.
 * @param indent the indentation for printing.
 * @generated
 */
protected static void printDiagnostic ( Diagnostic diagnostic, String indent )
{
    System.out.print ( indent );
    System.out.println ( diagnostic.getMessage () );
    for ( Diagnostic child : diagnostic.getChildren () )
    {
        printDiagnostic ( child, indent + "  " ); //$NON-NLS-1$
    }
}
 
Example 7
Source File: MemoryManagerExample.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * Prints diagnostics with indentation.
 * <!-- end-user-doc -->
 * @param diagnostic the diagnostic to print.
 * @param indent the indentation for printing.
 * @generated
 */
protected static void printDiagnostic ( Diagnostic diagnostic, String indent )
{
    System.out.print ( indent );
    System.out.println ( diagnostic.getMessage () );
    for ( Diagnostic child : diagnostic.getChildren () )
    {
        printDiagnostic ( child, indent + "  " ); //$NON-NLS-1$
    }
}
 
Example 8
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testExplicitOverride02() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
			"terminal ID: ('a'..'z'|'A'..'Z'|'_');");
	Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
	List<Diagnostic> issues = diag.getChildren();
	assertEquals(issues.toString(), 1, issues.size());
	assertEquals("This rule overrides ID in org.eclipse.xtext.common.Terminals and thus should be annotated with @Override.", issues.get(0).getMessage());
	assertEquals("diag.isWarning", diag.getSeverity(), Diagnostic.WARNING);
}
 
Example 9
Source File: ExecComponentsExample.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * Prints diagnostics with indentation.
 * <!-- end-user-doc -->
 * @param diagnostic the diagnostic to print.
 * @param indent the indentation for printing.
 * @generated
 */
protected static void printDiagnostic ( Diagnostic diagnostic, String indent )
{
    System.out.print ( indent );
    System.out.println ( diagnostic.getMessage () );
    for ( Diagnostic child : diagnostic.getChildren () )
    {
        printDiagnostic ( child, indent + "  " ); //$NON-NLS-1$
    }
}
 
Example 10
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testExplicitOverride05() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar\n" +
			"import \"http://www.eclipse.org/emf/2002/Ecore\" as ecore" +
			"@Override\n" +
			"terminal ID: ('a'..'z'|'A'..'Z'|'_');");
	Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
	List<Diagnostic> issues = diag.getChildren();
	assertEquals(issues.toString(), 1, issues.size());
	assertEquals("This grammar has no super grammar and therefore cannot override any rules.", issues.get(0).getMessage());
	assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
 
Example 11
Source File: MemoryExample.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * Prints diagnostics with indentation.
 * <!-- end-user-doc -->
 * @param diagnostic the diagnostic to print.
 * @param indent the indentation for printing.
 * @generated
 */
protected static void printDiagnostic ( Diagnostic diagnostic, String indent )
{
    System.out.print ( indent );
    System.out.println ( diagnostic.getMessage () );
    for ( Diagnostic child : diagnostic.getChildren () )
    {
        printDiagnostic ( child, indent + "  " );
    }
}
 
Example 12
Source File: AbstractBodyParser.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the {@link List} of {@link TemplateValidationMessage} from the given {@link Diagnostic}.
 * 
 * @param diagnostic
 *            the {@link Diagnostic}
 * @param queryText
 *            the query text
 * @param location
 *            the location of the {@link TemplateValidationMessage}
 * @return the {@link List} of {@link TemplateValidationMessage} from the given {@link Diagnostic}
 */
protected List<TemplateValidationMessage> getValidationMessage(Diagnostic diagnostic, String queryText,
        XWPFRun location) {
    final List<TemplateValidationMessage> res = new ArrayList<>();

    for (Diagnostic child : diagnostic.getChildren()) {
        final ValidationMessageLevel level;
        switch (diagnostic.getSeverity()) {
            case Diagnostic.INFO:
                level = ValidationMessageLevel.INFO;
                break;

            case Diagnostic.WARNING:
                level = ValidationMessageLevel.WARNING;
                break;

            case Diagnostic.ERROR:
                level = ValidationMessageLevel.ERROR;
                break;

            default:
                level = ValidationMessageLevel.INFO;
                break;
        }
        res.add(new TemplateValidationMessage(level,
                message(ParsingErrorMessage.INVALIDEXPR, queryText, child.getMessage()), location));
        res.addAll(getValidationMessage(child, queryText, location));
    }

    return res;
}
 
Example 13
Source File: ComponentExample.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * Prints diagnostics with indentation.
 * <!-- end-user-doc -->
 * @param diagnostic the diagnostic to print.
 * @param indent the indentation for printing.
 * @generated
 */
protected static void printDiagnostic ( Diagnostic diagnostic, String indent )
{
    System.out.print ( indent );
    System.out.println ( diagnostic.getMessage () );
    for ( Diagnostic child : diagnostic.getChildren () )
    {
        printDiagnostic ( child, indent + "  " ); //$NON-NLS-1$
    }
}
 
Example 14
Source File: JdbcExample.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * Prints diagnostics with indentation.
 * <!-- end-user-doc -->
 * @param diagnostic the diagnostic to print.
 * @param indent the indentation for printing.
 * @generated
 */
protected static void printDiagnostic ( Diagnostic diagnostic, String indent )
{
    System.out.print ( indent );
    System.out.println ( diagnostic.getMessage () );
    for ( Diagnostic child : diagnostic.getChildren () )
    {
        printDiagnostic ( child, indent + "  " ); //$NON-NLS-1$
    }
}
 
Example 15
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void diagnose(Diagnostic diagnostic) {
	if (diagnostic.getChildren().isEmpty()) {
		assertEquals(String.valueOf(diagnostic), diagnostic.getSeverity() == Diagnostic.OK);
	} else {
		for (Diagnostic child : diagnostic.getChildren()) {
			diagnose(child);
		}
	}
}
 
Example 16
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void diagnose(Diagnostic diagnostic) {
	if (diagnostic.getChildren().isEmpty()) {
		assertEquals(String.valueOf(diagnostic), diagnostic.getSeverity() == Diagnostic.OK);
	} else {
		for (Diagnostic child : diagnostic.getChildren()) {
			diagnose(child);
		}
	}
}
 
Example 17
Source File: ParserExample.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * Prints diagnostics with indentation.
 * <!-- end-user-doc -->
 * @param diagnostic the diagnostic to print.
 * @param indent the indentation for printing.
 * @generated
 */
protected static void printDiagnostic ( Diagnostic diagnostic, String indent )
{
    System.out.print ( indent );
    System.out.println ( diagnostic.getMessage () );
    for ( Diagnostic child : diagnostic.getChildren () )
    {
        printDiagnostic ( child, indent + "  " ); //$NON-NLS-1$
    }
}
 
Example 18
Source File: AbstractValidationTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Assert that diagnosticList contains a diagnostic of the given issueCode.
 *
 * @param diagnostics
 *          the diagnostic to check for issues
 * @param issueCode
 *          the code of the issue to look for
 */
private void assertDiagnostic(final Diagnostic diagnostics, final String issueCode) {
  for (Diagnostic diagnostic : diagnostics.getChildren()) {
    if (diagnostic instanceof AbstractValidationDiagnostic && ((AbstractValidationDiagnostic) diagnostic).getIssueCode().equals(issueCode)) {
      return;
    }
  }
  fail("Issue with code '" + issueCode + "' not found");
}
 
Example 19
Source File: CrossflowExample.java    From scava with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * Prints diagnostics with indentation.
 * <!-- end-user-doc -->
 * @param diagnostic the diagnostic to print.
 * @param indent the indentation for printing.
 * @generated
 */
protected static void printDiagnostic(Diagnostic diagnostic, String indent) {
	System.out.print(indent);
	System.out.println(diagnostic.getMessage());
	for (Diagnostic child : diagnostic.getChildren()) {
		printDiagnostic(child, indent + "  ");
	}
}
 
Example 20
Source File: AbstractValidationTest.java    From dsl-devkit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Assert that diagnosticList contains a diagnostic of the given issueCode on a given EObject.
 * For performance reasons one can validate the root object and afterwards use this method
 * to check that a particular diagnostic exists on one of the child objects of the validated model.
 *
 * @param diagnostics
 *          the diagnostic to check for issues
 * @param targetObject
 *          the object that should have a diagnostic with the given issueCode
 * @param issueCode
 *          the code of the issue to look for
 */
protected void assertDiagnosticOnObject(final Diagnostic diagnostics, final EObject targetObject, final String issueCode) {
  for (Diagnostic diagnostic : diagnostics.getChildren()) {
    if (diagnostic instanceof AbstractValidationDiagnostic) {
      AbstractValidationDiagnostic avd = (AbstractValidationDiagnostic) diagnostic;
      if (avd.getSourceEObject() == targetObject && avd.getIssueCode().equals(issueCode)) {
        return;
      }
    }
  }
  fail("Issue with code '" + issueCode + "' not found");
}