List of usage examples for org.eclipse.jdt.core.dom ArrayCreation TYPE_PROPERTY
ChildPropertyDescriptor TYPE_PROPERTY
To view the source code for org.eclipse.jdt.core.dom ArrayCreation TYPE_PROPERTY.
Click Source Link
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 ava2 s . c o 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 w ww.j a v a2 s. c om*/ argsTable.get(node.getParent()).add(array); }