Skip to content

Commit fa80d42

Browse files
committed
fix test case
#999
1 parent 42f4fc6 commit fa80d42

File tree

2 files changed

+50
-52
lines changed

2 files changed

+50
-52
lines changed

ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/ui/OutlineExtender1.java

+27-26
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,32 @@ public void configure() throws CoreException {
4444
public void deconfigure() throws CoreException {
4545
}
4646

47-
IProject p;
47+
private IProject project;
4848

4949
@Override
50-
public IProject getProject() {
51-
return p;
50+
public void setProject(final IProject project) {
51+
this.project = project;
5252
}
5353

5454
@Override
55-
public void setProject(IProject project) {
56-
this.p = project;
55+
public IProject getProject() {
56+
return project;
5757
}
5858

5959
@Override
60-
public GroovyOutlinePage getGroovyOutlinePageForEditor(String contextMenuID, GroovyEditor editor) {
60+
public GroovyOutlinePage getGroovyOutlinePageForEditor(final String contextMenuID, final GroovyEditor editor) {
6161
TCompilationUnit ounit = new TCompilationUnit(this, editor.getGroovyCompilationUnit());
6262
return new TGroovyOutlinePage(null, editor, ounit);
6363
}
6464

6565
@Override
66-
public boolean appliesTo(GroovyCompilationUnit unit) {
66+
public boolean appliesTo(final GroovyCompilationUnit unit) {
6767
return CharOperation.contains('X', unit.getFileName());
6868
}
6969

7070
public static class TGroovyOutlinePage extends GroovyOutlinePage {
71-
public TGroovyOutlinePage(String contextMenuID, GroovyEditor editor, OCompilationUnit unit) {
71+
72+
public TGroovyOutlinePage(final String contextMenuID, final GroovyEditor editor, final OCompilationUnit unit) {
7273
super(contextMenuID, editor, unit);
7374
}
7475

@@ -82,26 +83,26 @@ public static class TCompilationUnit extends OCompilationUnit {
8283
public OutlineExtender1 outlineExtender;
8384
public TType type;
8485

85-
public TCompilationUnit(OutlineExtender1 outlineExtender, GroovyCompilationUnit unit) {
86+
public TCompilationUnit(final OutlineExtender1 extender, final GroovyCompilationUnit unit) {
8687
super(unit);
87-
this.outlineExtender = outlineExtender;
88+
this.outlineExtender = extender;
8889
}
8990

9091
@Override
91-
public IMember[] refreshChildren() {
92-
type = new TType(this, getElementName());
93-
return new IMember[] { type };
92+
public IMember getOutlineElementAt(final int caretOffset) {
93+
return type;
9494
}
9595

9696
@Override
97-
public IMember getOutlineElementAt(int caretOffset) {
98-
return type;
97+
public IMember[] refreshChildren() {
98+
type = new TType(this, getElementName());
99+
return new IMember[] {type};
99100
}
100101
}
101102

102103
public static class TType extends OType {
103104

104-
public TType(IOJavaElement parent, String name) {
105+
public TType(final IOJavaElement parent, final String name) {
105106
super(parent, new ConstantExpression(name), name);
106107
this.name = name;
107108
}
@@ -111,30 +112,30 @@ public ASTNode getElementNameNode() {
111112
return getNode();
112113
}
113114

114-
public TType addTestType(String name) {
115+
public TType addTestType(final String name) {
115116
TType t = new TType(this, name);
116117
addChild(t);
117118
return t;
118119
}
119120

120-
public TMethod addTestMethod(String name, String returnType) {
121+
public TField addTestField(final String name, final String type) {
122+
TField f = new TField(this, name, type);
123+
addChild(f);
124+
return f;
125+
}
126+
127+
public TMethod addTestMethod(final String name, final String returnType) {
121128
TMethod m = new TMethod(this, name, returnType);
122129
addChild(m);
123130
return m;
124131
}
125-
126-
public TField addTestField(String name, String typeSignature) {
127-
TField f = new TField(this, name, typeSignature);
128-
addChild(f);
129-
return f;
130-
}
131132
}
132133

133134
public static class TMethod extends OMethod {
134135

135136
private String returnType;
136137

137-
public TMethod(OType parent, String name, String returnType) {
138+
public TMethod(final OType parent, final String name, final String returnType) {
138139
super(parent, new ConstantExpression(name), name);
139140
this.name = name;
140141
this.returnType = returnType;
@@ -155,7 +156,7 @@ public static class TField extends OField {
155156

156157
private String typeSignature;
157158

158-
public TField(OType parent, String name, String typeSignature) {
159+
public TField(final OType parent, final String name, final String typeSignature) {
159160
super(parent, new ConstantExpression(name), name);
160161
this.name = name;
161162
this.typeSignature = typeSignature;

ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/ui/OutlineExtender2.java

+23-26
Original file line numberDiff line numberDiff line change
@@ -35,46 +35,44 @@ public class OutlineExtender2 extends OutlineExtender1 {
3535
public static final String NATURE = "org.codehaus.groovy.eclipse.tests.testNature2";
3636

3737
@Override
38-
public boolean appliesTo(GroovyCompilationUnit unit) {
38+
public boolean appliesTo(final GroovyCompilationUnit unit) {
3939
return CharOperation.contains('Y', unit.getFileName());
4040
}
4141

4242
@Override
43-
public GroovyOutlinePage getGroovyOutlinePageForEditor(String contextMenuID, GroovyEditor editor) {
43+
public GroovyOutlinePage getGroovyOutlinePageForEditor(final String contextMenuID, final GroovyEditor editor) {
4444
TCompilationUnit2 ounit = new TCompilationUnit2(this, editor.getGroovyCompilationUnit());
4545
return new TGroovyOutlinePage(null, editor, ounit);
4646
}
4747

4848
public static class TCompilationUnit2 extends TCompilationUnit {
4949

50-
public TCompilationUnit2(OutlineExtender2 outlineExtender, GroovyCompilationUnit unit) {
51-
super(outlineExtender, unit);
50+
public TCompilationUnit2(final OutlineExtender2 extender, final GroovyCompilationUnit unit) {
51+
super(extender, unit);
5252
}
5353

5454
@Override
5555
public IMember[] refreshChildren() {
5656
type = new TType(this, getElementName().substring(0, getElementName().indexOf('.')));
57-
5857
ModuleNode moduleNode = (ModuleNode) getNode();
5958
if (moduleNode != null) {
6059
new Finder(moduleNode, type).execute();
6160
}
62-
return new IMember[] { type };
61+
return new IMember[] {type};
6362
}
6463

6564
@Override
6665
public void refresh() {
6766
super.refresh();
6867
}
69-
7068
}
7169

7270
public static class Finder extends ASTNodeFinder {
7371

7472
private ModuleNode moduleNode;
7573
private Stack<TType> methodStack = new Stack<>();
7674

77-
public Finder(ModuleNode moduleNode, TType rootType) {
75+
public Finder(final ModuleNode moduleNode, final TType rootType) {
7876
super(new Region(moduleNode));
7977
this.moduleNode = moduleNode;
8078
methodStack.push(rootType);
@@ -85,22 +83,7 @@ public void execute() {
8583
}
8684

8785
@Override
88-
public void visitMethodCallExpression(MethodCallExpression methodCall) {
89-
if (methodCall.getLineNumber() < 0) {
90-
super.visitMethodCallExpression(methodCall);
91-
return;
92-
}
93-
94-
TType parentType = methodStack.peek();
95-
TType t = parentType.addTestType(methodCall.getMethodAsString());
96-
97-
methodStack.push(t);
98-
super.visitMethodCallExpression(methodCall);
99-
methodStack.pop();
100-
}
101-
102-
@Override
103-
public void visitMethod(MethodNode method) {
86+
public void visitMethod(final MethodNode method) {
10487
if (method.getLineNumber() > 1) {
10588
TType parentType = methodStack.peek();
10689
parentType.addTestMethod(method.getName(), method.getReturnType().getNameWithoutPackage());
@@ -110,8 +93,22 @@ public void visitMethod(MethodNode method) {
11093
}
11194

11295
@Override
113-
public void visitVariableExpression(VariableExpression variable) {
114-
if (variable.getLineNumber() >= 0) {
96+
public void visitMethodCallExpression(final MethodCallExpression methodCall) {
97+
if (methodCall.getEnd() > 0) {
98+
TType parentType = methodStack.peek();
99+
TType t = parentType.addTestType(methodCall.getMethodAsString());
100+
101+
methodStack.push(t);
102+
}
103+
super.visitMethodCallExpression(methodCall);
104+
if (methodCall.getEnd() > 0) {
105+
methodStack.pop();
106+
}
107+
}
108+
109+
@Override
110+
public void visitVariableExpression(final VariableExpression variable) {
111+
if (variable.getEnd() > 0) {
115112
TType parentType = methodStack.peek();
116113
parentType.addTestField(variable.getName(), GroovyUtils.getTypeSignature(variable.getType(), false, false));
117114
}

0 commit comments

Comments
 (0)