Java Code Examples for org.eclipse.xtext.xbase.lib.IterableExtensions#head()

The following examples show how to use org.eclipse.xtext.xbase.lib.IterableExtensions#head() . 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
@Test
public void testXtendFunction_5() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo<T> {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo (java.util.List<T> list) {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
    final XtendTypeDeclaration xtendType = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
    this.assertCopyQualifiedName(IterableExtensions.<XtendMember>head(xtendType.getMembers()), "Foo.foo(List<T>)");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 2
@Test
public void testGetElementsByEObject_02() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("Rule: name=ID;");
  _builder.newLine();
  _builder.append("terminal ID: super;");
  _builder.newLine();
  final String grammarAsString = _builder.toString();
  EObject _model = this.getModel(grammarAsString);
  final Grammar grammar = ((Grammar) _model);
  AbstractRule _head = IterableExtensions.<AbstractRule>head(grammar.getRules());
  final SuperCallScope scope = new SuperCallScope(_head);
  final AbstractRule id = GrammarUtil.findRuleForName(grammar, "org.eclipse.xtext.common.Terminals.ID");
  Iterable<IEObjectDescription> _elements = scope.getElements(id);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "org.eclipse.xtext.common.Terminals.ID");
  Pair<String, AbstractRule> _mappedTo = Pair.<String, AbstractRule>of("super.ID", _findRuleForName);
  AbstractRule _findRuleForName_1 = GrammarUtil.findRuleForName(grammar, "org.eclipse.xtext.common.Terminals.ID");
  Pair<String, AbstractRule> _mappedTo_1 = Pair.<String, AbstractRule>of("Lang.ID", _findRuleForName_1);
  AbstractRule _findRuleForName_2 = GrammarUtil.findRuleForName(grammar, "org.eclipse.xtext.common.Terminals.ID");
  Pair<String, AbstractRule> _mappedTo_2 = Pair.<String, AbstractRule>of("test.Lang.ID", _findRuleForName_2);
  this.assertElements(_elements, _mappedTo, _mappedTo_1, _mappedTo_2);
}
 
Example 3
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 4
public <T extends AbstractXtextGeneratorFragment> T initializeFragmentWithGrammarFromString(final Class<T> fragmentClass, final String grammarString) {
  try {
    if ((this.rs == null)) {
      this.rs = this.<XtextResourceSet>get(XtextResourceSet.class);
    }
    final XtextResource resource = this.getResourceFromString(grammarString);
    EObject _head = IterableExtensions.<EObject>head(resource.getContents());
    final Grammar grammar = ((Grammar) _head);
    XtextRuntimeModule _xtextRuntimeModule = new XtextRuntimeModule();
    AbstractGeneratorFragmentTests.FragmentGeneratorModule _fragmentGeneratorModule = new AbstractGeneratorFragmentTests.FragmentGeneratorModule(grammar);
    final Injector generatorInjector = Guice.createInjector(
      Modules2.mixin(_xtextRuntimeModule, _fragmentGeneratorModule));
    final Xtext2EcoreTransformer transformer = new Xtext2EcoreTransformer(grammar);
    transformer.transform();
    final AbstractGeneratorFragmentTests.FakeEMFGeneratorFragment2 emfGeneratorFragment = generatorInjector.<AbstractGeneratorFragmentTests.FakeEMFGeneratorFragment2>getInstance(AbstractGeneratorFragmentTests.FakeEMFGeneratorFragment2.class);
    emfGeneratorFragment.initialize(generatorInjector);
    emfGeneratorFragment.getSaveAndReconcileGenModel(grammar, transformer.getGeneratedPackages(), resource.getResourceSet());
    AbstractGeneratorFragmentTests.lang.setResourceSet(resource.getResourceSet());
    this.rs = null;
    return generatorInjector.<T>getInstance(fragmentClass);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 5
Source Project: xtext-xtend   File: ExtractTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testExtractAnnotation() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("@extract.Extract");
  _builder.newLine();
  _builder.append("class MyClass {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("override doStuff(String myParam) throws IllegalArgumentException {");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("return myParam");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("}");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> {
    @Extension
    final TransformationContext ctx = it.getTransformationContext();
    final MutableInterfaceDeclaration interf = ctx.findInterface("MyClassInterface");
    final MutableClassDeclaration clazz = ctx.findClass("MyClass");
    Assert.assertEquals(IterableExtensions.head(clazz.getImplementedInterfaces()).getType(), interf);
    MutableMethodDeclaration _head = IterableExtensions.head(interf.getDeclaredMethods());
    final Procedure1<MutableMethodDeclaration> _function_1 = (MutableMethodDeclaration it_1) -> {
      Assert.assertEquals("doStuff", it_1.getSimpleName());
      Assert.assertEquals(ctx.getString(), it_1.getReturnType());
      Assert.assertEquals(ctx.newTypeReference(IllegalArgumentException.class), IterableExtensions.head(it_1.getExceptions()));
    };
    ObjectExtensions.<MutableMethodDeclaration>operator_doubleArrow(_head, _function_1);
  };
  this.compilerTester.compile(_builder, _function);
}
 
Example 6
protected TypeReference getGenProposalProviderSuperClass(final Grammar g) {
  TypeReference _xblockexpression = null;
  {
    final Grammar superGrammar = IterableExtensions.<Grammar>head(g.getUsedGrammars());
    TypeReference _xifexpression = null;
    if ((this.isInheritImplementation() && (superGrammar != null))) {
      _xifexpression = this.getProposalProviderClass(superGrammar);
    } else {
      _xifexpression = this.getDefaultGenProposalProviderSuperClass();
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example 7
protected void _internalSet(final String name, final EnumerationValueDeclaration[] values, final boolean mustBeArray) {
  ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(values)), "values");
  EnumerationValueDeclaration _head = IterableExtensions.<EnumerationValueDeclaration>head(((Iterable<EnumerationValueDeclaration>)Conversions.doWrapArray(values)));
  EnumerationTypeDeclaration _declaringType = null;
  if (_head!=null) {
    _declaringType=_head.getDeclaringType();
  }
  String _qualifiedName = null;
  if (_declaringType!=null) {
    _qualifiedName=_declaringType.getQualifiedName();
  }
  this.setValues(name, values, _qualifiedName, mustBeArray);
}
 
Example 8
@Test
public void testIssueCodeDelegation() {
  try {
    final IJavaProject javaProject = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProject(this.testHelper.getProject());
    final String javaSeverity = javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true);
    try {
      boolean _notEquals = (!Objects.equal(javaSeverity, "error"));
      if (_notEquals) {
        Assert.fail((("Wrong expectation Java compiler option \'" + JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE) + "\' should be \'error\' by default"));
      }
      String otherSeverity = "warning";
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("class ValidationClazz {");
      _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("ValidationClazz.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);
      this.cache.clear(xtendFile.eResource());
      javaProject.setOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, otherSeverity);
      this.helper.assertWarning(function.getParameters().get(0), TypesPackage.Literals.JVM_TYPE_REFERENCE, org.eclipse.xtext.xbase.validation.IssueCodes.FORBIDDEN_REFERENCE);
    } finally {
      javaProject.setOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, javaSeverity);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 9
/**
 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=465007
 */
@Test
public void testAnnotation4() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("class MyClass {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("@test.Annotation2 String foo");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("@test.Annotation2(\"hubble\") String foo2");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("@test.Annotation2(value=\"hubble\") String foo3");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
    final AnnotationReference anno = IterableExtensions.head(IterableExtensions.head(it.getTypeLookup().findClass("MyClass").getDeclaredFields()).getAnnotations());
    final AnnotationReference copied = it.getAnnotationReferenceProvider().newAnnotationReference(anno);
    Assert.assertTrue(((JvmAnnotationReferenceImpl) copied).getDelegate().getExplicitValues().isEmpty());
    final AnnotationReference anno2 = IterableExtensions.head((((MutableFieldDeclaration[])Conversions.unwrapArray(it.getTypeLookup().findClass("MyClass").getDeclaredFields(), MutableFieldDeclaration.class))[1]).getAnnotations());
    final AnnotationReference copied2 = it.getAnnotationReferenceProvider().newAnnotationReference(anno2);
    Assert.assertEquals(1, ((JvmAnnotationReferenceImpl) copied2).getDelegate().getExplicitValues().size());
    final AnnotationReference anno3 = IterableExtensions.head((((MutableFieldDeclaration[])Conversions.unwrapArray(it.getTypeLookup().findClass("MyClass").getDeclaredFields(), MutableFieldDeclaration.class))[2]).getAnnotations());
    final AnnotationReference copied3 = it.getAnnotationReferenceProvider().newAnnotationReference(anno3);
    Assert.assertEquals(1, ((JvmAnnotationReferenceImpl) copied3).getDelegate().getExplicitValues().size());
  };
  this.asCompilationUnit(this.validFile(_builder), _function);
}
 
Example 10
@Test
public void testReexported() {
  try {
    final XtendFile xtendFile = this.parse(IResourcesSetupUtil.createFile("thirdProject/src/Dummy.xtend", "class D { allowed.C c }"));
    XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
    final XtendClass c = ((XtendClass) _head);
    this._validationTestHelper.assertNoError(c, IssueCodes.DISCOURAGED_REFERENCE);
    this._validationTestHelper.assertNoError(c, IssueCodes.FORBIDDEN_REFERENCE);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 11
@Test
public void testExplicitRuleCallsAreTracked() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("Rule: name=super::ID name=ID;");
  _builder.newLine();
  _builder.append("terminal ID: super;");
  _builder.newLine();
  _builder.append("terminal _super: \'s\';");
  _builder.newLine();
  final String grammarAsString = _builder.toString();
  final XtextResource resource = this.getResourceFromString(grammarAsString);
  EObject _get = resource.getContents().get(0);
  Grammar grammar = ((Grammar) _get);
  final AbstractRule firstRule = IterableExtensions.<AbstractRule>head(grammar.getRules());
  final RuleCall firstRuleCall = IteratorExtensions.<RuleCall>head(Iterators.<RuleCall>filter(firstRule.eAllContents(), RuleCall.class));
  Assert.assertTrue(firstRuleCall.isExplicitlyCalled());
  final RuleCall secondRuleCall = IteratorExtensions.<RuleCall>last(Iterators.<RuleCall>filter(firstRule.eAllContents(), RuleCall.class));
  Assert.assertFalse(secondRuleCall.isExplicitlyCalled());
  final RuleCall thirdRuleCall = IteratorExtensions.<RuleCall>head(Iterators.<RuleCall>filter(grammar.getRules().get(1).eAllContents(), RuleCall.class));
  Assert.assertTrue(thirdRuleCall.isExplicitlyCalled());
  resource.update(grammarAsString.indexOf("_super"), 1, " ");
  Assert.assertEquals(resource, firstRuleCall.eResource());
  Assert.assertEquals(resource, secondRuleCall.eResource());
  Assert.assertEquals(resource, thirdRuleCall.eResource());
  resource.getContents();
  Assert.assertFalse(thirdRuleCall.isExplicitlyCalled());
  Assert.assertEquals(IterableExtensions.<AbstractRule>last(grammar.getRules()), thirdRuleCall.getRule());
}
 
Example 12
@Test
public void testConstants_WithStaticImport_01() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static test.Constants1.* ");
    _builder.newLine();
    _builder.append("import static MyConstants.*");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class C { ");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val someString = STRING_CONSTANT+\'-\'+MY_CONST");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class MyConstants {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static val MY_CONST = STRING_CONSTANT");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    final XtendField stringField = IterableExtensions.<XtendField>head(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class));
    Assert.assertEquals(((Constants1.STRING_CONSTANT + "-") + Constants1.STRING_CONSTANT), this.interpreter.evaluate(stringField.getInitialValue(), null));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 13
@Test
public void testJvmOperation() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo(java.util.List<String> list) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("list.clear");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("list.add(null)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
    final XtendTypeDeclaration xtendType = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
    XtendMember _head = IterableExtensions.<XtendMember>head(xtendType.getMembers());
    XExpression _expression = ((XtendFunction) _head).getExpression();
    final XBlockExpression expression = ((XBlockExpression) _expression);
    this.assertCopyQualifiedName(expression.getExpressions().get(0), "java.util.List.clear()");
    this.assertCopyQualifiedName(expression.getExpressions().get(1), "java.util.List.add(String)");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 14
protected void checkTypeInsertionOffset(final CharSequence model) {
  try {
    final String modelAsString = model.toString();
    final int caretOffset = modelAsString.replace("$", "").indexOf("|");
    final int expectedOffset = modelAsString.replace("|", "").indexOf("$");
    XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.parseHelper.parse(modelAsString.replace("|", "").replace("$", "")).getXtendTypes());
    final XtendClass xtendClass = ((XtendClass) _head);
    Resource _eResource = xtendClass.eResource();
    final XtextResource xtextResource = ((XtextResource) _eResource);
    final EObject caretElement = this._eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, caretOffset);
    Assert.assertEquals(expectedOffset, this._insertionOffsets.getNewTypeInsertOffset(caretElement, xtendClass));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 15
protected IFeatureCallArguments toArguments(final String signature, final String invocation, final boolean receiver) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def void m(");
    _builder.append(signature);
    _builder.append(") {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("m(");
    _builder.append(invocation, "\t");
    _builder.append(")");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    _builder.newLine();
    final String functionString = _builder.toString();
    final XtendFunction function = this.function(functionString);
    XExpression _expression = function.getExpression();
    final XBlockExpression body = ((XBlockExpression) _expression);
    XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
    final XFeatureCall featureCall = ((XFeatureCall) _head);
    final EList<XExpression> arguments = featureCall.getFeatureCallArguments();
    final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
    final IFeatureCallArguments result = this.factory.createStandardArguments(arguments, operation.getParameters(), receiver, this.getOwner());
    Class<? extends IFeatureCallArguments> _class = result.getClass();
    boolean _equals = Objects.equal(_class, StandardFeatureCallArguments.class);
    Assert.assertTrue(_equals);
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 16
@Test
public void testXtendFunction_2() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo(java.util.Map<? extends String, ? extends String> map) {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def <K, V> void bar(java.util.Map<K, V> map) {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
    final XtendTypeDeclaration xtendType = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
    this.assertCopyQualifiedName(IterableExtensions.<XtendMember>head(xtendType.getMembers()), "Foo.foo(Map<? extends String, ? extends String>)");
    this.assertCopyQualifiedName(IterableExtensions.<XtendMember>head(IterableExtensions.<XtendMember>tail(xtendType.getMembers())), "Foo.bar(Map<K, V>)");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 17
@Test
public void testAnonymousClass_01() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def foo() {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("new Runnable() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("int field");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("override run() {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(this.function(_builder.toString()));
    this.typeResolver.resolveTypes(operation.eResource());
    Assert.assertEquals(1, operation.getLocalClasses().size());
    final JvmGenericType anonymous = IterableExtensions.<JvmGenericType>head(operation.getLocalClasses());
    Assert.assertTrue(anonymous.isFinal());
    Assert.assertFalse(anonymous.isStatic());
    Assert.assertTrue(anonymous.isLocal());
    Assert.assertFalse(anonymous.isAnonymous());
    Assert.assertEquals(JvmVisibility.DEFAULT, anonymous.getVisibility());
    Assert.assertEquals(2, anonymous.getSuperTypes().size());
    Assert.assertEquals("java.lang.Runnable", IterableExtensions.<JvmTypeReference>last(anonymous.getSuperTypes()).getQualifiedName());
    Assert.assertEquals(3, anonymous.getMembers().size());
    final JvmMember constructor = IterableExtensions.<JvmMember>last(anonymous.getMembers());
    Assert.assertTrue((constructor instanceof JvmConstructor));
    Assert.assertEquals(0, ((JvmConstructor) constructor).getParameters().size());
    JvmMember _head = IterableExtensions.<JvmMember>head(anonymous.getMembers());
    Assert.assertTrue((_head instanceof JvmField));
    final JvmMember overriding = anonymous.getMembers().get(1);
    Assert.assertTrue((overriding instanceof JvmOperation));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 18
@Override
protected Integer head(Iterable<Integer> input) {
	return IterableExtensions.head(input);
}
 
Example 19
Source Project: xtext-xtend   File: ErrorTest.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testErrorModel_017() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import static extension Throwables.*");
  _builder.newLine();
  _builder.append("import java.net.URI");
  _builder.newLine();
  _builder.newLine();
  _builder.append("class Throwables {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("def static <T> T propagate(()=>T proc, (Exception)=>Exception handler) {");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("try {");
  _builder.newLine();
  _builder.append("\t\t\t");
  _builder.append("proc.apply");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("} catch(Exception e) {");
  _builder.newLine();
  _builder.append("\t\t\t");
  _builder.append("throw handler.apply(e)");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("}");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("}");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  _builder.append("class Client {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("valuri = [| new URI(\'\')].propagate [ new IllegalArgumentException(it) ]");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final XtendFile file = this.processWithoutException(_builder);
  final XtendTypeDeclaration client = IterableExtensions.<XtendTypeDeclaration>last(file.getXtendTypes());
  XtendMember _head = IterableExtensions.<XtendMember>head(client.getMembers());
  final XtendField field = ((XtendField) _head);
  XExpression _initialValue = field.getInitialValue();
  final XMemberFeatureCall initializer = ((XMemberFeatureCall) _initialValue);
  XExpression _head_1 = IterableExtensions.<XExpression>head(initializer.getMemberCallArguments());
  final XClosure closure = ((XClosure) _head_1);
  final JvmFormalParameter implicit = IterableExtensions.<JvmFormalParameter>head(closure.getImplicitFormalParameters());
  Assert.assertNotNull(implicit);
  final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(implicit);
  Assert.assertNotNull(resolvedTypes.getActualType(implicit));
}
 
Example 20
@Test
public void testBug403563() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("package myannotation");
  _builder.newLine();
  _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.AbstractClassProcessor");
  _builder.newLine();
  _builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration");
  _builder.newLine();
  _builder.newLine();
  _builder.append("@Active(ThrowExceptionAnnotationProcessor)");
  _builder.newLine();
  _builder.append("annotation ThrowExceptionAnnotation{ }");
  _builder.newLine();
  _builder.append("class ThrowExceptionAnnotationProcessor extends AbstractClassProcessor {");
  _builder.newLine();
  _builder.newLine();
  _builder.append("\t");
  _builder.append("override doTransform(MutableClassDeclaration clazz, extension TransformationContext context) {");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("throw new IllegalStateException");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("}");
  _builder.newLine();
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/ThrowExceptionAnnotationProcessor.xtend", _builder.toString());
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("package myusercode");
  _builder_1.newLine();
  _builder_1.newLine();
  _builder_1.append("@myannotation.ThrowExceptionAnnotation class MyClass {");
  _builder_1.newLine();
  _builder_1.append("}");
  _builder_1.newLine();
  Pair<String, String> _mappedTo_1 = Pair.<String, String>of("myusercode/UserCode.xtend", _builder_1.toString());
  final Procedure1<List<Issue>> _function = (List<Issue> it) -> {
    Assert.assertEquals(1, it.size());
    final Issue error = IterableExtensions.<Issue>head(it);
    Assert.assertNotNull(error);
    Assert.assertEquals(IssueCodes.PROCESSING_ERROR, error.getCode());
    Assert.assertTrue(error.getMessage().contains(IllegalStateException.class.getName()));
    Assert.assertFalse(error.getMessage().contains(AnnotationProcessor.class.getName()));
  };
  this.assertIssues(_mappedTo, _mappedTo_1, _function);
}