Search in sources :

Example 1 with PsiElementVisitor

use of com.intellij.psi.PsiElementVisitor in project intellij-community by JetBrains.

the class WrongPropertyKeyValueDelimiterInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    if (!(holder.getFile() instanceof PropertiesFileImpl)) {
        return PsiElementVisitor.EMPTY_VISITOR;
    }
    final PropertiesCodeStyleSettings codeStyleSettings = PropertiesCodeStyleSettings.getInstance(holder.getProject());
    final char codeStyleKeyValueDelimiter = codeStyleSettings.getDelimiter();
    return new PsiElementVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            if (element instanceof PropertyImpl) {
                final char delimiter = ((PropertyImpl) element).getKeyValueDelimiter();
                if (delimiter != codeStyleKeyValueDelimiter) {
                    holder.registerProblem(element, PropertiesBundle.message("wrong.property.key.value.delimiter.inspection.display.name"), new ReplaceKeyValueDelimiterQuickFix(element));
                }
            }
        }
    };
}
Also used : PropertiesCodeStyleSettings(com.intellij.lang.properties.psi.codeStyle.PropertiesCodeStyleSettings) PropertyImpl(com.intellij.lang.properties.psi.impl.PropertyImpl) PropertiesFileImpl(com.intellij.lang.properties.psi.impl.PropertiesFileImpl) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PsiElementVisitor

use of com.intellij.psi.PsiElementVisitor in project intellij-community by JetBrains.

the class SpellCheckingInspection method buildVisitor.

@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    final SpellCheckerManager manager = SpellCheckerManager.getInstance(holder.getProject());
    return new PsiElementVisitor() {

        @Override
        public void visitElement(final PsiElement element) {
            final ASTNode node = element.getNode();
            if (node == null) {
                return;
            }
            // Extract parser definition from element
            final Language language = element.getLanguage();
            final IElementType elementType = node.getElementType();
            final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
            // Handle selected options
            if (parserDefinition != null) {
                if (parserDefinition.getStringLiteralElements().contains(elementType)) {
                    if (!processLiterals) {
                        return;
                    }
                } else if (parserDefinition.getCommentTokens().contains(elementType)) {
                    if (!processComments) {
                        return;
                    }
                } else if (!processCode) {
                    return;
                }
            }
            tokenize(element, language, new MyTokenConsumer(manager, holder, LanguageNamesValidation.INSTANCE.forLanguage(language)));
        }
    };
}
Also used : IElementType(com.intellij.psi.tree.IElementType) SpellCheckerManager(com.intellij.spellchecker.SpellCheckerManager) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PsiElementVisitor

use of com.intellij.psi.PsiElementVisitor in project intellij-plugins by JetBrains.

the class CfmlFileReferenceInspection method buildVisitor.

@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    return new PsiElementVisitor() {

        public void visitElement(final PsiElement element) {
            PsiElement tagParent = PsiTreeUtil.getParentOfType((element), CfmlTag.class);
            if ((element.getNode().getElementType() == CfmlTokenTypes.STRING_TEXT)) {
                if ((tagParent == null || (!((CfmlTag) tagParent).getTagName().equalsIgnoreCase("cfinclude") && !((CfmlTag) tagParent).getTagName().equalsIgnoreCase("cfmodule")))) {
                    PsiElement superParent = element.getParent() != null ? element.getParent().getParent() : null;
                    ASTNode superParentNode = superParent != null ? superParent.getNode() : null;
                    if ((superParentNode == null || superParentNode.getElementType() != CfmlElementTypes.INCLUDEEXPRESSION)) {
                        return;
                    }
                }
                final PsiReference[] refs = element.getParent().getReferences();
                for (int i = 0, refsLength = refs.length; i < refsLength; i++) {
                    PsiReference ref = refs[i];
                    if (!(ref instanceof FileReference))
                        continue;
                    if (ref.resolve() == null) {
                        PsiDirectory dir;
                        if (i > 0) {
                            final PsiElement target = refs[i - 1].resolve();
                            dir = target instanceof PsiDirectory ? (PsiDirectory) target : null;
                        } else {
                            dir = element.getContainingFile().getParent();
                        }
                        holder.registerProblem(ref.getElement(), ref.getRangeInElement(), isOnTheFly ? "Path '" + ref.getCanonicalText() + "' not found" : "Path not found", isOnTheFly && dir != null ? new LocalQuickFix[] { new CreateFileFix(i < refs.length - 1, ref.getCanonicalText(), dir) } : LocalQuickFix.EMPTY_ARRAY);
                        //                       ProblemHighlightType.ERROR);
                        break;
                    }
                }
            }
        }
    };
}
Also used : CreateFileFix(com.intellij.codeInsight.daemon.quickFix.CreateFileFix) PsiDirectory(com.intellij.psi.PsiDirectory) ASTNode(com.intellij.lang.ASTNode) PsiReference(com.intellij.psi.PsiReference) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) CfmlTag(com.intellij.coldFusion.model.psi.CfmlTag) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) FileReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with PsiElementVisitor

use of com.intellij.psi.PsiElementVisitor in project intellij-plugins by JetBrains.

the class CucumberJavaAllFeaturesInFolderRunConfigurationProducer method getStepsGlue.

@Override
protected NullableComputable<String> getStepsGlue(@NotNull final PsiElement element) {
    final Set<String> glues = getHookGlue(element);
    if (element instanceof PsiDirectory) {
        final PsiDirectory dir = (PsiDirectory) element;
        final CucumberJvmExtensionPoint[] extensions = Extensions.getExtensions(CucumberJvmExtensionPoint.EP_NAME);
        return new NullableComputable<String>() {

            @Nullable
            @Override
            public String compute() {
                dir.accept(new PsiElementVisitor() {

                    @Override
                    public void visitFile(final PsiFile file) {
                        if (file instanceof GherkinFile) {
                            for (CucumberJvmExtensionPoint extension : extensions) {
                                extension.getGlues((GherkinFile) file, glues);
                            }
                        }
                    }

                    @Override
                    public void visitDirectory(PsiDirectory dir) {
                        for (PsiDirectory subDir : dir.getSubdirectories()) {
                            subDir.accept(this);
                        }
                        for (PsiFile file : dir.getFiles()) {
                            file.accept(this);
                        }
                    }
                });
                return StringUtil.join(glues, " ");
            }
        };
    }
    return null;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) CucumberJvmExtensionPoint(org.jetbrains.plugins.cucumber.CucumberJvmExtensionPoint) NullableComputable(com.intellij.openapi.util.NullableComputable) PsiFile(com.intellij.psi.PsiFile) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) GherkinFile(org.jetbrains.plugins.cucumber.psi.GherkinFile)

Example 5 with PsiElementVisitor

use of com.intellij.psi.PsiElementVisitor in project android by JetBrains.

the class ThemeEditorStyle method getValueTag.

/**
   * @param attribute The style attribute name.
   * @return the XmlTag that contains the value for a given attribute in the current style.
   */
@Nullable
private /*if the attribute does not exist in this theme*/
XmlTag getValueTag(@NotNull XmlTag sourceTag, @NotNull final String attribute) {
    if (!isProjectStyle()) {
        // Non project styles do not contain local values.
        return null;
    }
    final Ref<XmlTag> resultXmlTag = new Ref<XmlTag>();
    ApplicationManager.getApplication().assertReadAccessAllowed();
    sourceTag.acceptChildren(new PsiElementVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            super.visitElement(element);
            if (!(element instanceof XmlTag)) {
                return;
            }
            final XmlTag tag = (XmlTag) element;
            if (SdkConstants.TAG_ITEM.equals(tag.getName()) && attribute.equals(tag.getAttributeValue(SdkConstants.ATTR_NAME))) {
                resultXmlTag.set(tag);
            }
        }
    });
    return resultXmlTag.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiElementVisitor (com.intellij.psi.PsiElementVisitor)60 PsiElement (com.intellij.psi.PsiElement)54 NotNull (org.jetbrains.annotations.NotNull)49 ProblemsHolder (com.intellij.codeInspection.ProblemsHolder)39 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)37 BasePhpInspection (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpInspection)37 com.jetbrains.php.lang.psi.elements (com.jetbrains.php.lang.psi.elements)27 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)21 Project (com.intellij.openapi.project.Project)19 MessagesPresentationUtil (com.kalessil.phpStorm.phpInspectionsEA.utils.MessagesPresentationUtil)19 PhpTokenTypes (com.jetbrains.php.lang.lexer.PhpTokenTypes)17 Set (java.util.Set)17 com.kalessil.phpStorm.phpInspectionsEA.utils (com.kalessil.phpStorm.phpInspectionsEA.utils)16 HashSet (java.util.HashSet)16 OptionsComponent (com.kalessil.phpStorm.phpInspectionsEA.options.OptionsComponent)15 javax.swing (javax.swing)15 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)14 PhpType (com.jetbrains.php.lang.psi.resolve.types.PhpType)14 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)12 ProblemHighlightType (com.intellij.codeInspection.ProblemHighlightType)12