<commit_before>/*******************************************************************************
 * Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.xtext.junit4.ui;

import java.lang.reflect.Method;

import org.eclipse.xtext.ISetup;
import org.eclipse.xtext.junit4.AbstractXtextTests;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import com.google.inject.Injector;

/**
 * Unit test for class <code>DefaultContentAssistProcessor</code>. Reused by Xtend implementation.
 *
 * @author <NAME> - Initial contribution and API
 * @author <NAME>
 * @author <NAME>
 * @see org.eclipse.xtext.ui.editor.contentassist.impl.DefaultContentAssistProcessor
 */
public abstract class AbstractContentAssistProcessorTest extends AbstractXtextTests {

	public static class SetupExtension implements ISetup {

		private final ISetup plainSetup;

		public SetupExtension(ISetup plainSetup) {
			this.plainSetup = plainSetup;
		}
		
		public Injector createInjectorAndDoEMFRegistration() {
			return plainSetup.createInjectorAndDoEMFRegistration();
		}

		public void register(Injector injector) {
			try {
				Method method = plainSetup.getClass().getMethod("register", Injector.class);
				method.setAccessible(true);
				method.invoke(plainSetup, injector);
			} catch (Exception e) {
				throw new UnsupportedOperationException("register(Injector)", e);
			}
			
		}
		
	}
	
	private static boolean useStaticInjector = false;
	
	private static SetupExtension staticSetup = null;
	private static Injector staticInjector = null;
	
	@BeforeClass
	public void useStaticInjector() {
		useStaticInjector = true;
	}
	
	@AfterClass
	public void discardStaticInjector() {
		useStaticInjector = false;
		staticSetup = null;
		staticInjector = null;
	}
	
	protected ContentAssistProcessorTestBuilder newBuilder() throws Exception {
		return newBuilder(getSetup());
	}
	
	protected ContentAssistProcessorTestBuilder newBuilder(ISetup setup) throws Exception {
		return new ContentAssistProcessorTestBuilder(setup, this);
	}
	
	protected final ISetup getSetup() {
		if (!useStaticInjector) {
			return doGetSetup();
		}
		return new ISetup() {
			public Injector createInjectorAndDoEMFRegistration() {
				if (staticSetup == null) {
					staticSetup = new SetupExtension(doGetSetup());
					staticInjector = staticSetup.createInjectorAndDoEMFRegistration();
					return staticInjector;
				}
				staticSetup.register(staticInjector);
				return staticInjector;
			}
		};
	}
	
	protected abstract ISetup doGetSetup() ;

}<commit_msg>[xtext.ui][tests] Migrated to JUnit 4.x (missing change)<commit_after>/*******************************************************************************
 * Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.xtext.junit4.ui;

import java.lang.reflect.Method;

import org.eclipse.xtext.ISetup;
import org.eclipse.xtext.junit4.AbstractXtextTests;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import com.google.inject.Injector;

/**
 * Unit test for class <code>DefaultContentAssistProcessor</code>. Reused by Xtend implementation.
 *
 * @author <NAME> - Initial contribution and API
 * @author <NAME>
 * @author <NAME>
 * @see org.eclipse.xtext.ui.editor.contentassist.impl.DefaultContentAssistProcessor
 */
public abstract class AbstractContentAssistProcessorTest extends AbstractXtextTests {

	public static class SetupExtension implements ISetup {

		private final ISetup plainSetup;

		public SetupExtension(ISetup plainSetup) {
			this.plainSetup = plainSetup;
		}
		
		public Injector createInjectorAndDoEMFRegistration() {
			return plainSetup.createInjectorAndDoEMFRegistration();
		}

		public void register(Injector injector) {
			try {
				Method method = plainSetup.getClass().getMethod("register", Injector.class);
				method.setAccessible(true);
				method.invoke(plainSetup, injector);
			} catch (Exception e) {
				throw new UnsupportedOperationException("register(Injector)", e);
			}
			
		}
		
	}
	
	protected static boolean useStaticInjector = false;
	
	private static SetupExtension staticSetup = null;
	private static Injector staticInjector = null;
	
	@BeforeClass
	public static void useStaticInjector() {
		useStaticInjector = true;
	}
	
	@AfterClass
	public static void discardStaticInjector() {
		useStaticInjector = false;
		staticSetup = null;
		staticInjector = null;
	}
	
	protected ContentAssistProcessorTestBuilder newBuilder() throws Exception {
		return newBuilder(getSetup());
	}
	
	protected ContentAssistProcessorTestBuilder newBuilder(ISetup setup) throws Exception {
		return new ContentAssistProcessorTestBuilder(setup, this);
	}
	
	protected ISetup getSetup() {
		if (!useStaticInjector) {
			return doGetSetup();
		}
		return new ISetup() {
			public Injector createInjectorAndDoEMFRegistration() {
				if (staticSetup == null) {
					staticSetup = new SetupExtension(doGetSetup());
					staticInjector = staticSetup.createInjectorAndDoEMFRegistration();
					return staticInjector;
				}
				staticSetup.register(staticInjector);
				return staticInjector;
			}
		};
	}
	
	protected abstract ISetup doGetSetup() ;

}
{'fraction_non_alphanumeric': 0.13939081053175012, 'fraction_numerical': 0.0036138358286009293, 'mean_word_length': 4.894523326572008, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5837273', 'n_tokens_mistral': 1789, 'n_tokens_neox': 1615, 'n_words': 403}