package no.uio.ifi.refaktor.analyze.analyzers; import java.util.LinkedList; import java.util.List; import no.uio.ifi.refaktor.analyze.ExtractAndMoveMethodCandidate; import no.uio.ifi.refaktor.analyze.exceptions.RefaktorAnalyzerException; import no.uio.ifi.refaktor.debugging.RefaktorDebug; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; /** * Responsible for analyzing all methods in a compilation unit for * candidates to the Extract and Move Method refactoring. */ public class CompilationUnitWideExtractAndMoveMethodAnalyzer implements AggregationAnalyzer { private final ICompilationUnit compilationUnit; private final List results; public CompilationUnitWideExtractAndMoveMethodAnalyzer(ICompilationUnit compilationUnit) { this.compilationUnit = compilationUnit; results = new LinkedList(); } @Override public List getResults() { return results; } @Override public void analyze() throws RefaktorAnalyzerException { try { analyzeMethodsInCompilationUnit(); } catch (JavaModelException e) { RefaktorDebug.log(e); } } private void analyzeMethodsInCompilationUnit() throws JavaModelException { for (IType type: compilationUnit.getAllTypes()) analyzeMethodsInType(type); } private void analyzeMethodsInType(IType type) throws JavaModelException { TypeWideExtractAndMoveMethodAnalyzer analyzer = new TypeWideExtractAndMoveMethodAnalyzer(type); analyzer.analyze(); results.addAll(analyzer.getResults()); } }