Java Code Examples for com.jetbrains.php.lang.PhpLangUtil#equalsClassNames()

The following examples show how to use com.jetbrains.php.lang.PhpLangUtil#equalsClassNames() . 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: DoctrineAnnotationStaticCompletionProvider.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Override
public void getPropertyValueCompletions(AnnotationPropertyParameter annotationPropertyParameter, AnnotationCompletionProviderParameter completionParameter) {

    String propertyName = annotationPropertyParameter.getPropertyName();
    if(propertyName == null) {
        return;
    }

    if(propertyName.equals("type") && PhpLangUtil.equalsClassNames(annotationPropertyParameter.getPhpClass().getPresentableFQN(), "Doctrine\\ORM\\Mapping\\Column")) {
        completionParameter.getResult().addAllElements(DoctrineUtil.getTypes(annotationPropertyParameter.getProject()));
    }

    if(propertyName.equals("onDelete") && PhpLangUtil.equalsClassNames(annotationPropertyParameter.getPhpClass().getPresentableFQN(), "Doctrine\\ORM\\Mapping\\JoinColumn")) {
        for(String s: Arrays.asList("CASCADE", "SET NULL")) {
            completionParameter.getResult().addElement(LookupElementBuilder.create(s));
        }
    }

}
 
Example 2
Source File: ColumnNameCompletionProvider.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Override
public void getPropertyValueCompletions(AnnotationPropertyParameter annotationPropertyParameter, AnnotationCompletionProviderParameter completionParameter) {

    String propertyName = annotationPropertyParameter.getPropertyName();
    if(propertyName == null) {
        return;
    }

    if(propertyName.equals("name") && PhpLangUtil.equalsClassNames(annotationPropertyParameter.getPhpClass().getPresentableFQN(), "Doctrine\\ORM\\Mapping\\Column")) {
        PhpDocComment phpDocComment = PsiTreeUtil.getParentOfType(annotationPropertyParameter.getElement(), PhpDocComment.class);
        if(phpDocComment != null) {
            PhpPsiElement classField = phpDocComment.getNextPsiSibling();
            if(classField != null && classField.getNode().getElementType() == PhpElementTypes.CLASS_FIELDS) {
                Field field = PsiTreeUtil.getChildOfType(classField, Field.class);
                if(field != null) {
                    String name = field.getName();
                    if(StringUtils.isNotBlank(name)) {
                        completionParameter.getResult().addElement(LookupElementBuilder.create(underscore(name)));
                    }
                }
            }
        }
    }

}
 
Example 3
Source File: DoctrineAnnotationTypeProvider.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotationPropertyParameter, PhpAnnotationReferenceProviderParameter referencesByElementParameter) {

    if(annotationPropertyParameter.getType() != AnnotationPropertyParameter.Type.PROPERTY_VALUE) {
        return null;
    }

    String propertyName = annotationPropertyParameter.getPropertyName();
    if(propertyName == null || !propertyName.equals("repositoryClass")) {
        return null;
    }

    String presentableFQN = annotationPropertyParameter.getPhpClass().getPresentableFQN();
    if(!PhpLangUtil.equalsClassNames("Doctrine\\ORM\\Mapping\\Entity", presentableFQN)) {
        return null;
    }

    return new PsiReference[] {
        new DoctrineRepositoryReference((StringLiteralExpression) annotationPropertyParameter.getElement())
    };

}
 
Example 4
Source File: SymfonyCompletionProvider.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@Override
public void getPropertyValueCompletions(AnnotationPropertyParameter parameter, AnnotationCompletionProviderParameter completion) {
    if(parameter.getType() != AnnotationPropertyParameter.Type.PROPERTY_ARRAY) {
        return;
    }

    if("methods".equals(parameter.getPropertyName()) && PhpLangUtil.equalsClassNames(StringUtils.stripStart(parameter.getPhpClass().getFQN(), "\\"), "Symfony\\Component\\Routing\\Annotation\\Route")) {
        for (String s : new String[]{"HEAD", "GET", "POST", "PUT", "PATCH", "DELETE", "PURGE", "OPTIONS", "TRACE", "CONNECT"}) {
            completion.getResult().addElement(LookupElementBuilder.create(s));
        }
    }
}
 
Example 5
Source File: DoctrineCustomIdGenerator.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@Override
boolean supports(AnnotationPropertyParameter parameter) {
    return
        parameter.getType() == AnnotationPropertyParameter.Type.PROPERTY_VALUE &&
        "class".equals(parameter.getPropertyName()) &&
        PhpLangUtil.equalsClassNames(StringUtils.stripStart(parameter.getPhpClass().getFQN(), "\\"), "Doctrine\\ORM\\Mapping\\CustomIdGenerator");
}
 
Example 6
Source File: EmbeddedClassCompletionProvider.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@Override
boolean supports(AnnotationPropertyParameter parameter) {
    return
        parameter.getType() == AnnotationPropertyParameter.Type.PROPERTY_VALUE &&
        "class".equals(parameter.getPropertyName()) &&
        PhpLangUtil.equalsClassNames(StringUtils.stripStart(parameter.getPhpClass().getFQN(), "\\"), "Doctrine\\ORM\\Mapping\\Embedded");
}
 
Example 7
Source File: ConfigEntityTypeAnnotation.java    From idea-php-drupal-symfony2-bridge with MIT License 4 votes vote down vote up
private boolean isSupported(@NotNull AnnotationPropertyParameter parameter) {
    return parameter.getType() != AnnotationPropertyParameter.Type.DEFAULT &&
        PhpLangUtil.equalsClassNames(StringUtils.stripStart(parameter.getPhpClass().getFQN(), "\\"), "Drupal\\Core\\Entity\\Annotation\\ConfigEntityType");
}
 
Example 8
Source File: TranslationAnnotationReference.java    From idea-php-drupal-symfony2-bridge with MIT License 4 votes vote down vote up
private boolean isSupported(@NotNull AnnotationPropertyParameter parameter) {
    return parameter.getType() == AnnotationPropertyParameter.Type.DEFAULT &&
        PhpLangUtil.equalsClassNames(StringUtils.stripStart(parameter.getPhpClass().getFQN(), "\\"), "Drupal\\Core\\Annotation\\Translation");
}
 
Example 9
Source File: ContentEntityTypeAnnotation.java    From idea-php-drupal-symfony2-bridge with MIT License 4 votes vote down vote up
private boolean isSupported(@NotNull AnnotationPropertyParameter parameter) {
    return parameter.getType() != AnnotationPropertyParameter.Type.DEFAULT &&
        PhpLangUtil.equalsClassNames(StringUtils.stripStart(parameter.getPhpClass().getFQN(), "\\"), "Drupal\\Core\\Entity\\Annotation\\ContentEntityType");
}
 
Example 10
Source File: DoctrineTypeDeprecatedInspection.java    From idea-php-annotation-plugin with MIT License 4 votes vote down vote up
@Override
public void visitElement(PsiElement element) {
    if (!(element instanceof StringLiteralExpression) || element.getNode().getElementType() != PhpDocElementTypes.phpDocString) {
        super.visitElement(element);
        return;
    }

    String contents = ((StringLiteralExpression) element).getContents();
    if (StringUtils.isBlank(contents)) {
        super.visitElement(element);
        return;
    }

    PhpDocTag phpDocTag = PsiTreeUtil.getParentOfType(element, PhpDocTag.class);
    if (phpDocTag == null) {
        super.visitElement(element);
        return;
    }

    PsiElement propertyName = PhpElementsUtil.getPrevSiblingOfPatternMatch(element, PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER));
    if(propertyName == null) {
        super.visitElement(element);
        return;
    }

    String text = propertyName.getText();
    if ("type".equalsIgnoreCase(text)) {
        PhpDocTagAnnotation phpDocAnnotationContainer = AnnotationUtil.getPhpDocAnnotationContainer(phpDocTag);
        if (phpDocAnnotationContainer != null) {
            PhpClass tagPhpClass = phpDocAnnotationContainer.getPhpClass();
            if (PhpLangUtil.equalsClassNames(tagPhpClass.getPresentableFQN(), "Doctrine\\ORM\\Mapping\\Column")) {
                for (PhpClass columnPhpClass : DoctrineUtil.getColumnTypesTargets(holder.getProject(), contents)) {
                    if (!columnPhpClass.isDeprecated()) {
                        continue;
                    }

                    String deprecationMessage = PhpElementsUtil.getClassDeprecatedMessage(columnPhpClass);

                    holder.registerProblem(
                        element,
                        "[Annotations] " + (deprecationMessage != null ? deprecationMessage : String.format("Field '%s' is deprecated", text)),
                        ProblemHighlightType.LIKE_DEPRECATED
                    );

                    break;
                }
            }
        }
    }

    super.visitElement(element);
}
 
Example 11
Source File: PhpMetaUtil.java    From idea-php-advanced-autocomplete with MIT License 4 votes vote down vote up
private static boolean metaFunctionWithName(FunctionReference reference, String name) {
    return PhpLangUtil.equalsClassNames(reference.getName(), name) && META_NAMESPACE_PREFIX.equals(reference.getNamespaceName());
}