Java Code Examples for org.eclipse.xtext.xbase.lib.Exceptions

The following examples show how to use org.eclipse.xtext.xbase.lib.Exceptions. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: xtext-xtend   Source File: JavaFileConverterTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public JavaConverter.ConversionResult converToXtend(final String unitName, final String javaCode) {
  try {
    final JavaConverter j2x = this.javaConverter.get();
    JavaConverter.ConversionResult result = j2x.toXtend(unitName, javaCode);
    int _size = IterableExtensions.size(result.getProblems());
    boolean _equals = (_size == 0);
    if (_equals) {
      try {
        this.file(result.getXtendCode(), true);
      } catch (final Throwable _t) {
        if (_t instanceof AssertionError) {
          result = j2x.useRobustSyntax().toXtend(unitName, javaCode);
        } else {
          throw Exceptions.sneakyThrow(_t);
        }
      }
    }
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 2
Source Project: xtext-eclipse   Source File: ValidationTests.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testExplicitGetterReplacesTheGeneratedOne() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("entity E {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("name : String");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("op getName() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return name");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this._validationTestHelper.assertNoErrors(this._parseHelper.parse(_builder));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 3
Source Project: xtext-xtend   Source File: LambdaValidationTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testIncompatibleParameterType_01() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val I<Integer> f = [String k| 1]");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("interface I<T> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def T m(int u);");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this._validationTestHelper.assertError(this.file(_builder.toString()), XbasePackage.Literals.XCLOSURE, IssueCodes.INCOMPATIBLE_TYPES, "Type mismatch: cannot convert from (String)=>int to I<Integer>");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 4
Source Project: xtext-core   Source File: RequestManagerTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testRunReadLogException() {
  final Runnable _function = () -> {
    final Function1<CancelIndicator, Object> _function_1 = (CancelIndicator it) -> {
      throw new RuntimeException();
    };
    final CompletableFuture<Object> future = this.requestManager.<Object>runRead(_function_1);
    try {
      future.join();
    } catch (final Throwable _t) {
      if (_t instanceof Exception) {
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  };
  final LoggingTester.LogCapture logResult = LoggingTester.captureLogging(Level.ALL, ReadRequest.class, _function);
  logResult.assertLogEntry("Error during request:");
}
 
Example 5
Source Project: xtext-extras   Source File: XbaseValidationTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testUnreachableCatchClause_4() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("try {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("} catch (java.io.FileNotFoundException e) {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("} catch (java.io.IOException e) {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("} catch (Exception e) {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this._validationTestHelper.assertNoErrors(this.expression(_builder));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 6
@Test
public void testSuperClassWithoutEquals() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import org.eclipse.xtend.lib.annotations.EqualsHashCode");
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("@EqualsHashCode class Bar extends Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("String bar = \"Foo\"");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
      Assert.assertFalse(it.getGeneratedCode("Bar"), it.getGeneratedCode("Bar").contains("super.equals"));
      Assert.assertFalse(it.getGeneratedCode("Bar").contains("super.hashCode"));
    };
    this.compilationTestHelper.compile(_builder, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 7
Source Project: xtext-core   Source File: CliProjectsCreatorMain.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public static void main(final String[] args) {
	CliProjectsCreatorMain bean = new CliProjectsCreatorMain();
	CliProjectsCreator projectsCreator = new CliProjectsCreator();
	CmdLineParser parser = new CmdLineParser(bean);
	try {
		parser.parseArgument(args);
		final WizardConfiguration config = bean.createProjectConfig();
		projectsCreator.setLineDelimiter(config.getLineDelimiter());
		projectsCreator.createProjects(config);
		LOG.info(String.format("Created projects for language %s in %s", config.getLanguage().getName(), config.getRootLocation()));
	} catch (final Throwable _t) {
		if (_t instanceof CmdLineException) {
			final CmdLineException e = (CmdLineException) _t;
			System.err.println(e.getMessage());
			parser.printUsage(System.err);
		} else {
			throw Exceptions.sneakyThrow(_t);
		}
	}
}
 
Example 8
Source Project: xtext-extras   Source File: JvmTypesBuilderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testAnnotationDefaultValue() {
  try {
    final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE;
    final XExpression e = this.expression("\'Foo\'");
    final XAnnotation anno = f.createXAnnotation();
    JvmType _findDeclaredType = this.references.findDeclaredType(Named.class, e);
    anno.setAnnotationType(((JvmAnnotationType) _findDeclaredType));
    anno.setValue(e);
    final JvmGenericType type = this.typesFactory.createJvmGenericType();
    this._jvmTypesBuilder.addAnnotation(type, anno);
    Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation());
    JvmAnnotationValue _head = IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues());
    EObject _head_1 = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) _head).getValues());
    Assert.assertTrue((_head_1 instanceof XStringLiteral));
    Assert.assertNull(IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues()).getOperation());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 9
Source Project: xtext-xtend   Source File: OldDataCompilerTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSuperClassWithTypeParameters() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("@Data class Foo<T> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("T foo");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("@Data class Bar extends Foo<String> {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
      Assert.assertTrue(it.getGeneratedCode("Bar").contains("public Bar(final String foo) {"));
    };
    this.compilationTestHelper.compile(_builder, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 10
@Override
public NameEnvironmentAnswer findType(final char[][] compoundTypeName) {
  try {
    final Function1<char[], String> _function = (char[] it) -> {
      return String.valueOf(it);
    };
    String _join = IterableExtensions.join(ListExtensions.<char[], String>map(((List<char[]>)Conversions.doWrapArray(compoundTypeName)), _function), "/");
    final String fileName = (_join + ".class");
    boolean _containsKey = this.cache.containsKey(fileName);
    if (_containsKey) {
      return this.cache.get(fileName);
    }
    final URL url = this.classLoader.getResource(fileName);
    if ((url == null)) {
      this.cache.put(fileName, null);
      return null;
    }
    final ClassFileReader reader = ClassFileReader.read(url.openStream(), fileName);
    final NameEnvironmentAnswer result = new NameEnvironmentAnswer(reader, null);
    this.cache.put(fileName, result);
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 11
Source Project: xtext-extras   Source File: XbaseValidationTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testRedundantCases_05() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("switch i : 1 {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("case 1,");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("case 2: 1");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this._validationTestHelper.assertNoIssue(this.expression(_builder), XbasePackage.Literals.XCASE_PART, IssueCodes.REDUNDANT_CASE);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 12
protected Object _internalEvaluate(final XNumberLiteral it, final Context ctx) {
  try {
    Number _xblockexpression = null;
    {
      Class<? extends Number> _xifexpression = null;
      JvmTypeReference _expectedType = ctx.getExpectedType();
      boolean _tripleEquals = (_expectedType == null);
      if (_tripleEquals) {
        _xifexpression = this.numberLiterals.getJavaType(it);
      } else {
        Class<?> _javaType = this.getJavaType(ctx.getExpectedType().getType(), ctx.getClassFinder());
        _xifexpression = ((Class<? extends Number>) _javaType);
      }
      final Class<? extends Number> type = _xifexpression;
      _xblockexpression = this.numberLiterals.numberValue(it, type);
    }
    return _xblockexpression;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 13
protected void evaluatesWithException(final String expression, final Procedure1<? super ConstantExpressionEvaluationException> exceptionAssertions) {
  try {
    final XtendFunction function = this.function((("def void testFoo() { " + expression) + " }"));
    XExpression _expression = function.getExpression();
    final XExpression expr = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions());
    try {
      this.interpreter.evaluate(expr, null);
      Assert.fail("exception expected");
    } catch (final Throwable _t) {
      if (_t instanceof ConstantExpressionEvaluationException) {
        final ConstantExpressionEvaluationException e = (ConstantExpressionEvaluationException)_t;
        exceptionAssertions.apply(e);
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 14
@Test
public void testDeleteElement() {
  try {
    this._parseHelper.parse("foo", this.fooURI, this.rs1).eResource().getContents().clear();
    final Function1<IEObjectDescription, String> _function = (IEObjectDescription it) -> {
      return it.getQualifiedName().toString();
    };
    Assert.assertEquals("", IterableExtensions.join(IterableExtensions.<IEObjectDescription, String>map(this.fooContainer.getExportedObjects(), _function), ","));
    Assert.assertEquals(1, IterableExtensions.size(this.fooContainer.getResourceDescriptions()));
    Assert.assertEquals(1, this.fooContainer.getResourceDescriptionCount());
    Assert.assertEquals(0, IterableExtensions.size(this.fooContainer.getExportedObjects()));
    Assert.assertEquals(1, IterableExtensions.size(this.barContainer.getResourceDescriptions()));
    Assert.assertEquals(1, this.barContainer.getResourceDescriptionCount());
    this.assertGlobalDescriptionsAreUnaffected();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 15
protected void linksTo(final String invocation, final String method) {
  try {
    final XtendFile file = this.file(this.inMethodBody(invocation), false);
    XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    final XtendClass c = ((XtendClass) _head);
    XtendMember _head_1 = IterableExtensions.<XtendMember>head(c.getMembers());
    final XtendFunction m = ((XtendFunction) _head_1);
    XExpression _expression = m.getExpression();
    final XBlockExpression body = ((XBlockExpression) _expression);
    XExpression _last = IterableExtensions.<XExpression>last(body.getExpressions());
    final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
    JvmIdentifiableElement _feature = featureCall.getFeature();
    final JvmOperation operation = ((JvmOperation) _feature);
    final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, file);
    final ParameterizedTypeReference declaration = owner.newParameterizedTypeReference(operation.getDeclaringType());
    final BottomResolvedOperation resolved = new BottomResolvedOperation(operation, declaration, this.overrideTester);
    Assert.assertEquals(method, resolved.getSimpleSignature());
    Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty());
    Assert.assertNull(featureCall.getImplicitReceiver());
    Assert.assertNull(featureCall.getImplicitFirstArgument());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 16
Source Project: xtext-xtend   Source File: Java8ValidationTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testRedeclaredMethodFromObject() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("interface A {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override String toString()");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class C implements A {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this._validationTestHelper.assertNoErrors(this.file(_builder.toString()));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 17
Source Project: xtext-extras   Source File: XbaseValidationTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testUnreachableCase_8() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("switch new java.util.ArrayList<String> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("java.util.List: \"list of integers\"");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("java.util.List<String>: \"list of strings\"");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("default: \"something else\"");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this._validationTestHelper.assertError(this.expression(_builder), TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE, IssueCodes.UNREACHABLE_CASE);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 18
@Test
public void testEmptyProject() {
  try {
    final IProject project = IResourcesSetupUtil.createProject("MyProject");
    IResourcesSetupUtil.addNature(project, XtextProjectHelper.NATURE_ID);
    final ResourceSet rs = this.liveScopeResourceSetProvider.get(project);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("container MyProject isEmpty=true {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String expected = _builder.toString();
    Assert.assertEquals(expected, this.formatContainers(rs));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 19
Source Project: xtext-extras   Source File: XbaseValidationTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDuplicateCases_int() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("switch x : 1 {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("case 1: 1");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("case 1: 1");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this._validationTestHelper.assertError(this.expression(_builder), XbasePackage.Literals.XNUMBER_LITERAL, IssueCodes.DUPLICATE_CASE);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 20
@Test
public void testForbiddenArrayTypeUsage() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def bar(org.eclipse.xtend.core.tests.restricted.RestrictedClass[] x) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile xtendFile = this.testHelper.xtendFile("Clazz.xtend", _builder.toString());
    XtendMember _head = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers());
    final XtendFunction function = ((XtendFunction) _head);
    this.helper.assertError(function.getParameters().get(0), TypesPackage.Literals.JVM_TYPE_REFERENCE, org.eclipse.xtext.xbase.validation.IssueCodes.FORBIDDEN_REFERENCE);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 21
Source Project: xtext-eclipse   Source File: ValidationTests.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testImportUnused_1() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import java.util.List");
    _builder.newLine();
    _builder.append("entity X {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("sb: java.util.List<String>");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this._validationTestHelper.assertWarning(this._parseHelper.parse(_builder), XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 22
@Test
public void testAnnotationValues() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("@test.Annotation([email protected](\'foo\'))");
    _builder.newLine();
    _builder.append("class C { ");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    final XAnnotationElementValuePair pair = IterableExtensions.<XAnnotationElementValuePair>head(IterableExtensions.<XAnnotation>head(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getAnnotations()).getElementValuePairs());
    Object _evaluate = this.interpreter.evaluate(pair.getValue(), pair.getElement().getReturnType());
    final XAnnotation anno = ((XAnnotation) _evaluate);
    Assert.assertEquals("test.Annotation2", anno.getAnnotationType().getIdentifier());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 23
Source Project: xtext-eclipse   Source File: ValidationTests.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDuplicatedOperationWithDifferentSignatureIsAllowed() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("entity E {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("op m(int i) {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("op m() {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this._validationTestHelper.assertNoErrors(this._parseHelper.parse(_builder));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 24
@Test
public void testParsing() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package example {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("entity MyEntity {");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("property : String");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final DomainModel model = this._parseHelper.parse(_builder);
    AbstractElement _head = IterableExtensions.<AbstractElement>head(model.getElements());
    final PackageDeclaration pack = ((PackageDeclaration) _head);
    Assert.assertEquals("example", pack.getName());
    AbstractElement _head_1 = IterableExtensions.<AbstractElement>head(pack.getElements());
    final Entity entity = ((Entity) _head_1);
    Assert.assertEquals("MyEntity", entity.getName());
    Feature _head_2 = IterableExtensions.<Feature>head(entity.getFeatures());
    final Property property = ((Property) _head_2);
    Assert.assertEquals("property", property.getName());
    Assert.assertEquals("java.lang.String", property.getType().getIdentifier());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 25
Source Project: xtext-xtend   Source File: CustomClassesTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testInterfaceFinalAndStatic() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("interface Foo {}");
    Assert.assertFalse(this.interfaze(_builder.toString()).isFinal());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("interface Foo {}");
    Assert.assertFalse(this.interfaze(_builder_1.toString()).isStatic());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 26
Source Project: xtext-xtend   Source File: JavaIoFileSystemTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void assertToURI(final Path file, final String expectedContent) {
  final URI uri = this.fs.toURI(file);
  Assert.assertNotNull(uri);
  try {
    final File javaIoFile = new File(uri);
    Assert.assertTrue(javaIoFile.exists());
    long _length = javaIoFile.length();
    final byte[] data = new byte[((int) _length)];
    final FileInputStream fis = new FileInputStream(javaIoFile);
    fis.read(data);
    fis.close();
    String _string = new String(data);
    Assert.assertEquals(expectedContent, _string);
  } catch (final Throwable _t) {
    if (_t instanceof Exception) {
      final Exception e = (Exception)_t;
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("URI: ");
      _builder.append(uri);
      _builder.append("; ");
      String _message = e.getMessage();
      _builder.append(_message);
      Assert.fail(_builder.toString());
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
Example 27
Source Project: xtext-xtend   Source File: ImportedNamesTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testNestedTypesIncluded() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package foo");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val foo = types.StaticOuterClass.StaticMiddleClass.StaticInnerClass.CONSTANT");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource());
    final Iterable<QualifiedName> importedNames = description.getImportedNames();
    final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
      String _string = it.toString();
      String _lowerCase = "types.StaticOuterClass$StaticMiddleClass$StaticInnerClass".toLowerCase();
      return Boolean.valueOf(Objects.equal(_string, _lowerCase));
    };
    Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 28
Source Project: xtext-xtend   Source File: TestBatchCompiler.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private String getContents(final String fileName) {
  try {
    File _file = new File(fileName);
    return com.google.common.io.Files.asCharSource(_file, Charsets.UTF_8).read();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 29
@Test
public void testSignatureForXtendFunction() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package testPackage");
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def bar(String a) throws NullPointerException { }");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void bar(String a, int b) throws NullPointerException, RuntimeException {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
    final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
    final XtendMember xtendFunction1 = clazz.getMembers().get(0);
    final XtendMember xtendFunction2 = clazz.getMembers().get(1);
    final String signature1 = this.signatureProvider.getSignature(xtendFunction1);
    final String signature2 = this.signatureProvider.getSignature(xtendFunction2);
    Assert.assertEquals("Object bar(String a) throws NullPointerException", signature1);
    Assert.assertEquals("void bar(String a, int b) throws NullPointerException, RuntimeException", signature2);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 30
Source Project: xtext-xtend   Source File: NewDataCompilerTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testWithCreateExtension() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import org.eclipse.xtend.lib.annotations.Data");
    _builder.newLine();
    _builder.append("@Data class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def create {} foo() {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String text = _builder.toString();
    this._validationTestHelper.assertNoIssues(this.clazz(text));
    final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
      final Function1<Method, Boolean> _function_1 = (Method it_1) -> {
        return Boolean.valueOf(it_1.getName().startsWith("get"));
      };
      Assert.assertFalse(IterableExtensions.<Method>exists(((Iterable<Method>)Conversions.doWrapArray(it.getCompiledClass().getDeclaredMethods())), _function_1));
    };
    this.compilationTestHelper.compile(text, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}