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);
}
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;
}
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));
}
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();
}
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);
}
Aggregations