Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Drill >> mail # dev >> [37/52] [abbrv] [partial] DRILL-165: Reorganize directories (moves only)


Copy link to this message
-
[37/52] [abbrv] [partial] DRILL-165: Reorganize directories (moves only)
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a593d908/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/MethodGrabbingVisitor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/MethodGrabbingVisitor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/MethodGrabbingVisitor.java
new file mode 100644
index 0000000..75a6ff2
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/MethodGrabbingVisitor.java
@@ -0,0 +1,63 @@
+package org.apache.drill.exec.expr.fn;
+
+import java.io.StringWriter;
+import java.util.Map;
+
+import org.codehaus.janino.Java;
+import org.codehaus.janino.Java.ClassDeclaration;
+import org.codehaus.janino.Java.MethodDeclarator;
+import org.codehaus.janino.UnparseVisitor;
+import org.codehaus.janino.util.Traverser;
+
+import com.google.common.collect.Maps;
+
+
+public class MethodGrabbingVisitor{
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(MethodGrabbingVisitor.class);
+  
+  private Class<?> c;
+  private Map<String, String> methods = Maps.newHashMap();
+  private ClassFinder classFinder = new ClassFinder();
+  private boolean captureMethods = false;
+  
+  private MethodGrabbingVisitor(Class<?> c) {
+    super();
+    this.c = c;
+  }
+  
+  public class ClassFinder extends Traverser{
+
+    @Override
+    public void traverseClassDeclaration(ClassDeclaration cd) {
+//      logger.debug("Traversing: {}", cd.getClassName());
+      boolean prevCapture = captureMethods;
+      captureMethods = c.getName().equals(cd.getClassName());
+      super.traverseClassDeclaration(cd);
+      captureMethods = prevCapture;
+    }
+
+    @Override
+    public void traverseMethodDeclarator(MethodDeclarator md) {
+//      logger.debug(c.getName() + ": Found {}, include {}", md.name, captureMethods);
+      
+      if(captureMethods){
+        StringWriter writer = new StringWriter();
+        ModifiedUnparseVisitor v = new ModifiedUnparseVisitor(writer);
+//        UnparseVisitor v = new UnparseVisitor(writer);
+        
+        md.accept(v);
+        v.close();
+        writer.flush();
+        methods.put(md.name, writer.getBuffer().toString());  
+      }
+    }
+  }
+
+  
+  public static Map<String, String> getMethods(Java.CompilationUnit cu, Class<?> c){
+    MethodGrabbingVisitor visitor = new MethodGrabbingVisitor(c);
+    cu.getPackageMemberTypeDeclarations()[0].accept(visitor.classFinder.comprehensiveVisitor());
+    return visitor.methods;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a593d908/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/ModifiedUnparseVisitor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/ModifiedUnparseVisitor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/ModifiedUnparseVisitor.java
new file mode 100644
index 0000000..be03bac
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/ModifiedUnparseVisitor.java
@@ -0,0 +1,895 @@
+package org.apache.drill.exec.expr.fn;
+
+
+/*
+ *
+ * Modified so that we can avoid printing some things.
+ *
+ * Janino - An embedded Java[TM] compiler
+ *
+ * Copyright (c) 2001-2010, Arno Unkrig
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
+ * following conditions are met:
+ *
+ *    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
+ *       following disclaimer.
+ *    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
+ *       following disclaimer in the documentation and/or other materials provided with the distribution.
+ *    3. The name of the author may not be used to endorse or promote products derived from this software without
+ *       specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.codehaus.janino.JaninoRuntimeException;
+import org.codehaus.janino.Java;
+import org.codehaus.janino.Mod;
+import org.codehaus.janino.Parser;
+import org.codehaus.janino.Scanner;
+import org.codehaus.janino.Visitor.ComprehensiveVisitor;
+import org.codehaus.janino.util.AutoIndentWriter;
+
+/**
+ * A visitor that unparses (un-compiles) an AST to a {@link Writer}. See
+ * {@link #main(String[])} for a usage example.
+ */
+public class ModifiedUnparseVisitor implements ComprehensiveVisitor {
+    protected final AutoIndentWriter aiw;
+    protected final PrintWriter      pw;
+
+    /**
+     * Testing of parsing/unparsing.
+     * <p>
+     * Reads compilation units from the files named on the command line
+     * and unparses them to {@link Sy