Skip to content

Commit 3218e9f

Browse files
author
emmanue1
committed
Fix bug in CopyQualifiedNameAction
1 parent 1614a9a commit 3218e9f

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

services/src/main/java/org/jd/gui/service/actions/CopyQualifiedNameContextualActionsFactory.java

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,42 +45,46 @@ public CopyQualifiedNameAction(API api, Container.Entry entry, String fragment)
4545
}
4646

4747
public void actionPerformed(ActionEvent e) {
48-
if (fragment != null) {
49-
TypeFactory typeFactory = api.getTypeFactory(entry);
50-
Type type = (typeFactory == null) ? null : typeFactory.make(api, entry, fragment);
48+
TypeFactory typeFactory = api.getTypeFactory(entry);
49+
50+
if (typeFactory != null) {
51+
Type type = typeFactory.make(api, entry, fragment);
5152

5253
if (type != null) {
5354
StringBuilder sb = new StringBuilder(type.getDisplayPackageName());
54-
int dashIndex = fragment.indexOf('-');
5555

5656
if (sb.length() > 0) {
5757
sb.append('.');
5858
}
5959

6060
sb.append(type.getDisplayTypeName());
6161

62-
if (dashIndex != -1) {
63-
int lastDashIndex = fragment.lastIndexOf('-');
64-
65-
if (dashIndex == lastDashIndex) {
66-
// See jd.gui.api.feature.UriOpenable
67-
throw new InvalidFormatException("fragment: " + fragment);
68-
} else {
69-
String name = fragment.substring(dashIndex + 1, lastDashIndex);
70-
String descriptor = fragment.substring(lastDashIndex + 1);
71-
72-
if (descriptor.startsWith("(")) {
73-
for (Type.Method method : type.getMethods()) {
74-
if (method.getName().equals(name) && method.getDescriptor().equals(descriptor)) {
75-
sb.append('.').append(method.getDisplayName());
76-
break;
77-
}
78-
}
62+
if (fragment != null) {
63+
int dashIndex = fragment.indexOf('-');
64+
65+
if (dashIndex != -1) {
66+
int lastDashIndex = fragment.lastIndexOf('-');
67+
68+
if (dashIndex == lastDashIndex) {
69+
// See jd.gui.api.feature.UriOpenable
70+
throw new InvalidFormatException("fragment: " + fragment);
7971
} else {
80-
for (Type.Field field : type.getFields()) {
81-
if (field.getName().equals(name) && field.getDescriptor().equals(descriptor)) {
82-
sb.append('.').append(field.getDisplayName());
83-
break;
72+
String name = fragment.substring(dashIndex + 1, lastDashIndex);
73+
String descriptor = fragment.substring(lastDashIndex + 1);
74+
75+
if (descriptor.startsWith("(")) {
76+
for (Type.Method method : type.getMethods()) {
77+
if (method.getName().equals(name) && method.getDescriptor().equals(descriptor)) {
78+
sb.append('.').append(method.getDisplayName());
79+
break;
80+
}
81+
}
82+
} else {
83+
for (Type.Field field : type.getFields()) {
84+
if (field.getName().equals(name) && field.getDescriptor().equals(descriptor)) {
85+
sb.append('.').append(field.getDisplayName());
86+
break;
87+
}
8488
}
8589
}
8690
}
@@ -92,9 +96,16 @@ public void actionPerformed(ActionEvent e) {
9296
}
9397
}
9498

95-
// Copy path of entry
96-
String path = new File(entry.getUri()).getAbsolutePath();
97-
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(path), null);
99+
// Create qualified name from URI
100+
String path = entry.getUri().getPath();
101+
String rootPath = entry.getContainer().getRoot().getUri().getPath();
102+
String qualifiedName = path.substring(rootPath.length()).replace('/', '.');
103+
104+
if (qualifiedName.endsWith(".class")) {
105+
qualifiedName = qualifiedName.substring(0, qualifiedName.length()-6);
106+
}
107+
108+
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(qualifiedName), null);
98109
}
99110
}
100111
}

0 commit comments

Comments
 (0)