Search in sources :

Example 1 with PerlString

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

the class PerlElementFactory method createBareString.

public static PerlString createBareString(Project project, String content) {
    PerlFileImpl file = createFile(project, content + " => 42;");
    PerlString string = PsiTreeUtil.findChildOfType(file, PerlString.class);
    assert string != null : "While creating bare string from: " + content;
    return string;
}
Also used : PerlFileImpl(com.perl5.lang.perl.psi.impl.PerlFileImpl)

Example 2 with PerlString

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

the class PerlMooseExtendsStatementImpl method getParentsList.

@NotNull
protected List<String> getParentsList() {
    List<String> result = new ArrayList<>();
    PsiElement expr = getExpr();
    if (expr != null) {
        if (expr instanceof PerlString) {
            String content = ElementManipulators.getValueText(expr);
            if (!content.isEmpty()) {
                result.add(content);
            }
        } else if (expr instanceof PsiPerlCommaSequenceExpr) {
            PsiElement element = expr.getFirstChild();
            while (element != null) {
                if (element instanceof PerlString) {
                    String content = ElementManipulators.getValueText(element);
                    if (!content.isEmpty()) {
                        result.add(content);
                    }
                }
                element = element.getNextSibling();
            }
        } else if (expr instanceof PsiPerlStringList) {
            for (PsiElement element : PerlPsiUtil.collectStringElements(expr.getFirstChild())) {
                String content = element.getText();
                if (!content.isEmpty()) {
                    result.add(content);
                }
            }
        } else {
        // todo we need to somehow mark statement as bad
        }
    }
    return result;
}
Also used : PerlString(com.perl5.lang.perl.psi.PerlString) ArrayList(java.util.ArrayList) PsiPerlStringList(com.perl5.lang.perl.psi.PsiPerlStringList) PerlString(com.perl5.lang.perl.psi.PerlString) PsiPerlCommaSequenceExpr(com.perl5.lang.perl.psi.PsiPerlCommaSequenceExpr) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PerlString

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

the class HTMLMasonComponentCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement position = parameters.getPosition();
    PsiElement parent = position.getParent();
    PsiFile file = position.getContainingFile();
    if (parent instanceof PerlString && file instanceof HTMLMasonFileImpl) {
        PsiReference[] references = parent.getReferences();
        for (PsiReference reference : references) {
            TextRange refRange = reference.getRangeInElement();
            if (refRange.contains(position.getStartOffsetInParent())) {
                Project project = position.getProject();
                String fullPrefix = refRange.substring(parent.getText()).replace(CompletionInitializationContext.DUMMY_IDENTIFIER, "").replace(CompletionInitializationContext.DUMMY_IDENTIFIER_TRIMMED, "");
                final CompletionResultSet finalResultSet = result.withPrefixMatcher(fullPrefix);
                ;
                if (reference instanceof HTMLMasonMethodReference) {
                    PsiElement firstReferenceTarget = references[0].resolve();
                    if (firstReferenceTarget instanceof HTMLMasonFileImpl) {
                        HTMLMasonCompletionUtil.fillWithMethods(finalResultSet, (HTMLMasonFileImpl) firstReferenceTarget);
                    }
                } else {
                    HTMLMasonCompletionUtil.fillWithComponentSlugs(finalResultSet);
                    HTMLMasonCompletionUtil.fillWithSubcomponents(finalResultSet, (HTMLMasonFileImpl) file);
                    if (!StringUtil.startsWith(fullPrefix, "/")) {
                        HTMLMasonCompletionUtil.fillWithRelativeSubcomponents(finalResultSet, project, (HTMLMasonFileImpl) file);
                    } else {
                        HTMLMasonCompletionUtil.fillWithAbsoluteSubcomponents(finalResultSet, project);
                    }
                }
                result.stopHere();
                break;
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) HTMLMasonFileImpl(com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl) PerlString(com.perl5.lang.perl.psi.PerlString) HTMLMasonMethodReference(com.perl5.lang.htmlmason.parser.psi.references.HTMLMasonMethodReference) PsiReference(com.intellij.psi.PsiReference) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange) PerlString(com.perl5.lang.perl.psi.PerlString) PsiElement(com.intellij.psi.PsiElement)

Example 4 with PerlString

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

the class HTMLMasonMethodReference method resolveInner.

@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
    PerlString element = getElement();
    String methodName = getRangeInElement().substring(element.getText());
    if (StringUtil.isNotEmpty(methodName)) {
        PsiReference[] references = element.getReferences();
        if (references.length == 2) {
            PsiReference componentReference = references[0];
            PsiElement startComponent = componentReference.resolve();
            if (startComponent instanceof HTMLMasonFileImpl) {
                HTMLMasonMethodDefinition methodDefinition = ((HTMLMasonFileImpl) startComponent).findMethodDefinitionByNameInThisOrParents(methodName);
                if (methodDefinition != null) {
                    return new ResolveResult[] { new PsiElementResolveResult(methodDefinition) };
                }
            }
        }
    }
    return ResolveResult.EMPTY_ARRAY;
}
Also used : HTMLMasonMethodDefinition(com.perl5.lang.htmlmason.parser.psi.HTMLMasonMethodDefinition) HTMLMasonFileImpl(com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl) PerlString(com.perl5.lang.perl.psi.PerlString) PerlString(com.perl5.lang.perl.psi.PerlString) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with PerlString

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

the class HTMLMasonElementFactory method getBareCallString.

@Nullable
public static PerlString getBareCallString(Project project, String content) {
    String fileContent = "<& " + content + "&>";
    HTMLMasonFileImpl file = createFile(project, fileContent);
    return PsiTreeUtil.findChildOfType(file, PerlString.class);
}
Also used : HTMLMasonFileImpl(com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl) PerlString(com.perl5.lang.perl.psi.PerlString) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PerlString (com.perl5.lang.perl.psi.PerlString)7 PsiElement (com.intellij.psi.PsiElement)5 PsiFile (com.intellij.psi.PsiFile)3 HTMLMasonFileImpl (com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl)3 NotNull (org.jetbrains.annotations.NotNull)3 Project (com.intellij.openapi.project.Project)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiReference (com.intellij.psi.PsiReference)2 PsiPerlCommaSequenceExpr (com.perl5.lang.perl.psi.PsiPerlCommaSequenceExpr)2 PerlFileImpl (com.perl5.lang.perl.psi.impl.PerlFileImpl)2 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)1 FileType (com.intellij.openapi.fileTypes.FileType)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 IElementType (com.intellij.psi.tree.IElementType)1 HTMLMasonMethodDefinition (com.perl5.lang.htmlmason.parser.psi.HTMLMasonMethodDefinition)1 HTMLMasonMethodReference (com.perl5.lang.htmlmason.parser.psi.references.HTMLMasonMethodReference)1 HTMLMasonFlagsStatementStub (com.perl5.lang.htmlmason.parser.stubs.HTMLMasonFlagsStatementStub)1 MasonPurePerlComponentFileType (com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType)1