Commit 4b15514b authored by andrei's avatar andrei

fix for bug 304424 (reference view issues)

parent 7440f1f9
Manifest-Version: 1.0
Bundle-Name: Bytecode Outline Plug-in
Bundle-SymbolicName: de.loskutov.BytecodeOutline;singleton=true
Bundle-Version: 2.0.2
Bundle-Version: 2.0.4
Bundle-ClassPath: BytecodeOutline.jar
Bundle-Activator: de.loskutov.bco.BytecodeOutlinePlugin
Bundle-Vendor: Andrei Loskutov
......@@ -16,7 +16,6 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.jdt.ui,
org.eclipse.core.resources,
org.eclipse.ui.ide,
org.eclipse.jdt,
org.eclipse.compare,
org.eclipse.ui.console,
org.eclipse.help.base,
......
......@@ -28,3 +28,5 @@ BytecodeOutlineView.find_replace.image=
BytecodeOutlineView.toggle.vertical.label=&Vertical View Orientation
BytecodeOutlineView.toggle.horizontal.label=&Horizontal View Orientation
BytecodeOutlineView.toggle.automatic.label=&Automatic View Orientation
BytecodeReferenceView.empty.selection.text=<html><head><title>Bytecode reference</title></head><body bgcolor='#D3D3D3'>Please select any bytecode instruction in the bytecode outline view.</body></html>
......@@ -378,7 +378,8 @@ public class DecompiledMethod {
if (error != null && insn != null && insn.intValue() == errorInsn) {
return null;
}
if (frames != null && insn != null) {
if (frames != null && insn != null && insn.intValue() >= 0
&& insn.intValue() < frames.length) {
Frame f = frames[insn.intValue()];
if (f == null) {
return null;
......@@ -455,7 +456,7 @@ public class DecompiledMethod {
arraySymbols += "[";
s = s.substring(1);
}
int idx = s.lastIndexOf('/');
if (idx > 0) {
// from "Ljava/lang/Object;" to "Object"
......@@ -466,7 +467,7 @@ public class DecompiledMethod {
return arraySymbols + s;
}
// resolve primitive types
return arraySymbols +
return arraySymbols +
CommentedClassVisitor.getSimpleName(Type.getType(s));
}
return "Lnull;".equals(s) ? "null" : s;
......
......@@ -10,13 +10,17 @@ import org.eclipse.help.internal.appserver.WebappManager;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartReference;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.part.ViewPart;
import org.objectweb.asm.util.AbstractVisitor;
......@@ -25,12 +29,15 @@ import de.loskutov.bco.BytecodeOutlinePlugin;
public class BytecodeReferenceView extends ViewPart implements IPartListener2, ISelectionListener {
Browser browser;
private static final String NLS_PREFIX = "BytecodeReferenceView.";
private Browser browser;
public void createPartControl(Composite parent) {
browser = new Browser(parent, SWT.NONE);
browser = new Browser(parent, SWT.BORDER);
browser.setText(BytecodeOutlinePlugin.getResourceString(NLS_PREFIX
+ "empty.selection.text"));
getSite().getWorkbenchWindow().getPartService().addPartListener(this);
// TODO run this in background!
BaseHelpSystem.ensureWebappRunning();
}
......@@ -68,13 +75,28 @@ public class BytecodeReferenceView extends ViewPart implements IPartListener2, I
public void partHidden(IWorkbenchPartReference partRef) {
if (partRef.getId().equals(getSite().getId())) {
getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(this);
getSite().getWorkbenchWindow().getSelectionService()
.removePostSelectionListener(BytecodeOutlineView.class.getName(), this);
}
}
public void partVisible(IWorkbenchPartReference partRef) {
if (partRef.getId().equals(getSite().getId())) {
getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
IWorkbenchWindow workbenchWindow = getSite().getWorkbenchWindow();
ISelectionService selectionService = workbenchWindow
.getSelectionService();
String partId = BytecodeOutlineView.class.getName();
selectionService.addPostSelectionListener(partId, this);
// perform initialization with already existing selection (if any)
ISelection selection = selectionService.getSelection(partId);
if(selection != null) {
IViewReference viewReference = workbenchWindow.getActivePage()
.findViewReference(partId);
if(viewReference != null) {
selectionChanged(viewReference.getView(false), selection);
}
}
}
}
......@@ -83,42 +105,89 @@ public class BytecodeReferenceView extends ViewPart implements IPartListener2, I
}
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (selection instanceof ITextSelection && part instanceof BytecodeOutlineView) {
int line = ((ITextSelection)selection).getStartLine();
int opcode = ((BytecodeOutlineView)part).getBytecodeInstructionAtLine(line);
if(!(part instanceof BytecodeOutlineView)){
return;
}
int line = -1;
String opcodeName = null;
if (selection instanceof ITextSelection) {
line = ((ITextSelection)selection).getStartLine();
} else if(selection instanceof IStructuredSelection){
IStructuredSelection sselection = (IStructuredSelection) selection;
int size = sselection.size();
if(size == 1 && sselection.getFirstElement() instanceof Integer){
line = ((Integer)sselection.getFirstElement()).intValue();
}
}
String opcodeName = null;
if(line >= 0){
int opcode = ((BytecodeOutlineView)part).getBytecodeInstructionAtLine(line);
if (opcode != -1) {
opcodeName = AbstractVisitor.OPCODES[opcode];
}
}
if (opcodeName != null) {
URL url = getHelpResource( opcodeName);
if( url!=null) {
browser.setUrl( url.toString());
} else {
browser.setText("");
}
if (opcodeName != null) {
opcodeName = checkOpcodeName(opcodeName);
URL url = getHelpResource(opcodeName);
if (url != null) {
browser.setUrl(url.toString());
} else {
browser.setText("");
browser.setText(BytecodeOutlinePlugin.getResourceString(NLS_PREFIX
+ "empty.selection.text"));
}
} else {
browser.setText(BytecodeOutlinePlugin.getResourceString(NLS_PREFIX
+ "empty.selection.text"));
}
}
private String checkOpcodeName(String opcodeName) {
opcodeName = opcodeName.toLowerCase();
/*
* we need an additional check for DCONST_1...5, FCONST_1...5 etc case
* to convert it to DCONST_D etc
*/
int sepIndex = opcodeName.indexOf('_');
if(sepIndex > 0 && Character.isDigit(opcodeName.charAt(sepIndex + 1))){
opcodeName = opcodeName.substring(0, sepIndex);
switch(opcodeName.charAt(0)){
case 'd':
opcodeName += "_d";
break;
case 'f':
opcodeName += "_f";
break;
case 'l':
opcodeName += "_l";
break;
default:
// ICONST uses "n"
opcodeName += "_n";
break;
}
}
return opcodeName;
}
private URL getHelpResource( String name) {
try {
// BaseHelpSystem.resolve() method is not awailable in 3.0
String host = WebappManager.getHost();
int port = WebappManager.getPort();
String href = "/"+BytecodeOutlinePlugin.getDefault().getBundle().getSymbolicName()+
"/doc/ref-"+name.toLowerCase()+".html";
return new URL( "http://"+host+":"+port+"/help/nftopic"+href);
// return BaseHelpSystem.resolve( href, true);
// return new File( BytecodeOutlinePlugin.PLUGIN_PATH+"/doc/ref-"+name.toLowerCase()+".html").toURL();
} catch( Exception e) {
return null;
}
private URL getHelpResource(String name) {
try {
// BaseHelpSystem.resolve() method is not awailable in 3.0
String host = WebappManager.getHost();
int port = WebappManager.getPort();
String href = "/"
+ BytecodeOutlinePlugin.getDefault().getBundle()
.getSymbolicName() + "/doc/ref-" + name + ".html";
return new URL("http://" + host + ":" + port + "/help/nftopic"
+ href);
// return BaseHelpSystem.resolve( href, true);
// return new File(
// BytecodeOutlinePlugin.PLUGIN_PATH+"/doc/ref-"+name.toLowerCase()+".html").toURL();
} catch (Exception e) {
return null;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment