You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/10/06 19:37:28 UTC

git commit: OLINGO-434, OLINGO-435: Adding support to navigate Unary and Alias segements of parsed URL in UriParseTreeVisitor

Repository: olingo-odata4
Updated Branches:
  refs/heads/Olingo-434-435 [created] d3dac46ed


OLINGO-434, OLINGO-435: Adding support to navigate Unary and Alias segements of parsed URL in UriParseTreeVisitor

Signed-off-by: mibo <mi...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/d3dac46e
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/d3dac46e
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/d3dac46e

Branch: refs/heads/Olingo-434-435
Commit: d3dac46edceeeaf89743ea23319687e85942adb7
Parents: 9c60663
Author: Ramesh Reddy <ra...@jboss.org>
Authored: Fri Sep 19 10:49:14 2014 -0500
Committer: mibo <mi...@apache.org>
Committed: Mon Oct 6 19:35:20 2014 +0200

----------------------------------------------------------------------
 .../core/uri/parser/UriParseTreeVisitor.java    | 22 ++++++++++++++++++++
 .../core/uri/antlr/TestUriParserImpl.java       |  7 +++++++
 2 files changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d3dac46e/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
----------------------------------------------------------------------
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 c23ae68..ff19f3e 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<Object> {
     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;
+	}
+  
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d3dac46e/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
----------------------------------------------------------------------
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 844fdab..1ccebbb 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("<<<a> eq <b>> or < <c>         and <<e> eq <f>>>>");
     testFilter.runESabc("a eq b or c eq d and e     ").isCompr("<<<a> eq <b>> or <<<c> eq <d>> and  <e>      >>");
     testFilter.runESabc("a eq b or c eq d and e eq f").isCompr("<<<a> eq <b>> or <<<c> eq <d>> and <<e> eq <f>>>>");
+    testFilter.runESabc("not a").isCompr("<not <a>>");
   }
 
   @Test
@@ -1053,6 +1054,12 @@ public class TestUriParserImpl {
   }
 
   @Test
+  public void testAlias() throws Exception {
+    testUri.run("ESAllPrim?$filter=PropertyInt16 eq @p1&@p1=1)")
+        .goFilter().is("<<PropertyInt16> eq <@p1>>");
+  }  
+  
+  @Test
   public void testLambda() throws Exception {
     testUri.run("ESTwoKeyNav", "$filter=CollPropertyComp/all( l : true )")
         .goFilter().is("<CollPropertyComp/<ALL;<true>>>");