Search in sources :

Example 1 with RefManagerExtension

use of com.intellij.codeInspection.lang.RefManagerExtension in project intellij-community by JetBrains.

the class RefManagerImpl method cleanup.

public void cleanup() {
    myScope = null;
    myRefProject = null;
    synchronized (myRefTableLock) {
        (usePsiAsKey() ? myPsiToRefTable : myRefTable).clear();
        mySortedRefs = null;
    }
    myModules.clear();
    myContext = null;
    myGraphAnnotators.clear();
    for (RefManagerExtension extension : myExtensions.values()) {
        extension.cleanup();
    }
}
Also used : RefManagerExtension(com.intellij.codeInspection.lang.RefManagerExtension)

Example 2 with RefManagerExtension

use of com.intellij.codeInspection.lang.RefManagerExtension in project intellij-community by JetBrains.

the class RefManagerImpl method getGroupName.

@Override
@Nullable
public String getGroupName(final RefElement entity) {
    for (RefManagerExtension extension : myExtensions.values()) {
        final String groupName = extension.getGroupName(entity);
        if (groupName != null)
            return groupName;
    }
    final LinkedList<String> containingDirs = new LinkedList<>();
    RefEntity parent = entity.getOwner();
    while (parent != null && !(parent instanceof RefDirectory)) {
        parent = parent.getOwner();
    }
    while (parent instanceof RefDirectory) {
        containingDirs.addFirst(parent.getName());
        parent = parent.getOwner();
    }
    return containingDirs.isEmpty() ? null : StringUtil.join(containingDirs, File.separator);
}
Also used : RefManagerExtension(com.intellij.codeInspection.lang.RefManagerExtension) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with RefManagerExtension

use of com.intellij.codeInspection.lang.RefManagerExtension in project intellij-community by JetBrains.

the class RefManagerImpl method export.

@Override
public Element export(@NotNull RefEntity refEntity, @NotNull final Element element, final int actualLine) {
    refEntity = getRefinedElement(refEntity);
    Element problem = new Element("problem");
    if (refEntity instanceof RefDirectory) {
        Element fileElement = new Element("file");
        VirtualFile virtualFile = ((PsiDirectory) ((RefDirectory) refEntity).getElement()).getVirtualFile();
        fileElement.addContent(virtualFile.getUrl());
        problem.addContent(fileElement);
    } else if (refEntity instanceof RefElement) {
        final RefElement refElement = (RefElement) refEntity;
        final SmartPsiElementPointer pointer = refElement.getPointer();
        PsiFile psiFile = pointer.getContainingFile();
        if (psiFile == null)
            return null;
        Element fileElement = new Element("file");
        Element lineElement = new Element("line");
        final VirtualFile virtualFile = psiFile.getVirtualFile();
        LOG.assertTrue(virtualFile != null);
        fileElement.addContent(virtualFile.getUrl());
        if (actualLine == -1) {
            final Document document = PsiDocumentManager.getInstance(pointer.getProject()).getDocument(psiFile);
            LOG.assertTrue(document != null);
            final Segment range = pointer.getRange();
            lineElement.addContent(String.valueOf(range != null ? document.getLineNumber(range.getStartOffset()) + 1 : -1));
        } else {
            lineElement.addContent(String.valueOf(actualLine + 1));
        }
        problem.addContent(fileElement);
        problem.addContent(lineElement);
        appendModule(problem, refElement.getModule());
    } else if (refEntity instanceof RefModule) {
        final RefModule refModule = (RefModule) refEntity;
        final VirtualFile moduleFile = refModule.getModule().getModuleFile();
        final Element fileElement = new Element("file");
        fileElement.addContent(moduleFile != null ? moduleFile.getUrl() : refEntity.getName());
        problem.addContent(fileElement);
        appendModule(problem, refModule);
    }
    for (RefManagerExtension extension : myExtensions.values()) {
        extension.export(refEntity, problem);
    }
    new SmartRefElementPointerImpl(refEntity, true).writeExternal(problem);
    element.addContent(problem);
    return problem;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightElement(com.intellij.psi.impl.light.LightElement) Element(org.jdom.Element) RefManagerExtension(com.intellij.codeInspection.lang.RefManagerExtension) Document(com.intellij.openapi.editor.Document) Segment(com.intellij.openapi.util.Segment)

Example 4 with RefManagerExtension

use of com.intellij.codeInspection.lang.RefManagerExtension in project intellij-community by JetBrains.

the class RefManagerImpl method getReference.

@Nullable
@Override
public RefEntity getReference(final String type, final String fqName) {
    for (RefManagerExtension extension : myExtensions.values()) {
        final RefEntity refEntity = extension.getReference(type, fqName);
        if (refEntity != null)
            return refEntity;
    }
    if (SmartRefElementPointer.FILE.equals(type)) {
        return RefFileImpl.fileFromExternalName(this, fqName);
    }
    if (SmartRefElementPointer.MODULE.equals(type)) {
        return RefModuleImpl.moduleFromName(this, fqName);
    }
    if (SmartRefElementPointer.PROJECT.equals(type)) {
        return getRefProject();
    }
    if (SmartRefElementPointer.DIR.equals(type)) {
        String url = VfsUtilCore.pathToUrl(PathMacroManager.getInstance(getProject()).expandPath(fqName));
        VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(url);
        if (vFile != null) {
            final PsiDirectory dir = PsiManager.getInstance(getProject()).findDirectory(vFile);
            return getReference(dir);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RefManagerExtension(com.intellij.codeInspection.lang.RefManagerExtension) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with RefManagerExtension

use of com.intellij.codeInspection.lang.RefManagerExtension in project intellij-community by JetBrains.

the class RefManagerImpl method belongsToScope.

private boolean belongsToScope(final PsiElement psiElement, final boolean ignoreScope) {
    if (psiElement == null || !psiElement.isValid())
        return false;
    if (psiElement instanceof PsiCompiledElement)
        return false;
    final PsiFile containingFile = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() {

        @Override
        public PsiFile compute() {
            return psiElement.getContainingFile();
        }
    });
    if (containingFile == null) {
        return false;
    }
    for (RefManagerExtension extension : myExtensions.values()) {
        if (!extension.belongsToScope(psiElement))
            return false;
    }
    final Boolean inProject = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {

        @Override
        public Boolean compute() {
            return psiElement.getManager().isInProject(psiElement);
        }
    });
    return inProject.booleanValue() && (ignoreScope || getScope() == null || getScope().contains(psiElement));
}
Also used : RefManagerExtension(com.intellij.codeInspection.lang.RefManagerExtension)

Aggregations

RefManagerExtension (com.intellij.codeInspection.lang.RefManagerExtension)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Nullable (org.jetbrains.annotations.Nullable)2 Document (com.intellij.openapi.editor.Document)1 Segment (com.intellij.openapi.util.Segment)1 LightElement (com.intellij.psi.impl.light.LightElement)1 THashMap (gnu.trove.THashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Element (org.jdom.Element)1