Skip to content

Commit

Permalink
Fix spurious firing of language parser assertion for expressions incl…
Browse files Browse the repository at this point in the history
…uding method type arguments (deephaven#4544)
  • Loading branch information
rbasralian authored Sep 26, 2023
1 parent ae625af commit e2eeab4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,23 @@ public Class<?> visit(MethodCallExpr n, VisitArgs printer) {
}
} else { // Groovy or Java method call (or explicit python call)
printer.append(scopePrinter);

// Print method type arguments, if specified.
// (The parser ignores these, but they must be printed so that the printer output matches the printed AST.)
final Optional<NodeList<com.github.javaparser.ast.type.Type>> methodTypeArgs = n.getTypeArguments();
if (methodTypeArgs.isPresent()) {
printer.append('<');
NodeList<com.github.javaparser.ast.type.Type> get = methodTypeArgs.get();
for (int i = 0; i < get.size(); i++) {
if (i > 0) {
printer.append(", ");
}
com.github.javaparser.ast.type.Type typeArg = get.get(i);
printer.append(typeArg.asString());
}
printer.append('>');
}

printer.append(methodName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package io.deephaven.engine.table.impl.lang;

import io.deephaven.base.Pair;
import io.deephaven.vector.IntVector;

import java.io.Serializable;
Expand Down Expand Up @@ -83,6 +84,10 @@ static public <T> T typedRef() {
return null;
}

static public <T, U> Pair<T, U> typedRefTwoTypes() {
return null;
}

static public <T> T typedRefWithCapture(T obj) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2576,7 +2576,6 @@ public void testComplexExpressions() throws Exception {
resultExpression =
"floatCast((eq(remainder(myInt, 14), 0) ? NULL_DOUBLE : eq(remainder(myInt, 10), 0) ? divide(1.0F, 0.0F) : eq(remainder(myInt, 5), 0) ? divide(negate(1.0F), 0.0F) : multiply(floatCast(intCast(myIntObj)), (minus(multiply(Math.random(), 2), 1)))))";
check(expression, resultExpression, float.class, new String[] {"myInt", "myIntObj"});

}

public void testUnsupportedOperators() throws Exception {
Expand Down Expand Up @@ -2932,6 +2931,17 @@ public void testGenericMethodCall() throws Exception {
String resultExpression = "LanguageParserDummyClass.typedRefWithCapture(\"hello\")";
check(expression, resultExpression, String.class, new String[] {});

// Call a generic method with explicit type arguments to ensure that the type arguments are printed.
// The type arguments (i.e., '<Object>'/'<Object, Object>') will be included in the output but not processed
// by the parser (that is why they must be set to 'Object' in this test).
expression = "LanguageParserDummyClass.<Object>typedRef()";
resultExpression = "LanguageParserDummyClass.<Object>typedRef()";
check(expression, resultExpression, Object.class, new String[] {});

expression = "LanguageParserDummyClass.<Object, Object>typedRefTwoTypes()";
resultExpression = "LanguageParserDummyClass.<Object, Object>typedRefTwoTypes()";
check(expression, resultExpression, Pair.class, new String[] {});

// // Call generic method with explicit type arguments:
// expression="LanguageParserDummyClass.<String>typedRef()";
// resultExpression="LanguageParserDummyClass.<String>typedRef()";
Expand Down

0 comments on commit e2eeab4

Please sign in to comment.