Skip to content

Commit

Permalink
GROOVY-11374
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 13, 2024
1 parent 776e02f commit 7a98df5
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Collections;
import java.util.List;

import static org.codehaus.groovy.tools.Utilities.isJavaIdentifier;

/**
* A method call on an object or class.
*/
Expand All @@ -43,7 +45,6 @@ public class MethodCallExpression extends Expression implements MethodCall {

// type spec for generics
private GenericsType[] genericsTypes;
private boolean usesGenerics;

private MethodNode target;

Expand Down Expand Up @@ -132,12 +133,49 @@ public ASTNode getReceiver() {
}

public String getText() {
/* GRECLIPSE edit -- GROOVY-11374
String object = objectExpression.getText();
String meth = method.getText();
String args = arguments.getText();
String spread = spreadSafe ? "*" : "";
String dereference = safe ? "?" : "";
return object + spread + dereference + "." + meth + args;
*/
StringBuilder builder = new StringBuilder( 64 );
builder.append(getObjectExpression().getText());
if (isSpreadSafe()) builder.append('*');
if (isSafe()) builder.append('?');
builder.append('.');

if (isUsingGenerics()) {
builder.append('<');
boolean first = true;
for (GenericsType t : getGenericsTypes()) {
if (!first) builder.append(", ");
else first = false;
builder.append(t);
}
builder.append('>');
}

Expression method = getMethod();
if (method instanceof GStringExpression) {
builder.append('"').append(method.getText()).append('"');
} else if (!(method instanceof ConstantExpression)) {
builder.append('(').append(method.getText()).append(')');
} else {
Object value = ((ConstantExpression) method).getValue();
if (!(value instanceof String) || !isJavaIdentifier((String) value)) {
builder.append("'").append(value).append("'");
} else {
builder.append((String) value);
}
}

builder.append(getArguments().getText());

return builder.toString();
// GRECLIPSE end
}

/**
Expand Down Expand Up @@ -178,12 +216,11 @@ public GenericsType[] getGenericsTypes() {
}

public void setGenericsTypes(GenericsType[] genericsTypes) {
usesGenerics = usesGenerics || genericsTypes != null;
this.genericsTypes = genericsTypes;
}

public boolean isUsingGenerics() {
return usesGenerics;
return (genericsTypes != null && genericsTypes.length > 0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Collections;
import java.util.List;

import static org.codehaus.groovy.tools.Utilities.isJavaIdentifier;

/**
* A method call on an object or class.
*/
Expand All @@ -43,7 +45,6 @@ public class MethodCallExpression extends Expression implements MethodCall {

// type spec for generics
private GenericsType[] genericsTypes;
private boolean usesGenerics;

private MethodNode target;

Expand Down Expand Up @@ -138,12 +139,49 @@ public ASTNode getReceiver() {

@Override
public String getText() {
/* GRECLIPSE edit -- GROOVY-11374
String object = objectExpression.getText();
String meth = method.getText();
String args = arguments.getText();
String spread = spreadSafe ? "*" : "";
String dereference = safe ? "?" : "";
return object + spread + dereference + "." + meth + args;
*/
StringBuilder builder = new StringBuilder( 64 );
builder.append(getObjectExpression().getText());
if (isSpreadSafe()) builder.append('*');
if (isSafe()) builder.append('?');
builder.append('.');

if (isUsingGenerics()) {
builder.append('<');
boolean first = true;
for (GenericsType t : getGenericsTypes()) {
if (!first) builder.append(", ");
else first = false;
builder.append(t);
}
builder.append('>');
}

Expression method = getMethod();
if (method instanceof GStringExpression) {
builder.append('"').append(method.getText()).append('"');
} else if (!(method instanceof ConstantExpression)) {
builder.append('(').append(method.getText()).append(')');
} else {
Object value = ((ConstantExpression) method).getValue();
if (!(value instanceof String) || !isJavaIdentifier((String) value)) {
builder.append("'").append(value).append("'");
} else {
builder.append((String) value);
}
}

builder.append(getArguments().getText());

return builder.toString();
// GRECLIPSE end
}

/**
Expand Down Expand Up @@ -184,12 +222,11 @@ public GenericsType[] getGenericsTypes() {
}

public void setGenericsTypes(GenericsType[] genericsTypes) {
usesGenerics = usesGenerics || genericsTypes != null;
this.genericsTypes = genericsTypes;
}

public boolean isUsingGenerics() {
return usesGenerics;
return (genericsTypes != null && genericsTypes.length > 0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Collections;
import java.util.List;

import static org.codehaus.groovy.tools.Utilities.isJavaIdentifier;

/**
* A method call on an object or class.
*/
Expand All @@ -43,7 +45,6 @@ public class MethodCallExpression extends Expression implements MethodCall {

// type spec for generics
private GenericsType[] genericsTypes;
private boolean usesGenerics;

private MethodNode target;

Expand Down Expand Up @@ -138,12 +139,49 @@ public ASTNode getReceiver() {

@Override
public String getText() {
/* GRECLIPSE edit -- GROOVY-11374
String object = objectExpression.getText();
String meth = method.getText();
String args = arguments.getText();
String spread = spreadSafe ? "*" : "";
String dereference = safe ? "?" : "";
return object + spread + dereference + "." + meth + args;
*/
StringBuilder builder = new StringBuilder( 64 );
builder.append(getObjectExpression().getText());
if (isSpreadSafe()) builder.append('*');
if (isSafe()) builder.append('?');
builder.append('.');

if (isUsingGenerics()) {
builder.append('<');
boolean first = true;
for (GenericsType t : getGenericsTypes()) {
if (!first) builder.append(", ");
else first = false;
builder.append(t);
}
builder.append('>');
}

Expression method = getMethod();
if (method instanceof GStringExpression) {
builder.append('"').append(method.getText()).append('"');
} else if (!(method instanceof ConstantExpression)) {
builder.append('(').append(method.getText()).append(')');
} else {
Object value = ((ConstantExpression) method).getValue();
if (!(value instanceof String) || !isJavaIdentifier((String) value)) {
builder.append("'").append(value).append("'");
} else {
builder.append((String) value);
}
}

builder.append(getArguments().getText());

return builder.toString();
// GRECLIPSE end
}

/**
Expand Down Expand Up @@ -184,12 +222,11 @@ public GenericsType[] getGenericsTypes() {
}

public void setGenericsTypes(GenericsType[] genericsTypes) {
usesGenerics = usesGenerics || genericsTypes != null;
this.genericsTypes = genericsTypes;
}

public boolean isUsingGenerics() {
return usesGenerics;
return (genericsTypes != null && genericsTypes.length > 0);
}

/**
Expand Down

0 comments on commit 7a98df5

Please sign in to comment.