Commit 97729732 authored by andrei's avatar andrei

Introduced status parameter in log method, fixed errors on "invisible view",...

Introduced status parameter in log method, fixed errors on "invisible view", fixed primitive types output in non-raw mode in analyzer.
parent aa2f606d
......@@ -27,7 +27,7 @@ public class BytecodeOutlinePlugin extends AbstractUIPlugin {
private ResourceBundle resourceBundle;
/** asm logo */
public static final String IMG_ASM = "icons/asm.gif"; //$NON-NLS-1$
/**
* The constructor.
*/
......@@ -84,7 +84,7 @@ public class BytecodeOutlinePlugin extends AbstractUIPlugin {
return key;
}
}
/**
* Returns the plugin's resource bundle,
*/
......@@ -121,9 +121,10 @@ public class BytecodeOutlinePlugin extends AbstractUIPlugin {
}
/**
* @param statusID one of IStatus. constants like IStatus.ERROR etc
* @param error
*/
public static void logError(Throwable error) {
public static void log(Throwable error, int statusID) {
String message = error.getMessage();
if(message == null){
message = error.toString();
......@@ -131,9 +132,9 @@ public class BytecodeOutlinePlugin extends AbstractUIPlugin {
getDefault().getLog()
.log(
new Status(
IStatus.ERROR,
statusID,
"BytecodeOutline", 0, message, error)); //$NON-NLS-1$
}
}
\ No newline at end of file
......@@ -102,7 +102,7 @@ public class CommentedClassVisitor extends TraceClassVisitor {
* @param t
* @return simply class name without any package/outer class information
*/
private static String getSimpleName(Type t) {
public static String getSimpleName(Type t) {
String name = t.getClassName();
return eatPackageNames(name, '.');
}
......
......@@ -6,6 +6,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IStatus;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.LocalVariableNode;
import org.objectweb.asm.tree.MethodNode;
......@@ -96,7 +97,7 @@ public class DecompiledMethod {
.indexOf(':')));
error = error.substring(error.indexOf(':') + 2);
} else {
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
error = null;
}
}
......@@ -270,7 +271,7 @@ public class DecompiledMethod {
}
} catch (IndexOutOfBoundsException e) {
// TODO should we keep this?
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.WARNING);
}
}
......@@ -332,7 +333,7 @@ public class DecompiledMethod {
return new String[] {localsBuf.toString(), stackBuf.toString()};
} catch (IndexOutOfBoundsException e) {
// TODO should we keep this?
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.WARNING);
}
}
return null;
......@@ -380,7 +381,7 @@ public class DecompiledMethod {
(String[][]) stack.toArray( new String[ 2][])};
} catch (IndexOutOfBoundsException e) {
// TODO should we keep this?
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
}
}
return null;
......@@ -412,15 +413,21 @@ public class DecompiledMethod {
}
}
private String getTypeName( final boolean useQualifiedNames, String s) {
if(!useQualifiedNames) {
int idx = s.lastIndexOf('/');
if(idx > 0){
// from "Ljava/lang/Object;" to "Object"
return s.substring(idx + 1, s.length() - 1);
}
}
return "Lnull;".equals(s) ? "null" : s;
private String getTypeName(final boolean useQualifiedNames, String s) {
if (!useQualifiedNames) {
int idx = s.lastIndexOf('/');
if (idx > 0) {
// from "Ljava/lang/Object;" to "Object"
return s.substring(idx + 1, s.length() - 1);
}
// this is the case on LVT view - ignore it
if("." == s){
return s;
}
// resolve primitive types
return CommentedClassVisitor.getSimpleName(Type.getType(s));
}
return "Lnull;".equals(s) ? "null" : s;
}
public int getDecompiledLine(final int sourceLine) {
......
......@@ -20,7 +20,7 @@ import de.loskutov.bco.BytecodeOutlinePlugin;
* @author V. Grishchenko, Eugene Kuleshov
*/
public class BytecodeActionBarContributor extends ClassFileEditorActionContributor {
private BytecodeClassFileEditor editor;
BytecodeClassFileEditor editor;
private ShowBytecodeAction dAction;
......@@ -50,8 +50,9 @@ public class BytecodeActionBarContributor extends ClassFileEditorActionContribut
if (targetEditor instanceof BytecodeClassFileEditor) {
editor = (BytecodeClassFileEditor) targetEditor;
editor.doSetInput(false);
} else
} else {
editor = null;
}
super.setActiveEditor(targetEditor);
}
......@@ -66,8 +67,9 @@ public class BytecodeActionBarContributor extends ClassFileEditorActionContribut
}
public void run() {
if (editor != null)
editor.doSetInput(true);
if (editor != null) {
editor.doSetInput(true);
}
}
}
......
......@@ -67,8 +67,9 @@ public class BytecodeBufferManager extends BufferManager {
e);
BytecodeOutlinePlugin.getDefault().getLog().log(err);
}
if (realSource == null)
if (realSource == null) {
jManager.addBuffer(buffer);
}
}
}
}
......
/* $Id: BytecodeClassFileEditor.java,v 1.1 2005-01-09 10:08:28 ekuleshov Exp $ */
/* $Id: BytecodeClassFileEditor.java,v 1.2 2005-02-07 18:59:14 andrei Exp $ */
package de.loskutov.bco.editors;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.core.IBuffer;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.IJavaElement;
......@@ -20,7 +21,7 @@ import de.loskutov.bco.BytecodeOutlinePlugin;
/**
* A "better" way to hook into JDT...
*
*
* @author Eugene Kuleshov, V. Grishchenko, Jochen Klein
*/
public class BytecodeClassFileEditor extends ClassFileEditor {
......@@ -56,7 +57,7 @@ public class BytecodeClassFileEditor extends ClassFileEditor {
/**
* Sets edditor input only if buffer was actually opened.
*
*
* @param force
* if <code>true</code> initialize no matter what
*/
......@@ -66,7 +67,7 @@ public class BytecodeClassFileEditor extends ClassFileEditor {
try {
doSetInput(input);
} catch (Exception e) {
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
}
}
}
......@@ -89,27 +90,27 @@ public class BytecodeClassFileEditor extends ClassFileEditor {
// boolean always = prefs.getBoolean(JadclipsePlugin.IGNORE_EXISTING);
boolean reuseBuf = false;
boolean always = false;
String origSrc = cf.getSource();
// have to check our mark since all line comments are stripped
// in debug align mode
if (origSrc == null
if (origSrc == null
|| always && !origSrc.startsWith(MARK)
|| (origSrc.startsWith(MARK) && (!reuseBuf || force))) {
if (sourceMapper == null)
sourceMapper = new BytecodeSourceMapper();
char[] src = sourceMapper.findSource(cf.getType());
if (src == null) {
src = new char[]{'\n', '/', '/', 'E', 'r', 'r', 'o', 'r', '!'};
}
// char[] markedSrc = new char[MARK_ARRAY.length + src.length];
// // next time we know this is decompiled source
// System.arraycopy(MARK_ARRAY, 0, markedSrc, 0, MARK_ARRAY.length);
// System.arraycopy(src, 0, markedSrc, MARK_ARRAY.length, src.length);
IBuffer buffer = getBufferManager().createBuffer(cf);
buffer.setContents(src);
getBufferManager().addBuffer(buffer);
......@@ -119,7 +120,7 @@ public class BytecodeClassFileEditor extends ClassFileEditor {
}
return opened;
} catch (Exception e) {
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
}
}
return false;
......@@ -137,7 +138,7 @@ public class BytecodeClassFileEditor extends ClassFileEditor {
IClassFileEditorInput input = (IClassFileEditorInput) getEditorInput();
result = sourceMapper.findElement(input.getClassFile().getType(), offset);
} catch (JavaModelException x) {
BytecodeOutlinePlugin.logError(x);
BytecodeOutlinePlugin.log(x, IStatus.ERROR);
}
}
return result;
......@@ -159,16 +160,18 @@ public class BytecodeClassFileEditor extends ClassFileEditor {
try {
ISourceRange range = null;
if ((reference instanceof IJavaElement) && containsDecompiled())
if ((reference instanceof IJavaElement) && containsDecompiled()) {
range = sourceMapper.getSourceRange((IJavaElement) reference);
else
} else {
range = reference.getSourceRange();
}
int offset = range.getOffset();
int length = range.getLength();
if (offset > -1 && length > 0)
if (offset > -1 && length > 0) {
setHighlightRange(offset, length, moveCursor);
}
if (moveCursor && (reference instanceof IMember)) {
IMember member = (IMember) reference;
......@@ -192,8 +195,9 @@ public class BytecodeClassFileEditor extends ClassFileEditor {
}
}
if (moveCursor)
if (moveCursor) {
resetHighlightRange();
}
}
}
package de.loskutov.bco.editors;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
......@@ -26,17 +23,13 @@ import org.eclipse.jdt.internal.compiler.env.IBinaryType;
import org.eclipse.jdt.internal.core.BinaryType;
import org.eclipse.jdt.internal.core.SourceMapper;
import de.loskutov.bco.BytecodeOutlinePlugin;
import de.loskutov.bco.asm.DecompiledClass;
import de.loskutov.bco.asm.DecompilerClassVisitor;
/**
* Yet "better" way to hook into JDT...
*
* using a source mapper enables us to use the outline!
*
* Sorry, still ne better news for debuging.
*
* Yet "better" way to hook into JDT... using a source mapper enables us to use the
* outline! Sorry, still ne better news for debuging.
* @author Jochen Klein
*/
public class BytecodeSourceMapper extends SourceMapper {
......@@ -51,7 +44,6 @@ public class BytecodeSourceMapper extends SourceMapper {
/*
* (non-Javadoc) R2.1 fix
*
* @see org.eclipse.jdt.internal.core.SourceMapper#findSource(org.eclipse.jdt.core.IType)
*/
public char[] findSource(IType type) {
......@@ -68,6 +60,7 @@ public class BytecodeSourceMapper extends SourceMapper {
try {
info = (IBinaryType) declType.getElementInfo();
} catch (JavaModelException e) {
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
return null;
}
if (info == null) {
......@@ -82,24 +75,29 @@ public class BytecodeSourceMapper extends SourceMapper {
Collection exceptions = new LinkedList();
IPackageFragment pkgFrag = type.getPackageFragment();
IPackageFragmentRoot root = (IPackageFragmentRoot) pkgFrag.getParent();
String pkg = type.getPackageFragment().getElementName().replace( '.', '/');
String pkg = type.getPackageFragment().getElementName().replace(
'.', '/');
String location = "\tDECOMPILED FROM: ";
String classFile = new String(info.getFileName());
int p = classFile.lastIndexOf('/');
classFile = classFile.substring(p + 1);
StringBuffer source = new StringBuffer();
if (root.isArchive()) {
String archivePath = getArchivePath(root);
location += archivePath;
decompileFromArchive( source, archivePath, pkg, classFile);
decompileFromArchive(source, archivePath, pkg, classFile);
} else {
try {
location += root.getUnderlyingResource().getLocation().toOSString() + "/" + pkg + "/" + classFile;
decompile( source, root.getUnderlyingResource().getLocation().toOSString(), pkg, classFile);
location += root.getUnderlyingResource().getLocation()
.toOSString()
+ "/" + pkg + "/" + classFile;
decompile(source, root.getUnderlyingResource().getLocation()
.toOSString(), pkg, classFile);
} catch (JavaModelException e) {
exceptions.add(e);
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
}
}
......@@ -111,58 +109,41 @@ public class BytecodeSourceMapper extends SourceMapper {
return source.toString().toCharArray();
}
public void decompile(StringBuffer source, String root, String packege, String className) {
try {
decompile( source, new FileInputStream( root+"/"+packege+"/"+className));
} catch (IOException e) {
source.append( e.toString());
e.printStackTrace();
}
}
public void decompileFromArchive(StringBuffer source, String archivePath, String packege, String className) {
try {
ZipFile zf = new ZipFile( archivePath);
// TODO implement better entry resolution (inner classes?)
ZipEntry ze = zf.getEntry( packege+"/"+className);
decompile(source, zf.getInputStream(ze));
} catch( IOException e) {
source.append( e.toString());
e.printStackTrace();
}
}
private void decompile( StringBuffer source, InputStream is) throws IOException {
boolean raw = true;
boolean asmify = false;
boolean verify = false;
DecompiledClass decompiledClass = DecompilerClassVisitor.getDecompiledClass(
is, null, null, raw, asmify, verify, null);
source.append( decompiledClass.getText());
}
private void logExceptions(Collection exceptions, StringBuffer buffer) {
buffer.append("\n\tCAUGHT EXCEPTIONS:\n");
if (exceptions == null || exceptions.size() == 0)
return; // nothing to do
StringWriter stackTraces = new StringWriter();
PrintWriter stackTracesP = new PrintWriter(stackTraces);
Iterator i = exceptions.iterator();
while (i.hasNext()) {
((Exception) i.next()).printStackTrace(stackTracesP);
stackTracesP.println("");
public void decompile(StringBuffer source, String root, String packege,
String className) {
try {
decompile(source, new FileInputStream(root + "/" + packege + "/"
+ className));
} catch (IOException e) {
source.append(e.toString());
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
}
}
stackTracesP.flush();
stackTracesP.close();
buffer.append(stackTraces.toString());
public void decompileFromArchive(StringBuffer source, String archivePath,
String packege, String className) {
try {
ZipFile zf = new ZipFile(archivePath);
// TODO implement better entry resolution (inner classes?)
ZipEntry ze = zf.getEntry(packege + "/" + className);
decompile(source, zf.getInputStream(ze));
} catch (IOException e) {
source.append(e.toString());
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
}
}
private void decompile(StringBuffer source, InputStream is)
throws IOException {
boolean raw = true;
boolean asmify = false;
boolean verify = false;
DecompiledClass decompiledClass = DecompilerClassVisitor
.getDecompiledClass(is, null, null, raw, asmify, verify, null);
source.append(decompiledClass.getText());
}
private String getArchivePath(IPackageFragmentRoot root) {
......@@ -170,14 +151,16 @@ public class BytecodeSourceMapper extends SourceMapper {
IResource resource;
try {
if ((resource = root.getUnderlyingResource()) != null)
if ((resource = root.getUnderlyingResource()) != null) {
// jar in workspace
archivePath = resource.getLocation().toOSString();
else
} else {
// external jar
archivePath = root.getPath().toOSString();
}
} catch (JavaModelException e) {
throw new RuntimeException("Unexpected Java model exception: " + e.toString());
throw new RuntimeException("Unexpected Java model exception: "
+ e.toString());
}
return archivePath;
}
......@@ -187,7 +170,7 @@ public class BytecodeSourceMapper extends SourceMapper {
* <code>elt</elt>'s children (including <code>elt</code> itself)
* which has a source range that encloses <code>position</code>
* according to <code>mapper</code>.
*
*
* Code mostly taken from 'org.eclipse.jdt.internal.core.ClassFile'
*/
protected IJavaElement findElement(IJavaElement elt, int position) {
......@@ -205,7 +188,8 @@ public class BytecodeSourceMapper extends SourceMapper {
return match;
}
}
} catch (JavaModelException npe) {
} catch (JavaModelException e) {
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
}
}
return elt;
......@@ -215,10 +199,10 @@ public class BytecodeSourceMapper extends SourceMapper {
* @see org.eclipse.jdt.internal.core.SourceMapper#mapSource(IType, char[])
*/
public void mapSource(IType type, char[] contents, boolean force) {
if (force)
if (force) {
fSourceRanges.remove(type);
}
super.mapSource(type, contents);
}
}
......@@ -28,6 +28,7 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.IClasspathEntry;
......@@ -619,7 +620,10 @@ public class JdtUtils {
try {
is = new FileInputStream(classPath);
} catch (FileNotFoundException e) {
BytecodeOutlinePlugin.logError(e);
// if autobuild is disabled, we get tons of this errors.
// but I think we cannot ignore them, therefore WARNING and not
// ERROR status
BytecodeOutlinePlugin.log(e, IStatus.WARNING);
}
}
return is;
......@@ -646,7 +650,7 @@ public class JdtUtils {
underlyingResource = classFile.getResource();
}
} catch (JavaModelException e) {
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
return null;
}
IPath rawLocation = underlyingResource.getRawLocation();
......@@ -658,7 +662,7 @@ public class JdtUtils {
try {
return new FileInputStream(rawLocation.toOSString());
} catch (FileNotFoundException e) {
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
}
return null;
}
......@@ -692,7 +696,7 @@ public class JdtUtils {
try {
jar = new JarFile(path.toOSString());
} catch (IOException e) {
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
return null;
}
String fullClassName = getFullBytecodeName(classFile);
......@@ -704,7 +708,7 @@ public class JdtUtils {
try {
return jar.getInputStream(jarEntry);
} catch (IOException e) {
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
}
}
return null;
......@@ -869,7 +873,7 @@ public class JdtUtils {
defaultOutputLocation = javaProject.getOutputLocation();
} catch (JavaModelException e) {
// don't show message to user
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
}
if (paths == null) {
return JdtUtils.class.getClassLoader();
......@@ -904,7 +908,7 @@ public class JdtUtils {
urls.add(p.toFile().toURL());
} catch (MalformedURLException e) {
// don't show message to user
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
}
}
if (urls.isEmpty()) {
......
......@@ -17,6 +17,7 @@ import java.util.Map;
import java.util.ResourceBundle;
import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IInitializer;
import org.eclipse.jdt.core.IJavaElement;
......@@ -736,7 +737,7 @@ public class BytecodeOutlineView extends ViewPart {
protected void handleSelectionChanged(IWorkbenchPart part,
ISelection selection) {
if (!isLinkedWithEditor() || !isActive()
if (!isLinkedWithEditor() || !isActive() || !isVisible
|| !(part instanceof IEditorPart)) {
return;
}
......@@ -983,7 +984,7 @@ public class BytecodeOutlineView extends ViewPart {
updateVerifierControl( decompiledLine);
}
} catch (Exception e) {
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
}
}
......@@ -1079,7 +1080,7 @@ public class BytecodeOutlineView extends ViewPart {
}
} catch (JavaModelException e) {
// this is compilation problem - don't show the message
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.WARNING);
}
} else if (childEl.getElementType() == IJavaElement.METHOD) {
IMethod iMethod = (IMethod) childEl;
......@@ -1087,7 +1088,7 @@ public class BytecodeOutlineView extends ViewPart {
methodName = JdtUtils.createMethodSignature(iMethod);
} catch (JavaModelException e) {
// this is compilation problem - don't show the message
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.WARNING);
}
}
}
......@@ -1105,14 +1106,14 @@ public class BytecodeOutlineView extends ViewPart {
}
} catch (JavaModelException e1) {
// this is compilation problem - don't show the message
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.logError(e1);
BytecodeOutlinePlugin.log(e, IStatus.ERROR);
BytecodeOutlinePlugin.log(e1, IStatus.WARNING);
}
} finally {
try {
is.close();
} catch (IOException e) {
BytecodeOutlinePlugin.logError(e);
BytecodeOutlinePlugin.log(e, IStatus.WARNING);
}
}
return decompiledClass;
......
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