Skip to content

Commit 7ca0aa6

Browse files
committed
done
1 parent 7a337ab commit 7ca0aa6

File tree

20 files changed

+323
-149
lines changed

20 files changed

+323
-149
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
package com.albertoventurini.graphdbplugin.jetbrains.ui.console.graph;
2-
3-
import com.intellij.openapi.project.Project;
4-
import com.intellij.psi.PsiMethod;
1+
package com.albertoventurini.graphdbplugin.database.neo4j.bytecodedl;
52

63
/**
74
* @author daozhe@alibaba-inc.com
8-
* @date 2023/12/3 16:05
5+
* @date 2023/12/10 09:53
96
*/
10-
public class JavaInvokeInsn {
11-
private JavaMethodSignature callerSignature;
7+
public class InvocationSignature {
8+
private String callerSignature;
129
private String callee;
1310
private Integer index;
1411

15-
public JavaInvokeInsn(String insn){
12+
public InvocationSignature(String insn){
1613
String[] parts = insn.split("/");
1714
if (parts.length != 3) {
1815
throw new IllegalArgumentException("Invalid instruction format");
1916
}
2017

21-
this.callerSignature = new JavaMethodSignature(parts[0]);
18+
this.callerSignature = parts[0];
2219
this.callee = parts[1].replace("$", ".");
2320

2421
try {
@@ -28,8 +25,13 @@ public JavaInvokeInsn(String insn){
2825
}
2926
}
3027

31-
public PsiMethod getCaller(Project project){
32-
return this.callerSignature.getMethod(project);
28+
public MethodSignature getCallerMethodSignature(){
29+
MethodSignature methodSignature = new MethodSignature(this.callerSignature);
30+
return methodSignature;
31+
}
32+
33+
public String getCallerSignature(){
34+
return this.callerSignature;
3335
}
3436

3537
public String getCallee(){
@@ -40,5 +42,9 @@ public String getCalleeMethodName(){
4042
return this.callee.substring(callee.lastIndexOf(".")+1);
4143
}
4244

45+
public Integer getIndex(){
46+
return this.index;
47+
}
48+
4349

4450
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.albertoventurini.graphdbplugin.database.neo4j.bytecodedl;
2+
3+
import java.util.Arrays;
4+
import java.util.Collections;
5+
import java.util.List;
6+
import java.util.regex.Matcher;
7+
import java.util.regex.Pattern;
8+
import java.util.stream.Collectors;
9+
10+
/**
11+
* @author daozhe@alibaba-inc.com
12+
* @date 2023/12/10 09:45
13+
*/
14+
public class MethodSignature {
15+
private String signature;
16+
private String className;
17+
private String methodName;
18+
private final List<String> paramTypes;
19+
20+
private static final Pattern SIGNATURE_PATTERN = Pattern.compile(
21+
"^<([^:]+):\\s*(\\S+)\\s+([^\\(]+)\\(([^\\)]*)\\)>$"
22+
);
23+
24+
public MethodSignature(String signature) {
25+
this.signature = signature;
26+
// 假设输入的格式为 <org.apache.logging.log4j.core.filter.Filterable: boolean isFiltered(org.apache.logging.log4j.core.LogEvent)>
27+
Matcher matcher = SIGNATURE_PATTERN.matcher(signature);
28+
if (!matcher.matches()) {
29+
throw new IllegalArgumentException("Invalid method signature format");
30+
}
31+
32+
this.className = matcher.group(1).trim().replace("$", ".");
33+
// Group 2 is the return type which is not used in this implementation
34+
this.methodName = matcher.group(3).trim();
35+
36+
if (this.methodName.equals("<init>")) {
37+
this.methodName = className.substring(className.lastIndexOf(".") + 1);
38+
}
39+
40+
String params = matcher.group(4).trim();
41+
this.paramTypes = params.isEmpty() ? Collections.emptyList() : Arrays.stream(params.split(",")).map(param ->param.replace("$", ".")).collect(Collectors.toList());
42+
}
43+
44+
public String getClassName() {
45+
return this.className;
46+
}
47+
48+
public String getShortClassName(){
49+
return this.className.substring(this.className.lastIndexOf(".") + 1, this.className.length());
50+
}
51+
52+
public String getMethodName() {
53+
return this.methodName;
54+
}
55+
56+
public List<String> getParamTypes() {
57+
return this.paramTypes;
58+
}
59+
}

graph-database-plugin/src/main/resources/META-INF/plugin.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<idea-plugin>
2-
<id>com.albertoventurini.jetbrains.graphdbplugin</id>
3-
<name>Graph Database</name>
2+
<!-- <id>com.albertoventurini.jetbrains.graphdbplugin</id>-->
3+
<id>com.bytecodedl.jetbrains.graphdbplugin</id>
4+
<name>ByteCodeDL Graph Database Plugin</name>
45
<!-- Version is automatically replaced by the patchPluginXml task -->
56
<version>9.9.9</version>
6-
<vendor email="aventurini@gmail.com" url="https://github.com/albertoventurini/graphdb-intellij-plugin">Alberto Venturini</vendor>
7+
<vendor email="bytecodedl@gmail.com" url="https://github.com/bytecodedl/graphdb-intellij-plugin">bytecodedl</vendor>
78

89
<description><![CDATA[
910
<p>
@@ -138,7 +139,7 @@
138139
<applicationConfigurable groupId="tools"
139140
instance="com.albertoventurini.graphdbplugin.jetbrains.configuration.GraphDatabaseConfiguration"/>
140141
<!-- Update notification -->
141-
<postStartupActivity implementation="com.albertoventurini.graphdbplugin.jetbrains.component.updater.PluginUpdateActivity" />
142+
<!-- <postStartupActivity implementation="com.albertoventurini.graphdbplugin.jetbrains.component.updater.PluginUpdateActivity" />-->
142143
<!-- Cypher -->
143144
<fileType
144145
name="Cypher"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.albertoventurini.graphdbplugin.jetbrains.ui.console.graph;
2+
3+
import com.albertoventurini.graphdbplugin.database.api.data.GraphRelationship;
4+
import com.albertoventurini.graphdbplugin.jetbrains.actions.execute.ExecuteQueryPayload;
5+
import com.albertoventurini.graphdbplugin.jetbrains.component.datasource.state.DataSourceApi;
6+
import com.albertoventurini.graphdbplugin.jetbrains.database.QueryExecutionService;
7+
import com.google.common.collect.ImmutableMap;
8+
import com.intellij.openapi.actionSystem.AnAction;
9+
import com.intellij.openapi.actionSystem.AnActionEvent;
10+
import com.intellij.openapi.project.Project;
11+
import org.jetbrains.annotations.NotNull;
12+
13+
import javax.swing.*;
14+
15+
/**
16+
* @author daozhe@alibaba-inc.com
17+
* @date 2023/12/10 16:33
18+
*/
19+
public abstract class AbstractRelationshipCurdAction extends AnAction {
20+
protected DataSourceApi dataSource;
21+
protected GraphRelationship relationship;
22+
23+
AbstractRelationshipCurdAction(String title, String description, Icon icon, DataSourceApi dataSource, GraphRelationship relationship) {
24+
super(title, description, icon);
25+
this.dataSource = dataSource;
26+
this.relationship = relationship;
27+
}
28+
29+
30+
@Override
31+
public void actionPerformed(@NotNull AnActionEvent e) {
32+
Project project = getEventProject(e);
33+
if (project != null) {
34+
QueryExecutionService service = new QueryExecutionService(project, project.getMessageBus());
35+
36+
service.executeQuery(dataSource, this.getQuery());
37+
}
38+
}
39+
40+
public abstract ExecuteQueryPayload getQuery();
41+
}

ui/jetbrains/src/main/java/com/albertoventurini/graphdbplugin/jetbrains/ui/console/graph/EdgeNavigateAction.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.albertoventurini.graphdbplugin.jetbrains.ui.console.graph;
22

3-
import com.albertoventurini.graphdbplugin.database.api.data.GraphNode;
43
import com.albertoventurini.graphdbplugin.database.api.data.GraphRelationship;
54
import com.intellij.ide.SelectInEditorManager;
65
import com.intellij.openapi.project.Project;
6+
import com.intellij.openapi.vfs.VirtualFile;
77
import com.intellij.psi.*;
88
import com.intellij.psi.util.PsiTreeUtil;
99
import com.intellij.usageView.UsageInfo;
@@ -23,13 +23,13 @@ public EdgeNavigateAction(Project project){
2323
}
2424

2525
public void navigateToInvocation(GraphRelationship relationship, VisualItem item, MouseEvent e){
26-
JavaInvokeInsn invocation = getJavaInvokeInsn(relationship);
26+
PsiInvocationSignature invocation = getJavaInvokeInsn(relationship);
2727
PsiMethod method = getPsiMethod(invocation);
2828
PsiCallExpression methodCall = getPsiMethodCall(invocation, method);
29-
navigate(methodCall);
29+
navigate(methodCall, method.getContainingFile().getVirtualFile());
3030
}
3131

32-
public PsiCallExpression getPsiMethodCall(JavaInvokeInsn invocation, PsiMethod method){
32+
public PsiCallExpression getPsiMethodCall(PsiInvocationSignature invocation, PsiMethod method){
3333
PsiMethod psiMethod = null;
3434
if (method.getContainingFile().getName().endsWith(".java")){
3535
psiMethod = method;
@@ -41,14 +41,16 @@ public PsiCallExpression getPsiMethodCall(JavaInvokeInsn invocation, PsiMethod m
4141
return callExpressions.stream().filter(call -> matchInvocation(call, invocation)).findFirst().get();
4242
}
4343

44-
public PsiCallExpression getPsiMethodCall1(JavaInvokeInsn invocation, PsiMethod method){
44+
public PsiCallExpression getPsiMethodCall1(PsiInvocationSignature invocation, PsiMethod method){
4545
UsageInfo usage = new UsageInfo(method);
4646
PsiMethod psiMethod = PsiTreeUtil.getParentOfType(usage.getFile().findElementAt(usage.getSegment().getEndOffset()), PsiMethod.class);
4747
Collection<PsiCallExpression> callExpressions = PsiTreeUtil.collectElementsOfType(psiMethod, PsiCallExpression.class);
48+
// only find the first match ignore the index
49+
// TODO: consider the index
4850
return callExpressions.stream().filter(call -> matchInvocation(call, invocation)).findFirst().get();
4951
}
5052

51-
public boolean matchInvocation(PsiCallExpression call, JavaInvokeInsn invocation){
53+
public boolean matchInvocation(PsiCallExpression call, PsiInvocationSignature invocation){
5254
if (call instanceof PsiMethodCallExpression) {
5355
String fqn = getFqn((PsiMethodCallExpression) call);
5456
return invocation.getCallee().endsWith(fqn);
@@ -87,22 +89,22 @@ public String getFqn(PsiMethodCallExpression expression){
8789
return fqn;
8890
}
8991

90-
public JavaInvokeInsn getJavaInvokeInsn(GraphRelationship relationship){
92+
public PsiInvocationSignature getJavaInvokeInsn(GraphRelationship relationship){
9193
String insn = (String)relationship.getPropertyContainer().getProperties().get("insn");
92-
JavaInvokeInsn invocation = new JavaInvokeInsn(insn);
94+
PsiInvocationSignature invocation = new PsiInvocationSignature(insn);
9395
return invocation;
9496
}
9597

96-
public PsiMethod getPsiMethod(JavaInvokeInsn invocation){
98+
public PsiMethod getPsiMethod(PsiInvocationSignature invocation){
9799
PsiMethod method = invocation.getCaller(this.project);
98100
return method;
99101
}
100102

101103

102104

103-
private void navigate(PsiElement element){
105+
private void navigate(PsiElement element, VirtualFile virtualFile){
104106
UsageInfo usage = new UsageInfo(element);
105107
SelectInEditorManager.getInstance(this.project)
106-
.selectInEditor(usage.getVirtualFile(), usage.getSegment().getStartOffset(), usage.getSegment().getEndOffset(), true, false);
108+
.selectInEditor(virtualFile, usage.getSegment().getStartOffset(), usage.getSegment().getEndOffset(), true, false);
107109
}
108110
}

ui/jetbrains/src/main/java/com/albertoventurini/graphdbplugin/jetbrains/ui/console/graph/EntityActionGroup.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ public EntityActionGroup(DataSourceApi dataSourceApi, NoIdGraphEntity entity) {
3232
actions = new AnAction[]{
3333
new CopyToClipboardAction("Copy relationship", "", null, entity),
3434
new RelationshipEditAction("Edit relationship", "", null, dataSourceApi, (GraphRelationship) entity),
35-
new RelationshipDeleteAction("Delete relationship", "", null, dataSourceApi, (GraphRelationship) entity)
35+
new RelationshipDeleteAction("Delete relationship", "", null, dataSourceApi, (GraphRelationship) entity),
36+
new RelationshipOnlyLeaveAction("Only Leave this invocation", "", null, dataSourceApi, (GraphRelationship) entity),
37+
new RelationshipAllDeleteAction("Delete All this invocation", "", null, dataSourceApi, (GraphRelationship) entity)
38+
3639
};
3740
} else if (entity instanceof ObjectModel) {
3841
actions = new AnAction[] {

ui/jetbrains/src/main/java/com/albertoventurini/graphdbplugin/jetbrains/ui/console/graph/GraphPanelInteractions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private void registerVisualisationEvents() {
9797
visualization.addEdgeListener(EventType.CLICK, graphConsoleView.getGraphPanel()::showRelationshipData);
9898
visualization.addEdgeListener(EventType.CLICK, this.edgeNavigateAction::navigateToInvocation);
9999
visualization.addNodeListener(EventType.HOVER_START, graphConsoleView.getGraphPanel()::showTooltip);
100-
visualization.addNodeListener(EventType.HOVER_END, graphConsoleView.getGraphPanel()::hideTooltip);
100+
//visualization.addNodeListener(EventType.HOVER_END, graphConsoleView.getGraphPanel()::hideTooltip);
101101
visualization.addEdgeListener(EventType.HOVER_START, graphConsoleView.getGraphPanel()::showTooltip);
102102
visualization.addEdgeListener(EventType.HOVER_END, graphConsoleView.getGraphPanel()::hideTooltip);
103103
}

ui/jetbrains/src/main/java/com/albertoventurini/graphdbplugin/jetbrains/ui/console/graph/JavaMethodSignature.java

Lines changed: 0 additions & 84 deletions
This file was deleted.

ui/jetbrains/src/main/java/com/albertoventurini/graphdbplugin/jetbrains/ui/console/graph/NodeDeleteAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public void actionPerformed(@NotNull final AnActionEvent e) {
3535
if (project != null) {
3636
QueryExecutionService service = new QueryExecutionService(project, project.getMessageBus());
3737

38-
service.executeQuery(dataSource, new ExecuteQueryPayload("MATCH (n) WHERE ID(n) = $id DETACH DELETE n",
39-
ImmutableMap.of("id", Long.parseLong(node.getId())),
38+
service.executeQuery(dataSource, new ExecuteQueryPayload("MATCH (n) WHERE elementId(n) = $id DETACH DELETE n",
39+
ImmutableMap.of("id", node.getId()),
4040
null));
4141
}
4242
}

ui/jetbrains/src/main/java/com/albertoventurini/graphdbplugin/jetbrains/ui/console/graph/NodeNavigateAction.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.intellij.openapi.project.Project;
77
import com.intellij.openapi.vfs.VirtualFile;
88
import com.intellij.psi.*;
9-
import com.intellij.psi.search.GlobalSearchScope;
109
import com.intellij.usageView.UsageInfo;
1110
import prefuse.visual.VisualItem;
1211

@@ -29,7 +28,7 @@ public void navigateToMethodDeclaration(GraphNode node, VisualItem item, MouseEv
2928

3029
public PsiMethod getPsiMethod(GraphNode node){
3130
String methodSignature = (String)node.getPropertyContainer().getProperties().get("method");
32-
JavaMethodSignature signature = new JavaMethodSignature(methodSignature);
31+
PsiMethodSignature signature = new PsiMethodSignature(methodSignature);
3332
PsiMethod method = signature.getMethod(this.project);
3433
return method;
3534
}
@@ -45,7 +44,7 @@ private void navigateToMethod(PsiMethod method) {
4544
}
4645

4746
private void navigate(PsiMethod method){
48-
UsageInfo usage = new UsageInfo(method);
47+
UsageInfo usage = new UsageInfo(method.getNameIdentifier());
4948
SelectInEditorManager.getInstance(this.project)
5049
.selectInEditor(usage.getVirtualFile(), usage.getSegment().getStartOffset(), usage.getSegment().getEndOffset(), true, false);
5150
}

0 commit comments

Comments
 (0)