Search in sources :

Example 1 with DirectiveParamFileReference

use of ool.intellij.plugin.psi.DirectiveParamFileReference in project oxy-template-support-plugin by mutant-industries.

the class IncludedFilesCollector method visitDirectiveParamFileReference.

@Override
public void visitDirectiveParamFileReference(@NotNull DirectiveParamFileReference fileReference) {
    PsiFileSystemItem item;
    for (PsiReference reference : fileReference.getReferences()) {
        if (reference instanceof FileReference && (item = ((FileReference) reference).resolve()) != null && !(item instanceof PsiDirectory) && item.getContainingFile() != null) {
            VirtualFile file = item.getContainingFile().getVirtualFile();
            if (!includedFiles.containsValue(file) && !recursionGuard.contains(file)) {
                recursionGuard.add(file);
                item.getContainingFile().acceptChildren(this);
            }
            includedFiles.put(fileReference, file);
        }
    }
    super.visitElement(fileReference);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiReference(com.intellij.psi.PsiReference) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) FileReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference) DirectiveParamFileReference(ool.intellij.plugin.psi.DirectiveParamFileReference)

Example 2 with DirectiveParamFileReference

use of ool.intellij.plugin.psi.DirectiveParamFileReference in project oxy-template-support-plugin by mutant-industries.

the class RedundantIncludeInspection method buildVisitor.

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

        @Override
        public void visitDirectiveParamFileReference(@NotNull DirectiveParamFileReference fileReference) {
            final DirectiveStatement directiveStatement = PsiTreeUtil.getParentOfType(fileReference, DirectiveStatement.class);
            assert directiveStatement != null;
            if (!IncludeOnceDirective.NAME.equals(directiveStatement.getName()) || IncludeOptimizer.ignore(directiveStatement)) {
                return;
            }
            PsiReference[] references = fileReference.getReferences();
            PsiFile referencedFile = null;
            for (PsiReference reference : references) {
                if (reference instanceof FileReference && reference.resolve() instanceof PsiFile) {
                    referencedFile = (PsiFile) reference.resolve();
                    break;
                }
            }
            if (referencedFile == null) {
                return;
            }
            if (!directiveStatement.getContainingFile().getVirtualFile().getPath().equals(referencedFile.getVirtualFile().getPath())) {
                for (Map.Entry<PsiElement, JSElement> entry : OxyTemplateHelper.getUsedJsMacros(fileReference.getContainingFile()).entrySet()) {
                    if (entry.getValue().getContainingFile().getVirtualFile().getPath().equals(referencedFile.getVirtualFile().getPath())) {
                        return;
                    }
                }
            }
            holder.registerProblem(directiveStatement, getDisplayName(), ProblemHighlightType.LIKE_UNUSED_SYMBOL, new DeleteElementQuickFix());
        }
    };
}
Also used : PsiReference(com.intellij.psi.PsiReference) NotNull(org.jetbrains.annotations.NotNull) OxyTemplateElementVisitor(ool.intellij.plugin.psi.OxyTemplateElementVisitor) JSElement(com.intellij.lang.javascript.psi.JSElement) DeleteElementQuickFix(ool.intellij.plugin.editor.inspection.fix.DeleteElementQuickFix) PsiFile(com.intellij.psi.PsiFile) DirectiveParamFileReference(ool.intellij.plugin.psi.DirectiveParamFileReference) FileReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference) DirectiveParamFileReference(ool.intellij.plugin.psi.DirectiveParamFileReference) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement) DirectiveStatement(ool.intellij.plugin.psi.DirectiveStatement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiReference (com.intellij.psi.PsiReference)2 FileReference (com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference)2 DirectiveParamFileReference (ool.intellij.plugin.psi.DirectiveParamFileReference)2 JSElement (com.intellij.lang.javascript.psi.JSElement)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)1 Map (java.util.Map)1 DeleteElementQuickFix (ool.intellij.plugin.editor.inspection.fix.DeleteElementQuickFix)1 DirectiveStatement (ool.intellij.plugin.psi.DirectiveStatement)1 OxyTemplateElementVisitor (ool.intellij.plugin.psi.OxyTemplateElementVisitor)1 NotNull (org.jetbrains.annotations.NotNull)1