Example usage for org.eclipse.jdt.core.dom ArrayType COMPONENT_TYPE_PROPERTY

List of usage examples for org.eclipse.jdt.core.dom ArrayType COMPONENT_TYPE_PROPERTY

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom ArrayType COMPONENT_TYPE_PROPERTY.

Prototype

ChildPropertyDescriptor COMPONENT_TYPE_PROPERTY

To view the source code for org.eclipse.jdt.core.dom ArrayType COMPONENT_TYPE_PROPERTY.

Click Source Link

Document

The "componentType" structural property of this node type (child type: Type ).

Usage

From source file:org.eclipselabs.javainterpreter.ExpressionVisitor.java

License:Open Source License

@Override
public void endVisit(ArrayCreation node) {
    ArrayType type = (ArrayType) node.getStructuralProperty(ArrayCreation.TYPE_PROPERTY);

    Object[] args = argsTable.get(node).toArray();

    Object array = null;/*from  w ww  .  j  a  v a2s . co m*/
    if (args.length == 1 && args[0].getClass().isArray()) {
        array = args[0];
    } else if (type.getDimensions() == args.length) {
        int[] dims = new int[type.getDimensions()];
        for (int i = 0; i < dims.length; i++)
            dims[i] = (int) Double.parseDouble(args[i].toString());

        Type t = (Type) type.getStructuralProperty(ArrayType.COMPONENT_TYPE_PROPERTY);

        Class<?> clazz = loadClass(t);
        array = Array.newInstance(clazz, dims);
    } else
        throw new RuntimeException("Invalid array creation");

    if (node.getParent() instanceof ExpressionStatement)
        result = array;
    else
        argsTable.get(node.getParent()).add(array);
}

From source file:org.eclipselabs.javainterpreter.ExpressionVisitor.java

License:Open Source License

@Override
public void endVisit(ArrayInitializer node) {
    ArrayType type = (ArrayType) node.getParent().getStructuralProperty(ArrayCreation.TYPE_PROPERTY);

    Type t = (Type) type.getStructuralProperty(ArrayType.COMPONENT_TYPE_PROPERTY);
    Class<?> clazz = loadClass(t);

    Object array = Array.newInstance(clazz, argsTable.get(node).size());
    for (int i = 0; i < argsTable.get(node).size(); i++) {
        Array.set(array, i, argsTable.get(node).get(i));
    }/*from ww w . jav a 2 s.c  om*/
    argsTable.get(node.getParent()).add(array);
}

From source file:org.jboss.forge.parser.java.impl.JDTHelper.java

License:Open Source License

/**
 * Get the name of the given {@link Type}. Return the qualified name if possible.
 *///  w w  w  .jav a 2 s .  com
public static String getTypeName(final Type type) {
    if (type instanceof SimpleType) {
        return ((SimpleType) type).getName().toString();
    } else if (type instanceof ArrayType) {
        return ((ArrayType) type).getStructuralProperty(ArrayType.COMPONENT_TYPE_PROPERTY).toString();
    } else if (type instanceof QualifiedType) {
        return ((QualifiedType) type).toString();
    } else if (type instanceof PrimitiveType) {
        return ((PrimitiveType) type).toString();
    } else if (type instanceof ParameterizedType) {
        return ((ParameterizedType) type).getType().toString();
    } else if (type instanceof WildcardType) {
        return ((WildcardType) type).getBound().toString();
    }

    return null;
}