Java Code Examples for com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocTag#getFirstChild()
The following examples show how to use
com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocTag#getFirstChild() .
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: DoctrineOrmRepositoryIntention.java From idea-php-annotation-plugin with MIT License | 5 votes |
private void insertAttribute(@NotNull Editor editor, @NotNull String repositoryClass, @NotNull PhpDocTag phpDocTag, @Nullable PhpPsiElement firstPsiChild) { if(firstPsiChild == null) return; String attr = "repositoryClass=\"" + repositoryClass + "\""; // we already have an attribute list if(firstPsiChild.getNode().getElementType() == PhpDocElementTypes.phpDocAttributeList) { // AttributeList: "()", "(aaa)" String text = StringUtils.trim(firstPsiChild.getText()); text = StringUtils.strip(text, "("); text = StringUtils.strip(text, ")"); if (text.contains(attr)) { return; } if(text.length() == 0) { // @ORM\Entity() editor.getDocument().insertString(firstPsiChild.getTextRange().getStartOffset() + 1, attr); } else { // @ORM\Entity(readOnly=true) editor.getDocument().insertString(firstPsiChild.getTextRange().getStartOffset() + 1, attr + ", "); } return; } // @ORM\Entity PsiElement firstChild = phpDocTag.getFirstChild(); if(firstChild != null) { editor.getDocument().insertString(firstChild.getTextRange().getEndOffset(), "(" + attr + ")"); } }
Example 2
Source File: AnnotationDeprecatedInspection.java From idea-php-annotation-plugin with MIT License | 5 votes |
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 3
Source File: AnnotationDocBlockTagClassNotFoundInspection.java From idea-php-annotation-plugin with MIT License | 5 votes |
private void visitAnnotationDocTag(@NotNull PhpDocTag phpDocTag, @NotNull ProblemsHolder holder, @NotNull AnnotationInspectionUtil.LazyNamespaceImportResolver lazyUseImporterCollector) { // Target for our inspection is DocTag name: @Foobar() => Foobar // This prevent highlighting the complete DocTag PsiElement firstChild = phpDocTag.getFirstChild(); if (firstChild == null || firstChild.getNode().getElementType() != PhpDocElementTypes.DOC_TAG_NAME) { return; } String name = phpDocTag.getName(); String tagName = StringUtils.stripStart(name, "@"); // ignore "@test", but allow "@\test" to go through if (!tagName.startsWith("\\") && !Character.isUpperCase(tagName.codePointAt(0))) { return; } String clazz = AnnotationInspectionUtil.getClassFqnString(tagName, lazyUseImporterCollector); if (clazz == null) { return; } PhpClass classInterface = PhpElementsUtil.getClassInterface(phpDocTag.getProject(), clazz); if (classInterface == null) { holder.registerProblem( firstChild, MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING ); } }
Example 4
Source File: AnnotationMissingUseInspection.java From idea-php-annotation-plugin with MIT License | 4 votes |
private void visitAnnotationDocTag(@NotNull PhpDocTag phpDocTag, @NotNull ProblemsHolder holder, @NotNull AnnotationInspectionUtil.LazyNamespaceImportResolver lazyNamespaceImportResolver) { // Target for our inspection is DocTag name: @Foobar() => Foobar // This prevent highlighting the complete DocTag PsiElement firstChild = phpDocTag.getFirstChild(); if (firstChild == null || firstChild.getNode().getElementType() != PhpDocElementTypes.DOC_TAG_NAME) { return; } String name = phpDocTag.getName(); String tagName = StringUtils.stripStart(name, "@"); // ignore "@\Foo" absolute FQN ones if (tagName.startsWith("\\")) { return; } String[] split = tagName.split("\\\\"); Map<String, String> useImportMap = lazyNamespaceImportResolver.getImports(); if (useImportMap.containsKey(split[0])) { return; } PhpClass annotationReference = AnnotationUtil.getAnnotationReference(phpDocTag); if (annotationReference != null) { return; } Map<String, String> phpClasses = AnnotationUtil.getPossibleImportClasses(phpDocTag); if (phpClasses.size() > 0) { Collection<Pair<String, String>> collect = phpClasses.entrySet().stream() .map(entry -> Pair.create(entry.getKey(), entry.getValue())) .collect(Collectors.toList()); holder.registerProblem( firstChild, MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new ImportUseForAnnotationQuickFix(phpDocTag, collect) ); } }