use of com.goide.psi.GoFunctionDeclaration in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoUnusedFunctionInspection method buildGoVisitor.
@NotNull
@Override
protected GoVisitor buildGoVisitor(@NotNull ProblemsHolder holder, @NotNull LocalInspectionToolSession session) {
return new GoVisitor() {
@Override
public void visitFunctionDeclaration(@NotNull GoFunctionDeclaration o) {
if (o.isBlank())
return;
GoFile file = o.getContainingFile();
String name = o.getName();
if (!canRun(name))
return;
if (GoConstants.MAIN.equals(file.getPackageName()) && GoConstants.MAIN.equals(name))
return;
if (GoConstants.INIT.equals(name))
return;
if (GoTestFinder.isTestFile(file) && GoTestFunctionType.fromName(name) != null)
return;
if (ReferencesSearch.search(o, o.getUseScope()).findFirst() == null) {
PsiElement id = o.getIdentifier();
TextRange range = TextRange.from(id.getStartOffsetInParent(), id.getTextLength());
holder.registerProblem(o, "Unused function <code>#ref</code> #loc", ProblemHighlightType.LIKE_UNUSED_SYMBOL, range, new GoDeleteQuickFix("Delete function", GoFunctionDeclaration.class), new GoRenameToBlankQuickFix(o));
}
}
};
}
use of com.goide.psi.GoFunctionDeclaration 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;
}
use of com.goide.psi.GoFunctionDeclaration in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoRunLineMarkerProvider 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 (GoRunUtil.isMainGoFile(file) && parent instanceof GoFunctionDeclaration) {
if (GoConstants.MAIN.equals(((GoFunctionDeclaration) parent).getName())) {
return new Info(AllIcons.RunConfigurations.TestState.Run, TOOLTIP_PROVIDER, ExecutorAction.getActions(0));
}
}
}
return null;
}
use of com.goide.psi.GoFunctionDeclaration in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoEmptySignatureQuickFix method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
GoFunctionDeclaration function = ObjectUtils.tryCast(startElement, GoFunctionDeclaration.class);
GoSignature signature = function != null ? function.getSignature() : null;
if (signature == null)
return;
signature.replace(GoElementFactory.createFunctionSignatureFromText(project, ""));
}
Aggregations