diff --git a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/JavaDecompilerPlugin.java b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/JavaDecompilerPlugin.java index 4ad7ca09..75cc5177 100644 --- a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/JavaDecompilerPlugin.java +++ b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/JavaDecompilerPlugin.java @@ -75,15 +75,30 @@ public static JavaDecompilerPlugin getDefault() { } public static void logError(Throwable t, String message) { - JavaDecompilerPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, JavaDecompilerConstants.PLUGIN_ID, 0, message, t)); + JavaDecompilerPlugin.getDefault().getLog() + .log(new Status(IStatus.ERROR, JavaDecompilerConstants.PLUGIN_ID, 0, message, t)); + } + + public static void logWarn(Throwable t, String message) { + JavaDecompilerPlugin.getDefault().getLog() + .log(new Status(IStatus.WARNING, JavaDecompilerConstants.PLUGIN_ID, 0, message, t)); } public static void logInfo(String message) { - JavaDecompilerPlugin.getDefault().getLog().log(new Status(IStatus.INFO, JavaDecompilerConstants.PLUGIN_ID, 0, message, null)); + JavaDecompilerPlugin.getDefault().getLog() + .log(new Status(IStatus.INFO, JavaDecompilerConstants.PLUGIN_ID, 0, message, null)); } + /** + * + * @param severity severity constant see {@link IStatus#INFO} + * {@link IStatus#WARNING} {@link IStatus#ERROR} + * @param t + * @param message + */ public static void log(int severity, Throwable t, String message) { - JavaDecompilerPlugin.getDefault().getLog().log(new Status(severity, JavaDecompilerConstants.PLUGIN_ID, 0, message, t)); + JavaDecompilerPlugin.getDefault().getLog() + .log(new Status(severity, JavaDecompilerConstants.PLUGIN_ID, 0, message, t)); } public static ImageDescriptor getImageDescriptor(String path) { @@ -130,7 +145,8 @@ protected void initializeDefaultPreferences(IPreferenceStore store) { store.setDefault(JavaDecompilerConstants.CLASS_FILE_ATTR_SHOW_VARIABLE_TABLE, false); store.setDefault(JavaDecompilerConstants.CLASS_FILE_ATTR_SHOW_EXCEPTION_TABLE, false); store.setDefault(JavaDecompilerConstants.CLASS_FILE_ATTR_SHOW_MAXS, false); - store.setDefault(JavaDecompilerConstants.BRANCH_TARGET_ADDRESS_RENDERING, JavaDecompilerConstants.BRANCH_TARGET_ADDRESS_RELATIVE); + store.setDefault(JavaDecompilerConstants.BRANCH_TARGET_ADDRESS_RENDERING, + JavaDecompilerConstants.BRANCH_TARGET_ADDRESS_RELATIVE); store.setDefault(JavaDecompilerConstants.CLASS_FILE_ATTR_RENDER_TRYCATCH_BLOCKS, true); store.setDefault(JavaDecompilerConstants.CLASS_FILE_ATTR_SHOW_SOURCE_LINE_NUMBERS, true); store.setDefault(JavaDecompilerConstants.CLASS_FILE_ATTR_SHOW_MAXS, false); diff --git a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/UIUtil.java b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/UIUtil.java index 2be73a3c..4d491a0d 100644 --- a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/UIUtil.java +++ b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/UIUtil.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; @@ -92,18 +93,18 @@ public void run() { } public static JavaDecompilerClassFileEditor getActiveDecompilerEditor() { - final JavaDecompilerClassFileEditor[] editors = new JavaDecompilerClassFileEditor[1]; + final AtomicReference editors = new AtomicReference<>(); Display.getDefault().syncExec(new Runnable() { @Override public void run() { IWorkbenchPart editor = getActiveEditor(true); if (editor instanceof JavaDecompilerClassFileEditor) { - editors[0] = (JavaDecompilerClassFileEditor) editor; + editors.set((JavaDecompilerClassFileEditor) editor); } } }); - return editors[0]; + return editors.get(); } public static List getActiveSelection() { @@ -116,38 +117,33 @@ public static List getActiveSelection() { } public static String getActivePerspectiveId() { - final String[] ids = new String[1]; + final AtomicReference ids = new AtomicReference<>(); Display.getDefault().syncExec(new Runnable() { @Override public void run() { IWorkbench wb = PlatformUI.getWorkbench(); if (wb == null) { - ids[0] = null; return; } IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); if (win == null) { - ids[0] = null; return; } IWorkbenchPage page = win.getActivePage(); if (page == null) { - ids[0] = null; return; } IPerspectiveDescriptor perspective = page.getPerspective(); if (perspective == null) { - ids[0] = null; return; } - ids[0] = perspective.getId(); - + ids.set(perspective.getId()); } }); - return ids[0]; + return ids.get(); } public static boolean isDebug() { @@ -231,8 +227,7 @@ public static boolean isOpenClassEditor() { IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); if (windows != null) { - for (int i = 0; i < windows.length; i++) { - IWorkbenchWindow window = windows[i]; + for (IWorkbenchWindow window : windows) { for (IWorkbenchPage pg : window.getPages()) { if (pg == null) { continue; @@ -260,8 +255,9 @@ public static List getExportSelections() { return selectedJars; } - if (selectedJars.size() > 1) + if (selectedJars.size() > 1) { return null; + } final List selectedPackages = getSelectedElements(window.getSelectionService(), IPackageFragment.class); final List selectedClasses = getSelectedElements(window.getSelectionService(), IClassFile.class); @@ -278,7 +274,8 @@ public static boolean isPackageFlat() { try { IWorkbenchPart view = getActiveEditor(true); if (view != null) { - if (view.getSite().getId().equals("org.eclipse.ui.navigator.ProjectExplorer")) //$NON-NLS-1$ + String id = view.getSite().getId(); + if (id.equals("org.eclipse.ui.navigator.ProjectExplorer")) //$NON-NLS-1$ { CommonNavigator explorer = (CommonNavigator) view; Field field = CommonNavigator.class.getDeclaredField("commonManager"); //$NON-NLS-1$ @@ -294,10 +291,12 @@ public static boolean isPackageFlat() { isFlat = model.getBooleanProperty(Values.IS_LAYOUT_FLAT); } } - } else if (view.getSite().getId().equals("org.eclipse.jdt.ui.PackageExplorer")) //$NON-NLS-1$ + } else if (id.equals("org.eclipse.jdt.ui.PackageExplorer")) //$NON-NLS-1$ { PackageExplorerPart explorer = (PackageExplorerPart) view; isFlat = explorer.isFlatLayout(); + } else { + JavaDecompilerPlugin.logWarn(null, "isPackageFlat: unsupported view: " + id); } } } catch (Exception e) { @@ -317,8 +316,15 @@ public static String getPathLocation(IPath path) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IResource resource = root.findMember(path); - if (resource != null) { - return resource.getLocation().toOSString(); + if (resource == null) { + JavaDecompilerPlugin.logWarn(null, "Failed to find member of path " + path); + } else { + IPath location = resource.getLocation(); + if (location == null) { + JavaDecompilerPlugin.logWarn(null, "Failed to get location of path " + resource); + } else { + return location.toOSString(); + } } return null; }