-
Notifications
You must be signed in to change notification settings - Fork 3
/
OpenSourceFileQuery.java
80 lines (71 loc) · 3.05 KB
/
OpenSourceFileQuery.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*******************************************************************************
* Copyright (c) 2008, 2023 SAP AG and IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SAP AG - initial API and implementation
* IBM Corporation - get display for RAP
*******************************************************************************/
package org.eclipse.mat.jdt;
import org.eclipse.mat.query.IContextObject;
import org.eclipse.mat.query.IContextObjectSet;
import org.eclipse.mat.query.IQuery;
import org.eclipse.mat.query.IResult;
import org.eclipse.mat.query.annotations.Argument;
import org.eclipse.mat.query.annotations.CommandName;
import org.eclipse.mat.query.annotations.HelpUrl;
import org.eclipse.mat.query.annotations.Icon;
import org.eclipse.mat.snapshot.ISnapshot;
import org.eclipse.mat.snapshot.model.IClass;
import org.eclipse.mat.snapshot.model.IObject;
import org.eclipse.mat.util.IProgressListener;
import org.eclipse.swt.widgets.Display;
@CommandName("open_source_file")
@Icon("/icons/open_source_file.gif") // Icon from org.eclipse.jdt.ui/icons/full/obj16/jcu_obj.gif
@HelpUrl("/org.eclipse.mat.ui.help/reference/inspections/open_source_file.html")
public class OpenSourceFileQuery implements IQuery
{
@Argument
public ISnapshot snapshot;
@Argument
public IContextObject subject;
@Argument
public Display display;
public IResult execute(IProgressListener listener) throws Exception
{
int objectId = subject.getObjectId();
if (objectId < 0 && subject instanceof IContextObjectSet)
{
IContextObjectSet set = (IContextObjectSet) subject;
int[] objectIds = set.getObjectIds();
if (objectIds.length > 0)
objectId = objectIds[0];
}
if (objectId < 0)
throw new IProgressListener.OperationCanceledException();
IObject obj = snapshot.getObject(objectId);
String className = obj instanceof IClass ? ((IClass) obj).getName() : obj.getClazz().getName();
String methodName = null;
String signature = null;
int i = className.lastIndexOf('.');
int par = className.indexOf('(', i);
if (i >= 0 && par >= 0)
{
// Remove the method name from DTFJ methods as classes
int sig = className.indexOf(' ');
methodName = className.substring(i + 1, par);
if (sig >= 0)
signature = className.substring(par, sig);
else
signature = className.substring(par);
className = className.substring(0, i);
}
new OpenSourceFileJob(className, methodName, signature, display).schedule();
throw new IProgressListener.OperationCanceledException();
}
}