optimisation: do not load document during smart pointer creation

This commit is contained in:
Alexey Kudravtsev
2014-02-10 13:37:43 +04:00
parent 78581c6676
commit 9464870afd
2 changed files with 26 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -416,4 +416,22 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase {
Assert.assertNotNull(pointer1.getRange());
}
}
public void testSmartPointerCreationDoesNotLoadDocument() {
PsiPackage aPackage = myJavaFacade.findPackage("java.io");
SmartPointerManagerImpl smartPointerManager = (SmartPointerManagerImpl)SmartPointerManager.getInstance(myProject);
for (PsiClass aClass : aPackage.getClasses()) {
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
PsiFile file = aClass.getContainingFile();
Document document = documentManager.getCachedDocument(file);
if (document == null) { //ignore already loaded documents
SmartPsiElementPointer pointer = smartPointerManager.createSmartPsiElementPointer(aClass);
assertNull(documentManager.getCachedDocument(file));
//System.out.println("file = " + file);
}
else {
System.out.println("already loaded file = " + file);
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -62,14 +62,14 @@ public class SelfElementInfo implements SmartPointerElementInfo {
myProject = project;
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
Document document = documentManager.getDocument(containingFile);
if (document == null || documentManager.isUncommited(document)) {
Document document = documentManager.getCachedDocument(containingFile);
if (document != null && documentManager.isUncommited(document)) {
mySyncMarkerIsValid = false;
return;
}
mySyncMarkerIsValid = true;
setRange(range);
else {
mySyncMarkerIsValid = true;
setRange(range);
}
}
protected void setRange(@NotNull Segment range) {