@Override public boolean visit(MethodInvocation node) { String mName = node.getName().getFullyQualifiedName().toString(); Expression e = node.getExpression(); String typName = ""; if (e instanceof StringLiteral) { typName = "string"; } else if (e instanceof FieldAccess) { FieldAccess field = (FieldAccess) e; typName = field.getName().getFullyQualifiedName(); } else if (e instanceof Name) { typName = ((Name) e).getFullyQualifiedName(); if (varTypMap.containsKey(typName)) { typName = varTypMap.get(typName); } } else { if (e != null) { typName = e.toString(); if (typName.contains(".")) typName = typName.substring(0, typName.indexOf('.', 0)); if (varTypMap.containsKey(typName)) typName = varTypMap.get(typName); } } String key = typName + "->" + mName; if (freqRecord.containsKey(key)) { freqRecord.put(key, freqRecord.get(key) + 1); } else { freqRecord.put(key, 1); } return super.visit(node); }
/* * @see ASTVisitor#visit(FieldAccess) */ @Override public boolean visit(FieldAccess node) { node.getExpression().accept(this); this.fBuffer.append("."); // $NON-NLS-1$ node.getName().accept(this); return false; }
/* * Must be one of: * <ul> * <li>[result].length</li> * </ul> */ private boolean validateLengthQuery(Expression lengthQuery) { if (lengthQuery instanceof QualifiedName) { QualifiedName qualifiedName = (QualifiedName) lengthQuery; SimpleName name = qualifiedName.getName(); if (!LENGTH_QUERY.equals(name.getIdentifier())) return false; Name arrayAccess = qualifiedName.getQualifier(); ITypeBinding accessType = arrayAccess.resolveTypeBinding(); if (accessType == null) return false; if (!accessType.isArray()) return false; IBinding arrayBinding = arrayAccess.resolveBinding(); if (arrayBinding == null) return false; fArrayBinding = arrayBinding; fArrayAccess = arrayAccess; return true; } else if (lengthQuery instanceof FieldAccess) { FieldAccess fieldAccess = (FieldAccess) lengthQuery; SimpleName name = fieldAccess.getName(); if (!LENGTH_QUERY.equals(name.getIdentifier())) return false; Expression arrayAccess = fieldAccess.getExpression(); ITypeBinding accessType = arrayAccess.resolveTypeBinding(); if (accessType == null) return false; if (!accessType.isArray()) return false; IBinding arrayBinding = getBinding(arrayAccess); if (arrayBinding == null) return false; fArrayBinding = arrayBinding; fArrayAccess = arrayAccess; return true; } return false; }
/* * @see ASTVisitor#visit(FieldAccess) */ @Override public boolean visit(FieldAccess node) { evalQualifyingExpression(node.getExpression(), node.getName()); return false; }
private void collectSideEffects(Expression expr, List<Expression> sideEffectExprs) { // local variable, parameter, enum constant, etc. // OR method starting with is*(), get*() // except atomic long, atomic integer, etc. switch (expr.getNodeType()) { case METHOD_INVOCATION: MethodInvocation mi = (MethodInvocation) expr; methodHasSideEffects(mi.resolveMethodBinding(), mi, sideEffectExprs); collectSideEffects(mi.getExpression(), sideEffectExprs); collectSideEffects(arguments(mi), sideEffectExprs); break; case SUPER_METHOD_INVOCATION: SuperMethodInvocation smi = (SuperMethodInvocation) expr; methodHasSideEffects(smi.resolveMethodBinding(), smi, sideEffectExprs); collectSideEffects(arguments(smi), sideEffectExprs); break; case CLASS_INSTANCE_CREATION: ClassInstanceCreation cic = (ClassInstanceCreation) expr; methodHasSideEffects(cic.resolveConstructorBinding(), cic, sideEffectExprs); collectSideEffects(cic.getExpression(), sideEffectExprs); collectSideEffects(arguments(cic), sideEffectExprs); break; case ARRAY_ACCESS: ArrayAccess aa = (ArrayAccess) expr; collectSideEffects(aa.getArray(), sideEffectExprs); collectSideEffects(aa.getIndex(), sideEffectExprs); break; case ARRAY_CREATION: ArrayCreation ac = (ArrayCreation) expr; collectSideEffects(ac.getInitializer(), sideEffectExprs); collectSideEffects(ac.dimensions(), sideEffectExprs); break; case ARRAY_INITIALIZER: ArrayInitializer ai = (ArrayInitializer) expr; collectSideEffects(expressions(ai), sideEffectExprs); break; case ASSIGNMENT: Assignment as = (Assignment) expr; collectSideEffects(as.getLeftHandSide(), sideEffectExprs); collectSideEffects(as.getRightHandSide(), sideEffectExprs); break; case CONDITIONAL_EXPRESSION: ConditionalExpression ce = (ConditionalExpression) expr; collectSideEffects(ce.getExpression(), sideEffectExprs); collectSideEffects(ce.getThenExpression(), sideEffectExprs); collectSideEffects(ce.getElseExpression(), sideEffectExprs); break; case FIELD_ACCESS: FieldAccess fa = (FieldAccess) expr; collectSideEffects(fa.getExpression(), sideEffectExprs); collectSideEffects(fa.getName(), sideEffectExprs); break; case SUPER_FIELD_ACCESS: SuperFieldAccess sfa = (SuperFieldAccess) expr; collectSideEffects(sfa.getQualifier(), sideEffectExprs); collectSideEffects(sfa.getName(), sideEffectExprs); break; case THIS_EXPRESSION: collectSideEffects(((ThisExpression) expr).getQualifier(), sideEffectExprs); break; case VARIABLE_DECLARATION_EXPRESSION: collectSideEffects((VariableDeclarationExpression) expr, sideEffectExprs); break; case INFIX_EXPRESSION: InfixExpression ie = (InfixExpression) expr; collectSideEffects(ie.getLeftOperand(), sideEffectExprs); collectSideEffects(ie.getRightOperand(), sideEffectExprs); collectSideEffects(extendedOperands(ie), sideEffectExprs); break; case CAST_EXPRESSION: collectSideEffects(((CastExpression) expr).getExpression(), sideEffectExprs); break; case INSTANCEOF_EXPRESSION: collectSideEffects(((InstanceofExpression) expr).getLeftOperand(), sideEffectExprs); break; case PARENTHESIZED_EXPRESSION: collectSideEffects(((ParenthesizedExpression) expr).getExpression(), sideEffectExprs); break; case POSTFIX_EXPRESSION: sideEffectExprs.add(expr); break; case PREFIX_EXPRESSION: PrefixExpression pe = (PrefixExpression) expr; PrefixExpression.Operator op = pe.getOperator(); if (PrefixExpression.Operator.INCREMENT.equals(op) | PrefixExpression.Operator.DECREMENT.equals(op)) { sideEffectExprs.add(pe); } else { collectSideEffects(pe.getOperand(), sideEffectExprs); } break; default: // literals // names } }
/* (non-Javadoc) * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.FieldAccess) */ public boolean visit(FieldAccess node) { expression = createFieldAccess(node.getName().getIdentifier(), perform(node.getExpression())); return false; }