Skip to content

Commit

Permalink
Fixes a NPE thrown by 'Copy Qualified Name' action
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanue1 committed Jul 2, 2015
1 parent 62c3551 commit 121e8da
Showing 1 changed file with 37 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 121e8da

Please sign in to comment.