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

The following examples show how to use org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil#addProjectReference() . 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: 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 2
Source File: IntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("restriction")
@Test public void testBuildOrderIsWrong() throws Exception {
	foo_project = createJavaProjectWithRootSrc("foo");
	bar_project = createJavaProjectWithRootSrc("bar");

	org.eclipse.core.internal.resources.Workspace workspace =
			(org.eclipse.core.internal.resources.Workspace) ResourcesPlugin.getWorkspace();
	IBuildConfiguration[] buildOrder = workspace.getBuildOrder();
	assertEquals(bar_project.getProject(), buildOrder[0].getProject());
	assertEquals(foo_project.getProject(), buildOrder[1].getProject());
	// here we do only add a classpath entry and no core.resources project reference
	JavaProjectSetupUtil.addProjectReference(bar_project, foo_project);
	
	buildOrder = workspace.getBuildOrder();
	assertEquals(bar_project.getProject(), buildOrder[0].getProject());
	assertEquals(foo_project.getProject(), buildOrder[1].getProject());
}
 
Example 3
Source File: BuildAffectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private IFile createClientProjectFile(final String name, final CharSequence content) {
  try {
    IFile _xblockexpression = null;
    {
      this.clientProject = WorkbenchTestHelper.createPluginProject("test.client");
      JavaProjectSetupUtil.addProjectReference(JavaCore.create(this.clientProject), JavaCore.create(this.workbenchTestHelper.getProject()));
      Path _path = new Path((("test.client/src/" + name) + ".xtend"));
      _xblockexpression = IResourcesSetupUtil.createFile(_path, content.toString());
    }
    return _xblockexpression;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 4
Source File: RebuildAffectedResourcesTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testChangeInAnnotationProcessor() {
  try {
    final IJavaProject macroProject = JavaCore.create(this.<IProject>registerForCleanUp(WorkbenchTestHelper.createPluginProject((WorkbenchTestHelper.TESTPROJECT_NAME + "-anno"))));
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package anno");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.Active");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@Active(AnnoProcessor)");
    _builder.newLine();
    _builder.append("annotation Anno {}");
    _builder.newLine();
    this.createFile(macroProject, "src/anno/Anno.xtend", _builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package anno");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtend.lib.macro.AbstractFieldProcessor");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtend.lib.macro.TransformationContext");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class AnnoProcessor extends AbstractFieldProcessor {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("override doTransform(MutableFieldDeclaration it, extension TransformationContext context) {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    final IFile processorClass = this.createFile(macroProject, "src/anno/AnnoProcessor.xtend", _builder_1.toString());
    WorkbenchTestHelper.addExportedPackages(macroProject.getProject(), "anno");
    final IJavaProject clientProject = JavaCore.create(WorkbenchTestHelper.createPluginProject((WorkbenchTestHelper.TESTPROJECT_NAME + "-client")));
    JavaProjectSetupUtil.addProjectReference(clientProject, macroProject);
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("import anno.Anno");
    _builder_2.newLine();
    _builder_2.append("class Foo {");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("@Anno String foo");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("def bar() {");
    _builder_2.newLine();
    _builder_2.append("\t\t");
    _builder_2.append("foo - 3");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    final IFile clientClass = this.createFile(clientProject, "src/Foo.xtend", _builder_2.toString());
    IResourcesSetupUtil.waitForBuild();
    this.assertHasErrors(clientClass, "- cannot be resolved");
    StringConcatenation _builder_3 = new StringConcatenation();
    _builder_3.append("package anno");
    _builder_3.newLine();
    _builder_3.append("import org.eclipse.xtend.lib.macro.AbstractFieldProcessor");
    _builder_3.newLine();
    _builder_3.append("import org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration");
    _builder_3.newLine();
    _builder_3.append("import org.eclipse.xtend.lib.macro.TransformationContext");
    _builder_3.newLine();
    _builder_3.newLine();
    _builder_3.append("class AnnoProcessor extends AbstractFieldProcessor {");
    _builder_3.newLine();
    _builder_3.append("\t");
    _builder_3.append("override doTransform(MutableFieldDeclaration it, extension TransformationContext context) {");
    _builder_3.newLine();
    _builder_3.append("\t\t");
    _builder_3.append("type = primitiveInt");
    _builder_3.newLine();
    _builder_3.append("\t");
    _builder_3.append("}");
    _builder_3.newLine();
    _builder_3.append("}");
    _builder_3.newLine();
    StringInputStream _stringInputStream = new StringInputStream(_builder_3.toString());
    processorClass.setContents(_stringInputStream, true, true, null);
    IResourcesSetupUtil.waitForBuild();
    this.assertNoErrorsInWorkspace();
    WorkbenchTestHelper.deleteProject(clientProject.getProject());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 5
Source File: RebuildAffectedResourcesTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testChangeJavaClassLookedUpInAnnotationProcessor() {
  try {
    final IJavaProject macroProject = JavaCore.create(this.<IProject>registerForCleanUp(WorkbenchTestHelper.createPluginProject((WorkbenchTestHelper.TESTPROJECT_NAME + "-macro"))));
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package anno");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.Active");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.AbstractClassProcessor");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.TransformationContext");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@Active(AnnoProcessor)");
    _builder.newLine();
    _builder.append("annotation Anno {}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class AnnoProcessor extends AbstractClassProcessor {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override doTransform(MutableClassDeclaration cls, extension TransformationContext context) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val theType = context.findTypeGlobally(\"anno.A\")?:context.findTypeGlobally(\"anno.B\")");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("cls.addField(\"foo\") [");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("type = theType.newTypeReference");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("]");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this.createFile(macroProject, "src/anno/Anno.xtend", _builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package anno");
    _builder_1.newLine();
    _builder_1.append("class B {}");
    _builder_1.newLine();
    this.createFile(macroProject, "src/anno/B.xtend", _builder_1.toString());
    WorkbenchTestHelper.addExportedPackages(macroProject.getProject(), "anno");
    final IJavaProject clientProject = JavaCore.create(this.<IProject>registerForCleanUp(WorkbenchTestHelper.createPluginProject((WorkbenchTestHelper.TESTPROJECT_NAME + "-client"))));
    JavaProjectSetupUtil.addProjectReference(clientProject, macroProject);
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("import anno.Anno");
    _builder_2.newLine();
    _builder_2.append("@Anno");
    _builder_2.newLine();
    _builder_2.append("class Foo {");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("def test() {");
    _builder_2.newLine();
    _builder_2.append("\t\t");
    _builder_2.append("foo.bar");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    final IFile fooClass = this.createFile(clientProject, "src/Foo.xtend", _builder_2.toString());
    IResourcesSetupUtil.waitForBuild();
    this.assertHasErrors(fooClass, "bar is undefined");
    StringConcatenation _builder_3 = new StringConcatenation();
    _builder_3.append("package anno");
    _builder_3.newLine();
    _builder_3.append("class A {");
    _builder_3.newLine();
    _builder_3.append("\t");
    _builder_3.append("def bar() {}");
    _builder_3.newLine();
    _builder_3.append("}");
    _builder_3.newLine();
    this.createFile(macroProject, "src/anno/A.xtend", _builder_3.toString());
    IResourcesSetupUtil.waitForBuild();
    this.assertNoErrorsInWorkspace();
    WorkbenchTestHelper.deleteProject(clientProject.getProject());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 6
Source File: PerformanceTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testBuildOfDownstreamProject() throws Exception {
  final IJavaProject project = PerformanceTestProjectSetup.testProject;
  final IJavaProject downStreamProject = PerformanceTestProjectSetup.createJavaProject("performance.test.project.downstream", 
    new String[] { JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature" });
  JavaProjectSetupUtil.addProjectReference(downStreamProject, project);
  new ToggleXtextNatureCommand().toggleNature(downStreamProject.getProject());
  final IFolder sourceFolder = JavaProjectSetupUtil.addSourceFolder(downStreamProject, "src");
  JavaProjectSetupUtil.addSourceFolder(downStreamProject, "xtend-gen");
  sourceFolder.getFolder("foo").create(true, true, null);
  final IFile sourceFile = sourceFolder.getFile("foo/MyFile.xtend");
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("package foo");
  _builder.newLine();
  _builder.newLine();
  _builder.append("import org.eclipse.xtext.xbase.formatting.BasicFormatterPreferenceKeys");
  _builder.newLine();
  _builder.append("import org.eclipse.xtext.xbase.formatting.FormattableDocument");
  _builder.newLine();
  _builder.append("import org.eclipse.xtext.xbase.formatting.HiddenLeafAccess");
  _builder.newLine();
  _builder.append("import org.eclipse.xtext.xbase.formatting.NodeModelAccess");
  _builder.newLine();
  _builder.append("import org.eclipse.xtext.xbase.formatting.XbaseFormatter2");
  _builder.newLine();
  _builder.newLine();
  _builder.append("class MyFile extends XbaseFormatter2 {");
  _builder.newLine();
  _builder.append("\t");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("def a(BasicFormatterPreferenceKeys keys) {");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("BasicFormatterPreferenceKeys::indentation");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("}");
  _builder.newLine();
  _builder.append("\t");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("def b(FormattableDocument doc) {");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("doc.cfg.get(BasicFormatterPreferenceKeys::indentation)");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("}");
  _builder.newLine();
  _builder.append("\t");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("def c(HiddenLeafAccess x) {");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("x.getHiddenLeafsAfter(null).newLines");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("}");
  _builder.newLine();
  _builder.append("\t");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("def d(NodeModelAccess x) {");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("x.nodeForEObject(null).asTreeIterable");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("}");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  StringInputStream _stringInputStream = new StringInputStream(_builder.toString());
  sourceFile.create(_stringInputStream, true, null);
  final IProject p = downStreamProject.getProject();
  p.build(IncrementalProjectBuilder.FULL_BUILD, null);
  p.build(IncrementalProjectBuilder.FULL_BUILD, null);
  Stopwatches.resetAll();
  p.build(IncrementalProjectBuilder.FULL_BUILD, null);
}