Search in sources :

Example 1 with CfmlFunctionImpl

use of com.intellij.coldFusion.model.psi.impl.CfmlFunctionImpl 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)

Aggregations

CfmlFile (com.intellij.coldFusion.model.files.CfmlFile)1 CfmlTag (com.intellij.coldFusion.model.psi.CfmlTag)1 CfmlFunctionImpl (com.intellij.coldFusion.model.psi.impl.CfmlFunctionImpl)1 CfmlTagFunctionImpl (com.intellij.coldFusion.model.psi.impl.CfmlTagFunctionImpl)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 Nullable (org.jetbrains.annotations.Nullable)1