use of com.goide.psi.GoMethodDeclaration in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoTestLocator method getLocation.
@NotNull
@Override
public List<Location> getLocation(@NotNull String protocolId, @NotNull String path, @NotNull Project project, @NotNull GlobalSearchScope scope) {
if (PROTOCOL.equals(protocolId)) {
IdFilter idFilter = GoIdFilter.getTestsFilter(project);
List<String> locationDataItems = StringUtil.split(path, ".");
// Location is a function name, e.g. `TestCheckItOut`
if (locationDataItems.size() == 1) {
return ContainerUtil.mapNotNull(GoFunctionIndex.find(path, project, scope, idFilter), function -> PsiLocation.fromPsiElement(project, function));
}
// Location is a method name, e.g. `FooSuite.TestCheckItOut`
if (locationDataItems.size() == 2) {
List<Location> locations = ContainerUtil.newArrayList();
for (GoTypeSpec typeSpec : GoTypesIndex.find(locationDataItems.get(0), project, scope, idFilter)) {
for (GoMethodDeclaration method : typeSpec.getMethods()) {
if (locationDataItems.get(1).equals(method.getName())) {
ContainerUtil.addIfNotNull(locations, PsiLocation.fromPsiElement(method));
}
}
}
return locations;
}
} else if (SUITE_PROTOCOL.equals(protocolId)) {
IdFilter idFilter = GoIdFilter.getTestsFilter(project);
return ContainerUtil.mapNotNull(GoTypesIndex.find(path, project, scope, idFilter), spec -> PsiLocation.fromPsiElement(project, spec));
} else {
return Collections.emptyList();
}
throw new RuntimeException("Unsupported location: " + path);
}
use of com.goide.psi.GoMethodDeclaration in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoTestRunLineMarkerProvider method getInfo.
@Nullable
@Override
public Info getInfo(PsiElement e) {
if (e != null && e.getNode().getElementType() == GoTypes.IDENTIFIER) {
PsiElement parent = e.getParent();
PsiFile file = e.getContainingFile();
if (!GoTestFinder.isTestFile(file)) {
return null;
}
if (GoRunUtil.isPackageContext(e)) {
return new Info(AllIcons.RunConfigurations.TestState.Run_run, TOOLTIP_PROVIDER, ExecutorAction.getActions(0));
} else if (parent instanceof GoFunctionOrMethodDeclaration) {
GoTestFunctionType functionType = GoTestFunctionType.fromName(((GoFunctionOrMethodDeclaration) parent).getName());
if (functionType != null) {
if (parent instanceof GoFunctionDeclaration) {
return getInfo(GoTestLocator.PROTOCOL + "://" + ((GoFunctionDeclaration) parent).getName(), e.getProject());
} else if (parent instanceof GoMethodDeclaration) {
GoReceiver receiver = ((GoMethodDeclaration) parent).getReceiver();
PsiElement receiverIdentifier = receiver != null ? receiver.getIdentifier() : null;
String receiverText = receiverIdentifier != null ? receiverIdentifier.getText() + "." : "";
return getInfo(GoTestLocator.PROTOCOL + "://" + receiverText + ((GoMethodDeclaration) parent).getName(), e.getProject());
}
}
}
}
return null;
}
Aggregations