Search in sources :

Example 1 with PerlStringContentElementImpl

use of com.perl5.lang.perl.psi.impl.PerlStringContentElementImpl in project Perl5-IDEA by Camelcade.

the class PerlUnresolvedSubInspection method buildVisitor.

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

        @Override
        public void visitStringContentElement(@NotNull PerlStringContentElementImpl o) {
            if (EXPORT_ASSIGNED_STRING_CONTENT.accepts(o)) {
                if (!isResolvable(o.getReference())) {
                    registerProblem(holder, o, PerlBundle.message("perl.inspection.no.exported.entity"));
                }
            }
        }

        @Override
        public void visitPerlMethod(@NotNull PerlMethod o) {
            PerlNamespaceElement namespaceElement = o.getNamespaceElement();
            PerlSubNameElement subNameElement = o.getSubNameElement();
            // fixme adjust built in checking to the file; Remove second condition after implementing annotations
            if (subNameElement == null || namespaceElement != null && namespaceElement.isBuiltin() || subNameElement.isBuiltIn()) {
                return;
            }
            for (PsiReference reference : subNameElement.getReferences()) {
                if (isResolvable(reference)) {
                    return;
                }
            }
            registerProblem(holder, subNameElement, PerlBundle.message("perl.inspection.no.sub.definition"));
        }
    };
}
Also used : PerlMethod(com.perl5.lang.perl.psi.PerlMethod) PerlSubNameElement(com.perl5.lang.perl.psi.PerlSubNameElement) PerlNamespaceElement(com.perl5.lang.perl.psi.PerlNamespaceElement) PsiReference(com.intellij.psi.PsiReference) PerlVisitor(com.perl5.lang.perl.psi.PerlVisitor) NotNull(org.jetbrains.annotations.NotNull) PerlStringContentElementImpl(com.perl5.lang.perl.psi.impl.PerlStringContentElementImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PerlStringContentElementImpl

use of com.perl5.lang.perl.psi.impl.PerlStringContentElementImpl in project Perl5-IDEA by Camelcade.

the class PerlElementFactory method createStringContent.

public static PerlStringContentElementImpl createStringContent(Project project, String name) {
    PerlFileImpl file = createFile(project, "'" + name + "';");
    PsiPerlStringSq string = PsiTreeUtil.findChildOfType(file, PsiPerlStringSq.class);
    assert string != null;
    return (PerlStringContentElementImpl) string.getFirstChild().getNextSibling();
}
Also used : PerlFileImpl(com.perl5.lang.perl.psi.impl.PerlFileImpl) PerlStringContentElementImpl(com.perl5.lang.perl.psi.impl.PerlStringContentElementImpl)

Example 3 with PerlStringContentElementImpl

use of com.perl5.lang.perl.psi.impl.PerlStringContentElementImpl in project Perl5-IDEA by Camelcade.

the class PerlTemplateContextType method isInContext.

@Override
public boolean isInContext(@NotNull PsiFile psiFile, int fileOffset) {
    if (!PsiUtilCore.getLanguageAtOffset(psiFile, fileOffset).isKindOf(PerlLanguage.INSTANCE)) {
        return false;
    }
    PsiElement element = psiFile.findElementAt(fileOffset);
    if (element == null) {
        element = psiFile.findElementAt(fileOffset - 1);
    }
    if (element == null) {
        return false;
    }
    IElementType tokenType = PsiUtilCore.getElementType(element);
    return !(element instanceof PsiWhiteSpace || element instanceof PerlStringContentElementImpl || element instanceof PsiComment || tokenType == PerlElementTypes.REGEX_TOKEN) && isInContext(element);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiComment(com.intellij.psi.PsiComment) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace) PerlStringContentElementImpl(com.perl5.lang.perl.psi.impl.PerlStringContentElementImpl)

Example 4 with PerlStringContentElementImpl

use of com.perl5.lang.perl.psi.impl.PerlStringContentElementImpl in project Perl5-IDEA by Camelcade.

the class PerlStringCompletionUtil method fillWithHashIndexes.

public static void fillWithHashIndexes(@NotNull final PsiElement element, @NotNull final CompletionResultSet result) {
    for (String text : HASH_INDEXES_CACHE) {
        addElement(text, result);
    }
    PsiFile file = element.getContainingFile();
    file.accept(new PerlRecursiveVisitor() {

        @Override
        public void visitStringContentElement(@NotNull PerlStringContentElementImpl o) {
            if (o != element && SIMPLE_HASH_INDEX.accepts(o)) {
                processStringElement(o);
            }
            super.visitStringContentElement(o);
        }

        @Override
        public void visitCommaSequenceExpr(@NotNull PsiPerlCommaSequenceExpr o) {
            if (o.getParent() instanceof PsiPerlAnonHash) {
                PsiElement sequenceElement = o.getFirstChild();
                boolean isKey = true;
                while (sequenceElement != null) {
                    ProgressManager.checkCanceled();
                    IElementType elementType = sequenceElement.getNode().getElementType();
                    if (isKey && sequenceElement instanceof PerlString) {
                        for (PerlStringContentElement stringElement : PerlPsiUtil.collectStringElements(sequenceElement)) {
                            processStringElement(stringElement);
                        }
                    } else if (elementType == COMMA || elementType == FAT_COMMA) {
                        isKey = !isKey;
                    }
                    sequenceElement = PerlPsiUtil.getNextSignificantSibling(sequenceElement);
                }
            }
            super.visitCommaSequenceExpr(o);
        }

        protected void processStringElement(PerlStringContentElement stringContentElement) {
            String text = stringContentElement.getText();
            if (StringUtil.isNotEmpty(text) && !HASH_INDEXES_CACHE.contains(text) && PerlLexer.IDENTIFIER_PATTERN.matcher(text).matches()) {
                HASH_INDEXES_CACHE.add(text);
                addElement(text, result);
            }
        }
    });
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) PerlStringContentElementImpl(com.perl5.lang.perl.psi.impl.PerlStringContentElementImpl)

Aggregations

PerlStringContentElementImpl (com.perl5.lang.perl.psi.impl.PerlStringContentElementImpl)4 PsiElement (com.intellij.psi.PsiElement)2 IElementType (com.intellij.psi.tree.IElementType)2 PsiComment (com.intellij.psi.PsiComment)1 PsiFile (com.intellij.psi.PsiFile)1 PsiReference (com.intellij.psi.PsiReference)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1 PerlMethod (com.perl5.lang.perl.psi.PerlMethod)1 PerlNamespaceElement (com.perl5.lang.perl.psi.PerlNamespaceElement)1 PerlSubNameElement (com.perl5.lang.perl.psi.PerlSubNameElement)1 PerlVisitor (com.perl5.lang.perl.psi.PerlVisitor)1 PerlFileImpl (com.perl5.lang.perl.psi.impl.PerlFileImpl)1 NotNull (org.jetbrains.annotations.NotNull)1