Search in sources :

Example 1 with SoftReference

use of com.intellij.reference.SoftReference in project intellij-community by JetBrains.

the class AssignableFromContextFilter method isAcceptable.

@Override
public boolean isAcceptable(Object element, PsiElement context) {
    if (myCurrentContext.get() != context) {
        myCurrentContext = new SoftReference(context);
        PsiElement cachedClass = context;
        while (cachedClass != null && !(cachedClass instanceof PsiClass)) cachedClass = cachedClass.getContext();
        myCachedClass = new SoftReference(cachedClass);
    }
    if (myCachedClass.get() instanceof PsiClass && element instanceof PsiClass) {
        final String qualifiedName = ((PsiClass) myCachedClass.get()).getQualifiedName();
        return qualifiedName != null && (qualifiedName.equals(((PsiClass) element).getQualifiedName()) || ((PsiClass) element).isInheritor((PsiClass) myCachedClass.get(), true));
    }
    return false;
}
Also used : SoftReference(com.intellij.reference.SoftReference) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement)

Example 2 with SoftReference

use of com.intellij.reference.SoftReference in project intellij-plugins by JetBrains.

the class FrameworkInfo method reloadFramework.

private Trinity<Framework, Set<String>, Set<String>> reloadFramework() {
    VirtualFile file = LocalFileSystem.getInstance().findFileByPath(myBridgeSupportPath);
    if (file == null)
        return Trinity.create(null, null, null);
    Set<String> idSelectorNames = null;
    Set<String> selectorNames = null;
    Framework framework = null;
    try {
        framework = BridgeSupportReader.read(myName, myVersion, file.getInputStream(), myOSX);
        idSelectorNames = ContainerUtil.newHashSet();
        selectorNames = ContainerUtil.newHashSet();
        for (Class clazz : framework.getClasses()) {
            for (Function function : clazz.getFunctions()) {
                if (function.isId()) {
                    idSelectorNames.addAll(MotionSymbolUtil.getSelectorNames(function));
                }
                selectorNames.add(function.getName());
            }
        }
    } catch (IOException e) {
        LOG.error("Failed to load bridgesupport file", e);
    }
    myFramework = framework != null ? new SoftReference<>(framework) : null;
    myIdSelectorNames = idSelectorNames != null ? new SoftReference<>(idSelectorNames) : null;
    mySelectorNames = selectorNames != null ? new SoftReference<>(selectorNames) : null;
    return Trinity.create(framework, idSelectorNames, selectorNames);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SoftReference(com.intellij.reference.SoftReference) IOException(java.io.IOException)

Example 3 with SoftReference

use of com.intellij.reference.SoftReference in project intellij-community by JetBrains.

the class SrcFileAnnotator method doGetLineMapping.

@Nullable
private SoftReference<TIntIntHashMap> doGetLineMapping(final long date, boolean oldToNew, MyEditorBean editorBean) {
    VirtualFile virtualFile = editorBean.getVFile();
    final byte[] oldContent;
    synchronized (LOCK) {
        if (myOldContent == null) {
            if (ApplicationManager.getApplication().isDispatchThread())
                return null;
            final LocalHistory localHistory = LocalHistory.getInstance();
            byte[] byteContent = localHistory.getByteContent(virtualFile, new FileRevisionTimestampComparator() {

                public boolean isSuitable(long revisionTimestamp) {
                    return revisionTimestamp < date;
                }
            });
            if (byteContent == null && virtualFile.getTimeStamp() > date) {
                byteContent = loadFromVersionControl(date, virtualFile);
            }
            myOldContent = new SoftReference<>(byteContent);
        }
        oldContent = myOldContent.get();
    }
    if (oldContent == null)
        return null;
    String[] coveredLines = getCoveredLines(oldContent, virtualFile);
    final Document document = editorBean.getDocument();
    if (document == null)
        return null;
    String[] currentLines = getUpToDateLines(document);
    String[] oldLines = oldToNew ? coveredLines : currentLines;
    String[] newLines = oldToNew ? currentLines : coveredLines;
    Diff.Change change;
    try {
        change = Diff.buildChanges(oldLines, newLines);
    } catch (FilesTooBigForDiffException e) {
        LOG.info(e);
        return null;
    }
    return new SoftReference<>(getCoverageVersionToCurrentLineMapping(change, oldLines.length));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) Diff(com.intellij.util.diff.Diff) FileRevisionTimestampComparator(com.intellij.history.FileRevisionTimestampComparator) Document(com.intellij.openapi.editor.Document) SoftReference(com.intellij.reference.SoftReference) LocalHistory(com.intellij.history.LocalHistory) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

SoftReference (com.intellij.reference.SoftReference)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 FileRevisionTimestampComparator (com.intellij.history.FileRevisionTimestampComparator)1 LocalHistory (com.intellij.history.LocalHistory)1 Document (com.intellij.openapi.editor.Document)1 PsiClass (com.intellij.psi.PsiClass)1 PsiElement (com.intellij.psi.PsiElement)1 Diff (com.intellij.util.diff.Diff)1 FilesTooBigForDiffException (com.intellij.util.diff.FilesTooBigForDiffException)1 IOException (java.io.IOException)1 Nullable (org.jetbrains.annotations.Nullable)1