Java Code Examples for org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil#createJavaProject()

The following examples show how to use org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil#createJavaProject() . 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: GrammarLinkingInWorkspaceTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test 
public void testReferencedGrammarIsPlatformResourceURI() throws Exception {
	IJavaProject project = JavaProjectSetupUtil.createJavaProject("p1");
	IFile grammar1 = project.getProject().getFile("src/Grammar1.xtext");
	grammar1.create(new StringInputStream("grammar Grammar1 MyRule : 'foo';"), true, null);
	
	Injector injector = Activator.getDefault().getInjector(org.eclipse.xtext.xtext.ui.internal.Activator.ORG_ECLIPSE_XTEXT_XTEXT);
	XtextResourceSetProvider resourceSetProvider = injector.getInstance(XtextResourceSetProvider.class);
	ResourceSet resourceSet = resourceSetProvider.get(project.getProject());
	XtextResourceFactory resourceFactory = injector.getInstance(XtextResourceFactory.class);
	Resource resource = resourceFactory.createResource(URI.createURI("synthetic://MyGrammar.xtext"));
	resourceSet.getResources().add(resource);
	resource.load(new StringInputStream("grammar g2 with Grammar1 OtherRule : MyRule ;"), null);
	EcoreUtil.resolveAll(resource);
	assertEquals(2, resourceSet.getResources().size());
	assertTrue(resourceSet.getResources().get(1).getURI().isPlatformResource());
}
 
Example 2
Source File: Storage2UriMapperJavaImplTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testOnRemoveTwoProjects() {
  try {
    Assert.assertEquals(0, this.getCachedPackageFragmentRootData().size());
    final IJavaProject project = JavaProjectSetupUtil.createJavaProject("testProject");
    final IJavaProject project2 = JavaProjectSetupUtil.createJavaProject("testProject2");
    final int sizeBefore = this.getCachedPackageFragmentRootData().size();
    final IFile file = this.createJar(project);
    JavaProjectSetupUtil.addJarToClasspath(project, file);
    JavaProjectSetupUtil.addJarToClasspath(project2, file);
    this.assertBothProjects(sizeBefore);
    final WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
      @Override
      protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
        project.getProject().delete(true, monitor);
        project2.getProject().delete(true, monitor);
      }
    };
    op.run(IResourcesSetupUtil.monitor());
    this.assertNonProjects();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 3
Source File: JdtClasspathUriResolverTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testClasspathUriForFileInWorkspaceInOtherProjectRoot() throws Exception {
	_javaProject = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT_NAME);
	IJavaProject otherProject = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT_NAME + "2");
	try {
		JavaProjectSetupUtil.addProjectReference(_javaProject, otherProject);
		_project = otherProject.getProject();
		_project.getFolder("model").create(true, true, null);
		PluginUtil.copyFileToWorkspace(TestsActivator.getInstance(), "/testfiles/" + MODEL_FILE, _project, "model/"
				+ MODEL_FILE);
		URI classpathUri = URI.createURI("classpath:/model/" + MODEL_FILE + "#/");
		String expectedUri = "platform:/resource/" + TEST_PROJECT_NAME + "2/model/" + MODEL_FILE + "#/";
		URI normalizedUri = _resolver.resolve(_javaProject, classpathUri);
		assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
	} finally {
		otherProject.getProject().delete(true, null);
	}
}
 
Example 4
Source File: XtendEditorChangingClasspathTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testAddXtendLibWithDirtyEditor() {
  try {
    final IJavaProject project = JavaProjectSetupUtil.createJavaProject("testProject");
    final IFile file = IResourcesSetupUtil.createFile("testProject/src/Foo.xtend", "class Foo {}");
    IResourcesSetupUtil.waitForBuild();
    final XtextEditor editor = this.workbenchTestHelper.openEditor(file);
    final Procedure0 _function = () -> {
      this.changeContent(editor, "{}", "{ def foo () {} }");
    };
    this.waitForChangeEvent(_function);
    this.assertAddLibsToClasspath(project);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 5
Source File: JdtClasspathUriResolverTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testClasspathUriForFileInWorkspaceWithFragment() throws Exception {
	_javaProject = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT_NAME);
	_project = _javaProject.getProject();
	PluginUtil.copyFileToWorkspace(TestsActivator.getInstance(), "/testfiles/" + MODEL_FILE, _project, "src/"
			+ MODEL_FILE);
	URI classpathUri = URI.createURI("classpath:/" + MODEL_FILE + "#/");
	String expectedUri = "platform:/resource/" + TEST_PROJECT_NAME + "/src/" + MODEL_FILE + "#/";
	URI normalizedUri = _resolver.resolve(_javaProject, classpathUri);
	assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
}
 
Example 6
Source File: XtendEditorChangingClasspathTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAddXtendLib() {
  try {
    final IJavaProject project = JavaProjectSetupUtil.createJavaProject("testProject");
    final IFile file = IResourcesSetupUtil.createFile("testProject/src/Foo.xtend", "class Foo {}");
    IResourcesSetupUtil.waitForBuild();
    this.workbenchTestHelper.openEditor(file);
    this.assertAddLibsToClasspath(project);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 7
Source File: RuleEngineQuickfixTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setup() {
  try {
    JavaProjectSetupUtil.createJavaProject(this.getProjectName());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 8
Source File: QuickfixTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setup() {
  try {
    JavaProjectSetupUtil.createJavaProject(this.getProjectName());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 9
Source File: JavaDocHyperlinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setup() {
  try {
    JavaProjectSetupUtil.createJavaProject(this.getProjectName());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 10
Source File: JdtClasspathUriResolverTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testClasspathUriForFileInWorkspaceWithFragmentInProjectRoot() throws Exception {
	_javaProject = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT_NAME);
	_project = _javaProject.getProject();
	_project.getFolder("model").create(true, true, null);
	PluginUtil.copyFileToWorkspace(TestsActivator.getInstance(), "/testfiles/" + MODEL_FILE, _project, "model/"
			+ MODEL_FILE);
	URI classpathUri = URI.createURI("classpath:/model/" + MODEL_FILE + "#/");
	String expectedUri = "platform:/resource/" + TEST_PROJECT_NAME + "/model/" + MODEL_FILE + "#/";
	URI normalizedUri = _resolver.resolve(_javaProject, classpathUri);
	assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
}
 
Example 11
Source File: ToSaveOrNotToSaveTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	IJavaProject project = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT);
	addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
	Injector injector = TestsActivator.getInstance().getInjector(getEditorId());
	injector.injectMembers(this);
	IFile fooFile = IResourcesSetupUtil.createFile(TEST_PROJECT + "/foo.refactoringtestlanguage", "foo");
	IFile barFile = IResourcesSetupUtil
			.createFile(TEST_PROJECT + "/bar.refactoringtestlanguage", "bar { ref foo }");
	waitForBuild();
	fooEditor = openEditor(fooFile);
	barEditor = openEditor(barFile);
	assertTrue(refactoringPreferences.useInlineRefactoring());
}
 
Example 12
Source File: ValidationIssue719QuickFixTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setup() {
  try {
    JavaProjectSetupUtil.createJavaProject(this.getProjectName());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 13
Source File: WorkspaceClasspathUriResolverTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testClasspathUriForFileInJarInWorkspace() throws Exception {
	_javaProject = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT_NAME);
	_project = _javaProject.getProject();
	IFile jarFile = PluginUtil.copyFileToWorkspace(TestsActivator.getInstance(), "/testfiles/" + JAR_FILE, _project, "/"
			+ JAR_FILE);
	JavaProjectSetupUtil.addJarToClasspath(_javaProject, jarFile);
	URI classpathUri = URI.createURI("classpath:/model/" + MODEL_FILE);
	String expectedUri = "archive:platform:/resource/" + TEST_PROJECT_NAME + "/" + JAR_FILE + "!/model/" + MODEL_FILE;
	URI normalizedUri = _resolver.resolve(_project, classpathUri);
	assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
}
 
Example 14
Source File: WorkspaceClasspathUriResolverTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testClasspathUriForFileInWorkspaceWithFragment() throws Exception {
	_javaProject = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT_NAME);
	_project = _javaProject.getProject();
	PluginUtil.copyFileToWorkspace(TestsActivator.getInstance(), "/testfiles/" + MODEL_FILE, _project, "src/"
			+ MODEL_FILE);
	URI classpathUri = URI.createURI("classpath:/" + MODEL_FILE + "#/");
	String expectedUri = "platform:/resource/" + TEST_PROJECT_NAME + "/src/" + MODEL_FILE + "#/";
	URI normalizedUri = _resolver.resolve(_project, classpathUri);
	assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
}
 
Example 15
Source File: AbstractContentAssistTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() {
	try {
		AbstractContentAssistTest.javaProject = JavaProjectSetupUtil.createJavaProject("contentAssistTest");
	} catch (CoreException e) {
		throw Exceptions.sneakyThrow(e);
	}
}
 
Example 16
Source File: RuleEngineHoverTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setup() {
  try {
    JavaProjectSetupUtil.createJavaProject(this.getProjectName());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 17
Source File: HoverTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setup() {
  try {
    JavaProjectSetupUtil.createJavaProject(this.getProjectName());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 18
Source File: EclipseWorkspaceConfigurationTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testConfig() throws Exception {
	IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
	for (IProject p : wsroot.getProjects()) {
		p.delete(true, true, null);
	}
	Assert.assertEquals(0, wsroot.getProjects().length);
	IJavaProject project = JavaProjectSetupUtil.createJavaProject("projectA");
	JavaProjectSetupUtil.createJavaProject("projectB");
	EclipseProjectConfig projectConfig = projectConfigProvider.createProjectConfig(project.getProject());
	Assert.assertNotNull(projectConfig);
	Assert.assertNotNull(projectConfig.getWorkspaceConfig().findProjectByName("projectB"));
}
 
Example 19
Source File: RefactoringDocumentProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	IJavaProject project = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT);
	addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
	project.getProject().setDefaultCharset(StandardCharsets.ISO_8859_1.name(), new NullProgressMonitor());
	Injector injector = TestsActivator.getInstance().getInjector(getEditorId());
	injector.injectMembers(this);
	testFile = IResourcesSetupUtil.createFile(TEST_FILE_PATH, TEST_FILE_CONTENT);
	textEdit = new ReplaceEdit(0, 1, "C");
}
 
Example 20
Source File: AbstractContentAssistTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@BeforeClass
@BeforeAll
public static void setUp() throws CoreException {
	javaProject = JavaProjectSetupUtil.createJavaProject("contentAssistTest");
}