From d3294fc32c014a3965fadb616f593acab59363ff Mon Sep 17 00:00:00 2001 From: "Jan S." Date: Thu, 13 Jun 2024 21:34:28 +0200 Subject: [PATCH] fix problem where "Could not use {} for decompilation" error messages increase with every usage --- .../decompiler/editor/BaseDecompiler.java | 4 +++ .../editor/BaseDecompilerSourceMapper.java | 30 +++++++++---------- .../editor/DecompilerSourceMapper.java | 2 +- .../decompiler/editor/IDecompiler.java | 2 ++ .../editor/JavaDecompilerClassFileEditor.java | 2 +- .../sf/feeling/decompiler/util/ClassUtil.java | 5 +++- .../decompiler/util/DecompileUtil.java | 5 ++-- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/editor/BaseDecompiler.java b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/editor/BaseDecompiler.java index 2de00391..145a0bd2 100644 --- a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/editor/BaseDecompiler.java +++ b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/editor/BaseDecompiler.java @@ -16,4 +16,8 @@ public List getExceptions() { return exceptions; } + @Override + public void clearExceptions() { + exceptions.clear(); + } } diff --git a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/editor/BaseDecompilerSourceMapper.java b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/editor/BaseDecompilerSourceMapper.java index fb48fb89..7b78b948 100644 --- a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/editor/BaseDecompilerSourceMapper.java +++ b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/editor/BaseDecompilerSourceMapper.java @@ -158,7 +158,7 @@ public char[] findSource(IType type, IBinaryType info) { classLocation = ""; //$NON-NLS-1$ - usedDecompiler = decompile(null, type, exceptions, root, className); + usedDecompiler = decompile(type, exceptions, root, className); if (noDecompiledSourceCodeAvailable(usedDecompiler)) { if (usedDecompiler == null) { @@ -260,9 +260,12 @@ private boolean fromInput(IType type) { return false; } - private IDecompiler decompile(IDecompiler decompiler, IType type, Collection exceptions, - IPackageFragmentRoot root, String className) { - IDecompiler result = decompiler; + private IDecompiler decompile(IType type, Collection exceptions, IPackageFragmentRoot root, + String className) { + + originalDecompiler.clearExceptions(); + + IDecompiler result = null; String pkg = type.getPackageFragment().getElementName().replace('.', '/'); @@ -277,13 +280,11 @@ private IDecompiler decompile(IDecompiler decompiler, IType type, Collection getExceptions(); + void clearExceptions(); + /** * @return decompilation log specific to physical decompiler */ diff --git a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/editor/JavaDecompilerClassFileEditor.java b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/editor/JavaDecompilerClassFileEditor.java index bbe6295f..341b8d50 100644 --- a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/editor/JavaDecompilerClassFileEditor.java +++ b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/editor/JavaDecompilerClassFileEditor.java @@ -324,7 +324,7 @@ protected void doSetInput(IEditorInput input) throws CoreException { FileStoreEditorInput storeInput = (FileStoreEditorInput) input; IPreferenceStore prefs = JavaDecompilerPlugin.getDefault().getPreferenceStore(); String decompilerType = prefs.getString(JavaDecompilerConstants.DECOMPILER_TYPE); - String source = DecompileUtil.decompiler(storeInput, decompilerType); + String source = DecompileUtil.decompileInput(storeInput, decompilerType); if (source != null) { String packageName = DecompileUtil.getPackageName(source); diff --git a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/ClassUtil.java b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/ClassUtil.java index ddf0d2a3..fe17a626 100644 --- a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/ClassUtil.java +++ b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/ClassUtil.java @@ -41,6 +41,7 @@ public static IDecompiler checkAvailableDecompiler(IDecompiler decompiler, Input boolean debug = isDebug(); IDecompiler defaultDecompiler = getDebugDecompiler(classLevel, debug); + defaultDecompiler.clearExceptions(); if (decompiler.supportLevel(classLevel)) { if (debug) { @@ -128,7 +129,9 @@ public static IDecompiler getDebugDecompiler(int level, boolean debug) { if (!defaultDecompiler.isPresent()) { return null; } - return defaultDecompiler.get().getDecompiler(); + IDecompiler decompiler = defaultDecompiler.get().getDecompiler(); + decompiler.clearExceptions(); + return decompiler; } return null; } diff --git a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/DecompileUtil.java b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/DecompileUtil.java index 475e254f..c319a980 100644 --- a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/DecompileUtil.java +++ b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/DecompileUtil.java @@ -47,11 +47,10 @@ public static String decompile(IClassFile cf, String type, boolean always, boole return origSrc; } - public static String decompiler(FileStoreEditorInput input, String decompilerType) { + public static String decompileInput(FileStoreEditorInput input, String decompilerType) { DecompilerSourceMapper sourceMapper = SourceMapperFactory.getSourceMapper(decompilerType); File file = new File(input.getURI()); - return sourceMapper.decompile(decompilerType, file); - + return sourceMapper.decompileFile(decompilerType, file); } public static String getPackageName(String source) {