Java Code Examples for com.jetbrains.php.lang.psi.elements.PhpClass#isInterface()

The following examples show how to use com.jetbrains.php.lang.psi.elements.PhpClass#isInterface() . 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: Symfony2InterfacesUtil.java    From Thinkphp5-Plugin with MIT License 6 votes vote down vote up
public boolean isInstanceOf(@NotNull PhpClass subjectClass, @NotNull PhpClass expectedClass) {

//        Tool.log(subjectClass.getFQN()+":"+expectedClass.getFQN());

        if (subjectClass.getFQN().equals(expectedClass.getFQN())) return true;

        if (subjectClass == expectedClass) {
            return true;
        }

        if (expectedClass.isInterface()) {
            return isImplementationOfInterface(subjectClass, expectedClass);
        }

        if (null == subjectClass.getSuperClass()) {
            return false;
        }

        return isInstanceOf(subjectClass.getSuperClass(), expectedClass);
    }
 
Example 2
Source File: Symfony2InterfacesUtil.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
public boolean isInstanceOf(@NotNull PhpClass subjectClass, @NotNull PhpClass expectedClass) {

        // we have equal class instance, on non multiple classes with same name fallback to namespace and classname
        if (subjectClass == expectedClass || PhpElementsUtil.isEqualClassName(subjectClass, expectedClass)) {
            return true;
        }

        if (expectedClass.isInterface()) {
            return isImplementationOfInterface(subjectClass, expectedClass);
        }

        if (null == subjectClass.getSuperClass()) {
            return false;
        }

        return isInstanceOf(subjectClass.getSuperClass(), expectedClass);
    }
 
Example 3
Source File: Symfony2InterfacesUtil.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
public boolean isInstanceOf(@NotNull PhpClass subjectClass, @NotNull PhpClass expectedClass) {

        // we have equal class instance, on non multiple classes with same name fallback to namespace and classname
        if (subjectClass == expectedClass || PhpElementsUtil.isEqualClassName(subjectClass, expectedClass)) {
            return true;
        }

        if (expectedClass.isInterface()) {
            return isImplementationOfInterface(subjectClass, expectedClass);
        }

        if (null == subjectClass.getSuperClass()) {
            return false;
        }

        return isInstanceOf(subjectClass.getSuperClass(), expectedClass);
    }
 
Example 4
Source File: LegacyClassesForIDEIndex.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@Override
public void visitElement(@NotNull PsiElement element) {

    if (!PlatformPatterns.psiElement(PhpClass.class).accepts(element)) {
        super.visitElement(element);
        return;
    }

    PhpClass phpClass = (PhpClass) element;

    String fqn = phpClass.getFQN();

    String superFqn = null;
    if (!phpClass.isInterface()) {
        superFqn = phpClass.getSuperFQN();
    } else {
        List<ClassReference> referenceElements = phpClass.getExtendsList().getReferenceElements();
        for (ClassReference cr : referenceElements) {
            superFqn = cr.getFQN();
        }
    }

    if (superFqn != null) {
        map.put(fqn, superFqn);
    }

    super.visitElement(element);
}
 
Example 5
Source File: Utils.java    From phpstorm-plugin with MIT License 5 votes vote down vote up
public static Boolean isClassAtoumTest(PhpClass checkedClass)
{
    // First, we check if the class is in the units tests namespace
    if (!checkedClass.getNamespaceName().toLowerCase().contains(getTestsNamespaceSuffix().toLowerCase())) {
        return false;
    }

    if (checkedClass.isAbstract() || checkedClass.isInterface()) {
        return false;
    }

    // We also check if the class extends atoum
    PhpClass loopCheckedClass = checkedClass;
    while (loopCheckedClass.getSuperClass() != null) {
        PhpClass parent = loopCheckedClass.getSuperClass();
        if (parent.getFQN().equals("\\atoum")) {
            return true;
        }
        loopCheckedClass = parent;
    }

    // We try with another method to check, if the project does not have atoum/stubs
    do {
        List<ClassReference> extendsList = checkedClass.getExtendsList().getReferenceElements();
        if (extendsList.iterator().hasNext()) {
            ClassReference ref = extendsList.iterator().next();
            if (ref.getFQN() != null && ref.getFQN().equals("\\atoum")) {
                return true;
            }
        }
        checkedClass = checkedClass.getSuperClass();
    } while (checkedClass != null);

    return false;
}
 
Example 6
Source File: Symfony2InterfacesUtil.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
public boolean isInstanceOf(@NotNull PhpClass subjectClass, @NotNull PhpClass expectedClass) {
    if (subjectClass == expectedClass) {
        return true;
    }

    if (expectedClass.isInterface()) {
        return isImplementationOfInterface(subjectClass, expectedClass);
    }

    if (null == subjectClass.getSuperClass()) {
        return false;
    }

    return isInstanceOf(subjectClass.getSuperClass(), expectedClass);
}