Search in sources :

Example 1 with CfmlFile

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

the class CfmlStructureViewElement method getChildrenBase.

@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
    PsiElement element = getElement();
    Collection<StructureViewTreeElement> result = new LinkedList<>();
    if (element != null && (element instanceof CfmlFile || !(element instanceof CfmlFunction))) {
        collectResultsFromChildren(result, element);
    }
    return result;
}
Also used : CfmlFunction(com.intellij.coldFusion.model.psi.CfmlFunction) CfmlFile(com.intellij.coldFusion.model.files.CfmlFile) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) PsiElement(com.intellij.psi.PsiElement) LinkedList(java.util.LinkedList) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CfmlFile

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

the class CfmlComponentReference method buildVariants.

@NotNull
public static Object[] buildVariants(String text, PsiFile containingFile, final Project project, @Nullable CfmlComponentReference reference, final boolean forceQualify) {
    Collection<Object> variants = new THashSet<>();
    String directoryName = "";
    if (text.contains(".")) {
        int i = text.lastIndexOf(".");
        directoryName = text.substring(0, i);
    }
    CfmlProjectConfiguration.State state = CfmlProjectConfiguration.getInstance(project).getState();
    CfmlMappingsConfig mappings = state != null ? state.getMapps().clone() : new CfmlMappingsConfig();
    adjustMappingsIfEmpty(mappings, project);
    if (reference != null)
        addFakeMappingsForImports(reference, mappings);
    List<String> realPossiblePaths = mappings.mapVirtualToReal(directoryName);
    for (String realPath : realPossiblePaths) {
        addVariantsFromPath(variants, directoryName, realPath);
    }
    for (String value : mappings.getServerMappings().keySet()) {
        if (value.startsWith(directoryName) && !value.isEmpty() && (StringUtil.startsWithChar(value, '/') || StringUtil.startsWithChar(value, '\\'))) {
            variants.add(value.replace('\\', '.').replace('/', '.').substring(1));
        }
    }
    containingFile = containingFile == null ? null : containingFile.getOriginalFile();
    if (containingFile != null && containingFile instanceof CfmlFile) {
        CfmlFile cfmlContainingFile = (CfmlFile) containingFile;
        if (directoryName.length() == 0) {
            PsiDirectory directory = cfmlContainingFile.getParent();
            if (directory != null) {
                addVariantsFromPath(variants, "", directory.getVirtualFile().getPresentableUrl());
            }
        } else {
            String dirPath = cfmlContainingFile.getParent().getVirtualFile().getPath() + "/" + directoryName.replaceAll("[./]+", "/");
            addVariantsFromPath(variants, directoryName, dirPath);
        }
    }
    final String finalDirectoryName = directoryName;
    return ContainerUtil.map2Array(variants, new Function<Object, Object>() {

        class DotInsertHandler implements InsertHandler<LookupElement> {

            @Override
            public void handleInsert(InsertionContext context, LookupElement item) {
                Document document = context.getDocument();
                int offset = context.getEditor().getCaretModel().getOffset();
                document.insertString(offset, ".");
                context.getEditor().getCaretModel().moveToOffset(offset + 1);
            }
        }

        public Object fun(final Object object) {
            if (object instanceof VirtualFile) {
                VirtualFile element = (VirtualFile) object;
                String elementNameWithoutExtension = element.getNameWithoutExtension();
                String name = forceQualify ? finalDirectoryName + (finalDirectoryName.length() == 0 ? "" : ".") + elementNameWithoutExtension : elementNameWithoutExtension;
                if (name.length() == 0)
                    name = element.getName();
                if (element.isDirectory()) {
                    return LookupElementBuilder.create(name).withIcon(DIRECTORY_CLOSED_ICON).withInsertHandler(new DotInsertHandler()).withCaseSensitivity(false);
                } else {
                    Icon icon = CLASS_ICON;
                    // choosing correct icon (class or interface)
                    if (CfmlIndex.getInstance(project).getComponentsByNameInScope(elementNameWithoutExtension, GlobalSearchScope.fileScope(project, element)).size() == 1) {
                        icon = CLASS_ICON;
                    } else if (CfmlIndex.getInstance(project).getInterfacesByNameInScope(elementNameWithoutExtension, GlobalSearchScope.fileScope(project, element)).size() == 1) {
                        icon = INTERFACE_ICON;
                    }
                    return LookupElementBuilder.create(name).withIcon(icon).withCaseSensitivity(false);
                }
            } else if (object instanceof String) {
                return LookupElementBuilder.create((String) object).withInsertHandler(new DotInsertHandler()).withCaseSensitivity(false);
            }
            return object;
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CfmlFile(com.intellij.coldFusion.model.files.CfmlFile) InsertionContext(com.intellij.codeInsight.completion.InsertionContext) LookupElement(com.intellij.codeInsight.lookup.LookupElement) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) CfmlMappingsConfig(com.intellij.coldFusion.UI.config.CfmlMappingsConfig) CfmlProjectConfiguration(com.intellij.coldFusion.UI.config.CfmlProjectConfiguration) InsertHandler(com.intellij.codeInsight.completion.InsertHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CfmlFile

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

the class CfmlComponentReference method resolveFromQualifiedName.

/*
  private class PrefixSuffix {
    // with dot separators
    public String prefix;
    // with file separators
    public String suffix;

    private PrefixSuffix(String prefix, String suffix) {
      this.prefix = prefix;
      this.suffix = suffix;
    }
  }

  private List<String> getPossiblePathsForComponent(String componentQualifiedName) {
    CfmlMappingsConfig mappings = CfmlProjectConfiguration.getInstance(getProject()).getMappings();
    List<String> result = new LinkedList<String>();
    StringBuilder prefix = new StringBuilder();
    String suffix = File.separatorChar + componentQualifiedName.replace('.', File.separatorChar);

    List<PrefixSuffix> ps = new LinkedList<PrefixSuffix>();
    while (suffix != "") {
      ps.add(new PrefixSuffix(prefix.toString(), suffix));
      // recount prefix and suffix
      int i = suffix.indexOf(File.separatorChar, 1);
      if (i == -1) {
        break;
      }
      String s = suffix.substring(1, i);
      if (prefix.length() != 0) {
        s = File.separatorChar + s;
      }
      prefix.append(s);
      suffix = suffix.substring(i);
    }

    for (PrefixSuffix p : ps) {
      String s = mappings.serverMappings.get(p.prefix);
      if (s != null) {
        result.add(s + p.suffix);
      }
    }
    return result;
  }
  */
/**
   * @param componentQualifiedName
   * @param originalFile           = getContainingFile().getOriginalFile();
   * @return
   */
public static Collection<CfmlComponent> resolveFromQualifiedName(String componentQualifiedName, @NotNull CfmlFile originalFile) {
    List<CfmlComponent> result = new ArrayList<>();
    if (componentQualifiedName == null) {
        return result;
    }
    Project project = originalFile.getProject();
    if (!componentQualifiedName.contains(".")) {
        // resolve with directory scope
        // PsiFile containingFile = getContainingFile();
        // containingFile = containingFile == null ? null : containingFile.getOriginalFile();
        {
            CfmlFile cfmlConteiningFile = originalFile;
            PsiDirectory directory = cfmlConteiningFile.getParent();
            if (directory != null) {
                GlobalSearchScope searchScope = GlobalSearchScopes.directoryScope(directory, false);
                final Collection<CfmlComponent> components = CfmlIndex.getInstance(project).getComponentsByNameInScope(componentQualifiedName, searchScope);
                components.addAll(CfmlIndex.getInstance(project).getInterfacesByNameInScope(componentQualifiedName, searchScope));
                for (CfmlComponent component : components) {
                    result.add(component);
                }
            } else {
                final Collection<CfmlComponent> components = CfmlIndex.getInstance(project).getComponentsByName(componentQualifiedName);
                components.addAll(CfmlIndex.getInstance(project).getInterfacesByName(componentQualifiedName));
                for (CfmlComponent component : components) {
                    result.add(component);
                }
            }
        }
    }
    if (result.isEmpty()) {
        String componentName = getComponentName(componentQualifiedName);
        int i = componentQualifiedName.lastIndexOf(".");
        String directoryName;
        if (i == -1) {
            directoryName = "";
        } else {
            directoryName = componentQualifiedName.substring(0, i);
        }
        CfmlProjectConfiguration.State state = CfmlProjectConfiguration.getInstance(project).getState();
        CfmlMappingsConfig mappings = state != null ? state.getMapps().clone() : new CfmlMappingsConfig();
        adjustMappingsIfEmpty(mappings, originalFile.getProject());
        // addFakeMappingsForResolution(mappings);
        List<String> realPossiblePaths = mappings.mapVirtualToReal(directoryName);
        // Collections.sort(realPossiblePaths);
        final Collection<CfmlComponent> components = CfmlIndex.getInstance(project).getComponentsByName(componentName);
        components.addAll(CfmlIndex.getInstance(project).getInterfacesByName(componentName));
        for (CfmlComponent component : components) {
            PsiDirectory parent = component.getContainingFile().getParent();
            if (parent == null) {
                continue;
            }
            VirtualFile virtualFile = parent.getVirtualFile();
            for (String realPath : realPossiblePaths) {
                if (FileUtil.toSystemIndependentName(realPath).equals(FileUtil.toSystemIndependentName(virtualFile.getPresentableUrl()))) {
                    result.add(component);
                    break;
                }
            }
        }
        for (String realPath : realPossiblePaths) {
            VirtualFile fileByUrl = LocalFileSystem.getInstance().findFileByPath(realPath);
            if (fileByUrl != null) {
                PsiFile file = PsiManager.getInstance(project).findFile(fileByUrl);
                if (file != null) {
                    PsiDirectory directory = file.getParent();
                    if (directory != null) {
                        GlobalSearchScope searchScope = GlobalSearchScopes.directoryScope(directory, false);
                        final Collection<CfmlComponent> componentsFromGlobalScope = CfmlIndex.getInstance(project).getComponentsByNameInScope(componentName, searchScope);
                        componentsFromGlobalScope.addAll(CfmlIndex.getInstance(project).getInterfacesByNameInScope(componentName, searchScope));
                        for (CfmlComponent component : componentsFromGlobalScope) {
                            result.add(component);
                        }
                    }
                }
            }
        }
    }
    if (result.isEmpty()) {
        final Couple<String> prefixAndName = CfmlUtil.getPrefixAndName(componentQualifiedName);
        final String componentName = prefixAndName.getSecond();
        final CfmlImport cfmlImport = CfmlUtil.getImportByPrefix(originalFile, prefixAndName.getFirst());
        if (cfmlImport != null && !StringUtil.isEmpty(componentName)) {
            String libtag = cfmlImport.getImportString();
            final VirtualFile folder = CfmlUtil.findFileByLibTag(originalFile, libtag);
            if (folder != null && folder.isDirectory()) {
                final GlobalSearchScope scope = GlobalSearchScopes.directoryScope(originalFile.getProject(), folder, true);
                result.addAll(CfmlIndex.getInstance(originalFile.getProject()).getComponentsByNameInScope(componentName, scope));
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CfmlFile(com.intellij.coldFusion.model.files.CfmlFile) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) CfmlMappingsConfig(com.intellij.coldFusion.UI.config.CfmlMappingsConfig) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Collection(java.util.Collection) CfmlProjectConfiguration(com.intellij.coldFusion.UI.config.CfmlProjectConfiguration)

Example 4 with CfmlFile

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

the class CfmlIndexPatternBuilder method getIndexingLexer.

public Lexer getIndexingLexer(@NotNull final PsiFile file) {
    if (file instanceof CfmlFile) {
        Project project = file.getProject();
        SqlLanguageDialect dialect = SqlDialectMappings.getMapping(project, file.getVirtualFile());
        Lexer sqlLexer = LanguageParserDefinitions.INSTANCE.forLanguage(dialect).createLexer(project);
        LayeredLexer cfmlLayeredLexer = new LayeredLexer(new CfmlLexer(true, project));
        cfmlLayeredLexer.registerLayer(new HtmlHighlightingLexer(), CfmlElementTypes.TEMPLATE_TEXT);
        cfmlLayeredLexer.registerLayer(sqlLexer, CfmlElementTypes.SQL);
        return cfmlLayeredLexer;
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) Lexer(com.intellij.lexer.Lexer) HtmlHighlightingLexer(com.intellij.lexer.HtmlHighlightingLexer) CfmlLexer(com.intellij.coldFusion.model.lexer.CfmlLexer) LayeredLexer(com.intellij.lexer.LayeredLexer) CfmlFile(com.intellij.coldFusion.model.files.CfmlFile) HtmlHighlightingLexer(com.intellij.lexer.HtmlHighlightingLexer) LayeredLexer(com.intellij.lexer.LayeredLexer) CfmlLexer(com.intellij.coldFusion.model.lexer.CfmlLexer) SqlLanguageDialect(com.intellij.sql.dialects.SqlLanguageDialect)

Example 5 with CfmlFile

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

the class CfmlPsiUtil method createReferenceExpression.

@NotNull
public static CfmlReferenceExpression createReferenceExpression(final String text, final Project project) {
    final CfmlFile dummyFile = createDummyFile(project, "<cfset " + text + " = 0>");
    final PsiElement tag = dummyFile.getFirstChild();
    assert tag != null;
    final CfmlAssignmentExpression assignment = PsiTreeUtil.getChildOfType(tag, CfmlAssignmentExpression.class);
    assert assignment != null;
    final CfmlReferenceExpression expression = PsiTreeUtil.getChildOfType(assignment, CfmlReferenceExpression.class);
    assert expression != null;
    return expression;
}
Also used : CfmlFile(com.intellij.coldFusion.model.files.CfmlFile) NotNull(org.jetbrains.annotations.NotNull)

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