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

The following examples show how to use org.eclipse.xtext.xbase.lib.IterableExtensions. 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-xtend   Author: eclipse   File: DirtyStateEditorValidationTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private void assertNumberOfErrorAnnotations(final XtextEditor editor, final int expectedNumber) {
  final Function0<Boolean> _function = () -> {
    int _size = this.getErrorAnnotations(editor).size();
    return Boolean.valueOf((_size == expectedNumber));
  };
  this.helper.awaitUIUpdate(_function, DirtyStateEditorValidationTest.VALIDATION_TIMEOUT);
  final List<Annotation> errors = this.getErrorAnnotations(editor);
  final Function1<Annotation, String> _function_1 = (Annotation it) -> {
    String _text = it.getText();
    String _plus = (_text + "(");
    boolean _isPersistent = it.isPersistent();
    String _plus_1 = (_plus + Boolean.valueOf(_isPersistent));
    return (_plus_1 + ")");
  };
  Assert.assertEquals(IterableExtensions.join(ListExtensions.<Annotation, String>map(errors, _function_1), ", "), expectedNumber, errors.size());
}
 
Example #2
Source Project: xtext-core   Author: eclipse   File: ValidatorTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDiagnosticAtEndOfLineIncludingNewline() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("type");
  _builder.newLine();
  this.writeFile("MyType1.testlang", Strings.toUnixLineSeparator(_builder));
  this.initialize();
  final List<Diagnostic> problems = IterableExtensions.<Map.Entry<String, List<Diagnostic>>>head(this.getDiagnostics().entrySet()).getValue();
  String _join = IterableExtensions.join(problems, "\n");
  String _plus = ("problems found:\n" + _join);
  Assert.assertEquals(_plus, 1, problems.size());
  final Diagnostic problem = IterableExtensions.<Diagnostic>head(problems);
  this.assertEquals("mismatched input \'<EOF>\' expecting RULE_ID", problem.getMessage());
  Assert.assertEquals(org.eclipse.xtext.diagnostics.Diagnostic.SYNTAX_DIAGNOSTIC, problem.getCode().get());
  final Range range = problem.getRange();
  Assert.assertEquals(0, range.getStart().getLine());
  Assert.assertEquals(4, range.getStart().getCharacter());
  Assert.assertEquals(1, range.getEnd().getLine());
  Assert.assertEquals(0, range.getEnd().getCharacter());
}
 
Example #3
Source Project: xtext-xtend   Author: eclipse   File: XtendUIValidationTests.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDiscouragedTypeUsageInnernClass() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def bar(org.eclipse.xtend.core.tests.internal.InternalClass$InnerInternalClass x){}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile xtendFile = this.testHelper.xtendFile("Clazz.xtend", _builder.toString());
    XtendMember _head = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers());
    final XtendFunction function = ((XtendFunction) _head);
    this.helper.assertWarning(function.getParameters().get(0), TypesPackage.Literals.JVM_TYPE_REFERENCE, org.eclipse.xtext.xbase.validation.IssueCodes.DISCOURAGED_REFERENCE);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #4
Source Project: xtext-xtend   Author: eclipse   File: JavaFileConverterTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public JavaConverter.ConversionResult converToXtend(final String unitName, final String javaCode) {
  try {
    final JavaConverter j2x = this.javaConverter.get();
    JavaConverter.ConversionResult result = j2x.toXtend(unitName, javaCode);
    int _size = IterableExtensions.size(result.getProblems());
    boolean _equals = (_size == 0);
    if (_equals) {
      try {
        this.file(result.getXtendCode(), true);
      } catch (final Throwable _t) {
        if (_t instanceof AssertionError) {
          result = j2x.useRobustSyntax().toXtend(unitName, javaCode);
        } else {
          throw Exceptions.sneakyThrow(_t);
        }
      }
    }
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #5
Source Project: xtext-xtend   Author: eclipse   File: Solution_023.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public static boolean isAbundant(final int input) {
  final int sqrt = Double.valueOf(Math.floor(Math.sqrt(input))).intValue();
  final Function1<Integer, Boolean> _function = (Integer div) -> {
    return Boolean.valueOf((((div).intValue() != input) && ((input % (div).intValue()) == 0)));
  };
  final Function2<Integer, Integer, Integer> _function_1 = (Integer i1, Integer i2) -> {
    int _xblockexpression = (int) 0;
    {
      final int other = (input / (i2).intValue());
      int _xifexpression = (int) 0;
      if (((other != (i2).intValue()) && (other != input))) {
        _xifexpression = (((i1).intValue() + (i2).intValue()) + other);
      } else {
        _xifexpression = ((i1).intValue() + (i2).intValue());
      }
      _xblockexpression = _xifexpression;
    }
    return Integer.valueOf(_xblockexpression);
  };
  final Integer sumOfDivisors = IterableExtensions.<Integer, Integer>fold(IterableExtensions.<Integer>filter(new IntegerRange(2, sqrt), _function), Integer.valueOf(1), _function_1);
  return ((sumOfDivisors).intValue() > input);
}
 
Example #6
Source Project: xtext-core   Author: eclipse   File: BuildManager.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.18
 */
protected void mergeWithUnreportedDeltas(List<IResourceDescription.Delta> newDeltas) {
	if (unreportedDeltas.isEmpty()) {
		unreportedDeltas.addAll(newDeltas);
	} else {
		Map<URI, IResourceDescription.Delta> unreportedByUri = IterableExtensions.toMap(unreportedDeltas,
				IResourceDescription.Delta::getUri);
		for(IResourceDescription.Delta newDelta: newDeltas) {
			IResourceDescription.Delta unreportedDelta = unreportedByUri.get(newDelta.getUri());
			if (unreportedDelta == null) {
				unreportedDeltas.add(newDelta);
			} else {
				unreportedDeltas.remove(unreportedDelta);
				IResourceDescription oldDescription = unreportedDelta.getOld();
				IResourceDescription newDescription = newDelta.getNew();
				unreportedDeltas.add(new DefaultResourceDescriptionDelta(oldDescription, newDescription));
			}
		}
	}
}
 
Example #7
Source Project: xtext-xtend   Author: eclipse   File: XtendOutlineSourceTreeBuilder.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected void buildDispatchers(final JvmDeclaredType inferredType, final JvmDeclaredType baseType, final IXtendOutlineContext context) {
  final Function1<JvmOperation, Boolean> _function = (JvmOperation it) -> {
    return Boolean.valueOf(this.dispatchHelper.isDispatcherFunction(it));
  };
  Iterable<JvmOperation> _filter = IterableExtensions.<JvmOperation>filter(inferredType.getDeclaredOperations(), _function);
  for (final JvmOperation dispatcher : _filter) {
    {
      final List<JvmOperation> dispatchCases = this.getDispatchCases(dispatcher, baseType, context);
      final IXtendOutlineContext dispatcherContext = this.xtendOutlineNodeBuilder.buildDispatcherNode(baseType, dispatcher, dispatchCases, context).markAsProcessed(dispatcher);
      for (final JvmOperation dispatchCase : dispatchCases) {
        EObject _elvis = null;
        XtendFunction _xtendFunction = this._iXtendJvmAssociations.getXtendFunction(dispatchCase);
        if (_xtendFunction != null) {
          _elvis = _xtendFunction;
        } else {
          _elvis = dispatchCase;
        }
        this.buildFeature(baseType, dispatchCase, _elvis, dispatcherContext).markAsProcessed(dispatchCase);
      }
    }
  }
}
 
Example #8
Source Project: xtext-core   Author: eclipse   File: CodeLensTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testCodeLens() {
  final Procedure1<AbstractLanguageServerTest.TestCodeLensConfiguration> _function = (AbstractLanguageServerTest.TestCodeLensConfiguration it) -> {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("type Foo {}");
    _builder.newLine();
    _builder.append("type Bar {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("Foo foo");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    it.setModel(_builder.toString());
    final Procedure1<List<? extends CodeLens>> _function_1 = (List<? extends CodeLens> it_1) -> {
      this.assertEquals("Do Awesome Stuff(RESOLVED)", IterableExtensions.head(it_1).getCommand().getTitle());
      Object _data = IterableExtensions.head(it_1).getData();
      Assert.assertEquals(1, ((Position) _data).getLine());
    };
    it.setAssertCodeLenses(_function_1);
  };
  this.testCodeLens(_function);
}
 
Example #9
Source Project: xtext-xtend   Author: eclipse   File: QuickfixTestBuilder.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public QuickfixTestBuilder assertModelAfterQuickfix(final CharSequence expectedModel) {
  QuickfixTestBuilder _xblockexpression = null;
  {
    final Function1<Issue, List<IssueResolution>> _function = (Issue it) -> {
      return this._issueResolutionProvider.getResolutions(it);
    };
    final List<IssueResolution> resolutions = IterableExtensions.<IssueResolution>toList(Iterables.<IssueResolution>concat(IterableExtensions.<Issue, List<IssueResolution>>map(this.getIssuesAtCaret(), _function)));
    final String originalModel = this.editor.getDocument().get();
    final IssueResolution resolution = IterableExtensions.<IssueResolution>head(resolutions);
    Assert.assertNotNull(resolution);
    resolution.apply();
    Assert.assertEquals(expectedModel.toString(), this.editor.getDocument().get());
    this.editor.getDocument().set(originalModel);
    this._syncUtil.waitForReconciler(this.editor);
    _xblockexpression = this;
  }
  return _xblockexpression;
}
 
Example #10
Source Project: xtext-web   Author: eclipse   File: EntitiesValidator.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Check
public void checkOperationNamesAreUnique(Entity entity) {
	JvmGenericType inferredJavaClass = IterableExtensions
			.head(Iterables.filter(jvmModelAssociations.getJvmElements(entity), JvmGenericType.class));
	Multimap<String, JvmOperation> signature2Declarations = HashMultimap.create();
	overrideHelper.getResolvedFeatures(inferredJavaClass).getDeclaredOperations().forEach((it) -> {
		signature2Declarations.put(it.getResolvedErasureSignature(), it.getDeclaration());
	});
	signature2Declarations.asMap().values().forEach((jvmOperations) -> {
		if (jvmOperations.size() > 1) {
			Iterables
					.filter(IterableExtensions.map(jvmOperations,
							(op) -> jvmModelAssociations.getPrimarySourceElement(op)), Operation.class)
					.forEach((op) -> {
						error("Duplicate operation " + op.getName(), op, DomainmodelPackage.Literals.FEATURE__NAME, IssueCodes.DUPLICATE_OPERATION);
					});
		}
	});
}
 
Example #11
Source Project: xtext-core   Author: eclipse   File: AbstractLanguageServerTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected String _toExpectation(final Command it) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("command : ");
  String _command = it.getCommand();
  _builder.append(_command);
  _builder.newLineIfNotEmpty();
  _builder.append("title : ");
  String _title = it.getTitle();
  _builder.append(_title);
  _builder.newLineIfNotEmpty();
  _builder.append("args : ");
  _builder.newLine();
  _builder.append("\t");
  final Function1<Object, CharSequence> _function = (Object it_1) -> {
    return this.toExpectation(it_1);
  };
  String _join = IterableExtensions.<Object>join(it.getArguments(), ",", _function);
  _builder.append(_join, "\t");
  _builder.newLineIfNotEmpty();
  return _builder.toString();
}
 
Example #12
Source Project: xtext-core   Author: eclipse   File: GrammarAccessExtensions.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public List<String> initialHiddenTokens(final Grammar it) {
  List<String> _xblockexpression = null;
  {
    boolean _isDefinesHiddenTokens = it.isDefinesHiddenTokens();
    if (_isDefinesHiddenTokens) {
      final Function1<AbstractRule, String> _function = (AbstractRule it_1) -> {
        return this.ruleName(it_1);
      };
      return IterableExtensions.<String>toList(ListExtensions.<AbstractRule, String>map(it.getHiddenTokens(), _function));
    }
    int _size = it.getUsedGrammars().size();
    boolean _equals = (_size == 1);
    if (_equals) {
      return this.initialHiddenTokens(IterableExtensions.<Grammar>head(it.getUsedGrammars()));
    }
    _xblockexpression = CollectionLiterals.<String>emptyList();
  }
  return _xblockexpression;
}
 
Example #13
Source Project: xtext-xtend   Author: eclipse   File: InferredJvmModelTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testBug_340611_02() throws Exception {
	XtendFile xtendFile = file(
			"class Bug340611 {\n" + 
			"    def dispatch foo(String string) {\n" + 
			"        string\n" + 
			"    }\n" + 
			"    def dispatch foo(CharSequence charSeq) {\n" + 
			"        charSeq\n" + 
			"    }\n" + 
			"}", false);
	
	JvmGenericType inferredType = getInferredType(xtendFile);
	assertEquals(3, IterableExtensions.size(inferredType.getDeclaredOperations()));
	
	// one main dispatch
	Iterable<JvmOperation> operations = inferredType.getDeclaredOperations();
	JvmOperation dispatch = findByNameAndFirstParameterType(operations, "foo", CharSequence.class);
	assertEquals("java.lang.CharSequence", dispatch.getReturnType().getIdentifier());

	// two internal case methods
	JvmOperation stringParam = findByNameAndFirstParameterType(operations, "_foo", String.class);
	assertEquals("java.lang.CharSequence", stringParam.getReturnType().getIdentifier());
	
	JvmOperation objectParam = findByNameAndFirstParameterType(operations, "_foo", CharSequence.class);
	assertEquals("java.lang.CharSequence", objectParam.getReturnType().getIdentifier());
}
 
Example #14
Source Project: xtext-extras   Author: eclipse   File: XbaseFormatter2.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected Iterable<XExpression> explicitParams(final List<XExpression> params) {
  Iterable<XExpression> _xblockexpression = null;
  {
    final XClosure builder = this.builder(params);
    Iterable<XExpression> _xifexpression = null;
    if ((builder != null)) {
      int _size = params.size();
      int _minus = (_size - 1);
      _xifexpression = IterableExtensions.<XExpression>take(params, _minus);
    } else {
      _xifexpression = params;
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example #15
Source Project: xtext-core   Author: eclipse   File: IndentationAwareLanguageTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testParentChild() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("parent");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("child");
  _builder.newLine();
  final Tree tree = this.parse(_builder);
  Assert.assertNotNull(tree);
  Assert.assertEquals(1, tree.getNodes().size());
  Assert.assertEquals("parent", IterableExtensions.<TreeNode>head(tree.getNodes()).getName());
  Assert.assertEquals("child", IterableExtensions.<TreeNode>head(IterableExtensions.<TreeNode>head(tree.getNodes()).getChildren()).getName());
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("parent");
  _builder_1.newLine();
  _builder_1.append("\t");
  _builder_1.append("child");
  _builder_1.newLine();
  Assert.assertEquals(_builder_1.toString(), this.asText(tree));
}
 
Example #16
Source Project: xtext-xtend   Author: eclipse   File: Solution_005.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public static void main(final String[] args) {
  ArrayList<Integer> result = CollectionLiterals.<Integer>newArrayList();
  IntegerRange _upTo = new IntegerRange(2, 20);
  for (final Integer i : _upTo) {
    {
      Integer j = i;
      for (final Integer k : result) {
        if ((((j).intValue() % (k).intValue()) == 0)) {
          j = Integer.valueOf(((j).intValue() / (k).intValue()));
        }
      }
      if (((j).intValue() != 1)) {
        result.add(j);
      }
    }
  }
  final Function2<Integer, Integer, Integer> _function = (Integer m1, Integer m2) -> {
    return Integer.valueOf(((m1).intValue() * (m2).intValue()));
  };
  InputOutput.<Integer>println(IterableExtensions.<Integer>reduce(result, _function));
}
 
Example #17
Source Project: xtext-xtend   Author: eclipse   File: OperatorDeclarationTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testOperatorDeclaration_typeParam() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class A {");
    _builder.newLine();
    {
      Set<QualifiedName> _operators = this.operatorMapping.getOperators();
      for(final QualifiedName op : _operators) {
        _builder.append("\t");
        _builder.append("def <T> ");
        _builder.append(op, "\t");
        _builder.append("() { return null }");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this._parseHelper.parse(_builder);
    Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #18
Source Project: xtext-xtend   Author: eclipse   File: XtendHoverSignatureProviderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testInterfaceReference() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package testPackage");
    _builder.newLine();
    _builder.append("class Bar implements Foo {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("interface Foo { }");
    _builder.newLine();
    final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
    XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
    final JvmType in = IterableExtensions.<JvmTypeReference>head(((XtendClass) _head).getImplements()).getType();
    Assert.assertEquals("Foo", this.signatureProvider.getSignature(in));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #19
Source Project: xtext-core   Author: eclipse   File: EMFGeneratorFragment2.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private Map<String, EPackage> findEPackagesInGenPackages(final Collection<String> packageNsURIs, final ResourceSet resourceSet) {
  final HashMap<String, EPackage> result = CollectionLiterals.<String, EPackage>newHashMap();
  for (final String nsURI : packageNsURIs) {
    {
      final Resource resource = GenModelUtil2.getGenModelResource(null, nsURI, resourceSet);
      if ((resource != null)) {
        final GenModel loadedGenModel = IterableExtensions.<GenModel>head(Iterables.<GenModel>filter(resource.getContents(), GenModel.class));
        if ((loadedGenModel != null)) {
          final GenPackage genPackage = this.findGenPackageByNsURI(loadedGenModel, nsURI);
          result.put(nsURI, genPackage.getEcorePackage());
        }
      }
    }
  }
  return result;
}
 
Example #20
Source Project: xtext-extras   Author: eclipse   File: ResourceDescriptionProviderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testStubGeneration_02() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("public interface MyTest {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("public String helloWorld();");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<IResourceDescription> _function = (IResourceDescription it) -> {
    Assert.assertEquals("MyTest", IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getQualifiedName().toString());
    EObject _eObjectOrProxy = IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getEObjectOrProxy();
    Assert.assertTrue(((JvmGenericType) _eObjectOrProxy).isInterface());
    Assert.assertEquals(1, IterableExtensions.size(it.getExportedObjects()));
  };
  this.resultsIn(_builder, _function);
}
 
Example #21
Source Project: xtext-extras   Author: eclipse   File: OrderSensitivityTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void doTestOverloadedAndExpect(final String declarator, final String invocation, final String expectation) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("var java.util.List<CharSequence> chars = null");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("var java.util.List<String> strings = null");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("var ");
    _builder.append(declarator, "\t");
    _builder.append(" receiver = null");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("receiver.");
    _builder.append(invocation, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    _builder.newLine();
    XExpression _expression = this.expression(_builder);
    final XBlockExpression block = ((XBlockExpression) _expression);
    XExpression _last = IterableExtensions.<XExpression>last(block.getExpressions());
    final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
    final JvmIdentifiableElement feature = featureCall.getFeature();
    Assert.assertNotNull("feature is not null", feature);
    Assert.assertFalse("feature is resolved", feature.eIsProxy());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append(declarator);
    _builder_1.append(".");
    _builder_1.append(expectation);
    Assert.assertEquals(_builder_1.toString(), feature.getIdentifier());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #22
Source Project: n4js   Author: eclipse   File: AbstractIdeTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private String issuesToSortedString(Iterable<String> issues, String indent) {
	if (Iterables.isEmpty(issues)) {
		return indent + "<none>";
	}
	return IterableExtensions.sort(issues).stream()
			.map(issue -> issue.replace("\n", "\n" + indent))
			.collect(Collectors.joining("\n" + indent));
}
 
Example #23
Source Project: xtext-extras   Author: eclipse   File: XtypeFormatter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XImportSection section, @Extension final IFormattableDocument format) {
  EList<XImportDeclaration> _importDeclarations = section.getImportDeclarations();
  for (final XImportDeclaration imp : _importDeclarations) {
    {
      format.<XImportDeclaration>format(imp);
      XImportDeclaration _last = IterableExtensions.<XImportDeclaration>last(section.getImportDeclarations());
      boolean _notEquals = (!Objects.equal(imp, _last));
      if (_notEquals) {
        format.<XImportDeclaration>append(imp, XbaseFormatterPreferenceKeys.blankLinesBetweenImports);
      } else {
        format.<XImportDeclaration>append(imp, XbaseFormatterPreferenceKeys.blankLinesAfterImports);
      }
    }
  }
}
 
Example #24
Source Project: xtext-lib   Author: eclipse   File: IterableExtensionsTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testFlatMap () {
	ArrayList<String> list = newArrayList("foo", "bar");
	
	final Functions.Function1<String, Iterable<String>> function = new Functions.Function1<String, Iterable<String>>() {
		@Override
		public Iterable<String> apply(String p) {
			return newArrayList("Hello", p);
		}
	};
	assertEquals(newArrayList("Hello", "foo", "Hello", "bar"), newArrayList(IterableExtensions.flatMap(list, function)));
}
 
Example #25
Source Project: xtext-xtend   Author: eclipse   File: AbstractXtendCompilerTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected XtendFile doAssertCompilesTo(final CharSequence input, final CharSequence expected, final GeneratorConfig config, final boolean serializeAllTypes) {
  try {
    final XtendFile file = this.file(input.toString(), true);
    final ArrayList<CharSequence> results = CollectionLiterals.<CharSequence>newArrayList();
    Iterable<JvmDeclaredType> _filter = Iterables.<JvmDeclaredType>filter(file.eResource().getContents(), JvmDeclaredType.class);
    for (final JvmDeclaredType inferredType : _filter) {
      {
        Assert.assertFalse(DisableCodeGenerationAdapter.isDisabled(inferredType));
        CharSequence javaCode = this.generator.generateType(inferredType, config);
        javaCode = this.postProcessor.postProcess(null, javaCode);
        results.add(javaCode);
        if (this.useJavaCompiler) {
          final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
            it.getCompiledClass();
          };
          this.compilationTestHelper.compile(input, _function);
        }
      }
    }
    if (serializeAllTypes) {
      Assert.assertEquals(expected.toString(), IterableExtensions.join(results, "\n"));
    } else {
      Assert.assertEquals(expected.toString(), IterableExtensions.<CharSequence>head(results).toString());
    }
    return file;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #26
Source Project: xtext-xtend   Author: eclipse   File: AccessRestrictionInWorkspaceTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testReexported() {
  try {
    final XtendFile xtendFile = this.parse(IResourcesSetupUtil.createFile("thirdProject/src/Dummy.xtend", "class D { allowed.C c }"));
    XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
    final XtendClass c = ((XtendClass) _head);
    this._validationTestHelper.assertNoError(c, IssueCodes.DISCOURAGED_REFERENCE);
    this._validationTestHelper.assertNoError(c, IssueCodes.FORBIDDEN_REFERENCE);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #27
Source Project: n4js   Author: eclipse   File: N4ClassifierDefinitionImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EList<N4MemberDeclaration> getOwnedMembers() {
	final Function1<N4MemberDeclaration, Boolean> _function = new Function1<N4MemberDeclaration, Boolean>() {
		public Boolean apply(final N4MemberDeclaration it) {
			boolean _isCallableConstructor = it.isCallableConstructor();
			return Boolean.valueOf((!_isCallableConstructor));
		}
	};
	final Iterable<N4MemberDeclaration> methods = IterableExtensions.<N4MemberDeclaration>filter(Iterables.<N4MemberDeclaration>filter(this.getOwnedMembersRaw(), N4MemberDeclaration.class), _function);
	List<N4MemberDeclaration> _list = IterableExtensions.<N4MemberDeclaration>toList(methods);
	return new BasicEList<N4MemberDeclaration>(_list);
}
 
Example #28
Source Project: xtext-xtend   Author: eclipse   File: FileLocationsImpl.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Path getSourceFolder(final Path path) {
  final Function1<Path, Boolean> _function = (Path sourceFolder) -> {
    return Boolean.valueOf(path.startsWith(sourceFolder));
  };
  return IterableExtensions.<Path>findFirst(this.getProjectSourceFolders(path), _function);
}
 
Example #29
Source Project: xtext-core   Author: eclipse   File: WizardConfigurationTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void inlinedTestProjectsDontOverrideMainSources() {
	config.getRuntimeProject().getTestProject().setEnabled(true);
	config.setPreferredBuildSystem(BuildSystem.MAVEN);
	config.setSourceLayout(SourceLayout.MAVEN);
	AbstractFile pom = IterableExtensions.findFirst(config.getRuntimeProject().getFiles(),
			(AbstractFile it) -> "pom.xml".equals(it.getRelativePath()));
	assertTrue(pom instanceof PomFile);
	assertTrue(((PomFile) pom).getContent().toString().contains("<artifactId>org.example.mydsl</artifactId>"));
}
 
Example #30
Source Project: n4js   Author: eclipse   File: N4ClassifierDefinitionImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EList<N4FieldDeclaration> getOwnedFields() {
	final Iterable<N4FieldDeclaration> fields = Iterables.<N4FieldDeclaration>filter(this.getOwnedMembersRaw(), N4FieldDeclaration.class);
	List<N4FieldDeclaration> _list = IterableExtensions.<N4FieldDeclaration>toList(fields);
	return new BasicEList<N4FieldDeclaration>(_list);
}