Java Code Examples for com.google.javascript.rhino.JSDocInfo#Visibility

The following examples show how to use com.google.javascript.rhino.JSDocInfo#Visibility . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Protos.java    From js-dossier with Apache License 2.0 6 votes vote down vote up
static void setVisibility(Visibility.Builder builder, JSDocInfo.Visibility visibility) {
  switch (visibility) {
    case PUBLIC:
      builder.setPublic(true);
      break;
    case PROTECTED:
      builder.setProtected(true);
      break;
    case PACKAGE:
      builder.setPackage(true);
      break;
    case PRIVATE:
      builder.setPrivate(true);
      break;
    default:
      throw new AssertionError("unexpected visibility: " + visibility);
  }
}
 
Example 2
Source File: TypeInspector.java    From js-dossier with Apache License 2.0 6 votes vote down vote up
private JSDocInfo.Visibility determineVisibility(
    PropertyDocs docs, Iterable<InstanceProperty> overrides) {
  JsDoc jsdoc = docs.getJsDoc();
  JSDocInfo.Visibility vis = jsdoc.getVisibility();
  if (vis == JSDocInfo.Visibility.INHERITED) {
    for (InstanceProperty superType : overrides) {
      vis = getVisibility(superType);
      if (vis != JSDocInfo.Visibility.INHERITED) {
        break;
      }
    }
  }
  if (vis == JSDocInfo.Visibility.INHERITED) {
    vis = registry.getDefaultVisibility(docs.getContextType().getSourceFile());
  }
  return vis;
}
 
Example 3
Source File: TypeInspector.java    From js-dossier with Apache License 2.0 5 votes vote down vote up
private JSDocInfo.Visibility getVisibility(InstanceProperty property) {
  JsDoc docs = property.getJsDoc();
  if (docs == null) {
    return JSDocInfo.Visibility.INHERITED;
  }
  return docs.getVisibility();
}
 
Example 4
Source File: RenderDocumentationTaskSupplier.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
private void addEnumValues(JsType.Builder spec) {
  if (!type.getType().isEnumType()) {
    return;
  }
  JSType elementType = ((EnumType) type.getType()).getElementsType();
  JSDocInfo.Visibility visibility = typeRegistry.getVisibility(type);

  Enumeration.Builder enumBuilder =
      spec.getEnumerationBuilder()
          .setType(
              expressionParserFactory
                  .create(linkFactory)
                  .parse(elementType.toMaybeEnumElementType().getPrimitiveType()));
  if (JSDocInfo.Visibility.PUBLIC != visibility) {
    Protos.setVisibility(enumBuilder.getVisibilityBuilder(), visibility);
  }

  // Type may be documented as an enum without an associated object literal for us to analyze:
  //     /** @enum {string} */ namespace.foo;
  List<Property> properties = typeInspector.getProperties(type);
  properties.sort(comparing(Property::getName));
  for (Property property : properties) {
    if (!property.getType().isEnumElementType()) {
      continue;
    }

    Node node = property.getNode();
    JSDocInfo valueInfo = node == null ? null : node.getJSDocInfo();

    Enumeration.Value.Builder valueBuilder =
        enumBuilder.addValueBuilder().setName(property.getName());

    if (valueInfo != null) {
      JsDoc valueJsDoc = JsDoc.from(valueInfo);
      valueBuilder.setDescription(
          parser.parseComment(valueJsDoc.getBlockComment(), linkFactory));

      if (valueJsDoc.isDeprecated()) {
        valueBuilder.setDeprecation(getDeprecation(valueJsDoc));
      }
    }
  }
}
 
Example 5
Source File: TypeInspector.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
private BaseProperty getBasePropertyDetails(
    String name,
    JSType type,
    Node node,
    PropertyDocs docs,
    @Nullable DefinedByType definedBy,
    Iterable<InstanceProperty> overrides) {
  BaseProperty.Builder builder =
      BaseProperty.newBuilder()
          .setName(name)
          .setDescription(findBlockComment(linkFactory, docs, overrides))
          .setSource(linkFactory.withTypeContext(docs.getContextType()).createSourceLink(node));

  if (registry.isModule(type)) {
    builder.getTagsBuilder().setIsModule(true);
  }

  if ("default".equals(name)
      && docs.getContextType() == inspectedType
      && inspectedType.isModuleExports()
      && inspectedType.getModule().map(Module::isEs6).orElse(false)) {
    builder.getTagsBuilder().setIsDefault(true);
  }

  if (definedBy != null) {
    if (definedBy.isInterface()) {
      builder.addSpecifiedBy(definedBy.getType());
    } else {
      builder.setDefinedBy(definedBy.getType());
    }
  }

  InstanceProperty immediateOverride = findFirstClassOverride(overrides);
  if (immediateOverride != null) {
    builder.setOverrides(getPropertyLink(docs.getContextType(), immediateOverride));
  }

  for (InstanceProperty property : findSpecifications(overrides)) {
    builder.addSpecifiedBy(getPropertyLink(docs.getContextType(), property));
  }

  JSDocInfo.Visibility visibility = determineVisibility(docs, overrides);
  if (JSDocInfo.Visibility.PUBLIC != visibility) {
    Protos.setVisibility(builder.getVisibilityBuilder(), visibility);
  }

  LinkFactory contextLinkFactory = linkFactory.withTypeContext(docs.getContextType());

  JsDoc jsdoc = docs.getJsDoc();
  if (jsdoc.isDeprecated()) {
    builder.getTagsBuilder().setIsDeprecated(true);
    builder.setDeprecation(parser.parseComment(jsdoc.getDeprecationReason(), contextLinkFactory));
  }

  for (String seeAlso : jsdoc.getSeeClauses()) {
    // 1) Try as a link reference to another type.
    @Nullable NamedType typeRef = contextLinkFactory.resolveTypeReference(seeAlso);
    if (typeRef != null && !urlString(typeRef.getLink().getHref()).isEmpty()) {
      builder.addSeeAlsoBuilder().addTokenBuilder().setText(seeAlso).setLink(typeRef.getLink());
      continue;
    }

    if (URI_PATTERN.matcher(seeAlso).matches()) {
      seeAlso = "<" + seeAlso + ">";
    }

    builder.addSeeAlso(parser.parseComment(seeAlso, contextLinkFactory));
  }

  if (!type.isFunctionType() && (jsdoc.isConst() || jsdoc.isDefine())) {
    builder.getTagsBuilder().setIsConst(true);
  }
  return builder.build();
}
 
Example 6
Source File: JsDoc.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
public JSDocInfo.Visibility getVisibility() {
  return info.getVisibility();
}