Skip to content

Commit

Permalink
fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Dec 7, 2019
1 parent 42f4fc6 commit fa80d42
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,32 @@ public void configure() throws CoreException {
public void deconfigure() throws CoreException {
}

IProject p;
private IProject project;

@Override
public IProject getProject() {
return p;
public void setProject(final IProject project) {
this.project = project;
}

@Override
public void setProject(IProject project) {
this.p = project;
public IProject getProject() {
return project;
}

@Override
public GroovyOutlinePage getGroovyOutlinePageForEditor(String contextMenuID, GroovyEditor editor) {
public GroovyOutlinePage getGroovyOutlinePageForEditor(final String contextMenuID, final GroovyEditor editor) {
TCompilationUnit ounit = new TCompilationUnit(this, editor.getGroovyCompilationUnit());
return new TGroovyOutlinePage(null, editor, ounit);
}

@Override
public boolean appliesTo(GroovyCompilationUnit unit) {
public boolean appliesTo(final GroovyCompilationUnit unit) {
return CharOperation.contains('X', unit.getFileName());
}

public static class TGroovyOutlinePage extends GroovyOutlinePage {
public TGroovyOutlinePage(String contextMenuID, GroovyEditor editor, OCompilationUnit unit) {

public TGroovyOutlinePage(final String contextMenuID, final GroovyEditor editor, final OCompilationUnit unit) {
super(contextMenuID, editor, unit);
}

Expand All @@ -82,26 +83,26 @@ public static class TCompilationUnit extends OCompilationUnit {
public OutlineExtender1 outlineExtender;
public TType type;

public TCompilationUnit(OutlineExtender1 outlineExtender, GroovyCompilationUnit unit) {
public TCompilationUnit(final OutlineExtender1 extender, final GroovyCompilationUnit unit) {
super(unit);
this.outlineExtender = outlineExtender;
this.outlineExtender = extender;
}

@Override
public IMember[] refreshChildren() {
type = new TType(this, getElementName());
return new IMember[] { type };
public IMember getOutlineElementAt(final int caretOffset) {
return type;
}

@Override
public IMember getOutlineElementAt(int caretOffset) {
return type;
public IMember[] refreshChildren() {
type = new TType(this, getElementName());
return new IMember[] {type};
}
}

public static class TType extends OType {

public TType(IOJavaElement parent, String name) {
public TType(final IOJavaElement parent, final String name) {
super(parent, new ConstantExpression(name), name);
this.name = name;
}
Expand All @@ -111,30 +112,30 @@ public ASTNode getElementNameNode() {
return getNode();
}

public TType addTestType(String name) {
public TType addTestType(final String name) {
TType t = new TType(this, name);
addChild(t);
return t;
}

public TMethod addTestMethod(String name, String returnType) {
public TField addTestField(final String name, final String type) {
TField f = new TField(this, name, type);
addChild(f);
return f;
}

public TMethod addTestMethod(final String name, final String returnType) {
TMethod m = new TMethod(this, name, returnType);
addChild(m);
return m;
}

public TField addTestField(String name, String typeSignature) {
TField f = new TField(this, name, typeSignature);
addChild(f);
return f;
}
}

public static class TMethod extends OMethod {

private String returnType;

public TMethod(OType parent, String name, String returnType) {
public TMethod(final OType parent, final String name, final String returnType) {
super(parent, new ConstantExpression(name), name);
this.name = name;
this.returnType = returnType;
Expand All @@ -155,7 +156,7 @@ public static class TField extends OField {

private String typeSignature;

public TField(OType parent, String name, String typeSignature) {
public TField(final OType parent, final String name, final String typeSignature) {
super(parent, new ConstantExpression(name), name);
this.name = name;
this.typeSignature = typeSignature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,46 +35,44 @@ public class OutlineExtender2 extends OutlineExtender1 {
public static final String NATURE = "org.codehaus.groovy.eclipse.tests.testNature2";

@Override
public boolean appliesTo(GroovyCompilationUnit unit) {
public boolean appliesTo(final GroovyCompilationUnit unit) {
return CharOperation.contains('Y', unit.getFileName());
}

@Override
public GroovyOutlinePage getGroovyOutlinePageForEditor(String contextMenuID, GroovyEditor editor) {
public GroovyOutlinePage getGroovyOutlinePageForEditor(final String contextMenuID, final GroovyEditor editor) {
TCompilationUnit2 ounit = new TCompilationUnit2(this, editor.getGroovyCompilationUnit());
return new TGroovyOutlinePage(null, editor, ounit);
}

public static class TCompilationUnit2 extends TCompilationUnit {

public TCompilationUnit2(OutlineExtender2 outlineExtender, GroovyCompilationUnit unit) {
super(outlineExtender, unit);
public TCompilationUnit2(final OutlineExtender2 extender, final GroovyCompilationUnit unit) {
super(extender, unit);
}

@Override
public IMember[] refreshChildren() {
type = new TType(this, getElementName().substring(0, getElementName().indexOf('.')));

ModuleNode moduleNode = (ModuleNode) getNode();
if (moduleNode != null) {
new Finder(moduleNode, type).execute();
}
return new IMember[] { type };
return new IMember[] {type};
}

@Override
public void refresh() {
super.refresh();
}

}

public static class Finder extends ASTNodeFinder {

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

public Finder(ModuleNode moduleNode, TType rootType) {
public Finder(final ModuleNode moduleNode, final TType rootType) {
super(new Region(moduleNode));
this.moduleNode = moduleNode;
methodStack.push(rootType);
Expand All @@ -85,22 +83,7 @@ public void execute() {
}

@Override
public void visitMethodCallExpression(MethodCallExpression methodCall) {
if (methodCall.getLineNumber() < 0) {
super.visitMethodCallExpression(methodCall);
return;
}

TType parentType = methodStack.peek();
TType t = parentType.addTestType(methodCall.getMethodAsString());

methodStack.push(t);
super.visitMethodCallExpression(methodCall);
methodStack.pop();
}

@Override
public void visitMethod(MethodNode method) {
public void visitMethod(final MethodNode method) {
if (method.getLineNumber() > 1) {
TType parentType = methodStack.peek();
parentType.addTestMethod(method.getName(), method.getReturnType().getNameWithoutPackage());
Expand All @@ -110,8 +93,22 @@ public void visitMethod(MethodNode method) {
}

@Override
public void visitVariableExpression(VariableExpression variable) {
if (variable.getLineNumber() >= 0) {
public void visitMethodCallExpression(final MethodCallExpression methodCall) {
if (methodCall.getEnd() > 0) {
TType parentType = methodStack.peek();
TType t = parentType.addTestType(methodCall.getMethodAsString());

methodStack.push(t);
}
super.visitMethodCallExpression(methodCall);
if (methodCall.getEnd() > 0) {
methodStack.pop();
}
}

@Override
public void visitVariableExpression(final VariableExpression variable) {
if (variable.getEnd() > 0) {
TType parentType = methodStack.peek();
parentType.addTestField(variable.getName(), GroovyUtils.getTypeSignature(variable.getType(), false, false));
}
Expand Down

0 comments on commit fa80d42

Please sign in to comment.