List of usage examples for org.eclipse.jdt.core.dom ArrayAccess getArray
public Expression getArray()
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@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; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(ArrayAccess node) { boa.types.Ast.Expression.Builder b = boa.types.Ast.Expression.newBuilder(); // b.setPosition(pos.build()); b.setKind(boa.types.Ast.Expression.ExpressionKind.ARRAYINDEX); node.getArray().accept(this); b.addExpressions(expressions.pop()); node.getIndex().accept(this); b.addExpressions(expressions.pop()); expressions.push(b.build());/*from ww w . j a va2s.c om*/ return false; }
From source file:ca.mcgill.cs.swevo.ppa.inference.ArrayAccessInferenceStrategy.java
License:Open Source License
public boolean isSafe(ASTNode node) { ArrayAccess aAccess = (ArrayAccess) node; Expression exp1 = aAccess.getArray(); Expression exp2 = aAccess.getIndex(); return (!indexer.isIndexable(exp1) || indexer.isSafe(exp1)) && (!indexer.isIndexable(exp2) || indexer.isSafe(exp2)); }
From source file:ca.mcgill.cs.swevo.ppa.inference.ArrayAccessInferenceStrategy.java
License:Open Source License
public void makeSafe(ASTNode node, TypeFact typeFact) { ArrayAccess aAccess = (ArrayAccess) node; Expression exp1 = aAccess.getArray(); boolean isSafe = !PPABindingsUtil.isUnknownType(exp1.resolveTypeBinding()) && (indexer.isSafe(exp1)); ITypeBinding factType = typeFact != null ? typeFact.getNewType() : null; if (!isSafe && factType != null) { ITypeBinding newBinding = ppaEngine.getRegistry().getArrayTypeBinding(factType, exp1); ITypeBinding oldBinding = exp1.resolveTypeBinding(); TypeFact newTypeFact = new TypeFact(indexer.getMainIndex(exp1), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); ppaEngine.reportTypeFact(newTypeFact); }/* w w w.j a v a2 s. com*/ }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(ArrayAccess node) { node.getArray().accept(this); this.buffer.append("[");//$NON-NLS-1$ node.getIndex().accept(this); this.buffer.append("]");//$NON-NLS-1$ return false; }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override public boolean visit(org.eclipse.jdt.core.dom.ArrayAccess node) { Expression expression = translate(node.getArray()); Expression index = translate(node.getIndex()); return done(indexExpression(expression, index)); }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
@Override public boolean visit(ArrayAccess node) { buffer.append('['); printNilCheck(node.getArray(), true); buffer.append(' '); ITypeBinding binding = node.resolveTypeBinding(); if (binding == null) { binding = Types.getTypeBinding(node); }/*from w w w. ja v a 2 s. c om*/ IOSTypeBinding arrayBinding = Types.resolveArrayType(binding); if (arrayBinding == null) { J2ObjC.error(node, "No IOSArrayBinding for " + binding.getName()); } else { assert (arrayBinding instanceof IOSArrayTypeBinding); IOSArrayTypeBinding primitiveArray = (IOSArrayTypeBinding) arrayBinding; buffer.append(primitiveArray.getAccessMethod()); } buffer.append(':'); node.getIndex().accept(this); buffer.append(']'); return false; }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
private void printArrayElementAssignment(Expression lhs, Expression rhs, Assignment.Operator op) { ArrayAccess aa = (ArrayAccess) lhs; String kind = getArrayAccessKind(aa); buffer.append('['); if (aa.getArray() instanceof ArrayAccess) { buffer.append(String.format("(IOS%sArray *) ", kind)); }//w w w . j av a 2 s .c o m printNilCheck(aa.getArray(), true); buffer.append(" replace"); buffer.append(kind); buffer.append("AtIndex:"); aa.getIndex().accept(this); buffer.append(" with"); buffer.append(kind); buffer.append(':'); if (op == Operator.ASSIGN) { rhs.accept(this); } else { // Fetch value and apply operand; for example, "arr[i] += j" becomes // "[arr replaceIntAtIndex:i withInt:[arr intAtIndex:i] + j]", or // ... "withInt:(int) (((unsigned int) [arr intAtIndex:i]) >> j)]" for // unsigned right shift. String type = kind.toLowerCase(); if (op == Operator.RIGHT_SHIFT_UNSIGNED_ASSIGN) { buffer.append("("); buffer.append(type); buffer.append(") (((unsigned "); buffer.append(type); buffer.append(") "); } buffer.append('['); aa.getArray().accept(this); buffer.append(' '); buffer.append(type); buffer.append("AtIndex:"); aa.getIndex().accept(this); buffer.append(']'); if (op == Operator.RIGHT_SHIFT_UNSIGNED_ASSIGN) { buffer.append(") >>"); } else { buffer.append(' '); String s = op.toString(); buffer.append(s.substring(0, s.length() - 1)); // strip trailing '='. } buffer.append(' '); rhs.accept(this); if (op == Operator.RIGHT_SHIFT_UNSIGNED_ASSIGN) { buffer.append(')'); } } buffer.append(']'); }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
@Override public boolean visit(FieldAccess node) { if (maybePrintArrayLength(node.getName().getIdentifier(), node.getExpression())) { return false; }// ww w.j a v a 2s. c o m Expression expr = node.getExpression(); if (expr instanceof ArrayAccess) { // Since arrays are untyped in Obj-C, add a cast of its element type. ArrayAccess access = (ArrayAccess) expr; ITypeBinding elementType = Types.getTypeBinding(access.getArray()).getElementType(); buffer.append(String.format("((%s) ", NameTable.javaRefToCpp(elementType))); expr.accept(this); buffer.append(')'); } else { printNilCheck(expr, true); } if (Options.inlineFieldAccess() && isProperty(node.getName())) { buffer.append("->"); } else { buffer.append('.'); } node.getName().accept(this); return false; }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
private void printArrayIncrementOrDecrement(ArrayAccess access, String methodName) { buffer.append('['); printNilCheck(access.getArray(), true); buffer.append(' '); buffer.append(methodName);/* ww w. ja v a2 s. c o m*/ buffer.append(':'); access.getIndex().accept(this); buffer.append(']'); }