package no.uio.ifi.refaktor.analyze.analyzers; import java.util.LinkedList; import java.util.List; import no.uio.ifi.refaktor.analyze.ExtractAndMoveMethodAnalysisResult; import no.uio.ifi.refaktor.analyze.comparators.FavorNoUnfixesAnalysisResultComparator; import no.uio.ifi.refaktor.analyze.exceptions.NoTargetFoundException; import no.uio.ifi.refaktor.analyze.exceptions.RefaktorAnalyzerException; import no.uio.ifi.refaktor.utils.RefaktorDebug; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; /** * Responsible for analyzing all methods in a type for * candidates to the Extract and Move Method refactoring. */ public class TypeWideExtractAndMoveMethodAnalyzer implements AggregationAnalyzer { private final IType type; private final List results; public TypeWideExtractAndMoveMethodAnalyzer(IType type) { this.type = type; results = new LinkedList(); } @Override public List getResults() { return results; } @Override public void analyze() throws RefaktorAnalyzerException { try { analyzeMethodsInType(); } catch (JavaModelException e) { RefaktorDebug.log(e); } } private void analyzeMethodsInType() throws JavaModelException { for (IMethod method: type.getMethods()) { analyzeMethod(method); } } private void analyzeMethod(IMethod method) { try { SearchBasedExtractAndMoveMethodAnalyzer analyzer = new SearchBasedExtractAndMoveMethodAnalyzer(method, new FavorNoUnfixesAnalysisResultComparator()); analyzer.analyze(); results.add(analyzer.getResult()); } catch (NoTargetFoundException e) { // Ignoring } catch (AssertionError err) { RefaktorDebug.log(err); } } }