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

The following examples show how to use org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil#assertNoErrorsInWorkspace() . 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: Bug462047Test.java    From xtext-eclipse with Eclipse Public License 2.0 7 votes vote down vote up
@Test
public void testNoErrors() throws Exception {
	IResourcesSetupUtil.createFile("bug462047/src/a.bug462047lang", "element CORE ref CORE.b");
	IFile file = IResourcesSetupUtil.createFile("bug462047/src/b.bug462047lang", "element b ref CORE.c");
	IResourcesSetupUtil.createFile("bug462047/src/c.bug462047lang", "element c");
	IResourcesSetupUtil.waitForBuild();
	IResourcesSetupUtil.assertNoErrorsInWorkspace();
	LoggingTester.captureLogging(Level.ERROR, BatchLinkableResource.class, ()-> {
		
		try {
			XtextEditor editor = openEditor(file);
			IXtextDocument document = editor.getDocument();
			document.readOnly((XtextResource res)->{
				EcoreUtil.resolveAll(res);
				ResourceSet resourceSet = res.getResourceSet();
				assertNull(resourceSet.getResource(URI.createURI("java:/Objects/CORE.CORE"), false));
				return null;
			});
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}).assertNoLogEntries();
}
 
Example 2
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 3
Source File: SameClassNamesTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDuplicateNames_04() {
  try {
    final IJavaProject javaProject = JavaCore.create(this.second);
    final IClasspathEntry[] cp = javaProject.getRawClasspath();
    final List<IClasspathEntry> reversed = ListExtensions.<IClasspathEntry>reverse(((List<IClasspathEntry>)Conversions.doWrapArray(cp)));
    javaProject.setRawClasspath(((IClasspathEntry[])Conversions.unwrapArray(reversed, IClasspathEntry.class)), null);
    IResourcesSetupUtil.reallyWaitForAutoBuild();
    this.testHelper.createFileImpl("first/src/com/acme/A.xtend", "package com.acme class A { new(String s) {} }");
    this.testHelper.createFileImpl("second/src/com/acme/A.xtend", "package com.acme class A { new(int i) {} }");
    this.testHelper.createFileImpl("second/src/com/acme/B.xtend", "package com.acme class B extends A { new() { super(1) } }");
    this.testHelper.createFileImpl("third/src/com/acme/A.xtend", "package com.acme class A {}");
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 4
Source File: WorkspaceScenariosTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testJarWithEverything() {
  try {
    final Function1<String, Boolean> _function = (String it) -> {
      return Boolean.valueOf(false);
    };
    final IProject project = this.createProjectWithJarDependency(_function);
    try {
      IResourcesSetupUtil.assertNoErrorsInWorkspace();
      Assert.assertEquals(1, ((Object[])Conversions.unwrapArray(this.persistedResourceDescriptions.get().getAllResourceDescriptions(), Object.class)).length);
    } finally {
      project.delete(true, true, null);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 5
Source File: SameClassNamesTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDuplicateNames_03() {
  try {
    this.testHelper.createFileImpl("first/src/com/acme/A.xtend", "package com.acme class A { new(String s) {} }");
    this.testHelper.createFileImpl("second/src/com/acme/A.xtend", "package com.acme class A { new(int i) {} }");
    this.testHelper.createFileImpl("second/src/com/acme/B.xtend", "package com.acme class B extends A { new() { super(1) } }");
    this.testHelper.createFileImpl("third/src/com/acme/A.xtend", "package com.acme class A {}");
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 6
Source File: SameClassNamesTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDuplicateNames_02() {
  try {
    this.testHelper.createFileImpl("first/src/com/acme/A.xtend", "package com.acme class A { def static void m1() {} }");
    this.testHelper.createFileImpl("first/src/com/acme/B.xtend", "package com.acme class B { new() { A.m1 } }");
    this.testHelper.createFileImpl("second/src/com/acme/B.xtend", "package com.acme class B {}");
    this.testHelper.createFileImpl("third/src/com/acme/A.xtend", "package com.acme class A { def static void m2() {} }");
    this.testHelper.createFileImpl("third/src/com/acme/B.xtend", "package com.acme class B { new() { A.m2 } }");
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 7
Source File: SameClassNamesTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDuplicateNames_01() {
  try {
    this.testHelper.createFileImpl("first/src/com/acme/A.xtend", "package com.acme class A { new(int i) {} }");
    this.testHelper.createFileImpl("second/src/com/acme/B.xtend", "package com.acme class B extends A { new() { super(1) } }");
    this.testHelper.createFileImpl("third/src/com/acme/A.xtend", "package com.acme class A {}");
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 8
Source File: SameClassNamesTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testNoDuplicateNames() {
  try {
    this.testHelper.createFileImpl("first/src/com/acme/A.xtend", "package com.acme class A {}");
    this.testHelper.createFileImpl("second/src/com/acme/B.xtend", "package com.acme class B {}");
    this.testHelper.createFileImpl("third/src/com/acme/C.xtend", "package com.acme class C {}");
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 9
Source File: Bug457681Test.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testDaBug_NoAnnotationOnA() {
  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("if(annotatedClass.extendedClass.declaredSuperTypes.empty) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("annotatedClass.addError(\"Supertype must declare a supertype\")");
    _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());
    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_1 = new StringConcatenation();
    _builder_1.append("package client");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("import client.sub.B");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class A implements Cloneable {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("public B sub");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.newSource(userProject, "client/A.xtend", _builder_1.toString());
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("package client.sub");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("import annotation.MyAA");
    _builder_2.newLine();
    _builder_2.append("import client.A");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("@MyAA");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("class B extends A {");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    this.newSource(userProject, "client/sub/B.xtend", _builder_2.toString());
    IResourcesSetupUtil.cleanBuild();
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 10
Source File: WorkspaceScenariosTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testIncrementalChangeOnBidirectionalDep() {
  try {
    WorkbenchTestHelper.createPluginProject("my.project", "org.eclipse.xtext.xbase.lib", "org.eclipse.xtend.lib");
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package mypack");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class ClassA {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void myMethod(ClassB b) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("b.myMethod");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final IFile fileA = IResourcesSetupUtil.createFile("my.project/src/mypack/ClassA.xtend", _builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package mypack");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class ClassB {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def void anotherMethod(ClassA a) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("a.anotherMethod");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    IResourcesSetupUtil.createFile("my.project/src/mypack/ClassB.xtend", _builder_1.toString());
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
    final IFile javaB = fileA.getProject().getFile("xtend-gen/mypack/ClassB.java");
    Assert.assertTrue(WorkbenchTestHelper.getContentsAsString(javaB).contains("anotherMethod(a);"));
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("package mypack");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("class ClassA {");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("def void myMethod(ClassB b) {");
    _builder_2.newLine();
    _builder_2.append("\t\t");
    _builder_2.append("b.myMethod");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("def void anotherMethod() {}");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    StringInputStream _stringInputStream = new StringInputStream(_builder_2.toString());
    fileA.setContents(_stringInputStream, true, true, null);
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
    Assert.assertTrue(WorkbenchTestHelper.getContentsAsString(javaB).contains("a.anotherMethod();"));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 11
Source File: Bug457681Test.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testDaBug_1() {
  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("if(annotatedClass.extendedClass.declaredSuperTypes.empty) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("annotatedClass.addError(\"Supertype must declare a supertype\")");
    _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());
    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_1 = new StringConcatenation();
    _builder_1.append("package client");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("import client.sub.B");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("class A implements Cloneable {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("public B sub");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.newSource(userProject, "client/A.xtend", _builder_1.toString());
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("package client.sub");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("import annotation.MyAA");
    _builder_2.newLine();
    _builder_2.append("import client.A");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("@MyAA");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("class B extends A {");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    this.newSource(userProject, "client/sub/B.xtend", _builder_2.toString());
    IResourcesSetupUtil.cleanBuild();
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 12
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);
  }
}
 
Example 13
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 14
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 15
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 16
Source File: MoreActiveAnnotationsTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testBug473689() {
  try {
    final IJavaProject someUnrelatedProject = JavaCore.create(WorkbenchTestHelper.createPluginProject("unrelatedProject"));
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package org.eclipse.xtend.lib.annotations");
    _builder.newLine();
    _builder.newLine();
    _builder.append("annotation Accessors {}");
    _builder.newLine();
    this.newSource(someUnrelatedProject, "org/eclipse/xtend/lib/annotations/Accessors.xtend", _builder.toString());
    IResourcesSetupUtil.waitForBuild();
    final IJavaProject macroProject = JavaCore.create(WorkbenchTestHelper.createPluginProject("macroProject"));
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package mysource");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtend.lib.annotations.Accessors");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class Foo {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("@Accessors String name");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def void someMethod(Foo foo) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("foo.setName(foo.getName)");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.newSource(macroProject, "mysource/Foo.xtend", _builder_1.toString());
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 17
Source File: MoreActiveAnnotationsTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testBug461761_01() {
  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.RegisterGlobalsContext");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.declaration.ClassDeclaration");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@Active(DItemMiniProcessor)");
    _builder.newLine();
    _builder.append("annotation DItemMini {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("String value");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class DItemMiniProcessor extends AbstractClassProcessor {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override doRegisterGlobals(ClassDeclaration annotatedClass, extension RegisterGlobalsContext context) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val suffix = annotatedClass.annotations.head.getValue(\"value\")");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("registerClass(annotatedClass.qualifiedName + suffix)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this.newSource(macroProject, "annotation/DItemMini.xtend", _builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package annotation");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class StaticFeatures {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("public static final String BAR = \"Bar\"");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("public static final String FOOBAR = \"Foo\" + BAR ");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.newSource(macroProject, "annotation/StaticFeatures.xtend", _builder_1.toString());
    boolean _addExportedPackages = WorkbenchTestHelper.addExportedPackages(macroProject.getProject(), "annotation");
    if (_addExportedPackages) {
      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("import static annotation.StaticFeatures.FOOBAR");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("@annotation.DItemMini(FOOBAR)");
    _builder_2.newLine();
    _builder_2.append("class UserCode{");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("UserCodeFooBar item");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    this.newSource(userProject, "client/UserCode.xtend", _builder_2.toString());
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 18
Source File: MoreActiveAnnotationsTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testBug461761() {
  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.RegisterGlobalsContext");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.declaration.ClassDeclaration");
    _builder.newLine();
    _builder.append("import static extension com.google.common.io.Files.append");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@Active(DItemMiniProcessor)");
    _builder.newLine();
    _builder.append("annotation DItemMini {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class DItemMiniProcessor extends AbstractClassProcessor {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override doRegisterGlobals(ClassDeclaration annotatedClass, extension RegisterGlobalsContext context) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("registerClass(annotatedClass.qualifiedName + \"Item\")");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this.newSource(macroProject, "annotation/DItemMini.xtend", _builder.toString());
    boolean _addExportedPackages = WorkbenchTestHelper.addExportedPackages(macroProject.getProject(), "annotation");
    if (_addExportedPackages) {
      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_1 = new StringConcatenation();
    _builder_1.append("package client");
    _builder_1.newLine();
    _builder_1.append("@annotation.DItemMini");
    _builder_1.newLine();
    _builder_1.append("class UserCode{");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("UserCodeItem item");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.newSource(userProject, "client/UserCode.xtend", _builder_1.toString());
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}