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.

