org.eclipse.xtext.xbase.lib.IteratorExtensions Java Examples

The following examples show how to use org.eclipse.xtext.xbase.lib.IteratorExtensions. 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: IteratorExtensionsTest.java    From xtext-lib with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testToMap__WhenCalculatedKeyNull() {
	List<String> names = new ArrayList<String>();
	names.add("Mueller");
	names.add("Schneider");
	names.add("Schmidt");
	names.add("Koch");
	Function1<String, String> computeKeys = new Function1<String, String>() {

		@Override
		public String apply(String p) {
			return p.contains("y") ? "y" : null;
		}
	};
	Map<String, String> map = IteratorExtensions.toMap(names.iterator(), computeKeys);
	Assert.assertEquals("Expected grouped map size", 1, map.size());
	Assert.assertTrue("Contains null as key", map.keySet().contains(null));
	Assert.assertEquals("Contains entry Koch for key null", "Koch", map.get(null));
}
 
Example #2
Source File: IteratorExtensionsTest.java    From xtext-lib with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testToMap__WhenNoValuesForKey() {
	List<String> names = new ArrayList<String>();
	names.add("Mueller");
	names.add("Schneider");
	names.add("Schmidt");
	names.add("Koch");
	Function1<String, Boolean> computeKeys = new Function1<String, Boolean>() {

		@Override
		public Boolean apply(String p) {
			return p.contains("y");
		}
	};
	Map<Boolean, String> map = IteratorExtensions.toMap(names.iterator(), computeKeys);
	Assert.assertEquals("Expected grouped map size", 1, map.size());
	Assert.assertTrue("Contains FALSE as key", map.keySet().contains(Boolean.FALSE));
	Assert.assertTrue("Contains entry Mueller for key FALSE", map.get(Boolean.FALSE).equals("Koch"));
	Assert.assertNull("Contains no entry for key Boolean.TRUE", map.get(Boolean.TRUE));
}
 
Example #3
Source File: CachingResourceValidatorImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
private void addWarningsForOrphanedJvmElements(final Resource resource, final CancelIndicator monitor, final IAcceptor<Issue> acceptor) {
  final IssueSeverities issueSeverities = this.issueSeveritiesProvider.getIssueSeverities(resource);
  final Severity severity = issueSeverities.getSeverity(IssueCodes.ORPHAN_ELEMENT);
  boolean _equals = Objects.equal(severity, Severity.IGNORE);
  if (_equals) {
    return;
  }
  Iterable<JvmDeclaredType> _filter = Iterables.<JvmDeclaredType>filter(IterableExtensions.<EObject>tail(resource.getContents()), JvmDeclaredType.class);
  for (final JvmDeclaredType jvmType : _filter) {
    final Function1<JvmMember, Boolean> _function = (JvmMember it) -> {
      boolean _isSynthetic = this._jvmTypeExtensions.isSynthetic(it);
      return Boolean.valueOf((!_isSynthetic));
    };
    Iterable<JvmMember> _iterable = IteratorExtensions.<JvmMember>toIterable(IteratorExtensions.<JvmMember>filter(Iterators.<JvmMember>filter(jvmType.eAllContents(), JvmMember.class), _function));
    for (final JvmMember jvmMember : _iterable) {
      {
        this.operationCanceledManager.checkCanceled(monitor);
        final EObject sourceElement = this._iJvmModelAssociations.getPrimarySourceElement(jvmMember);
        if ((sourceElement == null)) {
          this.addWarningForOrphanedJvmElement(resource, jvmMember, severity, acceptor);
        }
      }
    }
  }
}
 
Example #4
Source File: IteratorExtensionsTest.java    From xtext-lib with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testGroupBy() {
	List<Pair<Integer, String>> pairs = new ArrayList<Pair<Integer, String>>();
	pairs.add(new Pair<Integer, String>(1, "A"));
	pairs.add(new Pair<Integer, String>(1, "a"));
	pairs.add(new Pair<Integer, String>(2, "B"));
	pairs.add(new Pair<Integer, String>(2, "b"));
	Function1<Pair<Integer, String>, Integer> computeKeys = new Function1<Pair<Integer, String>, Integer>() {

		@Override
		public Integer apply(Pair<Integer, String> p) {
			return p.getKey();
		}
	};
	Map<Integer, List<Pair<Integer, String>>> map = IteratorExtensions.groupBy(pairs.iterator(), computeKeys);
	Assert.assertEquals("Expected grouped map size", 2, map.size());
	Assert.assertTrue("Contains 1 as key", map.keySet().contains(1));
	Assert.assertEquals("Contains 2 entries for key 1", 2, map.get(1).size());
	Assert.assertEquals("Contains entry 1->A for key 1", new Pair<Integer, String>(1, "A"), map.get(1).get(0));
	Assert.assertEquals("Contains entry 1->a for key 1", new Pair<Integer, String>(1, "a"), map.get(1).get(1));
	Assert.assertTrue("Contains 2 as key", map.keySet().contains(2));
	Assert.assertEquals("Contains 2 entries for key 2", 2, map.get(2).size());
	Assert.assertEquals("Contains entry 2->B for key 2", new Pair<Integer, String>(2, "B"), map.get(2).get(0));
	Assert.assertEquals("Contains entry 2->b for key 2", new Pair<Integer, String>(2, "b"), map.get(2).get(1));
}
 
Example #5
Source File: ContentAssistXpectMethod.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private Pair<CommaSeparatedValuesExpectationImpl, CharSequence> expandVariables(
		CommaSeparatedValuesExpectationImpl csvE,
		XpEnvironmentData data) {

	// val CommaSeparatedValuesExpectationImpl csvE = (expectation as CommaSeparatedValuesExpectationImpl);
	IExpectationRegion region = csvE.getRegion();
	CharSequence doc = region.getDocument();
	CharSequence expectedText = null;
	if (region.getLength() < 0) {
		expectedText = "";
	} else {
		expectedText = doc.subSequence(region.getOffset(), region.getOffset() + region.getLength());
	}

	CommaSeparatedValuesExpectationCfg cfg = new CommaSeparatedValuesExpectationCfg(csvE.getAnnotation());
	cfg.setData(data);
	VarSubstCommaSeparatedValuesExpectationImpl csvRet = new VarSubstCommaSeparatedValuesExpectationImpl(csvE,
			cfg);
	VarSubstExpectationCollection vseColl = new VarSubstExpectationCollection(data);
	vseColl.init(expectedText.toString());
	String expandedExpectedText = IteratorExtensions.join(vseColl.iterator(), ",");

	return new Pair<>(csvRet, expandedExpectedText);
}
 
Example #6
Source File: Movies.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public List<Movie> apply() {
  try {
    final Function1<String, Movie> _function = (String line) -> {
      final Iterator<String> segments = ((List<String>)Conversions.doWrapArray(line.split("  "))).iterator();
      String _next = segments.next();
      int _parseInt = Integer.parseInt(segments.next());
      double _parseDouble = Double.parseDouble(segments.next());
      long _parseLong = Long.parseLong(segments.next());
      Set<String> _set = IteratorExtensions.<String>toSet(segments);
      return new Movie(_next, _parseInt, _parseDouble, _parseLong, _set);
    };
    List<Movie> _map = ListExtensions.<String, Movie>map(CharStreams.readLines(new FileReader("data.csv")), _function);
    return _map;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #7
Source File: IteratorExtensionsTest.java    From xtext-lib with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testGroupBy__WhenCalculatedKeyNull() {
	List<String> names = new ArrayList<String>();
	names.add("Mueller");
	names.add("Schneider");
	names.add("Schmidt");
	names.add("Koch");
	Function1<String, String> computeKeys = new Function1<String, String>() {

		@Override
		public String apply(String p) {
			return p.contains("y") ? "y" : null;
		}
	};
	Map<String, List<String>> map = IteratorExtensions.groupBy(names.iterator(), computeKeys);
	Assert.assertEquals("Expected grouped map size", 1, map.size());
	Assert.assertTrue("Contains null as key", map.keySet().contains(null));
	Assert.assertEquals("Contains 4 entries for key null", 4, map.get(null).size());
}
 
Example #8
Source File: ImplicitlyImportedFeatures.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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 #9
Source File: IteratorExtensionsTest.java    From xtext-lib with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testGroupBy__WhenNoValuesForKey() {
	List<String> names = new ArrayList<String>();
	names.add("Mueller");
	names.add("Schneider");
	names.add("Schmidt");
	names.add("Koch");
	Function1<String, Boolean> computeKeys = new Function1<String, Boolean>() {

		@Override
		public Boolean apply(String p) {
			return p.contains("y");
		}
	};
	Map<Boolean, List<String>> map = IteratorExtensions.groupBy(names.iterator(), computeKeys);
	Assert.assertEquals("Expected grouped map size", 1, map.size());
	Assert.assertTrue("Contains FALSE as key", map.keySet().contains(Boolean.FALSE));
	Assert.assertEquals("Contains 4 entries for key Boolean.FALSE", 4, map.get(Boolean.FALSE).size());
	Assert.assertTrue("Contains entry Mueller for key FALSE", map.get(Boolean.FALSE).contains("Mueller"));
	Assert.assertNull("Contains no entry for key Boolean.TRUE", map.get(Boolean.TRUE));
}
 
Example #10
Source File: IteratorExtensionsTest.java    From xtext-lib with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testToMap() {
	List<Pair<Integer, String>> pairs = new ArrayList<Pair<Integer, String>>();
	pairs.add(new Pair<Integer, String>(1, "A"));
	pairs.add(new Pair<Integer, String>(1, "a"));
	pairs.add(new Pair<Integer, String>(2, "B"));
	pairs.add(new Pair<Integer, String>(2, "b"));
	Function1<Pair<Integer, String>, Integer> computeKeys = new Function1<Pair<Integer, String>, Integer>() {

		@Override
		public Integer apply(Pair<Integer, String> p) {
			return p.getKey();
		}
	};
	Map<Integer, Pair<Integer, String>> map = IteratorExtensions.toMap(pairs.iterator(), computeKeys);
	Assert.assertEquals("Expected grouped map size", 2, map.size());
	Assert.assertTrue("Contains 1 as key", map.keySet().contains(1));
	Assert.assertEquals("Contains entry 1->a for key 1", map.get(1), new Pair<Integer, String>(1, "a"));
	Assert.assertTrue("Contains 2 as key", map.keySet().contains(2));
	Assert.assertEquals("Contains entry 2->b for key 2", map.get(2), new Pair<Integer, String>(2, "b"));
}
 
Example #11
Source File: AbstractConstructorCallTypeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected List<XConstructorCall> findConstructorCalls(final CharSequence expression) {
  try {
    final XExpression xExpression = this.expression(expression, false);
    Assert.assertTrue(xExpression.eResource().getErrors().isEmpty());
    final List<XConstructorCall> closures = IteratorExtensions.<XConstructorCall>toList(Iterators.<XConstructorCall>filter(EcoreUtil2.eAll(xExpression), XConstructorCall.class));
    final Function1<XConstructorCall, Integer> _function = (XConstructorCall it) -> {
      return Integer.valueOf(IterableExtensions.<INode>head(NodeModelUtils.findNodesForFeature(it, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR)).getOffset());
    };
    return IterableExtensions.<XConstructorCall, Integer>sortBy(closures, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #12
Source File: IteratorExtensionsTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testToMap__WhenEmptyList() {
	List<Pair<Integer, String>> pairs = new ArrayList<Pair<Integer, String>>();
	Function1<Pair<Integer, String>, Integer> computeKeys = new Function1<Pair<Integer, String>, Integer>() {

		@Override
		public Integer apply(Pair<Integer, String> p) {
			return p.getKey();
		}
	};
	Map<Integer, Pair<Integer, String>> map = IteratorExtensions.toMap(pairs.iterator(), computeKeys);
	Assert.assertEquals("Expected grouped map size", 0, map.size());
}
 
Example #13
Source File: AbstractClosureTypeTest2.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected List<XClosure> findClosures(final CharSequence expression) {
  try {
    final String expressionAsString = expression.toString().replace("ClosureTypeResolutionTestData", "org.eclipse.xtext.xbase.tests.typesystem.ClosureTypeResolutionTestData").replace("$$", "org::eclipse::xtext::xbase::lib::");
    final XExpression xExpression = this.expression(expressionAsString, false);
    final List<XClosure> Closures = IteratorExtensions.<XClosure>toList(Iterators.<XClosure>filter(EcoreUtil2.eAll(xExpression), XClosure.class));
    final Function1<XClosure, Integer> _function = (XClosure it) -> {
      return Integer.valueOf(NodeModelUtils.findActualNodeFor(it).getOffset());
    };
    return IterableExtensions.<XClosure, Integer>sortBy(Closures, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #14
Source File: StringLiteralTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected List<XStringLiteral> findLiterals(final CharSequence expression) {
  try {
    final XExpression xExpression = this.expression(expression, false);
    final List<XStringLiteral> featureCalls = IteratorExtensions.<XStringLiteral>toList(Iterators.<XStringLiteral>filter(EcoreUtil2.eAll(xExpression), XStringLiteral.class));
    final Function1<XStringLiteral, Integer> _function = (XStringLiteral it) -> {
      return Integer.valueOf(NodeModelUtils.findActualNodeFor(it).getOffset());
    };
    return IterableExtensions.<XStringLiteral, Integer>sortBy(featureCalls, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #15
Source File: BlockImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Iterator<YieldExpression> getAllVoidYieldExpressions() {
	final Function1<YieldExpression, Boolean> _function = new Function1<YieldExpression, Boolean>() {
		public Boolean apply(final YieldExpression it) {
			Expression _expression = it.getExpression();
			return Boolean.valueOf((_expression == null));
		}
	};
	return IteratorExtensions.<YieldExpression>filter(this.getAllYieldExpressions(), _function);
}
 
Example #16
Source File: AbstractExpectationTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testImplicitFirstArgument() {
  ExpectationTestingTypeComputer _typeComputer = this.getTypeComputer();
  final Function1<XExpression, Boolean> _function = (XExpression it) -> {
    return Boolean.valueOf(false);
  };
  _typeComputer.setPredicate(_function);
  this.expects("{val it = null as String[] head}");
  final XFeatureCall size = IteratorExtensions.<XFeatureCall>head(Iterators.<XFeatureCall>filter(this.rootExpression.eAllContents(), XFeatureCall.class));
  XExpression _implicitFirstArgument = size.getImplicitFirstArgument();
  this.expressions.add(_implicitFirstArgument);
  this.queriedAs("Iterable<String>");
}
 
Example #17
Source File: AbstractClosureTypeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected List<XClosure> findClosures(final CharSequence expression) {
  try {
    final String expressionAsString = expression.toString().replace("ClosureTypeResolutionTestData", "org.eclipse.xtext.xbase.tests.typesystem.ClosureTypeResolutionTestData").replace("$$", "org::eclipse::xtext::xbase::lib::");
    final XExpression xExpression = this.expression(expressionAsString, false);
    final List<XClosure> Closures = IteratorExtensions.<XClosure>toList(Iterators.<XClosure>filter(EcoreUtil2.eAll(xExpression), XClosure.class));
    final Function1<XClosure, Integer> _function = (XClosure it) -> {
      return Integer.valueOf(NodeModelUtils.findActualNodeFor(it).getOffset());
    };
    return IterableExtensions.<XClosure, Integer>sortBy(Closures, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #18
Source File: AbstractFeatureCallTypeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected List<XAbstractFeatureCall> findFeatureCalls(final CharSequence expression) {
  try {
    final XExpression xExpression = this.expression(expression, false);
    final List<XAbstractFeatureCall> featureCalls = IteratorExtensions.<XAbstractFeatureCall>toList(Iterators.<XAbstractFeatureCall>filter(EcoreUtil2.eAll(xExpression), XAbstractFeatureCall.class));
    final Function1<XAbstractFeatureCall, Integer> _function = (XAbstractFeatureCall it) -> {
      return Integer.valueOf(IterableExtensions.<INode>head(NodeModelUtils.findNodesForFeature(it, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE)).getOffset());
    };
    return IterableExtensions.<XAbstractFeatureCall, Integer>sortBy(featureCalls, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #19
Source File: BlockImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Iterator<ReturnStatement> getAllVoidReturnStatements() {
	final Function1<ReturnStatement, Boolean> _function = new Function1<ReturnStatement, Boolean>() {
		public Boolean apply(final ReturnStatement it) {
			Expression _expression = it.getExpression();
			return Boolean.valueOf((_expression == null));
		}
	};
	return IteratorExtensions.<ReturnStatement>filter(this.getAllReturnStatements(), _function);
}
 
Example #20
Source File: BlockImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Iterator<YieldExpression> getAllNonVoidYieldExpressions() {
	final Function1<YieldExpression, Boolean> _function = new Function1<YieldExpression, Boolean>() {
		public Boolean apply(final YieldExpression it) {
			Expression _expression = it.getExpression();
			return Boolean.valueOf((_expression != null));
		}
	};
	return IteratorExtensions.<YieldExpression>filter(this.getAllYieldExpressions(), _function);
}
 
Example #21
Source File: IteratorExtensionsTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGroupBy__WhenEmptyList() {
	List<Pair<Integer, String>> pairs = new ArrayList<Pair<Integer, String>>();
	Function1<Pair<Integer, String>, Integer> computeKeys = new Function1<Pair<Integer, String>, Integer>() {

		@Override
		public Integer apply(Pair<Integer, String> p) {
			return p.getKey();
		}
	};
	Map<Integer, List<Pair<Integer, String>>> map = IteratorExtensions.groupBy(pairs.iterator(), computeKeys);
	Assert.assertEquals("Expected grouped map size", 0, map.size());
}
 
Example #22
Source File: IteratorExtensionsTest.java    From xtext-lib with 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, Iterator<String>> function = new Functions.Function1<String, Iterator<String>>() {
		@Override
		public Iterator<String> apply(String p) {
			return newArrayList("Hello", p).iterator();
		}
	};
	assertEquals(newArrayList("Hello", "foo", "Hello", "bar"), newArrayList(IteratorExtensions.flatMap(list.iterator(), function)));
}
 
Example #23
Source File: IteratorExtensionsTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testContains() {
	ArrayList<String> list = newArrayList("element1", "element2", "element3", null);
	
	assertTrue(IteratorExtensions.contains(list.iterator(), "element3"));
	assertTrue(IteratorExtensions.contains(list.iterator(), new String("element3")));
	
	assertTrue(IteratorExtensions.contains(list.iterator(), null));
	
	assertFalse(IteratorExtensions.contains(list.iterator(), "element4"));
	assertFalse(IteratorExtensions.contains(list.iterator(), new String("element4")));
}
 
Example #24
Source File: Oven.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void fireproof(String input) throws Exception {
	try {
		EObject file = parseHelper.parse(input);
		IResolvedTypes resolvedTypes = typeResolver.resolveTypes(file);
		Assert.assertNotNull(resolvedTypes);
		if (file == null) {
			return;
		}
		for (EObject content : IteratorExtensions.toIterable(file.eAllContents())) {
			if (content instanceof XAbstractFeatureCall) {
				assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
				XAbstractFeatureCall abstractFeatureCall = (XAbstractFeatureCall) content;
				if (abstractFeatureCall.getImplicitReceiver() != null) {
					assertExpressionTypeIsResolved(abstractFeatureCall.getImplicitReceiver(), resolvedTypes);
				}
				if (abstractFeatureCall.getImplicitFirstArgument() != null) {
					assertExpressionTypeIsResolved(abstractFeatureCall.getImplicitFirstArgument(), resolvedTypes);
				}
			} else if (content instanceof XClosure) {
				assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
				((XClosure) content).getImplicitFormalParameters()
						.forEach((JvmFormalParameter it) -> assertIdentifiableTypeIsResolved(it, resolvedTypes));
			} else if (content instanceof XExpression) {
				assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
			} else if (content instanceof JvmIdentifiableElement) {
				assertIdentifiableTypeIsResolved(((JvmIdentifiableElement) content), resolvedTypes);
			}
		}
	} catch (Throwable e) {
		ComparisonFailure error = new ComparisonFailure(e.getMessage(), input, "");
		error.setStackTrace(e.getStackTrace());
		throw error;
	}
}
 
Example #25
Source File: DirtyStateEditorValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private List<Annotation> getErrorAnnotations(final XtextEditor editor) {
  final Function1<Annotation, Boolean> _function = (Annotation it) -> {
    String _type = it.getType();
    return Boolean.valueOf(Objects.equal(_type, "org.eclipse.xtext.ui.editor.error"));
  };
  return IteratorExtensions.<Annotation>toList(IteratorExtensions.<Annotation>filter(Iterators.<Annotation>filter(editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput()).getAnnotationIterator(), Annotation.class), _function));
}
 
Example #26
Source File: DirtyStateEditorSupportTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private List<Annotation> getErrorAnnotations(final XtextEditor editor) {
  final Function1<Annotation, Boolean> _function = (Annotation it) -> {
    String _type = it.getType();
    return Boolean.valueOf(Objects.equal(_type, "org.eclipse.xtext.ui.editor.error"));
  };
  return IteratorExtensions.<Annotation>toList(IteratorExtensions.<Annotation>filter(Iterators.<Annotation>filter(editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput()).getAnnotationIterator(), Annotation.class), _function));
}
 
Example #27
Source File: ErrorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testErrorModel_077() throws Exception {
  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("try return \'literal\' as as Boolean");
  _builder.newLine();
  _builder.append("\t\t  ");
  _builder.append("catch(NullPointerException e) return \'second thing is thrown\'\t\t  ");
  _builder.newLine();
  _builder.append("\t\t  ");
  _builder.append("catch(ClassCastException e) throw new NullPointerException()");
  _builder.newLine();
  _builder.append("    ");
  _builder.append("}");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final XtendFile file = this.processWithoutException(_builder);
  final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(file);
  final XCastedExpression casted = IteratorExtensions.<XCastedExpression>last(Iterators.<XCastedExpression>filter(file.eAllContents(), XCastedExpression.class));
  Assert.assertNull(casted.getType());
  Assert.assertNotNull(resolvedTypes.getActualType(casted));
}
 
Example #28
Source File: ValueConverterExceptionProducesErrorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428525
 */
@Test
public void testInvalidUnicode() throws Exception {
  final Resource resource = this.toResource("class C { def m() {\'\\u\'.toString}}");
  EcoreUtil2.resolveAll(resource);
  Assert.assertEquals(1, resource.getErrors().size());
  final Resource.Diagnostic error = IterableExtensions.<Resource.Diagnostic>head(resource.getErrors());
  Assert.assertNotNull(error);
  Assert.assertEquals("Invalid unicode", error.getMessage());
  final XStringLiteral literal = IteratorExtensions.<XStringLiteral>head(Iterators.<XStringLiteral>filter(resource.getAllContents(), XStringLiteral.class));
  Assert.assertEquals("u", literal.getValue());
}
 
Example #29
Source File: NoJdtTestLanguageGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
	Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class);
	Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() {

		@Override
		public String apply(Greeting greeting) {
			return greeting.getName();
		}
	});
	String fileName = resource.getURI().lastSegment();
	if(fileName == null) fileName = "greetings";
	fsa.generateFile(fileName+".txt", "People to greet: " + IteratorExtensions.join(names, ", "));
}
 
Example #30
Source File: XtextLinkerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testExplicitRuleCallsAreTracked() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("Rule: name=super::ID name=ID;");
  _builder.newLine();
  _builder.append("terminal ID: super;");
  _builder.newLine();
  _builder.append("terminal _super: \'s\';");
  _builder.newLine();
  final String grammarAsString = _builder.toString();
  final XtextResource resource = this.getResourceFromString(grammarAsString);
  EObject _get = resource.getContents().get(0);
  Grammar grammar = ((Grammar) _get);
  final AbstractRule firstRule = IterableExtensions.<AbstractRule>head(grammar.getRules());
  final RuleCall firstRuleCall = IteratorExtensions.<RuleCall>head(Iterators.<RuleCall>filter(firstRule.eAllContents(), RuleCall.class));
  Assert.assertTrue(firstRuleCall.isExplicitlyCalled());
  final RuleCall secondRuleCall = IteratorExtensions.<RuleCall>last(Iterators.<RuleCall>filter(firstRule.eAllContents(), RuleCall.class));
  Assert.assertFalse(secondRuleCall.isExplicitlyCalled());
  final RuleCall thirdRuleCall = IteratorExtensions.<RuleCall>head(Iterators.<RuleCall>filter(grammar.getRules().get(1).eAllContents(), RuleCall.class));
  Assert.assertTrue(thirdRuleCall.isExplicitlyCalled());
  resource.update(grammarAsString.indexOf("_super"), 1, " ");
  Assert.assertEquals(resource, firstRuleCall.eResource());
  Assert.assertEquals(resource, secondRuleCall.eResource());
  Assert.assertEquals(resource, thirdRuleCall.eResource());
  resource.getContents();
  Assert.assertFalse(thirdRuleCall.isExplicitlyCalled());
  Assert.assertEquals(IterableExtensions.<AbstractRule>last(grammar.getRules()), thirdRuleCall.getRule());
}