Skip to content

Commit 3c0e47f

Browse files
committed
fix issue #3 support parameter is anther method call, fix issue #4 support pipeline call.
1 parent 2dcf3dd commit 3c0e47f

File tree

7 files changed

+93
-55
lines changed

7 files changed

+93
-55
lines changed

META-INF/plugin.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
Simple Sequence Diagram Generator. fixed version of SequencePlugin , work from 13.x. <br />
55
The original version SequencePlugin come from ksibilev@yahoo.com. <br />
66
For more info, please visit: http://vanco.github.io/SequencePlugin/]]></description>
7-
<version>1.0.9</version>
7+
<version>1.1</version>
88
<vendor>fanhuagang@gmail.com</vendor>
99
<idea-version since-build="IU-123.72" />
1010

1111
<depends>com.intellij.modules.java</depends>
1212

1313
<change-notes><![CDATA[
1414
<dl>
15+
<dt>1.1</dt>
16+
<dd>fix issue #3 support parameter is anther method call, fix issue #4 support pipeline call.</dd>
1517
<dt>1.0.9</dt>
1618
<dd>fix issue #1 recognise more generic method definition, fix issue #2 show popup menu on mac and linux.</dd>
1719
<dt>1.0.8</dt>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Place the cursor in side the method, trigger it from context menu > Sequence Dia
3434

3535
## Version History
3636
<dl>
37+
<dt>1.1</dt>
38+
<dd>fix issue #3 support parameter is anther method call, fix issue #4 support pipeline call.</dd>
3739
<dt>1.0.9</dt>
3840
<dd>fix issue #1 recognise more generic method definition, fix issue #2 show popup menu on mac and linux.</dd>
3941
<dt>1.0.8</dt>

src/org/intellij/sequencer/config/Configuration.form

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.intellij.sequencer.config.ConfigurationUI">
3-
<grid id="60330" binding="_mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
3+
<grid id="60330" binding="_mainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
6-
<xy x="10" y="38" width="579" height="311"/>
6+
<xy x="10" y="38" width="579" height="286"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
@@ -13,7 +13,8 @@
1313
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="6" fill="0" indent="0" use-parent-layout="false"/>
1414
</constraints>
1515
<properties>
16-
<text value="Kesh Sibilev ksibilev@yahoo.com"/>
16+
<foreground color="-6842473"/>
17+
<text value="Orginal: Kesh Sibilev(ksibilev@yahoo.com), Now: Evan Fan (fanhuagang@gmail.com)"/>
1718
</properties>
1819
</component>
1920
<grid id="de5e2" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
@@ -222,14 +223,6 @@
222223
</grid>
223224
</children>
224225
</grid>
225-
<component id="5c79e" class="javax.swing.JLabel">
226-
<constraints>
227-
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
228-
</constraints>
229-
<properties>
230-
<text value="Evan Fan fanhuagang@gmail.com"/>
231-
</properties>
232-
</component>
233226
</children>
234227
</grid>
235228
</form>

src/org/intellij/sequencer/diagram/Parser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ else if (c == '\\') {
170170
if (deep == 0)
171171
isGeneric = false;
172172
sb.append(tmp.toString());
173+
} else {
174+
sb.append(tmp.toString());
173175
}
174176
}
175177
}

src/org/intellij/sequencer/generator/SequenceGenerator.java

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.intellij.openapi.diagnostic.Logger;
44
import com.intellij.psi.*;
5+
import com.intellij.util.containers.Stack;
56
import org.intellij.sequencer.diagram.Info;
67
import org.intellij.sequencer.util.PsiUtil;
78

@@ -10,6 +11,8 @@
1011
import java.util.List;
1112

1213
public class SequenceGenerator extends JavaElementVisitor {
14+
private final Stack<PsiCallExpression> _exprStack = new Stack<PsiCallExpression>();
15+
private final Stack<CallStack> _callStack = new Stack<CallStack>();
1316
private static final Logger LOGGER = Logger.getInstance(SequenceGenerator.class.getName());
1417

1518
private CallStack topStack;
@@ -22,7 +25,7 @@ public SequenceGenerator(SequenceParams params) {
2225
}
2326

2427
public void visitElement(PsiElement psiElement) {
25-
PsiUtil.acceptChildren(psiElement, this);
28+
psiElement.acceptChildren(this);
2629
}
2730

2831
public void visitClass(PsiClass psiClass) {
@@ -35,35 +38,43 @@ public CallStack generate(PsiMethod psiMethod) {
3538

3639
public void visitMethod(PsiMethod psiMethod) {
3740
MethodDescription method = createMethod(psiMethod);
38-
if(topStack == null) {
41+
if (topStack == null) {
3942
topStack = new CallStack(method);
4043
currentStack = topStack;
4144
} else {
42-
if(!params.isAllowRecursion() && currentStack.isReqursive(method))
45+
if (!params.isAllowRecursion() && currentStack.isReqursive(method))
4346
return;
4447
currentStack = currentStack.methodCall(method);
4548
}
4649
super.visitMethod(psiMethod);
4750
}
4851

49-
public void visitNewExpression(PsiNewExpression psiNewExpression) {
50-
PsiMethod psiMethod = psiNewExpression.resolveConstructor();
51-
methodCall(psiMethod);
52-
super.visitNewExpression(psiNewExpression);
53-
}
54-
55-
public void visitMethodCallExpression(PsiMethodCallExpression psiMethodCallExpression) {
56-
PsiMethod psiMethod = psiMethodCallExpression.resolveMethod();
57-
methodCall(psiMethod);
58-
super.visitMethodCallExpression(psiMethodCallExpression);
52+
@Override
53+
public void visitCallExpression(PsiCallExpression callExpression) {
54+
if (!(PsiUtil.isComplexCall(callExpression) || PsiUtil.isPipeline(callExpression))) {
55+
PsiMethod psiMethod = callExpression.resolveMethod();
56+
methodCall(psiMethod);
57+
} else {
58+
_exprStack.push(callExpression);
59+
_callStack.push(currentStack);
60+
}
61+
super.visitCallExpression(callExpression);
62+
if ((PsiUtil.isPipeline(callExpression) || PsiUtil.isComplexCall(callExpression)))
63+
if (!_exprStack.isEmpty()) {
64+
CallStack old = currentStack;
65+
PsiCallExpression pop = _exprStack.pop();
66+
currentStack = _callStack.pop();
67+
methodCall(pop.resolveMethod());
68+
currentStack = old;
69+
}
5970
}
6071

6172
private void methodCall(PsiMethod psiMethod) {
62-
if(psiMethod == null)
73+
if (psiMethod == null)
6374
return;
64-
if(!params.getMethodFilter().allow(psiMethod))
75+
if (!params.getMethodFilter().allow(psiMethod))
6576
return;
66-
else if(depth < params.getMaxDepth() - 1) {
77+
else if (depth < params.getMaxDepth() - 1) {
6778
CallStack oldStack = currentStack;
6879
depth++;
6980
LOGGER.debug("+ depth = " + depth + " method = " + psiMethod.getName());
@@ -79,7 +90,7 @@ private MethodDescription createMethod(PsiMethod psiMethod) {
7990
PsiParameter[] parameters = psiMethod.getParameterList().getParameters();
8091
List argNames = new ArrayList();
8192
List argTypes = new ArrayList();
82-
for(int i = 0; i < parameters.length; i++) {
93+
for (int i = 0; i < parameters.length; i++) {
8394
PsiParameter parameter = parameters[i];
8495
argNames.add(parameter.getName());
8596
PsiType psiType = parameter.getType();
@@ -90,35 +101,36 @@ private MethodDescription createMethod(PsiMethod psiMethod) {
90101
if (containingClass == null) {
91102
containingClass = (PsiClass) psiMethod.getParent().getContext();
92103
}
93-
if(psiMethod.isConstructor())
104+
if (psiMethod.isConstructor())
94105
return MethodDescription.createConstructorDescription(
95-
createClassDescription(containingClass),
96-
attributes, argNames, argTypes);
106+
createClassDescription(containingClass),
107+
attributes, argNames, argTypes);
97108
return MethodDescription.createMethodDescription(
98-
createClassDescription(containingClass),
99-
attributes, psiMethod.getName(), psiMethod.getReturnType().getCanonicalText(),
100-
argNames, argTypes);
109+
createClassDescription(containingClass),
110+
attributes, psiMethod.getName(), psiMethod.getReturnType().getCanonicalText(),
111+
argNames, argTypes);
101112
}
102113

103114
private ClassDescription createClassDescription(PsiClass psiClass) {
104115
return new ClassDescription(psiClass.getQualifiedName(),
105-
createAttributes(psiClass.getModifierList()));
116+
createAttributes(psiClass.getModifierList()));
106117
}
107118

108119
private List createAttributes(PsiModifierList psiModifierList) {
109-
if(psiModifierList == null)
120+
if (psiModifierList == null)
110121
return Collections.EMPTY_LIST;
111122
List attributes = new ArrayList();
112-
for(int i = 0; i < Info.RECOGNIZED_METHOD_ATTRIBUTES.length; i++) {
123+
for (int i = 0; i < Info.RECOGNIZED_METHOD_ATTRIBUTES.length; i++) {
113124
String attribute = Info.RECOGNIZED_METHOD_ATTRIBUTES[i];
114-
if(psiModifierList.hasModifierProperty(attribute))
125+
if (psiModifierList.hasModifierProperty(attribute))
115126
attributes.add(attribute);
116127
}
117-
if(PsiUtil.isInClassFile(psiModifierList) || PsiUtil.isInJarFileSystem(psiModifierList))
128+
if (PsiUtil.isInClassFile(psiModifierList) || PsiUtil.isInJarFileSystem(psiModifierList))
118129
attributes.add(Info.EXTERNAL_ATTRIBUTE);
119130
return attributes;
120131
}
121132

122133
public void visitReferenceExpression(PsiReferenceExpression psiReferenceExpression) {
134+
psiReferenceExpression.acceptChildren(this);
123135
}
124136
}

src/org/intellij/sequencer/util/CallFinder.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package org.intellij.sequencer.util;
22

33
import com.intellij.psi.*;
4+
import com.intellij.util.containers.Stack;
45
import org.intellij.sequencer.generator.filters.MethodFilter;
56

67
public class CallFinder extends JavaElementVisitor {
8+
private final Stack<PsiCallExpression> _exprStack = new Stack<PsiCallExpression>();
9+
710
private int _callsLeft;
811
private MethodFilter _methodFilter;
912
private PsiMethod _psiMethod;
@@ -16,26 +19,29 @@ public CallFinder(int callsLeft, MethodFilter methodFilter, PsiMethod psiMethod)
1619
}
1720

1821
public void visitElement(PsiElement psiElement) {
19-
PsiUtil.acceptChildren(psiElement, this);
22+
psiElement.acceptChildren(this);
2023
}
2124

2225
public void visitReferenceExpression(PsiReferenceExpression psiReferenceExpression) {
26+
psiReferenceExpression.acceptChildren(this);
2327
}
2428

2529
public PsiElement getPsiElement() {
2630
return _psiElement;
2731
}
2832

29-
public void visitNewExpression(PsiNewExpression psiNewExpression) {
30-
PsiMethod psiMethod = psiNewExpression.resolveConstructor();
31-
checkCurrentPsiElement(psiMethod, psiNewExpression);
32-
super.visitNewExpression(psiNewExpression);
33-
}
34-
35-
public void visitMethodCallExpression(PsiMethodCallExpression psiMethodCallExpression) {
36-
PsiMethod psiMethod = psiMethodCallExpression.resolveMethod();
37-
checkCurrentPsiElement(psiMethod, psiMethodCallExpression);
38-
super.visitMethodCallExpression(psiMethodCallExpression);
33+
public void visitCallExpression(PsiCallExpression callExpression) {
34+
if (!(PsiUtil.isComplexCall(callExpression) || PsiUtil.isPipeline(callExpression))) {
35+
PsiMethod psiMethod = callExpression.resolveMethod();
36+
checkCurrentPsiElement(psiMethod, callExpression);
37+
} else {
38+
_exprStack.push(callExpression);
39+
}
40+
super.visitCallExpression(callExpression);
41+
if (!_exprStack.isEmpty() && (PsiUtil.isPipeline(callExpression) || PsiUtil.isComplexCall(callExpression))) {
42+
PsiCallExpression pop = _exprStack.pop();
43+
checkCurrentPsiElement(pop.resolveMethod(), pop);
44+
}
3945
}
4046

4147
private void checkCurrentPsiElement(PsiMethod psiMethod, PsiElement psiElement) {

src/org/intellij/sequencer/util/PsiUtil.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package org.intellij.sequencer.util;
22

33
import com.intellij.openapi.project.Project;
4-
import com.intellij.openapi.util.Condition;
54
import com.intellij.openapi.vfs.VirtualFile;
65
import com.intellij.psi.*;
7-
import com.intellij.psi.search.GlobalSearchScope;
8-
import com.intellij.psi.search.searches.AllClassesSearch;
96
import com.intellij.psi.util.ClassUtil;
10-
import com.intellij.util.Query;
117
import org.intellij.sequencer.generator.filters.MethodFilter;
128

139
import java.util.List;
@@ -115,4 +111,29 @@ public static void acceptChildren(PsiElement psiElement, PsiElementVisitor visit
115111
psiElement.acceptChildren(visitor);
116112
}
117113

114+
public static boolean isPipeline(PsiCallExpression callExpression) {
115+
PsiElement[] children = callExpression.getChildren();
116+
for (PsiElement child : children) {
117+
for (PsiElement psiElement : child.getChildren()) {
118+
if (psiElement instanceof PsiMethodCallExpression) {
119+
return true;
120+
}
121+
}
122+
}
123+
return false;
124+
}
125+
126+
public static boolean isComplexCall(PsiCallExpression callExpression) {
127+
PsiExpressionList argumentList = callExpression.getArgumentList();
128+
if (argumentList != null) {
129+
PsiExpression[] expressions = argumentList.getExpressions();
130+
for (PsiExpression expression : expressions) {
131+
if (expression instanceof PsiCallExpression) {
132+
return true;
133+
}
134+
}
135+
}
136+
return false;
137+
}
138+
118139
}

0 commit comments

Comments
 (0)