org.eclipse.xtext.testing.InjectWith Java Examples

The following examples show how to use org.eclipse.xtext.testing.InjectWith. 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: InjectionExtension.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private static InjectWith getInjectWith(Class<?> cls) {
	InjectWith result = null;
	Class<?> firstClassMatched = null;
	while (cls != null) {
		InjectWith iw = cls.getAnnotation(InjectWith.class);
		if (iw != null) {
			if(result != null) {
				throw new ExtensionConfigurationException(String.format("Multiple @InjectWith annotations are found (%s and %s). Only a single one is supported.",
						firstClassMatched.getName(), cls.getName()));
			}
			result = iw;
			firstClassMatched = cls;
		}
		cls = cls.getEnclosingClass();
	}
	return result;
}
 
Example #2
Source File: InjectionExtension.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private static IInjectorProvider getOrCreateInjectorProvider(ExtensionContext context) {
	InjectWith injectWith = getInjectWith(context.getRequiredTestClass());
	if (injectWith != null) {
		Class<? extends IInjectorProvider> klass = injectWith.value();
		IInjectorProvider injectorProvider = injectorProviderClassCache.get(klass);
		if (injectorProvider == null) {
			try {
				injectorProvider = klass.getDeclaredConstructor().newInstance();
				injectorProviderClassCache.put(klass, injectorProvider);
			} catch (Exception e) {
				throwUncheckedException(e);
			}
		}
		return injectorProvider;
	}
	return null;
}
 
Example #3
Source File: InjectorProviders.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public static IInjectorProvider getOrCreateInjectorProvider(TestClass testClass) {
	InjectWith injectWith = testClass.getJavaClass().getAnnotation(InjectWith.class);
	if (injectWith != null) {
		Class<? extends IInjectorProvider> klass = injectWith.value();
		IInjectorProvider injectorProvider = injectorProviderClassCache.get(klass);
		if (injectorProvider == null) {
			try {
				injectorProvider = klass.getDeclaredConstructor().newInstance();
				injectorProviderClassCache.put(klass, injectorProvider);
			} catch (Exception e) {
				throwUncheckedException(e);
			}
		}
		return injectorProvider;
	}
	return null;
}
 
Example #4
Source File: AbstractInjectorExtension.java    From sarl with Apache License 2.0 6 votes vote down vote up
private static IInjectorProvider createInjectorProvider(ExtensionContext context) {
	InjectWith injectWith = context.getRequiredTestClass().getAnnotation(InjectWith.class);
	if (injectWith != null) {
		Class<? extends IInjectorProvider> klass = injectWith.value();
		try {
			// TODO this mode of creation is not efficient, but it ensures that the injector providers are really reset.
			final IInjectorProvider injectorProvider = klass.getDeclaredConstructor().newInstance();
			if (injectorProvider instanceof IRegistryConfigurator) {
				final IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) injectorProvider;
				registryConfigurator.setupRegistry();
			}
			return injectorProvider;
		} catch (Exception e) {
			throwUncheckedException(e);
		}
	}
	throw new IllegalStateException("Expected valid @InjectWith annotation");
}
 
Example #5
Source File: InjectorProviders.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public static IInjectorProvider getInjectorProvider(TestClass testClass) {
	InjectWith injectWith = testClass.getJavaClass().getAnnotation(InjectWith.class);
	if (injectWith != null) {
		return injectorProviderClassCache.get(injectWith.value());
	}
	return null;
}
 
Example #6
Source File: InjectorProviders.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public static IInjectorProvider createInjectorProvider(TestClass testClass) {
	InjectWith injectWith = testClass.getJavaClass().getAnnotation(InjectWith.class);
	if (injectWith != null) {
		try {
			return injectWith.value().getDeclaredConstructor().newInstance();
		} catch (Exception e) {
			throwUncheckedException(e);
		}
	}
	return null;
}