Skip to content

Commit

Permalink
Fix source offsets for special constructor call expression
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jul 23, 2019
1 parent aa05051 commit cedbbb9
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3083,8 +3083,7 @@ public void testMethodOverloadsArgumentMatching7() {
" face.with {\n" +
" setValue(Keys.ONE, false)\n" +
" }\n" +
"}\n" +
"}";
"}\n";
int offset = contents.indexOf("setValue");
MethodNode m = assertDeclaration(contents, offset, offset + "setValue".length(), "Face", "setValue", DeclarationKind.METHOD);
Assert.assertEquals("Expected 'setValue(String,boolean)'", "boolean", m.getParameters()[1].getType().toString(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ public void testClosureSyntax() {
"----------\n" +
"1. ERROR in Foo.groovy (at line 12)\n" +
"\tabc()\n" +
"\t^\n" +
"Groovy:unexpected token: abc @ line 12, column 3.\n" +
"\t^" + (!isParrotParser() ? "" : "^^^^") + "\n" +
"Groovy:" + (!isParrotParser()
? "unexpected token: abc @ line 12, column 3.\n"
: "You defined a method[abc] without a body. Try adding a method body, or declare it abstract @ line 12, column 3.\n") +
"----------\n");
}

Expand Down Expand Up @@ -574,7 +576,7 @@ public void testDuplicateClasses_GRE796_2() {
}

@Test
public void testGroovyColon_GRE801() {
public void testInvalidAssignment_GRE801() {
//@formatter:off
String[] sources = {
"A.groovy",
Expand All @@ -588,9 +590,10 @@ public void testGroovyColon_GRE801() {
"----------\n" +
"1. ERROR in A.groovy (at line 1)\n" +
"\thttpClientControl.demand.generalConnection(1..1) = {->\n" +
"\t ^\n" +
"Groovy:\"httpClientControl.demand.generalConnection((1..1))\" is a method call expression," +
" but it should be a variable expression at line: 1 column: 50. File: A.groovy @ line 1, column 50.\n" +
"\t" + (isParrotParser() ? "" : " ") + "^\n" +
"Groovy:" + (isParrotParser()
? "The LHS of an assignment should be a variable or a field accessing expression @ line 1, column 1.\n"
: "\"httpClientControl.demand.generalConnection((1..1))\" is a method call expression, but it should be a variable expression at line: 1 column: 50. File: A.groovy @ line 1, column 50.\n") +
"----------\n");
}

Expand Down Expand Up @@ -1349,7 +1352,9 @@ public void testAbstractMethodWithBody1() {
"1. ERROR in Script.groovy (at line 1)\n" +
"\tabstract def meth() {\n" +
"\t^\n" +
"Groovy:Abstract methods do not define a body. at line: 1 column: 1. File: Script.groovy @ line 1, column 1.\n" +
"Groovy:" + (!isParrotParser()
? "Abstract methods do not define a body. at line: 1 column: 1. File: Script.groovy @ line 1, column 1.\n"
: "You cannot define an abstract method[meth] in the script. Try removing the 'abstract' @ line 1, column 1.\n") +
"----------\n");
}

Expand All @@ -1366,13 +1371,43 @@ public void testAbstractMethodWithBody2() {
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 2)\n" +
"\tabstract def meth() {\n" +
"\t^\n" +
"Groovy:Abstract methods do not define a body. at line: 2 column: 3. File: Main.groovy @ line 2, column 3.\n" +
"----------\n");
if (!isParrotParser()) {
runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 2)\n" +
"\tabstract def meth() {\n" +
"\t^\n" +
"Groovy:Abstract methods do not define a body. at line: 2 column: 3. File: Main.groovy @ line 2, column 3.\n" +
"----------\n");
} else {
runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 1)\n" +
"\tclass Main {\n" +
"\t ^^^^\n" +
"The type Main must be an abstract class to define abstract methods\n" +
"----------\n" +
"2. ERROR in Main.groovy (at line 1)\n" +
"\tclass Main {\n" +
"\t ^^^^\n" +
"Groovy:Can't have an abstract method in a non-abstract class. The class 'Main' must be declared abstract or the method 'java.lang.Object meth()' must be implemented.\n" +
"----------\n" +
"3. ERROR in Main.groovy (at line 2)\n" +
"\tabstract def meth() {\n" +
"\t ^^^^^^\n" +
"The abstract method meth in type Main can only be defined by an abstract class\n" +
"----------\n" +
"4. ERROR in Main.groovy (at line 2)\n" +
"\tabstract def meth() {\n" +
"\t ^^^^^^\n" +
"Abstract methods do not specify a body\n" +
"----------\n" +
"5. ERROR in Main.groovy (at line 2)\n" +
"\tabstract def meth() {\n" +
"\t ^^^^^^\n" +
"Groovy:Can't have an abstract method in a non-abstract class. The class 'Main' must be declared abstract or the method 'java.lang.Object meth()' must not be abstract.\n" +
"----------\n");
}
}

@Test
Expand Down Expand Up @@ -1841,7 +1876,9 @@ public void testBreak_GRE290() {
"1. ERROR in p\\X.groovy (at line 2)\n" +
"\tbreak words\n" +
"\t^^^^^^^^^^^\n" +
"Groovy:the break statement with named label is only allowed inside loops\n" +
"Groovy:" + (!isParrotParser()
? "the break statement with named label is only allowed inside loops\n"
: "break statement is only allowed inside loops or switches @ line 2, column 3.\n") +
"----------\n");
}

Expand All @@ -1863,7 +1900,9 @@ public void testContinue_GRE291() {
"1. ERROR in ContinueTestCase.groovy (at line 3)\n" +
"\tcontinue;\n" +
"\t^^^^^^^^\n" +
"Groovy:the continue statement is only allowed inside loops\n" +
"Groovy:" + (!isParrotParser()
? "the continue statement is only allowed inside loops\n"
: "continue statement is only allowed inside loops @ line 3, column 5.\n") +
"----------\n");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2797,6 +2797,7 @@ public Expression visitPathElement(PathElementContext ctx) {
ctx);
}

/* GRECLIPSE edit
return configureAST(
new ConstructorCallExpression(
SUPER_STR.equals(baseExprText)
Expand All @@ -2805,6 +2806,13 @@ public Expression visitPathElement(PathElementContext ctx) {
argumentsExpr
),
ctx);
*/
ConstructorCallExpression constructorCallExpression = new ConstructorCallExpression(
SUPER_STR.equals(baseExprText) ? ClassNode.SUPER : ClassNode.THIS, argumentsExpr);
constructorCallExpression.setNameStart(baseExpr.getStart());
constructorCallExpression.setNameEnd(baseExpr.getEnd() - 1);
return configureAST(constructorCallExpression, ctx);
// GRECLIPSE end
}

MethodCallExpression methodCallExpression =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
import java.io.IOException;
import java.io.Reader;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -264,21 +262,24 @@ public void convert() throws CompilationFailedException {
}
catch (SyntaxException e) {
if (this.ast == null) {
// Create a dummy ModuleNode to represent a failed parse - in case a later phase attempts to use the ast
// create an empty ModuleNode to represent a failed parse, in case a later phase attempts to use the AST
this.ast = new ModuleNode(this);
}
getErrorCollector().addError(new SyntaxErrorMessage(e, this));
}
// GRECLIPSE add
catch (CompilationFailedException cfe) {
if (this.ast == null) {
// Create a dummy ModuleNode to represent a failed parse - in case a later phase attempts to use the ast
// create an empty ModuleNode to represent a failed parse, in case a later phase attempts to use the AST
this.ast = new ModuleNode(this);
}
throw cfe;
if (!getErrorCollector().hasErrors()) {
throw cfe;
}
}
// GRECLIPSE end

/* GRECLIPSE edit
String property = (String) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty("groovy.ast");
Expand All @@ -288,13 +289,14 @@ public Object run() {
if ("xml".equals(property)) {
saveAsXML(name, ast);
}
*/
}

/* GRECLIPSE edit
private static void saveAsXML(String name, ModuleNode ast) {
// GRECLIPSE edit
//XStreamUtils.serialize(name, ast);
// GRECLIPSE end
XStreamUtils.serialize(name, ast);
}
*/

//---------------------------------------------------------------------------
// SOURCE SAMPLING
Expand Down

0 comments on commit cedbbb9

Please sign in to comment.