List of usage examples for org.eclipse.jdt.core.dom FieldAccess resolveFieldBinding
public IVariableBinding resolveFieldBinding()
From source file:changetypes.ASTVisitorAtomicChange.java
License:Open Source License
public boolean visit(FieldAccess node) { IVariableBinding ivb = node.resolveFieldBinding(); if (this.mtbStack.isEmpty()) { return true; }/*from ww w. ja v a 2 s. c o m*/ IMethodBinding mtb = (IMethodBinding) this.mtbStack.peek(); try { if ((!node.getName().toString().equals("length")) || (ivb.getDeclaringClass() != null)) { this.facts.add( Fact.makeAccessesFact(getQualifiedName(node.resolveFieldBinding()), getQualifiedName(mtb))); } } catch (Exception localException1) { System.err.println("Cannot resolve field access \"" + node.getName().toString() + "\""); } try { String simpleMethodName = getSimpleName(mtb); if (simpleMethodName.toLowerCase().startsWith("get")) { this.facts.add( Fact.makeGetterFact(getQualifiedName(mtb), getQualifiedName(node.resolveFieldBinding()))); } else if (simpleMethodName.toLowerCase().startsWith("set")) { this.facts.add( Fact.makeSetterFact(getQualifiedName(mtb), getQualifiedName(node.resolveFieldBinding()))); } } catch (Exception localException2) { System.err.println("Cannot resolve bindings for exceptions"); } return true; }
From source file:com.architexa.diagrams.jdt.extractors.TypeRefExtractor.java
License:Open Source License
@Override public boolean visit(FieldAccess node) { addRefFromCaller(bindingToResource(node.resolveFieldBinding())); return true; }
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.types.BindingMapBuilder.java
License:Open Source License
@Override public boolean visit(FieldAccess node) { put(node, node.resolveFieldBinding()); return true; }
From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java
License:Open Source License
/** * Consider the case://ww w . jav a 2 s . 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); }
From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java
License:Open Source License
/** * Process a field access. Semantics differ for static and instance fields. Fields can throw null pointer exceptions so we must * connect proper exceptional edges in the CFG. * // ww w .ja va2s. c o m * @param n * @param context * @return */ private CAstNode visit(FieldAccess n, WalkContext context) { CAstNode targetNode = visitNode(n.getExpression(), context); return createFieldAccess(targetNode, n.getName().getIdentifier(), n.resolveFieldBinding(), n, context); }
From source file:edu.cmu.cs.plural.concurrent.syncorswim.IsSynchronizedRefAnalysis.java
License:Open Source License
/** * If this is a field or variable, return the variable biding, else NONE. */// w w w . j a v a 2s. c o m static Option<IVariableBinding> asVar(Expression expr) { if (expr instanceof FieldAccess) { FieldAccess field = (FieldAccess) expr; return Option.some(field.resolveFieldBinding()); } else if (expr instanceof SimpleName) { SimpleName name = (SimpleName) expr; if (name.resolveBinding() instanceof IVariableBinding) { IVariableBinding binding = (IVariableBinding) name.resolveBinding(); return Option.some(binding); } } else if (expr instanceof Name) { Name name = (Name) expr; if (name.resolveBinding() instanceof IVariableBinding) { IVariableBinding binding = (IVariableBinding) name.resolveBinding(); return Option.some(binding); } } else if (expr instanceof QualifiedName) { QualifiedName qname = (QualifiedName) expr; if (qname.resolveBinding() instanceof IVariableBinding) { IVariableBinding binding = (IVariableBinding) qname.resolveBinding(); return Option.some(binding); } } // If we get down to here, it wasn't a field... return Option.none(); }
From source file:edu.uci.ics.sourcerer.extractor.ast.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes:/*from w w w . ja v a2 s. com*/ *<ul> * <li>For field access expressions: * <ul> * <li>Writes relation to <code>IRelationWriter</code>.</li> * <li>Reads relation to <code>IRelationWriter</code>.</li> * </ul></li> *</ul> */ @Override public boolean visit(FieldAccess node) { // Get the fqn String fqn = null; IVariableBinding binding = node.resolveFieldBinding(); if (binding == null) { fqn = getUnknownFqn(node.getName().getIdentifier()); } else { ITypeBinding declaringClass = binding.getDeclaringClass(); if (declaringClass != null) { declaringClass = declaringClass.getErasure(); } if (declaringClass == null) { if (binding.isRecovered()) { fqn = getUnknownFqn(binding.getName()); } else if (node.getExpression().resolveTypeBinding().isArray() && binding.getName().equals("length")) { // Ignore array length return true; } else { logger.log(Level.SEVERE, "Non-recovered field binding without a declaring class that's not an array.length!"); } } else { fqn = getTypeFqn(declaringClass) + "." + binding.getName(); } } // Write the relation if (inLhsAssignment) { relationWriter.writeWrites(fqnStack.getFqn(), fqn, getLocation(node.getName())); } else { relationWriter.writeReads(fqnStack.getFqn(), fqn, getLocation(node.getName())); } inLhsAssignment = false; node.getExpression().accept(this); return false; }
From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes:/*from w w w.ja v a 2s. c o m*/ *<ul> * <li>For field access expressions: * <ul> * <li>Writes relation to <code>IRelationWriter</code>.</li> * <li>Reads relation to <code>IRelationWriter</code>.</li> * </ul></li> *</ul> */ @Override public boolean visit(FieldAccess node) { // Get the fqn String fqn = null; IVariableBinding binding = node.resolveFieldBinding(); if (binding == null) { fqn = createUnknownFqn(node.getName().getIdentifier()); } else { ITypeBinding declaringClass = binding.getDeclaringClass(); if (declaringClass != null) { declaringClass = declaringClass.getErasure(); } if (declaringClass == null) { if (binding.isRecovered()) { fqn = createUnknownFqn(binding.getName()); } else if (node.getExpression().resolveTypeBinding().isArray() && binding.getName().equals("length")) { // Ignore array length return true; } else { logger.log(Level.SEVERE, "Non-recovered field binding without a declaring class that's not an array.length!"); } } else { fqn = getTypeFqn(declaringClass) + "." + binding.getName(); } } // Write the relation if (inLhsAssignment) { relationWriter.writeRelation(Relation.WRITES, fqnStack.getFqn(), fqn, createLocation(node.getName())); } else { relationWriter.writeRelation(Relation.READS, fqnStack.getFqn(), fqn, createLocation(node.getName())); } inLhsAssignment = false; node.getExpression().accept(this); return false; }
From source file:fr.labri.harmony.rta.junit.jdt.JDTVisitorRTA.java
License:Open Source License
public boolean visit(FieldAccess a) { IVariableBinding b = a.resolveFieldBinding(); if (b != null && currentJavaMethod != null) { if (b.getDeclaringClass() != null) { if (!(a.getParent() instanceof Assignment)) { String fieldId = getVariableBindingId(b); //System.err.println("Add "+fieldId); currentJavaMethod.getCallsSite().add(fieldId); } else { if (((Assignment) a.getParent()).getLeftHandSide() instanceof FieldAccess) { if (((FieldAccess) ((Assignment) a.getParent()).getLeftHandSide()) .resolveFieldBinding() != null) { if (!((FieldAccess) ((Assignment) a.getParent()).getLeftHandSide()) .resolveFieldBinding().getKey().equals(b.getKey())) { String fieldId = getVariableBindingId(b); //System.err.println("Add "+fieldId); currentJavaMethod.getCallsSite().add(fieldId); }// www . ja v a2 s.c o m } } } } } return true; }