Skip to content

Commit

Permalink
Exclude generics from end position of qualified types
Browse files Browse the repository at this point in the history
Current source range for ClassNode with GenericsTypes:

    Map<X, Y> map
    ^^^

    Map.Entry<X,Y> entry
    ^^^^^^^^^^^^^^

#727
  • Loading branch information
eric-milles committed Jun 13, 2019
1 parent 2eea884 commit 061750c
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1448,13 +1448,13 @@ protected Parameter parameter(AST paramNode) {
ClassNode type = ClassHelper.DYNAMIC_TYPE;
if (isType(TYPE, node)) {
type = makeTypeWithArguments(node);
// GROOVY edit
// GRECLIPSE edit
//if (variableParameterDef) type = type.makeArray();
if (variableParameterDef) {
type = type.makeArray();
configureAST(type, node);
}
// GROOVY end
// GRECLIPSE end
node = node.getNextSibling();
}

Expand Down Expand Up @@ -3594,6 +3594,26 @@ protected ClassNode makeType(AST typeNode) {
// GRECLIPSE edit -- retain generics
//answer = makeType(node).makeArray();
answer = makeTypeWithArguments(node).makeArray();
configureAST(answer, node);
if (getController() != null) {
// check for trailing whitespace
GroovySourceAST root = (GroovySourceAST) node;
int start = locations.findOffset(root.getLine(), root.getColumn());
int until = locations.findOffset(root.getLineLast(), root.getColumnLast());
char[] sourceChars = getController().readSourceRange(start, until - start);
if (sourceChars != null) {
int idx = (sourceChars.length - 1), off = until;
while (idx >= 0 && Character.isWhitespace(sourceChars[idx])) {
idx -= 1; off -= 1;
}
if (off < until) {
int[] row_col = locations.getRowCol(off);
answer.setEnd(off);
answer.setLastLineNumber(row_col[0]);
answer.setLastColumnNumber(row_col[1]);
}
}
}
// GRECLIPSE end
} else {
answer = ClassHelper.make(qualifiedName(node));
Expand All @@ -3602,27 +3622,19 @@ protected ClassNode makeType(AST typeNode) {
newAnswer.setRedirect(answer);
answer = newAnswer;
}
}
// GRECLIPSE add
if (getController() != null) {
// check for trailing whitespace
GroovySourceAST root = (GroovySourceAST) node;
int start = locations.findOffset(root.getLine(), root.getColumn());
int until = locations.findOffset(root.getLineLast(), root.getColumnLast());
char[] sourceChars = getController().readSourceRange(start, until - start);
if (sourceChars != null) {
int idx = (sourceChars.length - 1), off = until;
while (idx >= 0 && Character.isWhitespace(sourceChars[idx])) {
idx -= 1; off -= 1;
}
if (off < until) {
int[] row_col = locations.getRowCol(off);
root.setLineLast(row_col[0]); root.setColumnLast(row_col[1]);
}
// GRECLIPSE add
configureAST(answer, node);
if (isType(DOT, node)) { // exclude generics from end position
GroovySourceAST type = (GroovySourceAST) node.getFirstChild().getNextSibling();
answer.setLastLineNumber(type.getLineLast());
answer.setLastColumnNumber(type.getColumnLast());
answer.setEnd(locations.findOffset(type.getLineLast(), type.getColumnLast()));
}
// GRECLIPSE end
}
// GRECLIPSE end
/* GRECLIPSE edit
configureAST(answer, node);
*/
}
return answer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1457,13 +1457,13 @@ protected Parameter parameter(AST paramNode) {
ClassNode type = ClassHelper.DYNAMIC_TYPE;
if (isType(TYPE, node)) {
type = makeTypeWithArguments(node);
// GROOVY edit
// GRECLIPSE edit
//if (variableParameterDef) type = type.makeArray();
if (variableParameterDef) {
type = type.makeArray();
configureAST(type, node);
}
// GROOVY end
// GRECLIPSE end
node = node.getNextSibling();
}

Expand Down Expand Up @@ -3611,6 +3611,26 @@ protected ClassNode makeType(AST typeNode) {
// GRECLIPSE edit -- retain generics
//answer = makeType(node).makeArray();
answer = makeTypeWithArguments(node).makeArray();
configureAST(answer, node);
if (getController() != null) {
// check for trailing whitespace
GroovySourceAST root = (GroovySourceAST) node;
int start = locations.findOffset(root.getLine(), root.getColumn());
int until = locations.findOffset(root.getLineLast(), root.getColumnLast());
char[] sourceChars = getController().readSourceRange(start, until - start);
if (sourceChars != null) {
int idx = (sourceChars.length - 1), off = until;
while (idx >= 0 && Character.isWhitespace(sourceChars[idx])) {
idx -= 1; off -= 1;
}
if (off < until) {
int[] row_col = locations.getRowCol(off);
answer.setEnd(off);
answer.setLastLineNumber(row_col[0]);
answer.setLastColumnNumber(row_col[1]);
}
}
}
// GRECLIPSE end
} else {
checkTypeArgs(node, false);
Expand All @@ -3620,27 +3640,19 @@ protected ClassNode makeType(AST typeNode) {
newAnswer.setRedirect(answer);
answer = newAnswer;
}
}
// GRECLIPSE add
if (getController() != null) {
// check for trailing whitespace
GroovySourceAST root = (GroovySourceAST) node;
int start = locations.findOffset(root.getLine(), root.getColumn());
int until = locations.findOffset(root.getLineLast(), root.getColumnLast());
char[] sourceChars = getController().readSourceRange(start, until - start);
if (sourceChars != null) {
int idx = (sourceChars.length - 1), off = until;
while (idx >= 0 && Character.isWhitespace(sourceChars[idx])) {
idx -= 1; off -= 1;
}
if (off < until) {
int[] row_col = locations.getRowCol(off);
root.setLineLast(row_col[0]); root.setColumnLast(row_col[1]);
}
// GRECLIPSE add
configureAST(answer, node);
if (isType(DOT, node)) { // exclude generics from end position
GroovySourceAST type = (GroovySourceAST) node.getFirstChild().getNextSibling();
answer.setLastLineNumber(type.getLineLast());
answer.setLastColumnNumber(type.getColumnLast());
answer.setEnd(locations.findOffset(type.getLineLast(), type.getColumnLast()));
}
// GRECLIPSE end
}
// GRECLIPSE end
/* GRECLIPSE edit
configureAST(answer, node);
*/
}
return answer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1219,9 +1219,10 @@ protected void methodDef(AST methodDef) {
methodNode = new MethodNode(name, modifiers, returnType, parameters, exceptions, code);
if ((modifiers & Opcodes.ACC_ABSTRACT) == 0) {
if (node == null) {
// GRECLIPSE edit
// throw new ASTRuntimeException(methodDef, "You defined a method without body. Try adding a body, or declare it abstract.");
//}
/* GRECLIPSE edit
throw new ASTRuntimeException(methodDef, "You defined a method without body. Try adding a body, or declare it abstract.");
}
*/
if (getController() != null) getController().addError(new SyntaxException(
"You defined a method without body. Try adding a body, or declare it abstract.", methodDef.getLine(), methodDef.getColumn()));
// create a fake node that can pretend to be the body
Expand Down Expand Up @@ -3707,6 +3708,26 @@ protected ClassNode makeType(AST typeNode) {
// GRECLIPSE edit -- retain generics
//answer = makeType(node).makeArray();
answer = makeTypeWithArguments(node).makeArray();
configureAST(answer, node);
if (getController() != null) {
// check for trailing whitespace
GroovySourceAST root = (GroovySourceAST) node;
int start = locations.findOffset(root.getLine(), root.getColumn());
int until = locations.findOffset(root.getLineLast(), root.getColumnLast());
char[] sourceChars = getController().readSourceRange(start, until - start);
if (sourceChars != null) {
int idx = (sourceChars.length - 1), off = until;
while (idx >= 0 && Character.isWhitespace(sourceChars[idx])) {
idx -= 1; off -= 1;
}
if (off < until) {
int[] row_col = locations.getRowCol(off);
answer.setEnd(off);
answer.setLastLineNumber(row_col[0]);
answer.setLastColumnNumber(row_col[1]);
}
}
}
// GRECLIPSE end
} else {
checkTypeArgs(node, false);
Expand All @@ -3716,27 +3737,19 @@ protected ClassNode makeType(AST typeNode) {
newAnswer.setRedirect(answer);
answer = newAnswer;
}
}
// GRECLIPSE add
if (getController() != null) {
// check for trailing whitespace
GroovySourceAST root = (GroovySourceAST) node;
int start = locations.findOffset(root.getLine(), root.getColumn());
int until = locations.findOffset(root.getLineLast(), root.getColumnLast());
char[] sourceChars = getController().readSourceRange(start, until - start);
if (sourceChars != null) {
int idx = (sourceChars.length - 1), off = until;
while (idx >= 0 && Character.isWhitespace(sourceChars[idx])) {
idx -= 1; off -= 1;
}
if (off < until) {
int[] row_col = locations.getRowCol(off);
root.setLineLast(row_col[0]); root.setColumnLast(row_col[1]);
}
// GRECLIPSE add
configureAST(answer, node);
if (isType(DOT, node)) { // exclude generics from end position
GroovySourceAST type = (GroovySourceAST) node.getFirstChild().getNextSibling();
answer.setLastLineNumber(type.getLineLast());
answer.setLastColumnNumber(type.getColumnLast());
answer.setEnd(locations.findOffset(type.getLineLast(), type.getColumnLast()));
}
// GRECLIPSE end
}
// GRECLIPSE end
/* GRECLIPSE edit
configureAST(answer, node);
*/
}
return answer;
}
Expand Down

0 comments on commit 061750c

Please sign in to comment.