public static void doDecompilerAttach(PackageFragmentRoot root)
{
try
{
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
SourceMapper existingMapper = root.getSourceMapper();
if (existingMapper instanceof RealignmentJDSourceMapper)
{
// Remove decompiler attachment
RealignmentJDSourceMapper jdSourceMapper = (RealignmentJDSourceMapper) existingMapper;
root.setSourceMapper(null);
RealignmentJDSourceMapper.clearDecompiled(jdSourceMapper);
// Re-attach any source which was previously attached
SourceAttachmentDetails details = jdSourceMapper.sourceDetails;
if (details != null)
{
applySourceAttachment(shell, details.newEntry,
details.project, details.containerPath,
details.isReferencedEntry);
}
}
else
{
SourceAttachmentDetails details = null;
if (root.getSourceAttachmentPath() != null)
{
AtomicReference<IPath> containerPath = new AtomicReference<IPath>();
IClasspathEntry entry = getClasspathEntry(root, containerPath);
// Backup existing attachment details
CPListElement backupCpElement = CPListElement.createFromExisting(entry,
root.getJavaProject());
details = new SourceAttachmentDetails(backupCpElement.getClasspathEntry(),
root.getJavaProject(),
containerPath.get(),
entry.getReferencingEntry() != null);
}
// Source copied from
// jd.ide.eclipse.editors.JDClassFileEditor
// The location of the archive file containing classes.
IPath classPath = root.getPath();
// The location of the archive file containing source.
IPath sourcePath = root.getSourceAttachmentPath();
if (sourcePath == null)
sourcePath = classPath;
// Specifies the location of the package fragment root
// within the zip (empty specifies the default root).
IPath sourceAttachmentRootPath = root.getSourceAttachmentRootPath();
String sourceRootPath;
if (sourceAttachmentRootPath == null)
{
sourceRootPath = null;
}
else
{
sourceRootPath = sourceAttachmentRootPath.toString();
if ((sourceRootPath != null) && (sourceRootPath.length() == 0))
sourceRootPath = null;
}
Map<?, ?> options = root.getJavaProject().getOptions(true);
// Create source mapper
SourceMapper mapper = RealignmentJDSourceMapper.newSourceMapper(
classPath, sourcePath, sourceRootPath, options, details);
root.setSourceMapper(mapper);
}
// Remove any buffers associated with the root being modified