Search in sources :

Example 6 with CfmlFile

use of com.intellij.coldFusion.model.files.CfmlFile in project intellij-plugins by JetBrains.

the class CfmlUnitQualifiedNameLocationProvider method findElement.

@Nullable
private static PsiElement findElement(String link, Project project) {
    String[] location = link.split("::");
    int tokensNumber = location.length;
    if (tokensNumber <= 0 || tokensNumber > 3) {
        return null;
    }
    PsiElement result;
    String filePath = location[0];
    VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(filePath);
    if (virtualFile != null) {
        result = PsiManager.getInstance(project).findFile(virtualFile);
        if (result == null || !(result instanceof CfmlFile)) {
            return null;
        }
        // TODO: to move to index
        final CfmlTag[] tags = PsiTreeUtil.getChildrenOfType(result, CfmlTag.class);
        if (tags == null || tags.length == 0) {
            return result;
        }
        for (CfmlTag tag : tags) {
            if ("cfcomponent".equals(tag.getTagName().toLowerCase(Locale.ENGLISH))) {
                result = tag;
                break;
            }
        }
    } else {
        return null;
    }
    if (tokensNumber > 1) {
        String functionName = location[1];
        final CfmlTagFunctionImpl[] functions = PsiTreeUtil.getChildrenOfType(result, CfmlTagFunctionImpl.class);
        if (functions != null) {
            for (CfmlTagFunctionImpl function : functions) {
                if (functionName.equals(function.getName())) {
                    result = function.getNavigationElement();
                    break;
                }
            }
        }
        final CfmlFunctionImpl[] scriptFunctions = PsiTreeUtil.getChildrenOfType(result, CfmlFunctionImpl.class);
        if (scriptFunctions != null) {
            for (CfmlFunctionImpl function : scriptFunctions) {
                if (functionName.equals(function.getName())) {
                    result = function.getNavigationElement();
                    break;
                }
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CfmlFile(com.intellij.coldFusion.model.files.CfmlFile) CfmlTagFunctionImpl(com.intellij.coldFusion.model.psi.impl.CfmlTagFunctionImpl) CfmlFunctionImpl(com.intellij.coldFusion.model.psi.impl.CfmlFunctionImpl) CfmlTag(com.intellij.coldFusion.model.psi.CfmlTag) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with CfmlFile

use of com.intellij.coldFusion.model.files.CfmlFile in project intellij-plugins by JetBrains.

the class CfmlFoldingBuilder method buildFoldRegions.

@NotNull
public FoldingDescriptor[] buildFoldRegions(@NotNull ASTNode node, @NotNull Document document) {
    final PsiElement element = node.getPsi();
    if (element instanceof CfmlFile) {
        final CfmlFile file = (CfmlFile) element;
        final PsiElement[] children = file.getChildren();
        Collection<FoldingDescriptor> result = new LinkedList<>();
        for (PsiElement child : children) {
            if (child != null && (child instanceof CfmlCompositeElement || child instanceof PsiComment)) {
                List<FoldingDescriptor> descriptors = new ArrayList<>();
                addFoldingDescriptors(descriptors, child, document);
                result.addAll(descriptors);
            }
        }
        return result.toArray(FoldingDescriptor.EMPTY);
    }
    return FoldingDescriptor.EMPTY;
}
Also used : FoldingDescriptor(com.intellij.lang.folding.FoldingDescriptor) PsiComment(com.intellij.psi.PsiComment) CfmlFile(com.intellij.coldFusion.model.files.CfmlFile) ArrayList(java.util.ArrayList) CfmlCompositeElement(com.intellij.coldFusion.model.psi.CfmlCompositeElement) PsiElement(com.intellij.psi.PsiElement) LinkedList(java.util.LinkedList) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with CfmlFile

use of com.intellij.coldFusion.model.files.CfmlFile in project intellij-plugins by JetBrains.

the class CfmlPsiUtil method createConstantString.

@NotNull
public static PsiElement createConstantString(final String text, final Project project) {
    final CfmlFile dummyFile = createDummyFile(project, "<cffunction name=\"" + text + "\"></cffunction>");
    final PsiElement tag = dummyFile.getFirstChild();
    assert tag != null;
    final CfmlAttributeNameImpl namedAttribute = PsiTreeUtil.getChildOfType(tag, CfmlAttributeNameImpl.class);
    assert namedAttribute != null;
    final PsiElement element = namedAttribute.getValueElement();
    assert element != null;
    return element;
}
Also used : CfmlFile(com.intellij.coldFusion.model.files.CfmlFile) CfmlAttributeNameImpl(com.intellij.coldFusion.model.psi.impl.CfmlAttributeNameImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with CfmlFile

use of com.intellij.coldFusion.model.files.CfmlFile in project intellij-plugins by JetBrains.

the class CfmlComponentReference method addFakeMappingsForImports.

private static void addFakeMappingsForImports(CfmlComponentReference ref, CfmlMappingsConfig mappings) {
    if (PsiTreeUtil.getParentOfType(ref, CfmlImport.class) != null) {
        // create fake mappings for imports
        CfmlFile file = ref.getContainingFile();
        Collection<String> importStrings = file.getImportStrings();
        for (String importString : importStrings) {
            final int index = importString.lastIndexOf('.');
            if (index == -1) {
                continue;
            }
            final String leftMapping = file.getComponentQualifiedName(importString).substring(0, index);
            if (!StringUtil.isEmpty(leftMapping)) {
                mappings.putToServerMappings("", leftMapping);
            }
        }
    }
}
Also used : CfmlFile(com.intellij.coldFusion.model.files.CfmlFile)

Aggregations

CfmlFile (com.intellij.coldFusion.model.files.CfmlFile)9 NotNull (org.jetbrains.annotations.NotNull)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiElement (com.intellij.psi.PsiElement)3 CfmlMappingsConfig (com.intellij.coldFusion.UI.config.CfmlMappingsConfig)2 CfmlProjectConfiguration (com.intellij.coldFusion.UI.config.CfmlProjectConfiguration)2 Project (com.intellij.openapi.project.Project)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 InsertHandler (com.intellij.codeInsight.completion.InsertHandler)1 InsertionContext (com.intellij.codeInsight.completion.InsertionContext)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 CfmlLexer (com.intellij.coldFusion.model.lexer.CfmlLexer)1 CfmlCompositeElement (com.intellij.coldFusion.model.psi.CfmlCompositeElement)1 CfmlFunction (com.intellij.coldFusion.model.psi.CfmlFunction)1 CfmlTag (com.intellij.coldFusion.model.psi.CfmlTag)1 CfmlAttributeNameImpl (com.intellij.coldFusion.model.psi.impl.CfmlAttributeNameImpl)1 CfmlFunctionImpl (com.intellij.coldFusion.model.psi.impl.CfmlFunctionImpl)1 CfmlTagFunctionImpl (com.intellij.coldFusion.model.psi.impl.CfmlTagFunctionImpl)1 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1