package bluej.collect;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import bluej.compiler.CompileInputFile;
import bluej.compiler.CompileReason;
import bluej.compiler.CompileType;
import bluej.compiler.Diagnostic;
import bluej.compiler.FXCompileObserver;
import bluej.extensions.SourceType;
import bluej.pkgmgr.Project;
| A wrapper for a {}link FXCompileObserver} that also logs the
| error messages to the data collector.
|
| @author Neil Brown
|
public class DataCollectionCompileObserverWrapper
implements FXCompileObserver{
private FXCompileObserver wrapped;
private List<DiagnosticWithShown> diagnostics = new ArrayList<DiagnosticWithShown>();
private CompileInputFile[] sources;
private CompileReason reason;
private Project project;
public DataCollectionCompileObserverWrapper(Project project, FXCompileObserver wrapped)
{
this.project = project;
this.wrapped = wrapped;
}
@Override
public void startCompile(CompileInputFile[] sources, CompileReason reason, CompileType type, int compilationSequence)
{
diagnostics.clear();
this.sources = sources;
this.reason = reason;
wrapped.startCompile(sources, reason, type, compilationSequence);
}
@Override
public boolean compilerMessage(Diagnostic diagnostic, CompileType type)
{
boolean shownToUser = wrapped.compilerMessage(diagnostic, type);
if (diagnostic.getFileName() != null)
{
File userFile = new File(diagnostic.getFileName());
for (CompileInputFile input : sources)
{
if (input.getJavaCompileInputFile().getName().equals(userFile.getName()))
{
userFile = input.getUserSourceFile();
break;
}
}
diagnostics.add(new DiagnosticWithShown(diagnostic, shownToUser, userFile));
}
return shownToUser;
}
@Override
public void endCompile(CompileInputFile[] sources, boolean successful, CompileType type, int compilationSequence)
{
Set<String> packages = new HashSet<String>();
for (CompileInputFile f : sources)
{
packages.add(project.getPackageForFile(f.getJavaCompileInputFile()));
}
bluej.pkgmgr.Package pkg = packages.size() == 1 ? project.getPackage(packages.iterator().next()) : null;
DataCollector.compiled(project, pkg, sources, diagnostics, successful, reason, compilationSequence);
wrapped.endCompile(sources, successful, type, compilationSequence);
}
}
top,
use,
map,
class DataCollectionCompileObserverWrapper
. DataCollectionCompileObserverWrapper
. startCompile
. compilerMessage
. endCompile
97 neLoCode
+ 3 LoComm