de.espend.idea.php.annotation.util.AnnotationUtil Java Examples

The following examples show how to use de.espend.idea.php.annotation.util.AnnotationUtil. 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: TemplateAnnotationIndex.java    From idea-php-generics-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, TemplateAnnotationUsage, FileContent> getIndexer() {
    return inputData -> {
        final Map<String, TemplateAnnotationUsage> map = new HashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if (!(psiFile instanceof PhpFile)) {
            return map;
        }

        if (!AnnotationUtil.isValidForIndex(inputData)) {
            return map;
        }

        psiFile.accept(new MyPsiRecursiveElementWalkingVisitor(map));

        return map;
    };
}
 
Example #2
Source File: RouteHelper.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * Extract route name of @Route(name="foobar_")
 * Must return empty string for easier accessibility
 */
@NotNull
private static String getRouteNamePrefix(@NotNull  PhpClass phpClass) {
    PhpDocCommentAnnotation phpClassContainer = AnnotationUtil.getPhpDocCommentAnnotationContainer(phpClass.getDocComment());
    if(phpClassContainer != null) {
        PhpDocTagAnnotation firstPhpDocBlock = phpClassContainer.getFirstPhpDocBlock(ROUTE_CLASSES.toArray(new String[ROUTE_CLASSES.size()]));
        if(firstPhpDocBlock != null) {
            String name = firstPhpDocBlock.getPropertyValue("name");
            if(name != null && StringUtils.isNotBlank(name)) {
                return name;
            }
        }
    }

    return "";
}
 
Example #3
Source File: AnnotationUtilTest.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
public void testGetClassAnnotationAsUnknown() {
    Collection<Object[]> dataProvider = new ArrayList<Object[]>() {{
        add(new Object[] {"@Target()", AnnotationTarget.UNKNOWN});
        add(new Object[] {"@Target", AnnotationTarget.UNKNOWN});
        add(new Object[] {"", AnnotationTarget.UNDEFINED});
    }};

    for (Object[] objects: dataProvider) {
        PhpClass phpClass = PhpPsiElementFactory.createFromText(getProject(), PhpClass.class, "<?php\n" +
            "/**\n" +
            "* @Annotation\n" +
            "* "+ objects[0] +"\n" +
            "*/\n" +
            "class Foo {}\n"
        );

        PhpAnnotation classAnnotation = AnnotationUtil.getClassAnnotation(phpClass);
        List<AnnotationTarget> targets = classAnnotation.getTargets();

        assertContainsElements(targets, objects[1]);
    }
}
 
Example #4
Source File: DoctrineUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * Extract text: @Entity(repositoryClass="foo")
 */
@Nullable
public static String getAnnotationRepositoryClass(@NotNull PhpDocTag phpDocTag, @NotNull PhpClass phpClass) {
    PsiElement phpDocAttributeList = PsiElementUtils.getChildrenOfType(phpDocTag, PlatformPatterns.psiElement(PhpDocElementTypes.phpDocAttributeList));
    if(phpDocAttributeList == null) {
        return null;
    }

    // @TODO: use annotation plugin
    // repositoryClass="Foobar"
    String text = phpDocAttributeList.getText();

    String repositoryClass = EntityHelper.resolveDoctrineLikePropertyClass(
        phpClass,
        text,
        "repositoryClass",
        aVoid -> AnnotationUtil.getUseImportMap(phpDocTag)
    );

    if (repositoryClass == null) {
        return null;
    }

    return StringUtils.stripStart(repositoryClass, "\\");
}
 
Example #5
Source File: AnnotationUtilTest.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
public void testIsAnnotationClass() {
    assertTrue(AnnotationUtil.isAnnotationClass(
        PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpClass.class, "<?php\n" +
        "/**\n" +
        "* @Annotation\n" +
        "*/\n" +
        "class Foo() {}\n"
    )));

    assertTrue(AnnotationUtil.isAnnotationClass(
        PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpClass.class, "<?php\n" +
        "/**\n" +
        "* @Annotation()\n" +
        "*/\n" +
        "class Foo() {}\n"
    )));

    assertFalse(AnnotationUtil.isAnnotationClass(
        PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpClass.class, "<?php\n" +
        "/**\n" +
        "* @Foo\n" +
        "*/\n" +
        "class Foo() {}\n"
    )));
}
 
Example #6
Source File: AnnotationUtilTest.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
public void testGetUseImportMap() {
    PhpDocTag phpDocTag = PhpPsiElementFactory.createFromText(getProject(), PhpDocTag.class, "<?php\n" +
        "use Foobar;\n" +
        "use Bar as MyFoo" +
        "\n" +
        "/**\n" +
        " * @Foo()\n" +
        " **/\n" +
        "class Foo() {}\n"
    );

    Map<String, String> propertyForEnum = AnnotationUtil.getUseImportMap((PsiElement) phpDocTag);

    assertEquals("\\Foobar", propertyForEnum.get("Foobar"));
    assertEquals("\\Bar", propertyForEnum.get("MyFoo"));
}
 
Example #7
Source File: RepositoryClassInspection.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    if(!DoctrineUtil.isDoctrineOrmInVendor(holder.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new MyAnnotationPropertyPsiElementVisitor("Doctrine\\ORM\\Mapping\\Entity") {
        @Override
        protected void visitAnnotationProperty(@NotNull PhpDocTag phpDocTag) {
            StringLiteralExpression repositoryClass = AnnotationUtil.getPropertyValueAsPsiElement(phpDocTag, "repositoryClass");
            if (repositoryClass == null) {
                return;
            }

            if(!DoctrineUtil.repositoryClassExists(phpDocTag)) {
                holder.registerProblem(
                    repositoryClass,
                    MESSAGE,
                    new DoctrineOrmRepositoryIntention()
                );
            }
        }
    };
}
 
Example #8
Source File: DocTagNameAnnotationReferenceContributor.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
/**
 * Attach element identify name to class of "use" usage
 *
 * @param psiElement PhpClass used in "use" statement
 */
@Override
public boolean isReferenceTo(@NotNull PsiElement psiElement) {
    if(!(psiElement instanceof PhpNamedElement)) {
        return false;
    }

    String text = getElement().getText();
    if(StringUtils.isBlank(text)) {
        return false;
    }

    String classByContext = AnnotationUtil.getUseImportMap(myElement).get(text);
    if(classByContext != null) {
        return StringUtils.stripStart(((PhpNamedElement) psiElement).getFQN(), "\\")
            .equalsIgnoreCase(StringUtils.stripStart(fqn, "\\"));
    }

    return false;
}
 
Example #9
Source File: AnnotationUsageIndex.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, Set<String>, FileContent> getIndexer() {
    return inputData -> {
        final Map<String, Set<String>> map = new THashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if(!(psiFile instanceof PhpFile)) {
            return map;
        }

        if(!AnnotationUtil.isValidForIndex(inputData)) {
            return map;
        }

        psiFile.accept(new PhpDocTagAnnotationRecursiveElementWalkingVisitor(pair -> {
            map.put(pair.getFirst(), new HashSet<>());
            return true;
        }));

        return map;
    };
}
 
Example #10
Source File: AnnotationCompletionContributor.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement psiElement = parameters.getOriginalPosition();
    if(psiElement == null) {
        return;
    }

    PhpDocTag phpDocTag = PsiTreeUtil.getParentOfType(parameters.getOriginalPosition(), PhpDocTag.class);
    PhpClass phpClass = AnnotationUtil.getAnnotationReference(phpDocTag);
    if(phpClass == null) {
        return;
    }

    AnnotationPropertyParameter annotationPropertyParameter = new AnnotationPropertyParameter(parameters.getOriginalPosition(), phpClass, AnnotationPropertyParameter.Type.DEFAULT);
    providerWalker(parameters, context, result, annotationPropertyParameter);

}
 
Example #11
Source File: ApplicationSettings.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
public static Collection<UseAliasOption> getDefaultUseAliasOption() {
    Collection<UseAliasOption> options = new ArrayList<>();

    options.add(new UseAliasOption("Symfony\\Component\\Validator\\Constraints", "Assert", true));
    options.add(new UseAliasOption("Doctrine\\ORM\\Mapping", "ORM", true));
    options.add(new UseAliasOption("JMS\\DiExtraBundle\\Annotation", "DI", true));
    options.add(new UseAliasOption("JMS\\Serializer\\Annotation", "Serializer", true));
    options.add(new UseAliasOption("Gedmo\\Mapping\\Annotation", "Gedmo", true));
    options.add(new UseAliasOption("Vich\\UploaderBundle\\Mapping\\Annotation", "Vich", true));
    options.add(new UseAliasOption("FOS\\RestBundle\\Controller\\Annotations", "Rest", true));
    options.add(new UseAliasOption("Swagger\\Annotations", "SWG", true));

    for (PhpAnnotationUseAlias extensions: AnnotationUtil.EP_USE_ALIASES.getExtensions()) {
        options.addAll(extensions.getAliases().entrySet().stream().map(
            entry -> new UseAliasOption(entry.getValue(), entry.getKey(), true)).collect(Collectors.toList()
        ));
    }

    return options;
}
 
Example #12
Source File: AnnotationGoToDeclarationHandler.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
/**
 * Add static field targets for @Route(name=ClassName::<FOO>)
 *
 * @param psiElement DOC_IDENTIFIER after DOC_STATIC
 * @param targets Goto targets
 */
private void addStaticClassConstTargets(PsiElement psiElement, List<PsiElement> targets) {
    PhpClass phpClass = AnnotationUtil.getClassFromConstant(psiElement);
    if(phpClass != null) {
        String constName = psiElement.getText();

        if ("class".equals(constName)) {
            targets.add(phpClass);
        } else {
            Field field = phpClass.findFieldByName(constName, true);
            if(field != null) {
                targets.add(field);
            }
        }
    }
}
 
Example #13
Source File: AnnotationCompletionContributor.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
    PsiElement psiElement = completionParameters.getOriginalPosition();
    if(psiElement == null) {
        return;
    }

    PhpDocComment parentOfType = PsiTreeUtil.getParentOfType(psiElement, PhpDocComment.class);
    if(parentOfType == null) {
        return;
    }

    AnnotationTarget annotationTarget = PhpElementsUtil.findAnnotationTarget(parentOfType);
    if(annotationTarget == null) {
        return;
    }

    Map<String, String> importMap = AnnotationUtil.getUseImportMap((PsiElement) parentOfType);

    Project project = completionParameters.getPosition().getProject();
    attachLookupElements(project, importMap , annotationTarget, completionResultSet);

}
 
Example #14
Source File: AnnotationGoToDeclarationHandler.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
/**
 * Add goto for DocTag itself which should be the PhpClass and provide Extension
 *
 * @param psiElement origin DOC_TAG_NAME psi element
 * @param targets Goto targets
 */
private void addDocTagNameGoto(PsiElement psiElement, List<PsiElement> targets) {

    PsiElement phpDocTagValue = psiElement.getContext();
    if(!(phpDocTagValue instanceof PhpDocTag)) {
        return;
    }

    PhpClass phpClass = AnnotationUtil.getAnnotationReference((PhpDocTag) phpDocTagValue);
    if(phpClass == null) {
        return;
    }

    targets.add(phpClass);

    AnnotationDocTagGotoHandlerParameter parameter = new AnnotationDocTagGotoHandlerParameter((PhpDocTag) phpDocTagValue, phpClass, targets);
    for(PhpAnnotationDocTagGotoHandler phpAnnotationExtension : AnnotationUtil.EP_DOC_TAG_GOTO.getExtensions()) {
        phpAnnotationExtension.getGotoDeclarationTargets(parameter);
    }

}
 
Example #15
Source File: AnnotationUtilTest.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public void testGetPropertyValueAsPsiElement() {
    PhpDocTag phpDocTag = PhpPsiElementFactory.createPhpPsiFromText(
        getProject(),
        PhpDocTag.class, "<?php\n /** @Template(\"Foobar\", name=\"Foo\") */"
    );

    assertEquals("Foo", AnnotationUtil.getPropertyValueAsPsiElement(phpDocTag, "name").getContents());
}
 
Example #16
Source File: AnnotationUtilTest.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public void testGetPropertyValue() {
    Collection<String[]> dataProvider = new ArrayList<String[]>() {{
        add(new String[] {"/** @Template(\"Foobar\") */", "property", null});
        add(new String[] {"/** @Template(name=\"Foo\") */", "name", "Foo"});
        add(new String[] {"/** @Template(\"Foobar\", name=\"Foo\") */", "name", "Foo"});
        add(new String[] {"/** @Template(\"Foobar\", foo=\"Foo\") */", "name", null});
        add(new String[] {"/** @Template(\"Foobar\", foo=FOO::class) */", "foo", null});
    }};

    for (String[] strings : dataProvider) {
        PhpDocTag phpDocTag = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpDocTag.class, "<?php\n" + strings[0]);
        assertEquals(strings[2], AnnotationUtil.getPropertyValue(phpDocTag, strings[1]));
    }
}
 
Example #17
Source File: AnnotationUtilTest.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public void testGetPropertyAndClassForArray() {
    myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
        "/**\n" +
        "* @Foo(name={\"FOOBAR\", \"FO<caret>OBAR2\"})n" +
        "*/\n" +
        "class Foo() {}\n"
    );

    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    PsiElement propertyForEnum = AnnotationUtil.getPropertyForArray((StringLiteralExpression) psiElement.getParent());

    assertNotNull(propertyForEnum);
    assertEquals("name", propertyForEnum.getText());
}
 
Example #18
Source File: AnnotationUtilTest.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public void testGetClassAnnotation() {
    PhpClass phpClass = PhpPsiElementFactory.createFromText(getProject(), PhpClass.class, "<?php\n" +
        "/**\n" +
        "* @Annotation\n" +
        "* @Target(\"PROPERTY\")\n" +
        "*/\n" +
        "class Foo {}\n"
    );

    PhpAnnotation classAnnotation = AnnotationUtil.getClassAnnotation(phpClass);
    List<AnnotationTarget> targets = classAnnotation.getTargets();

    assertContainsElements(targets, AnnotationTarget.PROPERTY);
}
 
Example #19
Source File: AnnotationUtilTest.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public void testGetClassAnnotationAsArray() {
    PhpClass phpClass = PhpPsiElementFactory.createFromText(getProject(), PhpClass.class, "<?php\n" +
        "/**\n" +
        "* @Annotation\n" +
        "* @Target(\"PROPERTY\", \"METHOD\")\n" +
        "* @Target(\"ALL\")\n" +
        "*/\n" +
        "class Foo {}\n"
    );

    PhpAnnotation classAnnotation = AnnotationUtil.getClassAnnotation(phpClass);
    List<AnnotationTarget> targets = classAnnotation.getTargets();

    assertContainsElements(targets, AnnotationTarget.PROPERTY, AnnotationTarget.METHOD, AnnotationTarget.ALL);
}
 
Example #20
Source File: AnnotationUtilTest.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public void testGetPropertyValueOrDefault() {
    Collection<String[]> dataProvider = new ArrayList<String[]>() {{
        add(new String[] {"/** @Template(\"Foobar\") */", "property", "Foobar"});
        add(new String[] {"/** @Template(name=\"Foo\") */", "name", "Foo"});
        add(new String[] {"/** @Template(\"Foobar\", name=\"Foo\") */", "name", "Foo"});
        add(new String[] {"/** @Template(\"Foobar\", foo=\"Foo\") */", "name", "Foobar"});
        add(new String[] {"/** @Template() */", "property", null});
    }};

    for (String[] strings : dataProvider) {
        PhpDocTag phpDocTag = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpDocTag.class, "<?php\n" + strings[0]);
        assertEquals(strings[2], AnnotationUtil.getPropertyValueOrDefault(phpDocTag, strings[1]));
    }
}
 
Example #21
Source File: AnnotationDeprecatedInspection.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
private void visitAnnotationDocTag(PhpDocTag phpDocTag, @NotNull ProblemsHolder holder) {
    PhpClass phpClass = AnnotationUtil.getAnnotationReference(phpDocTag);
    if (phpClass == null || !phpClass.isDeprecated()) {
        return;
    }

    PsiElement firstChild = phpDocTag.getFirstChild();
    if (firstChild == null || firstChild.getNode().getElementType() != PhpDocElementTypes.DOC_TAG_NAME) {
        return;
    }

    holder.registerProblem(firstChild, MESSAGE, ProblemHighlightType.LIKE_DEPRECATED);
}
 
Example #22
Source File: AnnotationDeprecatedInspection.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    return new PsiElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if (element instanceof PhpDocTag && AnnotationUtil.isAnnotationPhpDocTag((PhpDocTag) element)) {
                visitAnnotationDocTag((PhpDocTag) element, holder);
            }

            super.visitElement(element);
        }
    };
}
 
Example #23
Source File: AnnotationUtilTest.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public void testThatImportForClassIsSuggestedForImportedClass() {
    myFixture.copyFileToProject("doctrine.php");

    PhpDocTag phpDocTag = PhpPsiElementFactory.createFromText(getProject(), PhpDocTag.class, "<?php\n" +
        "/**\n" +
        "* @Entity()\n" +
        "*/\n" +
        "class Foo {}\n"
    );

    Map<String, String> possibleImportClasses = AnnotationUtil.getPossibleImportClasses(phpDocTag);
    assertNull(possibleImportClasses.get("\\Doctrine\\ORM\\Mapping"));
}
 
Example #24
Source File: AnnotationIconProvider.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public Icon getIcon(@NotNull PsiElement element, @Iconable.IconFlags int flags) {
    if (element instanceof PhpFile && PhpPsiUtil.findClasses((PhpFile)element, AnnotationUtil::isAnnotationClass).size() == 1) {
        return PlatformIcons.ANNOTATION_TYPE_ICON;
    }

    return null;
}
 
Example #25
Source File: AnnotationUtilTest.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public void testThatImportForClassIsSuggestedForAliasImportClass() {
    myFixture.copyFileToProject("doctrine.php");

    PhpDocTag phpDocTag = PhpPsiElementFactory.createFromText(getProject(), PhpDocTag.class, "<?php\n" +
        "/**\n" +
        "* @ORM\\Entity()\n" +
        "*/\n" +
        "class Foo {}\n"
    );

    Map<String, String> possibleImportClasses = AnnotationUtil.getPossibleImportClasses(phpDocTag);
    assertEquals("ORM", possibleImportClasses.get("\\Doctrine\\ORM\\Mapping"));
}
 
Example #26
Source File: AnnotationUsageLineMarkerProvider.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNull Collection<LineMarkerInfo> results) {
    for(PsiElement psiElement: psiElements) {
        if(!getClassNamePattern().accepts(psiElement)) {
            continue;
        }

        PsiElement phpClass = psiElement.getContext();
        if(!(phpClass instanceof PhpClass) || !AnnotationUtil.isAnnotationClass((PhpClass) phpClass)) {
            return;
        }

        String fqn = StringUtils.stripStart(((PhpClass) phpClass).getFQN(), "\\");

        // find one index annotation class and stop processing on first match
        final boolean[] processed = {false};
        FileBasedIndex.getInstance().getFilesWithKey(AnnotationUsageIndex.KEY, new HashSet<>(Collections.singletonList(fqn)), virtualFile -> {
            processed[0] = true;

            // stop on first match
            return false;
        }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(psiElement.getProject()), PhpFileType.INSTANCE));

        // we found at least one target to provide lazy target linemarker
        if(processed[0]) {
            NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(PhpIcons.IMPLEMENTS)
                .setTargets(new CollectionNotNullLazyValue(psiElement.getProject(), fqn))
                .setTooltipText("Navigate to implementations");

            results.add(builder.createLineMarkerInfo(psiElement));
        }
    }
}
 
Example #27
Source File: AnnotationUtilTest.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public void testThatAlreadyFqnNameMustNotSuggestAnyImport() {
    myFixture.copyFileToProject("doctrine.php");

    PhpDocTag phpDocTag = PhpPsiElementFactory.createFromText(getProject(), PhpDocTag.class, "<?php\n" +
        "/**\n" +
        "* @\\ORM\\Entity()\n" +
        "*/\n" +
        "class Foo {}\n"
    );

    Map<String, String> possibleImportClasses = AnnotationUtil.getPossibleImportClasses(phpDocTag);
    assertEquals(0, possibleImportClasses.size());
}
 
Example #28
Source File: AnnotationGoToDeclarationHandler.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
/**
 * Add class targets @Route(name=<ClassName>::FOO)
 *
 * @param psiElement DOC_IDENTIFIER
 * @param targets Goto targets
 */
private void addStaticClassTargets(PsiElement psiElement, List<PsiElement> targets) {
    PhpClass phpClass = AnnotationUtil.getClassFromDocIdentifier(psiElement);
    if(phpClass != null) {
        targets.add(phpClass);
    }
}
 
Example #29
Source File: AnnotationGoToDeclarationHandler.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
/**
 * Add goto for property value which are Fields inside PhpClass
 *
 * @param psiElement origin DOC_IDENTIFIER psi element
 * @param targets Goto targets
 */
private void addPropertyGoto(PsiElement psiElement, List<PsiElement> targets) {
    PhpDocTag phpDocTag = PsiTreeUtil.getParentOfType(psiElement, PhpDocTag.class);
    if(phpDocTag == null) {
        return;
    }

    PhpClass phpClass = AnnotationUtil.getAnnotationReference(phpDocTag);
    if(phpClass == null) {
        return;
    }

    String property = psiElement.getText();
    if(StringUtils.isBlank(property)) {
        return;
    }

    AnnotationUtil.visitAttributes(phpClass, (attributeName, type, target) -> {
        if(attributeName.equals(property)) {
            targets.add(target);
        }

        return null;
    });

    // extension point to provide virtual properties / fields targets
    AnnotationVirtualPropertyTargetsParameter parameter = null;
    for (PhpAnnotationVirtualProperties ep : AnnotationUtil.EP_VIRTUAL_PROPERTIES.getExtensions()) {
        if(parameter == null) {
            parameter = new AnnotationVirtualPropertyTargetsParameter(phpClass, psiElement, property);
        }

        ep.getTargets(parameter);
    }

    if(parameter != null) {
        targets.addAll(parameter.getTargets());
    }
}
 
Example #30
Source File: AnnotationInspectionUtil.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@NotNull
public Map<String, String> getImports() {
    if (imports != null) {
        return this.imports;
    }

    return this.imports = AnnotationUtil.getUseImportMap(psiElement);
}