Java Code Examples for com.siyeh.ig.psiutils.ClassUtils

The following examples show how to use com.siyeh.ig.psiutils.ClassUtils. These examples are extracted from open source projects. 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 Project: KodeBeagle   Source File: PsiJavaElementVisitor.java    License: Apache License 2.0 6 votes vote down vote up
private void visitPsiFields(final PsiField psiField) {
    if (!ClassUtils.isPrimitive(psiField.getType())) {
        String type = removeSpecialSymbols(psiField.getType().getCanonicalText());
        if (psiField.getInitializer() != null) {
            PsiExpression psiExpression = psiField.getInitializer();
            if (psiExpression != null) {
                PsiType psiType = psiExpression.getType();
                if (psiType != null && !ClassUtils.isPrimitive(psiType)) {
                    String psiFieldInitializer =
                            removeSpecialSymbols(psiType.getCanonicalText());
                    addInMap(psiFieldInitializer, emptySet);
                }
            }
        }
        addInMap(type, emptySet);
    }
}
 
Example 2
Source Project: HakunaMatataIntelliJPlugin   Source File: ImportUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the current context has a static member import, either on-demand or explicit.
 *
 * @param fqClassName The class to import from
 * @param memberName  The class member to import
 * @param context     The context to be imported into
 */
public static boolean hasImportStatic(String fqClassName, String memberName, PsiElement context) {
    final PsiFile file = context.getContainingFile();
    if (!(file instanceof PsiJavaFile)) {
        return false;
    }
    final PsiJavaFile javaFile = (PsiJavaFile) file;
    final PsiImportList importList = javaFile.getImportList();
    if (importList == null) {
        return false;
    }
    final PsiImportStaticStatement[] importStaticStatements = importList.getImportStaticStatements();
    for (PsiImportStaticStatement importStaticStatement : importStaticStatements) {
        if (importStaticStatement.isOnDemand()) {
            PsiClass psiClass = ClassUtils.findClass(fqClassName, context);
            if (psiClass != null && psiClass.equals(importStaticStatement.resolveTargetClass())) {
                return true;
            }
            continue;
        }
        final String name = importStaticStatement.getReferenceName();
        if (!memberName.equals(name)) {
            continue;
        }
        final PsiJavaCodeReferenceElement importReference = importStaticStatement.getImportReference();
        if (importReference == null) {
            continue;
        }
        final PsiElement qualifier = importReference.getQualifier();
        if (qualifier == null) {
            continue;
        }
        final String qualifierText = qualifier.getText();
        if (fqClassName.equals(qualifierText)) {
            return true;
        }
    }
    return false;
}
 
Example 3
Source Project: KodeBeagle   Source File: PsiJavaElementVisitor.java    License: Apache License 2.0 5 votes vote down vote up
private void visitPsiNewExpression(final PsiNewExpression element) {
    if (element.getType() != null) {
        PsiType psiType = element.getType();
        if (psiType != null && !ClassUtils.isPrimitive(psiType)) {
            String type = removeSpecialSymbols(psiType.getCanonicalText());
            addInMap(type, emptySet);
        }
    }
}
 
Example 4
Source Project: android-postfix-plugin   Source File: ImportUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the current context has a static member import, either on-demand or explicit.
 *
 * @param fqClassName The class to import from
 * @param memberName  The class member to import
 * @param context     The context to be imported into
 */
public static boolean hasImportStatic(String fqClassName, String memberName, PsiElement context) {
    final PsiFile file = context.getContainingFile();
    if (!(file instanceof PsiJavaFile)) {
        return false;
    }
    final PsiJavaFile javaFile = (PsiJavaFile) file;
    final PsiImportList importList = javaFile.getImportList();
    if (importList == null) {
        return false;
    }
    final PsiImportStaticStatement[] importStaticStatements = importList.getImportStaticStatements();
    for (PsiImportStaticStatement importStaticStatement : importStaticStatements) {
        if (importStaticStatement.isOnDemand()) {
            PsiClass psiClass = ClassUtils.findClass(fqClassName, context);
            if (psiClass != null && psiClass.equals(importStaticStatement.resolveTargetClass())) {
                return true;
            }
            continue;
        }
        final String name = importStaticStatement.getReferenceName();
        if (!memberName.equals(name)) {
            continue;
        }
        final PsiJavaCodeReferenceElement importReference = importStaticStatement.getImportReference();
        if (importReference == null) {
            continue;
        }
        final PsiElement qualifier = importReference.getQualifier();
        if (qualifier == null) {
            continue;
        }
        final String qualifierText = qualifier.getText();
        if (fqClassName.equals(qualifierText)) {
            return true;
        }
    }
    return false;
}