Java Code Examples for org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil#file()

The following examples show how to use org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil#file() . 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: Bug456868Test.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=452821
 */
@Test
public void testProjectWithWhitespaceInNameWorks() {
  try {
    this.project = JavaProjectSetupUtil.createJavaProject("my project");
    JavaProjectSetupUtil.makeJava8Compliant(this.project);
    NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
    this.libAdder.addLibsToClasspath(this.project, _nullProgressMonitor);
    this.natureAdder.toggleNature(this.project.getProject());
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class MyClass {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    IResourcesSetupUtil.createFile("my project/src/MyClass.xtend", _builder.toString());
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
    final IResource generatedJava = IResourcesSetupUtil.file("my project/xtend-gen/MyClass.java");
    Assert.assertTrue(generatedJava.exists());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 2
Source File: OpenTargetWithMultipleSourcesTestCase.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testOpenTargetSourceTwice() {
  try {
    IResource _file = IResourcesSetupUtil.file("testProject/xtend-gen/mypackage/B.java");
    final IFile childFile = ((IFile) _file);
    Assert.assertEquals(this._workbenchTestHelper.openEditor(childFile), this._workbenchTestHelper.openEditor(childFile));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 3
Source File: OpenTargetWithMultipleSourcesTestCase.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testOpenTargetSourceWithOpenedParentSource() {
  try {
    IResource _file = IResourcesSetupUtil.file("testProject/xtend-gen/mypackage/A.java");
    final IFile parenFile = ((IFile) _file);
    IResource _file_1 = IResourcesSetupUtil.file("testProject/xtend-gen/mypackage/B.java");
    final IFile childFile = ((IFile) _file_1);
    Assert.assertNotSame(this._workbenchTestHelper.openEditor(parenFile), this._workbenchTestHelper.openEditor(childFile));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 4
Source File: JdtBasedProcessorProviderTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=439925
 */
@Test
public void testClassLoaderSeesAllUpstreamProjects() {
  try {
    final IJavaProject macroProject = JavaCore.create(WorkbenchTestHelper.createPluginProject("macroProject"));
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package annotation");
    _builder.newLine();
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.AbstractClassProcessor");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.Active");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.TransformationContext");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@Active(MyAAProcessor)");
    _builder.newLine();
    _builder.append("annotation MyAA {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class MyAAProcessor extends AbstractClassProcessor {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override doTransform(MutableClassDeclaration annotatedClass, extension TransformationContext context) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val comment = getClass.getClassLoader.loadClass(\"mylib.Lib\").newInstance.toString");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("annotatedClass.docComment = comment");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this.newSource(macroProject, "annotation/MyAA.xtend", _builder.toString());
    WorkbenchTestHelper.addExportedPackages(macroProject.getProject(), "annotation");
    final IJavaProject libProject = JavaCore.create(WorkbenchTestHelper.createPluginProject("libProject"));
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package mylib");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class Lib {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("override String toString() {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("return \"HUNKELDUNKEL\"");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.newSource(libProject, "mylib/Lib.xtend", _builder_1.toString());
    WorkbenchTestHelper.addExportedPackages(libProject.getProject(), "mylib");
    IResourcesSetupUtil.waitForBuild();
    final IJavaProject userProject = JavaCore.create(
      WorkbenchTestHelper.createPluginProject("userProject", "com.google.inject", "org.eclipse.xtend.lib", 
        "org.eclipse.xtext.xbase.lib", "org.eclipse.xtend.ide.tests.data", "org.junit", "macroProject", "libProject"));
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("package client");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("@annotation.MyAA");
    _builder_2.newLine();
    _builder_2.append("class SomeClass {");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    this.newSource(userProject, "client/A.xtend", _builder_2.toString());
    IResourcesSetupUtil.cleanBuild();
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
    IResource _file = IResourcesSetupUtil.file("userProject/xtend-gen/client/SomeClass.java");
    final String javaCode = WorkbenchTestHelper.getContentsAsString(((IFile) _file));
    Assert.assertTrue(javaCode.contains("HUNKELDUNKEL"));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 5
Source File: JdtBasedProcessorProviderTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testClassLoaderSeesAllUpstreamProjects_01() {
  try {
    final IJavaProject libProject = JavaCore.create(WorkbenchTestHelper.createPluginProject("libProject"));
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package mylib");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Lib {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override String toString() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return \"HUNKELDUNKEL\"");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this.newSource(libProject, "mylib/Lib.xtend", _builder.toString());
    WorkbenchTestHelper.addExportedPackages(libProject.getProject(), "mylib");
    final IJavaProject macroProject = JavaCore.create(WorkbenchTestHelper.createPluginProject("macroProject", "com.google.inject", "org.eclipse.xtend.lib", 
      "org.eclipse.xtext.xbase.lib", "org.eclipse.xtend.ide.tests.data", "org.junit", "libProject"));
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package annotation");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtend.lib.macro.AbstractClassProcessor");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtend.lib.macro.Active");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtend.lib.macro.TransformationContext");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@Active(MyAAProcessor)");
    _builder_1.newLine();
    _builder_1.append("annotation MyAA {");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class MyAAProcessor extends AbstractClassProcessor {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("override doTransform(MutableClassDeclaration annotatedClass, extension TransformationContext context) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("annotatedClass.docComment = new mylib.Lib().toString()");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.newSource(macroProject, "annotation/MyAA.xtend", _builder_1.toString());
    WorkbenchTestHelper.addExportedPackages(macroProject.getProject(), "annotation");
    IResourcesSetupUtil.waitForBuild();
    final IJavaProject userProject = JavaCore.create(
      WorkbenchTestHelper.createPluginProject("userProject", "com.google.inject", "org.eclipse.xtend.lib", 
        "org.eclipse.xtext.xbase.lib", "org.eclipse.xtend.ide.tests.data", "org.junit", "macroProject"));
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("package client");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("@annotation.MyAA");
    _builder_2.newLine();
    _builder_2.append("class SomeClass {");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    this.newSource(userProject, "client/A.xtend", _builder_2.toString());
    IResourcesSetupUtil.cleanBuild();
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
    IResource _file = IResourcesSetupUtil.file("userProject/xtend-gen/client/SomeClass.java");
    final String javaCode = WorkbenchTestHelper.getContentsAsString(((IFile) _file));
    Assert.assertTrue(javaCode.contains("HUNKELDUNKEL"));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 6
Source File: JdtBasedProcessorProviderTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testClassLoaderSeesAllDepsFromReferencedProjects() {
  try {
    final IJavaProject libProject = this.xtendProject("libProject");
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package mylib");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Lib {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override String toString() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return \"HUNKELDUNKEL\"");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this.newSource(libProject, "mylib/Lib.xtend", _builder.toString());
    final IJavaProject macroProject = this.xtendProject("macroProject", this.xtendProject("inbetween", libProject));
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package annotation");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtend.lib.macro.AbstractClassProcessor");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtend.lib.macro.Active");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtend.lib.macro.TransformationContext");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@Active(MyAAProcessor)");
    _builder_1.newLine();
    _builder_1.append("annotation MyAA {");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class MyAAProcessor extends AbstractClassProcessor {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("override doTransform(MutableClassDeclaration annotatedClass, extension TransformationContext context) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("annotatedClass.docComment = new mylib.Lib().toString()");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.newSource(macroProject, "annotation/MyAA.xtend", _builder_1.toString());
    IResourcesSetupUtil.waitForBuild();
    final IJavaProject userProject = this.xtendProject("userProject", macroProject);
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("package client");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("@annotation.MyAA");
    _builder_2.newLine();
    _builder_2.append("class SomeClass {");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    this.newSource(userProject, "client/A.xtend", _builder_2.toString());
    IResourcesSetupUtil.cleanBuild();
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
    IResource _file = IResourcesSetupUtil.file("userProject/xtend-gen/client/SomeClass.java");
    final String javaCode = WorkbenchTestHelper.getContentsAsString(((IFile) _file));
    Assert.assertTrue(javaCode.contains("HUNKELDUNKEL"));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 7
Source File: JdtBasedProcessorProviderTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testClassLoaderDoesNotSeeLocalClasses() {
  try {
    final IJavaProject macroProject = this.xtendProject("macroProject");
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package annotation");
    _builder.newLine();
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.AbstractClassProcessor");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.Active");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.TransformationContext");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@Active(MyAAProcessor)");
    _builder.newLine();
    _builder.append("annotation MyAA {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class MyAAProcessor extends AbstractClassProcessor {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override doTransform(MutableClassDeclaration annotatedClass, extension TransformationContext context) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("try {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("Class.forName(\"client.B\")");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("} catch (ClassNotFoundException e) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("annotatedClass.docComment = \'classnotfound\'");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this.newSource(macroProject, "annotation/MyAA.xtend", _builder.toString());
    IResourcesSetupUtil.waitForBuild();
    final IJavaProject userProject = this.xtendProject("userProject", macroProject);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package client;");
    _builder_1.newLine();
    _builder_1.append("public class B {}");
    _builder_1.newLine();
    this.newSource(userProject, "client/B.java", _builder_1.toString());
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("package client");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("@annotation.MyAA");
    _builder_2.newLine();
    _builder_2.append("class SomeClass {");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    this.newSource(userProject, "client/A.xtend", _builder_2.toString());
    IResourcesSetupUtil.cleanBuild();
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
    IResource _file = IResourcesSetupUtil.file("userProject/xtend-gen/client/SomeClass.java");
    final String javaCode = WorkbenchTestHelper.getContentsAsString(((IFile) _file));
    Assert.assertTrue(javaCode.contains("classnotfound"));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}