Java Code Examples for com.intellij.psi.javadoc.PsiDocComment#getTags()

The following examples show how to use com.intellij.psi.javadoc.PsiDocComment#getTags() . 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: FlatJUnitGenerator.java    From java2typescript with Apache License 2.0 5 votes vote down vote up
private String generateTestSuite(StringBuilder sb, StringBuilder sbDev, PsiClass clazz) {
    boolean classInstanciated = false;
    for (PsiMethod method : clazz.getAllMethods()) {
        boolean ignore = false;
        PsiDocComment comment = method.getDocComment();
        if (comment != null) {
            PsiDocTag[] tags = comment.getTags();
            if (tags != null) {
                for (PsiDocTag tag : tags) {
                    if (tag.getName().equals(DocTagTranslator.IGNORE) && tag.getValueElement() != null && tag.getValueElement().getText().equals(DocTagTranslator.TS)) {
                        ignore = true;
                    }
                }
            }
        }
        if (!ignore) {
            PsiAnnotation testAnnot = method.getModifierList().findAnnotation("Test");
            if (testAnnot != null) {
                if (!classInstanciated) {
                    sb.append(instanciateClass(clazz));
                    sbDev.append(instanciateClassDev(clazz));
                    classInstanciated = true;
                }
                generateTestCall(sb, clazz, method);
                generateTestCallDev(sbDev, clazz, method);
            }
        }
    }
    if (classInstanciated) {
        sb.append("});\n\n");
        sbDev.append("} catch(err) {\n" +
                "\tconsole.error(err.stack);\n" +
                "}\n\n");
    }

    return sb.toString();
}
 
Example 2
Source File: SystemObject.java    From IntelliJDeodorant with MIT License 4 votes vote down vote up
private void inheritanceHierarchyMatchingWithStaticTypes(TypeCheckElimination typeCheckElimination,
                                                         CompleteInheritanceDetection inheritanceDetection) {
    List<PsiField> staticFields = typeCheckElimination.getStaticFields();
    String abstractClassType = typeCheckElimination.getAbstractClassType();
    InheritanceTree tree = null;
    if (abstractClassType != null) {
        tree = inheritanceDetection.getTree(abstractClassType);
    }
    if (tree != null) {
        DefaultMutableTreeNode rootNode = tree.getRootNode();
        DefaultMutableTreeNode leaf = rootNode.getFirstLeaf();
        List<String> inheritanceHierarchySubclassNames = new ArrayList<>();
        while (leaf != null) {
            inheritanceHierarchySubclassNames.add((String) leaf.getUserObject());
            leaf = leaf.getNextLeaf();
        }
        int matchCounter = 0;
        for (PsiField staticField : staticFields) {
            for (String subclassName : inheritanceHierarchySubclassNames) {
                ClassObject classObject = getClassObject(subclassName);
                PsiElement abstractTypeDeclaration = classObject.getAbstractTypeDeclaration();
                if (abstractTypeDeclaration instanceof PsiClass) {
                    PsiClass typeDeclaration = (PsiClass) abstractTypeDeclaration;
                    PsiDocComment javadoc = typeDeclaration.getDocComment();
                    if (javadoc != null) {
                        PsiDocTag[] tagElements = javadoc.getTags();
                        for (PsiDocTag tagElement : tagElements) {
                            tagElement.getName();
                            if ("see".equals(tagElement.getName())) {
                                PsiElement[] fragments = tagElement.getDataElements();
                                for (PsiElement fragment : fragments) {
                                    if (!(fragment instanceof PsiDocMethodOrFieldRef)) {
                                        continue;
                                    }
                                    PsiReference memberRef = fragment.getReference();
                                    if (memberRef == null) {
                                        continue;
                                    }
                                    PsiElement resolvedRef = memberRef.resolve();
                                    if (staticField.equals(resolvedRef)) {
                                        typeCheckElimination.putStaticFieldSubclassTypeMapping(staticField, subclassName);
                                        matchCounter++;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (matchCounter == staticFields.size()) {
            typeCheckElimination.setInheritanceTreeMatchingWithStaticTypes(tree);
        }
    }
}