Java Code Examples for de.espend.idea.php.annotation.util.AnnotationUtil#getPropertyValue()

The following examples show how to use de.espend.idea.php.annotation.util.AnnotationUtil#getPropertyValue() . 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: AnnotationRouteElementWalkingVisitor.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * Extract route name of parent class "@Route(name="foo_")"
 */
@Nullable
private String getRouteNamePrefix(@NotNull PhpDocTag phpDocTag) {
    PhpClass phpClass = PsiTreeUtil.getParentOfType(phpDocTag, PhpClass.class);
    if (phpClass == null) {
        return null;
    }

    PhpDocComment docComment = phpClass.getDocComment();
    if (docComment == null) {
        return null;
    }

    for (PhpDocTag docTag : PsiTreeUtil.getChildrenOfTypeAsList(docComment, PhpDocTag.class)) {
        String annotationFqnName = AnnotationBackportUtil.getClassNameReference(docTag, this.fileImports);

        // check @Route or alias
        if(annotationFqnName == null || !RouteHelper.isRouteClassAnnotation(annotationFqnName)) {
            continue;
        }

        // extract "name" property
        String annotationRouteName = AnnotationUtil.getPropertyValue(docTag, "name");
        if(StringUtils.isNotBlank(annotationRouteName)) {
            return annotationRouteName;
        }
    }

    return null;
}
 
Example 2
Source File: AnnotationRouteElementWalkingVisitor.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
private void visitPhpDocTag(@NotNull PhpDocTag phpDocTag) {

        // "@var" and user non related tags dont need an action
        if(AnnotationBackportUtil.NON_ANNOTATION_TAGS.contains(phpDocTag.getName())) {
            return;
        }

        // init file imports
        if(this.fileImports == null) {
            this.fileImports = AnnotationBackportUtil.getUseImportMap(phpDocTag);
        }

        if(this.fileImports.size() == 0) {
            return;
        }

        String annotationFqnName = AnnotationBackportUtil.getClassNameReference(phpDocTag, this.fileImports);
        if(annotationFqnName == null || !RouteHelper.isRouteClassAnnotation(annotationFqnName)) {
            return;
        }

        PsiElement phpDocAttributeList = PsiElementUtils.getChildrenOfType(phpDocTag, PlatformPatterns.psiElement(PhpDocElementTypes.phpDocAttributeList));
        if(!(phpDocAttributeList instanceof PhpPsiElement)) {
            return;
        }

        String routeName = AnnotationUtil.getPropertyValue(phpDocTag, "name");
        if(routeName == null) {
            routeName = AnnotationBackportUtil.getRouteByMethod(phpDocTag);
        }

        if(routeName != null && StringUtils.isNotBlank(routeName)) {
            // prepend route name on PhpClass scope
            String routeNamePrefix = getRouteNamePrefix(phpDocTag);
            if(routeNamePrefix != null) {
                routeName = routeNamePrefix + routeName;
            }

            StubIndexedRoute route = new StubIndexedRoute(routeName);

            String path = "";

            // extract class path @Route("/foo") => "/foo" for prefixing upcoming methods
            String classPath = getClassRoutePattern(phpDocTag);
            if(classPath != null) {
                path += classPath;
            }

            // extract method path @Route("/foo") => "/foo"
            PhpPsiElement firstPsiChild = ((PhpPsiElement) phpDocAttributeList).getFirstPsiChild();
            if(firstPsiChild instanceof StringLiteralExpression) {
                String contents = ((StringLiteralExpression) firstPsiChild).getContents();
                if(StringUtils.isNotBlank(contents)) {
                    path += contents;
                }
            }

            if (path.length() > 0) {
                route.setPath(path);
            }

            route.setController(getController(phpDocTag));

            // @Method(...)
            extractMethods(phpDocTag, route);

            map.put(routeName, route);
        }
    }
 
Example 3
Source File: PhpDocTagAnnotation.java    From idea-php-annotation-plugin with MIT License 2 votes vote down vote up
/**
 * Get property Value from "@Template(template="foo");
 *
 * @param propertyName property name template=""
 * @return Property value
 */
@Nullable
public String getPropertyValue(@NotNull String propertyName) {
    return AnnotationUtil.getPropertyValue(phpDocTag, propertyName);
}