Search in sources :

Example 46 with JavaClass

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

the class AbstractFixJavadocMojoTest method testReplaceLinkTags_spacesAfterMethod.

public void testReplaceLinkTags_spacesAfterMethod() throws Throwable {
    String comment = "/** {@link ConnectException#getMessage()       } */";
    String source = "import java.net.ConnectException;\n" + comment + "\n" + "public class SpacesAfterMethod {}";
    JavaClass clazz = getJavaSource(source).getClassByName("SpacesAfterMethod");
    String newComment = AbstractFixJavadocMojo.replaceLinkTags(comment, clazz);
    assertEquals("/** {@link java.net.ConnectException#getMessage()} */", newComment);
}
Also used : JavaClass(com.thoughtworks.qdox.model.JavaClass)

Example 47 with JavaClass

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

the class AbstractFixJavadocMojoTest method testReplaceLinkTags_oneLinkTag.

public void testReplaceLinkTags_oneLinkTag() throws Throwable {
    String comment = "/** {@link ConnectException} */";
    String source = "import java.net.ConnectException;\n" + comment + "\n" + "public class OneLinkTag {}";
    JavaClass clazz = getJavaSource(source).getClassByName("OneLinkTag");
    String newComment = AbstractFixJavadocMojo.replaceLinkTags(comment, clazz);
    assertEquals("/** {@link java.net.ConnectException} */", newComment);
}
Also used : JavaClass(com.thoughtworks.qdox.model.JavaClass)

Example 48 with JavaClass

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

the class AbstractFixJavadocMojo method replaceLinkTags.

static String replaceLinkTags(String comment, JavaAnnotatedElement entity) {
    StringBuilder resolvedComment = new StringBuilder();
    // scan comment for {@link someClassName} and try to resolve this
    Matcher linktagMatcher = Pattern.compile("\\{@link\\s").matcher(comment);
    int startIndex = 0;
    while (linktagMatcher.find()) {
        int startName = linktagMatcher.end();
        resolvedComment.append(comment.substring(startIndex, startName));
        int endName = comment.indexOf("}", startName);
        if (endName >= 0) {
            String name;
            String link = comment.substring(startName, endName);
            int hashIndex = link.indexOf('#');
            if (hashIndex >= 0) {
                name = link.substring(0, hashIndex);
            } else {
                name = link;
            }
            if (StringUtils.isNotBlank(name)) {
                String typeName;
                if (entity instanceof JavaClass) {
                    JavaClass clazz = (JavaClass) entity;
                    typeName = TypeResolver.byClassName(clazz.getBinaryName(), clazz.getJavaClassLibrary(), clazz.getSource().getImports()).resolveType(name.trim());
                } else if (entity instanceof JavaMember) {
                    JavaClass clazz = ((JavaMember) entity).getDeclaringClass();
                    typeName = TypeResolver.byClassName(clazz.getBinaryName(), clazz.getJavaClassLibrary(), clazz.getSource().getImports()).resolveType(name.trim());
                } else {
                    typeName = null;
                }
                if (typeName == null) {
                    typeName = name.trim();
                } else {
                    typeName = typeName.replaceAll("\\$", ".");
                }
                // adjust name for inner classes
                resolvedComment.append(typeName);
            }
            if (hashIndex >= 0) {
                resolvedComment.append(link.substring(hashIndex).trim());
            }
            startIndex = endName;
        } else {
            startIndex = startName;
        }
    }
    resolvedComment.append(comment.substring(startIndex));
    return resolvedComment.toString();
}
Also used : JavaClass(com.thoughtworks.qdox.model.JavaClass) Matcher(java.util.regex.Matcher) JavaMember(com.thoughtworks.qdox.model.JavaMember)

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