Beispiel #1
0
 /**
  * Determine if the program element is shown, according to the given level of visibility.
  *
  * @param ped The given program element.
  * @param visLevel The desired visibility level; "public", "protected", "package" or "private". If
  *     null, only check for an exclude tag.
  * @return boolean Set if this element is shown.
  */
 public boolean shownElement(Doc doc, String visLevel) {
   // If a doc block contains @exclude or a similar such tag,
   // then don't display it.
   if (doExclude && excludeTag != null && doc != null) {
     String rct = doc.getRawCommentText();
     if (rct != null && rct.indexOf(excludeTag) != -1) {
       return false;
     }
   }
   if (visLevel == null) {
     return true;
   }
   ProgramElementDoc ped = null;
   if (doc instanceof ProgramElementDoc) {
     ped = (ProgramElementDoc) doc;
   }
   if (visLevel.compareTo("private") == 0) return true;
   // Show all that is not private
   if (visLevel.compareTo("package") == 0) return !ped.isPrivate();
   // Show all that is not private or package
   if (visLevel.compareTo("protected") == 0) return !(ped.isPrivate() || ped.isPackagePrivate());
   // Show all that is not private or package or protected,
   // i.e. all that is public
   if (visLevel.compareTo("public") == 0) return ped.isPublic();
   return false;
 } // shownElement()
 /**
  * Add the modifier for the member.
  *
  * @param member the member to add the type for
  * @param code the content tree to which the modified will be added
  */
 private void addModifier(ProgramElementDoc member, Content code) {
   if (member.isProtected()) {
     code.addContent("protected ");
   } else if (member.isPrivate()) {
     code.addContent("private ");
   } else if (!member.isPublic()) { // Package private
     code.addContent(configuration.getText("doclet.Package_private"));
     code.addContent(" ");
   }
   if (member.isMethod()) {
     if (!(member.containingClass().isInterface()) && ((MethodDoc) member).isAbstract()) {
       code.addContent("abstract ");
     }
     // This check for isDefault() and the default modifier needs to be
     // added for it to appear on the "Modifier and Type" column in the
     // method summary section. Once the default modifier is added
     // to the Modifier list on DocEnv and once it is updated to use the
     // javax.lang.model.element.Modifier, we will need to remove this.
     if (((MethodDoc) member).isDefault()) {
       code.addContent("default ");
     }
   }
   if (member.isStatic()) {
     code.addContent("static ");
   }
 }
 /**
  * Return true if the given <code>ProgramElement</code> is inherited by the class that is being
  * documented.
  *
  * @param ped The <code>ProgramElement</code> being checked. return true if the <code>
  *     ProgramElement</code> is being inherited and false otherwise.
  */
 protected boolean isInherited(ProgramElementDoc ped) {
   if (ped.isPrivate()
       || (ped.isPackagePrivate()
           && !ped.containingPackage().equals(classdoc.containingPackage()))) {
     return false;
   }
   return true;
 }
 /**
  * Construct a new ConstructorWriterImpl.
  *
  * @param writer The writer for the class that the constructors belong to.
  * @param classDoc the class being documented.
  */
 public ConstructorWriterImpl(SubWriterHolderWriter writer, ClassDoc classDoc) {
   super(writer, classDoc);
   VisibleMemberMap visibleMemberMap =
       new VisibleMemberMap(classDoc, VisibleMemberMap.CONSTRUCTORS, configuration);
   List<ProgramElementDoc> constructors =
       new ArrayList<>(visibleMemberMap.getMembersFor(classDoc));
   for (ProgramElementDoc constructor : constructors) {
     if (constructor.isProtected() || constructor.isPrivate()) {
       setFoundNonPubConstructor(true);
     }
   }
 }
Beispiel #5
0
  /**
   * Add qualifiers for the program element as attributes.
   *
   * @param ped The given program element.
   */
  public void addCommonModifiers(ProgramElementDoc ped, int indent) {
    addSourcePosition(ped, indent);
    // Static and final and visibility on one line
    for (int i = 0; i < indent; i++) outputFile.print(" ");
    outputFile.print("static=\"" + ped.isStatic() + "\"");
    outputFile.print(" final=\"" + ped.isFinal() + "\"");
    // Visibility
    String visibility = null;
    if (ped.isPublic()) visibility = "public";
    else if (ped.isProtected()) visibility = "protected";
    else if (ped.isPackagePrivate()) visibility = "package";
    else if (ped.isPrivate()) visibility = "private";
    outputFile.println(" visibility=\"" + visibility + "\"");

    // Deprecation on its own line
    for (int i = 0; i < indent; i++) outputFile.print(" ");
    boolean isDeprecated = false;
    Tag[] ta = ((Doc) ped).tags("deprecated");
    if (ta.length != 0) {
      isDeprecated = true;
    }
    if (ta.length > 1) {
      System.out.println(
          "JDiff: warning: multiple @deprecated tags found in comments for "
              + ped.name()
              + ". Using the first one only.");
      System.out.println("Text is: " + ((Doc) ped).getRawCommentText());
    }
    if (isDeprecated) {
      String text = ta[0].text(); // Use only one @deprecated tag
      if (text != null && text.compareTo("") != 0) {
        int idx = endOfFirstSentence(text);
        if (idx == 0) {
          // No useful comment
          outputFile.print("deprecated=\"deprecated, no comment\"");
        } else {
          String fs = null;
          if (idx == -1) fs = text;
          else fs = text.substring(0, idx + 1);
          String st = API.hideHTMLTags(fs);
          outputFile.print("deprecated=\"" + st + "\"");
        }
      } else {
        outputFile.print("deprecated=\"deprecated, no comment\"");
      }
    } else {
      outputFile.print("deprecated=\"not deprecated\"");
    }
  } // addQualifiers()
 /** {@inheritDoc} */
 protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) {
   if (foundNonPubConstructor) {
     Content code = new HtmlTree(HtmlTag.CODE);
     if (member.isProtected()) {
       code.addContent("protected ");
     } else if (member.isPrivate()) {
       code.addContent("private ");
     } else if (member.isPublic()) {
       code.addContent(writer.getSpace());
     } else {
       code.addContent(configuration.getText("doclet.Package_private"));
     }
     tdSummaryType.addContent(code);
   }
 }
  /**
   * Returns string representation of scope
   *
   * @param doc
   * @return
   */
  protected static String DetermineScope(ProgramElementDoc doc) {
    ScopeModifier scope;

    if (doc.isPrivate()) {
      scope = ScopeModifier.PRIVATE;
    } else if (doc.isProtected()) {
      scope = ScopeModifier.PROTECTED;
    } else if (doc.isPackagePrivate()) {
      scope = ScopeModifier.PACKAGEPRIVATE;
    } else if (doc.isPublic()) {
      scope = ScopeModifier.PUBLIC;
    } else {
      log.error("No scope defined for: " + doc.name());
      scope = ScopeModifier.PACKAGEPRIVATE;
    }

    return scope.toString().toLowerCase();
  }