Java Code Examples for org.eclipse.xtext.xbase.lib.Procedures.Procedure1

The following examples show how to use org.eclipse.xtext.xbase.lib.Procedures.Procedure1. 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
Source Project: xtext-extras   Source File: XbaseFormatterTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatSynchronizedBlock_2() {
  final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("synchronized (new Object) {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    it.setExpectation(_builder);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("synchronized         (          new            Object           )        {        }");
    _builder_1.newLine();
    it.setToBeFormatted(_builder_1);
  };
  this._xbaseFormatterTester.assertFormattedExpression(_function);
}
 
Example 2
Source Project: xtext-extras   Source File: XbaseFormatterTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatIfElse2() {
  final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("if (true) {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("println(\"foo\")");
    _builder.newLine();
    _builder.append("} else {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("println(\"bar\")");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    it.setToBeFormatted(_builder);
  };
  this._xbaseFormatterTester.assertFormattedExpression(_function);
}
 
Example 3
@Test
public void formatMethodWithTwoExpressions2() {
  final Procedure1<MapBasedPreferenceValues> _function = (MapBasedPreferenceValues it) -> {
    it.<Boolean>put(XtendFormatterPreferenceKeys.keepOneLineMethods, Boolean.valueOf(true));
  };
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("class C {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("def m() {");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("println(this)");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("\"Foo\"");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("}");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  this.assertFormatted(_function, _builder);
}
 
Example 4
Source Project: xtext-xtend   Source File: ObservableExample.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public static void main(final String[] args) {
  ObservableBean _observableBean = new ObservableBean();
  final Procedure1<ObservableBean> _function = (ObservableBean it) -> {
    final PropertyChangeListener _function_1 = (PropertyChangeEvent it_1) -> {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("property ");
      String _propertyName = it_1.getPropertyName();
      _builder.append(_propertyName);
      _builder.append(" changed from ");
      Object _oldValue = it_1.getOldValue();
      _builder.append(_oldValue);
      _builder.append(" to ");
      Object _newValue = it_1.getNewValue();
      _builder.append(_newValue);
      InputOutput.<String>println(_builder.toString());
    };
    it.addPropertyChangeListener(_function_1);
    it.setFirstName("Max");
    it.setLastName("Mustermann");
    it.setFirstName("John");
    it.setLastName("Doe");
  };
  ObjectExtensions.<ObservableBean>operator_doubleArrow(_observableBean, _function);
}
 
Example 5
Source Project: xtext-extras   Source File: XbaseFormatterTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatSynchronizedBlock_1() {
  final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("synchronized (new Object) {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    it.setExpectation(_builder);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("synchronized(new Object){}");
    _builder_1.newLine();
    it.setToBeFormatted(_builder_1);
  };
  this._xbaseFormatterTester.assertFormattedExpression(_function);
}
 
Example 6
public void assertFormatted(final Procedure1<? super MapBasedPreferenceValues> cfg, final CharSequence expectation, final CharSequence toBeFormatted, final String prefix, final String postfix, final boolean allowErrors) {
  final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
    final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
      it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(80));
      it_1.<Boolean>put(XtendFormatterPreferenceKeys.keepOneLineMethods, Boolean.valueOf(false));
      if (cfg!=null) {
        cfg.apply(it_1);
      }
    };
    it.preferences(_function_1);
    it.setExpectation(((prefix + expectation) + postfix));
    it.setToBeFormatted(((prefix + toBeFormatted) + postfix));
    Collection<ITextRegion> _regions = it.getRequest().getRegions();
    int _length = prefix.length();
    int _length_1 = toBeFormatted.length();
    TextRegion _textRegion = new TextRegion(_length, _length_1);
    _regions.add(_textRegion);
    it.setAllowSyntaxErrors(allowErrors);
  };
  this.tester.assertFormatted(_function);
}
 
Example 7
Source Project: xtext-extras   Source File: JvmTypesBuilder.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates a <code>toString()</code> method accumulating the values of all fields.
 *
 * @return a result representing a Java toString() method, <code>null</code> if sourceElement or declaredType are <code>null</code>.
 */
/* @Nullable */ 
public JvmOperation toToStringMethod(/* @Nullable */ final EObject sourceElement, /* @Nullable */ final JvmDeclaredType declaredType) {
	if(sourceElement == null || declaredType == null)
		return null;
	JvmOperation result = toMethod(sourceElement, "toString", newTypeRef(sourceElement, String.class), null);
	if (result == null)
		return null;
	JvmType overrideType = references.findDeclaredType(Override.class, sourceElement);
	if (overrideType != null)
		result.getAnnotations().add(toAnnotation(sourceElement, Override.class));
	setBody(result, new Procedure1<ITreeAppendable>() {
		@Override
		public void apply(/* @Nullable */ ITreeAppendable p) {
			if (p == null)
				return;
			p.append("String result = new ");
			p.append(ToStringBuilder.class);
			p.append("(this).addAllFields().toString();");
			p.newLine().append("return result;");
		}
	});
	return result;
}
 
Example 8
Source Project: xtext-extras   Source File: LoopExtensions.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Iterates elements and execute the procedure. A prefix, a separator and a
 * suffix can be initialized with the loopInitializer lambda.
 */
public <T> void forEach(ITreeAppendable appendable, Iterable<T> elements,
		Procedure1<? super LoopParams> loopInitializer, Procedure1<? super T> procedure) {
	if (Iterables.isEmpty(elements)) {
		return;
	}
	LoopParams params = new LoopParams();
	loopInitializer.apply(params);
	params.appendPrefix(appendable);
	procedure.apply(Iterables.getFirst(elements, null));
	IterableExtensions.tail(elements).forEach((T it) -> {
		params.appendSeparator(appendable);
		procedure.apply(it);
	});
	params.appendSuffix(appendable);
}
 
Example 9
@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 10
@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 11
@Test
public void formatClass112() {
  final Procedure1<MapBasedPreferenceValues> _function = (MapBasedPreferenceValues it) -> {
    it.<Boolean>put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(false));
  };
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("package foo");
  _builder.newLine();
  _builder.newLine();
  _builder.append("class bar {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("int member1");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  this.assertFormatted(_function, _builder);
}
 
Example 12
Source Project: xtext-xtend   Source File: JdtFindReferencesTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testClassJavaElements() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Xtend {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendTypeDeclaration clazz = IterableExtensions.<XtendTypeDeclaration>head(this._workbenchTestHelper.xtendFile("Xtend.xtend", _builder.toString()).getXtendTypes());
    IResourcesSetupUtil.waitForBuild();
    Iterable<IJavaElement> _javaElements = this._jvmModelFindReferenceHandler.getJavaElements(clazz);
    final Procedure1<Iterable<IJavaElement>> _function = (Iterable<IJavaElement> it) -> {
      Assert.assertEquals(1, IterableExtensions.size(it));
      final Function1<IJavaElement, Boolean> _function_1 = (IJavaElement it_1) -> {
        return Boolean.valueOf(((it_1 instanceof IType) && Objects.equal(((IType) it_1).getElementName(), "Xtend")));
      };
      Assert.assertTrue(IterableExtensions.<IJavaElement>exists(it, _function_1));
    };
    ObjectExtensions.<Iterable<IJavaElement>>operator_doubleArrow(_javaElements, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 13
Source Project: xtext-core   Source File: DocumentTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testApplyTextDocumentChanges_04() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("foo");
  _builder.newLine();
  _builder.append("bar");
  _builder.newLine();
  String _normalize = this.normalize(_builder);
  TextDocumentContentChangeEvent _change = this.change(this.position(0, 3), this.position(0, 3), "b");
  TextDocumentContentChangeEvent _change_1 = this.change(this.position(0, 4), this.position(0, 4), "a");
  TextDocumentContentChangeEvent _change_2 = this.change(this.position(0, 5), this.position(0, 5), "r");
  Document _applyTextDocumentChanges = new Document(Integer.valueOf(1), _normalize).applyTextDocumentChanges(
    Collections.<TextDocumentContentChangeEvent>unmodifiableList(CollectionLiterals.<TextDocumentContentChangeEvent>newArrayList(_change, _change_1, _change_2)));
  final Procedure1<Document> _function = (Document it) -> {
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("foobar");
    _builder_1.newLine();
    _builder_1.append("bar");
    _builder_1.newLine();
    Assert.assertEquals(this.normalize(_builder_1), it.getContents());
    Assert.assertEquals(2, (it.getVersion()).intValue());
  };
  ObjectExtensions.<Document>operator_doubleArrow(_applyTextDocumentChanges, _function);
}
 
Example 14
@Test
public void testEnumerationWithCompleter() {
  try {
    final XExpression expression = this.expression("null", false);
    final Procedure1<JvmEnumerationType> _function = (JvmEnumerationType it) -> {
      EList<JvmMember> _members = it.getMembers();
      JvmEnumerationLiteral _enumerationLiteral = this.builder.toEnumerationLiteral(expression, "BAR");
      this.builder.<JvmEnumerationLiteral>operator_add(_members, _enumerationLiteral);
      EList<JvmMember> _members_1 = it.getMembers();
      JvmEnumerationLiteral _enumerationLiteral_1 = this.builder.toEnumerationLiteral(expression, "BAZ");
      this.builder.<JvmEnumerationLiteral>operator_add(_members_1, _enumerationLiteral_1);
    };
    final JvmEnumerationType enumeration = this.builder.toEnumerationType(expression, "my.test.Foo", _function);
    expression.eResource().getContents().add(enumeration);
    this.completer.complete(enumeration);
    final Class<?> compiled = this.compile(expression.eResource(), enumeration);
    final Method valuesMethod = compiled.getMethod("values");
    Object _invoke = valuesMethod.invoke(null);
    final Object[] values = ((Object[]) _invoke);
    Assert.assertEquals("BAR", (values[0]).toString());
    Assert.assertEquals("BAZ", (values[1]).toString());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 15
Source Project: xtext-extras   Source File: XbaseFormatterTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatBasicFor5() {
  final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("val x = 1");
    _builder.newLine();
    _builder.append("for (;; x = x + 1, x = x + 2)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("println(x)");
    _builder.newLine();
    it.setExpectation(_builder);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("val x = 1");
    _builder_1.newLine();
    _builder_1.append("for  (       ;     ;     x     =      x \t+      1  ,  x  =   x   +    2 )          println(x)");
    _builder_1.newLine();
    it.setToBeFormatted(_builder_1);
  };
  this._xbaseFormatterTester.assertFormattedExpression(_function);
}
 
Example 16
Source Project: xtext-eclipse   Source File: ValidationTests.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDuplicatedProperty() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("entity E {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("p : String");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("p : String");
    _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.PROPERTY, org.eclipse.xtext.example.domainmodel.validation.IssueCodes.DUPLICATE_PROPERTY, model.indexOf("p"), 1, "Duplicate property p");
      this._validationTestHelper.assertError(it, DomainmodelPackage.Literals.PROPERTY, org.eclipse.xtext.example.domainmodel.validation.IssueCodes.DUPLICATE_PROPERTY, model.lastIndexOf("p"), 1, "Duplicate property p");
    };
    ObjectExtensions.<DomainModel>operator_doubleArrow(_parse, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 17
@Test
public void testListUpperBoundObject() {
  ParameterizedTypeReference _typeRef = this.typeRef(List.class);
  final Procedure1<ParameterizedTypeReference> _function = (ParameterizedTypeReference it) -> {
    WildcardTypeReference _newWildcardTypeReference = it.getOwner().newWildcardTypeReference();
    final Procedure1<WildcardTypeReference> _function_1 = (WildcardTypeReference it_1) -> {
      it_1.addUpperBound(this.typeRef(Object.class));
    };
    WildcardTypeReference _doubleArrow = ObjectExtensions.<WildcardTypeReference>operator_doubleArrow(_newWildcardTypeReference, _function_1);
    it.addTypeArgument(_doubleArrow);
  };
  this.assertInXtendAndJava(ObjectExtensions.<ParameterizedTypeReference>operator_doubleArrow(_typeRef, _function), "java.util.List<?>");
}
 
Example 18
Source Project: xtext-extras   Source File: PureXbaseFormatter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void _format(final XBlockExpression xBlockExpression, @Extension final IFormattableDocument document) {
  final Consumer<ISemanticRegion> _function = (ISemanticRegion it) -> {
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
      it_1.newLine();
    };
    document.append(it, _function_1);
  };
  this.textRegionExtensions.regionFor(xBlockExpression).keywords(this._pureXbaseGrammarAccess.getSpecialBlockExpressionAccess().getSemicolonKeyword_1_1()).forEach(_function);
  EList<XExpression> _expressions = xBlockExpression.getExpressions();
  for (final XExpression xExpression : _expressions) {
    document.<XExpression>format(xExpression);
  }
}
 
Example 19
public void renameInJavaEditor(final SWTBotEclipseEditor javaEditor, final String newName, final String dialogName) {
  final SWTBotMenu renameMenuItem = SwtBotProjectHelper.clickableContextMenu(javaEditor, "Refactor", "Rename...");
  renameMenuItem.click();
  boolean _isUseInlineRefactoring = this.testParams.isUseInlineRefactoring();
  if (_isUseInlineRefactoring) {
    javaEditor.typeText(newName);
    boolean _isUsePreview = this.testParams.isUsePreview();
    if (_isUsePreview) {
      javaEditor.pressShortcut(SWT.CTRL, SWT.CR);
      AbstractRefactoringSwtBotTest.bot.shell(dialogName).activate();
      AbstractRefactoringSwtBotTest.bot.button("OK").click();
    } else {
      javaEditor.pressShortcut(KeyStroke.getInstance(SWT.LF));
    }
  } else {
    SWTBot _bot = AbstractRefactoringSwtBotTest.bot.shell(dialogName).activate().bot();
    final Procedure1<SWTBot> _function = (SWTBot it) -> {
      SWTBotText _textWithLabel = it.textWithLabel("New name:");
      _textWithLabel.setText(newName);
      boolean _isUsePreview_1 = this.testParams.isUsePreview();
      if (_isUsePreview_1) {
        it.button("Next").click();
      }
      it.button("Finish").click();
    };
    ObjectExtensions.<SWTBot>operator_doubleArrow(_bot, _function);
  }
  this.waitForRefactoring(javaEditor);
}
 
Example 20
Source Project: xtext-xtend   Source File: XtendFormatter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void _format(final XVariableDeclaration expr, @Extension final IFormattableDocument format) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  format.append(this.textRegionExtensions.regionFor(expr).keyword("extension"), _function);
  super._format(expr, format);
}
 
Example 21
@Test
public void testPackageInfo() {
  final Procedure1<BuildRequest> _function = (BuildRequest it) -> {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package foo;");
    _builder.newLine();
    URI _minus = this.operator_minus(
      "src/foo/package-info.java", _builder.toString());
    it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_minus)));
  };
  final BuildRequest buildRequest = this.newBuildRequest(_function);
  this.build(buildRequest);
  Assert.assertTrue(this.issues.toString(), this.issues.isEmpty());
}
 
Example 22
Source Project: xtext-extras   Source File: JvmTypesBuilder.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected <T extends EObject> T initializeSafely(/* @Nullable */ T targetElement, /* @Nullable */ Procedure1<? super T> initializer) {
	if(targetElement != null && initializer != null) {
		try {
			initializer.apply(targetElement);
		} catch (Exception e) {
			LOG.error("Error initializing JvmElement", e);
		}
	}
	return targetElement;
}
 
Example 23
Source Project: xtext-extras   Source File: XbaseFormatterTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void formatSwitchSL1() {
  final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
    final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
      it_1.<Boolean>put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(true));
    };
    it.preferences(_function_1);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("switch \'x\' { case \'x\': println(\'x\') case \'y\': println(\'y\') }");
    _builder.newLine();
    it.setToBeFormatted(_builder);
  };
  this._xbaseFormatterTester.assertFormattedExpression(_function);
}
 
Example 24
Source Project: xtext-extras   Source File: JvmTypesBuilder.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Same as {@link #toEnumerationLiteral(EObject, String)} but with an initializer passed as the last argument.
 */
/* @Nullable */ 
public JvmEnumerationLiteral toEnumerationLiteral(/* @Nullable */ EObject sourceElement, /* @Nullable */ String name, 
		/* @Nullable */ Procedure1<? super JvmEnumerationLiteral> initializer) {
	if (sourceElement == null || name == null)
		return null;
	JvmEnumerationLiteral result = typesFactory.createJvmEnumerationLiteral();
	result.setSimpleName(name);
	result.setVisibility(JvmVisibility.PUBLIC);
	associate(sourceElement, result);
	return initializeSafely(result, initializer);
}
 
Example 25
@Test
public void formatConstructorTwoAnnotationsSL2() {
  final Procedure1<MapBasedPreferenceValues> _function = (MapBasedPreferenceValues it) -> {
    it.<Boolean>put(XbaseFormatterPreferenceKeys.newLineAfterConstructorAnnotations, Boolean.valueOf(false));
    it.<Boolean>put(XbaseFormatterPreferenceKeys.preserveNewLines, Boolean.valueOf(true));
  };
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("@Override @Deprecated new() {");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  this.assertFormattedMember(_function, _builder.toString());
}
 
Example 26
@Test
public void events_state() {
  final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("events doorClosed D1CL drawerOpened D2OP lightOn L1ON doorOpened D1OP panelClosed PNCL end");
    _builder.newLine();
    _builder.append("state idle end");
    _builder.newLine();
    it.setToBeFormatted(_builder);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("events");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("doorClosed   D1CL");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("drawerOpened D2OP");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("lightOn      L1ON");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("doorOpened   D1OP");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("panelClosed  PNCL");
    _builder_1.newLine();
    _builder_1.append("end");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("state idle");
    _builder_1.newLine();
    _builder_1.append("end");
    _builder_1.newLine();
    it.setExpectation(_builder_1);
  };
  this._formatterTestHelper.assertFormatted(_function);
}
 
Example 27
public MutableFieldDeclaration addField(final String name, final Procedure1<MutableFieldDeclaration> initializer) {
  this.checkMutable();
  ConditionUtils.checkJavaIdentifier(name, "name");
  Preconditions.checkArgument((initializer != null), "initializer cannot be null");
  final JvmField newField = TypesFactory.eINSTANCE.createJvmField();
  newField.setSimpleName(name);
  newField.setVisibility(JvmVisibility.PRIVATE);
  this.getDelegate().getMembers().add(newField);
  MemberDeclaration _memberDeclaration = this.getCompilationUnit().toMemberDeclaration(newField);
  final MutableFieldDeclaration mutableFieldDeclaration = ((MutableFieldDeclaration) _memberDeclaration);
  initializer.apply(mutableFieldDeclaration);
  return mutableFieldDeclaration;
}
 
Example 28
Source Project: xtext-xtend   Source File: XtendFormatter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void _format(final JvmFormalParameter expr, @Extension final IFormattableDocument format) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  format.append(this.textRegionExtensions.regionFor(expr).keyword("extension"), _function);
  super._format(expr, format);
}
 
Example 29
Source Project: xtext-extras   Source File: JvmTypesBuilder.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void setCompilationStrategy(/* @Nullable */ JvmMember member, /* @Nullable */ Procedures.Procedure1<ITreeAppendable> strategy) {
	if(member == null || strategy == null)
		return;
	CompilationStrategyAdapter adapter = new CompilationStrategyAdapter();
	adapter.setCompilationStrategy(strategy);
	member.eAdapters().add(adapter);
}
 
Example 30
Source Project: xtext-core   Source File: CodeActionTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testCodeAction() {
  final Procedure1<AbstractLanguageServerTest.TestCodeActionConfiguration> _function = (AbstractLanguageServerTest.TestCodeActionConfiguration it) -> {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("type foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    it.setModel(_builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("command : my.textedit.command");
    _builder_1.newLine();
    _builder_1.append("title : Make \'foo\' upper case");
    _builder_1.newLine();
    _builder_1.append("args : ");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("changes :");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("MyModel.testlang : Foo [[0, 5] .. [0, 8]]");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("documentChanges : ");
    _builder_1.newLine();
    it.setExpectedCodeActions(_builder_1.toString());
  };
  this.testCodeAction(_function);
}