Hi,
ParseHelper is not meant to be used in that usecase. you have to fix it to be able to handle it
@RunWith(XtextRunner)
@InjectWith(SmallFuncDslTestInjectorProvider)
class SmallFuncDslValidatorTest {
@Inject extension SmartParseHelper<Namespace>
@Inject extension ValidationTestHelper
@Inject Provider<XtextResourceSet> resourceSetProvider
@Test
def void testCheckParamIfSmallClassHasAttributes() {
val rs = resourceSetProvider.get
val sc = '''
namespace tests.smalllang
class Library {
}
'''.parse(rs,"sjava")
val smallFunc = '''
namespace tests.smalllang
import tests.smalllang.*
def CheckLibraryHasBooks(Library library) {
}
'''.parse(rs).artifact as SmallFunction
smallFunc.params.head => [
assertError(SmallFuncDslPackage.Literals.PARAM, "", "Small class has no attributes...")
]
}
}
class SmartParseHelper<T extends EObject> extends ParseHelper<T> {
@Inject
IResourceFactory resourceFactory;
def T parse(CharSequence text, ResourceSet resourceSetToUse, String fileExtension) throws Exception {
return parse(getAsStream(text), computeUnusedUri(resourceSetToUse, fileExtension), null, resourceSetToUse, fileExtension) as T
}
def URI computeUnusedUri(ResourceSet resourceSet, String fileExtension) {
val String name = "__synthetic";
for (i : 0..Integer.MAX_VALUE) {
val URI syntheticUri = URI.createURI(name + i + "." + fileExtension);
if (resourceSet.getResource(syntheticUri, false) == null)
return syntheticUri;
}
throw new IllegalStateException();
}
def T parse(InputStream in, URI uriToUse, Map<?, ?> options, ResourceSet resourceSet, String fileExtension) {
val Resource resource = resourceSet.createResource(uriToUse);
try {
resource.load(in, options);
val T root = if (resource.getContents().isEmpty()) null else resource.getContents().get(0) as T;
return root;
} catch (IOException e) {
throw new WrappedException(e);
}
}
}