org.eclipse.xtext.xbase.lib.Procedures.Procedure1 Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.lib.Procedures.Procedure1.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ValidationTests.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@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 #2
Source File: XbaseFormatterTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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
Source File: XtendOnelinersFormatterTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@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 File: XbaseFormatterTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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 #5
Source File: ObservableExample.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
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 #6
Source File: XbaseFormatterTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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 #7
Source File: AbstractXtendFormatterTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
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 #8
Source File: JvmTypesBuilder.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * 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 #9
Source File: LoopExtensions.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * 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 #10
Source File: ConstructorBuilderTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@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 #11
Source File: ConstructorBuilderTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@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 #12
Source File: XtendFileFormatterTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@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 #13
Source File: JdtFindReferencesTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@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 #14
Source File: DocumentTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@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 #15
Source File: JvmModelGeneratorTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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 #16
Source File: XbaseFormatterTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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 #17
Source File: XbaseFormatterTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void formatSwitchMLBlock() { final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> { final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> { it_1.<Boolean>put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(false)); }; it.preferences(_function_1); StringConcatenation _builder = new StringConcatenation(); _builder.append("switch \'x\' {"); _builder.newLine(); _builder.append("\t"); _builder.append("case \'x\': {"); _builder.newLine(); _builder.append("\t\t"); _builder.append("println(\'x\')"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("\t"); _builder.append("case \'y\': {"); _builder.newLine(); _builder.append("\t\t"); _builder.append("println(\'y\')"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); it.setExpectation(_builder); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("switch \'x\' { case \'x\': { println(\'x\') } case \'y\': { println(\'y\') } }"); _builder_1.newLine(); it.setToBeFormatted(_builder_1); }; this._xbaseFormatterTester.assertFormattedExpression(_function); }
Example #18
Source File: XbaseFormatterTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void formatMemberFeatureCallBuilder2() { final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> { StringConcatenation _builder = new StringConcatenation(); _builder.append("newArrayList(\"x\").map()[lenght]"); _builder.newLine(); it.setExpectation(_builder); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("newArrayList(\"x\") . map ( ) [ lenght ]"); _builder_1.newLine(); it.setToBeFormatted(_builder_1); }; this._xbaseFormatterTester.assertFormattedExpression(_function); }
Example #19
Source File: AbstractLanguageServerTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void close(final String fileUri) { DidCloseTextDocumentParams _didCloseTextDocumentParams = new DidCloseTextDocumentParams(); final Procedure1<DidCloseTextDocumentParams> _function = (DidCloseTextDocumentParams it) -> { TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri); it.setTextDocument(_textDocumentIdentifier); }; DidCloseTextDocumentParams _doubleArrow = ObjectExtensions.<DidCloseTextDocumentParams>operator_doubleArrow(_didCloseTextDocumentParams, _function); this.languageServer.didClose(_doubleArrow); }
Example #20
Source File: LightweightTypeReferenceSerializerTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testListWildcard() { ParameterizedTypeReference _typeRef = this.typeRef(List.class); final Procedure1<ParameterizedTypeReference> _function = (ParameterizedTypeReference it) -> { it.addTypeArgument(it.getOwner().newWildcardTypeReference()); }; this.assertInXtendAndJava(ObjectExtensions.<ParameterizedTypeReference>operator_doubleArrow(_typeRef, _function), "java.util.List<?>"); }
Example #21
Source File: AbstractRefactoringSwtBotTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public void renameInXtendEditor(final SWTBotEclipseEditor xtendEditor, final String newName, final String dialogName) { final SWTBotMenu renameMenuItem = SwtBotProjectHelper.clickableContextMenu(xtendEditor, "Refactor", "Rename Element"); renameMenuItem.click(); boolean _isUseInlineRefactoring = this.testParams.isUseInlineRefactoring(); if (_isUseInlineRefactoring) { this.waitForLinkedMode(); xtendEditor.typeText(newName); boolean _isUsePreview = this.testParams.isUsePreview(); if (_isUsePreview) { xtendEditor.pressShortcut(SWT.CTRL, SWT.CR); AbstractRefactoringSwtBotTest.bot.shell(dialogName).activate(); AbstractRefactoringSwtBotTest.bot.button("OK").click(); } else { xtendEditor.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("Preview >").click(); } it.button("OK").click(); }; ObjectExtensions.<SWTBot>operator_doubleArrow(_bot, _function); } this.waitForRefactoring(xtendEditor); }
Example #22
Source File: XtendFormatter.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@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 #23
Source File: XbaseFormatter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void _format(final XPostfixOperation expr, @Extension final IFormattableDocument doc) { final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> { it.noSpace(); }; doc.prepend(this.textRegionExtensions.regionFor(expr).feature(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE), _function); doc.<XExpression>format(expr.getOperand()); }
Example #24
Source File: JdtFindReferencesTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testMethodJavaElements() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("class Xtend {"); _builder.newLine(); _builder.append("\t"); _builder.append("def foo() {"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XtendMember method = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(this._workbenchTestHelper.xtendFile("Xtend.xtend", _builder.toString()).getXtendTypes(), XtendClass.class)).getMembers()); IResourcesSetupUtil.waitForBuild(); Iterable<IJavaElement> _javaElements = this._jvmModelFindReferenceHandler.getJavaElements(method); 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 IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "foo"))); }; Assert.assertTrue(IterableExtensions.<IJavaElement>exists(it, _function_1)); }; ObjectExtensions.<Iterable<IJavaElement>>operator_doubleArrow(_javaElements, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #25
Source File: DeclarationsTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
/** * 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 #26
Source File: XtendIncrementalBuilderTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@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 #27
Source File: DeclarationsTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testSimpleClassWithField() { StringConcatenation _builder = new StringConcatenation(); _builder.append("package foo"); _builder.newLine(); _builder.newLine(); _builder.append("class MyClass extends Object implements java.io.Serializable {"); _builder.newLine(); _builder.append("\t"); _builder.append("MyClass foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> { Assert.assertEquals("foo", it.getPackageName()); TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations()); final ClassDeclaration clazz = ((ClassDeclaration) _head); Assert.assertEquals("foo.MyClass", clazz.getQualifiedName()); Assert.assertEquals("Object", clazz.getExtendedClass().toString()); Assert.assertEquals("Serializable", IterableExtensions.head(clazz.getImplementedInterfaces()).toString()); MemberDeclaration _head_1 = IterableExtensions.head(clazz.getDeclaredMembers()); final FieldDeclaration field = ((FieldDeclaration) _head_1); Assert.assertEquals("foo", field.getSimpleName()); Assert.assertSame(it.getTypeLookup().findClass("foo.MyClass"), field.getType().getType()); }; this.asCompilationUnit(this.validFile(_builder), _function); }
Example #28
Source File: XbaseFormatterTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void formatIfElseIf1() { 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 if (false)"); _builder.newLine(); _builder.append("\t"); _builder.append("println(\"bar\")"); _builder.newLine(); it.setExpectation(_builder); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("if(true)"); _builder_1.newLine(); _builder_1.append("println(\"foo\")"); _builder_1.newLine(); _builder_1.append("else if(false)"); _builder_1.newLine(); _builder_1.append("println(\"bar\")"); _builder_1.newLine(); it.setToBeFormatted(_builder_1); }; this._xbaseFormatterTester.assertFormattedExpression(_function); }
Example #29
Source File: XtextCallHierarchyBuilderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void testBuildCalleeHierarchy(final Procedure1<? super AbstractHierarchyBuilderTest.HierarchyBuilderTestConfiguration> configurator) { final Procedure1<AbstractHierarchyBuilderTest.HierarchyBuilderTestConfiguration> _function = (AbstractHierarchyBuilderTest.HierarchyBuilderTestConfiguration it) -> { final Function1<ResourceSet, IHierarchyBuilder> _function_1 = (ResourceSet resourceSet) -> { final XtextCallHierarchyBuilder callHierarchyBuilder = this.<XtextCallHierarchyBuilder>configureBuilderWith(this.callHierarchyBuilderProvider.get(), resourceSet); callHierarchyBuilder.setHierarchyType(ICallHierarchyBuilder.CallHierarchyType.CALLEE); return callHierarchyBuilder; }; it.setHierarchyBuilderProvider(_function_1); configurator.apply(it); }; super.testBuildHierarchy(_function); }
Example #30
Source File: AbstractRefactoringSwtBotTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
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); }