Search in sources :

Example 1 with GoCallExpr

use of com.goide.psi.GoCallExpr 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);
                }
            }
        }
    }
}
Also used : GoFunctionOrMethodDeclaration(com.goide.psi.GoFunctionOrMethodDeclaration) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) GoCallExpr(com.goide.psi.GoCallExpr) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 2 with GoCallExpr

use of com.goide.psi.GoCallExpr in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoExpressionUtilTest method doTest.

@Override
protected void doTest() {
    PsiFile file = myFixture.configureByText("a.go", "package main\n func foo(i interface{}, j interface{}){}\n" + vars + "\n func _(){\n fo<caret>o(" + left + ", " + right + ")\n}");
    myFixture.checkHighlighting();
    GoCallExpr call = PsiTreeUtil.getParentOfType(file.findElementAt(myFixture.getCaretOffset()), GoCallExpr.class);
    assert call != null;
    List<GoExpression> expressions = call.getArgumentList().getExpressionList();
    assertTrue(left + " should " + (ok ? "" : "not ") + "be identical " + right, ok == GoExpressionUtil.identical(expressions.get(0), expressions.get(1)));
}
Also used : PsiFile(com.intellij.psi.PsiFile) GoExpression(com.goide.psi.GoExpression) GoCallExpr(com.goide.psi.GoCallExpr)

Example 3 with GoCallExpr

use of com.goide.psi.GoCallExpr in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoFunctionArgumentUnwrapper method doUnwrap.

@Override
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
    PsiElement parent = element.getParent();
    GoCallExpr call = parent != null ? ObjectUtils.tryCast(parent.getParent(), GoCallExpr.class) : null;
    if (call != null) {
        context.extractElement(element, call);
        context.delete(call);
    }
}
Also used : PsiElement(com.intellij.psi.PsiElement) GoCallExpr(com.goide.psi.GoCallExpr)

Aggregations

GoCallExpr (com.goide.psi.GoCallExpr)3 PsiElement (com.intellij.psi.PsiElement)2 GoExpression (com.goide.psi.GoExpression)1 GoFunctionOrMethodDeclaration (com.goide.psi.GoFunctionOrMethodDeclaration)1 Document (com.intellij.openapi.editor.Document)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1 PsiFile (com.intellij.psi.PsiFile)1