com.sun.javadoc.Doc Java Examples

The following examples show how to use com.sun.javadoc.Doc. 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: SpecificationTaglet.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * @see com.sun.tools.doclets.internal.toolkit.taglets.Taglet#getTagletOutput(com.sun.javadoc.Doc, com.sun.tools.doclets.internal.toolkit.taglets.TagletWriter)
 */
@Override
public TagletOutput getTagletOutput(Doc doc, TagletWriter writer) throws IllegalArgumentException {
	Tag[] tags = doc.tags(getName());
	if (tags.length==0 && doc instanceof MethodDoc) { // inherit if necessary and possible
		final DocFinder.Output inheritedDoc = DocFinder.search(new DocFinder.Input((MethodDoc) doc, this));
		tags = inheritedDoc.holderTag == null ? tags : new Tag[] {inheritedDoc.holderTag};
	}
	if (tags.length==0)
		return null;
	final StringBuilder out = writeHeader(new StringBuilder());
	for(Tag tag : tags) { 
		writeTag(out, tag, writer);
	}
	return new TagletOutputImpl(out.toString());
}
 
Example #2
Source File: SpecificationTaglet.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Content getTagletOutput(Doc doc, TagletWriter writer) throws IllegalArgumentException {
	Tag[] tags = doc.tags(getName());
	if (tags.length==0 && doc instanceof MethodDoc) { // inherit if necessary and possible
		final DocFinder.Output inheritedDoc = DocFinder.search(new DocFinder.Input((MethodDoc) doc, this));
		tags = inheritedDoc.holderTag == null ? tags : new Tag[] {inheritedDoc.holderTag};
	}
	if (tags.length==0)
		return null;
	final StringBuilder out = writeHeader(new StringBuilder());
	for(Tag tag : tags) { 
		writeTag(out, tag, writer);
	}
	return new RawHtml(out.toString());
}
 
Example #3
Source File: DefaultApidocExcluder.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isExcluded(Doc doc) {
	if (Utils.isHiddenMember(doc.name())) {
		return true;
	}
	if (doc.tags(EXCLUDE_FROM_JAVADOC_TAG).length > 0) {
		return true;
	}
	if (doc instanceof ProgramElementDoc) {
		final ProgramElementDoc element = (ProgramElementDoc) doc;
		if (element.containingPackage().tags(EXCLUDE_FROM_JAVADOC_TAG).length > 0) {
			return true;
		}
		if (Utils.findFirst(element.annotations(), it ->
			Utils.qualifiedNameEquals(
					Utils.getKeywords().getSyntheticMemberAnnotationName(),
					it.annotationType().qualifiedName())) != null) {
			return true;
		}
	}
	// nothing above found a reason to exclude
	return false;
}
 
Example #4
Source File: RootDocProcessor.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
private static boolean exclude( Doc doc )
{
    AnnotationDesc[] annotations = null;
    if ( doc instanceof ProgramElementDoc )
    {
        annotations = ( (ProgramElementDoc) doc ).annotations();
    }
    else if ( doc instanceof PackageDoc )
    {
        annotations = ( (PackageDoc) doc ).annotations();
    }
    if ( annotations != null )
    {
        for ( AnnotationDesc annotation : annotations )
        {
            String qualifiedTypeName = annotation.annotationType().qualifiedTypeName();
            if ( qualifiedTypeName.equals( JavadocExclude.class.getCanonicalName() ) )
            {
                return true;
            }
        }
    }
    // nothing above found a reason to exclude
    return false;
}
 
Example #5
Source File: SarlLinkFactory.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Build the link for the type variable.
 *
 * @param link the link.
 * @param linkInfo the information on the link.
 * @param type the type.
 */
protected void getLinkForTypeVariable(Content link, LinkInfo linkInfo, Type type) {
	link.addContent(getTypeAnnotationLinks(linkInfo));
	linkInfo.isTypeBound = true;
	final Doc owner = type.asTypeVariable().owner();
	if ((!linkInfo.excludeTypeParameterLinks) && owner instanceof ClassDoc) {
		linkInfo.classDoc = (ClassDoc) owner;
		final Content label = newContent();
		label.addContent(type.typeName());
		linkInfo.label = label;
		link.addContent(getClassLink(linkInfo));
	} else {
		link.addContent(type.typeName());
	}
	final Type[] bounds = type.asTypeVariable().bounds();
	if (!linkInfo.excludeTypeBounds) {
		linkInfo.excludeTypeBounds = true;
		final SARLFeatureAccess kw = Utils.getKeywords();
		for (int i = 0; i < bounds.length; ++i) {
			link.addContent(i > 0 ? " " + kw.getAmpersandKeyword() + " " //$NON-NLS-1$ //$NON-NLS-2$
					: " " + kw.getExtendsKeyword() + " "); //$NON-NLS-1$ //$NON-NLS-2$
			setBoundsLinkInfo(linkInfo, bounds[i]);
			link.addContent(getLink(linkInfo));
		}
	}
}
 
Example #6
Source File: Doclava.java    From doclava with Apache License 2.0 6 votes vote down vote up
/**
 * Filters out hidden elements.
 */
private static Object filterHidden(Object o, Class<?> expected) {
  if (o == null) {
    return null;
  }

  Class<?> type = o.getClass();
  if (type.getName().startsWith("com.sun.")) {
    // TODO: Implement interfaces from superclasses, too.
    return Proxy
        .newProxyInstance(type.getClassLoader(), type.getInterfaces(), new HideHandler(o));
  } else if (o instanceof Object[]) {
    Class<?> componentType = expected.getComponentType();
    Object[] array = (Object[]) o;
    List<Object> list = new ArrayList<Object>(array.length);
    for (Object entry : array) {
      if ((entry instanceof Doc) && isHidden((Doc) entry)) {
        continue;
      }
      list.add(filterHidden(entry, componentType));
    }
    return list.toArray((Object[]) Array.newInstance(componentType, list.size()));
  } else {
    return o;
  }
}
 
Example #7
Source File: RootDocProcessor.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static Object[] filter(Doc[] array, Class<?> componentType) {
     if (array == null || array.length == 0) {
return array;
     }
     List<Object> list = new ArrayList<Object>(array.length);
     for (Doc entry : array) {
if (!exclude(entry)) {
  list.add(process(entry, componentType));
}
     }
     return list.toArray((Object[]) Array.newInstance(componentType, list
  .size()));
   }
 
Example #8
Source File: TodoTagRenderer.java    From markdown-doclet with GNU General Public License v3.0 5 votes vote down vote up
private Counter getCounter(Doc doc) {
    Counter counter = counters.get(doc);
    if ( counter == null ) {
        counter = new Counter();
        counters.put(doc, counter);
    }
    return counter;
}
 
Example #9
Source File: RootDocProcessor.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static Object[] filter(Doc[] array, Class<?> componentType) {
     if (array == null || array.length == 0) {
return array;
     }
     List<Object> list = new ArrayList<Object>(array.length);
     for (Doc entry : array) {
if (!exclude(entry)) {
  list.add(process(entry, componentType));
}
     }
     return list.toArray((Object[]) Array.newInstance(componentType, list
  .size()));
   }
 
Example #10
Source File: ExcludeDoclet.java    From Tehreer-Android with Apache License 2.0 5 votes vote down vote up
private static Object process(Object obj, Class<?> expect) {
    if (obj == null) {
        return null;
    }

    Class<?> clazz = obj.getClass();
    if (clazz.getName().startsWith("com.sun.")) {
        return Proxy.newProxyInstance(clazz.getClassLoader(),
                clazz.getInterfaces(), new ExcludeHandler(obj));
    }

    if (obj instanceof Object[]) {
        Class<?> componentType = expect.getComponentType();
        Object[] array = (Object[]) obj;
        List<Object> list = new ArrayList<>(array.length);

        for (int i = 0; i < array.length; i++) {
            Object entry = array[i];
            if ((entry instanceof Doc) && exclude((Doc) entry)) {
                continue;
            }

            list.add(process(entry, componentType));
        }

        return list.toArray((Object[]) Array.newInstance(componentType, list.size()));
    }

    return obj;
}
 
Example #11
Source File: ExcludeDoclet.java    From Tehreer-Android with Apache License 2.0 5 votes vote down vote up
private static boolean exclude(Doc doc) {
    if (doc.tags(TAG_HIDE).length > 0) {
        return true;
    }
    if (doc instanceof ProgramElementDoc) {
        if (((ProgramElementDoc) doc).containingPackage().tags(TAG_HIDE).length > 0) {
            return true;
        }
    }

    return false;
}
 
Example #12
Source File: MarkdownDoclet.java    From markdown-doclet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Default processing of any documentation node.
 *
 * @param doc              The documentation.
 * @param fixLeadingSpaces `true` if leading spaces should be fixed.
 *
 * @see Options#toHtml(String, boolean)
 */
protected void defaultProcess(Doc doc, boolean fixLeadingSpaces) {
    try {
        StringBuilder buf = new StringBuilder();
        buf.append(getOptions().toHtml(doc.commentText(), fixLeadingSpaces));
        buf.append('\n');
        for ( Tag tag : doc.tags() ) {
            processTag(tag, buf);
            buf.append('\n');
        }
        doc.setRawCommentText(buf.toString());
    }
    catch ( final ParserRuntimeException e ) {
        if ( doc instanceof RootDoc ) {
            printError(new SourcePosition() {
                @Override
                public File file() {
                    return options.getOverviewFile();
                }
                @Override
                public int line() {
                    return 0;
                }
                @Override
                public int column() {
                    return 0;
                }
            }, e.getMessage());
        }
        else {
            printError(doc.position(), e.getMessage());
        }
    }
}
 
Example #13
Source File: RootDocProcessor.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
private static Object process( Object obj, Class<?> type )
{
    if ( obj == null )
        return null;
    Class<?> cls = obj.getClass();
    if ( cls.getName().startsWith( "com.sun." ) )
    {
        return Proxy.newProxyInstance( cls.getClassLoader(), cls.getInterfaces(), new ExcludeHandler( obj ) );
    }
    else if ( obj instanceof Object[] )
    {
        Class<?> componentType = type.isArray() ? type.getComponentType() : cls.getComponentType();
        Object[] array = (Object[]) obj;
        List<Object> list = new ArrayList<>( array.length );
        for ( Object entry : array )
        {
            if ( ( entry instanceof Doc ) && exclude( (Doc) entry ) )
            {
                continue;
            }
            list.add( process( entry, componentType ) );
        }
        return list.toArray( (Object[]) Array.newInstance( componentType, list.size() ) );
    }
    else
    {
        return obj;
    }
}
 
Example #14
Source File: DefaultApidocExcluder.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isTranslatableToTag(Doc doc) {
	if (doc instanceof ProgramElementDoc) {
		final ProgramElementDoc element = (ProgramElementDoc) doc;
		if (Utils.findFirst(element.annotations(), it ->
			Utils.qualifiedNameEquals(
					Utils.getKeywords().getSyntheticMemberAnnotationName(),
					it.annotationType().qualifiedName())) != null) {
			return true;
		}
	}
	return false;
}
 
Example #15
Source File: Doclava.java    From doclava with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the given element is hidden.
 */
private static boolean isHidden(Doc doc) {
  // Methods, fields, constructors.
  if (doc instanceof MemberDoc) {
    return hasHideAnnotation(doc);
  }

  // Classes, interfaces, enums, annotation types.
  if (doc instanceof ClassDoc) {
    ClassDoc classDoc = (ClassDoc) doc;

    // Check the containing package.
    if (hasHideAnnotation(classDoc.containingPackage())) {
      return true;
    }

    // Check the class doc and containing class docs if this is a
    // nested class.
    ClassDoc current = classDoc;
    do {
      if (hasHideAnnotation(current)) {
        return true;
      }

      current = current.containingClass();
    } while (current != null);
  }

  return false;
}
 
Example #16
Source File: DocCommentProcessor.java    From markdown-doclet with GNU General Public License v3.0 4 votes vote down vote up
private void renderSeeTag(MarkdownDoclet doclet, StringBuilder tagBlock, PsiDocTag docTag) {
    final String seeText = toString(docTag, false);
    if ( seeText.startsWith("\"") ) {
        SeeTag tag = new SeeTag() {
            @Override
            public String label() {
                return null;
            }
            @Override
            public PackageDoc referencedPackage() {
                return null;
            }
            @Override
            public String referencedClassName() {
                return null;
            }
            @Override
            public ClassDoc referencedClass() {
                return null;
            }
            @Override
            public String referencedMemberName() {
                return null;
            }
            @Override
            public MemberDoc referencedMember() {
                return null;
            }
            @Override
            public String name() {
                return "@see";
            }
            @Override
            public Doc holder() {
                return null;
            }
            @Override
            public String kind() {
                return "@see";
            }
            @Override
            public String text() {
                return seeText;
            }
            @Override
            public Tag[] inlineTags() {
                return new Tag[0];
            }
            @Override
            public Tag[] firstSentenceTags() {
                return new Tag[0];
            }
            @Override
            public SourcePosition position() {
                return null;
            }
        };
        SeeTagRenderer.INSTANCE.render(tag, tagBlock, doclet);
    }
    else {
        tagBlock.append("\n@").append(docTag.getName());
        tagBlock.append(' ').append(seeText);
    }
}
 
Example #17
Source File: Doclava.java    From doclava with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if the given element has an @hide or @pending annotation.
 */
private static boolean hasHideAnnotation(Doc doc) {
  String comment = doc.getRawCommentText();
  return comment.indexOf("@hide") != -1 || comment.indexOf("@pending") != -1;
}
 
Example #18
Source File: ProgrammaticWrappingProxyInstaller.java    From sarl with Apache License 2.0 4 votes vote down vote up
private boolean isIncluded(Doc element) {
	return !this.configuration.getApidocExcluder().isExcluded(element);
}
 
Example #19
Source File: RootDocProcessor.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
   public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
     String methodName = method.getName();
     if (target instanceof Doc) {
if (methodName.equals("isIncluded")) {
  Doc doc = (Doc) target;
  return !exclude(doc) && doc.isIncluded();
}
if (target instanceof RootDoc) {
  if (methodName.equals("classes")) {
    return filter(((RootDoc) target).classes(), ClassDoc.class);
  } else if (methodName.equals("specifiedClasses")) {
    return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class);
  } else if (methodName.equals("specifiedPackages")) {
    return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class);
  }
} else if (target instanceof ClassDoc) {
  if (isFiltered(args)) {
    if (methodName.equals("methods")) {
      return filter(((ClassDoc) target).methods(true), MethodDoc.class);
    } else if (methodName.equals("fields")) {
      return filter(((ClassDoc) target).fields(true), FieldDoc.class);
    } else if (methodName.equals("innerClasses")) {
      return filter(((ClassDoc) target).innerClasses(true),
	  ClassDoc.class);
    } else if (methodName.equals("constructors")) {
      return filter(((ClassDoc) target).constructors(true),
	  ConstructorDoc.class);
    }
  }
} else if (target instanceof PackageDoc) {
  if (methodName.equals("allClasses")) {
    if (isFiltered(args)) {
      return filter(((PackageDoc) target).allClasses(true),
	ClassDoc.class);
    } else {
      return filter(((PackageDoc) target).allClasses(), ClassDoc.class);  
    }
  } else if (methodName.equals("annotationTypes")) {
    return filter(((PackageDoc) target).annotationTypes(),
	AnnotationTypeDoc.class);
  } else if (methodName.equals("enums")) {
    return filter(((PackageDoc) target).enums(),
	ClassDoc.class);
  } else if (methodName.equals("errors")) {
    return filter(((PackageDoc) target).errors(),
	ClassDoc.class);
  } else if (methodName.equals("exceptions")) {
    return filter(((PackageDoc) target).exceptions(),
	ClassDoc.class);
  } else if (methodName.equals("interfaces")) {
    return filter(((PackageDoc) target).interfaces(),
	ClassDoc.class);
  } else if (methodName.equals("ordinaryClasses")) {
    return filter(((PackageDoc) target).ordinaryClasses(),
	ClassDoc.class);
  }
}
     }

     if (args != null) {
if (methodName.equals("compareTo") || methodName.equals("equals")
    || methodName.equals("overrides")
    || methodName.equals("subclassOf")) {
  args[0] = unwrap(args[0]);
}
     }
     try {
return process(method.invoke(target, args), method.getReturnType());
     } catch (InvocationTargetException e) {
throw e.getTargetException();
     }
   }
 
Example #20
Source File: RootDocProcessor.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
   public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
     String methodName = method.getName();
     if (target instanceof Doc) {
if (methodName.equals("isIncluded")) {
  Doc doc = (Doc) target;
  return !exclude(doc) && doc.isIncluded();
}
if (target instanceof RootDoc) {
  if (methodName.equals("classes")) {
    return filter(((RootDoc) target).classes(), ClassDoc.class);
  } else if (methodName.equals("specifiedClasses")) {
    return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class);
  } else if (methodName.equals("specifiedPackages")) {
    return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class);
  }
} else if (target instanceof ClassDoc) {
  if (isFiltered(args)) {
    if (methodName.equals("methods")) {
      return filter(((ClassDoc) target).methods(true), MethodDoc.class);
    } else if (methodName.equals("fields")) {
      return filter(((ClassDoc) target).fields(true), FieldDoc.class);
    } else if (methodName.equals("innerClasses")) {
      return filter(((ClassDoc) target).innerClasses(true),
	  ClassDoc.class);
    } else if (methodName.equals("constructors")) {
      return filter(((ClassDoc) target).constructors(true),
	  ConstructorDoc.class);
    }
  }
} else if (target instanceof PackageDoc) {
  if (methodName.equals("allClasses")) {
    if (isFiltered(args)) {
      return filter(((PackageDoc) target).allClasses(true),
	ClassDoc.class);
    } else {
      return filter(((PackageDoc) target).allClasses(), ClassDoc.class);  
    }
  } else if (methodName.equals("annotationTypes")) {
    return filter(((PackageDoc) target).annotationTypes(),
	AnnotationTypeDoc.class);
  } else if (methodName.equals("enums")) {
    return filter(((PackageDoc) target).enums(),
	ClassDoc.class);
  } else if (methodName.equals("errors")) {
    return filter(((PackageDoc) target).errors(),
	ClassDoc.class);
  } else if (methodName.equals("exceptions")) {
    return filter(((PackageDoc) target).exceptions(),
	ClassDoc.class);
  } else if (methodName.equals("interfaces")) {
    return filter(((PackageDoc) target).interfaces(),
	ClassDoc.class);
  } else if (methodName.equals("ordinaryClasses")) {
    return filter(((PackageDoc) target).ordinaryClasses(),
	ClassDoc.class);
  }
}
     }

     if (args != null) {
if (methodName.equals("compareTo") || methodName.equals("equals")
    || methodName.equals("overrides")
    || methodName.equals("subclassOf")) {
  args[0] = unwrap(args[0]);
}
     }
     try {
return process(method.invoke(target, args), method.getReturnType());
     } catch (InvocationTargetException e) {
throw e.getTargetException();
     }
   }
 
Example #21
Source File: ApidocExcluder.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Replies if the given documented element should be translated to a tag.
 *
 * @param doc the element.
 * @return {@code true} if the element should be translated.
 */
boolean isTranslatableToTag(Doc doc);
 
Example #22
Source File: ApidocExcluder.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Replies if the given documented element should be excluded from the documentation.
 *
 * @param doc the element.
 * @return {@code true} if the element should be excluded.
 */
boolean isExcluded(Doc doc);