apex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hsy...@apache.org
Subject [1/2] incubator-apex-core git commit: APEX-127 #resolve #comment when a method has no comments and only omitFromUI tag than the super class method info was being used
Date Tue, 15 Sep 2015 19:25:06 GMT
Repository: incubator-apex-core
Updated Branches:
  refs/heads/devel-3 0936445bd -> 2cd917d9b


APEX-127 #resolve #comment when a method has no comments and only omitFromUI tag than the
super class method info was being used


Project: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/commit/b1666b77
Tree: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/tree/b1666b77
Diff: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/diff/b1666b77

Branch: refs/heads/devel-3
Commit: b1666b778b54667023f5beba43e07227eb90298b
Parents: c0baa9d
Author: Chandni Singh <csingh@apache.org>
Authored: Mon Sep 14 17:24:09 2015 -0700
Committer: Chandni Singh <csingh@apache.org>
Committed: Tue Sep 15 11:20:43 2015 -0700

----------------------------------------------------------------------
 .../stram/webapp/OperatorDiscoverer.java        | 66 ++++++++++++++------
 .../stram/webapp/OperatorDiscoveryTest.java     |  9 +++
 2 files changed, 56 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/b1666b77/engine/src/main/java/com/datatorrent/stram/webapp/OperatorDiscoverer.java
----------------------------------------------------------------------
diff --git a/engine/src/main/java/com/datatorrent/stram/webapp/OperatorDiscoverer.java b/engine/src/main/java/com/datatorrent/stram/webapp/OperatorDiscoverer.java
index f08a96b..5c2c580 100644
--- a/engine/src/main/java/com/datatorrent/stram/webapp/OperatorDiscoverer.java
+++ b/engine/src/main/java/com/datatorrent/stram/webapp/OperatorDiscoverer.java
@@ -25,7 +25,6 @@ import com.datatorrent.stram.webapp.asm.CompactFieldNode;
 import com.google.common.base.Predicate;
 import com.google.common.base.Splitter;
 import com.google.common.collect.Iterables;
-import com.google.common.collect.Iterators;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
@@ -75,8 +74,6 @@ public class OperatorDiscoverer
   public static final String PORT_TYPE_INFO_KEY = "portTypeInfo";
   private final TypeGraph typeGraph = TypeGraphFactory.createTypeGraphProtoType();
 
-  private static final String USE_SCHEMA_TAG = "@useSchema";
-  private static final String DESCRIPTION_TAG = "@description";
   private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\s+?");
 
   private static final String SCHEMA_REQUIRED_KEY = "schemaRequired";
@@ -88,7 +85,6 @@ public class OperatorDiscoverer
     final Map<String, String> tags = new HashMap<String, String>();
     final Map<String, MethodInfo> getMethods = Maps.newHashMap();
     final Map<String, MethodInfo> setMethods = Maps.newHashMap();
-    final Set<String> invisibleGetSetMethods = new HashSet<String>();
     final Map<String, String> fields = new HashMap<String, String>();
   }
 
@@ -97,6 +93,34 @@ public class OperatorDiscoverer
     Map<String, String> descriptions = Maps.newHashMap();
     Map<String, String> useSchemas = Maps.newHashMap();
     String comment;
+    boolean omitFromUI;
+  }
+
+  enum MethodTagType
+  {
+    USE_SCHEMA("@useSchema"),
+    DESCRIPTION("@description"),
+    OMIT_FROM_UI("@omitFromUI");
+
+    private static final Map<String, MethodTagType> TAG_TEXT_MAPPING = Maps.newHashMap();
+
+    static {
+      for (MethodTagType type : MethodTagType.values()) {
+        TAG_TEXT_MAPPING.put(type.tag, type);
+      }
+    }
+
+    private final String tag;
+
+    MethodTagType(String tag)
+    {
+      this.tag = tag;
+    }
+
+    static MethodTagType from(String tag)
+    {
+      return TAG_TEXT_MAPPING.get(tag);
+    }
   }
 
   private class JavadocSAXHandler extends DefaultHandler {
@@ -139,12 +163,9 @@ public class OperatorDiscoverer
             boolean lSetterCheck = !lGetterCheck && isSetter(methodName);
 
             if (lGetterCheck || lSetterCheck) {
-              if ("@omitFromUI".equals(tagName)) {
-                oci.invisibleGetSetMethods.add(methodName);
-              } else if (DESCRIPTION_TAG.equals(tagName)) {
-                addTagToMethod(lGetterCheck ? oci.getMethods : oci.setMethods, tagText, true);
-              } else if (USE_SCHEMA_TAG.equals(tagName)) {
-                addTagToMethod(lGetterCheck ? oci.getMethods : oci.setMethods, tagText, false);
+              MethodTagType type = MethodTagType.from(tagName);
+              if (type != null) {
+                addTagToMethod(lGetterCheck ? oci.getMethods : oci.setMethods, tagText, type);
               }
             }
 //            if ("@return".equals(tagName) && isGetter(methodName)) {
@@ -168,17 +189,21 @@ public class OperatorDiscoverer
       }
     }
 
-    private void addTagToMethod(Map<String, MethodInfo> methods, String tagText, boolean
isDescription)
+    private void addTagToMethod(Map<String, MethodInfo> methods, String tagText, MethodTagType
tagType)
     {
       MethodInfo mi = methods.get(methodName);
       if (mi == null) {
         mi = new MethodInfo();
         methods.put(methodName, mi);
       }
+      if (tagType == MethodTagType.OMIT_FROM_UI) {
+        mi.omitFromUI = true;
+        return;
+      }
       String[] tagParts = Iterables.toArray(Splitter.on(WHITESPACE_PATTERN).trimResults().omitEmptyStrings().
         limit(2).split(tagText), String.class);
       if (tagParts.length == 2) {
-        if (isDescription) {
+        if (tagType == MethodTagType.DESCRIPTION) {
           mi.descriptions.put(tagParts[0], tagParts[1]);
         } else {
           mi.useSchemas.put(tagParts[0], tagParts[1]);
@@ -388,7 +413,7 @@ public class OperatorDiscoverer
       }
     });
 
-    if (searchTerm == null && parent == Operator.class.getName()) {
+    if (searchTerm == null && parent.equals(Operator.class.getName())) {
       return filteredClass;
     }
 
@@ -398,7 +423,7 @@ public class OperatorDiscoverer
 
     Set<String> result = new HashSet<String>();
     for (String clazz : filteredClass) {
-      if (parent == Operator.class.getName() || typeGraph.isAncestor(parent, clazz)) {
+      if (parent.equals(Operator.class.getName()) || typeGraph.isAncestor(parent, clazz))
{
         if (searchTerm == null) {
           result.add(clazz);
         } else {
@@ -595,13 +620,16 @@ public class OperatorDiscoverer
         result.put(propJ);
         continue;
       }
-      if (oci.invisibleGetSetMethods.contains(getPrefix + propName) || oci.invisibleGetSetMethods.contains(setPrefix
+ propName)) {
+      MethodInfo setterInfo = oci.setMethods.get(setPrefix + propName);
+      MethodInfo getterInfo = oci.getMethods.get(getPrefix + propName);
+
+      if ((getterInfo != null && getterInfo.omitFromUI) || (setterInfo != null &&
setterInfo.omitFromUI)) {
         continue;
       }
-      MethodInfo methodInfo = oci.setMethods.get(setPrefix + propName);
-      methodInfo = methodInfo == null ? oci.getMethods.get(getPrefix + propName) : methodInfo;
-      if (methodInfo != null) {
-        addTagsToProperties(methodInfo, propJ);
+      if (setterInfo != null) {
+        addTagsToProperties(setterInfo, propJ);
+      } else if (getterInfo != null) {
+        addTagsToProperties(getterInfo, propJ);
       }
       result.put(propJ);
     }

http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/b1666b77/engine/src/test/java/com/datatorrent/stram/webapp/OperatorDiscoveryTest.java
----------------------------------------------------------------------
diff --git a/engine/src/test/java/com/datatorrent/stram/webapp/OperatorDiscoveryTest.java
b/engine/src/test/java/com/datatorrent/stram/webapp/OperatorDiscoveryTest.java
index 9af7d34..7dca6cd 100644
--- a/engine/src/test/java/com/datatorrent/stram/webapp/OperatorDiscoveryTest.java
+++ b/engine/src/test/java/com/datatorrent/stram/webapp/OperatorDiscoveryTest.java
@@ -1126,5 +1126,14 @@ public class OperatorDiscoveryTest
 
     Assert.assertEquals("number of port types with schema", 0, portsWithSchemaClasses.length());
   }
+
+  @Test
+  public void testMethodType()
+  {
+    Assert.assertEquals("@omitFromUI", OperatorDiscoverer.MethodTagType.OMIT_FROM_UI, OperatorDiscoverer.MethodTagType.from("@omitFromUI"));
+    Assert.assertEquals("@useSchema", OperatorDiscoverer.MethodTagType.USE_SCHEMA, OperatorDiscoverer.MethodTagType.from("@useSchema"));
+    Assert.assertEquals("@description", OperatorDiscoverer.MethodTagType.DESCRIPTION, OperatorDiscoverer.MethodTagType.from("@description"));
+    Assert.assertEquals("@random", null, OperatorDiscoverer.MethodTagType.from("@random"));
+  }
 }
 


Mime
View raw message