List of usage examples for org.eclipse.jdt.core.dom FieldAccess getExpression
public Expression getExpression()
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(FieldAccess node) { node.getExpression().accept(this); this.fBuffer.append(".");//$NON-NLS-1$ node.getName().accept(this); return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(FieldAccess node) { boa.types.Ast.Expression.Builder b = boa.types.Ast.Expression.newBuilder(); // b.setPosition(pos.build()); b.setKind(boa.types.Ast.Expression.ExpressionKind.VARACCESS); node.getExpression().accept(this); b.addExpressions(expressions.pop()); b.setVariable(node.getName().getFullyQualifiedName()); expressions.push(b.build());/*from ww w. j av a2 s.c om*/ return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(FieldAccess node) { node.getExpression().accept(this); this.buffer.append(".");//$NON-NLS-1$ node.getName().accept(this); return false; }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override public boolean visit(org.eclipse.jdt.core.dom.FieldAccess node) { PropertyAccess result = propertyAccess(translateExpression(node.getExpression()), (SimpleIdentifier) translate(node.getName())); context.putNodeBinding(result, node.resolveFieldBinding()); return done(result); }
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; }/*from w w w. jav a2 s . c om*/ 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.j2objc.ast.DebugASTPrinter.java
License:Apache License
@Override public boolean visit(FieldAccess node) { node.getExpression().accept(this); sb.print('.'); node.getName().accept(this); return false; }
From source file:com.google.devtools.j2objc.ast.TreeUtil.java
License:Apache License
/** * Replaces (in place) a QualifiedName node with an equivalent FieldAccess * node. This is helpful when a mutation needs to replace the qualifier with * a node that has Expression type but not Name type. *//*from w w w .j a v a 2s. c o m*/ public static FieldAccess convertToFieldAccess(QualifiedName node) { TreeNode parent = node.getParent(); if (parent instanceof QualifiedName) { FieldAccess newParent = convertToFieldAccess((QualifiedName) parent); Expression expr = newParent.getExpression(); assert expr instanceof QualifiedName; node = (QualifiedName) expr; } IVariableBinding variableBinding = getVariableBinding(node); assert variableBinding != null : "node must be a variable"; FieldAccess newNode = new FieldAccess(variableBinding, remove(node.getQualifier())); node.replaceWith(newNode); return newNode; }
From source file:com.google.devtools.j2objc.translate.ASTFactory.java
License:Apache License
/** * Replaces (in place) a QualifiedName node with an equivalent FieldAccess * node. This is helpful when a mutation needs to replace the qualifier with * a node that has Expression type but not Name type. *///w ww .j a va2 s .c o m public static FieldAccess convertToFieldAccess(QualifiedName node) { AST ast = node.getAST(); ASTNode parent = node.getParent(); if (parent instanceof QualifiedName) { FieldAccess newParent = convertToFieldAccess((QualifiedName) parent); Expression expr = newParent.getExpression(); assert expr instanceof QualifiedName; node = (QualifiedName) expr; } FieldAccess newNode = newFieldAccess(ast, Types.getVariableBinding(node), NodeCopier.copySubtree(ast, node.getQualifier())); ASTUtil.setProperty(node, newNode); return newNode; }
From source file:com.google.gdt.eclipse.designer.smart.model.data.DataSourceInfo.java
License:Open Source License
public StatementTarget calculateStatementTarget(JavaInfo component, List<ASTNode> afterNodes) throws Exception { // prepare/*from w w w . jav a 2 s.c o m*/ prepareForAssignTo(component); // LazyVariableSupport lazyVariableSupport = null; if (getVariableSupport() instanceof LazyVariableSupport) { lazyVariableSupport = (LazyVariableSupport) getVariableSupport(); } // collect nodes List<ASTNode> nodes = Lists.newArrayList(afterNodes); for (ASTNode node : getRelatedNodes()) { if (lazyVariableSupport != null && lazyVariableSupport.m_accessor.equals(AstNodeUtils.getEnclosingMethod(node))) { // skip nodes in "lazy" method continue; } // all "dataSource.setX()" invocations must be before ASTNode parentNode = node.getParent(); if (parentNode instanceof MethodInvocation) { MethodInvocation methodInvocation = (MethodInvocation) parentNode; if (isRepresentedBy(methodInvocation.getExpression()) && methodInvocation.getName().getIdentifier().startsWith("set")) { nodes.add(node); continue; } } // all "dataSource.x = X" fields assignment must be before if (parentNode instanceof FieldAccess) { FieldAccess fieldAccess = (FieldAccess) parentNode; if (isRepresentedBy(fieldAccess.getExpression()) && fieldAccess.getParent() instanceof Assignment) { nodes.add(node); continue; } } } // process nodes if (!nodes.isEmpty()) { nodes.add(getCreationSupport().getNode()); nodes.add(component.getCreationSupport().getNode()); // sort nodes ExecutionFlowDescription flowDescription = JavaInfoUtils.getState(getRootJava()).getFlowDescription(); JavaInfoUtils.sortNodesByFlow(flowDescription, false, nodes); ASTNode targetNode = nodes.get(nodes.size() - 1); return new StatementTarget(targetNode, false); } return null; }
From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java
License:Open Source License
/** * Consider the case://ww w . j a v a 2s. c om * * <pre> * String real_oneheyya = (((returnObjectWithSideEffects().y))+="hey")+"ya" * </pre> * * where field 'y' is parameterized to type string. then += is not defined for type 'object'. This function is a hack that expands * the code into an assignment and binary operation. * * @param leftCast this is the left cast in the original expression. We throw most of it away, although we use the "Cast from" and * "cast to" * @param left * @param context * @return */ private CAstNode doFunkyGenericAssignPreOpHack(Assignment assign, WalkContext context) { Expression left = assign.getLeftHandSide(); Expression right = assign.getRightHandSide(); // consider the case: // String real_oneheyya = (((returnObjectWithSideEffects().y))+="hey")+"ya"; // this is going to be a MAJOR pain... // where field 'y' is parameterized to type string. then += is not defined for type 'object'. we want to transform // it kind of like this, except we have to define temp. // String real_oneheyya = (String)((temp=cg2WithSideEffects()).y = (String)temp.y + "hey")+"ya"; // ---------------------------------------------------------------- // // we are responsible for underlined portion // CAST(LOCAL SCOPE(BLOCK EXPR(DECL STMT(temp, // left.target),ASSIGN(OBJECT_REF(temp,y),BINARY_EXPR(CAST(OBJECT_REF(Temp,y)),RIGHT))))) // yeah, I know, it's cheating, LOCAL SCOPE / DECL STMT inside an expression ... will it work? while (left instanceof ParenthesizedExpression) left = ((ParenthesizedExpression) left).getExpression(); assert left instanceof FieldAccess : "Cast in assign pre-op but no field access?!"; FieldAccess field = (FieldAccess) left; InfixExpression.Operator infixop = JDT2CAstUtils.mapAssignOperatorToInfixOperator(assign.getOperator()); // DECL_STMT: temp = ...; final String tmpName = "temp generic preop hack"; // illegal Java identifier CAstNode exprNode = visitNode(field.getExpression(), context); CAstNode tmpDeclNode = makeNode(context, fFactory, left, CAstNode.DECL_STMT, fFactory.makeConstant(new InternalCAstSymbol(tmpName, fTypeDict.getCAstTypeFor(field.getExpression().resolveTypeBinding()), true)), exprNode); // need two object refndoes "temp.y" CAstNode obref1 = createFieldAccess( makeNode(context, fFactory, left, CAstNode.VAR, fFactory.makeConstant(tmpName), fFactory.makeConstant(fTypeDict.getCAstTypeFor(field.resolveFieldBinding().getType()))), field.getName().getIdentifier(), field.resolveFieldBinding(), left, new AssignmentContext(context)); CAstNode obref2 = createFieldAccess( makeNode(context, fFactory, left, CAstNode.VAR, fFactory.makeConstant(tmpName), fFactory.makeConstant(fTypeDict.getCAstTypeFor(field.resolveFieldBinding().getType()))), field.getName().getIdentifier(), field.resolveFieldBinding(), left, context); ITypeBinding realtype = JDT2CAstUtils.getErasedType(field.resolveFieldBinding().getType(), ast); ITypeBinding fromtype = JDT2CAstUtils .getTypesVariablesBase(field.resolveFieldBinding().getVariableDeclaration().getType(), ast); CAstNode castedObref = obref2;// createCast(left, obref2, fromtype, realtype, context); // put it all together // CAST(LOCAL SCOPE(BLOCK EXPR(DECL STMT(temp, // left.target),ASSIGN(OBJECT_REF(temp,y),BINARY_EXPR(CAST(OBJECT_REF(Temp,y)),RIGHT))))) CAstNode result = makeNode(context, fFactory, assign, CAstNode.LOCAL_SCOPE, makeNode(context, fFactory, assign, CAstNode.BLOCK_EXPR, tmpDeclNode, makeNode(context, fFactory, assign, CAstNode.ASSIGN, obref1, createInfixExpression(infixop, realtype, left.getStartPosition(), left.getLength(), castedObref, right, context)))); return createCast(assign, result, fromtype, realtype, context); }