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

The following examples show how to use org.eclipse.xtext.xbase.lib.ObjectExtensions. 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 check out the related API usage on the sidebar.
Example 1
protected List<Class<?>> getExtensionClasses() {
	return Lists.<Class<?>> newArrayList(
		ArrayExtensions.class,
		BigDecimalExtensions.class,
		BigIntegerExtensions.class,
		BooleanExtensions.class,
		ByteExtensions.class,
		CharacterExtensions.class,
		CollectionExtensions.class,
		ComparableExtensions.class,
		DoubleExtensions.class,
		FloatExtensions.class,
		FunctionExtensions.class,
		IntegerExtensions.class,
		IterableExtensions.class,
		IteratorExtensions.class,
		ListExtensions.class,
		LongExtensions.class,
		MapExtensions.class,
		ObjectExtensions.class,
		ProcedureExtensions.class,
		ShortExtensions.class,
		StringExtensions.class);
}
 
Example 2
Source Project: xtext-core   Source File: DefaultTaskParserTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testCaseInSensitive() {
  this.definitions.setCaseSensitive(false);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("/*");
  _builder.newLine();
  _builder.append(" ");
  _builder.append("* FixMe case insensitive match");
  _builder.newLine();
  _builder.append(" ");
  _builder.append("*/");
  _builder.newLine();
  Task _task = new Task();
  final Procedure1<Task> _function = (Task it) -> {
    it.setTag(DefaultTaskParserTest.createTaskTag("FIXME", Priority.HIGH));
    it.setDescription(" case insensitive match");
    it.setLineNumber(2);
    it.setOffset(6);
  };
  Task _doubleArrow = ObjectExtensions.<Task>operator_doubleArrow(_task, _function);
  this.assertContainsTasks(_builder, 
    Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList(_doubleArrow)));
}
 
Example 3
protected JvmTypeReference toTypeReference(final JvmType type, final int arrayDimensions) {
  if ((type == null)) {
    return null;
  }
  JvmParameterizedTypeReference _createJvmParameterizedTypeReference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
  final Procedure1<JvmParameterizedTypeReference> _function = (JvmParameterizedTypeReference it) -> {
    it.setType(type);
  };
  JvmTypeReference resultTypeRef = ObjectExtensions.<JvmParameterizedTypeReference>operator_doubleArrow(_createJvmParameterizedTypeReference, _function);
  ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, arrayDimensions, true);
  for (final Integer i : _doubleDotLessThan) {
    {
      final JvmGenericArrayTypeReference arrayRef = TypesFactory.eINSTANCE.createJvmGenericArrayTypeReference();
      arrayRef.setComponentType(resultTypeRef);
      resultTypeRef = arrayRef;
    }
  }
  return resultTypeRef;
}
 
Example 4
Source Project: xtext-xtend   Source File: CompilationUnitImpl.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected String getMessageWithStackTrace(final Throwable t) {
  final Function1<Throwable, String> _function = (Throwable it) -> {
    String _xblockexpression = null;
    {
      StringWriter _stringWriter = new StringWriter();
      final Procedure1<StringWriter> _function_1 = (StringWriter it_1) -> {
        PrintWriter _printWriter = new PrintWriter(it_1);
        final Procedure1<PrintWriter> _function_2 = (PrintWriter it_2) -> {
          it_2.println(this.getMessageWithoutStackTrace(t));
          t.printStackTrace(it_2);
          it_2.flush();
        };
        ObjectExtensions.<PrintWriter>operator_doubleArrow(_printWriter, _function_2);
      };
      final StringWriter writer = ObjectExtensions.<StringWriter>operator_doubleArrow(_stringWriter, _function_1);
      _xblockexpression = writer.toString();
    }
    return _xblockexpression;
  };
  return this.getMessageWithReducedStackTrace(t, _function);
}
 
Example 5
@Test
public void testFunctionType4() {
  FunctionTypeReference _newFunctionTypeReference = this.getOwner().newFunctionTypeReference(this.type(Function3.class));
  final Procedure1<FunctionTypeReference> _function = (FunctionTypeReference it) -> {
    it.setReturnType(this.typeRef(Object.class));
    it.addTypeArgument(this.typeRef(Object.class));
    it.addParameterType(this.typeRef(String.class));
    it.addTypeArgument(this.typeRef(String.class));
    ParameterizedTypeReference _typeRef = this.typeRef(List.class);
    final Procedure1<ParameterizedTypeReference> _function_1 = (ParameterizedTypeReference it_1) -> {
      WildcardTypeReference _newWildcardTypeReference = it_1.getOwner().newWildcardTypeReference();
      final Procedure1<WildcardTypeReference> _function_2 = (WildcardTypeReference it_2) -> {
        it_2.setLowerBound(this.typeRef(CharSequence.class));
      };
      WildcardTypeReference _doubleArrow = ObjectExtensions.<WildcardTypeReference>operator_doubleArrow(_newWildcardTypeReference, _function_2);
      it_1.addTypeArgument(_doubleArrow);
    };
    final ParameterizedTypeReference listOfCharSequence = ObjectExtensions.<ParameterizedTypeReference>operator_doubleArrow(_typeRef, _function_1);
    it.addParameterType(listOfCharSequence);
    it.addTypeArgument(listOfCharSequence);
    final ArrayTypeReference arrayOfObject = it.getOwner().newArrayTypeReference(this.typeRef(Object.class));
    it.addParameterType(arrayOfObject);
    it.addTypeArgument(arrayOfObject);
  };
  this.assertInJava(this.assertInXtend(ObjectExtensions.<FunctionTypeReference>operator_doubleArrow(_newFunctionTypeReference, _function), "(java.lang.String, java.util.List<? super java.lang.CharSequence>, java.lang.Object[])=>java.lang.Object"), "org.eclipse.xtext.xbase.lib.Functions$Function3<java.lang.Object, java.lang.String, java.util.List<? super java.lang.CharSequence>, java.lang.Object[]>");
}
 
Example 6
protected void testRangeFormatting(final Procedure1<? super DocumentRangeFormattingParams> paramsConfigurator, final Procedure1<? super RangeFormattingConfiguration> configurator) {
  try {
    @Extension
    final RangeFormattingConfiguration configuration = new RangeFormattingConfiguration();
    configuration.setFilePath(("MyModel." + this.fileExtension));
    configurator.apply(configuration);
    final FileInfo fileInfo = this.initializeContext(configuration);
    DocumentRangeFormattingParams _documentRangeFormattingParams = new DocumentRangeFormattingParams();
    final Procedure1<DocumentRangeFormattingParams> _function = (DocumentRangeFormattingParams it) -> {
      String _uri = fileInfo.getUri();
      TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(_uri);
      it.setTextDocument(_textDocumentIdentifier);
      it.setRange(configuration.getRange());
      if ((paramsConfigurator != null)) {
        paramsConfigurator.apply(it);
      }
    };
    DocumentRangeFormattingParams _doubleArrow = ObjectExtensions.<DocumentRangeFormattingParams>operator_doubleArrow(_documentRangeFormattingParams, _function);
    final CompletableFuture<List<? extends TextEdit>> changes = this.languageServer.rangeFormatting(_doubleArrow);
    String _contents = fileInfo.getContents();
    final Document result = new Document(Integer.valueOf(1), _contents).applyChanges(ListExtensions.<TextEdit>reverse(CollectionLiterals.<TextEdit>newArrayList(((TextEdit[])Conversions.unwrapArray(changes.get(), TextEdit.class)))));
    this.assertEqualsStricter(configuration.getExpectedText(), result.getContents());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 7
@Test
public void testFunctionType7() {
  FunctionTypeReference _newFunctionTypeReference = this.getOwner().newFunctionTypeReference(this.type(Procedure3.class));
  final Procedure1<FunctionTypeReference> _function = (FunctionTypeReference it) -> {
    it.addParameterType(this.typeRef(String.class));
    it.addTypeArgument(this.typeRef(String.class));
    ParameterizedTypeReference _typeRef = this.typeRef(List.class);
    final Procedure1<ParameterizedTypeReference> _function_1 = (ParameterizedTypeReference it_1) -> {
      WildcardTypeReference _newWildcardTypeReference = it_1.getOwner().newWildcardTypeReference();
      final Procedure1<WildcardTypeReference> _function_2 = (WildcardTypeReference it_2) -> {
        it_2.setLowerBound(this.typeRef(CharSequence.class));
      };
      WildcardTypeReference _doubleArrow = ObjectExtensions.<WildcardTypeReference>operator_doubleArrow(_newWildcardTypeReference, _function_2);
      it_1.addTypeArgument(_doubleArrow);
    };
    final ParameterizedTypeReference listOfCharSequence = ObjectExtensions.<ParameterizedTypeReference>operator_doubleArrow(_typeRef, _function_1);
    it.addParameterType(listOfCharSequence);
    it.addTypeArgument(listOfCharSequence);
    final ArrayTypeReference arrayOfObject = it.getOwner().newArrayTypeReference(this.typeRef(Object.class));
    it.addParameterType(arrayOfObject);
    it.addTypeArgument(arrayOfObject);
  };
  this.assertInJava(this.assertInXtend(ObjectExtensions.<FunctionTypeReference>operator_doubleArrow(_newFunctionTypeReference, _function), "(java.lang.String, java.util.List<? super java.lang.CharSequence>, java.lang.Object[])=>void"), "org.eclipse.xtext.xbase.lib.Procedures$Procedure3<java.lang.String, java.util.List<? super java.lang.CharSequence>, java.lang.Object[]>");
}
 
Example 8
Source Project: xtext-core   Source File: DocumentTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private TextEdit textEdit(final Position startPos, final Position endPos, final String newText) {
  TextEdit _textEdit = new TextEdit();
  final Procedure1<TextEdit> _function = (TextEdit it) -> {
    if ((startPos != null)) {
      Range _range = new Range();
      final Procedure1<Range> _function_1 = (Range it_1) -> {
        it_1.setStart(startPos);
        it_1.setEnd(endPos);
      };
      Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1);
      it.setRange(_doubleArrow);
    }
    it.setNewText(newText);
  };
  return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function);
}
 
Example 9
Source Project: xtext-xtend   Source File: CompilationUnitImpl.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public TypeReference toTypeReference(final LightweightTypeReference delegate, final JvmTypeReference source) {
  TypeReferenceImpl _xblockexpression = null;
  {
    this.checkCanceled();
    if ((delegate == null)) {
      return null;
    }
    TypeReferenceImpl _typeReferenceImpl = new TypeReferenceImpl();
    final Procedure1<TypeReferenceImpl> _function = (TypeReferenceImpl it) -> {
      it.setDelegate(delegate);
      it.setCompilationUnit(this);
      it.setSource(source);
    };
    _xblockexpression = ObjectExtensions.<TypeReferenceImpl>operator_doubleArrow(_typeReferenceImpl, _function);
  }
  return _xblockexpression;
}
 
Example 10
Source Project: xtext-eclipse   Source File: ResourceMoveTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected void performMove(final IContainer theDestination, final IResource... theResources) {
  try {
    MoveResourcesDescriptor _moveResourcesDescriptor = new MoveResourcesDescriptor();
    final Procedure1<MoveResourcesDescriptor> _function = (MoveResourcesDescriptor it) -> {
      final Function1<IResource, IPath> _function_1 = (IResource it_1) -> {
        return it_1.getFullPath();
      };
      it.setResourcePathsToMove(((IPath[])Conversions.unwrapArray(ListExtensions.<IResource, IPath>map(((List<IResource>)Conversions.doWrapArray(theResources)), _function_1), IPath.class)));
      it.setDestinationPath(theDestination.getFullPath());
    };
    MoveResourcesDescriptor _doubleArrow = ObjectExtensions.<MoveResourcesDescriptor>operator_doubleArrow(_moveResourcesDescriptor, _function);
    this.performRefactoring(_doubleArrow);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 11
Source Project: xtext-eclipse   Source File: ValidationTests.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDuplicatedOperationWithDifferentSignatureWithSameTypeErasure() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("entity E {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("op m(java.util.List<String> l1) {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("op m(java.util.List<Integer> l2) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String model = _builder.toString();
    DomainModel _parse = this._parseHelper.parse(model);
    final Procedure1<DomainModel> _function = (DomainModel it) -> {
      this.assertNumberOfIssues(it, 2);
      this._validationTestHelper.assertError(it, DomainmodelPackage.Literals.OPERATION, org.eclipse.xtext.example.domainmodel.validation.IssueCodes.DUPLICATE_OPERATION, model.indexOf("m"), 1, "Duplicate operation m");
      this._validationTestHelper.assertError(it, DomainmodelPackage.Literals.OPERATION, org.eclipse.xtext.example.domainmodel.validation.IssueCodes.DUPLICATE_OPERATION, model.lastIndexOf("m"), 1, "Duplicate operation m");
    };
    ObjectExtensions.<DomainModel>operator_doubleArrow(_parse, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 12
@Override
public void generateProjects(final IProjectGenerator generator) {
  PluginProjectFactory _pluginProjectFactory = new PluginProjectFactory();
  final Procedure1<PluginProjectFactory> _function = (PluginProjectFactory it) -> {
    it.setProjectName(this.getProjectInfo().getProjectName());
    it.setLocation(this.getProjectInfo().getLocationPath());
    List<String> _projectNatures = it.getProjectNatures();
    Iterables.<String>addAll(_projectNatures, Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature", XtextProjectHelper.NATURE_ID)));
    List<String> _builderIds = it.getBuilderIds();
    Iterables.<String>addAll(_builderIds, Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(JavaCore.BUILDER_ID, XtextProjectHelper.BUILDER_ID)));
    List<String> _folders = it.getFolders();
    _folders.add("src");
    List<String> _folders_1 = it.getFolders();
    _folders_1.add("src-gen");
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("src/");
    _builder.append(this.path);
    _builder.append("/MrsGrantsSecretCompartments.statemachine");
    this.addFile(it, _builder, TemplateContent.MrsGrantsSecretCompartments);
  };
  PluginProjectFactory _doubleArrow = ObjectExtensions.<PluginProjectFactory>operator_doubleArrow(_pluginProjectFactory, _function);
  generator.generate(_doubleArrow);
}
 
Example 13
Source Project: xtext-xtend   Source File: KeepLocalHistoryTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public void assertChangeContentByAnotherContent(final IFile it, final int expectedLocalHistorySize) {
  try {
    XtextEditor _openEditor = this.workbenchTestHelper.openEditor(it);
    final Procedure1<XtextEditor> _function = (XtextEditor it_1) -> {
      final String currentContent = it_1.getDocument().get();
      boolean _equals = currentContent.equals(KeepLocalHistoryTest.CONTENT_WITHOUT_BODY);
      if (_equals) {
        it_1.getDocument().set(KeepLocalHistoryTest.CONTENT_WITH_BODY);
      } else {
        it_1.getDocument().set(KeepLocalHistoryTest.CONTENT_WITHOUT_BODY);
      }
      this.workbenchTestHelper.saveEditor(it_1, false);
    };
    ObjectExtensions.<XtextEditor>operator_doubleArrow(_openEditor, _function);
    this.assertGeneratedFiles(expectedLocalHistorySize);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 14
@Test
public void testJavaConstructor() {
  AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getJavaClass());
  final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> {
    it.setContext(this.getJavaClass());
    it.setVisibility(JvmVisibility.PRIVATE);
    AbstractParameterBuilder _newParameterBuilder = it.newParameterBuilder();
    _newParameterBuilder.setType(this.createTypeRef(this.getJavaClass()));
    AbstractParameterBuilder _newParameterBuilder_1 = it.newParameterBuilder();
    _newParameterBuilder_1.setType(this.createTypeRef(this.getJavaClass()));
  };
  AbstractConstructorBuilder _doubleArrow = ObjectExtensions.<AbstractConstructorBuilder>operator_doubleArrow(_createConstructorBuilder, _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("private Bar(Bar bar, Bar bar2) {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
  _builder.append(";");
  _builder.newLineIfNotEmpty();
  _builder.append("}");
  this.assertBuilds(_doubleArrow, _builder.toString());
}
 
Example 15
@Test
public void testXtendExceptions() {
  AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getXtendClass());
  final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> {
    it.setContext(this.getXtendClass());
    LightweightTypeReference _createTypeRef = this.createTypeRef(Exception.class, this.getXtendClass());
    LightweightTypeReference _createTypeRef_1 = this.createTypeRef(RuntimeException.class, this.getXtendClass());
    it.setExceptions(Collections.<LightweightTypeReference>unmodifiableList(CollectionLiterals.<LightweightTypeReference>newArrayList(_createTypeRef, _createTypeRef_1)));
  };
  AbstractConstructorBuilder _doubleArrow = ObjectExtensions.<AbstractConstructorBuilder>operator_doubleArrow(_createConstructorBuilder, _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("new() throws Exception, RuntimeException {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
  _builder.newLineIfNotEmpty();
  _builder.append("}");
  this.assertBuilds(_doubleArrow, _builder.toString());
}
 
Example 16
@Test
public void testXtendCustomBody() {
  AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getXtendClass());
  final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> {
    it.setContext(this.getXtendClass());
    final Procedure1<ISourceAppender> _function_1 = (ISourceAppender it_1) -> {
      it_1.append("return");
    };
    it.setBodyGenerator(_function_1);
  };
  AbstractConstructorBuilder _doubleArrow = ObjectExtensions.<AbstractConstructorBuilder>operator_doubleArrow(_createConstructorBuilder, _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("new() {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append("return");
  _builder.newLine();
  _builder.append("}");
  this.assertBuilds(_doubleArrow, _builder.toString());
}
 
Example 17
@Test
public void testJavaCustomBody() {
  AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getJavaClass());
  final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> {
    it.setContext(this.getJavaClass());
    final Procedure1<ISourceAppender> _function_1 = (ISourceAppender it_1) -> {
      it_1.append("return");
    };
    it.setBodyGenerator(_function_1);
  };
  AbstractConstructorBuilder _doubleArrow = ObjectExtensions.<AbstractConstructorBuilder>operator_doubleArrow(_createConstructorBuilder, _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("Bar() {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append("return;");
  _builder.newLine();
  _builder.append("}");
  this.assertBuilds(_doubleArrow, _builder.toString());
}
 
Example 18
Source Project: xtext-core   Source File: FormattingTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testRangeFormattingService() {
  final Procedure1<RangeFormattingConfiguration> _function = (RangeFormattingConfiguration it) -> {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("type Foo{int bar} type Bar{Foo foo}");
    it.setModel(_builder.toString());
    Range _range = new Range();
    final Procedure1<Range> _function_1 = (Range it_1) -> {
      Position _position = new Position(0, 0);
      it_1.setStart(_position);
      Position _position_1 = new Position(0, 17);
      it_1.setEnd(_position_1);
    };
    Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1);
    it.setRange(_doubleArrow);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("type Foo{");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("int bar");
    _builder_1.newLine();
    _builder_1.append("} type Bar{Foo foo}");
    it.setExpectedText(_builder_1.toString());
  };
  this.testRangeFormatting(_function);
}
 
Example 19
Source Project: xtext-xtend   Source File: MethodBuilderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testJavaMethod() {
  AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getJavaClass());
  final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
    it.setContext(this.getJavaClass());
    it.setMethodName("bar");
    it.setReturnType(this.createTypeRef(this.getJavaClass()));
    it.setVisibility(JvmVisibility.PUBLIC);
    AbstractParameterBuilder _newParameterBuilder = it.newParameterBuilder();
    _newParameterBuilder.setType(this.createTypeRef(this.getJavaClass()));
    AbstractParameterBuilder _newParameterBuilder_1 = it.newParameterBuilder();
    _newParameterBuilder_1.setType(this.createTypeRef(this.getJavaClass()));
  };
  AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("public Bar bar(Bar bar, Bar bar2) {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
  _builder.append(";");
  _builder.newLineIfNotEmpty();
  _builder.append("}");
  this.assertBuilds(_doubleArrow, _builder.toString());
}
 
Example 20
Source Project: xtext-xtend   Source File: MethodBuilderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testStaticJavaMethod() {
  AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getJavaClass());
  final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
    it.setContext(this.getJavaClass());
    it.setMethodName("bar");
    it.setReturnType(this.createTypeRef(this.getJavaClass()));
    it.setVisibility(JvmVisibility.PRIVATE);
    it.setStaticFlag(true);
    AbstractParameterBuilder _newParameterBuilder = it.newParameterBuilder();
    _newParameterBuilder.setType(this.createTypeRef(this.getJavaClass()));
  };
  AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("private static Bar bar(Bar bar) {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
  _builder.append(";");
  _builder.newLineIfNotEmpty();
  _builder.append("}");
  this.assertBuilds(_doubleArrow, _builder.toString());
}
 
Example 21
Source Project: xtext-xtend   Source File: MethodBuilderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testXtendCustomBody() {
  AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getXtendClass());
  final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
    it.setContext(this.getXtendClass());
    it.setMethodName("foo");
    final Procedure1<ISourceAppender> _function_1 = (ISourceAppender it_1) -> {
      it_1.append("return");
    };
    it.setBodyGenerator(_function_1);
  };
  AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("def foo() {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append("return");
  _builder.newLine();
  _builder.append("}");
  this.assertBuilds(_doubleArrow, _builder.toString());
}
 
Example 22
Source Project: xtext-xtend   Source File: MethodBuilderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testJavaCustomBody() {
  AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getJavaClass());
  final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
    it.setContext(this.getJavaClass());
    it.setMethodName("foo");
    final Procedure1<ISourceAppender> _function_1 = (ISourceAppender it_1) -> {
      it_1.append("return");
    };
    it.setBodyGenerator(_function_1);
  };
  AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("void foo() {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append("return;");
  _builder.newLine();
  _builder.append("}");
  this.assertBuilds(_doubleArrow, _builder.toString());
}
 
Example 23
@Override
public Document createDocument(final String before) throws Exception {
  XtextDocument _xblockexpression = null;
  {
    XtendDocumentTokenSource _xtendDocumentTokenSource = new XtendDocumentTokenSource();
    final Procedure1<XtendDocumentTokenSource> _function = (XtendDocumentTokenSource it) -> {
      AntlrTokenDefProvider _antlrTokenDefProvider = new AntlrTokenDefProvider();
      final Procedure1<AntlrTokenDefProvider> _function_1 = (AntlrTokenDefProvider it_1) -> {
        XtendAntlrTokenFileProvider _xtendAntlrTokenFileProvider = new XtendAntlrTokenFileProvider();
        it_1.setAntlrTokenFileProvider(_xtendAntlrTokenFileProvider);
      };
      AntlrTokenDefProvider _doubleArrow = ObjectExtensions.<AntlrTokenDefProvider>operator_doubleArrow(_antlrTokenDefProvider, _function_1);
      it.setTokenDefProvider(_doubleArrow);
      final Provider<Lexer> _function_2 = () -> {
        return this.createLexer();
      };
      it.setLexer(_function_2);
      it.setFlexerFactory(this.flexerFactory);
    };
    final XtendDocumentTokenSource source = ObjectExtensions.<XtendDocumentTokenSource>operator_doubleArrow(_xtendDocumentTokenSource, _function);
    final XtextDocument document = new XtextDocument(source, null, this.outdatedStateManager, this.operationCanceledManager);
    document.set(before);
    _xblockexpression = document;
  }
  return _xblockexpression;
}
 
Example 24
Source Project: xtext-xtend   Source File: MethodBuilderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testXtendOverrride() {
  AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getXtendClass());
  final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
    it.setContext(this.getXtendClass());
    it.setMethodName("foo");
    it.setOverrideFlag(true);
  };
  AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("override foo() {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
  _builder.newLineIfNotEmpty();
  _builder.append("}");
  this.assertBuilds(_doubleArrow, _builder.toString());
}
 
Example 25
Source Project: xtext-xtend   Source File: MethodBuilderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testJavaOverride() {
  AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getJavaClass());
  final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
    it.setContext(this.getJavaClass());
    it.setMethodName("foo");
    it.setOverrideFlag(true);
  };
  AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("@Override");
  _builder.newLine();
  _builder.append("void foo() {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
  _builder.append(";");
  _builder.newLineIfNotEmpty();
  _builder.append("}");
  this.assertBuilds(_doubleArrow, _builder.toString());
}
 
Example 26
Source Project: xtext-xtend   Source File: MethodBuilderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testXtendExceptions() {
  AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getXtendClass());
  final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
    it.setContext(this.getXtendClass());
    it.setMethodName("foo");
    LightweightTypeReference _createTypeRef = this.createTypeRef(Exception.class, this.getXtendClass());
    LightweightTypeReference _createTypeRef_1 = this.createTypeRef(RuntimeException.class, this.getXtendClass());
    it.setExceptions(Collections.<LightweightTypeReference>unmodifiableList(CollectionLiterals.<LightweightTypeReference>newArrayList(_createTypeRef, _createTypeRef_1)));
  };
  AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("def foo() throws Exception, RuntimeException {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
  _builder.newLineIfNotEmpty();
  _builder.append("}");
  this.assertBuilds(_doubleArrow, _builder.toString());
}
 
Example 27
Source Project: xtext-xtend   Source File: MethodBuilderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testJavaException() {
  AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getJavaClass());
  final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
    it.setContext(this.getJavaClass());
    it.setMethodName("foo");
    LightweightTypeReference _createTypeRef = this.createTypeRef(Exception.class, this.getJavaClass());
    LightweightTypeReference _createTypeRef_1 = this.createTypeRef(RuntimeException.class, this.getJavaClass());
    it.setExceptions(Collections.<LightweightTypeReference>unmodifiableList(CollectionLiterals.<LightweightTypeReference>newArrayList(_createTypeRef, _createTypeRef_1)));
  };
  AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("void foo() throws Exception, RuntimeException {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
  _builder.append(";");
  _builder.newLineIfNotEmpty();
  _builder.append("}");
  this.assertBuilds(_doubleArrow, _builder.toString());
}
 
Example 28
Source Project: xtext-xtend   Source File: MethodBuilderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testXtendSynchronized() {
  AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getXtendClass());
  final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
    it.setContext(this.getXtendClass());
    it.setMethodName("foo");
    it.setReturnType(this.createTypeRef(this.getXtendClass()));
    it.setVisibility(JvmVisibility.PUBLIC);
    it.setSynchronizedFlag(true);
  };
  AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("def synchronized foo() {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
  _builder.newLineIfNotEmpty();
  _builder.append("}");
  this.assertBuilds(_doubleArrow, _builder.toString());
}
 
Example 29
Source Project: xtext-xtend   Source File: MethodBuilderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testJavaSynchronized() {
  AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getJavaClass());
  final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
    it.setContext(this.getJavaClass());
    it.setMethodName("bar");
    it.setReturnType(this.createTypeRef(this.getJavaClass()));
    it.setVisibility(JvmVisibility.PUBLIC);
    it.setSynchronizedFlag(true);
  };
  AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("public synchronized Bar bar() {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
  _builder.append(";");
  _builder.newLineIfNotEmpty();
  _builder.append("}");
  this.assertBuilds(_doubleArrow, _builder.toString());
}
 
Example 30
Source Project: xtext-xtend   Source File: CompilationUnitImpl.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public XtendParameterDeclarationImpl toXtendParameterDeclaration(final XtendParameter delegate) {
  final Function1<XtendParameter, XtendParameterDeclarationImpl> _function = (XtendParameter it) -> {
    XtendParameterDeclarationImpl _xtendParameterDeclarationImpl = new XtendParameterDeclarationImpl();
    final Procedure1<XtendParameterDeclarationImpl> _function_1 = (XtendParameterDeclarationImpl it_1) -> {
      it_1.setDelegate(delegate);
      it_1.setCompilationUnit(this);
    };
    return ObjectExtensions.<XtendParameterDeclarationImpl>operator_doubleArrow(_xtendParameterDeclarationImpl, _function_1);
  };
  return this.<XtendParameter, XtendParameterDeclarationImpl>getOrCreate(delegate, _function);
}