From d3dac46edceeeaf89743ea23319687e85942adb7 Mon Sep 17 00:00:00 2001 From: Ramesh Reddy Date: Fri, 19 Sep 2014 10:49:14 -0500 Subject: [PATCH] OLINGO-434, OLINGO-435: Adding support to navigate Unary and Alias segements of parsed URL in UriParseTreeVisitor Signed-off-by: mibo --- .../core/uri/parser/UriParseTreeVisitor.java | 22 +++++++++++++++++++ .../core/uri/antlr/TestUriParserImpl.java | 7 ++++++ 2 files changed, 29 insertions(+) diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java index c23ae6860..ff19f3e0c 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java @@ -18,6 +18,7 @@ */ package org.apache.olingo.server.core.uri.parser; +import org.antlr.v4.runtime.misc.NotNull; import org.antlr.v4.runtime.misc.ParseCancellationException; import org.antlr.v4.runtime.tree.ParseTree; import org.apache.olingo.commons.api.edm.Edm; @@ -45,6 +46,7 @@ import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResourcePartTyped; import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind; import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind; +import org.apache.olingo.server.api.uri.queryoption.expression.UnaryOperatorKind; import org.apache.olingo.server.core.uri.UriInfoImpl; import org.apache.olingo.server.core.uri.UriParameterImpl; import org.apache.olingo.server.core.uri.UriResourceActionImpl; @@ -68,6 +70,7 @@ import org.apache.olingo.server.core.uri.UriResourceValueImpl; import org.apache.olingo.server.core.uri.UriResourceWithKeysImpl; import org.apache.olingo.server.core.uri.antlr.UriLexer; import org.apache.olingo.server.core.uri.antlr.UriParserBaseVisitor; +import org.apache.olingo.server.core.uri.antlr.UriParserParser; import org.apache.olingo.server.core.uri.antlr.UriParserParser.AllEOFContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.AllExprContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.AltAddContext; @@ -84,6 +87,7 @@ import org.apache.olingo.server.core.uri.antlr.UriParserParser.BatchEOFContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.BooleanNonCaseContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.CastExprContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.CeilingMethodCallExprContext; +import org.apache.olingo.server.core.uri.antlr.UriParserParser.CommonExprContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.ConcatMethodCallExprContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.ConstSegmentContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.ContainsMethodCallExprContext; @@ -153,6 +157,7 @@ import org.apache.olingo.server.core.uri.antlr.UriParserParser.TopContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.TotalOffsetMinutesMethodCallExprContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.TotalsecondsMethodCallExprContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.TrimMethodCallExprContext; +import org.apache.olingo.server.core.uri.antlr.UriParserParser.UnaryContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.YearMethodCallExprContext; import org.apache.olingo.server.core.uri.queryoption.CountOptionImpl; import org.apache.olingo.server.core.uri.queryoption.ExpandItemImpl; @@ -168,6 +173,7 @@ import org.apache.olingo.server.core.uri.queryoption.SkipOptionImpl; import org.apache.olingo.server.core.uri.queryoption.SkipTokenOptionImpl; import org.apache.olingo.server.core.uri.queryoption.SystemQueryOptionImpl; import org.apache.olingo.server.core.uri.queryoption.TopOptionImpl; +import org.apache.olingo.server.core.uri.queryoption.expression.AliasImpl; import org.apache.olingo.server.core.uri.queryoption.expression.BinaryImpl; import org.apache.olingo.server.core.uri.queryoption.expression.EnumerationImpl; import org.apache.olingo.server.core.uri.queryoption.expression.ExpressionImpl; @@ -175,6 +181,7 @@ import org.apache.olingo.server.core.uri.queryoption.expression.LiteralImpl; import org.apache.olingo.server.core.uri.queryoption.expression.MemberImpl; import org.apache.olingo.server.core.uri.queryoption.expression.MethodImpl; import org.apache.olingo.server.core.uri.queryoption.expression.TypeLiteralImpl; +import org.apache.olingo.server.core.uri.queryoption.expression.UnaryImpl; import java.util.ArrayList; import java.util.List; @@ -2156,4 +2163,19 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor { return new ParseCancellationException(uriParserException); } + @Override + public ExpressionImpl visitAltUnary(@NotNull UriParserParser.AltUnaryContext ctx) { + UnaryImpl unary = new UnaryImpl(); + unary.setOperator(ctx.unary().NOT() == null?UnaryOperatorKind.MINUS:UnaryOperatorKind.NOT); + unary.setOperand((ExpressionImpl)ctx.commonExpr().accept(this)); + return unary; + } + + @Override + public ExpressionImpl visitAltAlias(@NotNull UriParserParser.AltAliasContext ctx) { + AliasImpl alias = new AliasImpl(); + alias.setParameter("@"+ctx.odataIdentifier().getChild(0).getText()); + return alias; + } + } diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java index 844fdab3e..1ccebbb5b 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java @@ -576,6 +576,7 @@ public class TestUriParserImpl { testFilter.runESabc("a eq b or c and e eq f").isCompr("<< eq > or < and < eq >>>"); testFilter.runESabc("a eq b or c eq d and e ").isCompr("<< eq > or << eq > and >>"); testFilter.runESabc("a eq b or c eq d and e eq f").isCompr("<< eq > or << eq > and < eq >>>"); + testFilter.runESabc("not a").isCompr(">"); } @Test @@ -1052,6 +1053,12 @@ public class TestUriParserImpl { testUri.run("FICRTCollCTTwoPrimParam(ParameterInt16=1,ParameterString='2')/olingo.odata.test1.CTBase"); } + @Test + public void testAlias() throws Exception { + testUri.run("ESAllPrim?$filter=PropertyInt16 eq @p1&@p1=1)") + .goFilter().is("< eq <@p1>>"); + } + @Test public void testLambda() throws Exception { testUri.run("ESTwoKeyNav", "$filter=CollPropertyComp/all( l : true )")