Several Xtext based DSLs will use import statements that import JvmTypes, be them real Java types, or just inferred types produced with your IJvmModelInferrer. The check for a valid import might be simple, but here it is to just make it even easier for you. I just had the need to realize this to resolve Spray issue#113. Basically you need to get the IJvmTypeProvider, to which you gain access through the IJvmTypeProvider.Factory.
public class SprayJavaValidator extends AbstractSprayJavaValidator implements IssueCodes {
@Inject
private IJvmTypeProvider.Factory typeProviderFactory;
@Check
public void checkImports(final Import imp) {
// don't check wildcard imports
if (imp.getImportedNamespace().endsWith(".*"))
return;
IJvmTypeProvider typeProvider = typeProviderFactory.findOrCreateTypeProvider(imp.eResource().getResourceSet());
JvmType jvmType = typeProvider.findTypeByName(imp.getImportedNamespace());
if (jvmType == null) {
error("The import " + imp.getImportedNamespace() + " cannot be resolved", SprayPackage.Literals.IMPORT__IMPORTED_NAMESPACE, IMPORT_NOTEXISTS, new String[0]);
}
}
...
}
That’s all.



Cool, thanks.
Now I only need to figure out why Eclipse keeps telling me that IJvmTypeProvider isn’t exported
Comment by digulla — April 3, 2012 @ 3:47 PM
Ah, it’s a feature: http://www.eclipse.org/forums/index.php/m/836406/#msg_836406
Comment by digulla — April 5, 2012 @ 9:20 AM