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

The following examples show how to use org.eclipse.xtext.xbase.lib.ArrayExtensions. 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: 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 #2
Source File: Formatter2Fragment2.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected String toVarName(final ENamedElement element, final String... reservedNames) {
  String _xblockexpression = null;
  {
    if ((element instanceof EReference)) {
      return this.toVarName(((EReference)element).getEReferenceType(), reservedNames);
    }
    String name = StringExtensions.toFirstLower(element.getName());
    boolean _contains = XtendFileAccess.XTEND_KEYWORDS.contains(name);
    if (_contains) {
      name = ("_" + name);
    }
    boolean _contains_1 = ArrayExtensions.contains(reservedNames, name);
    if (_contains_1) {
      name = ("_" + name);
    }
    _xblockexpression = name;
  }
  return _xblockexpression;
}
 
Example #3
Source File: AbstractFSSynchronizationTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void testCleanUpDerivedResourcesWithCreateBetween(IContainer output) {
	File outputDirectory = output.getLocation().toFile();
	final int initialSize;
	if (outputDirectory.exists()) {
		initialSize = outputDirectory.list().length;
	} else {
		initialSize = 0;
	}
	createFile(project.getFile(("src/Foo" + F_EXT)).getFullPath(), "object Foo");
	build();
	Assert.assertTrue(outputDirectory.exists());
	Assert.assertNotEquals(initialSize, outputDirectory.list().length);
	disableAutobuild(() -> {
		createJavaIoFile(output.getFile(new Path("Lalala.txt")).getLocation());
		int expectedSize = (initialSize + 1);
		cleanBuild();
		Assert.assertEquals(expectedSize, outputDirectory.list().length);
		Assert.assertTrue(ArrayExtensions.contains(outputDirectory.list(), "Lalala.txt"));
	});
}
 
Example #4
Source File: ArrayExtensionsFloatTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__float() {
  Assert.assertTrue(ArrayExtensions.contains(this.data, 10.0f));
  Assert.assertTrue(ArrayExtensions.contains(this.data, 20.0f));
  Assert.assertTrue(ArrayExtensions.contains(this.data, 30.0f));
  Assert.assertFalse(ArrayExtensions.contains(this.data, 40.0f));
}
 
Example #5
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public void assertFeatureCallError(final XtendFile file, final EClass objectType) {
  final Resource resource = file.eResource();
  final List<Issue> allIssues = this._validationTestHelper.validate(resource);
  final Function1<Issue, Boolean> _function = (Issue it) -> {
    EObject object = resource.getResourceSet().getEObject(it.getUriToProblem(), true);
    final boolean featureCall = ArrayExtensions.contains(it.getData(), UnresolvedFeatureCallTypeAwareMessageProvider.FEATURE_CALL);
    return Boolean.valueOf((((Objects.equal(it.getCode(), Diagnostic.LINKING_DIAGNOSTIC) && (it.getSeverity() == Severity.ERROR)) && 
      objectType.isInstance(object)) && featureCall));
  };
  final Iterable<Issue> match = IterableExtensions.<Issue>filter(allIssues, _function);
  boolean _isEmpty = IterableExtensions.isEmpty(match);
  if (_isEmpty) {
    Assert.fail("No Diagnostic.LINKING_DIAGNOSTIC issue with user data FEATURE_CALL found");
  }
}
 
Example #6
Source File: QuickfixTestBuilder.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public QuickfixTestBuilder assertTypeLiteralLinkingIssue() {
  QuickfixTestBuilder _xblockexpression = null;
  {
    final Function1<Issue, Boolean> _function = (Issue it) -> {
      return Boolean.valueOf((Objects.equal(it.getCode(), Diagnostic.LINKING_DIAGNOSTIC) && 
        ArrayExtensions.contains(it.getData(), UnresolvedFeatureCallTypeAwareMessageProvider.TYPE_LITERAL)));
    };
    Assert.assertTrue(IterableExtensions.<Issue>exists(this.getIssuesAtCaret(), _function));
    _xblockexpression = this;
  }
  return _xblockexpression;
}
 
Example #7
Source File: QuickfixTestBuilder.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public QuickfixTestBuilder assertFeatureCallLinkingIssue() {
  QuickfixTestBuilder _xblockexpression = null;
  {
    final Function1<Issue, Boolean> _function = (Issue it) -> {
      return Boolean.valueOf((Objects.equal(it.getCode(), Diagnostic.LINKING_DIAGNOSTIC) && 
        ArrayExtensions.contains(it.getData(), UnresolvedFeatureCallTypeAwareMessageProvider.FEATURE_CALL)));
    };
    Assert.assertTrue(IterableExtensions.<Issue>exists(this.getIssuesAtCaret(), _function));
    _xblockexpression = this;
  }
  return _xblockexpression;
}
 
Example #8
Source File: AbstractFSSynchronizationTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void testCleanUpDerivedResourcesWithCreateBefore(IContainer output) {
	File ouputDirectory = createJavaIoFile(output.getFile(new Path("Lalala.txt")).getLocation()).getParentFile();
	int expectedSize = ouputDirectory.list().length;
	createFile(project.getFile(("src/Foo" + F_EXT)).getFullPath(), "object Foo");
	build();
	Assert.assertNotEquals(expectedSize, ouputDirectory.list().length);
	disableAutobuild(() -> {
		cleanBuild();
		Assert.assertEquals(expectedSize, ouputDirectory.list().length);
		Assert.assertTrue(ArrayExtensions.contains(ouputDirectory.list(), "Lalala.txt"));
	});
}
 
Example #9
Source File: ArrayExtensionsFloatTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__float_negInfinity() {
  final float[] nanData = { 1.0f, Float.NEGATIVE_INFINITY };
  Assert.assertTrue(ArrayExtensions.contains(nanData, Float.NEGATIVE_INFINITY));
  Assert.assertTrue(ArrayExtensions.contains(nanData, (Float.NEGATIVE_INFINITY + 7.2f)));
  Assert.assertFalse(ArrayExtensions.contains(nanData, Float.NaN));
  Assert.assertFalse(ArrayExtensions.contains(nanData, (0f / 0f)));
  double _log = Math.log((-1));
  Assert.assertFalse(ArrayExtensions.contains(nanData, ((float) _log)));
  Assert.assertFalse(ArrayExtensions.contains(nanData, Float.POSITIVE_INFINITY));
}
 
Example #10
Source File: ArrayExtensionsFloatTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__float_posInfinity() {
  final float[] nanData = { 1.0f, Float.POSITIVE_INFINITY };
  Assert.assertTrue(ArrayExtensions.contains(nanData, Float.POSITIVE_INFINITY));
  Assert.assertTrue(ArrayExtensions.contains(nanData, (Float.POSITIVE_INFINITY + 7.2f)));
  Assert.assertFalse(ArrayExtensions.contains(nanData, Float.NaN));
  Assert.assertFalse(ArrayExtensions.contains(nanData, (0f / 0f)));
  double _log = Math.log((-1));
  Assert.assertFalse(ArrayExtensions.contains(nanData, ((float) _log)));
  Assert.assertFalse(ArrayExtensions.contains(nanData, Float.NEGATIVE_INFINITY));
}
 
Example #11
Source File: ArrayExtensionsFloatTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__float_NaN() {
  final float[] nanData = { 1.0f, Float.NaN };
  Assert.assertTrue(ArrayExtensions.contains(nanData, Float.NaN));
  Assert.assertTrue(ArrayExtensions.contains(nanData, (0f / 0f)));
  double _log = Math.log((-1));
  Assert.assertTrue(ArrayExtensions.contains(nanData, ((float) _log)));
  Assert.assertFalse(ArrayExtensions.contains(nanData, Float.NEGATIVE_INFINITY));
  Assert.assertFalse(ArrayExtensions.contains(nanData, Float.POSITIVE_INFINITY));
}
 
Example #12
Source File: ArrayExtensionsDoubleTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__double_negInfinity() {
  final double[] nanData = { 1.0f, Double.NEGATIVE_INFINITY };
  Assert.assertTrue(ArrayExtensions.contains(nanData, Double.NEGATIVE_INFINITY));
  Assert.assertTrue(ArrayExtensions.contains(nanData, (Double.NEGATIVE_INFINITY + 7.2f)));
  Assert.assertFalse(ArrayExtensions.contains(nanData, Double.NaN));
  Assert.assertFalse(ArrayExtensions.contains(nanData, (0f / 0f)));
  Assert.assertFalse(ArrayExtensions.contains(nanData, Math.log((-1))));
  Assert.assertFalse(ArrayExtensions.contains(nanData, Double.POSITIVE_INFINITY));
}
 
Example #13
Source File: ArrayExtensionsDoubleTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__double_posInfinity() {
  final double[] nanData = { 1.0f, Double.POSITIVE_INFINITY };
  Assert.assertTrue(ArrayExtensions.contains(nanData, Double.POSITIVE_INFINITY));
  Assert.assertTrue(ArrayExtensions.contains(nanData, (Double.POSITIVE_INFINITY + 7.2f)));
  Assert.assertFalse(ArrayExtensions.contains(nanData, Double.NaN));
  Assert.assertFalse(ArrayExtensions.contains(nanData, (0f / 0f)));
  Assert.assertFalse(ArrayExtensions.contains(nanData, Math.log((-1))));
  Assert.assertFalse(ArrayExtensions.contains(nanData, Double.NEGATIVE_INFINITY));
}
 
Example #14
Source File: ArrayExtensionsDoubleTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__float_NaN() {
  final double[] nanData = { 1.0, Double.NaN };
  Assert.assertTrue(ArrayExtensions.contains(nanData, Double.NaN));
  Assert.assertTrue(ArrayExtensions.contains(nanData, (0f / 0f)));
  Assert.assertTrue(ArrayExtensions.contains(nanData, Math.log((-1))));
  Assert.assertFalse(ArrayExtensions.contains(nanData, Double.NEGATIVE_INFINITY));
  Assert.assertFalse(ArrayExtensions.contains(nanData, Double.POSITIVE_INFINITY));
}
 
Example #15
Source File: ArrayExtensionsDoubleTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__double() {
  Assert.assertTrue(ArrayExtensions.contains(this.data, 10.0));
  Assert.assertTrue(ArrayExtensions.contains(this.data, 20.0));
  Assert.assertTrue(ArrayExtensions.contains(this.data, 30.0));
  Assert.assertFalse(ArrayExtensions.contains(this.data, 40.0));
}
 
Example #16
Source File: ArrayExtensionsIntTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__int() {
  Assert.assertTrue(ArrayExtensions.contains(this.data, 10));
  Assert.assertTrue(ArrayExtensions.contains(this.data, 20));
  Assert.assertTrue(ArrayExtensions.contains(this.data, 30));
  Assert.assertFalse(ArrayExtensions.contains(this.data, 40));
}
 
Example #17
Source File: ArrayExtensionsByteTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__byte() {
  Assert.assertTrue(ArrayExtensions.contains(this.data, ((byte) 10)));
  Assert.assertTrue(ArrayExtensions.contains(this.data, ((byte) 20)));
  Assert.assertTrue(ArrayExtensions.contains(this.data, ((byte) 30)));
  Assert.assertFalse(ArrayExtensions.contains(this.data, ((byte) 40)));
}
 
Example #18
Source File: ArrayExtensionsObjectTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__Object() {
  Assert.assertTrue(ArrayExtensions.contains(this.data, Integer.valueOf(0)));
  Assert.assertTrue(ArrayExtensions.contains(this.data, Integer.valueOf(1)));
  Assert.assertTrue(ArrayExtensions.contains(this.data, null));
  Assert.assertFalse(ArrayExtensions.contains(this.data, Integer.valueOf(3)));
  Assert.assertFalse(ArrayExtensions.contains(this.data, Integer.valueOf(4)));
}
 
Example #19
Source File: ArrayExtensionsCharTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__char() {
  Assert.assertTrue(ArrayExtensions.contains(this.data, this.a));
  Assert.assertTrue(ArrayExtensions.contains(this.data, this.b));
  Assert.assertTrue(ArrayExtensions.contains(this.data, this.c));
  Assert.assertFalse(ArrayExtensions.contains(this.data, this.x));
}
 
Example #20
Source File: ArrayExtensionsBooleanTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__boolean() {
  Assert.assertTrue(ArrayExtensions.contains(this.data, true));
  Assert.assertTrue(ArrayExtensions.contains(this.data, false));
  boolean[] _newBooleanArrayOfSize = new boolean[2];
  final Procedure1<boolean[]> _function = (boolean[] it) -> {
    it[0] = false;
    it[1] = false;
  };
  final boolean[] onlyFalse = ObjectExtensions.<boolean[]>operator_doubleArrow(_newBooleanArrayOfSize, _function);
  Assert.assertFalse(ArrayExtensions.contains(onlyFalse, true));
  Assert.assertTrue(ArrayExtensions.contains(onlyFalse, false));
}
 
Example #21
Source File: ArrayExtensionsShortTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__short() {
  Assert.assertTrue(ArrayExtensions.contains(this.data, ((short) 10)));
  Assert.assertTrue(ArrayExtensions.contains(this.data, ((short) 20)));
  Assert.assertTrue(ArrayExtensions.contains(this.data, ((short) 30)));
  Assert.assertFalse(ArrayExtensions.contains(this.data, ((short) 40)));
}
 
Example #22
Source File: ArrayExtensionsLongTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains__long() {
  Assert.assertTrue(ArrayExtensions.contains(this.data, 10l));
  Assert.assertTrue(ArrayExtensions.contains(this.data, 20l));
  Assert.assertTrue(ArrayExtensions.contains(this.data, 30l));
  Assert.assertFalse(ArrayExtensions.contains(this.data, 40l));
}
 
Example #23
Source File: StaticImplicitMethodsFeatureForTypeProvider.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected Multimap<Class<?>, Class<?>> simpleComputeExtensionClasses() {
	Multimap<Class<?>, Class<?>> result = ArrayListMultimap.create();
	result.put(String.class, StringExtensions.class);
	result.put(Double.TYPE, DoubleExtensions.class);
	result.put(Float.TYPE, FloatExtensions.class);
	result.put(Long.TYPE, LongExtensions.class);
	result.put(Integer.TYPE, IntegerExtensions.class);
	result.put(Character.TYPE, CharacterExtensions.class);
	result.put(Short.TYPE, ShortExtensions.class);
	result.put(Byte.TYPE, ByteExtensions.class);
	result.put(Boolean.TYPE, BooleanExtensions.class);
	result.put(double[].class, ArrayExtensions.class);
	result.put(float[].class, ArrayExtensions.class);
	result.put(long[].class, ArrayExtensions.class);
	result.put(int[].class, ArrayExtensions.class);
	result.put(char[].class, ArrayExtensions.class);
	result.put(short[].class, ArrayExtensions.class);
	result.put(byte[].class, ArrayExtensions.class);
	result.put(boolean[].class, ArrayExtensions.class);
	result.put(BigInteger.class, BigIntegerExtensions.class);
	result.put(BigDecimal.class, BigDecimalExtensions.class);
	result.put(Comparable.class, ComparableExtensions.class);
	result.put(Object.class, ObjectExtensions.class);
	result.put(List.class, ListExtensions.class);
	result.put(Collection.class, CollectionExtensions.class);
	result.put(Map.class, CollectionExtensions.class);
	result.put(Map.class, MapExtensions.class);
	result.put(Iterable.class, IterableExtensions.class);
	result.put(Iterator.class, IteratorExtensions.class);
	result.put(Functions.Function0.class, FunctionExtensions.class);
	result.put(Functions.Function1.class, FunctionExtensions.class);
	result.put(Functions.Function2.class, FunctionExtensions.class);
	result.put(Functions.Function3.class, FunctionExtensions.class);
	result.put(Functions.Function4.class, FunctionExtensions.class);
	result.put(Functions.Function5.class, FunctionExtensions.class);
	result.put(Functions.Function6.class, FunctionExtensions.class);
	result.put(Procedures.Procedure0.class, ProcedureExtensions.class);
	result.put(Procedures.Procedure1.class, ProcedureExtensions.class);
	result.put(Procedures.Procedure2.class, ProcedureExtensions.class);
	result.put(Procedures.Procedure3.class, ProcedureExtensions.class);
	result.put(Procedures.Procedure4.class, ProcedureExtensions.class);
	result.put(Procedures.Procedure5.class, ProcedureExtensions.class);
	result.put(Procedures.Procedure6.class, ProcedureExtensions.class);
	return result;
}
 
Example #24
Source File: RichStringPartionIndentationStrategy.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void customizeDocumentCommand(final IDocument d, final DocumentCommand c) {
  if (((c.text.length() > 1) && (!ArrayExtensions.contains(d.getLegalLineDelimiters(), c.text)))) {
    try {
      final String lineIndentation = this.getLineIndentation(d, c.offset);
      final Function1<String, Integer> _function = (String s) -> {
        return Integer.valueOf(s.length());
      };
      final List<String> legalLineDelimiters = ListExtensions.<String>reverseView(IterableExtensions.<String, Integer>sortBy(((Iterable<String>)Conversions.doWrapArray(d.getLegalLineDelimiters())), _function));
      final String defaultLineDelimiter = TextUtilities.getDefaultLineDelimiter(d);
      final Function1<String, CharSequence> _function_1 = (String delimiter) -> {
        return Pattern.quote(delimiter);
      };
      final String regex = IterableExtensions.<String>join(legalLineDelimiters, "(", ")|(", ")", _function_1);
      final Pattern pattern = Pattern.compile(regex);
      final Matcher matcher = pattern.matcher(c.text);
      final StringBuilder convertedText = new StringBuilder();
      int currentStart = 0;
      int currentEnd = 0;
      while (matcher.find()) {
        {
          currentEnd = matcher.start();
          if ((currentStart != 0)) {
            convertedText.append(lineIndentation);
          }
          convertedText.append(c.text.substring(currentStart, currentEnd));
          convertedText.append(defaultLineDelimiter);
          currentStart = matcher.end();
        }
      }
      int _length = c.text.length();
      boolean _lessThan = (currentStart < _length);
      if (_lessThan) {
        if ((currentStart != 0)) {
          convertedText.append(lineIndentation);
        }
        convertedText.append(c.text.substring(currentStart));
      }
      c.text = convertedText.toString();
    } catch (final Throwable _t) {
      if (_t instanceof BadLocationException) {
        super.customizeDocumentCommand(d, c);
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  }
  super.customizeDocumentCommand(d, c);
}
 
Example #25
Source File: XtendResourceDescriptionManager.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
private boolean containsActiveAnnotation(final IResourceDescription description) {
  final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
    return Boolean.valueOf(ArrayExtensions.contains(it.getUserDataKeys(), XtendResourceDescriptionStrategy.ACTIVE_ANNOTATION_TIMESTAMP));
  };
  return IterableExtensions.<IEObjectDescription>exists(description.getExportedObjects(), _function);
}
 
Example #26
Source File: SocketServerLauncher.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected PrintWriter getTrace(String... args) {
	if (ArrayExtensions.contains(args, TRACE)) {
		return new PrintWriter(System.out);
	}
	return null;
}
 
Example #27
Source File: SocketServerLauncher.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean shouldValidate(String... args) {
	return !ArrayExtensions.contains(args, NO_VALIDATE);
}