com.jetbrains.php.lang.psi.elements.ClassReference Java Examples

The following examples show how to use com.jetbrains.php.lang.psi.elements.ClassReference. 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: LegacyClassesForIDEInspection.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
    return new PhpElementVisitor() {
        @Override
        public void visitPhpClassReference(ClassReference classReference) {
            if (classReference.getFQN() != null && LegacyClassesForIDEIndex.isLegacyClass(classReference.getProject(), classReference.getFQN())) {
                problemsHolder.registerProblem(classReference, "Legacy class usage", ProblemHighlightType.LIKE_DEPRECATED, new LegacyClassesForIdeQuickFix());
            }

            super.visitPhpClassReference(classReference);
        }

        @Override
        public void visitPhpClassConstantReference(ClassConstantReference constantReference) {
            super.visitPhpClassConstantReference(constantReference);
        }
    };
}
 
Example #2
Source File: LegacyClassesForIdeQuickFix.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {

    PsiElement psiElement = descriptor.getPsiElement();
    if (DumbService.isDumb(project)) {
        showIsInDumpModeMessage(project, psiElement);
        return;
    }

    if (psiElement instanceof ClassReference) {
        ClassReference classReference = (ClassReference) psiElement;
        String fqn = classReference.getFQN();
        if (fqn != null) {
            String replacementFQN = LegacyClassesForIDEIndex.findReplacementClass(project, fqn);
            if (replacementFQN != null) {
                try {
                    classReference.replace(PhpPsiElementFactory.createClassReference(project, replacementFQN));
                } catch (IncorrectOperationException e) {
                    showErrorMessage(project, "Could not replace class reference", psiElement);
                }
            }
        }
    }
}
 
Example #3
Source File: ClassNameMatcherInspection.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
    return new PhpElementVisitor() {

        @Override
        public void visitPhpClassReference(ClassReference classReference) {
            Set<String> deprecatedClassNames = getDeprecatedClassNames(classReference.getProject());
            if (deprecatedClassNames.contains(classReference.getFQN())) {
                problemsHolder.registerProblem(classReference, "Class scheduled for removal in upcoming TYPO3 version, consider using an alternative");
            }

            super.visitPhpClassReference(classReference);
        }
    };
}
 
Example #4
Source File: TemplateUtil.java    From Thinkphp5-Plugin with MIT License 5 votes vote down vote up
private void visitMethodReference(MethodReference methodReference) {

            String methodName = methodReference.getName();
            if (!RENDER_METHODS.contains(methodName)) {
                return;
            }

            PsiElement classReference = methodReference.getFirstChild();
            if (!(classReference instanceof ClassReference)) {
                return;
            }

            if (!"View".equals(((ClassReference) classReference).getName())) {
                return;
            }

            PsiElement[] parameters = methodReference.getParameters();
            if (parameters.length == 0 || !(parameters[0] instanceof StringLiteralExpression)) {
                return;
            }

            String contents = ((StringLiteralExpression) parameters[0]).getContents();
            if (StringUtils.isBlank(contents)) {
                return;
            }

            views.add(Pair.create(contents, parameters[0]));
        }
 
Example #5
Source File: SignalSlotMethodReference.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public SignalSlotMethodReference(@NotNull ClassConstantReference classConstantReference, @NotNull StringLiteralExpression subject) {
    super(subject);

    this.methodName = subject.getContents();

    ClassReference classReference = PsiTreeUtil.findChildOfType(classConstantReference, ClassReference.class);
    if (classReference == null || classReference.getFQN() == null) {
        classFqn = "";
        subject.getContents();

        return;
    }

    this.classFqn = classReference.getFQN();
}
 
Example #6
Source File: SignalSlotMethodReference.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public SignalSlotMethodReference(@NotNull ClassConstantReference classConstantReference, @NotNull StringLiteralExpression subject, TextRange range) {
    super(subject, range);

    this.methodName = subject.getContents();

    ClassReference classReference = PsiTreeUtil.findChildOfType(classConstantReference, ClassReference.class);
    if (classReference == null || classReference.getFQN() == null) {
        classFqn = "";

        return;
    }

    this.classFqn = classReference.getFQN();
}
 
Example #7
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 #8
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 #9
Source File: BladeTemplateUtil.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
private void visitMethodReference(MethodReference methodReference) {

            String methodName = methodReference.getName();
            if(!RENDER_METHODS.contains(methodName)) {
                return;
            }

            PsiElement classReference = methodReference.getFirstChild();
            if(!(classReference instanceof ClassReference)) {
                return;
            }

            if(!"View".equals(((ClassReference) classReference).getName())) {
                return;
            }

            PsiElement[] parameters = methodReference.getParameters();
            if(parameters.length == 0 || !(parameters[0] instanceof StringLiteralExpression)) {
                return;
            }

            String contents = ((StringLiteralExpression) parameters[0]).getContents();
            if(StringUtils.isBlank(contents)) {
                return;
            }

            views.add(Pair.create(contents, parameters[0]));
        }