public int countStatements(MethodDeclaration methodDeclaration) { counter = 0; methodDeclaration.accept(this); return counter; } @Override
public int countStatements(MethodDeclaration methodDeclaration) { counter = 0; methodDeclaration.accept(this); return counter; } @Override
private boolean canReturn(MethodDeclaration constructor) { final ReturnFinder retFinder= new ReturnFinder(); constructor.accept(retFinder); return retFinder.foundOne; }
private boolean canReturn(MethodDeclaration constructor) { final ReturnFinder retFinder= new ReturnFinder(); constructor.accept(retFinder); return retFinder.foundOne; }
private VariableDeclarationFragment getEventBackingField(MethodDeclaration node) { FieldAccessFinder finder = new FieldAccessFinder(); node.accept(finder); return findDeclaringNode(finder.field); }
/** * Checks whether variable is referenced by the method declaration or not. * * @param binding binding of variable to check. * @return <code>true</code> if variable is referenced by the method, otherwise <code>false</code> */ public boolean isVariableReferenced(IVariableBinding binding) { VariableReferenceFinder finder= new VariableReferenceFinder(binding); fDeclaration.accept(finder); return finder.getResult(); }
/** * Checks whether variable is referenced by the method declaration or not. * * @param binding binding of variable to check. * @return <code>true</code> if variable is referenced by the method, otherwise <code>false</code> */ public boolean isVariableReferenced(IVariableBinding binding) { VariableReferenceFinder finder= new VariableReferenceFinder(binding); fDeclaration.accept(finder); return finder.getResult(); }
/** * Checks whether variable is referenced by the method declaration or not. * * @param binding binding of variable to check. * @return <code>true</code> if variable is referenced by the method, otherwise <code>false</code> */ public boolean isVariableReferenced(IVariableBinding binding) { VariableReferenceFinder finder= new VariableReferenceFinder(binding); fDeclaration.accept(finder); return finder.getResult(); }
public ObjectUsage findObjectUsage(final String varname, final MethodDeclaration method) { ensureIsNotNull(varname); ensureIsNotNull(method); setVarname(varname); initializeResult(); if ("".equals(varname) || "this".equals(varname) || "super".equals(varname)) { res.kind = Kind.THIS; } method.accept(this); if (res.kind == null) res.kind = Kind.FIELD; return res; }
/** * @param sn the symbol to resolve * @return pure type name, null if not found */ public static String findDeclType(SimpleName sn) { { DeclTypeSelector declTypeSelector = new DeclTypeSelector(sn.getIdentifier()); MethodDeclaration upperMethod = FindUpper.methodScope(sn); if (upperMethod != null) { FindUpper.methodScope(sn).accept(declTypeSelector); if (declTypeSelector.getHits().size() > 0) { return declTypeSelector.getHits().get(0).toString().trim(); } } } List<Type> hits = findDeclTypeInClass(sn, FindUpper.typeScope(sn)); Assert.assertTrue(hits.size() <= 1); if (hits.size() == 1) { return hits.get(0).toString().trim(); } return null; }
static boolean hasReference(MethodDeclaration node) { try { SuperThisReferenceFinder finder= new SuperThisReferenceFinder(); ClassInstanceCreation cic= (ClassInstanceCreation) node.getParent().getParent(); finder.fFunctionalInterface= cic.getType().resolveBinding(); finder.fMethodDeclaration= node; node.accept(finder); } catch (AbortSearchException e) { return true; } return false; }
static boolean hasReference(MethodDeclaration node) { try { SuperThisReferenceFinder finder = new SuperThisReferenceFinder(); ClassInstanceCreation cic = (ClassInstanceCreation) node.getParent().getParent(); finder.fFunctionalInterface = cic.getType().resolveBinding(); finder.fMethodDeclaration = node; node.accept(finder); } catch (AbortSearchException e) { return true; } return false; }
static boolean hasReference(MethodDeclaration node) { try { SuperThisReferenceFinder finder= new SuperThisReferenceFinder(); ClassInstanceCreation cic= (ClassInstanceCreation) node.getParent().getParent(); finder.fFunctionalInterface= cic.getType().resolveBinding(); finder.fMethodDeclaration= node; node.accept(finder); } catch (AbortSearchException e) { return true; } return false; }
private void hasMagicNumbers() { NumberLiteralVisitor visitor = new NumberLiteralVisitor(); methodMetrics.getMethod().getMethodDeclaration().accept(visitor); List<NumberLiteral> literals = visitor.getNumberLiteralsExpressions(); if( literals.size() < 1 ) { return; } for(NumberLiteral singleNumberLiteral : literals) { if( isLiteralValid(singleNumberLiteral) ) { addToSmells(initializeCodeSmell(MAGIC_NUMBER)); } } }
/** * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TypeDeclaration) */ public boolean visit(TypeDeclaration node) { if (containsPosition(node)) { // visit the methode declarations MethodDeclaration[] methods = node.getMethods(); for (int i = 0, length = methods.length; i < length && !fFound; i++) { methods[i].accept(this); } if (!fFound) { // visit inner types TypeDeclaration[] types = node.getTypes(); for (int i = 0, length = types.length; i < length && !fFound; i++) { types[i].accept(this); } } } return false; }
private void hasMissingDefaults() { MethodControlFlowVisitor visitor = new MethodControlFlowVisitor(); methodMetrics.getMethod().getMethodDeclaration().accept(visitor); List<SwitchStatement> switchStatements = visitor.getSwitchStatements(); for(SwitchStatement singleSwitchStatement : switchStatements) { if(switchIsMissingDefault(singleSwitchStatement)) { addToSmells(initializeCodeSmell(MISSING_DEFAULT)); } } }
private int calculateCyclomaticComplexity() { MethodControlFlowVisitor visitor = new MethodControlFlowVisitor(); method.getMethodDeclaration().accept(visitor); return visitor.getNumOfIfStatements() + visitor.getNumOfSwitchCaseStatementsWitoutDefault() + visitor.getNumOfForStatements() + visitor.getNumOfWhileStatements() + visitor.getNumOfDoStatements() + visitor.getNumOfForeachStatements() + 1; }
private void hasComplexConditional() { MethodControlFlowVisitor visitor = new MethodControlFlowVisitor(); methodMetrics.getMethod().getMethodDeclaration().accept(visitor); for (IfStatement ifStatement : visitor.getIfStatements()) { if (numOfBooleanSubExpressions(ifStatement) >= thresholdsDTO.getComplexCondition()) { addToSmells(initializeCodeSmell(COMPLEX_CONDITIONAL)); } } }
public List<ImplementationCodeSmell> detectEmptyCatchBlock() { MethodControlFlowVisitor visitor = new MethodControlFlowVisitor(); methodMetrics.getMethod().getMethodDeclaration().accept(visitor); for (TryStatement tryStatement : visitor.getTryStatements()) { for (Object catchClause : tryStatement.catchClauses()) { if (!hasBody((CatchClause) catchClause)) { addToSmells(initializeCodeSmell(EMPTY_CATCH_CLAUSE)); } } } return smells; }
@SuppressWarnings("unchecked") @Override public boolean visit(TypeDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); } // @Inria pushNode(node, node.getName().toString()); visitListAsNode(EntityType.MODIFIERS, node.modifiers()); visitListAsNode(EntityType.TYPE_ARGUMENTS, node.typeParameters()); if (node.getSuperclassType() != null) { node.getSuperclassType().accept(this); } visitListAsNode(EntityType.SUPER_INTERFACE_TYPES, node.superInterfaceTypes()); // @Inria // Change Distiller does not check the changes at Class Field declaration for (FieldDeclaration fd : node.getFields()) { fd.accept(this); } // @Inria // Visit Declaration and Body (inside MD visiting) for (MethodDeclaration md : node.getMethods()) { md.accept(this); } return false; }