Search in sources :

Example 21 with JavaClass

use of com.thoughtworks.qdox.model.JavaClass in project maven-plugins by apache.

the class AbstractFixJavadocMojoTest method testReplaceLinkTags_OnlyAnchor.

public void testReplaceLinkTags_OnlyAnchor() throws Throwable {
    String comment = "/** There's a {@link #getClass()} but no setClass() */";
    String source = "import java.net.ConnectException;\n" + comment + "\n" + "public class OnlyAnchor {}";
    JavaClass clazz = getJavaSource(source).getClassByName("OnlyAnchor");
    String newComment = AbstractFixJavadocMojo.replaceLinkTags(comment, clazz);
    assertEquals("/** There's a {@link #getClass()} but no setClass() */", newComment);
}
Also used : JavaClass(com.thoughtworks.qdox.model.JavaClass)

Example 22 with JavaClass

use of com.thoughtworks.qdox.model.JavaClass in project arrow by NetEase.

the class NeXMLSuiteResultWriter method getTestMethodAttr.

private String getTestMethodAttr(String attr, String className, ITestNGMethod method) {
    logger.info("className = " + className);
    String value = "";
    JavaClass cls = builder.getClassByName(className);
    JavaMethod[] mtds = cls.getMethods();
    logger.info("JavaMethod = " + mtds.toString());
    for (JavaMethod mtd : mtds) {
        if (mtd.getName().equals(method.getMethodName())) {
            Annotation[] annotations = mtd.getAnnotations();
            logger.info("Annotation = " + annotations.toString());
            for (Annotation ant : annotations) {
                logger.info("Annotation.getClass().getName() = " + ant.getClass().getName());
                String clss = ant.getType().getFullyQualifiedName();
                if (clss.equals("org.testng.annotations.Test")) {
                    Map<String, String> map = ant.getNamedParameterMap();
                    if (map.containsKey(attr)) {
                        value = map.get(attr);
                        value = value.substring(1, value.length() - 1);
                    }
                }
            }
            break;
        }
    }
    return value;
}
Also used : JavaClass(com.thoughtworks.qdox.model.JavaClass) JavaMethod(com.thoughtworks.qdox.model.JavaMethod) Annotation(com.thoughtworks.qdox.model.Annotation)

Example 23 with JavaClass

use of com.thoughtworks.qdox.model.JavaClass in project arrow by NetEase.

the class NeXMLSuiteResultWriter method getAuthors.

/**
 * Get ITestNGMethod author(s) string, or class author(s) if no method author is present.
 * Default return value is "unknown".
 *
 * @param className
 * @param method
 * @return
 * @author hzjingcheng
 */
private String getAuthors(String className, ITestNGMethod method) {
    logger.info("className = " + className);
    JavaClass cls = builder.getClassByName(className);
    DocletTag[] authors = cls.getTagsByName("author");
    logger.info("authors = " + authors.toString());
    // get class authors as default author name
    String allAuthors = "";
    if (authors.length == 0) {
        allAuthors = "";
    } else {
        for (DocletTag author : authors) {
            allAuthors += author.getValue() + " ";
        }
    }
    // get method author name
    JavaMethod[] mtds = cls.getMethods();
    logger.info("JavaMethod = " + mtds.toString());
    for (JavaMethod mtd : mtds) {
        if (mtd.getName().equals(method.getMethodName())) {
            authors = mtd.getTagsByName("author");
            if (authors.length != 0) {
                allAuthors = "";
                for (DocletTag author : authors) {
                    allAuthors += author.getValue() + " ";
                }
            }
            break;
        }
    }
    return allAuthors.trim();
}
Also used : JavaClass(com.thoughtworks.qdox.model.JavaClass) JavaMethod(com.thoughtworks.qdox.model.JavaMethod) DocletTag(com.thoughtworks.qdox.model.DocletTag)

Example 24 with JavaClass

use of com.thoughtworks.qdox.model.JavaClass in project jsonschema2pojo by joelittlejohn.

the class JavaNameIT method originalPropertyNamesAppearInJavaDoc.

@Test
public void originalPropertyNamesAppearInJavaDoc() throws IOException {
    schemaRule.generateAndCompile("/schema/javaName/javaName.json", "com.example.javaname");
    File generatedJavaFile = schemaRule.generated("com/example/javaname/JavaName.java");
    JavaDocBuilder javaDocBuilder = new JavaDocBuilder();
    javaDocBuilder.addSource(generatedJavaFile);
    JavaClass classWithDescription = javaDocBuilder.getClassByName("com.example.javaname.JavaName");
    JavaField javaPropertyField = classWithDescription.getFieldByName("javaProperty");
    assertThat(javaPropertyField.getComment(), containsString("Corresponds to the \"propertyWithJavaName\" property."));
    JavaField javaEnumField = classWithDescription.getFieldByName("javaEnum");
    assertThat(javaEnumField.getComment(), containsString("Corresponds to the \"enumWithJavaName\" property."));
    JavaField javaObjectField = classWithDescription.getFieldByName("javaObject");
    assertThat(javaObjectField.getComment(), containsString("Corresponds to the \"objectWithJavaName\" property."));
}
Also used : JavaField(com.thoughtworks.qdox.model.JavaField) JavaClass(com.thoughtworks.qdox.model.JavaClass) File(java.io.File) JavaDocBuilder(com.thoughtworks.qdox.JavaDocBuilder) Test(org.junit.Test)

Example 25 with JavaClass

use of com.thoughtworks.qdox.model.JavaClass in project geronimo-xbean by apache.

the class QdoxMappingLoader method loadElements.

private List<ElementMapping> loadElements(JavaDocBuilder builder) {
    JavaSource[] javaSources = builder.getSources();
    List<ElementMapping> elements = new ArrayList<ElementMapping>();
    for (JavaSource javaSource : javaSources) {
        if (javaSource.getClasses().length == 0) {
            log.info("No Java Classes defined in: " + javaSource.getURL());
        } else {
            JavaClass[] classes = javaSource.getClasses();
            for (JavaClass javaClass : classes) {
                ElementMapping element = loadElement(builder, javaClass);
                if (element != null && !javaClass.isAbstract()) {
                    elements.add(element);
                } else {
                    log.debug("No XML annotation found for type: " + javaClass.getFullyQualifiedName());
                }
            }
        }
    }
    return elements;
}
Also used : JavaClass(com.thoughtworks.qdox.model.JavaClass) JavaSource(com.thoughtworks.qdox.model.JavaSource) ArrayList(java.util.ArrayList)

Aggregations

JavaClass (com.thoughtworks.qdox.model.JavaClass)48 AbstractInheritableJavaEntity (com.thoughtworks.qdox.model.AbstractInheritableJavaEntity)12 JavaMethod (com.thoughtworks.qdox.model.JavaMethod)12 DocletTag (com.thoughtworks.qdox.model.DocletTag)10 JavaDocBuilder (com.thoughtworks.qdox.JavaDocBuilder)6 File (java.io.File)6 StringReader (java.io.StringReader)6 JavaParameter (com.thoughtworks.qdox.model.JavaParameter)5 JavaSource (com.thoughtworks.qdox.model.JavaSource)5 ArrayList (java.util.ArrayList)5 JavaProjectBuilder (com.thoughtworks.qdox.JavaProjectBuilder)4 BeanProperty (com.thoughtworks.qdox.model.BeanProperty)4 JavaField (com.thoughtworks.qdox.model.JavaField)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Test (org.junit.Test)3 AbstractJavaEntity (com.thoughtworks.qdox.model.AbstractJavaEntity)2 JavaExecutable (com.thoughtworks.qdox.model.JavaExecutable)2 JavaMember (com.thoughtworks.qdox.model.JavaMember)2 JavaType (com.thoughtworks.qdox.model.JavaType)2