/** * @param scalar * @return true if the scalar is defines as $GLOBALS call */ private static boolean checkGLOBALS(Scalar scalar) { final String stringValue = scalar.getStringValue(); if (scalar.getScalarType() != Scalar.TYPE_STRING || stringValue.length() < 3) { return false; } final char charAtZero = stringValue.charAt(0); final char charAtEnd = stringValue.charAt(stringValue.length() - 1); if (!detectString(charAtZero) || !detectString(charAtEnd)) { return false; } if (scalar.getParent().getType() == ASTNode.ARRAY_ACCESS) { ArrayAccess arrayAccess = (ArrayAccess) scalar.getParent(); final Expression variableName = arrayAccess.getName(); if (variableName.getType() == ASTNode.VARIABLE) { Variable var = (Variable) variableName; if (var.isDollared() && var.getName() instanceof Identifier) { final Identifier id = (Identifier) var.getName(); return id.getName().equals("_GLOBALS") // $NON-NLS-1$ || id.getName().equals("GLOBALS"); // $NON-NLS-1$ } } } return false; }
/* * @see ASTVisitor#visit(ArrayAccess) */ @Override public boolean visit(ArrayAccess node) { node.getArray().accept(this); this.fBuffer.append("["); // $NON-NLS-1$ node.getIndex().accept(this); this.fBuffer.append("]"); // $NON-NLS-1$ return false; }
@Override public Object read(Object reuse, Decoder dec) throws IOException { Object array = _arrayAccess.create(reuse); int i = 0; for (int n = (int) dec.readArrayStart(); n != 0; n = (int) dec.readArrayNext()) { array = _arrayAccess.ensureSize(array, i + n); _arrayAccess.addElements(array, n, i, _itemReader, dec, _reusable); i += n; } array = _arrayAccess.resize(array, i); return array; }
/* (non-Javadoc) * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ArrayAccess) */ public boolean visit(ArrayAccess node) { PTArrayAccess aa = InstantiationFactory.eINSTANCE.createPTArrayAccess(); List indexes = aa.getIndexes(); Expression arrayExp = node; while (arrayExp.getNodeType() == ASTNode.ARRAY_ACCESS) { // Visit the index to get the index expression. ArrayAccess array = (ArrayAccess) arrayExp; indexes.add( 0, perform( array .getIndex())); // We're trying to create the final expression from inside out, the // indexes are created in reverse order. arrayExp = array.getArray(); } aa.setArray(perform(arrayExp)); // Final arrayExp is the true expression. expression = aa; // Set the return expression for this visit. return false; }
public String toString() { String s = null; if (ident != null) s = ident; if (arrAccess != null) s = arrAccess.toString(); return super.toString() + ": " + s; }