Search in sources :

Example 31 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoLabelReference method getLabelDefinitions.

@NotNull
private Collection<GoLabelDefinition> getLabelDefinitions() {
    GoFunctionLit functionLit = PsiTreeUtil.getParentOfType(myElement, GoFunctionLit.class);
    PsiElement blockToSearch = functionLit != null ? functionLit.getBlock() : PsiTreeUtil.getTopmostParentOfType(myElement, GoBlock.class);
    return PsiTreeUtil.findChildrenOfType(blockToSearch, GoLabelDefinition.class);
}
Also used : PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoLabelReference method processDefinitionsForBreakReference.

private static boolean processDefinitionsForBreakReference(@NotNull GoBreakStatement breakStatement, @NotNull GoScopeProcessor processor) {
    PsiElement breakStatementOwner = GoPsiImplUtil.getBreakStatementOwner(breakStatement);
    while (breakStatementOwner != null) {
        PsiElement parent = breakStatementOwner.getParent();
        if (parent instanceof GoLabeledStatement) {
            if (!processor.execute(((GoLabeledStatement) parent).getLabelDefinition(), ResolveState.initial())) {
                return false;
            }
        }
        breakStatementOwner = GoPsiImplUtil.getBreakStatementOwner(breakStatementOwner);
    }
    return true;
}
Also used : PsiElement(com.intellij.psi.PsiElement)

Example 33 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoTypeUtil method getExpectedTypesFromArgumentList.

@NotNull
private static List<GoType> getExpectedTypesFromArgumentList(@NotNull GoExpression expression, @NotNull GoArgumentList argumentList) {
    PsiElement parentOfParent = argumentList.getParent();
    assert parentOfParent instanceof GoCallExpr;
    PsiReference reference = ((GoCallExpr) parentOfParent).getExpression().getReference();
    if (reference != null) {
        PsiElement resolve = reference.resolve();
        if (resolve instanceof GoFunctionOrMethodDeclaration) {
            GoSignature signature = ((GoFunctionOrMethodDeclaration) resolve).getSignature();
            if (signature != null) {
                List<GoExpression> exprList = argumentList.getExpressionList();
                List<GoParameterDeclaration> paramsList = signature.getParameters().getParameterDeclarationList();
                if (exprList.size() == 1) {
                    List<GoType> typeList = ContainerUtil.newSmartList();
                    for (GoParameterDeclaration parameterDecl : paramsList) {
                        for (GoParamDefinition parameter : parameterDecl.getParamDefinitionList()) {
                            typeList.add(getGoType(parameter, argumentList));
                        }
                        if (parameterDecl.getParamDefinitionList().isEmpty()) {
                            typeList.add(getInterfaceIfNull(parameterDecl.getType(), argumentList));
                        }
                    }
                    List<GoType> result = ContainerUtil.newSmartList(createGoTypeListOrGoType(typeList, argumentList));
                    if (paramsList.size() > 1) {
                        assert paramsList.get(0) != null;
                        result.add(getInterfaceIfNull(paramsList.get(0).getType(), argumentList));
                    }
                    return result;
                } else {
                    int position = exprList.indexOf(expression);
                    if (position >= 0) {
                        int i = 0;
                        for (GoParameterDeclaration parameterDecl : paramsList) {
                            int paramDeclSize = Math.max(1, parameterDecl.getParamDefinitionList().size());
                            if (i + paramDeclSize > position) {
                                return Collections.singletonList(getInterfaceIfNull(parameterDecl.getType(), argumentList));
                            }
                            i += paramDeclSize;
                        }
                    }
                }
            }
        }
    }
    return Collections.singletonList(getInterfaceIfNull(null, argumentList));
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoTypeUtil method getExpectedTypes.

@NotNull
public static List<GoType> getExpectedTypes(@NotNull GoExpression expression) {
    PsiElement parent = expression.getParent();
    if (parent == null)
        return Collections.emptyList();
    if (parent instanceof GoAssignmentStatement) {
        return getExpectedTypesFromAssignmentStatement(expression, (GoAssignmentStatement) parent);
    }
    if (parent instanceof GoRangeClause) {
        return Collections.singletonList(getGoType(null, parent));
    }
    if (parent instanceof GoRecvStatement) {
        return getExpectedTypesFromRecvStatement((GoRecvStatement) parent);
    }
    if (parent instanceof GoVarSpec) {
        return getExpectedTypesFromVarSpec(expression, (GoVarSpec) parent);
    }
    if (parent instanceof GoArgumentList) {
        return getExpectedTypesFromArgumentList(expression, (GoArgumentList) parent);
    }
    if (parent instanceof GoUnaryExpr) {
        GoUnaryExpr unaryExpr = (GoUnaryExpr) parent;
        if (unaryExpr.getSendChannel() != null) {
            GoType type = ContainerUtil.getFirstItem(getExpectedTypes(unaryExpr));
            GoType chanType = GoElementFactory.createType(parent.getProject(), "chan " + getInterfaceIfNull(type, parent).getText());
            return Collections.singletonList(chanType);
        } else {
            return Collections.singletonList(getGoType(null, parent));
        }
    }
    if (parent instanceof GoSendStatement || parent instanceof GoLeftHandExprList && parent.getParent() instanceof GoSendStatement) {
        GoSendStatement sendStatement = (GoSendStatement) (parent instanceof GoSendStatement ? parent : parent.getParent());
        return getExpectedTypesFromGoSendStatement(expression, sendStatement);
    }
    if (parent instanceof GoExprCaseClause) {
        return getExpectedTypesFromExprCaseClause((GoExprCaseClause) parent);
    }
    return Collections.emptyList();
}
Also used : PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoVarProcessor method add.

@Override
protected boolean add(@NotNull GoNamedElement o) {
    PsiElement commonParent = PsiTreeUtil.findCommonParent(o, myOrigin);
    if (commonParent instanceof GoRangeClause || commonParent instanceof GoTypeSwitchGuard)
        return true;
    PsiElement p = o.getParent();
    boolean inVarOrRange = PsiTreeUtil.getParentOfType(o, GoVarDeclaration.class) != null || p instanceof GoRangeClause;
    boolean differentBlocks = differentBlocks(o);
    boolean inShortVar = PsiTreeUtil.getParentOfType(o, GoShortVarDeclaration.class, GoRecvStatement.class) != null;
    if (inShortVar && differentBlocks && myImShortVarDeclaration)
        return true;
    if (differentBlocks && inShortVar && !inVarOrRange && getResult() != null && !myIsCompletion)
        return true;
    if (inShortVar && fromNotAncestorBlock(o))
        return true;
    if (myParentGuard != null && o instanceof GoVarDefinition && p.isEquivalentTo(myParentGuard))
        return true;
    return super.add(o);
}
Also used : PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)3198 Nullable (org.jetbrains.annotations.Nullable)493 PsiFile (com.intellij.psi.PsiFile)474 NotNull (org.jetbrains.annotations.NotNull)442 TextRange (com.intellij.openapi.util.TextRange)239 PsiReference (com.intellij.psi.PsiReference)227 Project (com.intellij.openapi.project.Project)222 VirtualFile (com.intellij.openapi.vfs.VirtualFile)210 ArrayList (java.util.ArrayList)195 ASTNode (com.intellij.lang.ASTNode)142 XmlTag (com.intellij.psi.xml.XmlTag)134 PsiClass (com.intellij.psi.PsiClass)115 Editor (com.intellij.openapi.editor.Editor)112 Document (com.intellij.openapi.editor.Document)109 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)85 PsiDirectory (com.intellij.psi.PsiDirectory)80 IElementType (com.intellij.psi.tree.IElementType)78 Module (com.intellij.openapi.module.Module)77 PsiMethod (com.intellij.psi.PsiMethod)73 UsageInfo (com.intellij.usageView.UsageInfo)70