1 package com.stateofflow.eclipse.metrics.builder.list;
2
3 import java.io.IOException;
4
5 import org.eclipse.core.runtime.CoreException;
6 import org.eclipse.jdt.core.IJavaProject;
7 import org.eclipse.jdt.core.IPackageFragmentRoot;
8 import org.eclipse.jdt.core.JavaModelException;
9
10 import com.stateofflow.eclipse.metrics.util.ProgressMonitor;
11
12 class FullListBuilder {
13 private final IJavaProject project;
14 private final JavaElementListBuilder javaElementListBuilder;
15
16 public FullListBuilder(final IJavaProject project, final JavaElementListBuilder javaElementListBuilder) throws IOException {
17 this.project = project;
18 this.javaElementListBuilder = javaElementListBuilder;
19 }
20
21 public void build(final ProgressMonitor monitor) throws CoreException, IOException {
22 buildComplete(monitor);
23 }
24
25 private void buildComplete(final ProgressMonitor monitor) throws JavaModelException {
26 final IPackageFragmentRoot[] packageFragmentRoots = project.getAllPackageFragmentRoots();
27 monitor.beginTask("Building complete compilation unit list", packageFragmentRoots.length);
28
29 for (int i = 0; i < packageFragmentRoots.length; i++) {
30 addTypesForPackageFragmentRoot(packageFragmentRoots[i], monitor.newChild(1));
31 }
32 }
33
34 private void addTypesForPackageFragmentRoot(final IPackageFragmentRoot packageFragmentRoot, final ProgressMonitor monitor) throws JavaModelException {
35 if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE && packageFragmentRoot.getCorrespondingResource() != null && project.getProject().equals(packageFragmentRoot.getCorrespondingResource().getProject())) {
36 javaElementListBuilder.addTypesForJavaElements(packageFragmentRoot.getChildren(), packageFragmentRoot.getElementName(), monitor);
37 }
38 }
39 }
40