Java Code Examples for org.eclipse.xtext.xbase.lib.Conversions#doWrapArray()

The following examples show how to use org.eclipse.xtext.xbase.lib.Conversions#doWrapArray() . 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: Xbase11_TypeCoercion.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public int myMethod() throws Throwable {
  int _xblockexpression = (int) 0;
  {
    "string".length();
    final Integer i = Integer.valueOf("string".length());
    /* i; */
    Integer.valueOf("string".length()).toString();
    "string".toCharArray();
    /* "string".toCharArray()[3]; */
    final List<Character> l = (List<Character>)Conversions.doWrapArray("string".toCharArray());
    /* l; */
    final Comparator<String> _function = (String a, String b) -> {
      return Integer.valueOf(a.length()).compareTo(Integer.valueOf(b.length()));
    };
    final Comparator<String> comparator = _function;
    _xblockexpression = comparator.compare("1", " 2");
  }
  return _xblockexpression;
}
 
Example 2
Source File: Solution_004.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public static void main(final String[] args) {
  int result = 0;
  IntegerRange _upTo = new IntegerRange(100, 999);
  for (final Integer left : _upTo) {
    IntegerRange _upTo_1 = new IntegerRange((left).intValue(), 999);
    for (final Integer right : _upTo_1) {
      {
        int candidate = ((left).intValue() * (right).intValue());
        if ((candidate > result)) {
          List<Character> charList = (List<Character>)Conversions.doWrapArray(Integer.valueOf(candidate).toString().toCharArray());
          List<Character> _reverseView = ListExtensions.<Character>reverseView(charList);
          boolean _equals = Objects.equal(_reverseView, charList);
          if (_equals) {
            result = candidate;
          }
        }
      }
    }
  }
  InputOutput.<Integer>println(Integer.valueOf(result));
}
 
Example 3
Source File: TypeReference.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public TypeReference(final String packageName, final String className, final List<TypeReference> arguments) {
  if ((packageName == null)) {
    throw new IllegalArgumentException(("Invalid package name: " + packageName));
  }
  if ((className == null)) {
    throw new IllegalArgumentException(("Invalid class name: " + className));
  }
  this.packageName = packageName;
  this.simpleNames = ((List<String>)Conversions.doWrapArray(className.split("\\.")));
  List<TypeReference> _elvis = null;
  if (arguments != null) {
    _elvis = arguments;
  } else {
    List<TypeReference> _emptyList = Collections.<TypeReference>emptyList();
    _elvis = _emptyList;
  }
  this.typeArguments = _elvis;
}
 
Example 4
Source File: XbaseInterpreter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected Object wrapOrUnwrapArray(Object result, LightweightTypeReference expectedType) {
	if (expectedType.isArray() && !(result instanceof Object[])) {
		Class<?> arrayType;
		try {
			arrayType = getJavaType(expectedType.getComponentType().getType());
			return Conversions.unwrapArray(result, arrayType);
		} catch (ClassNotFoundException e) {
			return result;
		}
	} else if (!expectedType.isArray() && expectedType.isSubtypeOf(Iterable.class)) {
		return Conversions.doWrapArray(result);
	}
	return result;
}
 
Example 5
Source File: CompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testArrayConversion_01() throws Exception {
	int[] expected = new int[] { 1, 2, 3 };
	Object wrappedArray = Conversions.doWrapArray(expected);
	invokeAndExpect3(
			expected, 
			"def int[] unpackArray(Iterable<Integer> iterable) {" + 
			"    return iterable\n" +
			"}", "unpackArray", new Class[] { Iterable.class }, wrappedArray);
}
 
Example 6
Source File: TypeReference.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public static TypeReference typeRef(final String name, final TypeReference... arguments) {
  return new TypeReference(name, (List<TypeReference>)Conversions.doWrapArray(arguments));
}
 
Example 7
Source File: TypeReference.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @deprecated this method is available for backwards compatibility reasons
 */
@Deprecated
public static TypeReference guessTypeRef(final String name, final TypeReference... arguments) {
  return new TypeReference(name, (List<TypeReference>)Conversions.doWrapArray(arguments), false);
}
 
Example 8
Source File: TypeReference.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public static TypeReference typeRef(final Class<?> clazz, final TypeReference... arguments) {
  return new TypeReference(clazz, (List<TypeReference>)Conversions.doWrapArray(arguments));
}