Search in sources :

Example 81 with Diagnostic

use of org.eclipse.emf.common.util.Diagnostic in project iobserve-analysis by research-iobserve.

the class systemadaptationEditor method createModel.

/**
 * This is the method called to load a resource into the editing domain's resource set based on the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void createModel() {
    URI resourceURI = EditUIUtil.getURI(getEditorInput(), editingDomain.getResourceSet().getURIConverter());
    Exception exception = null;
    Resource resource = null;
    try {
        // Load the resource through the editing domain.
        // 
        resource = editingDomain.getResourceSet().getResource(resourceURI, true);
    } catch (Exception e) {
        exception = e;
        resource = editingDomain.getResourceSet().getResource(resourceURI, false);
    }
    Diagnostic diagnostic = analyzeResourceProblems(resource, exception);
    if (diagnostic.getSeverity() != Diagnostic.OK) {
        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
    }
    editingDomain.getResourceSet().eAdapters().add(problemIndicationAdapter);
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) Diagnostic(org.eclipse.emf.common.util.Diagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) URI(org.eclipse.emf.common.util.URI) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException)

Example 82 with Diagnostic

use of org.eclipse.emf.common.util.Diagnostic in project iobserve-analysis by research-iobserve.

the class systemadaptationExample method printDiagnostic.

/**
 * <!-- 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 + "  ");
    }
}
Also used : Diagnostic(org.eclipse.emf.common.util.Diagnostic)

Example 83 with Diagnostic

use of org.eclipse.emf.common.util.Diagnostic in project iobserve-analysis by research-iobserve.

the class cloudprofileExample method printDiagnostic.

/**
 * <!-- 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 + "  ");
    }
}
Also used : Diagnostic(org.eclipse.emf.common.util.Diagnostic)

Example 84 with Diagnostic

use of org.eclipse.emf.common.util.Diagnostic in project iobserve-analysis by research-iobserve.

the class cloudprofileExample method main.

/**
 * <!-- begin-user-doc -->
 * Load all the argument file paths or URIs as instances of the model.
 * <!-- end-user-doc -->
 * @param args the file paths or URIs.
 * @generated
 */
public static void main(String[] args) {
    // Create a resource set to hold the resources.
    // 
    ResourceSet resourceSet = new ResourceSetImpl();
    // Register the appropriate resource factory to handle all file extensions.
    // 
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new cloudprofileResourceFactoryImpl());
    // Register the package to ensure it is available during loading.
    // 
    resourceSet.getPackageRegistry().put(cloudprofilePackage.eNS_URI, cloudprofilePackage.eINSTANCE);
    // 
    if (args.length == 0) {
        System.out.println("Enter a list of file paths or URIs that have content like this:");
        try {
            Resource resource = resourceSet.createResource(URI.createURI("http:///My.cloudprofile"));
            CloudProfile root = cloudprofileFactory.eINSTANCE.createCloudProfile();
            resource.getContents().add(root);
            resource.save(System.out, null);
        } catch (IOException exception) {
            exception.printStackTrace();
        }
    } else {
        // 
        for (int i = 0; i < args.length; ++i) {
            // Construct the URI for the instance file.
            // The argument is treated as a file path only if it denotes an existing file.
            // Otherwise, it's directly treated as a URL.
            // 
            File file = new File(args[i]);
            URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()) : URI.createURI(args[i]);
            try {
                // Demand load resource for this file.
                // 
                Resource resource = resourceSet.getResource(uri, true);
                System.out.println("Loaded " + uri);
                // 
                for (EObject eObject : resource.getContents()) {
                    Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
                    if (diagnostic.getSeverity() != Diagnostic.OK) {
                        printDiagnostic(diagnostic, "");
                    }
                }
            } catch (RuntimeException exception) {
                System.out.println("Problem loading " + uri);
                exception.printStackTrace();
            }
        }
    }
}
Also used : CloudProfile(org.iobserve.planning.cloudprofile.CloudProfile) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Diagnostic(org.eclipse.emf.common.util.Diagnostic) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) File(java.io.File) URI(org.eclipse.emf.common.util.URI) org.iobserve.planning.cloudprofile.util.cloudprofileResourceFactoryImpl(org.iobserve.planning.cloudprofile.util.cloudprofileResourceFactoryImpl)

Example 85 with Diagnostic

use of org.eclipse.emf.common.util.Diagnostic in project statecharts by Yakindu.

the class STextJavaValidatorTest method checkNoAssignmentInGuard.

@Test
public void checkNoAssignmentInGuard() {
    String scope = "internal: var myInt : integer var myBool : boolean = true";
    EObject expression = super.parseExpression("[myBool = false]", ReactionTrigger.class.getSimpleName(), scope);
    AssertableDiagnostics validationResult = tester.validate(expression);
    validationResult.assertErrorContains(STextJavaValidator.GUARD_CONTAINS_ASSIGNMENT);
    expression = super.parseExpression("[myInt = 5]", ReactionTrigger.class.getSimpleName(), scope);
    validationResult = tester.validate(expression);
    Iterator<Diagnostic> diag = validationResult.getAllDiagnostics().iterator();
    while (diag.hasNext()) {
        Diagnostic d = diag.next();
        if (d.getMessage().equals(GUARD_EXPRESSION)) {
            assertEquals(STextJavaValidator.GUARD_EXPRESSION, d.getMessage());
        } else {
            assertEquals(STextJavaValidator.GUARD_CONTAINS_ASSIGNMENT, d.getMessage());
        }
    }
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) EObject(org.eclipse.emf.ecore.EObject) Diagnostic(org.eclipse.emf.common.util.Diagnostic) Test(org.junit.Test)

Aggregations

Diagnostic (org.eclipse.emf.common.util.Diagnostic)354 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)223 EObject (org.eclipse.emf.ecore.EObject)148 WrappedException (org.eclipse.emf.common.util.WrappedException)113 Test (org.junit.Test)89 PartInitException (org.eclipse.ui.PartInitException)88 CoreException (org.eclipse.core.runtime.CoreException)73 Resource (org.eclipse.emf.ecore.resource.Resource)66 XtextResource (org.eclipse.xtext.resource.XtextResource)60 IOException (java.io.IOException)56 URI (org.eclipse.emf.common.util.URI)56 Point (org.eclipse.swt.graphics.Point)45 ProblemEditorPart (org.eclipse.emf.common.ui.editor.ProblemEditorPart)44 IResource (org.eclipse.core.resources.IResource)37 List (java.util.List)13 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)13 ArrayList (java.util.ArrayList)11 AbstractValidationDiagnostic (org.eclipse.xtext.validation.AbstractValidationDiagnostic)11 File (java.io.File)10 Iterator (java.util.Iterator)10