diff --git a/plugins/IdeaTestAssistant/src/META-INF/plugin.xml b/plugins/IdeaTestAssistant/src/META-INF/plugin.xml index df0a2d1ce721..460595db0e63 100644 --- a/plugins/IdeaTestAssistant/src/META-INF/plugin.xml +++ b/plugins/IdeaTestAssistant/src/META-INF/plugin.xml @@ -18,6 +18,7 @@ + diff --git a/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/GotoTestRelatedProvider.java b/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/GotoTestRelatedProvider.java new file mode 100644 index 000000000000..1a9d044a558e --- /dev/null +++ b/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/GotoTestRelatedProvider.java @@ -0,0 +1,63 @@ +/* + * Copyright 2000-2011 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.testAssistant; + +import com.intellij.navigation.GotoRelatedItem; +import com.intellij.navigation.GotoRelatedProvider; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiFile; +import com.intellij.psi.search.FilenameIndex; +import com.intellij.psi.search.GlobalSearchScope; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Konstantin Bulenkov + */ +public class GotoTestRelatedProvider extends GotoRelatedProvider { + @NotNull + @Override + public List getItems(@NotNull DataContext context) { + final VirtualFile file = PlatformDataKeys.VIRTUAL_FILE.getData(context); + final Project project = PlatformDataKeys.PROJECT.getData(context); + if (file != null && project != null) { + final String ext = file.getExtension(); + String name = file.getNameWithoutExtension(); + final String filename; + if (ext != null && ext.length() > 0 && name.length() > 0) { + if (name.endsWith("Test") && name.length() > 4) { + filename = name.substring(0, name.length() - 4) + "." + ext; + } else { + filename = name + "Test." + ext; + } + final PsiFile[] files = FilenameIndex.getFilesByName(project, filename, GlobalSearchScope.allScope(project)); + if (files.length > 0) { + List items = new ArrayList(); + for (PsiFile psiFile : files) { + items.add(new GotoRelatedItem(psiFile)); + } + return items; + } + } + } + return super.getItems(context); + } +}