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

The following examples show how to use com.jetbrains.php.lang.psi.elements.PhpClass#getFQN() . 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: XmlReferenceContributor.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext context) {
    if(!Symfony2ProjectComponent.isEnabled(psiElement) || !(psiElement instanceof XmlAttributeValue)) {
        return new PsiReference[0];
    }

    String method = ((XmlAttributeValue) psiElement).getValue();
    if(StringUtils.isBlank(method)) {
        return new PsiReference[0];
    }

    PhpClass phpClass = XmlHelper.getPhpClassForServiceFactory((XmlAttributeValue) psiElement);
    if(phpClass == null) {
        return new PsiReference[0];
    }

    Method targetMethod = phpClass.findMethodByName(method);
    if(targetMethod == null) {
        return new PsiReference[0];
    }

    return new PsiReference[] {
        new ClassMethodStringPsiReference(psiElement, phpClass.getFQN(), targetMethod.getName()),
    };
}
 
Example 2
Source File: XmlReferenceContributor.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) {
    if(!Symfony2ProjectComponent.isEnabled(psiElement) || !(psiElement instanceof XmlAttributeValue)) {
        return new PsiReference[0];
    }

    String method = ((XmlAttributeValue) psiElement).getValue();
    if(StringUtils.isBlank(method)) {
        return new PsiReference[0];
    }

    PhpClass phpClass = XmlHelper.getPhpClassForClassFactory((XmlAttributeValue) psiElement);
    if(phpClass == null) {
        return new PsiReference[0];
    }

    Method classMethod = phpClass.findMethodByName(method);
    if(classMethod == null) {
        return new PsiReference[0];
    }

    return new PsiReference[]{
        new ClassMethodStringPsiReference(psiElement, phpClass.getFQN(), classMethod.getName()),
    };
}
 
Example 3
Source File: TemplateAnnotationIndex.java    From idea-php-generics-plugin with MIT License 5 votes vote down vote up
private void visitPhpClass(@NotNull PhpClass phpClass) {
    String fqn = phpClass.getFQN();
    if(!fqn.startsWith("\\")) {
        fqn = "\\" + fqn;
    }

    PhpDocComment phpDocComment = phpClass.getDocComment();
    if (phpDocComment != null) {
        Map<String, String> useImportMap = null;
        for (PhpDocTag phpDocTag : GenericsUtil.getTagElementsByNameForAllFrameworks(phpDocComment, "extends")) {
            String tagValue = phpDocTag.getTagValue();

            Matcher matcher = CLASS_EXTENDS_MATCHER.matcher(tagValue);
            if (!matcher.find()) {
                continue;
            }

            String extendsClass = matcher.group(1);
            String type = matcher.group(2);

            // init the imports scope; to be only loaded once
            if (useImportMap == null) {
                useImportMap = AnnotationUtil.getUseImportMap(phpDocComment);
            }

            // resolve the class name based on the scope of namespace and use statement
            // eg: "@template BarAlias\MyContainer<Bar\Foobar>" we need global namespaces starting with "\"
            extendsClass = GenericsUtil.getFqnClassNameFromScope(fqn, extendsClass, useImportMap);
            type = GenericsUtil.getFqnClassNameFromScope(fqn, type, useImportMap);

            map.put(fqn, new TemplateAnnotationUsage(
                fqn,
                TemplateAnnotationUsage.Type.EXTENDS,
                0,
                extendsClass + "::" + type
            ));
        }
    }

}
 
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: DoctrinePhpMappingDriver.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Override
public DoctrineMetadataModel getMetadata(@NotNull DoctrineMappingDriverArguments args) {
    PsiFile psiFile = args.getPsiFile();
    if(!(psiFile instanceof PhpFile)) {
        return null;
    }

    Collection<DoctrineModelField> fields = new ArrayList<>();
    DoctrineMetadataModel model = new DoctrineMetadataModel(fields);

    for (PhpClass phpClass : PhpElementsUtil.getClassesInterface(args.getProject(), args.getClassName())) {
        // remove duplicate code
        // @TODO: fr.adrienbrault.idea.symfony2plugin.doctrine.EntityHelper.getModelFields()
        PhpDocComment docComment = phpClass.getDocComment();
        if(docComment == null) {
            continue;
        }

        // Doctrine ORM
        // @TODO: external split
        if(AnnotationBackportUtil.hasReference(docComment, "\\Doctrine\\ORM\\Mapping\\Entity", "\\TYPO3\\Flow\\Annotations\\Entity")) {

            // @TODO: reuse annotations plugin
            PhpDocTag phpDocTag = AnnotationBackportUtil.getReference(docComment, "\\Doctrine\\ORM\\Mapping\\Table");
            if(phpDocTag != null) {
                Matcher matcher = Pattern.compile("name[\\s]*=[\\s]*[\"|']([\\w_\\\\]+)[\"|']").matcher(phpDocTag.getText());
                if (matcher.find()) {
                    model.setTable(matcher.group(1));
                }
            }

            Map<String, Map<String, String>> maps = new HashMap<>();
            for(Field field: phpClass.getFields()) {
                if (field.isConstant()) {
                    continue;
                }

                if (!AnnotationBackportUtil.hasReference(field.getDocComment(), EntityHelper.ANNOTATION_FIELDS)) {
                    continue;
                }

                // context change is case of "trait" or extends
                PhpClass containingClass = field.getContainingClass();
                if (containingClass == null) {
                    continue;
                }

                // collect import context based on the class name
                String fqn = containingClass.getFQN();
                if (!maps.containsKey(fqn)) {
                    maps.put(fqn, AnnotationUtil.getUseImportMap(field.getDocComment()));
                }

                DoctrineModelField modelField = new DoctrineModelField(field.getName());
                EntityHelper.attachAnnotationInformation(containingClass, field, modelField.addTarget(field), maps.get(fqn));
                fields.add(modelField);
            }
        }
    }

    if(fields.size() == 0) {
        return null;
    }

    return model;
}