From 121e8da60165113ef1a988218884abf1cb88c47f Mon Sep 17 00:00:00 2001 From: emmanue1 Date: Thu, 2 Jul 2015 22:10:06 +0200 Subject: [PATCH] Fixes a NPE thrown by 'Copy Qualified Name' action --- ...alifiedNameContextualActionsFactory.groovy | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/services/src/main/groovy/org/jd/gui/service/actions/CopyQualifiedNameContextualActionsFactory.groovy b/services/src/main/groovy/org/jd/gui/service/actions/CopyQualifiedNameContextualActionsFactory.groovy index bc28980e..61e1b8c1 100644 --- a/services/src/main/groovy/org/jd/gui/service/actions/CopyQualifiedNameContextualActionsFactory.groovy +++ b/services/src/main/groovy/org/jd/gui/service/actions/CopyQualifiedNameContextualActionsFactory.groovy @@ -41,52 +41,55 @@ class CopyQualifiedNameContextualActionsFactory implements ContextualActionsFact } void actionPerformed(ActionEvent e) { - def type = api.getTypeFactory(entry)?.make(api, entry, fragment) + if (fragment) { + def type = api.getTypeFactory(entry)?.make(api, entry, fragment) - if (type) { - def sb = new StringBuffer(type.displayPackageName) - int dashIndex = fragment.indexOf('-') + if (type) { + def sb = new StringBuffer(type.displayPackageName) + int dashIndex = fragment.indexOf('-') - if (sb.length() > 0) { - sb.append('.') - } - - sb.append(type.displayTypeName) + if (sb.length() > 0) { + sb.append('.') + } - if (dashIndex != -1) { - int lastDashIndex = fragment.lastIndexOf('-') + sb.append(type.displayTypeName) - if (dashIndex == lastDashIndex) { - // See jd.gui.api.feature.UriOpenable - throw new InvalidFormatException('fragment: ' + fragment) - } else { - def name = fragment.substring(dashIndex+1, lastDashIndex) - def descriptor = fragment.substring(lastDashIndex+1) + if (dashIndex != -1) { + int lastDashIndex = fragment.lastIndexOf('-') - if (descriptor.startsWith('(')) { - for (def method : type.methods) { - if (method.name.equals(name) && method.descriptor.equals(descriptor)) { - sb.append('.').append(method.displayName) - break - } - } + if (dashIndex == lastDashIndex) { + // See jd.gui.api.feature.UriOpenable + throw new InvalidFormatException('fragment: ' + fragment) } else { - for (def field : type.fields) { - if (field.name.equals(name) && field.descriptor.equals(descriptor)) { - sb.append('.').append(field.displayName) - break + def name = fragment.substring(dashIndex + 1, lastDashIndex) + def descriptor = fragment.substring(lastDashIndex + 1) + + if (descriptor.startsWith('(')) { + for (def method : type.methods) { + if (method.name.equals(name) && method.descriptor.equals(descriptor)) { + sb.append('.').append(method.displayName) + break + } + } + } else { + for (def field : type.fields) { + if (field.name.equals(name) && field.descriptor.equals(descriptor)) { + sb.append('.').append(field.displayName) + break + } } } } } - } - Toolkit.defaultToolkit.systemClipboard.setContents(new StringSelection(sb.toString()), null) - } else { - // Copy path of entry - def path = new File(entry.uri).absolutePath - Toolkit.defaultToolkit.systemClipboard.setContents(new StringSelection(path), null) + Toolkit.defaultToolkit.systemClipboard.setContents(new StringSelection(sb.toString()), null) + return + } } + + // Copy path of entry + def path = new File(entry.uri).absolutePath + Toolkit.defaultToolkit.systemClipboard.setContents(new StringSelection(path), null) } } }