Пример #1
0
  /** Extract the Type information from a TYPE node. */
  private static String _typeName(IterableTree ast) {
    if (ast == null) {
      return null;
    }
    StringBuilder typeName = new StringBuilder();

    if (ast.getType() == JavaParser.TYPE) {

      IterableTree qualifiedType = ast.firstChildOfType(JavaParser.QUALIFIED_TYPE_IDENT);

      if (qualifiedType != null) {
        StringBuilder qualifiedTypeName = new StringBuilder();
        for (int i = 0; i < qualifiedType.getChildCount(); i++) {
          qualifiedTypeName.append("." + qualifiedType.getChild(i).getText());

          IterableTree generics =
              qualifiedType.getChild(i).firstChildOfType(JavaParser.GENERIC_TYPE_ARG_LIST);
          if (generics != null) {
            qualifiedTypeName.append('<');
            qualifiedTypeName.append(_genericsTypeList(generics));
            qualifiedTypeName.append('>');
          }
        }
        /* to remove the leading dot */
        typeName.append(qualifiedTypeName.substring(1));
      } else {
        typeName.append(ast.getChild(0).getText());
      }

      Tree arrayDecl = ast.firstChildOfType(JavaParser.ARRAY_DECLARATOR_LIST);
      if (arrayDecl != null) {
        for (int i = 0; i < arrayDecl.getChildCount(); i++) {
          typeName.append("[]");
        }
      }

    } else if (ast.getType() == JavaParser.QUESTION) {
      typeName.append("?");

      if (ast.getChildCount() > 0) {
        /* ^(QUESTION ^(EXTENDS|SUPER type)) */
        IterableTree extendsAst = ast.getChild(0);
        typeName.append(" ");
        typeName.append(extendsAst.getText());
        typeName.append(" ");
        typeName.append(_typeName(extendsAst.getChild(0)));
      }
    }

    return typeName.toString();
  }
Пример #2
0
  /** Handle root node ^(JAVA_SOURCE ...) */
  private void __root(IterableTree ast) {
    IterableTree packageDecl = ast.firstChildOfType(JavaParser.PACKAGE);
    String packageName;
    if (packageDecl != null) {
      packageName = _dottedName(packageDecl.getChild(0));
    } else {
      packageName = "";
    }

    APIScope packageScope =
        new APIScope(
            packageName,
            language,
            _source(ast),
            Visibility.PUBLIC,
            scopeStack.peek(),
            null,
            null,
            null);
    ((APIScope) scopeStack.peek()).subScopes.add(packageScope);

    scopeStack.push(packageScope);
    walkChildren(ast, JavaParser.IMPORT);

    /* only one of these three will actually be walked */
    walk(ast.firstChildOfType(JavaParser.CLASS));
    walk(ast.firstChildOfType(JavaParser.INTERFACE));
    walk(ast.firstChildOfType(JavaParser.ENUM));
    scopeStack.pop();
  }
Пример #3
0
 private static String _dottedName(IterableTree ast) {
   StringBuilder buffer = new StringBuilder();
   switch (ast.getType()) {
     case JavaParser.IDENT:
       buffer.append(ast.getText());
       break;
     case JavaParser.DOT:
       buffer.append(_dottedName(ast.getChild(0)));
       buffer.append(".");
       buffer.append(_dottedName(ast.getChild(1)));
       break;
     default:
       break;
   }
   return buffer.toString();
 }
Пример #4
0
 /** Extract the modifiers from a MODIFIER_LIST node (without the "visibility" information) */
 private static Set<String> _javaModifiers(IterableTree ast) {
   Set<String> modifiers = new HashSet<String>();
   if (ast != null) {
     for (IterableTree child : ast) {
       switch (child.getType()) {
         case JavaParser.PUBLIC:
         case JavaParser.PRIVATE:
         case JavaParser.PROTECTED:
           break;
         case JavaParser.AT:
           modifiers.add("@" + _dottedName(child.getChild(0)));
           break;
         default:
           modifiers.add(child.getText());
       }
     }
   }
   return modifiers;
 }