Java Code Examples for com.jetbrains.php.lang.psi.elements.Field#getContainingClass()

The following examples show how to use com.jetbrains.php.lang.psi.elements.Field#getContainingClass() . 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: 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;
}
 
Example 2
Source File: PhpConstantFieldPhpLookupElement.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
public PhpConstantFieldPhpLookupElement(@NotNull Field field) {
    super(field);
    this.phpClass = field.getContainingClass();
}