Skip to content

Commit

Permalink
language and api migration for test framework class
Browse files Browse the repository at this point in the history
  • Loading branch information
Haehnchen committed Sep 15, 2017
1 parent 5bf5ef4 commit 34acbf2
Showing 1 changed file with 32 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
Expand All @@ -32,9 +31,8 @@
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import com.intellij.util.Processor;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.indexing.FileBasedIndexImpl;
import com.intellij.util.indexing.FileBasedIndex;
import com.intellij.util.indexing.ID;
import com.intellij.util.ui.UIUtil;
import com.jetbrains.php.lang.psi.elements.Function;
Expand Down Expand Up @@ -394,12 +392,9 @@ public void assertIndex(@NotNull ID<String, ?> id, boolean notCondition, @NotNul

final Collection<VirtualFile> virtualFiles = new ArrayList<VirtualFile>();

FileBasedIndexImpl.getInstance().getFilesWithKey(id, new HashSet<String>(Arrays.asList(key)), new Processor<VirtualFile>() {
@Override
public boolean process(VirtualFile virtualFile) {
virtualFiles.add(virtualFile);
return true;
}
FileBasedIndex.getInstance().getFilesWithKey(id, new HashSet<>(Collections.singletonList(key)), virtualFile -> {
virtualFiles.add(virtualFile);
return true;
}, GlobalSearchScope.allScope(getProject()));

if(notCondition && virtualFiles.size() > 0) {
Expand All @@ -411,11 +406,11 @@ public boolean process(VirtualFile virtualFile) {
}

public void assertIndexContainsKeyWithValue(@NotNull ID<String, String> id, @NotNull String key, @NotNull String value) {
assertContainsElements(FileBasedIndexImpl.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject())), value);
assertContainsElements(FileBasedIndex.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject())), value);
}

public <T> void assertIndexContainsKeyWithValue(@NotNull ID<String, T> id, @NotNull String key, @NotNull IndexValue.Assert<T> tAssert) {
List<T> values = FileBasedIndexImpl.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject()));
List<T> values = FileBasedIndex.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject()));
for (T t : values) {
if(tAssert.match(t)) {
return;
Expand Down Expand Up @@ -527,7 +522,7 @@ public void assertLineMarker(@NotNull PsiElement psiElement, @NotNull LineMarker
final List<PsiElement> elements = collectPsiElementsRecursive(psiElement);

for (LineMarkerProvider lineMarkerProvider : LineMarkerProviders.INSTANCE.allForLanguage(psiElement.getLanguage())) {
Collection<LineMarkerInfo> lineMarkerInfos = new ArrayList<LineMarkerInfo>();
Collection<LineMarkerInfo> lineMarkerInfos = new ArrayList<>();
lineMarkerProvider.collectSlowLineMarkers(elements, lineMarkerInfos);

if(lineMarkerInfos.size() == 0) {
Expand All @@ -549,7 +544,7 @@ public void assertLineMarkerIsEmpty(@NotNull PsiElement psiElement) {
final List<PsiElement> elements = collectPsiElementsRecursive(psiElement);

for (LineMarkerProvider lineMarkerProvider : LineMarkerProviders.INSTANCE.allForLanguage(psiElement.getLanguage())) {
Collection<LineMarkerInfo> lineMarkerInfos = new ArrayList<LineMarkerInfo>();
Collection<LineMarkerInfo> lineMarkerInfos = new ArrayList<>();
lineMarkerProvider.collectSlowLineMarkers(elements, lineMarkerInfos);

if(lineMarkerInfos.size() > 0) {
Expand Down Expand Up @@ -654,41 +649,33 @@ public MyLookupElementConditionalInsertRunnable(@NotNull LookupElementInsert.Ass

@Override
public void run() {
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
@Override
public void run() {
final CodeCompletionHandlerBase handler = new CodeCompletionHandlerBase(CompletionType.BASIC) {

@Override
protected void completionFinished(final CompletionProgressIndicator indicator, boolean hasModifiers) {

// find our lookup element
final LookupElement lookupElement = ContainerUtil.find(indicator.getLookup().getItems(), new Condition<LookupElement>() {
@Override
public boolean value(LookupElement lookupElement) {
return insert.match(lookupElement);
}
});

if(lookupElement == null) {
fail("No matching lookup element found");
}
CommandProcessor.getInstance().executeCommand(getProject(), () -> {
final CodeCompletionHandlerBase handler = new CodeCompletionHandlerBase(CompletionType.BASIC) {

@Override
protected void completionFinished(final CompletionProgressIndicator indicator, boolean hasModifiers) {

// overwrite behavior and force completion + insertHandler
CommandProcessor.getInstance().executeCommand(indicator.getProject(), new Runnable() {
@Override
public void run() {
indicator.setMergeCommand();
indicator.getLookup().finishLookup(Lookup.AUTO_INSERT_SELECT_CHAR, lookupElement);
}
}, "Autocompletion", null);
// find our lookup element
final LookupElement lookupElement = ContainerUtil.find(indicator.getLookup().getItems(), insert::match);

if(lookupElement == null) {
fail("No matching lookup element found");
}
};

Editor editor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(getEditor(), getFile());
handler.invokeCompletion(getProject(), editor);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
}
// overwrite behavior and force completion + insertHandler
CommandProcessor.getInstance().executeCommand(indicator.getProject(), new Runnable() {
@Override
public void run() {
indicator.setMergeCommand();
indicator.getLookup().finishLookup(Lookup.AUTO_INSERT_SELECT_CHAR, lookupElement);
}
}, "Autocompletion", null);
}
};

Editor editor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(getEditor(), getFile());
handler.invokeCompletion(getProject(), editor);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
}, null, null);
}
}
Expand Down

0 comments on commit 34acbf2

Please sign in to comment.