blob: bbe3e54899f7fe41915bf5680bc5f01a5adaac6d [file] [log] [blame]
Tor Norbyec667c1f2014-05-28 17:06:51 -07001/*
2 * Copyright 2000-2014 JetBrains s.r.o.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.jetbrains.idea.devkit.testAssistant;
17
18import com.intellij.execution.Location;
19import com.intellij.navigation.GotoRelatedItem;
20import com.intellij.navigation.GotoRelatedProvider;
21import com.intellij.openapi.actionSystem.CommonDataKeys;
22import com.intellij.openapi.actionSystem.DataContext;
23import com.intellij.openapi.editor.Editor;
24import com.intellij.openapi.project.Project;
25import com.intellij.openapi.vfs.VirtualFile;
26import com.intellij.util.Function;
27import com.intellij.util.containers.ContainerUtil;
28import org.jetbrains.annotations.NotNull;
29
30import java.util.Collections;
31import java.util.List;
32
33public class TestCaseAsRelatedFileProvider extends GotoRelatedProvider {
34 @NotNull
35 @Override
36 public List<? extends GotoRelatedItem> getItems(@NotNull DataContext context) {
37 final Editor editor = CommonDataKeys.EDITOR.getData(context);
38 final Project project = CommonDataKeys.PROJECT.getData(context);
39 final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(context);
40 if (editor == null || file == null || project == null) {
41 return Collections.emptyList();
42 }
43
44 final List<Location> locations = TestLocationDataRule.collectRelativeLocations(project, file);
45 if (locations.isEmpty()) {
46 return Collections.emptyList();
47 }
48
49 return ContainerUtil.map(locations, new Function<Location, GotoRelatedItem>() {
50 @Override
51 public GotoRelatedItem fun(Location location) {
52 return new GotoRelatedItem(location.getPsiElement());
53 }
54 });
55 }
56}