Java Code Examples for org.eclipse.emf.ecore.resource.Resource#getErrors()

The following examples show how to use org.eclipse.emf.ecore.resource.Resource#getErrors() . 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: BuiltInTypeScopeTest.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("javadoc")
@Test
public void testLoadingBuiltInTypes() {
	BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet);
	IEObjectDescription anyType = scope.getSingleElement(QualifiedName.create("any"));
	Assert.assertNotNull(anyType);
	String s = "";
	for (Resource resource : resourceSet.getResources()) {
		if (resource.getErrors().size() > 0) {
			for (Diagnostic d : resource.getErrors()) {
				s += "\n  " + d.getMessage() + " at " + resource.getURI() + ":" + d.getLine();
			}
		}
	}

	Assert.assertEquals("Resources definine built-in types must have no error.", "", s);
}
 
Example 2
Source File: Executor.java    From joynr with Apache License 2.0 6 votes vote down vote up
public void generate() {
    ModelLoader modelLoader = prepareGeneratorEnvironment();
    for (Resource resource : modelLoader.getResources()) {
        if (resource.getErrors().size() > 0) {
            StringBuilder errorMsg = new StringBuilder();
            errorMsg.append("Error loading model " + resource.getURI().toString()
                    + ". The following errors occured: \n");
            for (Diagnostic error : resource.getErrors()) {
                errorMsg.append(error.getMessage());
            }
            logger.log(Level.SEVERE, errorMsg.toString());
            System.exit(-1);
        } else {
            generator.doGenerate(resource, outputFileSystem);
        }
    }
}
 
Example 3
Source File: XcoreReader.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor,
		Issues issues) {
	ResourceSet resourceSet = getResourceSet();

	// due to some Xcore peculiarity we have to access the IAllContainerState here
	// to trigger some lazy init logic
	IAllContainersState allContainerState = (IAllContainersState) EcoreUtil.getAdapter(resourceSet.eAdapters(),
			IAllContainersState.class);
	allContainerState.isEmpty("");

	Multimap<String, URI> uris = getPathTraverser().resolvePathes(pathes,
			new Predicate<URI>() {
		@Override
		public boolean apply(URI input) {
			return input.fileExtension().equals(XCORE_FILE_EXT);
		}
	});
	List<Resource> resources = new ArrayList<>();
	for (URI uri : uris.values()) {
		LOGGER.info(uri);
		try {
			resources.add(parse(uri, resourceSet));
		} catch (Exception e) {
			LOGGER.error("Problem during loading of resource @ " + uri, e);
		}
	}
	installIndex(resourceSet);
	for (Resource r : resources) {
		EcoreUtil.resolveAll(r);
		for (Diagnostic x : r.getErrors()) {
			issues.addError(x.getMessage(), x);
		}

	}
	ctx.set(slot, resources);
}
 
Example 4
Source File: GrammarGeneratorTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void checkErrors(EPackage ePackage, Resource xtextResource, String xtextGrammar) {
	EList<Diagnostic> errors = xtextResource.getErrors();
	if (!errors.isEmpty()) {
		System.out.println(xtextGrammar);
		fail("Errors in grammar for " + ePackage.getNsURI() + ":" + errors.get(0).getMessage());
	}
}
 
Example 5
Source File: ResourceLoadTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void assertNoExceptionDiagnostic(Resource r, String model) throws Exception {
	for (Diagnostic d : r.getErrors()) {
		if (d instanceof ExceptionDiagnostic) {
			throw new Exception(model, ((ExceptionDiagnostic) d).getException());
		}
	}
}
 
Example 6
Source File: OnChangeEvictingCacheAdapterTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testCacheSurvivesChangeToDiagnostics() throws Exception {
	EcoreFactory factory = EcoreFactory.eINSTANCE;
	EClass eClass = factory.createEClass();
	Resource resource = new ResourceImpl();
	resource.getContents().add(eClass);
	CacheAdapter ca = new OnChangeEvictingCache().getOrCreate(resource);
	setValue(ca);
	List<Diagnostic> errors = resource.getErrors();
	assertIsSet(ca);
	errors.clear();
	assertIsSet(ca);
}
 
Example 7
Source File: ScriptEngineImpl.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
private XExpression parseScriptIntoXTextEObject(String scriptAsString) throws ScriptParsingException {
    XtextResourceSet resourceSet = getResourceSet();
    Resource resource = resourceSet.createResource(computeUnusedUri(resourceSet)); // IS-A XtextResource
    try {
        resource.load(new StringInputStream(scriptAsString, StandardCharsets.UTF_8.name()),
                resourceSet.getLoadOptions());
    } catch (IOException e) {
        throw new ScriptParsingException(
                "Unexpected IOException; from close() of a String-based ByteArrayInputStream, no real I/O; how is that possible???",
                scriptAsString, e);
    }

    List<Diagnostic> errors = resource.getErrors();
    if (!errors.isEmpty()) {
        throw new ScriptParsingException("Failed to parse expression (due to managed SyntaxError/s)",
                scriptAsString).addDiagnosticErrors(errors);
    }

    EList<EObject> contents = resource.getContents();

    if (!contents.isEmpty()) {
        Iterable<Issue> validationErrors = getValidationErrors(contents.get(0));
        if (!validationErrors.iterator().hasNext()) {
            return (XExpression) contents.get(0);
        } else {
            throw new ScriptParsingException("Failed to parse expression (due to managed ValidationError/s)",
                    scriptAsString).addValidationIssues(validationErrors);
        }
    } else {
        return null;
    }
}
 
Example 8
Source File: SARLEditorErrorTickUpdater.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("checkstyle:nestedifdepth")
public void modelChanged(IAnnotationModel model) {
	super.modelChanged(model);
	//FIXME: for helping to resolve #661
	final XtextEditor editor = getEditor();
	if (editor != null && !editor.isDirty() && editor.getInternalSourceViewer() != null) {
		final IAnnotationModel currentModel = editor.getInternalSourceViewer().getAnnotationModel();
		if (currentModel != null && currentModel == model) {
			final Resource resource = getXtextResource();
			if (isReconciliable(resource)) {
				final Set<String> markers = extractErrorMarkerMessages(currentModel);
				final List<Diagnostic> resourceErrors = resource.getErrors();
				if (markers.size() != resourceErrors.size() || notSame(markers, resourceErrors)) {
					final Display display = PlatformUI.getWorkbench().getDisplay();
					display.asyncExec(new Runnable() {
						@Override
						public void run() {
							LangActivator.getInstance().getLog().log(
									new Status(IStatus.ERROR, LangActivator.PLUGIN_ID,
									MessageFormat.format(Messages.SARLEditorErrorTickUpdater_0, resource.getURI())));
						}
					});
				}
			}
		}
	}
}
 
Example 9
Source File: XtextFileLoader.java    From orcas with Apache License 2.0 5 votes vote down vote up
private T loadModelDslFile( File pFile, Parameters pParameters, XtextResourceSet pResourceSet, Map<Object, Object> pLoadOptions, int pCounter )
{
  Resource lResource = pResourceSet.createResource( URI.createURI( "dummy:/dummy" + pCounter + "." + getXtextExpectedFileEnding() ) );
  try
  {
    loadFileIntoResource( pFile, pLoadOptions, lResource );
    EList<EObject> lContents = lResource.getContents();

    if( lContents.isEmpty() )
    {
      return null;
    }

    @SuppressWarnings( "unchecked" )
    T lModel = (T) lContents.get( 0 );

    if( !lResource.getErrors().isEmpty() )
    {
      throw new RuntimeException( "parse errors" + pFile + " :" + lResource.getErrors().get( 0 ) );
    }

    return lModel;
  }
  catch( Exception e )
  {
    if( lResource != null )
    {
      for( Diagnostic lDiagnostic : lResource.getErrors() )
      {
        Orcas.logError( "Error in File: " + pFile, pParameters );
        Orcas.logError( lDiagnostic + "", pParameters );
      }
    }

    throw new RuntimeException( e );
  }
}
 
Example 10
Source File: ScriptEngineImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private XExpression parseScriptIntoXTextEObject(String scriptAsString) throws ScriptParsingException {
    XtextResourceSet resourceSet = getResourceSet();
    Resource resource = resourceSet.createResource(computeUnusedUri(resourceSet)); // IS-A XtextResource
    try {
        resource.load(new StringInputStream(scriptAsString, StandardCharsets.UTF_8.name()),
                resourceSet.getLoadOptions());
    } catch (IOException e) {
        throw new ScriptParsingException(
                "Unexpected IOException; from close() of a String-based ByteArrayInputStream, no real I/O; how is that possible???",
                scriptAsString, e);
    }

    List<Diagnostic> errors = resource.getErrors();
    if (errors.size() != 0) {
        throw new ScriptParsingException("Failed to parse expression (due to managed SyntaxError/s)",
                scriptAsString).addDiagnosticErrors(errors);
    }

    EList<EObject> contents = resource.getContents();

    if (!contents.isEmpty()) {
        Iterable<Issue> validationErrors = getValidationErrors(contents.get(0));
        if (!validationErrors.iterator().hasNext()) {
            return (XExpression) contents.get(0);
        } else {
            throw new ScriptParsingException("Failed to parse expression (due to managed ValidationError/s)",
                    scriptAsString).addValidationIssues(validationErrors);
        }
    } else {
        return null;
    }
}