use of com.goide.psi.GoFunctionOrMethodDeclaration in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoRecursiveCallMarkerProvider method collectSlowLineMarkers.
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
Set<Integer> lines = ContainerUtil.newHashSet();
for (PsiElement element : elements) {
if (element instanceof GoCallExpr) {
PsiElement resolve = GoPsiImplUtil.resolveCall((GoCallExpr) element);
if (resolve instanceof GoFunctionOrMethodDeclaration) {
if (isRecursiveCall(element, (GoFunctionOrMethodDeclaration) resolve)) {
PsiDocumentManager instance = PsiDocumentManager.getInstance(element.getProject());
Document document = instance.getDocument(element.getContainingFile());
int textOffset = element.getTextOffset();
if (document == null)
continue;
int lineNumber = document.getLineNumber(textOffset);
if (!lines.contains(lineNumber)) {
result.add(new RecursiveMethodCallMarkerInfo(element));
}
lines.add(lineNumber);
}
}
}
}
}
use of com.goide.psi.GoFunctionOrMethodDeclaration in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoAddFunctionBlockIntention method invoke.
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
PsiElement parent = element.getParent();
if (parent instanceof GoFunctionOrMethodDeclaration) {
GoBlock block = ((GoFunctionOrMethodDeclaration) parent).getBlock();
if (block == null) {
GoBlock newBlock = ObjectUtils.tryCast(parent.add(GoElementFactory.createBlock(project)), GoBlock.class);
if (newBlock != null) {
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
new GoSmartEnterProcessor.PlainEnterProcessor().doEnter(newBlock, newBlock.getContainingFile(), editor, false);
}
}
}
}
use of com.goide.psi.GoFunctionOrMethodDeclaration in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoTestRunConfigurationProducerBase method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(@NotNull GoTestRunConfiguration configuration, ConfigurationContext context, Ref sourceElement) {
PsiElement contextElement = GoRunUtil.getContextElement(context);
if (contextElement == null) {
return false;
}
Module module = ModuleUtilCore.findModuleForPsiElement(contextElement);
Project project = contextElement.getProject();
if (module == null || !GoSdkService.getInstance(project).isGoModule(module))
return false;
if (!myFramework.isAvailable(module))
return false;
configuration.setModule(module);
configuration.setTestFramework(myFramework);
if (contextElement instanceof PsiDirectory) {
configuration.setName(getPackageConfigurationName(((PsiDirectory) contextElement).getName()));
configuration.setKind(GoTestRunConfiguration.Kind.DIRECTORY);
String directoryPath = ((PsiDirectory) contextElement).getVirtualFile().getPath();
configuration.setDirectoryPath(directoryPath);
configuration.setWorkingDirectory(directoryPath);
return true;
}
PsiFile file = contextElement.getContainingFile();
if (myFramework.isAvailableOnFile(file)) {
String importPath = ((GoFile) file).getImportPath(false);
if (GoRunUtil.isPackageContext(contextElement) && StringUtil.isNotEmpty(importPath)) {
configuration.setKind(GoTestRunConfiguration.Kind.PACKAGE);
configuration.setPackage(importPath);
configuration.setName(getPackageConfigurationName(importPath));
return true;
} else {
GoFunctionOrMethodDeclaration function = findTestFunctionInContext(contextElement);
if (function != null) {
if (myFramework.isAvailableOnFunction(function)) {
configuration.setName(getFunctionConfigurationName(function, file.getName()));
configuration.setPattern("^" + function.getName() + "$");
configuration.setKind(GoTestRunConfiguration.Kind.PACKAGE);
configuration.setPackage(StringUtil.notNullize(((GoFile) file).getImportPath(false)));
return true;
}
} else if (hasSupportedFunctions((GoFile) file)) {
configuration.setName(getFileConfigurationName(file.getName()));
configuration.setKind(GoTestRunConfiguration.Kind.FILE);
configuration.setFilePath(file.getVirtualFile().getPath());
return true;
}
}
}
return false;
}
use of com.goide.psi.GoFunctionOrMethodDeclaration in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoTestRunConfigurationProducerBase method isConfigurationFromContext.
@Override
public boolean isConfigurationFromContext(@NotNull GoTestRunConfiguration configuration, ConfigurationContext context) {
PsiElement contextElement = GoRunUtil.getContextElement(context);
if (contextElement == null)
return false;
Module module = ModuleUtilCore.findModuleForPsiElement(contextElement);
if (!Comparing.equal(module, configuration.getConfigurationModule().getModule()))
return false;
if (!Comparing.equal(myFramework, configuration.getTestFramework()))
return false;
PsiFile file = contextElement.getContainingFile();
switch(configuration.getKind()) {
case DIRECTORY:
if (contextElement instanceof PsiDirectory) {
String directoryPath = ((PsiDirectory) contextElement).getVirtualFile().getPath();
return FileUtil.pathsEqual(configuration.getDirectoryPath(), directoryPath) && FileUtil.pathsEqual(configuration.getWorkingDirectory(), directoryPath);
}
case PACKAGE:
if (!GoTestFinder.isTestFile(file))
return false;
if (!Comparing.equal(((GoFile) file).getImportPath(false), configuration.getPackage()))
return false;
if (GoRunUtil.isPackageContext(contextElement) && configuration.getPattern().isEmpty())
return true;
GoFunctionOrMethodDeclaration contextFunction = findTestFunctionInContext(contextElement);
return contextFunction != null && myFramework.isAvailableOnFunction(contextFunction) ? configuration.getPattern().equals("^" + contextFunction.getName() + "$") : configuration.getPattern().isEmpty();
case FILE:
GoFunctionOrMethodDeclaration contextTestFunction = findTestFunctionInContext(contextElement);
return contextTestFunction == null && GoTestFinder.isTestFile(file) && FileUtil.pathsEqual(configuration.getFilePath(), file.getVirtualFile().getPath());
}
return false;
}
use of com.goide.psi.GoFunctionOrMethodDeclaration 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