protected boolean shouldCreateStubInBlock(ASTNode node) { return PsiTreeUtil.getParentOfType(node.getPsi(), GoBlock.class) == null; } }
@Override public boolean shouldCreateStub(@NotNull ASTNode node) { return super.shouldCreateStub(node) && PsiTreeUtil.getParentOfType(node.getPsi(), GoFunctionOrMethodDeclaration.class) == null; } }
@Override public boolean shouldCreateStub(@NotNull ASTNode node) { return super.shouldCreateStub(node) && PsiTreeUtil.getParentOfType(node.getPsi(), GoFunctionOrMethodDeclaration.class) == null; } }
@Override public boolean shouldCreateStub(ASTNode node) { return super.shouldCreateStub(node) && PsiTreeUtil.getParentOfType(node.getPsi(), GoFunctionOrMethodDeclaration.class) == null; }
@Override protected boolean shouldCreateStubInBlock(ASTNode node) { return PsiTreeUtil.getParentOfType(node.getPsi(), GoTypeSpec.class) != null || super.shouldCreateStubInBlock(node); }
@Override public boolean shouldCreateStub(@NotNull ASTNode node) { if (!super.shouldCreateStub(node)) return false; PsiElement psi = node.getPsi(); return psi instanceof GoNamedElement && StringUtil.isNotEmpty(((GoNamedElement)psi).getName()); }
@NotNull private GoFormattingBlock buildSubBlock(@NotNull ASTNode child, @Nullable Alignment alignment) { if (child.getPsi() instanceof GoType && child.getTreeParent().getElementType() == FIELD_DECLARATION) { alignment = getUserData(TYPE_ALIGNMENT_INSIDE_STRUCT); } Indent indent = calcIndent(child); return new GoFormattingBlock(child, alignment, indent, null, mySettings, mySpacingBuilder); }
@Override public boolean shouldCreateStub(ASTNode node) { Call call = (Call) node.getPsi(); return isNameable(call) && hasNameOrCanonicalNames(call); } }
private static Couple<PsiElement> getElementRange(@NotNull Editor editor, @NotNull PsiFile file) { Pair<PsiElement, PsiElement> primeElementRangePair = getElementRange(editor, file, getLineRangeFromSelection(editor)); if (primeElementRangePair == null) return null; ASTNode firstNode = TreeUtil.findFirstLeaf(primeElementRangePair.first.getNode()); ASTNode lastNode = TreeUtil.findLastLeaf(primeElementRangePair.second.getNode()); if (firstNode == null || lastNode == null) return null; return Couple.of(firstNode.getPsi(), lastNode.getPsi()); }
@Nullable private static Couple<PsiElement> getElementRange(@NotNull GoFile file, int startOffset, int endOffset) { PsiElement startElement = findNotWhiteSpaceElementAtOffset(file, startOffset, true); PsiElement endElement = findNotWhiteSpaceElementAtOffset(file, endOffset - 1, false); if (startElement == null || endElement == null) return null; ASTNode startNode = TreeUtil.findFirstLeaf(startElement.getNode()); ASTNode endNode = TreeUtil.findLastLeaf(endElement.getNode()); if (startNode == null || endNode == null) return null; startElement = startNode.getPsi(); endElement = endNode.getPsi(); if (startElement == null || endElement == null) return null; return Couple.of(startElement, endElement); }
@Override public boolean shouldCreateStub(@NotNull ASTNode node) { if (!super.shouldCreateStub(node)) { return false; } PsiElement psi = node.getPsi(); return psi instanceof BallerinaNamedElement && StringUtil.isNotEmpty(((BallerinaNamedElement) psi).getName()); }
@Override public boolean shouldCreateStub(ASTNode node) { return super.shouldCreateStub(node) && node.getElementType() == GoTypes.VAR_SPEC && PsiTreeUtil.getParentOfType(node.getPsi(), GoFunctionOrMethodDeclaration.class) == null; }
@NotNull private WrapType noParenthesesOneArgumentWrapType(@NotNull ASTNode noParenthesesOneArgument) { ASTNode noParenthesesOneArgumentParent = noParenthesesOneArgument.getTreeParent(); WrapType wrapType = WrapType.ALWAYS; if (UNMATCHED_CALL_TOKEN_SET.contains(noParenthesesOneArgumentParent.getElementType())) { Call call = noParenthesesOneArgumentParent.getPsi(Call.class); if (IMPORT.equals(call.functionName())) { /* Usage of `import` with `only` or `except` is meant for compactness, so applying keyword exclusivity would go against that */ wrapType = WrapType.CHOP_DOWN_IF_LONG; } } return wrapType; }
@NotNull public static Trinity<GoExpression, GoExpression, GoExpression> getIndices(@NotNull GoIndexOrSliceExpr slice) { GoExpression start; GoExpression end = null; GoExpression max = null; ASTNode[] colons = slice.getNode().getChildren(TokenSet.create(GoTypes.COLON)); List<GoExpression> exprList = slice.getExpressionList(); start = ContainerUtil.getFirstItem(getExpressionsInRange(exprList, slice.getLbrack(), colons.length > 0 ? colons[0].getPsi() : null)); if (colons.length == 1) { end = ContainerUtil.getFirstItem(getExpressionsInRange(exprList, colons[0].getPsi(), slice.getRbrack())); } if (colons.length == 2) { end = ContainerUtil.getFirstItem(getExpressionsInRange(exprList, colons[0].getPsi(), colons[1].getPsi())); max = ContainerUtil.getFirstItem(getExpressionsInRange(exprList, colons[1].getPsi(), slice.getRbrack())); } return Trinity.create(start, end, max); }
private CodeStyleSettings codeStyleSettings(@NotNull ASTNode node) { return CodeStyleSettingsManager .getInstance(node.getPsi().getProject()) .getCurrentSettings() .getCustomSettings(CodeStyleSettings.class); }
private CommonCodeStyleSettings commonCodeStyleSettings(@NotNull ASTNode node) { return CodeStyleSettingsManager .getInstance(node.getPsi().getProject()) .getCurrentSettings() .getCommonSettings(ElixirLanguage.INSTANCE); }
@Nullable private static PsiElement findTargetElement(@NotNull Project project, @NotNull XSourcePosition position, @NotNull Editor editor, @NotNull String name) { PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null || !file.getVirtualFile().equals(position.getFile())) return null; ASTNode leafElement = file.getNode().findLeafElementAt(position.getOffset()); if (leafElement == null) return null; GoTopLevelDeclaration topLevel = PsiTreeUtil.getTopmostParentOfType(leafElement.getPsi(), GoTopLevelDeclaration.class); SyntaxTraverser<PsiElement> traverser = SyntaxTraverser.psiTraverser(topLevel) .filter(e -> e instanceof GoNamedElement && Comparing.equal(name, ((GoNamedElement)e).getName())); Iterator<PsiElement> iterator = traverser.iterator(); return iterator.hasNext() ? iterator.next() : null; }
@Override protected boolean isRegionCollapsedByDefault(@NotNull ASTNode node) { IElementType type = node.getElementType(); if (type == GoParserDefinition.LINE_COMMENT || type == GoParserDefinition.MULTILINE_COMMENT) { return CodeFoldingSettings.getInstance().COLLAPSE_DOC_COMMENTS; } if (type == GoTypes.BLOCK && CodeFoldingSettings.getInstance().COLLAPSE_METHODS) { ASTNode parent = node.getTreeParent(); return parent != null && parent.getPsi() instanceof GoFunctionOrMethodDeclaration; } return CodeFoldingSettings.getInstance().COLLAPSE_IMPORTS && node.getElementType() == GoTypes.IMPORT_LIST; } }
private boolean firstOnLine(@NotNull ASTNode node) { Document document = document(node.getPsi()); assert document != null; int nodeStartOffset = node.getStartOffset(); int lineNumber = document.getLineNumber(nodeStartOffset); int lineStartOffset = document.getLineStartOffset(lineNumber); String prefix = document.getText(new TextRange(lineStartOffset, nodeStartOffset)); return isWhitespace(prefix); }
@NotNull private Indent calcIndent(@NotNull ASTNode child) { IElementType parentType = myNode.getElementType(); IElementType type = child.getElementType(); if (type == SWITCH_START) return Indent.getNoneIndent(); if (parentType == BLOCK && type == SELECT_STATEMENT) return Indent.getNoneIndent(); if (parentType == SELECT_STATEMENT && type == RBRACE) return Indent.getNormalIndent(); if (parentType == ARGUMENT_LIST && type != LPAREN && type != RPAREN) return Indent.getNormalIndent(); if ((parentType == EXPR_CASE_CLAUSE || parentType == TYPE_CASE_CLAUSE) && (type == CASE || type == DEFAULT)) return Indent.getNoneIndent(); if (BLOCKS_TOKEN_SET.contains(parentType)) return indentIfNotBrace(child); if (parentType == IMPORT_DECLARATION) return indentOfMultipleDeclarationChild(type, IMPORT_SPEC); if (parentType == CONST_DECLARATION) return indentOfMultipleDeclarationChild(type, CONST_SPEC); if (parentType == VAR_DECLARATION) return indentOfMultipleDeclarationChild(type, VAR_SPEC); if (parentType == TYPE_DECLARATION) return indentOfMultipleDeclarationChild(type, TYPE_SPEC); if (parentType == COMM_CLAUSE && child.getPsi() instanceof GoStatement) return Indent.getNormalIndent(); if (child.getPsi() instanceof GoExpression) return Indent.getContinuationWithoutFirstIndent(); return Indent.getNoneIndent(); }