org.eclipse.xtext.xbase.lib
Class Conversions

java.lang.Object
  extended by org.eclipse.xtext.xbase.lib.Conversions

@GwtIncompatible(value="reflection")
public class Conversions
extends Object

This is a library used to convert arrays to lists and vice versa in a way that keeps the identity of the to-be-converted object. That is, changes in the array will be reflected by the list and changes to the list will be reflected by the array for both kinds of conversion. The utilities in this class should only be used by the Xbase compiler.

Author:
Sebastian Zarnekow - Initial contribution and API, Sven Efftinge

Nested Class Summary
static class Conversions.WrappedArray<T>
          A list that is completely backed by an array and that provides access to that array.
static class Conversions.WrappedPrimitiveArray
          A list that is completely backed by an array of primitives and that provides access to that array.
 
Constructor Summary
Conversions()
           
 
Method Summary
static Object doWrapArray(Object object)
          Wraps object in a list if and only if object is an array.
static Object unwrapArray(Object value)
          Unwraps object to extract the original array if and only if object was previously created by doWrapArray(Object).
static Object unwrapArray(Object value, Class<?> componentType)
          Unwraps object to extract the original array if and only if object was previously created by doWrapArray(Object).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Conversions

public Conversions()
Method Detail

doWrapArray

@Pure
public static Object doWrapArray(Object object)
Wraps object in a list if and only if object is an array. Works for primitive and object-component types.

Parameters:
object - the object to be wrapped. May be null.
Returns:
a list if the given object was an array. Otherwise the unmodified given object. May return null if the object was null.

unwrapArray

@Pure
public static Object unwrapArray(Object value)
Unwraps object to extract the original array if and only if object was previously created by doWrapArray(Object). If the array's component type cannot be determined at runtime, Object is used.

Parameters:
value - the object to be unwrapped. May be null.
Returns:
the previously wrapped array if the given value represents such. Otherwise returns the value unmodified. May return null if the value was null.

unwrapArray

@Pure
public static Object unwrapArray(Object value,
                                      Class<?> componentType)
Unwraps object to extract the original array if and only if object was previously created by doWrapArray(Object).

Parameters:
value - the object to be unwrapped. May be null.
componentType - the expected component type of the array. May not be null.
Returns:
the previously wrapped array if the given value represents such. Otherwise returns the value unmodified. May return null if the value was null.
Throws:
ArrayStoreException - if the expected runtime componentType does not match the actual runtime component type.


Copyright © 2013. All Rights Reserved.